From 1ad3f46ba54b0b2e57e4ab3ec66acf6da73cdde4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 1 Feb 2019 16:57:32 +0300 Subject: fixes #1777 (SkypeWeb duplicates already received incoming messages) --- protocols/SkypeWeb/src/skype_db.cpp | 45 ++++++--------------------- protocols/SkypeWeb/src/skype_history_sync.cpp | 9 +++--- protocols/SkypeWeb/src/skype_messages.cpp | 10 +++--- protocols/SkypeWeb/src/skype_proto.cpp | 2 +- protocols/SkypeWeb/src/skype_proto.h | 9 ++---- protocols/SkypeWeb/src/version.h | 4 +-- 6 files changed, 23 insertions(+), 56 deletions(-) (limited to 'protocols') diff --git a/protocols/SkypeWeb/src/skype_db.cpp b/protocols/SkypeWeb/src/skype_db.cpp index 0b7bfb2ac8..e627d76423 100644 --- a/protocols/SkypeWeb/src/skype_db.cpp +++ b/protocols/SkypeWeb/src/skype_db.cpp @@ -30,49 +30,23 @@ struct SkypeDBType { int type; char *name; DWORD flags; } g_SkypeDBTypes[] = { SKYPE_DB_EVENT_TYPE_UNKNOWN, LPGEN("Unknown event"), 0 }, }; -MEVENT CSkypeProto::GetMessageFromDb(MCONTACT hContact, const char *messageId, LONGLONG timestamp) +MEVENT CSkypeProto::GetMessageFromDb(const char *messageId) { if (messageId == nullptr) return NULL; - timestamp -= 600; // we check events written 10 minutes ago - size_t messageIdLength = mir_strlen(messageId); - - mir_cslock lock(messageSyncLock); - for (MEVENT hDbEvent = db_event_last(hContact); hDbEvent; hDbEvent = db_event_prev(hContact, hDbEvent)) { - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - - if (dbei.cbBlob < messageIdLength) - continue; - - mir_ptr blob((PBYTE)mir_alloc(dbei.cbBlob)); - dbei.pBlob = blob; - db_event_get(hDbEvent, &dbei); - - size_t cbLen = mir_strlen((char*)dbei.pBlob); - if (memcmp(&dbei.pBlob[cbLen + 1], messageId, messageIdLength) == 0) - return hDbEvent; - - if (dbei.timestamp < timestamp) - break; - } - - return NULL; + return db_event_getById(m_szModuleName, messageId); } MEVENT CSkypeProto::AddDbEvent(WORD type, MCONTACT hContact, DWORD timestamp, DWORD flags, const char *content, const char *uid) { - if (MEVENT hDbEvent = GetMessageFromDb(hContact, uid, timestamp)) + if (MEVENT hDbEvent = GetMessageFromDb(uid)) return hDbEvent; - size_t messageLength = mir_strlen(content) + 1; - size_t messageIdLength = mir_strlen(uid); - size_t cbBlob = messageLength + messageIdLength; - PBYTE pBlob = (PBYTE)mir_alloc(cbBlob); - memcpy(pBlob, content, messageLength); - memcpy(pBlob + messageLength, uid, messageIdLength); - - return AddEventToDb(hContact, type, timestamp, flags, (DWORD)cbBlob, pBlob); + + MEVENT ret = AddEventToDb(hContact, type, timestamp, flags, (DWORD)mir_strlen(content), (BYTE*)content); + if (uid && ret) + db_event_setId(m_szModuleName, ret, uid); + return ret; } MEVENT CSkypeProto::AppendDBEvent(MCONTACT hContact, MEVENT hEvent, const char *szContent, const char *szUid, time_t edit_time) @@ -120,9 +94,8 @@ MEVENT CSkypeProto::AppendDBEvent(MCONTACT hContact, MEVENT hEvent, const char * jEdits << jEdit; jMsg << jEdits; - - } + db_event_delete(hContact, hEvent); return AddDbEvent(SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE, hContact, dbei.timestamp, dbei.flags, jMsg.write().c_str(), szUid); } diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index 429c445603..643114156a 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -70,12 +70,11 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) 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) { + MEVENT dbevent = GetMessageFromDb(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 + 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); diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 7adc815f46..0c6744c35f 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -172,7 +172,7 @@ void CSkypeProto::OnPrivateMessageEvent(const JSONNode &node) if (it == m_mpOutMessages.end()) { m_mpOutMessages[hMessage] = timestamp; } - ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, hMessage, 0); + ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, hMessage, (LPARAM)szMessageId.c_str()); { mir_cslock lck(m_lckOutMessagesList); m_OutMessages.remove(hMessage); @@ -185,14 +185,12 @@ void CSkypeProto::OnPrivateMessageEvent(const JSONNode &node) } else { CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_OFF); - MEVENT hDbEvent = GetMessageFromDb(hContact, szMessageId); - if (bEdited && hDbEvent != NULL) { + MEVENT hDbEvent = GetMessageFromDb(szMessageId); + if (bEdited && hDbEvent != NULL) AppendDBEvent(hContact, hDbEvent, szClearedContent, szMessageId, timestamp); - } - else { + else OnReceiveMessage(hContact, szClearedContent, szMessageId, timestamp, nEmoteOffset); - } } } else if (strMessageType == "Event/Call") { diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 88b658dd20..d83f0fc133 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -325,7 +325,7 @@ int CSkypeProto::RecvContacts(MCONTACT hContact, PROTORECVEVENT* pre) pCurBlob += mir_strlen((char*)pCurBlob) + 1; } - //memcpy(pCurBlob + 1, szMessageId, mir_strlen(szMessageId)); + // memcpy(pCurBlob + 1, szMessageId, mir_strlen(szMessageId)); AddEventToDb(hContact, EVENTTYPE_CONTACTS, pre->timestamp, (pre->flags & PREF_CREATEREAD) ? DBEF_READ : 0, cbBlob, pBlob); diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 42ed652b25..6137f1c399 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -169,8 +169,6 @@ private: INT_PTR __cdecl SvcGetMyAvatar(WPARAM, LPARAM); INT_PTR __cdecl SvcSetMyAvatar(WPARAM, LPARAM); - int InternalSetAvatar(MCONTACT hContact, const char *szJid, const wchar_t *ptszFileName); - // requests void InitNetwork(); @@ -293,7 +291,7 @@ private: std::map m_mpOutMessagesIds; - MEVENT GetMessageFromDb(MCONTACT hContact, const char *messageId, LONGLONG timestamp = 0); + MEVENT GetMessageFromDb(const char *messageId); MEVENT AddDbEvent(WORD type, MCONTACT hContact, DWORD timestamp, DWORD flags, const char *content, const char *uid); MEVENT AppendDBEvent(MCONTACT hContact, MEVENT hEvent, const char *szContent, const char *szUid, time_t edit_time); int OnReceiveMessage(MCONTACT hContact, const char *szContent, const char *szMessageId, time_t timestamp, int emoteOffset = 0, bool isRead = false); @@ -329,12 +327,12 @@ private: void OnChatEvent(const JSONNode &node); void OnSendChatMessage(const wchar_t *chat_id, const wchar_t * tszMessage); - char *GetChatUsers(const wchar_t *chat_id); + char* GetChatUsers(const wchar_t *chat_id); bool IsChatContact(const wchar_t *chat_id, const char *id); void AddMessageToChat(const wchar_t *chat_id, const wchar_t *from, const char *content, bool isAction, int emoteOffset, time_t timestamp, bool isLoading = false); void AddChatContact(const wchar_t *tchat_id, const char *id, const char *name, const wchar_t *role, bool isChange = false); void RemoveChatContact(const wchar_t *tchat_id, const char *id, const char *name, bool isKick = false, const char *initiator = ""); - wchar_t *GetChatContactNick(const char *chat_id, const char *id, const char *name); + wchar_t* GetChatContactNick(const char *chat_id, const char *id, const char *name); void RenameChat(const char *chat_id, const char *name); void ChangeChatTopic(const char * chat_id, const char *topic, const char *initiator); @@ -392,7 +390,6 @@ private: static void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD); //---/ - time_t GetLastMessageTime(MCONTACT hContact); CMStringW RunConfirmationCode(); CMStringW ChangeTopicForm(); void CloseDialogs(); diff --git a/protocols/SkypeWeb/src/version.h b/protocols/SkypeWeb/src/version.h index 05569a99e7..351d653f24 100644 --- a/protocols/SkypeWeb/src/version.h +++ b/protocols/SkypeWeb/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 12 -#define __RELEASE_NUM 2 -#define __BUILD_NUM 5 +#define __RELEASE_NUM 3 +#define __BUILD_NUM 1 #include -- cgit v1.2.3