summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/VKontakte/src/misc.cpp28
-rw-r--r--protocols/VKontakte/src/vk_messages.cpp4
-rw-r--r--protocols/VKontakte/src/vk_pollserver.cpp4
-rw-r--r--protocols/VKontakte/src/vk_proto.h3
-rw-r--r--protocols/VKontakte/src/vk_struct.h4
5 files changed, 33 insertions, 10 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp
index 847250b6ef..d4af4c1a8c 100644
--- a/protocols/VKontakte/src/misc.cpp
+++ b/protocols/VKontakte/src/misc.cpp
@@ -1539,6 +1539,14 @@ void CVkProto::AddVkDeactivateEvent(MCONTACT hContact, CMStringW& wszType)
db_event_add(hContact, &dbei);
}
+
+MEVENT CVkProto::GetMessageFromDb(UINT iMsgId, UINT &timestamp, CMStringW &msg)
+{
+ char szMid[40];
+ _itoa(iMsgId, szMid, 10);
+ return GetMessageFromDb(szMid, timestamp, msg);
+}
+
MEVENT CVkProto::GetMessageFromDb(const char *messageId, UINT &timestamp, CMStringW &msg)
{
if (messageId == nullptr)
@@ -1566,10 +1574,22 @@ int CVkProto::DeleteContact(MCONTACT hContact)
return db_delete_contact(hContact);
}
-bool CVkProto::IsMessageExist(UINT MsgId)
+bool CVkProto::IsMessageExist(UINT iMsgId, VKMesType vkType)
{
char szMid[40];
- _itoa(MsgId, szMid, 10);
+ _itoa(iMsgId, szMid, 10);
+
+ MEVENT hDbEvent = db_event_getById(m_szModuleName, szMid);
- return (db_event_getById(m_szModuleName, szMid) != 0);
-} \ No newline at end of file
+ if (!hDbEvent)
+ return false;
+
+ if (vkType == vkALL)
+ return true;
+
+ DBEVENTINFO dbei = {};
+ if(db_event_get(hDbEvent, &dbei))
+ return false;
+
+ return ((vkType == vkOUT) == (bool)(dbei.flags & DBEF_SENT));
+}
diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp
index 453ed380e4..3da04a204a 100644
--- a/protocols/VKontakte/src/vk_messages.cpp
+++ b/protocols/VKontakte/src/vk_messages.cpp
@@ -327,7 +327,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
wszBody;
CMStringW wszOldMsg;
- MEVENT hDbEvent = GetMessageFromDb(szMid, datetime, wszOldMsg);
+ MEVENT hDbEvent = GetMessageFromDb(mid, datetime, wszOldMsg);
if (hDbEvent) {
wszBody += SetBBCString(TranslateT("\nOriginal message:\n"), m_vkOptions.BBCForAttachments(), vkbbcB) +
wszOldMsg;
@@ -343,7 +343,7 @@ 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 (!IsMessageExist(mid) || bEdited) {
+ if (!IsMessageExist(mid, vkOUT) || bEdited) {
debugLogA("CVkProto::OnReceiveMessages ProtoChainRecvMsg");
ProtoChainRecvMsg(hContact, &recv);
if (mid > getDword(hContact, "lastmsgid", -1))
diff --git a/protocols/VKontakte/src/vk_pollserver.cpp b/protocols/VKontakte/src/vk_pollserver.cpp
index b747e2055c..1f95f2954a 100644
--- a/protocols/VKontakte/src/vk_pollserver.cpp
+++ b/protocols/VKontakte/src/vk_pollserver.cpp
@@ -91,7 +91,7 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates)
uid = jnChild[3].as_int();
hContact = FindUser(uid);
- if (hContact != 0 && (flags & VKFLAG_MSGUNREAD) && !IsMessageExist(msgid)) {
+ if (hContact != 0 && (flags & VKFLAG_MSGUNREAD) && !IsMessageExist(msgid, vkIN)) {
setDword(hContact, "LastMsgReadTime", time(0));
if (ServiceExists(MS_MESSAGESTATE_UPDATE)) {
MessageReadData data(time(0), MRD_TYPE_READTIME);
@@ -117,7 +117,7 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates)
msgid = jnChild[1].as_int();
// skip outgoing messages sent from a client
flags = jnChild[2].as_int();
- if (flags & VKFLAG_MSGOUTBOX && !(flags & VKFLAG_MSGCHAT) && !m_vkOptions.bSendVKLinksAsAttachments && IsMessageExist(msgid))
+ if (flags & VKFLAG_MSGOUTBOX && !(flags & VKFLAG_MSGCHAT) && !m_vkOptions.bSendVKLinksAsAttachments && IsMessageExist(msgid, vkOUT))
break;
if (!mids.IsEmpty())
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index b8e8301f1c..8e3b2135e2 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -354,9 +354,10 @@ private:
void SetInvisible(MCONTACT hContact);
CMStringW RemoveBBC(CMStringW& wszSrc);
void AddVkDeactivateEvent(MCONTACT hContact, CMStringW & wszType);
+ MEVENT GetMessageFromDb(UINT iMsgId, UINT & timestamp, CMStringW & msg);
MEVENT GetMessageFromDb(const char * messageId, UINT &timestamp, CMStringW &msg);
int DeleteContact(MCONTACT hContact);
- bool IsMessageExist(UINT MsgId);
+ bool IsMessageExist(UINT iMsgId, VKMesType vkType = vkALL);
void InitQueue();
void UninitQueue();
void ExecuteRequest(AsyncHttpRequest*);
diff --git a/protocols/VKontakte/src/vk_struct.h b/protocols/VKontakte/src/vk_struct.h
index ad359cc992..00e24f5b90 100644
--- a/protocols/VKontakte/src/vk_struct.h
+++ b/protocols/VKontakte/src/vk_struct.h
@@ -343,4 +343,6 @@ struct CVKDeactivateEvent {
char *szDescription;
};
-enum VKContactType : BYTE { vkContactNormal, vkContactSelf, vkContactMUCUser }; \ No newline at end of file
+enum VKContactType : BYTE { vkContactNormal, vkContactSelf, vkContactMUCUser };
+enum VKMesType : BYTE { vkALL, vkIN, vkOUT };
+