diff options
author | Robert Pösel <robyer@seznam.cz> | 2016-08-31 10:11:34 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2016-08-31 10:11:34 +0000 |
commit | f19d5fcb4c2807387aa89649a3601658766e3755 (patch) | |
tree | 3ba439c573e2a864ee68741f6531e0a550ed65bb /protocols/FacebookRM/src | |
parent | 8a904bdef0e8237dee49c1b704d4ebbc2b28a958 (diff) |
Facebook: Improve handling users joining chatroom (fixes #1279)
This commit makes them add to chat's user list and load their name too.
git-svn-id: http://svn.miranda-ng.org/main/trunk@17223 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 24 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 27 |
2 files changed, 42 insertions, 9 deletions
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 2c97a56b4a..a46fd08fb2 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -972,6 +972,14 @@ int facebook_json_parser::parse_messages(std::string *pData, std::vector<faceboo } else if (logType == "log:subscribe") { message.type = SUBSCRIBE; + + const JSONNode &fbids_ = log_data_["added_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:unsubscribe") { message.type = UNSUBSCRIBE; @@ -1194,6 +1202,14 @@ int facebook_json_parser::parse_thread_messages(std::string *data, std::vector< } else if (log_type == "log:subscribe") { message.type = SUBSCRIBE; + + const JSONNode &fbids_ = log_data_["added_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 (log_type == "log:unsubscribe") { message.type = UNSUBSCRIBE; @@ -1300,6 +1316,14 @@ int facebook_json_parser::parse_history(std::string *data, std::vector< facebook } else if (log_type == "log:subscribe") { message.type = SUBSCRIBE; + + const JSONNode &fbids_ = log_data_["added_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 (log_type == "log:unsubscribe") { message.type = UNSUBSCRIBE; diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index bc90683341..9e47f091ee 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -979,9 +979,6 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo if (jt != fbc->participants.end()) { name = jt->second.nick; } - else { - // TODO: Load info about this participant from server, and add it manually to participants list (maybe only if this is SUBSCRIBE type) - } switch (msg.type) { default: @@ -992,18 +989,30 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo UpdateChat(thread_id.c_str(), NULL, NULL, msg.message_text.c_str()); break; case SUBSCRIBE: - // TODO: We must get data with list of added users (their ids) from json to work properly, so for now we just print it as admin message + { UpdateChat(thread_id.c_str(), NULL, NULL, msg.message_text.c_str()); - /*if (jt == fbc->participants.end()) { + + std::vector<std::string> ids; + utils::text::explode(msg.data, ";", &ids); + for (std::vector<std::string>::size_type i = 0; i < ids.size(); i++) + { + if (fbc->participants.find(ids[i]) != fbc->participants.end()) { + continue; // We have this participant in chatroom already + } // 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.loaded = false; - participant.nick = msg.data; - participant.user_id = msg.data; + participant.user_id = ids[i]; + + // 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; |