diff options
author | Robert Pösel <robyer@seznam.cz> | 2016-04-17 17:06:12 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2016-04-17 17:06:12 +0000 |
commit | 9e64b26c646913d5669723269c07e6fe8277f10c (patch) | |
tree | 0702a4bf6254e49b0cf5af82f3b2d71c56721d30 /protocols/FacebookRM/src/json.cpp | |
parent | 34dd9e912952befefa30ba0d64dbd18d84201552 (diff) |
Facebook: Loading names of all users in multi chat from server (not only existing Miranda contacts)
It primary iterates over Miranda's contacts list to find existing contacts (e.g. to preserve existing custom names of these contacts). Then for missing ones it does request to server to get their names.
git-svn-id: http://svn.miranda-ng.org/main/trunk@16701 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src/json.cpp')
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index ecd69d393b..d4e4c84d87 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -158,6 +158,33 @@ void parseUser(const JSONNode &it, facebook_user *fbu) } } +int facebook_json_parser::parse_chat_participant_names(std::string *data, std::map<std::string, std::string>* participants) +{ + std::string jsonData = data->substr(9); + + JSONNode root = JSONNode::parse(jsonData.c_str()); + if (!root) + return EXIT_FAILURE; + + const JSONNode &profiles = root["payload"].at("profiles"); + if (!profiles) + return EXIT_FAILURE; + + for (auto it = profiles.begin(); it != profiles.end(); ++it) { + std::string userId = (*it).name(); + std::string userName = (*it)["name"].as_string(); + + if (userId.empty() || userName.empty()) + continue; + + auto participant = participants->find(userId); + if (participant != participants->end()) + participant->second = userName; + } + + return EXIT_SUCCESS; +} + int facebook_json_parser::parse_friends(std::string *data, std::map< std::string, facebook_user* >* friends) { std::string jsonData = data->substr(9); @@ -1195,22 +1222,6 @@ int facebook_json_parser::parse_chat_info(std::string *data, facebook_chatroom* if (!threads) return EXIT_FAILURE; - /*const JSONNode &roger = payload, "roger"); - if (roger) { - for (unsigned int i = 0; i < json_size(roger); i++) { - const JSONNode &it = json_at(roger, i); - std::tstring id = _A2T(json_name(it)); - - // Ignore "wrong" (duplicit) identifiers - these that doesn't begin with "id." - if (id.substr(0, 3) == _T("id.")) { - facebook_chatroom *room = new facebook_chatroom(); - room->thread_id = id; - - chatrooms->insert(std::make_pair((char*)_T2A(room->thread_id.c_str()), room)); - } - } - }*/ - for (auto it = threads.begin(); it != threads.end(); ++it) { const JSONNode &is_canonical_user_ = (*it)["is_canonical_user"]; const JSONNode &thread_id_ = (*it)["thread_id"]; @@ -1223,14 +1234,16 @@ int facebook_json_parser::parse_chat_info(std::string *data, facebook_chatroom* std::string tid = thread_id_.as_string(); - // TODO: allow more users to parse at once + // TODO: allow more chats to parse at once if (fbc->thread_id != tid) continue; + // const JSONNode &former_participants = (*it)["former_participants"]; // TODO: Do we want to list also former participants? We can show them with different role or something like that... + const JSONNode &participants = (*it)["participants"]; for (auto jt = participants.begin(); jt != participants.end(); ++jt) { std::string user_id = (*jt).as_string(); - fbc->participants.insert(std::make_pair(user_id.substr(5), "")); + fbc->participants.insert(std::make_pair(user_id.substr(5), "")); // strip "fbid:" prefix } fbc->chat_name = std::tstring(ptrT(mir_utf8decodeT(name_.as_string().c_str()))); |