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/contacts.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/contacts.cpp')
-rw-r--r-- | protocols/FacebookRM/src/contacts.cpp | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index 0aec3fcaa0..167933f061 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -244,7 +244,10 @@ void FacebookProto::LoadContactInfo(facebook_user* fbu) void FacebookProto::LoadParticipantsNames(facebook_chatroom *fbc) { - for (std::map<std::string, std::string>::iterator it = fbc->participants.begin(); it != fbc->participants.end(); ++it) { + std::vector<std::string> namelessIds; + + // TODO: We could load all names from server at once by skipping this for cycle and using namelessIds as all in participants list, but we would lost our local names of our contacts. But maybe that's not a problem? + for (auto it = fbc->participants.begin(); it != fbc->participants.end(); ++it) { if (it->second.empty()) { if (!mir_strcmp(it->first.c_str(), facy.self_.user_id.c_str())) it->second = facy.self_.real_name; @@ -259,15 +262,51 @@ void FacebookProto::LoadParticipantsNames(facebook_chatroom *fbc) // TODO: set correct role (friend/user) for this contact here - need rework participants map to <id, participant> } - // TODO: load unknown contact's names from server if (it->second.empty()) - it->second = it->first; - - //if (isOffline()) - // return; + namelessIds.push_back(it->first); } } } + + // if (isOffline()) + // return; + + if (!namelessIds.empty()) { + // we have some contacts without name, let's load them all from the server + + std::string data = "&__user=" + facy.self_.user_id; + data += "&__dyn=" + facy.__dyn(); + data += "&__req=" + facy.__req(); + data += "&fb_dtsg=" + facy.dtsg_; + data += "&ttstamp=" + facy.ttstamp_; + data += "&__rev=" + facy.__rev(); + + for (std::string::size_type i = 0; i < namelessIds.size() - 1; i++) { + std::string pos = utils::conversion::to_string(&i, UTILS_CONV_UNSIGNED_NUMBER); + std::string id = utils::url::encode(namelessIds.at(i)); + data += "&ids[" + pos + "]=" + id; + } + + http::response resp = facy.flap(REQUEST_USER_INFO, &data); // NOTE: Request revised 11.2.2016 + + if (resp.code == HTTP_CODE_OK) { + CODE_BLOCK_TRY + + // TODO: We can cache these results and next time (e.g. for different chatroom) we can use that already cached names + + facebook_json_parser* p = new facebook_json_parser(this); + p->parse_chat_participant_names(&resp.data, &fbc->participants); + delete p; + + debugLogA("*** Participant names processed"); + + CODE_BLOCK_CATCH + + debugLogA("*** Error processing participant names: %s", e.what()); + + CODE_BLOCK_END + } + } } void FacebookProto::LoadChatInfo(facebook_chatroom *fbc) @@ -341,8 +380,6 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc) fbc->chat_name = std::tstring(_A2T(fbc->thread_id.c_str())); // TODO: is this needed? Isn't it showed automatically as id if there is no name? } - //ReceiveMessages(messages, true); // don't let it fall into infinite cycle, solve it somehow... - debugLogA("*** Chat thread info processed"); CODE_BLOCK_CATCH |