diff options
author | Robert Pösel <robyer@seznam.cz> | 2014-08-31 18:34:12 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2014-08-31 18:34:12 +0000 |
commit | cf488b3a97eb641d271cf0b3f183fc914ee0caf2 (patch) | |
tree | 6af6006ac7971c3bb9499258938ab36771b20ec4 /protocols/FacebookRM/src | |
parent | b35a3607236bcd628d56290fe4a72977454ac1c7 (diff) |
Facebook: Save message read time into DB as key "MessageRead" (DWORD)
git-svn-id: http://svn.miranda-ng.org/main/trunk@10347 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r-- | protocols/FacebookRM/src/client.h | 3 | ||||
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 32 | ||||
-rw-r--r-- | protocols/FacebookRM/src/connection.cpp | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/db.h | 1 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 3 | ||||
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 6 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 10 |
7 files changed, 48 insertions, 9 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index 1bab682836..03a62be446 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -114,6 +114,9 @@ public: void clear_cookies();
void clear_notifications();
void clear_chatrooms();
+ void clear_readers();
+ void insert_reader(MCONTACT, time_t);
+ void erase_reader(MCONTACT);
////////////////////////////////////////////////////////////
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 3223c110ff..cc6eef0292 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -715,6 +715,38 @@ void facebook_client::clear_chatrooms() chat_rooms.clear(); } +/** + * Clears readers info for all contacts from readers list and db + */ +void facebook_client::clear_readers() +{ + for (std::map<MCONTACT, time_t>::iterator it = readers.begin(); it != readers.end();) { + parent->delSetting(it->first, FACEBOOK_KEY_MESSAGE_READ); + it = readers.erase(it); + } + readers.clear(); +} + +/** + * Inserts info to readers list, db and writes to statusbar + */ +void facebook_client::insert_reader(MCONTACT hContact, time_t timestamp) +{ + parent->setDword(hContact, FACEBOOK_KEY_MESSAGE_READ, timestamp); + readers.insert(std::make_pair(hContact, timestamp)); + parent->MessageRead(hContact); +} + +/** + * Removes info from readers list, db and clears statusbar + */ +void facebook_client::erase_reader(MCONTACT hContact) +{ + parent->delSetting(hContact, FACEBOOK_KEY_MESSAGE_READ); + readers.erase(hContact); + CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, NULL); +} + void loginError(FacebookProto *proto, std::string error_str) { error_str = utils::text::trim( utils::text::html_entities_decode( diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index 21cadf807d..fbc4819308 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -53,11 +53,11 @@ void FacebookProto::ChangeStatus(void*) facy.clear_cookies(); facy.clear_notifications(); facy.clear_chatrooms(); + facy.clear_readers(); facy.buddies.clear(); facy.messages_ignore.clear(); facy.pages.clear(); facy.typers.clear(); - facy.readers.clear(); if (facy.hMsgCon) Netlib_CloseHandle(facy.hMsgCon); diff --git a/protocols/FacebookRM/src/db.h b/protocols/FacebookRM/src/db.h index d978fd4f98..9802f09c9e 100644 --- a/protocols/FacebookRM/src/db.h +++ b/protocols/FacebookRM/src/db.h @@ -59,6 +59,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define FACEBOOK_KEY_MESSAGES_ON_OPEN "MessagesOnOpen"
#define FACEBOOK_KEY_MESSAGES_ON_OPEN_COUNT "MessagesOnOpenCount"
#define FACEBOOK_KEY_HIDE_CHATS "HideChats"
+#define FACEBOOK_KEY_MESSAGE_READ "MessageRead"
#define FACEBOOK_KEY_POLL_RATE "PollRate" // [HIDDEN]
#define FACEBOOK_KEY_TIMEOUTS_LIMIT "TimeoutsLimit" // [HIDDEN]
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 005780b45f..9590f0878d 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -482,8 +482,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa } else { // classic contact MCONTACT hContact = proto->ContactIDToHContact(json_as_pstring(reader)); if (hContact) { - proto->facy.readers.insert(std::make_pair(hContact, timestamp)); - proto->MessageRead(hContact); + proto->facy.insert_reader(hContact, timestamp); } } } else if (t == "deliver") { diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index c4f066ed0c..59d75ec6f1 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -27,8 +27,7 @@ int FacebookProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre) StopTyping(hContact); // Remove from "readers" list and clear statusbar - facy.readers.erase(hContact); - CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, NULL); + facy.erase_reader(hContact); return Proto_RecvMessage(hContact, pre); } @@ -58,8 +57,7 @@ void FacebookProto::SendMsgWorker(void *p) ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, data->msgid, 0); // Remove from "readers" list and clear statusbar - facy.readers.erase(data->hContact); - CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)data->hContact, NULL); + facy.erase_reader(data->hContact); } else { ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, (LPARAM)error_text.c_str()); diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index fe062681b2..b81f436cfa 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -65,6 +65,7 @@ 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_READ); InitHotkeys(); InitPopups(); @@ -981,12 +982,17 @@ void FacebookProto::InitSounds() */ void FacebookProto::MessageRead(MCONTACT hContact) { - std::map<MCONTACT, time_t>::iterator it = facy.readers.find(hContact); + /*std::map<MCONTACT, time_t>::iterator it = facy.readers.find(hContact); if (it == facy.readers.end()) + return;*/ + + // We may use this instead of checing map as we have this info already in memory (this value is resident) + time_t time = getDword(hContact, FACEBOOK_KEY_MESSAGE_READ, 0); + if (!time) return; TCHAR ttime[64]; - _tcsftime(ttime, SIZEOF(ttime), _T("%X"), localtime(&it->second)); + _tcsftime(ttime, SIZEOF(ttime), _T("%X"), localtime(&time)); StatusTextData st = { 0 }; st.cbSize = sizeof(st); |