diff options
author | Robert Pösel <robyer@seznam.cz> | 2014-07-06 07:53:55 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2014-07-06 07:53:55 +0000 |
commit | 95d43413eeef2a573d8e317088c8a0e108a3c3f7 (patch) | |
tree | a975e844823990ee8ec25409c5fd0d8074fcc3b9 | |
parent | 7cf07cdfae771f29937815f5dafcb74af7d35664 (diff) |
Facebook: Set "Message read" info (if exists) on opening message window
git-svn-id: http://svn.miranda-ng.org/main/trunk@9698 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/FacebookRM/src/client.h | 3 | ||||
-rw-r--r-- | protocols/FacebookRM/src/connection.cpp | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/contacts.cpp | 12 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 8 | ||||
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 5 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 25 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 1 |
7 files changed, 43 insertions, 13 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index a1fca8e1e0..29b2ba0f95 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -105,7 +105,8 @@ public: std::string get_privacy_type();
std::map<MCONTACT, bool> ignore_read;
- std::set<MCONTACT> typing; // store info about typing contacts, because Facebook doesn't send "stopped typing" event when there is actual message being sent
+ std::set<MCONTACT> typers; // store info about typing contacts, because Facebook doesn't send "stopped typing" event when there is actual message being sent
+ std::map<MCONTACT, time_t> readers;
char* load_cookies();
void store_headers(http::response* resp, NETLIBHTTPHEADER* headers, int headers_count);
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index 14abd9cd4b..ecaf18c2a1 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -55,7 +55,7 @@ void FacebookProto::ChangeStatus(void*) facy.buddies.clear();
facy.messages_ignore.clear();
facy.pages.clear();
- facy.typing.clear();
+ facy.typers.clear();
if (facy.hMsgCon)
Netlib_CloseHandle(facy.hMsgCon);
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index 76939ee44b..a4834d6237 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -77,6 +77,8 @@ bool FacebookProto::IsMyContact(MCONTACT hContact, bool include_chat) MCONTACT FacebookProto::ChatIDToHContact(std::tstring chat_id) { + // TODO: use some cache to optimize this + for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { if (!IsMyContact(hContact, true)) continue; @@ -91,6 +93,8 @@ MCONTACT FacebookProto::ChatIDToHContact(std::tstring chat_id) MCONTACT FacebookProto::ContactIDToHContact(std::string user_id) { + // TODO: use some cache to optimize this + for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { if (isChatRoom(hContact)) continue; @@ -420,20 +424,20 @@ int FacebookProto::OnContactDeleted(WPARAM wParam,LPARAM) void FacebookProto::StartTyping(MCONTACT hContact) { // ignore if contact is already typing - if (facy.typing.find(hContact) != facy.typing.end()) + if (facy.typers.find(hContact) != facy.typers.end()) return; // show notification and insert into typing set CallService(MS_PROTO_CONTACTISTYPING, hContact, (LPARAM)FACEBOOK_TYPING_TIME); - facy.typing.insert(hContact); + facy.typers.insert(hContact); } void FacebookProto::StopTyping(MCONTACT hContact) { // ignore if contact is not typing - if (facy.typing.find(hContact) == facy.typing.end()) + if (facy.typers.find(hContact) == facy.typers.end()) return; // show notification and remove from typing set CallService(MS_PROTO_CONTACTISTYPING, hContact, (LPARAM)PROTOTYPE_CONTACTTYPING_OFF); - facy.typing.erase(hContact); + facy.typers.erase(hContact); }
\ No newline at end of file diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 331e473fd3..d0ff3ad01a 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -460,12 +460,8 @@ 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) {
- StatusTextData st = { 0 };
- st.cbSize = sizeof(st);
- mir_sntprintf(st.tszText, SIZEOF(st.tszText), TranslateT("Message read: %s"), ttime);
-
- st.hIcon = Skin_GetIconByHandle(GetIconHandle("read"));
- CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, (LPARAM)&st);
+ proto->facy.readers.insert(std::make_pair(hContact, timestamp));
+ proto->MessageRead(hContact);
}
}
} else if (t == "deliver") {
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index aae8a55ca5..f54312b8d6 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -26,6 +26,8 @@ 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);
return Proto_RecvMessage(hContact, pre);
@@ -57,6 +59,9 @@ void FacebookProto::SendMsgWorker(void *p) }
if (result) {
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);
} 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 9a5fd73d02..4a36cc96d4 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -534,7 +534,10 @@ int FacebookProto::OnProcessSrmmEvent(WPARAM, LPARAM lParam) { MessageWindowEventData *event = (MessageWindowEventData *)lParam; - if (event->uType == MSG_WINDOW_EVT_OPEN) { + if (event->uType == MSG_WINDOW_EVT_OPENING) { + // Set statusbar to "Message read" time (if present) + MessageRead(event->hContact); + } else if (event->uType == MSG_WINDOW_EVT_OPEN) { // Check if we have enabled loading messages on open window if (!getBool(FACEBOOK_KEY_MESSAGES_ON_OPEN, DEFAULT_MESSAGES_ON_OPEN)) return 0; @@ -936,3 +939,23 @@ void FacebookProto::InitSounds() SkinAddNewSoundExT("NewsFeed", m_tszUserName, LPGENT("News Feed")); SkinAddNewSoundExT("OtherEvent", m_tszUserName, LPGENT("Other Event")); } + +/** + * Sets statusbar text of hContact with last read time (from facy.readers map) + */ +void FacebookProto::MessageRead(MCONTACT hContact) +{ + std::map<MCONTACT, time_t>::iterator it = facy.readers.find(hContact); + if (it == facy.readers.end()) + return; + + TCHAR ttime[64]; + _tcsftime(ttime, SIZEOF(ttime), _T("%X"), localtime(&it->second)); + + StatusTextData st = { 0 }; + st.cbSize = sizeof(st); + st.hIcon = Skin_GetIconByHandle(GetIconHandle("read")); + mir_sntprintf(st.tszText, SIZEOF(st.tszText), TranslateT("Message read: %s"), ttime); + + CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, (LPARAM)&st); +} diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 47e4dde821..0887d402a7 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -224,6 +224,7 @@ public: void SaveName(MCONTACT hContact, const facebook_user *fbu); void OpenUrl(std::string url); void __cdecl OpenUrlThread(void*); + void MessageRead(MCONTACT hContact); // Handles, Locks HGENMENU m_hMenuRoot, m_hMenuServicesRoot, m_hStatusMind; |