From e808179197e8875f3faa85ad8f0d1e75d756716f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 1 Oct 2018 15:36:26 +0300 Subject: centralized system of processing message ids. also fixes #1375 --- protocols/Discord/src/dispatch.cpp | 8 ++++++-- protocols/Discord/src/proto.cpp | 14 +------------- protocols/Discord/src/proto.h | 9 ++++----- protocols/JabberG/src/jabber_omemo.cpp | 4 +--- protocols/JabberG/src/jabber_proto.cpp | 11 ----------- protocols/JabberG/src/jabber_proto.h | 2 -- protocols/JabberG/src/jabber_thread.cpp | 3 +-- protocols/SkypeWeb/src/skype_messages.cpp | 7 ++----- protocols/SkypeWeb/src/skype_proto.cpp | 2 +- protocols/VKontakte/src/vk_feed.cpp | 2 +- protocols/VKontakte/src/vk_history.cpp | 2 +- protocols/VKontakte/src/vk_messages.cpp | 13 ++----------- protocols/VKontakte/src/vk_proto.cpp | 2 +- protocols/VKontakte/src/vk_proto.h | 1 - 14 files changed, 21 insertions(+), 59 deletions(-) (limited to 'protocols') diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 2ee6930721..dbb30f382c 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -316,7 +316,8 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot) CMStringW wszMessageId = pRoot["id"].as_mstring(); CMStringW wszUserId = pRoot["author"]["id"].as_mstring(); SnowFlake userId = _wtoi64(wszUserId); - CDiscordMessage msg(_wtoi64(wszMessageId), userId); + SnowFlake msgId = _wtoi64(wszMessageId); + CDiscordMessage msg(msgId, userId); // try to find a sender by his channel SnowFlake channelId = ::getId(pRoot["channel_id"]); @@ -350,9 +351,12 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot) debugLogA("store a message from private user %lld, channel id %lld", pUser->id, pUser->channelId); ptrA buf(mir_utf8encodeW(wszText)); + char szMsgId[100]; + _i64toa_s(msgId, szMsgId, _countof(szMsgId), 10); + recv.timestamp = (DWORD)StringToDate(pRoot["timestamp"].as_mstring()); recv.szMessage = buf; - recv.lParam = (LPARAM)wszMessageId.c_str(); + recv.szMsgId = szMsgId; ProtoChainRecvMsg(pUser->hContact, &recv); } else { diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 386f9c8844..574bd2be53 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -145,7 +145,7 @@ INT_PTR CDiscordProto::GetCaps(int type, MCONTACT) case PFLAGNUM_3: return PF2_ONLINE | PF2_LONGAWAY | PF2_HEAVYDND | PF2_INVISIBLE; case PFLAGNUM_4: - return PF4_FORCEADDED | PF4_FORCEAUTH | PF4_NOCUSTOMAUTH | PF4_NOAUTHDENYREASON | PF4_SUPPORTTYPING | PF4_SUPPORTIDLE | PF4_AVATARS | PF4_IMSENDOFFLINE; + return PF4_FORCEADDED | PF4_FORCEAUTH | PF4_NOCUSTOMAUTH | PF4_NOAUTHDENYREASON | PF4_SUPPORTTYPING | PF4_SUPPORTIDLE | PF4_AVATARS | PF4_IMSENDOFFLINE | PF4_SERVERMSGID; case PFLAG_UNIQUEIDTEXT: return (INT_PTR)Translate("User ID"); } @@ -350,18 +350,6 @@ MCONTACT CDiscordProto::AddToList(int flags, PROTOSEARCHRESULT *psr) return hContact; } -//////////////////////////////////////////////////////////////////////////////////////// -// RecvMsg - -MEVENT CDiscordProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *evt) -{ - MEVENT hDbEvent = CSuper::RecvMsg(hContact, evt); - if (hDbEvent && evt->lParam) - db_event_setId(m_szModuleName, hDbEvent, T2Utf((const wchar_t*)evt->lParam)); - - return hDbEvent; -} - //////////////////////////////////////////////////////////////////////////////////////// // SendMsg diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 878b054e6f..7874a8ffb6 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -265,16 +265,15 @@ public: HWND CreateExtendedSearchUI(HWND owner) override; HWND SearchAdvanced(HWND owner) override; - HANDLE SearchBasic(const wchar_t* id) override; - MCONTACT AddToList(int flags, PROTOSEARCHRESULT* psr) override; + HANDLE SearchBasic(const wchar_t *id) override; + MCONTACT AddToList(int flags, PROTOSEARCHRESULT *psr) override; - int AuthRecv(MCONTACT, PROTORECVEVENT* pre) override; + int AuthRecv(MCONTACT, PROTORECVEVENT *pre) override; int Authorize(MEVENT hDbEvent) override; int AuthDeny(MEVENT hDbEvent, const wchar_t* szReason) override; int AuthRequest(MCONTACT hContact, const wchar_t*) override; - MEVENT RecvMsg(MCONTACT hContact, PROTORECVEVENT *evt) override; - int SendMsg(MCONTACT hContact, int flags, const char* pszSrc) override; + int SendMsg(MCONTACT hContact, int flags, const char *pszSrc) override; HANDLE SendFile(MCONTACT hContact, const wchar_t *szDescription, wchar_t **ppszFiles) override; diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp index f52b0340fc..186cd5c2e9 100755 --- a/protocols/JabberG/src/jabber_omemo.cpp +++ b/protocols/JabberG/src/jabber_omemo.cpp @@ -1875,11 +1875,9 @@ bool CJabberProto::OmemoHandleMessage(HXML node, wchar_t *jid, time_t msgTime) if (m_bFixIncorrectTimestamps && (msgTime > now || (msgTime < (time_t)JabberGetLastContactMessageTime(hContact)))) msgTime = now; - pResourceStatus pFromResource(ResourceInfoFromJID(jid)); - PROTORECVEVENT recv = { 0 }; + PROTORECVEVENT recv = {}; recv.timestamp = (DWORD)msgTime; recv.szMessage = mir_strdup(out); - recv.lParam = (LPARAM)((pFromResource != nullptr && m_bEnableRemoteControl) ? pFromResource->m_tszResourceName : 0); ProtoChainRecvMsg(hContact, &recv); mir_free(out); return true; diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 48575d97d9..7a29dc6e91 100755 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -804,17 +804,6 @@ HANDLE CJabberProto::SearchByName(const wchar_t *nick, const wchar_t *firstName, return (HANDLE)pInfo->GetIqId(); } -//////////////////////////////////////////////////////////////////////////////////////// -// RecvMsg - -MEVENT CJabberProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *evt) -{ - MEVENT hDbEvent = CSuper::RecvMsg(hContact, evt); - if (hDbEvent != 0 && evt->lParam) - db_event_setId(m_szModuleName, hDbEvent, T2Utf((const wchar_t *)evt->lParam)); - return hDbEvent; -} - //////////////////////////////////////////////////////////////////////////////////////// // SendContacts diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 6bd4a2d6da..38ba232fbc 100755 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -96,8 +96,6 @@ struct CJabberProto : public PROTO, public IJabberInterface HWND SearchAdvanced(HWND owner) override; HWND CreateExtendedSearchUI(HWND owner) override; - MEVENT RecvMsg(MCONTACT hContact, PROTORECVEVENT*) override; - int SendContacts(MCONTACT hContact, int flags, int nContacts, MCONTACT *hContactsList) override; HANDLE SendFile(MCONTACT hContact, const wchar_t *szDescription, wchar_t **ppszFiles) override; int SendMsg(MCONTACT hContact, int flags, const char *msg) override; diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 6ad324838b..3246229ff4 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -1496,7 +1496,7 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info) if (m_bFixIncorrectTimestamps && (msgTime > now || (msgTime < (time_t)JabberGetLastContactMessageTime(hContact)))) msgTime = now; - PROTORECVEVENT recv = { 0 }; + PROTORECVEVENT recv = {}; if (carbon) { recv.flags |= PREF_CREATEREAD; if (carbonSent) @@ -1504,7 +1504,6 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info) } recv.timestamp = (DWORD)msgTime; recv.szMessage = buf; - recv.lParam = (LPARAM)((pFromResource != nullptr && m_bEnableRemoteControl) ? pFromResource->m_tszResourceName : 0); ProtoChainRecvMsg(hContact, &recv); } diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 7daad29062..09f123f0c4 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -26,14 +26,11 @@ int CSkypeProto::OnReceiveMessage(MCONTACT hContact, const char *szContent, cons recv.timestamp = timestamp; recv.szMessage = mir_strdup(szContent); recv.lParam = emoteOffset; + recv.szMsgId = szMessageId; if (isRead) recv.flags |= PREF_CREATEREAD; - MEVENT hDbEvent = ProtoChainRecvMsg(hContact, &recv); - if (hDbEvent) - db_event_setId(m_szModuleName, hDbEvent, szMessageId); - - return hDbEvent; + return ProtoChainRecvMsg(hContact, &recv); } /* MESSAGE SENDING */ diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index d0c2cdb495..fde09f0757 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -116,7 +116,7 @@ INT_PTR CSkypeProto::GetCaps(int type, MCONTACT) case PFLAGNUM_3: return PF2_ONLINE | PF2_INVISIBLE | PF2_SHORTAWAY | PF2_HEAVYDND; case PFLAGNUM_4: - return PF4_FORCEADDED | PF4_NOAUTHDENYREASON | PF4_SUPPORTTYPING | PF4_AVATARS | PF4_IMSENDOFFLINE | PF4_OFFLINEFILES; + return PF4_FORCEADDED | PF4_NOAUTHDENYREASON | PF4_SUPPORTTYPING | PF4_AVATARS | PF4_IMSENDOFFLINE | PF4_OFFLINEFILES | PF4_SERVERMSGID; case PFLAG_UNIQUEIDTEXT: return (INT_PTR)Translate("Skypename"); } diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp index 5d1715779a..82f488f5af 100644 --- a/protocols/VKontakte/src/vk_feed.cpp +++ b/protocols/VKontakte/src/vk_feed.cpp @@ -54,7 +54,7 @@ void CVkProto::AddFeedEvent(CVKNewsItem& vkNewsItem) MCONTACT hContact = FindUser(VK_FEED_USER, true); T2Utf pszBody(vkNewsItem.wszText); - PROTORECVEVENT recv = { 0 }; + PROTORECVEVENT recv = {}; recv.timestamp = vkNewsItem.tDate; recv.szMessage = pszBody; diff --git a/protocols/VKontakte/src/vk_history.cpp b/protocols/VKontakte/src/vk_history.cpp index 9db577a853..dab77003d9 100644 --- a/protocols/VKontakte/src/vk_history.cpp +++ b/protocols/VKontakte/src/vk_history.cpp @@ -292,7 +292,7 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque recv.timestamp = datetime; recv.szMessage = pszBody; - recv.lParam = (LPARAM)szMid; + recv.szMsgId = szMid; ProtoChainRecvMsg(hContact, &recv); if (isRead && isOut && datetime > tLastReadMessageTime) diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp index d04f907043..4dcf1e2346 100644 --- a/protocols/VKontakte/src/vk_messages.cpp +++ b/protocols/VKontakte/src/vk_messages.cpp @@ -17,15 +17,6 @@ along with this program. If not, see . #include "stdafx.h" -MEVENT CVkProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *evt) -{ - MEVENT hDbEvent = CSuper::RecvMsg(hContact, evt); - if (hDbEvent && evt->lParam) - db_event_setId(m_szModuleName, hDbEvent, (char*)evt->lParam); - - return hDbEvent; -} - ////////////////////////////////////////////////////////////////////////////// void CVkProto::SendMsgAck(void *param) @@ -342,7 +333,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe } } - PROTORECVEVENT recv = { 0 }; + PROTORECVEVENT recv = {}; if (isRead && bUseServerReadFlag) recv.flags |= PREF_CREATEREAD; @@ -360,7 +351,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (!IsMessageExist(mid, vkOUT) || bEdited) { debugLogA("CVkProto::OnReceiveMessages ProtoChainRecvMsg"); - recv.lParam = (LPARAM)szMid; + recv.szMsgId = szMid; ProtoChainRecvMsg(hContact, &recv); if (mid > getDword(hContact, "lastmsgid", -1)) setDword(hContact, "lastmsgid", mid); diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 0ffebbc529..eda0ad160b 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -498,7 +498,7 @@ INT_PTR CVkProto::GetCaps(int type, MCONTACT) case PFLAGNUM_4: return PF4_AVATARS | PF4_SUPPORTTYPING | PF4_NOAUTHDENYREASON | PF4_IMSENDOFFLINE - | PF4_OFFLINEFILES | PF4_READNOTIFY | PF4_GROUPCHATFILES; + | PF4_OFFLINEFILES | PF4_READNOTIFY | PF4_GROUPCHATFILES | PF4_SERVERMSGID; case PFLAGNUM_5: return PF2_ONTHEPHONE; diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index f0ee1549df..841d2a5f78 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -61,7 +61,6 @@ struct CVkProto : public PROTO HANDLE SearchBasic(const wchar_t *id) override; HANDLE SearchByEmail(const wchar_t *email) override; HANDLE SearchByName(const wchar_t *nick, const wchar_t *firstName, const wchar_t *lastName) override; - MEVENT RecvMsg(MCONTACT hContact, PROTORECVEVENT*) override; int SendMsg(MCONTACT hContact, int flags, const char *msg) override; HANDLE SendFile(MCONTACT hContact, const wchar_t *szDescription, wchar_t **ppszFiles) override; int SetStatus(int iNewStatus) override; -- cgit v1.2.3