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 | |
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')
-rw-r--r-- | protocols/FacebookRM/src/entities.h | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 42 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 1 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 2 |
5 files changed, 47 insertions, 4 deletions
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h index ecb54136bb..f9a8283e36 100644 --- a/protocols/FacebookRM/src/entities.h +++ b/protocols/FacebookRM/src/entities.h @@ -107,12 +107,15 @@ struct facebook_message bool isUnread;
bool isChat;
+ int flag_;
+
facebook_message()
{
this->user_id = this->message_text = this->sender_name = this->message_id = this->thread_id = "";
this->time = 0;
this->isUnread = this->isIncoming = true;
this->isChat = false;
+ this->flag_ = 0;
}
facebook_message(const facebook_message& msg)
@@ -126,6 +129,7 @@ struct facebook_message this->isIncoming = msg.isIncoming;
this->isUnread = msg.isUnread;
this->isChat = msg.isChat;
+ this->flag_ = msg.flag_;
}
};
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index e7c6630642..1478aab8ca 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -176,6 +176,8 @@ void FacebookProto::ReadMessageWorker(void *p) if (mid == NULL)
return;
+ // TODO: for multi-chat messages we might need to mark as read threadID and not messageID, but I'm not sure about that now...
+
std::string data = "ids[" + utils::url::encode(std::string(mid)) + "]=true";
data += "&fb_dtsg=" + (facy.dtsg_.length() ? facy.dtsg_ : "0");
data += "&__user=" + facy.self_.user_id;
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;
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index 3a5b5d38dd..9be2277fe1 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -57,7 +57,6 @@ FacebookProto::FacebookProto(const char* proto_name,const TCHAR* username) : db_set_resident(m_szModuleName, "Status");
db_set_resident(m_szModuleName, "IdleTS");
- db_set_resident(m_szModuleName, FACEBOOK_KEY_MESSAGE_ID);
InitHotkeys();
InitPopups();
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 346ece4193..a6d783f57d 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -204,7 +204,7 @@ public: void RemoveChatContact(const TCHAR *chat_id, const char *id);
void SetChatStatus(const char *chat_id, int status);
char *GetChatUsers(const TCHAR *chat_id);
- void ReceiveMessages(std::vector<facebook_message*> messages, bool local_timestamp);
+ void ReceiveMessages(std::vector<facebook_message*> messages, bool local_timestamp, bool check_duplicates = false);
// Connection client
facebook_client facy; // TODO: Refactor to "client" and make dynamic
|