From eff5259d6dac303fafa0e661a181428680197584 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Wed, 9 Sep 2015 12:51:17 +0000 Subject: MessageState: code optimization; leaks fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@15314 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MessageState/src/utils.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 plugins/MessageState/src/utils.cpp (limited to 'plugins/MessageState/src/utils.cpp') diff --git a/plugins/MessageState/src/utils.cpp b/plugins/MessageState/src/utils.cpp new file mode 100644 index 0000000000..27040cf3c2 --- /dev/null +++ b/plugins/MessageState/src/utils.cpp @@ -0,0 +1,24 @@ +#include "stdafx.h" + +LONGLONG GetLastSentMessageTime(MCONTACT hContact) +{ + for (MEVENT hDbEvent = db_event_last(hContact); hDbEvent; hDbEvent = db_event_prev(hContact, hDbEvent)) + { + DBEVENTINFO dbei = { sizeof(dbei) }; + db_event_get(hDbEvent, &dbei); + if (FLAG_CONTAINS(dbei.flags, DBEF_SENT)) + return dbei.timestamp; + } + return -1; +} + +bool HasUnread(MCONTACT hContact) +{ + const char *szProto = GetContactProto(hContact); + if (CheckProtoSupport(szProto)) + { + return ((GetLastSentMessageTime(hContact) > db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME, 0)) && db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME, 0) != 0); + } + + return false; +} -- cgit v1.2.3