void CSkypeProto::OnCapabilitiesSended(const NETLIBHTTPREQUEST *response) { if (!IsStatusConnecting(m_iStatus)) return; if (response == NULL || response->pData == NULL) { ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN); SetStatus(ID_STATUS_OFFLINE); return; } SendRequest(new SetStatusRequest(MirandaToSkypeStatus(m_iDesiredStatus), li), &CSkypeProto::OnStatusChanged); LIST<char> skypenames(1); for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { if (!isChatRoom(hContact)) skypenames.insert(getStringA(hContact, SKYPE_SETTINGS_ID)); } SendRequest(new CreateContactsSubscriptionRequest(skypenames, li)); FreeList(skypenames); skypenames.destroy(); m_hPollingEvent.Set(); SendRequest(new LoadChatsRequest(li), &CSkypeProto::OnLoadChats); SendRequest(new CreateTrouterRequest(), &CSkypeProto::OnCreateTrouter); PushRequest(new GetContactListRequest(li, NULL), &CSkypeProto::LoadContactList); PushRequest(new GetAvatarRequest(ptrA(getStringA("AvatarUrl"))), &CSkypeProto::OnReceiveAvatar, NULL); if (getBool("AutoSync", true)) PushRequest(new SyncHistoryFirstRequest(100, li), &CSkypeProto::OnSyncHistory); JSONNode root = JSONNode::parse(response->pData); if (root) setString("SelfEndpointName", UrlToSkypename(root["selfLink"].as_string().c_str())); PushRequest(new GetProfileRequest(li), &CSkypeProto::LoadProfile); }
void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response) { if (response == NULL) return; JSONNode root = JSONNode::parse(response->pData); if (!root) return; LIST<char> 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; const JSONNode &name = item["name"]; const JSONNode &phones = item["phones"]; std::string skypename = item["id"].as_string(); CMString display_name = item["display_name"].as_mstring(); CMString first_name = name["first"].as_mstring(); CMString last_name = name["surname"].as_mstring(); CMString avatar_url = item["avatar_url"].as_mstring(); std::string type = item["type"].as_string(); if (type == "skype" || loadAll) { MCONTACT hContact = AddContact(skypename.c_str()); if (hContact) { if (item["authorized"].as_bool()) { delSetting(hContact, "Auth"); delSetting(hContact, "Grant"); } else setByte(hContact, "Grant", 1); if (item["blocked"].as_bool()) { db_set_dw(hContact, "Ignore", "Mask1", 127); db_set_b(hContact, "CList", "Hidden", 1); 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); } } setString(hContact, "Type", type.c_str()); if (display_name) setTString(hContact, "Nick", display_name); if (first_name) setTString(hContact, "FirstName", first_name); if (last_name) setTString(hContact, "LastName", last_name); SetAvatarUrl(hContact, avatar_url); ReloadAvatarInfo(hContact); for (size_t j = 0; j < phones.size(); j++) { const JSONNode &phone = phones.at(j); if (!phone) break; CMString number = phone["number"].as_mstring(); switch (phone["type"].as_int()) { case 0: setTString(hContact, "Phone", number); break; case 2: setTString(hContact, "Cellular", number); break; } } if (type == "skype") skypenames.insert(mir_strdup(skypename.c_str())); } } } if (skypenames.getCount() > 0) { int i = 0; do { LIST<char> users(1); for (; i < skypenames.getCount() && users.getCount() <= 50; i++) users.insert(skypenames[i]); PushRequest(new GetContactsInfoRequest(li, users), &CSkypeProto::LoadContactsInfo); } while(i < skypenames.getCount()); FreeList(skypenames); skypenames.destroy(); } PushRequest(new GetContactsAuthRequest(li), &CSkypeProto::LoadContactsAuth); }