From 7a3cc797437ff18ec801978a7606db347345cb34 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 11 Jan 2014 22:04:51 +0000 Subject: - fixed chat messages duping - chat messages are marked read git-svn-id: http://svn.miranda-ng.org/main/trunk@7610 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/vk_chats.cpp | 7 ++++--- protocols/VKontakte/src/vk_proto.h | 2 ++ protocols/VKontakte/src/vk_thread.cpp | 15 +++++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'protocols/VKontakte') diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index a604e9bda9..0df57d6856 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -243,12 +243,13 @@ void CVkProto::AppendChatMessage(int id, JSONNODE *pMsg, bool bIsHistory) if (cc->m_bHistoryRead) AppendChatMessage(cc, uid, msgTime, tszBody, bIsHistory); else { - CVkChatMessage *cm = new CVkChatMessage(); - cm->m_mid = mid; + CVkChatMessage *cm = cc->m_msgs.find((CVkChatMessage *)&mid); + if (cm == NULL) + cc->m_msgs.insert(cm = new CVkChatMessage(mid)); + cm->m_uid = uid; cm->m_date = msgTime; cm->m_tszBody = tszBody.detouch(); - cc->m_msgs.insert(cm); } } diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index a98ad33681..50fb47cef6 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -35,6 +35,8 @@ struct AsyncHttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject struct CVkChatMessage : public MZeroedObject { + CVkChatMessage(int _id) : m_mid(_id) {} + int m_mid, m_uid, m_date; ptrT m_tszBody; }; diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 1effedd0db..eb24d1b226 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -432,16 +432,19 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (pMsg == NULL) continue; + char szMid[40]; + int mid = json_as_int(json_get(pMsg, "mid")); + _itoa(mid, szMid, 10); + if (!mids.IsEmpty()) + mids.AppendChar(','); + mids.Append(szMid); + int chat_id = json_as_int(json_get(pMsg, "chat_id")); if (chat_id != 0) { AppendChatMessage(chat_id, pMsg, false); continue; } - char szMid[40]; - int mid = json_as_int(json_get(pMsg, "mid")); - _itoa(mid, szMid, 10); - // VK documentation lies: even if you specified preview_length=0, // long messages get cut out. So we need to retrieve them from scratch ptrT ptszBody( json_as_string( json_get(pMsg, "body"))); @@ -475,10 +478,6 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe recv.pCustomData = szMid; recv.cbCustomDataSize = (int)strlen(szMid); ProtoChainRecvMsg(hContact, &recv); - - if (!mids.IsEmpty()) - mids.AppendChar(','); - mids.Append(szMid); } MarkMessagesRead(mids); -- cgit v1.2.3