示例#1
0
void QStreamCubeChat::onSmilesLoaded()
{
    QNetworkReply * reply = qobject_cast< QNetworkReply * >( sender() );

    QJsonParseError parseError;

    QJsonDocument jsonDoc = QJsonDocument::fromJson( reply->readAll(), &parseError );

    if( QJsonParseError::NoError == parseError.error && jsonDoc.isArray() )
    {
        QJsonArray jsonArr =jsonDoc.array();

        for( const QJsonValue & smileVal : jsonArr )
        {
            QJsonArray smileInfo = smileVal.toArray();

            addSmile( smileInfo[ 0 ].toString(), DEFAULT_STREAM_CUBE_SMILE_PREFIX + smileInfo[ 1 ].toString() );
        }

        if( isShowSystemMessages() )
        {
            emit newMessage( ChatMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Smiles loaded..." ), QString(), this ) );
            emitSystemMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Smiles loaded..." ) );
        }
    }
    else
    {
        emit newMessage( ChatMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Can not load smiles..." ), QString(), this ) );
        emitSystemMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Can not laod smiles..." ) );
    }

    reply->deleteLater();
}
示例#2
0
void QYoutubeChat::onChannelInfoLoaded()
{
    QNetworkReply * reply = qobject_cast< QNetworkReply *  >( sender() );

    QString channelInfo = reply->readAll();

    int startLastTimePos = channelInfo.indexOf( "\'COMMENTS_LATEST_TIMESTAMP\'" );
    startLastTimePos = channelInfo.indexOf( ':', startLastTimePos ) + 1;
    int endLastTimePos = channelInfo.indexOf( ',', startLastTimePos ) - 1;

    lastMessageTime_ = channelInfo.mid( startLastTimePos,endLastTimePos - startLastTimePos + 1 );

    lastMessageTime_.replace( ' ', "" );

    if( !lastMessageTime_.isEmpty() )
    {
        if( isShowSystemMessages() )
            emit newMessage( new QChatMessage( YOUTUBE_SERVICE, YOUTUBE_USER, "Connected to " + channelName_ + "...", "", this ) );

        if( updateMessagesTimerId_ == -1 )
            updateMessagesTimerId_ = startTimer( updateMessagesInterval_ );
    }

    reply->deleteLater();
}
示例#3
0
void QStreamCubeChat::onChannelInfoLoaded()
{
    QNetworkReply * reply = qobject_cast< QNetworkReply * >( sender() );

    QJsonParseError parseError;

    QJsonDocument jsonDoc = QJsonDocument::fromJson( reply->readAll(), &parseError );

    if( QJsonParseError::NoError == parseError.error && jsonDoc.isArray() )
    {
        QJsonArray jsonArr = jsonDoc.array();

        channelId_ = jsonArr[ 0 ].toString();

        if( isShowSystemMessages() )
        {
            emit newMessage( ChatMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Connected to " ) + channelName_ + tr( "..." ), QString(), this ) );
            emitSystemMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Connected to " ) + channelName_ + tr( "..." ) );
        }

        loadMessages();
        startUniqueTimer( updateTimerId_, UPDATE_INTERVAL );
    }

    reply->deleteLater();
}
示例#4
0
void QTwitchChat::onEmotIconsLoaded()
{
    QNetworkReply *reply = qobject_cast< QNetworkReply * >( sender() );

    QJsonParseError parseError;
    QJsonDocument jsonDoc;

    jsonDoc = QJsonDocument::fromJson( reply->readAll(), &parseError );

    if( parseError.error == QJsonParseError::NoError )
    {
        if( jsonDoc.isObject() )
        {
            emotIcons_.clear();

            QJsonArray jsonEmotIcons = jsonDoc.object()[ "emoticons" ].toArray();

            foreach( const QJsonValue &value, jsonEmotIcons )
            {
                QJsonObject jsonEmotIcon = value.toObject();

                QChatSmile smile(   jsonEmotIcon[ "regex" ].toString(),
                                    jsonEmotIcon[ "url" ].toString(),
                                    jsonEmotIcon[ "width" ].toInt(),
                                    jsonEmotIcon[ "height" ].toInt() );
                //emotIcons_.append( smile );
                emotIcons_.insert( smile.name(), smile );
            }
            if( isShowSystemMessages() )
                emit newMessage( new QChatMessage( TWITCH_SERVICE, TWITCH_USER, "Smiles ready...", "", this ) );
        }
示例#5
0
void QTwitchChat::connect()
{
    if( channelName_ == "" )
        return;

    if( isShowSystemMessages() )
        emit newMessage( new QChatMessage( TWITCH_SERVICE, TWITCH_USER, "Connecting to " + channelName_ + "...", "", this ) );

    if( socket_)
    {
        if( socket_->state() == QAbstractSocket::ConnectedState )
            return;
        /*else
            reconnect();*/
    }

    socket_ = new QTcpSocket();

    QObject::connect( socket_, SIGNAL( connected() ), this, SLOT( onConnected() ) );
    QObject::connect( socket_, SIGNAL( readyRead() ), this, SLOT( parseMessage() ) );
    QObject::connect( socket_, SIGNAL( error( QAbstractSocket::SocketError ) ), this, SLOT( onSocketError() ) );

    //QObject::connect( socket_, SIGNAL( disconnected() ), this, SLOT( reconnect() ) );

    socket_->connectToHost( DEFAULT_TWITCH_CHAT_HOST_NAME, DEFAULT_TWITCH_CHAT_PORT_NUMBER );
}
示例#6
0
void QVidiChat::onSocketMessageReceived( const QString & message )
{   
    QJsonParseError parseError;

    QJsonDocument jsonDoc = QJsonDocument::fromJson( message.toUtf8(), &parseError );

    if( QJsonParseError::NoError == parseError.error && jsonDoc.isObject() )
    {
        QJsonObject jsonObj = jsonDoc.object();

        QString type = jsonObj[ "type" ].toString();

        if( "message" == type )
        {
            //{\"type\":\"message\",\"data\":{\"channel_id\":1024,\"user_id\":1016,\"user_name\":\"c0deum\",\"user_rights\":20,\"user_groups\":[],\"hideIcon\":0,\"icon\":\"\",\"color\":\"\",\"isStatus\":0,\"mobile\":0,\"paidsmiles\":{\"0\":[],\"1024\":[]},\"message_id\":3,\"timestamp\":1460203043,\"text\":\"123\"}}

            QJsonObject jsonMessageInfo = jsonObj[ "data" ].toObject();

            QString nickName = jsonMessageInfo[ "user_name" ].toString();
            QString messageText = jsonMessageInfo[ "text" ].toString();

            messageText = ChatMessage::deleteTags( messageText );

            emit newMessage( ChatMessage( SERVICE_NAME, nickName, messageText, QString(), this ) );
        }
        else if( "welcome" == type )
        {
            socket_->sendTextMessage( "{\"type\":\"auth\",\"data\":{\"token\":\"undefined\",\"site_id\":2}}" );
        }
        else if( "success_auth" == type )
        {
            socket_->sendTextMessage( "{\"type\":\"unjoin\",\"data\":{\"channel_id\":\"" + channelId_ +"\"}}" );
            socket_->sendTextMessage( "{\"type\":\"join\",\"data\":{\"channel_id\":\"" + channelId_ + "\",\"hidden\":false,\"mobile\":0}}" );
        }
        else if( "success_join" == type )
        {
            if( isShowSystemMessages() )
            {
                emit newMessage( ChatMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Connected to " ) + channelName_ + "...", QString(), this ) );
                emitSystemMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Connected to " ) + channelName_ + tr( "..." ) );
            }

            loadStatistic();
            startUniqueTimer( statisticTimerId_, STATISTIC_INTERVAL );

            startUniqueTimer( saveSocketConnectionTimerId_, SAVE_SOCKET_CONNECTION_INTERVAL );
        }
    }

    //{\"type\":\"get_channel_counters\",\"data\":{\"channel_id\":1024}}
    //{\"type\":\"get_channel_history\",\"data\":{\"channel_id\":1024,\"from\":0}}

    //

    //{\"type\":\"channel_counters\",\"data\":{\"channel_id\":\"1024\",\"clients_in_channel\":1,\"users_in_channel\":0}}
    //{\"type\":\"message\",\"data\":{\"channel_id\":1024,\"user_id\":1016,\"user_name\":\"c0deum\",\"user_rights\":20,\"user_groups\":[],\"hideIcon\":0,\"icon\":\"\",\"color\":\"\",\"isStatus\":0,\"mobile\":0,\"paidsmiles\":{\"0\":[],\"1024\":[]},\"message_id\":3,\"timestamp\":1460203043,\"text\":\"123\"}}
}
示例#7
0
void QFunStreamChat::reconnect()
{
    QString oldChannelName = channelName_;
    disconnect();
    loadSettings();
    if( channelName_ != "" && oldChannelName != "" )
        if( isShowSystemMessages() )
            emit newMessage( new QChatMessage( FUNSTREAM_SERVICE, FUNSTREAM_USER, "Reconnecting...", "", this ) );
    connect();
}
示例#8
0
void QYoutubeChat::reconnect()
{
    QString oldChannelName = channelName_;
    disconnect();
    loadSettings();
    if( channelName_ != "" && oldChannelName != "" )
        if( isShowSystemMessages() )
            emit newMessage( new QChatMessage( YOUTUBE_SERVICE, YOUTUBE_USER, "Reconnecting...", "", this ) );
    connect();
}
示例#9
0
void QVidiChat::onSocketConnetError()
{
    if( isShowSystemMessages() )
    {
        emit newMessage( ChatMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "WebSocket Error... " ), QString(), this ) );
        emitSystemMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "WebSocket Error..." ));
    }

    startUniqueTimer( reconnectTimerId_, RECONNECT_INTERVAL );
}
示例#10
0
void QTwitchChat::reconnect()
{
    QString oldChannelName = channelName_;
    disconnect();
    loadSettings();
    if( channelName_ != "" && oldChannelName != "" )
        if( isShowSystemMessages() )
            emit newMessage( new QChatMessage( TWITCH_SERVICE, TWITCH_USER, "Reconnecting...", "", this ) );
    connect();
}
示例#11
0
void QYoutubeChat::connect()
{
    if( channelName_ == "" )
        return;

    if( isShowSystemMessages() )
        emit newMessage( new QChatMessage( YOUTUBE_SERVICE, YOUTUBE_USER, "Connecting to " + channelName_ + "...", "", this ) );

    getChannelInfo();
}
示例#12
0
void QStreamCubeChat::reconnect()
{
    QString oldChannelName = channelName_;
    disconnect();
    loadSettings();
    if( isEnabled() && !channelName_.isEmpty() && !oldChannelName.isEmpty() && isShowSystemMessages() )
    {
        emit newMessage( ChatMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Reconnecting to " ) + channelName_ + tr( "..." ), QString(), this ) );
        emitSystemMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Reconnecting to " ) + channelName_ + tr( "..." ) );
    }
    connect();
}
示例#13
0
void QStreamCubeChat::onMessagesLoadError()
{
    QNetworkReply * reply = qobject_cast< QNetworkReply * >( sender() );

    if( isShowSystemMessages() )
    {
        emit newMessage( ChatMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Can not load messages..." ), QString(), this ) );
        emitSystemMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Can not laod messages..." ) );
    }

    reply->deleteLater();
}
示例#14
0
void QVidiChat::connect()
{
    if( !isEnabled() || channelName_.isEmpty() )
        return;

    if( isShowSystemMessages() )
    {
        emit newMessage( ChatMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Connecting to " ) + channelName_ + tr( "..." ), QString(), this ) );
        emitSystemMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Connecting to " ) + channelName_ + tr( "..." ) );
    }

    loadChannelInfo();
}
示例#15
0
void QStreamCubeChat::onChannelInfoLoadError()
{
    QNetworkReply * reply = qobject_cast< QNetworkReply * >( sender() );

    if( isShowSystemMessages() )
    {
        emit newMessage( ChatMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Can not connect to " ) + channelName_ + tr( "..." ), QString(), this ) );
        emitSystemMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Can not connect to " ) + channelName_ + tr( "..." ) );
    }

    startUniqueTimer( reconnectTimerId_, RECONNECT_INTERVAL );
    reply->deleteLater();
}
示例#16
0
void QTwitchChat::onSelfLoadError()
{
    QNetworkReply *reply = qobject_cast< QNetworkReply * >( sender() );

    //reconnect();
    if( isShowSystemMessages() )
        emit newMessage( new QChatMessage( TWITCH_SERVICE, TWITCH_USER, "Can not connect to " + channelName_ + "..." + reply->errorString(), "", this ) );
    //reconnect();
    if( reconnectTimerId_ == -1 )
        reconnectTimerId_ = startTimer( reconnectInterval_ );
    //qDebug() << "Twitch::onSelfLoadError(): reconnectTimerId_" << reconnectTimerId_;

    reply->deleteLater();
}
示例#17
0
void QFunStreamChat::connect()
{
    if( channelName_ == "" )
        return;

    lastMessageId_ = 0;

    smiles_.clear();

    if( isShowSystemMessages() )
        emit newMessage( new QChatMessage( FUNSTREAM_SERVICE, FUNSTREAM_USER, "Connecting to " + channelName_ + "...", "", this ) );

    getChannelInfo();
}
示例#18
0
void QVidiChat::onChannelInfoLoaded()
{
    QNetworkReply * reply = qobject_cast< QNetworkReply * >( sender() );

    QJsonParseError parseError;

    QJsonDocument jsonDoc = QJsonDocument::fromJson( reply->readAll(), &parseError );

    if( QJsonParseError::NoError == parseError.error && jsonDoc.isObject() )
    {
        QJsonObject jsonObj = jsonDoc.object();

        QJsonObject jsonUser = jsonObj[ "user" ].toObject();

        QJsonObject jsonChannel = jsonUser[ "Channel" ].toObject();

        channelId_ = jsonChannel[ "name" ].toString();


        int delPos = channelId_.indexOf( '_' );

        if( delPos > 0 )
        {
            channelId_ = channelId_.right( channelId_.length() - delPos - 1 );
            connectToSocket();
        }
        else
        {
            if( isShowSystemMessages() )
            {
                emit newMessage( ChatMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Can not connect to " ) + channelName_ + "...", QString(), this ) );
                emitSystemMessage( SERVICE_NAME, SERVICE_USER_NAME, tr( "Can not connect to " ) + channelName_ + tr( "..." ) );
            }

            startUniqueTimer( reconnectTimerId_, RECONNECT_INTERVAL );
        }


        //        connectToJoinSocket();
        //loadSid();
    }

    reply->deleteLater();
}
示例#19
0
void QTwitchChat::parseMessage()
{
    if( !socket_ )
        return;

    if( socket_->state() == QAbstractSocket::ConnectedState )
    {
        QString line = socket_->readLine();

        //qDebug() << line;

        //поадекватнее надо быть

        if( line.contains ( "376 " + DEFAULT_USER_NICK_NAME ) )
        {
            socket_->write( QString( "JOIN #" + channelName_ + "\r\n" ).toStdString().c_str() );
            getSelf();

            //emit newMessage( new QChatMessage( "qrc:/resources/twitchlogo.png", TWITCH_USER, "Connecting to " + channelName_ + "...", this ) );
            if( isShowSystemMessages() )
                emit newMessage( new QChatMessage( TWITCH_SERVICE, TWITCH_USER, "Connected to " + channelName_ + "...", "", this ) );

            getStatistic();
            if( statisticTimerId_ )
                statisticTimerId_ = startTimer( statisticInterval_ );
        }
        else if( line.contains( "PING" ) )
        {
            qDebug() << line;
            //socket_->write( "PONG tmi.twitch.tv\r\n" );
            socket_->write( "PONG :tmi.twitch.tv\r\n" );
        }
        else
        {
            //TODO: parse message
            if( line.contains( "PRIVMSG" ) && !line.contains( "HISTORYEND" ) && !line.contains( "USERCOLOR") )
            {
                QString nickName = line.mid( 1, line.indexOf( '!' ) - 1 );
                QString message = line.right( line.size() - line.indexOf( ':', 1 ) - 1 );

                //\r\n
                message = message.left( message.size() - 2 );

                //qDebug() << message;

                message = QChatMessage::replaceEscapeCharecters( message );
                message = insertEmotIcons( message );
                //message = QChatMessage::insertLinks( message );

                bool blackListUser = blackList().contains( nickName );
                bool supportersListUser = supportersList().contains( nickName );

                if( !isRemoveBlackListUsers() || !blackListUser )
                {
                    if( blackListUser )
                    {
                        emit newMessage( new QChatMessage( TWITCH_SERVICE, nickName, message, "ignore", this ) );
                    }
                    else
                    {
                        if( supportersListUser )
                        {
                            emit newMessage( new QChatMessage( TWITCH_SERVICE, nickName, message, "supporter", this ) );
                        }
                        else
                        {
                            if( isContainsAliases( message ) )
                            {
                                emit newMessage( new QChatMessage( TWITCH_SERVICE, nickName, message, "alias", this ) );
                            }
                            else
                            {
                                emit newMessage( new QChatMessage( TWITCH_SERVICE, nickName, message, "", this ) );
                            }
                        }
                    }
                }
            }
        }

        if( socket_->canReadLine() )
        {
            parseMessage();
        }
    }
}
示例#20
0
//#yotube signals region
void QYoutubeChatEx::error(const QString errorMessage)
{
    if( isShowSystemMessages() )
        emit newMessage( ChatMessage( YOUTUBE_SERVICE, YOUTUBE_USER, "Error: " + errorMessage , "", this ) );
}
示例#21
0
void QFunStreamChat::onChannelInfoLoaded()
{
    QNetworkReply *reply = qobject_cast< QNetworkReply * >( sender() );

    QString info = reply->readAll();

    int startInfoPos = info.indexOf( "[[" );
    int endInfoPos = info.indexOf( ";</script>" );

    info = info.mid( startInfoPos, endInfoPos - startInfoPos );

    //qDebug() << "Script:\n" << info;

    QJsonParseError parseError;

    QJsonDocument jsonDoc = QJsonDocument::fromJson( QByteArray( info.toStdString().c_str() ), &parseError );

    if( parseError.error == QJsonParseError::NoError )
    {
        if( jsonDoc.isArray() )
        {

            QJsonArray jsonArr = jsonDoc.array();

            /*
            QJsonArray jsonStreamInfoArr = jsonArr[ 0 ].toArray();

            QJsonObject streamInfo = jsonStreamInfoArr[ 1 ].toObject();

            channelId_ = QString::number( streamInfo[ "id" ].toInt() );
            */


            QJsonArray jsonStreamInfoArr = jsonArr[ 1 ].toArray();
            //parse stream info

            QJsonObject jsonStreamInfoObj = jsonStreamInfoArr[ 2 ].toObject();
            QJsonObject jsonStreamerInfoObj = jsonStreamInfoObj[ "streamer" ].toObject();

            channelId_ = QString::number( jsonStreamerInfoObj[ "id" ].toInt() );

            //parse smile info
            QJsonArray jsonSmilesInfoArr = jsonArr[ 3 ].toArray();
            QJsonArray jsonSmilesTabs = jsonSmilesInfoArr[ 2 ].toArray();

            //0-6 + 1(streamers smiles)
            const int SMILES_TABS = 8;

            for( int i = 0; i < SMILES_TABS; i++ )
            {
                foreach( const QJsonValue &smileInfo, jsonSmilesTabs[ i ].toArray() )
                {
                    QJsonObject smileInfoObj = smileInfo.toObject();
                    smiles_.append( QChatSmile( ":" + smileInfoObj[ "code" ].toString() + ":", DEFAULT_FUNSTREAM_SMILES_LINK + smileInfoObj[ "image" ].toString(), 0 , 0 ) );

                    //Free smiles for funstream
                    smiles_.append( QChatSmile( ":free-" + smileInfoObj[ "code" ].toString() + ":", DEFAULT_FUNSTREAM_SMILES_LINK + smileInfoObj[ "image" ].toString(), 0 , 0 ) );
                }
            }

            if( isShowSystemMessages() )
                emit newMessage( new QChatMessage( FUNSTREAM_SERVICE, FUNSTREAM_USER, "Smiles ready...", "", this ) );

            connectToWebClient();
        }
    }