Example #1
0
QQMsg *MsgProcessor::createGroupMsg(const Json::Value &result) const
{
	QQGroupChatMsg *g_chat_msg = new QQGroupChatMsg();
	g_chat_msg->set_type(QQMsg::kGroup);
	g_chat_msg->send_uin_ = QString::number(result["value"]["send_uin"].asLargestInt());
	g_chat_msg->from_uin_ = QString::number(result["value"]["from_uin"].asLargestInt());
	g_chat_msg->to_uin_ = QString::number(result["value"]["to_uin"].asLargestInt());
	g_chat_msg->info_seq_ = QString::number(result["value"]["info_seq"].asLargestInt());
	g_chat_msg->group_code_ =QString::number(result["value"]["group_code"].asLargestInt());
	g_chat_msg->color_ = QString::fromStdString(result["value"]["content"][0][1]["color"].asString());
	g_chat_msg->size_ = result["value"]["content"][0][1]["size"].asInt();
	g_chat_msg->time_ = result["value"]["time"].asLargestInt();
	g_chat_msg->font_name_ = QString::fromStdString(result["value"]["content"][0][1]["name"].asString());

	for (unsigned int i = 1; i < result["value"]["content"].size(); ++i)
	{
		QQChatItem item;
		Json::Value content = result["value"]["content"][i];

		if (content.type() == Json::stringValue)
		{
			if ( isChatContentEmpty(g_chat_msg, QString::fromStdString(content.asString())) )
				continue;

			item.set_type(QQChatItem::kWord);
			item.set_content(QString::fromStdString(content.asString()));
		}
		else
		{
			QString face_type =  QString::fromStdString(content[0].asString());

			if (face_type == "face")
			{
				item.set_type(QQChatItem::kQQFace);
				item.set_content(QString::number(content[1].asInt()));
			}
			else
			{
				if ( content[0].asString() == "cface_idx" )
					continue;

				item.set_type(QQChatItem::kGroupChatImg);
				item.set_content(QString::fromStdString(content[1]["name"].asString()));
				item.set_file_id(QString::number(content[1]["file_id"].asLargestInt()));
				QString server = QString::fromStdString(content[1]["server"].asString());
				int ip_end_idx = server.indexOf(":");
				item.set_server_ip(server.mid(0, ip_end_idx));
				item.set_server_port(server.mid(ip_end_idx+1));
			}
		}
		g_chat_msg->msg_.append(item);
	}
	return g_chat_msg;
}
Example #2
0
QQMsg *MsgProcessor::createSessMsg(const Json::Value &result) const
{
	QQSessChatMsg *chat_msg = new QQSessChatMsg();
	chat_msg->set_type(QQMsg::kSess);
	chat_msg->from_uin_ = QString::number(result["value"]["from_uin"].asLargestInt());
	chat_msg->gid_ = QString::number(result["value"]["id"].asLargestInt());
	chat_msg->msg_id_ = QString::number(result["value"]["msg_id"].asInt());
	chat_msg->to_uin_ = QString::number(result["value"]["to_uin"].asLargestInt());
	chat_msg->color_ = QString::fromStdString(result["value"]["content"][0][1]["color"].asString());
	chat_msg->size_ = result["value"]["content"][0][1]["size"].asInt();
	chat_msg->time_ = result["value"]["time"].asLargestInt();
	chat_msg->font_name_ = QString::fromStdString(result["value"]["content"][0][1]["name"].asString());

	for (unsigned int i = 1; i < result["value"]["content"].size(); ++i)
	{
		QQChatItem item;
		Json::Value content = result["value"]["content"][i];

		if (content.type() == Json::stringValue)
		{
			if ( isChatContentEmpty(chat_msg, QString::fromStdString(content.asString())) )
				continue;

			item.set_type(QQChatItem::kWord);
			item.set_content(QString::fromStdString(content.asString()));
		}
		else
		{
			QString face_type =  QString::fromStdString(content[0].asString());

			if (face_type == "face")
			{
				item.set_type(QQChatItem::kQQFace);
				item.set_content(QString::number(content[1].asInt()));
			}
			else if (face_type == "offpic")
			{
				item.set_type(QQChatItem::kFriendOffpic);
				item.set_content(QString::fromStdString(content[1]["file_path"].asString()));
			}
			else
			{
				item.set_type(QQChatItem::kFriendCface);
				item.set_content(QString::fromStdString(content[1].asString()));
			}
		}
		chat_msg->msg_.append(item);
	}

	return chat_msg;
}
Example #3
0
QQMsg* QQParseThread::createMsg(QString type, const Json::Value result)
{
    if (type ==  "group_message")
    {
        QQGroupChatMsg *g_chat_msg = new QQGroupChatMsg();
        g_chat_msg->set_type(QQMsg::kGroup);
        g_chat_msg->send_uin_ = QString::number(result["value"]["send_uin"].asLargestInt());
        g_chat_msg->from_uin_ = QString::number(result["value"]["from_uin"].asLargestInt());
        g_chat_msg->to_uin_ = QString::number(result["value"]["from_uin"].asLargestInt());
        g_chat_msg->info_seq_ = QString::number(result["value"]["info_seq"].asLargestInt());
        g_chat_msg->color_ = QString::fromStdString(result["value"]["content"][0][1]["color"].asString());
        g_chat_msg->size_ = result["value"]["content"][0][1]["size"].asInt();
        g_chat_msg->time_ = result["value"]["time"].asLargestInt();
        g_chat_msg->font_name_ = QString::fromStdString(result["value"]["content"][0][1]["name"].asString());

        for (unsigned int i = 1; i < result["value"]["content"].size(); ++i)
        {
            QQChatItem item;
            Json::Value content = result["value"]["content"][i];

            if (content.type() == Json::stringValue)
            {
                item.set_type(QQChatItem::kWord);
                item.set_content(QString::fromStdString(content.asString()));
            }
            else
            {
                QString face_type =  QString::fromStdString(content[0].asString());

                if (face_type == "face")
                {
                    item.set_type(QQChatItem::kQQFace);
                    item.set_content(QString::number(content[1].asInt()));
                }
                else
                {
                    item.set_type(QQChatItem::kGroupChatImg);
                    item.set_content(QString::fromStdString(content[1]["name"].asString()));
                }
            }
            g_chat_msg->msg_.append(item);
        }
        return g_chat_msg;
    }
    else if (type == "buddies_status_change")
    {
        QQStatusChangeMsg *status_msg = new QQStatusChangeMsg();
        status_msg->set_type(QQMsg::kBuddiesStatusChange);
        status_msg->uin_ = QString::number(result["value"]["uin"].asLargestInt());
        status_msg->client_type_ = result["value"]["client_type"].asInt();
        QString status_str = QString::fromStdString(result["value"]["status"].asString());
        if (status_str == "online")
        {
            status_msg->status_ = kOnline;
        }
        else
        {
            status_msg->status_ = kLeave;
        }
        return status_msg;
    }
    else if (type == "sys_g_msg")
    {
        QQSystemMsg *system_msg = new QQSystemMsg();
        system_msg->set_type(QQMsg::kSystem);
        system_msg->from_ = QString::number(result["value"]["request_uin"].asLargestInt());
        system_msg->aid_ = QString::number(result["value"]["gcode"].asLargestInt());
        system_msg->msg_ = QString::fromStdString(result["value"]["msg"].asString());
        return system_msg;
    }
    else if (type == "message")
    {
        qDebug()<<"message parseing"<<endl;
        QQChatMsg *chat_msg = new QQChatMsg();
        chat_msg->set_type(QQMsg::kFriend);
        chat_msg->from_uin_ = QString::number(result["value"]["from_uin"].asLargestInt());
        chat_msg->msg_id_ = QString::number(result["value"]["msg_id"].asInt());
        chat_msg->to_uin_ = QString::number(result["value"]["to_uin"].asLargestInt());
        chat_msg->color_ = QString::fromStdString(result["value"]["content"][0][1]["color"].asString());
        chat_msg->size_ = result["value"]["content"][0][1]["size"].asInt();
        chat_msg->time_ = result["value"]["time"].asLargestInt();
        chat_msg->font_name_ = QString::fromStdString(result["value"]["content"][0][1]["name"].asString());

        for (unsigned int i = 1; i < result["value"]["content"].size(); ++i)
        {
            QQChatItem item;
            Json::Value content = result["value"]["content"][i];

            if (content.type() == Json::stringValue)
            {
                item.set_type(QQChatItem::kWord);
                item.set_content(QString::fromStdString(content.asString()));
            }
            else
            {
                QString face_type =  QString::fromStdString(content[0].asString());

                if (face_type == "face")
                {
                    item.set_type(QQChatItem::kQQFace);
                    item.set_content(QString::number(content[1].asInt()));
                }
                else if (face_type == "offpic")
                {
                    item.set_type(QQChatItem::kFriendOffpic);
                    item.set_content(QString::fromStdString(content[1]["file_path"].asString()));
                }
                else
                {
                    item.set_type(QQChatItem::kFriendCface);
                    item.set_content(QString::fromStdString(content[1].asString()));
                }
            }
            chat_msg->msg_.append(item);
        }

        return chat_msg;
    }
    else
    {
        qDebug()<<"unknow type"<<endl;
        return NULL;
    }
}