diff options
author | ElzorFox <elzorfox@ya.ru> | 2018-09-21 23:27:02 +0500 |
---|---|---|
committer | ElzorFox <elzorfox@ya.ru> | 2018-09-21 23:27:17 +0500 |
commit | dfc40eb5c9d357c7cd5e8cb0e9e6f2173b4935ef (patch) | |
tree | 6b19efd113451ed462e09291b15c201d3683fea0 /protocols/VKontakte | |
parent | a2245d6446c46b5701190e957f56a42f038eea88 (diff) |
VKontakte: crutch for prevention of duplicate messages removed
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r-- | protocols/VKontakte/src/misc.cpp | 8 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_messages.cpp | 28 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_pollserver.cpp | 19 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 3 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 6 |
5 files changed, 26 insertions, 38 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 34b3f17614..847250b6ef 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -1565,3 +1565,11 @@ int CVkProto::DeleteContact(MCONTACT hContact) setByte(hContact, "SilentDelete", 1);
return db_delete_contact(hContact);
}
+
+bool CVkProto::IsMessageExist(UINT MsgId)
+{
+ char szMid[40];
+ _itoa(MsgId, szMid, 10);
+
+ return (db_event_getById(m_szModuleName, szMid) != 0);
+}
\ No newline at end of file diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp index 6e9772bb4d..453ed380e4 100644 --- a/protocols/VKontakte/src/vk_messages.cpp +++ b/protocols/VKontakte/src/vk_messages.cpp @@ -121,9 +121,6 @@ void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) mid = 0;
}
- if (param->iMsgID != -1)
- m_sendIds.insert((HANDLE)mid);
-
if (mid > getDword(param->hContact, "lastmsgid"))
setDword(param->hContact, "lastmsgid", mid);
@@ -315,22 +312,17 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe else if (m_vkOptions.bUserForceInvisibleOnActivity && time(0) - datetime < 60 * m_vkOptions.iInvisibleInterval)
SetInvisible(hContact);
- bool bEdited = CheckMid(m_editedIds, mid);
- if (bEdited) {
- time_t update_time = (time_t)jnMsg["update_time"].as_int();
- CMStringW wszEditTime;
-
- if (update_time) {
- wchar_t ttime[64];
- _locale_t locale = _create_locale(LC_ALL, "");
- _wcsftime_l(ttime, _countof(ttime), TranslateT("%x at %X"), localtime(&update_time), locale);
- _free_locale(locale);
+ time_t update_time = (time_t)jnMsg["update_time"].as_int();
+ bool bEdited = (update_time != 0);
- wszEditTime.Format(TranslateT("Edited message (updated %s):\n"), ttime);
- }
+ if (bEdited) {
+ wchar_t ttime[64];
+ _locale_t locale = _create_locale(LC_ALL, "");
+ _wcsftime_l(ttime, _countof(ttime), TranslateT("%x at %X"), localtime(&update_time), locale);
+ _free_locale(locale);
wszBody = SetBBCString(
- wszEditTime.IsEmpty() ? TranslateT("Edited message:\n") : wszEditTime,
+ CMStringW(FORMAT, TranslateT("Edited message (updated %s):\n"), ttime),
m_vkOptions.BBCForAttachments(), vkbbcB) +
wszBody;
@@ -351,13 +343,11 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe debugLogA("CVkProto::OnReceiveMessages mid = %d, datetime = %d, isOut = %d, isRead = %d, uid = %d", mid, datetime, isOut, isRead, uid);
- if (!CheckMid(m_sendIds, mid)) {
+ if (!IsMessageExist(mid) || bEdited) {
debugLogA("CVkProto::OnReceiveMessages ProtoChainRecvMsg");
ProtoChainRecvMsg(hContact, &recv);
if (mid > getDword(hContact, "lastmsgid", -1))
setDword(hContact, "lastmsgid", mid);
- if (!isOut)
- m_incIds.insert((HANDLE)mid);
}
else if (m_vkOptions.bLoadSentAttachments && !wszAttachmentDescr.IsEmpty() && isOut) {
T2Utf pszAttach(wszAttachmentDescr);
diff --git a/protocols/VKontakte/src/vk_pollserver.cpp b/protocols/VKontakte/src/vk_pollserver.cpp index 735d7c1eb7..b747e2055c 100644 --- a/protocols/VKontakte/src/vk_pollserver.cpp +++ b/protocols/VKontakte/src/vk_pollserver.cpp @@ -78,7 +78,6 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates) debugLogA("CVkProto::PollUpdates");
CMStringA mids;
int msgid, uid, flags, platform;
- bool bNonEdited = true;
MCONTACT hContact;
for (auto &it : jnUpdates) {
@@ -92,7 +91,7 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates) uid = jnChild[3].as_int();
hContact = FindUser(uid);
- if (hContact != 0 && (flags & VKFLAG_MSGUNREAD) && !CheckMid(m_incIds, msgid)) {
+ if (hContact != 0 && (flags & VKFLAG_MSGUNREAD) && !IsMessageExist(msgid)) {
setDword(hContact, "LastMsgReadTime", time(0));
if (ServiceExists(MS_MESSAGESTATE_UPDATE)) {
MessageReadData data(time(0), MRD_TYPE_READTIME);
@@ -108,24 +107,22 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates) break;
case VKPOLL_MSG_EDITED:
- bNonEdited = false;
+ msgid = jnChild[1].as_int();
+ if (!mids.IsEmpty())
+ mids.AppendChar(',');
+ mids.AppendFormat("%d", msgid);
+ break;
case VKPOLL_MSG_ADDED: // new message
msgid = jnChild[1].as_int();
-
- // skip outgoing messages sent from a client
+ // skip outgoing messages sent from a client
flags = jnChild[2].as_int();
- if (bNonEdited && (flags & VKFLAG_MSGOUTBOX && !(flags & VKFLAG_MSGCHAT) && !m_vkOptions.bSendVKLinksAsAttachments && CheckMid(m_sendIds, msgid)))
+ if (flags & VKFLAG_MSGOUTBOX && !(flags & VKFLAG_MSGCHAT) && !m_vkOptions.bSendVKLinksAsAttachments && IsMessageExist(msgid))
break;
if (!mids.IsEmpty())
mids.AppendChar(',');
mids.AppendFormat("%d", msgid);
-
- if(!bNonEdited)
- m_editedIds.insert((HANDLE)msgid);
-
- bNonEdited = true;
break;
case VKPOLL_READ_ALL_OUT:
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 52b4f69bc6..0ffebbc529 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -29,9 +29,6 @@ mir_cs csInstances; CVkProto::CVkProto(const char *szModuleName, const wchar_t *pwszUserName) :
PROTO<CVkProto>(szModuleName, pwszUserName),
m_arRequestsQueue(10, sttCompareAsyncHttpRequest),
- m_sendIds(3, PtrKeySortT),
- m_editedIds(1, PtrKeySortT),
- m_incIds(3, PtrKeySortT),
m_cookies(5),
m_msgId(1),
m_chats(1, NumericKeySortT),
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index a81a509b4a..b8e8301f1c 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -210,11 +210,6 @@ private: int m_iLoadHistoryTask;
- LIST<void>
- m_sendIds,
- m_editedIds,
- m_incIds;
-
OBJLIST<CVkChatInfo> m_chats;
OBJLIST<CVKChatContactTypingParam> m_ChatsTyping;
OBJLIST<CVkCookie> m_cookies;
@@ -361,6 +356,7 @@ private: void AddVkDeactivateEvent(MCONTACT hContact, CMStringW & wszType);
MEVENT GetMessageFromDb(const char * messageId, UINT ×tamp, CMStringW &msg);
int DeleteContact(MCONTACT hContact);
+ bool IsMessageExist(UINT MsgId);
void InitQueue();
void UninitQueue();
void ExecuteRequest(AsyncHttpRequest*);
|