From 3b576fbd2dc5359c9c2e3b79633f77ec97d307c9 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 16 Apr 2020 20:27:26 +0300 Subject: SkypeWeb: - fixes #2306 (SkypeWeb: sometimes plugin does not show contacts statuses); - obsoleted GetContactsInfoRequest removed (as well as its handler CSkypeProto::LoadContactsInfo); - major optimization for polling process; - ugly & crashy map Contacts removed; - old crappy timer code removed and replaced with CTimer; - version bump --- protocols/SkypeWeb/src/skype_trouter.cpp | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'protocols/SkypeWeb/src/skype_trouter.cpp') diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index cfc41f7b8c..79a4f12cf3 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -17,6 +17,63 @@ along with this program. If not, see . #include "stdafx.h" +void CSkypeProto::ProcessTimer() +{ + if (!IsOnline()) + return; + + PushRequest(new GetContactListRequest(this, nullptr), &CSkypeProto::LoadContactList); + SendPresence(false); + + RefreshStatuses(); +} + +void CSkypeProto::OnReceiveStatus(const NETLIBHTTPREQUEST *response) +{ + JsonReply reply(response); + if (reply.error()) + return; + + auto &root = reply.data(); + for (auto &it : root["Responses"]) { + std::string id = it["Contact"].as_string(); + id.erase(0, 2); + MCONTACT hContact = AddContact(id.c_str()); + if (hContact) { + int status = SkypeToMirandaStatus(it["Payload"]["status"].as_string().c_str()); + setWord(hContact, "Status", status); + } + } +} + +void CSkypeProto::RefreshStatuses(void) +{ + int nRecs = 0; + GetStatusRequest *pReq = nullptr; + + for (auto &it : AccContacts()) { + CMStringA id(getId(it)); + if (id.IsEmpty()) + continue; + + if (pReq == nullptr) { + pReq = new GetStatusRequest(this); + nRecs = 0; + } + + pReq->Url << CHAR_VALUE("cMri", "8:" + id); + nRecs++; + + if (nRecs >= 10) { + PushRequest(pReq, &CSkypeProto::OnReceiveStatus); + pReq = nullptr; + } + } + + if (pReq) + PushRequest(pReq, &CSkypeProto::OnReceiveStatus); +} + void CSkypeProto::OnCreateTrouter(const NETLIBHTTPREQUEST *response) { JsonReply reply(response); -- cgit v1.2.3