diff options
author | Robert Pösel <robyer@seznam.cz> | 2016-09-04 14:04:58 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2016-09-04 14:04:58 +0000 |
commit | abb7234475a08089b046b05de7a872d13491539b (patch) | |
tree | 351459b322cbb09197225b399042ba5d3dfc7a52 | |
parent | 1cfb77837fef9854796ee06929caa673fd3e6a6b (diff) |
Facebook: Handle unsubscribe events in chat; improve also subscribe event
git-svn-id: http://svn.miranda-ng.org/main/trunk@17250 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 8 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 34 |
2 files changed, 26 insertions, 16 deletions
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 71d706a4e1..310a61b0aa 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -100,6 +100,14 @@ void parseMessageType(FacebookProto *proto, facebook_message &message, const JSO } else if (logType == "log:unsubscribe") { message.type = UNSUBSCRIBE; + + const JSONNode &fbids_ = log_data_["removed_participants"]; + for (auto it2 = fbids_.begin(); it2 != fbids_.end(); ++it2) { + std::string id = (*it2).as_string().substr(5); // strip "fbid:" prefix + if (!message.data.empty()) + message.data += ";"; + message.data += id; + } } else if (logType == "log:thread-name") { message.type = THREAD_NAME; diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 6e678e6ca7..a2b533cda9 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -893,6 +893,7 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo UpdateChat(thread_id.c_str(), NULL, NULL, msg.message_text.c_str()); break; case SUBSCRIBE: + case UNSUBSCRIBE: { UpdateChat(thread_id.c_str(), NULL, NULL, msg.message_text.c_str()); @@ -900,26 +901,27 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo utils::text::explode(msg.data, ";", &ids); for (std::vector<std::string>::size_type k = 0; k < ids.size(); k++) { - if (fbc->participants.find(ids[k]) != fbc->participants.end()) { - continue; // We have this participant in chatroom already + auto jt = fbc->participants.find(ids[k]); + if (jt == fbc->participants.end()) { + // We don't have this user there yet, so load info about him and then process event + chatroom_participant participant; + participant.is_former = (msg.type == UNSUBSCRIBE); + participant.user_id = ids[k]; + + // FIXME: Load info about all participants at once + fbc->participants.insert(std::make_pair(participant.user_id, participant)); + LoadParticipantsNames(fbc); + jt = fbc->participants.find(ids[k]); + } + if (jt != fbc->participants.end()) { + if (msg.type == SUBSCRIBE) + AddChatContact(thread_id.c_str(), jt->second, msg.isUnread); + else + RemoveChatContact(thread_id.c_str(), jt->second.user_id.c_str(), jt->second.nick.c_str()); } - // We don't have this user there yet, so load info about him and then add him - chatroom_participant participant; - participant.is_former = false; - participant.user_id = ids[k]; - - // FIXME: Load info about all participants at once - fbc->participants.insert(std::make_pair(participant.user_id, participant)); - LoadParticipantsNames(fbc); - - AddChatContact(thread_id.c_str(), participant, msg.isUnread); } - break; } - case UNSUBSCRIBE: - RemoveChatContact(thread_id.c_str(), msg.user_id.c_str(), name.c_str()); - break; case THREAD_NAME: // proto->RenameChat(thread_id.c_str(), msg.data.c_str()); // this don't work, why? setStringUtf(hChatContact, FACEBOOK_KEY_NICK, msg.data.c_str()); |