From 6dc2b417c94f35b0175e41fd99e96533cb2107ee Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 25 Sep 2019 19:33:29 +0300 Subject: SkypeWeb: - some contacts are still displayed as hidden; - empty group ignored on login even if a protocol has valid default group name; - more json iterators --- protocols/SkypeWeb/src/skype_chatrooms.cpp | 12 +++---- protocols/SkypeWeb/src/skype_contacts.cpp | 47 +++++++++------------------ protocols/SkypeWeb/src/skype_history_sync.cpp | 3 +- 3 files changed, 21 insertions(+), 41 deletions(-) diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index ef6dfdf717..ab464fa852 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -72,14 +72,12 @@ void CSkypeProto::OnLoadChats(const NETLIBHTTPREQUEST *response) if (totalCount >= 99 || conversations.size() >= 99) PushRequest(new SyncHistoryFirstRequest(syncState.c_str(), this), &CSkypeProto::OnSyncHistory); - for (size_t i = 0; i < conversations.size(); i++) { - const JSONNode &conversation = conversations.at(i); - const JSONNode &threadProperties = conversation["threadProperties"]; - const JSONNode &id = conversation["id"]; - + for (auto &conversation : conversations) { if (!conversation["lastMessage"]) continue; + const JSONNode &id = conversation["id"]; + const JSONNode &threadProperties = conversation["threadProperties"]; CMStringW topic(threadProperties["topic"].as_mstring()); SendRequest(new GetChatInfoRequest(id.as_string().c_str(), this), &CSkypeProto::OnGetChatInfo, topic.Detach()); } @@ -384,9 +382,7 @@ void CSkypeProto::OnGetChatInfo(const NETLIBHTTPREQUEST *response, void *p) CMStringA chatId(UrlToSkypename(root["messages"].as_string().c_str())); StartChatRoom(_A2T(chatId), topic); - for (size_t i = 0; i < members.size(); i++) { - const JSONNode &member = members.at(i); - + for (auto &member : members) { CMStringA username(UrlToSkypename(member["userLink"].as_string().c_str())); std::string role = member["role"].as_string(); AddChatContact(chatId, username, username, role.c_str(), true); diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index 4ad569bf7e..a6d896302e 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -99,12 +99,7 @@ void CSkypeProto::LoadContactsAuth(const NETLIBHTTPREQUEST *response) if (!root) return; - const JSONNode &items = root["invite_list"].as_array(); - for (size_t i = 0; i < items.size(); i++) { - const JSONNode &item = items.at(i); - if (!item) - break; - + for (auto &item : root["invite_list"]) { std::string skypename = item["mri"].as_string().erase(0, 2); std::string reason = item["greeting"].as_string(); @@ -141,12 +136,7 @@ void CSkypeProto::LoadContactsInfo(const NETLIBHTTPREQUEST *response) if (!root) return; - const JSONNode &items = root.as_array(); - for (size_t i = 0; i < items.size(); i++) { - const JSONNode &item = items.at(i); - if (!item) - break; - + for (auto &item : root) { std::string skypename = item["username"].as_string(); MCONTACT hContact = AddContact(skypename.c_str()); if (hContact) { @@ -171,14 +161,8 @@ void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response) LIST skypenames(1); bool loadAll = getBool("LoadAllContacts", false); - const JSONNode &items = root["contacts"].as_array(); - for (size_t i = 0; i < items.size(); i++) { - const JSONNode &item = items.at(i); - if (!item) - break; - + for (auto &item : root["contacts"]) { const JSONNode &name = item["name"]; - const JSONNode &phones = item["phones"]; std::string skypename = item["id"].as_string(); CMStringW display_name = item["display_name"].as_mstring(); @@ -202,10 +186,16 @@ void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response) setByte(hContact, "IsBlocked", 1); } else { - if (db_get_b(hContact, m_szModuleName, "IsBlocked", 0)) { - db_set_dw(hContact, "Ignore", "Mask1", 0); - db_set_b(hContact, "CList", "Hidden", 0); - setByte(hContact, "IsBlocked", 0); + db_set_dw(hContact, "Ignore", "Mask1", 0); + db_set_b(hContact, "CList", "Hidden", 0); + delSetting(hContact, "IsBlocked"); + } + + ptrW wszGroup(Clist_GetGroup(hContact)); + if (wszGroup == nullptr) { + if (m_opts.wstrCListGroup) { + Clist_GroupCreate(0, m_opts.wstrCListGroup); + Clist_SetGroup(hContact, m_opts.wstrCListGroup); } } @@ -218,18 +208,13 @@ void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response) if (last_name) setWString(hContact, "LastName", last_name); - if (item["mood"]) { + if (item["mood"]) db_set_utf(hContact, "CList", "StatusMsg", ptrA(RemoveHtml(item["mood"].as_string().c_str()))); - } SetAvatarUrl(hContact, avatar_url); ReloadAvatarInfo(hContact); - for (size_t j = 0; j < phones.size(); j++) { - const JSONNode &phone = phones.at(j); - if (!phone) - break; - + for (auto &phone : item["phones"]) { CMStringW number = phone["number"].as_mstring(); switch (phone["type"].as_int()) { @@ -319,5 +304,5 @@ void CSkypeProto::OnUnblockContact(const NETLIBHTTPREQUEST *response, void *p) return; db_set_dw(hContact, "Ignore", "Mask1", 0); db_set_b(hContact, "CList", "Hidden", 0); - db_set_b(hContact, m_szModuleName, "IsBlocked", 0); + delSetting(hContact, "IsBlocked"); } diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index 025718215b..d8d43e1bcc 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -126,8 +126,7 @@ void CSkypeProto::OnSyncHistory(const NETLIBHTTPREQUEST *response) if (totalCount >= 99 || conversations.size() >= 99) PushRequest(new SyncHistoryFirstRequest(syncState.c_str(), this), &CSkypeProto::OnSyncHistory); - for (size_t i = 0; i < conversations.size(); i++) { - const JSONNode &conversation = conversations.at(i); + for (auto &conversation : conversations) { const JSONNode &lastMessage = conversation["lastMessage"]; if (lastMessage) { std::string strConversationLink = lastMessage["conversationLink"].as_string(); -- cgit v1.2.3