summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/m_protosvc.h11
-rw-r--r--protocols/Discord/src/dispatch.cpp8
-rw-r--r--protocols/Discord/src/proto.cpp14
-rw-r--r--protocols/Discord/src/proto.h9
-rwxr-xr-xprotocols/JabberG/src/jabber_omemo.cpp4
-rwxr-xr-xprotocols/JabberG/src/jabber_proto.cpp11
-rwxr-xr-xprotocols/JabberG/src/jabber_proto.h2
-rwxr-xr-xprotocols/JabberG/src/jabber_thread.cpp3
-rw-r--r--protocols/SkypeWeb/src/skype_messages.cpp7
-rw-r--r--protocols/SkypeWeb/src/skype_proto.cpp2
-rw-r--r--protocols/VKontakte/src/vk_feed.cpp2
-rw-r--r--protocols/VKontakte/src/vk_history.cpp2
-rw-r--r--protocols/VKontakte/src/vk_messages.cpp13
-rw-r--r--protocols/VKontakte/src/vk_proto.cpp2
-rw-r--r--protocols/VKontakte/src/vk_proto.h1
-rw-r--r--src/mir_app/src/proto_utils.cpp14
16 files changed, 42 insertions, 63 deletions
diff --git a/include/m_protosvc.h b/include/m_protosvc.h
index 2cfe9c4b21..4d5b0c5de4 100644
--- a/include/m_protosvc.h
+++ b/include/m_protosvc.h
@@ -149,6 +149,7 @@ static __inline unsigned long Proto_Status2Flag(int status)
#define PF4_GROUPCHATFILES 0x00000800 // protocol supports sending files to group chats
#define PF4_SINGLEFILEONLY 0x00001000 // protocol supports sending files one by one only
#define PF4_READNOTIFY 0x00002000 // protocol supports receiving notify of message reading
+#define PF4_SERVERMSGID 0x00004000 // protocol uses server message ids
#define PFLAG_UNIQUEIDTEXT 100 // returns a static buffer of text describing the unique field by which this protocol identifies users (already translated), or NULL
#define PFLAG_MAXCONTACTSPERPACKET 200 // returns the maximum number of contacts which can be sent in a single PSS_CONTACTS, lParam = (LPARAM)hContact.
@@ -770,10 +771,12 @@ struct PROTOFILERESUME
struct PROTORECVEVENT
{
- DWORD flags;
- DWORD timestamp; // unix time
- char *szMessage; // message body in utf8
- LPARAM lParam; // extra space for the network level protocol module
+ DWORD flags;
+ DWORD timestamp; // unix time
+ char *szMessage; // message body in utf8
+ LPARAM lParam; // extra space for the network level protocol module
+ const char *szMsgId; // server message id, optional, should be NULL otherwise
+ // ignored for protocols without PF4_SERVERMSGID in GetCaps()
};
#define PREF_CREATEREAD 1 // create the database event with the 'read' flag set
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");
}
@@ -351,18 +351,6 @@ MCONTACT CDiscordProto::AddToList(int flags, PROTOSEARCHRESULT *psr)
}
////////////////////////////////////////////////////////////////////////////////////////
-// 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
void __cdecl CDiscordProto::SendMessageAckThread(void *param)
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
@@ -805,17 +805,6 @@ HANDLE CJabberProto::SearchByName(const wchar_t *nick, const wchar_t *firstName,
}
////////////////////////////////////////////////////////////////////////////////////////
-// 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
int CJabberProto::SendContacts(MCONTACT hContact, int, int nContacts, MCONTACT *hContactsList)
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<CJabberProto>, 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 <http://www.gnu.org/licenses/>.
#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<CVkProto>
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;
diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp
index a09fb63ec6..a82f92eb78 100644
--- a/src/mir_app/src/proto_utils.cpp
+++ b/src/mir_app/src/proto_utils.cpp
@@ -514,6 +514,20 @@ MEVENT PROTO_INTERFACE::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre)
if (pre->flags & PREF_SENT)
dbei.flags |= DBEF_SENT;
+ // if it's possible to find an existing event by its id, do that
+ if ((GetCaps(PFLAGNUM_4) & PF4_SERVERMSGID) && pre->szMsgId != nullptr) {
+ MEVENT hDbEvent = db_event_getById(m_szModuleName, pre->szMsgId);
+ if (hDbEvent == 0) {
+ hDbEvent = db_event_add(hContact, &dbei);
+ if (hDbEvent)
+ db_event_setId(m_szModuleName, hDbEvent, pre->szMsgId);
+ }
+ else db_event_edit(hContact, hDbEvent, &dbei);
+
+ return hDbEvent;
+ }
+
+ // event is new? add it
return (INT_PTR)db_event_add(hContact, &dbei);
}