void CSkypeProto::AddMessageToChat(const TCHAR *chat_id, const TCHAR *from, const char *content, bool isAction, int emoteOffset, time_t timestamp, bool isLoading) { GCDEST gcd = { m_szModuleName, chat_id, isAction ? GC_EVENT_ACTION : GC_EVENT_MESSAGE }; GCEVENT gce = { sizeof(GCEVENT), &gcd }; gce.bIsMe = IsMe(_T2A(from)); gce.ptszNick = from; gce.time = timestamp; gce.ptszUID = from; ptrA szHtml(RemoveHtml(content)); ptrT tszHtml(mir_utf8decodeT(szHtml)); if (!isAction) { gce.ptszText = tszHtml; gce.dwFlags = GCEF_ADDTOLOG; } else { gce.ptszText = &tszHtml[emoteOffset]; } if (isLoading) gce.dwFlags = GCEF_NOTNOTIFY; CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); }
void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) { if (response == NULL) return; JSONNode root = JSONNode::parse(response->pData); if (!root) return; const JSONNode &metadata = root["_metadata"]; const JSONNode &conversations = root["messages"].as_array(); int totalCount = metadata["totalCount"].as_int(); std::string syncState = metadata["syncState"].as_string(); bool markAllAsUnread = getBool("MarkMesUnread", true); if (totalCount >= 99 || conversations.size() >= 99) PushRequest(new GetHistoryOnUrlRequest(syncState.c_str(), li), &CSkypeProto::OnGetServerHistory); for (int i = (int)conversations.size(); i >= 0; i--) { const JSONNode &message = conversations.at(i); CMStringA szMessageId = message["clientmessageid"] ? message["clientmessageid"].as_string().c_str() : message["skypeeditedid"].as_string().c_str(); std::string messageType = message["messagetype"].as_string(); std::string from = message["from"].as_string(); std::string content = message["content"].as_string(); std::string conversationLink = message["conversationLink"].as_string(); int emoteOffset = message["skypeemoteoffset"].as_int(); time_t timestamp = IsoToUnixTime(message["composetime"].as_string().c_str()); CMStringA skypename(UrlToSkypename(from.c_str())); bool isEdited = message["skypeeditedid"]; MCONTACT hContact = FindContact(UrlToSkypename(conversationLink.c_str())); if (timestamp > db_get_dw(hContact, m_szModuleName, "LastMsgTime", 0)) db_set_dw(hContact, m_szModuleName, "LastMsgTime", (DWORD)timestamp); int iFlags = DBEF_UTF; if (!markAllAsUnread) iFlags |= DBEF_READ; if (IsMe(skypename)) iFlags |= DBEF_SENT; if (strstr(conversationLink.c_str(), "/8:")) { if (messageType == "Text" || messageType == "RichText") { ptrA szMessage(messageType == "RichText" ? RemoveHtml(content.c_str()) : mir_strdup(content.c_str())); MEVENT dbevent = GetMessageFromDb(hContact, szMessageId); if (isEdited && dbevent != NULL) { AppendDBEvent(hContact, dbevent, szMessage, szMessageId, timestamp); } else AddDbEvent(emoteOffset == 0 ? EVENTTYPE_MESSAGE : SKYPE_DB_EVENT_TYPE_ACTION, hContact, timestamp, iFlags, &szMessage[emoteOffset], szMessageId); } else if (messageType == "Event/Call") { AddDbEvent(SKYPE_DB_EVENT_TYPE_CALL_INFO, hContact, timestamp, iFlags, content.c_str(), szMessageId); } else if (messageType == "RichText/Files") { AddDbEvent(SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO, hContact, timestamp, iFlags, content.c_str(), szMessageId); } else if (messageType == "RichText/UriObject") { AddDbEvent(SKYPE_DB_EVENT_TYPE_URIOBJ, hContact, timestamp, iFlags, content.c_str(), szMessageId); } else if (messageType == "RichText/Contacts") { ProcessContactRecv(hContact, timestamp, content.c_str(), szMessageId); } else { AddDbEvent(SKYPE_DB_EVENT_TYPE_UNKNOWN, hContact, timestamp, iFlags, content.c_str(), szMessageId); } } else if (conversationLink.find("/19:") != -1) { CMStringA chatname(UrlToSkypename(conversationLink.c_str())); if (messageType == "Text" || messageType == "RichText") { AddMessageToChat(_A2T(chatname), _A2T(skypename), content.c_str(), emoteOffset != NULL, emoteOffset, timestamp, true); } } } }