diff options
author | George Hazan <george.hazan@gmail.com> | 2024-08-06 12:37:41 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-08-06 12:37:41 +0300 |
commit | af775d509bf12dd75cdc5088a04bd39cae06ef30 (patch) | |
tree | 606dd3e1000db4cc8d10b3e462e2faebfb5e1b03 /protocols/SkypeWeb | |
parent | 739955c81588319e5bc24c5efb96162bbadc13cd (diff) |
SkypeWeb: duplicate message processing code went to the common function
Diffstat (limited to 'protocols/SkypeWeb')
-rw-r--r-- | protocols/SkypeWeb/src/skype_chatrooms.cpp | 109 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_history_sync.cpp | 45 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_messages.cpp | 116 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 3 |
4 files changed, 124 insertions, 149 deletions
diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index a5e6652c32..de29ccfe0e 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -241,7 +241,7 @@ INT_PTR CSkypeProto::OnLeaveChatRoom(WPARAM hContact, LPARAM) /* CHAT EVENT */
-void CSkypeProto::OnChatEvent(const JSONNode &node)
+bool CSkypeProto::OnChatEvent(const JSONNode &node)
{
CMStringW wszChatId(UrlToSkypeId(node["conversationLink"].as_mstring()));
CMStringW szFromId(UrlToSkypeId(node["from"].as_mstring()));
@@ -254,7 +254,7 @@ void CSkypeProto::OnChatEvent(const JSONNode &node) si = StartChatRoom(wszChatId, wszTopic);
if (si == nullptr) {
debugLogW(L"unable to create chat %s", wszChatId.c_str());
- return;
+ return true;
}
}
@@ -262,72 +262,75 @@ void CSkypeProto::OnChatEvent(const JSONNode &node) if (messageType == "ThreadActivity/AddMember") {
// <addmember><eventtime>1429186229164</eventtime><initiator>8:initiator</initiator><target>8:user</target></addmember>
TiXmlDocument doc;
- if (0 != doc.Parse(T2Utf(wszContent)))
- return;
-
- if (auto *pRoot = doc.FirstChildElement("addMember")) {
- CMStringW target = Utf2T(XmlGetChildText(pRoot, "target"));
- AddChatContact(si, target, L"User");
+ if (!doc.Parse(T2Utf(wszContent))) {
+ if (auto *pRoot = doc.FirstChildElement("addMember")) {
+ CMStringW target = Utf2T(XmlGetChildText(pRoot, "target"));
+ AddChatContact(si, target, L"User");
+ }
}
+ return true;
}
- else if (messageType == "ThreadActivity/DeleteMember") {
+
+ if (messageType == "ThreadActivity/DeleteMember") {
// <deletemember><eventtime>1429186229164</eventtime><initiator>8:initiator</initiator><target>8:user</target></deletemember>
TiXmlDocument doc;
- if (0 != doc.Parse(T2Utf(wszContent)))
- return;
-
- if (auto *pRoot = doc.FirstChildElement("deletemember")) {
- CMStringW target = Utf2T(UrlToSkypeId(XmlGetChildText(pRoot, "target")));
- CMStringW initiator = Utf2T(XmlGetChildText(pRoot, "initiator"));
- RemoveChatContact(si, target, true, initiator);
+ if (!doc.Parse(T2Utf(wszContent))) {
+ if (auto *pRoot = doc.FirstChildElement("deletemember")) {
+ CMStringW target = Utf2T(UrlToSkypeId(XmlGetChildText(pRoot, "target")));
+ CMStringW initiator = Utf2T(XmlGetChildText(pRoot, "initiator"));
+ RemoveChatContact(si, target, true, initiator);
+ }
}
+ return true;
}
- else if (messageType == "ThreadActivity/TopicUpdate") {
+
+ if (messageType == "ThreadActivity/TopicUpdate") {
// <topicupdate><eventtime>1429532702130</eventtime><initiator>8:user</initiator><value>test topic</value></topicupdate>
TiXmlDocument doc;
- if (0 != doc.Parse(T2Utf(wszContent)))
- return;
-
- auto *pRoot = doc.FirstChildElement("topicupdate");
- if (pRoot) {
- CMStringW initiator = Utf2T(XmlGetChildText(pRoot, "initiator"));
- CMStringW value = Utf2T(XmlGetChildText(pRoot, "value"));
- Chat_ChangeSessionName(si, value);
-
- GCEVENT gce = { si, GC_EVENT_TOPIC };
- gce.pszUID.w = initiator;
- gce.pszNick.w = GetSkypeNick(initiator);
- gce.pszText.w = wszTopic;
- Chat_Event(&gce);
+ if (!doc.Parse(T2Utf(wszContent))) {
+ if (auto *pRoot = doc.FirstChildElement("topicupdate")) {
+ CMStringW initiator = Utf2T(XmlGetChildText(pRoot, "initiator"));
+ CMStringW value = Utf2T(XmlGetChildText(pRoot, "value"));
+ Chat_ChangeSessionName(si, value);
+
+ GCEVENT gce = { si, GC_EVENT_TOPIC };
+ gce.pszUID.w = initiator;
+ gce.pszNick.w = GetSkypeNick(initiator);
+ gce.pszText.w = wszTopic;
+ Chat_Event(&gce);
+ }
}
+ return true;
}
- else if (messageType == "ThreadActivity/RoleUpdate") {
+
+ if (messageType == "ThreadActivity/RoleUpdate") {
// <roleupdate><eventtime>1429551258363</eventtime><initiator>8:user</initiator><target><id>8:user1</id><role>admin</role></target></roleupdate>
TiXmlDocument doc;
- if (0 != doc.Parse(T2Utf(wszContent)))
- return;
-
- auto *pRoot = doc.FirstChildElement("roleupdate");
- if (pRoot) {
- CMStringW initiator = Utf2T(UrlToSkypeId(XmlGetChildText(pRoot, "initiator")));
-
- auto *pTarget = pRoot->FirstChildElement("target");
- if (pTarget) {
- CMStringW id = Utf2T(UrlToSkypeId(XmlGetChildText(pTarget, "id")));
- const char *role = XmlGetChildText(pTarget, "role");
-
- GCEVENT gce = { si, !mir_strcmpi(role, "Admin") ? GC_EVENT_ADDSTATUS : GC_EVENT_REMOVESTATUS };
- gce.dwFlags = GCEF_ADDTOLOG;
- gce.pszNick.w = id;
- gce.pszUID.w = id;
- gce.pszText.w = initiator;
- gce.time = time(0);
- gce.bIsMe = IsMe(T2Utf(id));
- gce.pszStatus.w = TranslateT("Admin");
- Chat_Event(&gce);
+ if (!doc.Parse(T2Utf(wszContent))) {
+ if (auto *pRoot = doc.FirstChildElement("roleupdate")) {
+ CMStringW initiator = Utf2T(UrlToSkypeId(XmlGetChildText(pRoot, "initiator")));
+
+ auto *pTarget = pRoot->FirstChildElement("target");
+ if (pTarget) {
+ CMStringW id = Utf2T(UrlToSkypeId(XmlGetChildText(pTarget, "id")));
+ const char *role = XmlGetChildText(pTarget, "role");
+
+ GCEVENT gce = { si, !mir_strcmpi(role, "Admin") ? GC_EVENT_ADDSTATUS : GC_EVENT_REMOVESTATUS };
+ gce.dwFlags = GCEF_ADDTOLOG;
+ gce.pszNick.w = id;
+ gce.pszUID.w = id;
+ gce.pszText.w = initiator;
+ gce.time = time(0);
+ gce.bIsMe = IsMe(T2Utf(id));
+ gce.pszStatus.w = TranslateT("Admin");
+ Chat_Event(&gce);
+ }
}
}
+ return true;
}
+
+ return false;
}
void CSkypeProto::SendChatMessage(SESSION_INFO *si, const wchar_t *tszMessage)
diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index b858b3afce..294800d304 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -46,14 +46,13 @@ void CSkypeProto::OnGetServerHistory(MHttpResponse *response, AsyncHttpRequest * CMStringA szFrom = UrlToSkypeId(message["from"].as_mstring());
MCONTACT hContact = FindContact(szChatId);
- std::string messageType = message["messagetype"].as_string();
- int emoteOffset = message["skypeemoteoffset"].as_int();
time_t timestamp = IsoToUnixTime(message["composetime"].as_string());
if (timestamp > getDword(hContact, "LastMsgTime", 0))
setDword(hContact, "LastMsgTime", timestamp);
DB::EventInfo dbei(db_event_getById(m_szModuleName, szMessageId));
+ dbei.hContact = hContact;
dbei.szModule = m_szModuleName;
dbei.timestamp = timestamp;
dbei.szId = szMessageId;
@@ -73,44 +72,12 @@ void CSkypeProto::OnGetServerHistory(MHttpResponse *response, AsyncHttpRequest * if (IsMe(szFrom))
dbei.flags |= DBEF_SENT;
- CMStringW wszContent = message["content"].as_mstring();
- if (messageType == "RichText/UriObject") {
- ProcessFileRecv(hContact, T2Utf(wszContent), dbei);
- continue;
- }
- if (messageType == "RichText/Contacts") {
- ProcessContactRecv(hContact, T2Utf(wszContent), dbei);
- continue;
- }
-
- if (messageType == "Text" || messageType == "RichText") {
- if (messageType == "RichText")
- wszContent = RemoveHtml(wszContent);
- dbei.eventType = (emoteOffset == 0) ? EVENTTYPE_MESSAGE : SKYPE_DB_EVENT_TYPE_ACTION;
- }
- else if (messageType == "Event/Call") {
- dbei.eventType = SKYPE_DB_EVENT_TYPE_CALL_INFO;
- }
- else if (messageType == "RichText/Files") {
- dbei.eventType = SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO;
- }
- else if (messageType == "RichText/Media_Album") {
- // do nothing
- continue;
- }
- else {
- dbei.eventType = SKYPE_DB_EVENT_TYPE_UNKNOWN;
- }
-
- T2Utf szMsg(wszContent);
- dbei.cbBlob = (uint32_t)mir_strlen(szMsg);
- dbei.pBlob = szMsg;
-
- if (dbei) {
- db_event_edit(dbei.getEvent(), &dbei, true);
- dbei.pBlob = nullptr;
+ if (ParseMessage(message, dbei)) {
+ if (dbei)
+ db_event_edit(dbei.getEvent(), &dbei, true);
+ else
+ db_event_add(hContact, &dbei);
}
- else db_event_add(hContact, &dbei);
}
if (totalCount >= 99 || conv.size() >= 99) {
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 5f1619d8e0..8ceb243d0a 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -87,70 +87,33 @@ int CSkypeProto::OnPreCreateMessage(WPARAM, LPARAM lParam) /* MESSAGE EVENT */
-void CSkypeProto::ProcessNewMessage(const JSONNode &node)
+bool CSkypeProto::ParseMessage(const JSONNode &node, DB::EventInfo &dbei)
{
- int iUserType;
- UrlToSkypeId(node["conversationLink"].as_string().c_str(), &iUserType);
-
- CMStringA szMessageId = node["clientmessageid"] ? node["clientmessageid"].as_mstring() : node["skypeeditedid"].as_mstring();
- CMStringA szConversationName(UrlToSkypeId(node["conversationLink"].as_string().c_str()));
- CMStringA szFromSkypename(UrlToSkypeId(node["from"].as_mstring()));
-
int nEmoteOffset = node["skypeemoteoffset"].as_int();
-
- MCONTACT hContact = AddContact(szConversationName, nullptr, true);
-
- time_t timestamp = time(0); // fuck the server time, we need to place events in the order of our local time
- if (m_bHistorySynced)
- setDword(hContact, "LastMsgTime", timestamp);
-
- if (iUserType == 19) {
- OnChatEvent(node);
- return;
- }
-
- std::string strMessageType = node["messagetype"].as_string();
- if (strMessageType == "Control/Typing") {
- CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_INFINITE);
- return;
- }
- if (strMessageType == "Control/ClearTyping") {
- CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_OFF);
- return;
- }
-
CMStringW wszContent = node["content"].as_mstring();
- DB::EventInfo dbei(db_event_getById(m_szModuleName, szMessageId));
- dbei.timestamp = timestamp;
- dbei.szId = szMessageId;
- dbei.flags = DBEF_UTF;
- if (IsMe(szFromSkypename))
- dbei.flags |= DBEF_SENT;
- if (iUserType == 19)
- dbei.szUserId = szFromSkypename;
-
+ std::string strMessageType = node["messagetype"].as_string();
if (strMessageType == "RichText/Media_GenericFile") {
- ProcessFileRecv(hContact, T2Utf(wszContent), dbei);
- return;
+ ProcessFileRecv(dbei.hContact, node["content"].as_string().c_str(), dbei);
+ return false;
}
if (strMessageType == "RichText/Contacts") {
- ProcessContactRecv(hContact, T2Utf(wszContent), dbei);
- return;
+ ProcessContactRecv(dbei.hContact, node["content"].as_string().c_str(), dbei);
+ return false;
}
if (strMessageType == "Text" || strMessageType == "RichText") {
- if (IsMe(szFromSkypename)) {
- HANDLE hMessage = (HANDLE)atoi(szMessageId);
+ if ((dbei.flags & DBEF_SENT) && dbei.szId) {
+ HANDLE hMessage = (HANDLE)atoi(dbei.szId);
if (m_OutMessages.getIndex(hMessage) != -1) {
- ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, hMessage, (LPARAM)szMessageId.c_str());
+ ProtoBroadcastAck(dbei.hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, hMessage, (LPARAM)dbei.szId);
mir_cslock lck(m_lckOutMessagesList);
m_OutMessages.remove(hMessage);
- return;
+ return false;
}
}
- else CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_OFF);
+ else CallService(MS_PROTO_CONTACTISTYPING, dbei.hContact, PROTOTYPE_CONTACTTYPING_OFF);
if (strMessageType == "RichText")
wszContent = RemoveHtml(wszContent);
@@ -167,21 +130,62 @@ void CSkypeProto::ProcessNewMessage(const JSONNode &node) dbei.eventType = SKYPE_DB_EVENT_TYPE_MOJI;
}
else if (strMessageType == "RichText/Media_Album") {
- // do nothing
+ return false;
}
else {
dbei.eventType = SKYPE_DB_EVENT_TYPE_UNKNOWN;
}
- T2Utf szMsg(wszContent);
- dbei.pBlob = szMsg;
- dbei.cbBlob = (uint32_t)mir_strlen(szMsg);
+ replaceStr(dbei.pBlob, mir_utf8encodeW(wszContent));
+ dbei.cbBlob = (uint32_t)mir_strlen(dbei.pBlob);
+ return true;
+}
- if (dbei) {
- db_event_edit(dbei.getEvent(), &dbei, true);
- dbei.pBlob = nullptr;
+void CSkypeProto::ProcessNewMessage(const JSONNode &node)
+{
+ int iUserType;
+ UrlToSkypeId(node["conversationLink"].as_string().c_str(), &iUserType);
+
+ CMStringA szMessageId = node["clientmessageid"] ? node["clientmessageid"].as_mstring() : node["skypeeditedid"].as_mstring();
+ CMStringA szConversationName(UrlToSkypeId(node["conversationLink"].as_string().c_str()));
+ CMStringA szFromSkypename(UrlToSkypeId(node["from"].as_mstring()));
+
+ MCONTACT hContact = AddContact(szConversationName, nullptr, true);
+
+ time_t timestamp = time(0); // fuck the server time, we need to place events in the order of our local time
+ if (m_bHistorySynced)
+ setDword(hContact, "LastMsgTime", timestamp);
+
+ if (iUserType == 19)
+ if (OnChatEvent(node))
+ return;
+
+ std::string strMessageType = node["messagetype"].as_string();
+ if (strMessageType == "Control/Typing") {
+ CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_INFINITE);
+ return;
+ }
+ if (strMessageType == "Control/ClearTyping") {
+ CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_OFF);
+ return;
+ }
+
+ DB::EventInfo dbei(db_event_getById(m_szModuleName, szMessageId));
+ dbei.hContact = hContact;
+ dbei.timestamp = timestamp;
+ dbei.szId = szMessageId;
+ dbei.flags = DBEF_UTF;
+ if (IsMe(szFromSkypename))
+ dbei.flags |= DBEF_SENT;
+ if (iUserType == 19)
+ dbei.szUserId = szFromSkypename;
+
+ if (ParseMessage(node, dbei)) {
+ if (dbei)
+ db_event_edit(dbei.getEvent(), &dbei, true);
+ else
+ ProtoChainRecvMsg(hContact, dbei);
}
- else ProtoChainRecvMsg(hContact, dbei);
}
void CSkypeProto::OnMarkRead(MCONTACT hContact, MEVENT hDbEvent)
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 7a4da4ff38..1a4cccda18 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -276,7 +276,7 @@ private: SESSION_INFO* StartChatRoom(const wchar_t *tid, const wchar_t *tname);
- void OnChatEvent(const JSONNode &node);
+ bool OnChatEvent(const JSONNode &node);
wchar_t* GetChatContactNick(MCONTACT hContact, const wchar_t *id, const wchar_t *name = nullptr);
void AddChatContact(SESSION_INFO *si, const wchar_t *id, const wchar_t *role, bool isChange = false);
@@ -288,6 +288,7 @@ private: // polling
void __cdecl PollingThread(void*);
+ bool ParseMessage(const JSONNode &node, DB::EventInfo &dbei);
void ParsePollData(const char*);
void ProcessNewMessage(const JSONNode &node);
|