diff options
author | Robert Pösel <robyer@seznam.cz> | 2014-04-14 12:13:11 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2014-04-14 12:13:11 +0000 |
commit | 6ddbe0d66de5c6ef05c5bde9be9766eb23df1704 (patch) | |
tree | 6d9f7386ffece0206f6fb6b5b0360236b67ad9f5 /protocols/FacebookRM/src/process.cpp | |
parent | 73af3297ebf6253ce4bad65545391941a7c0f179 (diff) |
Facebook: Don't load "unread messages" which we received already (but didn't read them yet)
- this needs further optimalization
- also it makes FACEBOOK_KEY_MESSAGE_ID no longer resident
git-svn-id: http://svn.miranda-ng.org/main/trunk@8973 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src/process.cpp')
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index d0dc4085d6..171341701c 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -384,7 +384,7 @@ void FacebookProto::ProcessUnreadMessage(void *p) }
chatrooms.clear();
- ReceiveMessages(messages, local_timestamp);
+ ReceiveMessages(messages, local_timestamp, true);
debugLogA("***** Unread messages processed");
@@ -406,10 +406,48 @@ void FacebookProto::ProcessUnreadMessage(void *p) }
}
-void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, bool local_timestamp)
+void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, bool local_timestamp, bool check_duplicates)
{
bool naseemsSpamMode = getBool(FACEBOOK_KEY_NASEEMS_SPAM_MODE, false);
+ // TODO: make this checking more lightweight as now it is not effective at all...
+ if (check_duplicates) {
+ // 1. check if there are some message that we already have (compare FACEBOOK_KEY_MESSAGE_ID = last received message ID)
+ for (std::vector<facebook_message*>::size_type i = 0; i < messages.size(); i++) {
+
+ MCONTACT hContact = messages[i]->isChat
+ ? ChatIDToHContact(std::tstring(_A2T(messages[i]->thread_id.c_str())))
+ : ContactIDToHContact(messages[i]->user_id);
+
+ if (hContact == NULL)
+ continue;
+
+ ptrA lastId(getStringA(hContact, FACEBOOK_KEY_MESSAGE_ID));
+ if (lastId == NULL)
+ continue;
+
+ if (!messages[i]->message_id.compare(lastId)) {
+ // Equal, ignore all older messages (including this) from same contact
+ for (std::vector<facebook_message*>::size_type j = 0; j < messages.size(); j++) {
+ bool equalsId = messages[i]->isChat
+ ? (messages[j]->thread_id == messages[i]->thread_id)
+ : (messages[j]->user_id == messages[i]->user_id);
+
+ if (equalsId && messages[j]->time <= messages[i]->time)
+ messages[j]->flag_ = 1;
+ }
+ }
+ }
+
+ // 2. remove all marked messages from list
+ for (std::vector<facebook_message*>::iterator it = messages.begin(); it != messages.end();) {
+ if ((*it)->flag_ == 1)
+ it = messages.erase(it);
+ else
+ ++it;
+ }
+ }
+
for(std::vector<facebook_message*>::size_type i = 0; i < messages.size(); i++) {
DWORD timestamp = local_timestamp || !messages[i]->time ? ::time(NULL) : messages[i]->time;
|