From 01fe5ca202c527a3a06a1464a373607828cb6276 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 5 Jun 2020 20:27:57 +0300 Subject: Revert "SkypeWeb:" This reverts commit 59d3e0a8aa91452de46df3ae448f3cb499c5dce1. # Conflicts: # protocols/SkypeWeb/src/requests/poll.h # protocols/SkypeWeb/src/skype_login.cpp # protocols/SkypeWeb/src/skype_proto.h # protocols/SkypeWeb/src/skype_trouter.cpp --- protocols/SkypeWeb/src/requests/status.h | 7 +++++ protocols/SkypeWeb/src/skype_login.cpp | 4 ++- protocols/SkypeWeb/src/skype_proto.h | 2 ++ protocols/SkypeWeb/src/skype_trouter.cpp | 46 ++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) (limited to 'protocols/SkypeWeb/src') diff --git a/protocols/SkypeWeb/src/requests/status.h b/protocols/SkypeWeb/src/requests/status.h index 9aafe49678..166b2e7bbe 100644 --- a/protocols/SkypeWeb/src/requests/status.h +++ b/protocols/SkypeWeb/src/requests/status.h @@ -18,6 +18,13 @@ along with this program. If not, see . #ifndef _SKYPE_REQUEST_STATUS_H_ #define _SKYPE_REQUEST_STATUS_H_ +struct GetStatusRequest : public AsyncHttpRequest +{ + GetStatusRequest() : + AsyncHttpRequest(REQUEST_GET, HOST_DEFAULT, "/users/ME/contacts/ALL/presenceDocs/messagingService", &CSkypeProto::OnReceiveStatus) + {} +}; + struct SetStatusRequest : public AsyncHttpRequest { SetStatusRequest(const char *status) : diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index 0bb7711995..2cf41db7c2 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -182,7 +182,9 @@ void CSkypeProto::OnEndpointCreated(NETLIBHTTPREQUEST *response, AsyncHttpReques m_szId = val.Detach(); } } - + + RefreshStatuses(); + PushRequest(new CreateSubscriptionsRequest()); } diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 8355e0e33c..8a9a243afe 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -114,6 +114,7 @@ public: void OnLoginOAuth(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest); void OnSubscriptionsCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest); void OnCapabilitiesSended(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest); + void OnReceiveStatus(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest); void OnStatusChanged(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest); void OnEndpointCreated(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest); @@ -300,6 +301,7 @@ private: void ProcessEndpointPresence(const JSONNode &node); void ProcessConversationUpdate(const JSONNode &node); + void RefreshStatuses(void); void ReadHistoryRest(const char *url); // utils diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index f0c07d5ede..9d9a9a9cb0 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -25,3 +25,49 @@ void CSkypeProto::ProcessTimer() SendRequest(new GetContactListRequest(this, nullptr)); SendPresence(); } + +void CSkypeProto::OnReceiveStatus(NETLIBHTTPREQUEST *response, AsyncHttpRequest*) +{ + 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(); + nRecs = 0; + } + + pReq << CHAR_PARAM("cMri", "8:" + id); + nRecs++; + + if (nRecs >= 10) { + PushRequest(pReq); + pReq = nullptr; + } + } + + if (pReq) + PushRequest(pReq); +} -- cgit v1.2.3