diff options
Diffstat (limited to 'protocols/VKontakte/src/misc.cpp')
-rw-r--r-- | protocols/VKontakte/src/misc.cpp | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 1b32b50932..34b3f17614 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -1539,39 +1539,25 @@ void CVkProto::AddVkDeactivateEvent(MCONTACT hContact, CMStringW& wszType) db_event_add(hContact, &dbei);
}
-MEVENT CVkProto::GetMessageFromDb(MCONTACT hContact, const char *messageId, UINT ×tamp, CMStringW &msg)
+MEVENT CVkProto::GetMessageFromDb(const char *messageId, UINT ×tamp, CMStringW &msg)
{
if (messageId == nullptr)
return 0;
- size_t messageIdLength = mir_strlen(messageId);
-
- 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<BYTE> blob((PBYTE)mir_alloc(dbei.cbBlob));
- dbei.pBlob = blob;
- db_event_get(hDbEvent, &dbei);
-
- size_t cbLen = mir_strlen((char*)dbei.pBlob);
- if ((dbei.eventType != EVENTTYPE_MESSAGE) || (cbLen + messageIdLength + 1 > dbei.cbBlob))
- continue;
+ MEVENT hDbEvent = db_event_getById(m_szModuleName, messageId);
+ if (!hDbEvent)
+ return 0;
- if (memcmp(&dbei.pBlob[cbLen + 1], messageId, messageIdLength) == 0) {
- msg = ptrW(mir_utf8decodeW((char*)dbei.pBlob));
- timestamp = dbei.timestamp;
- return hDbEvent;
- }
+ DBEVENTINFO dbei = {};
+ dbei.cbBlob = db_event_getBlobSize(hDbEvent);
+ mir_ptr<BYTE> blob((PBYTE)mir_alloc(dbei.cbBlob));
+ dbei.pBlob = blob;
+ db_event_get(hDbEvent, &dbei);
- if (dbei.timestamp < timestamp)
- break;
- }
+ msg = ptrW(mir_utf8decodeW((char*)dbei.pBlob));
+ timestamp = dbei.timestamp;
- return 0;
+ return hDbEvent;
}
int CVkProto::DeleteContact(MCONTACT hContact)
|