From 19dc7d627dead63d4b3442b88b3e823605ebce29 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 15 Mar 2025 17:39:13 +0300 Subject: more code cleaning --- protocols/SkypeWeb/src/requests/messages.h | 58 ------------------------------ protocols/SkypeWeb/src/skype_messages.cpp | 12 +++++-- protocols/SkypeWeb/src/skype_proto.cpp | 20 ++++++++--- protocols/SkypeWeb/src/stdafx.h | 1 - 4 files changed, 26 insertions(+), 65 deletions(-) delete mode 100644 protocols/SkypeWeb/src/requests/messages.h (limited to 'protocols/SkypeWeb/src') diff --git a/protocols/SkypeWeb/src/requests/messages.h b/protocols/SkypeWeb/src/requests/messages.h deleted file mode 100644 index 4c7a3cecae..0000000000 --- a/protocols/SkypeWeb/src/requests/messages.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright (c) 2015-25 Miranda NG team (https://miranda-ng.org) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation version 2 -of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#ifndef _SKYPE_REQUEST_MESSAGES_H_ -#define _SKYPE_REQUEST_MESSAGES_H_ - -struct SendTypingRequest : public AsyncHttpRequest -{ - SendTypingRequest(const char *username, int iState) : - AsyncHttpRequest(REQUEST_POST, HOST_DEFAULT, "/users/ME/conversations/" + mir_urlEncode(username) + "/messages") - { - const char *state = (iState == PROTOTYPE_SELFTYPING_ON) ? "Control/Typing" : "Control/ClearTyping"; - - JSONNode node; - node << INT64_PARAM("clientmessageid", getRandomId()) << CHAR_PARAM("messagetype", state) - << CHAR_PARAM("contenttype", "text") << CHAR_PARAM("content", ""); - m_szParam = node.write().c_str(); - } -}; - -struct DeleteMessageRequest : public AsyncHttpRequest -{ - DeleteMessageRequest(CSkypeProto *ppro, const char *username, const char *msgId) : - AsyncHttpRequest(REQUEST_DELETE, HOST_DEFAULT, "/users/ME/conversations/" + mir_urlEncode(username) + "/messages/" + msgId) - { - AddAuthentication(ppro); - - AddHeader("Origin", "https://web.skype.com"); - AddHeader("Referer", "https://web.skype.com/"); - } -}; - -struct MarkMessageReadRequest : public AsyncHttpRequest -{ - MarkMessageReadRequest(const char *username, int64_t msgTimestamp) : - AsyncHttpRequest(REQUEST_PUT, HOST_DEFAULT, "/users/ME/conversations/" + mir_urlEncode(username) + "/properties?name=consumptionhorizon") - { - JSONNode node(JSON_NODE); - node << CHAR_PARAM("consumptionhorizon", CMStringA(::FORMAT, "%lld;%lld;%lld", msgTimestamp, msgTimestamp, msgTimestamp)); - m_szParam = node.write().c_str(); - } -}; - -#endif //_SKYPE_REQUEST_MESSAGES_H_ diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index d4fdd4c373..71bd4aea31 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -224,8 +224,16 @@ void CSkypeProto::OnMarkRead(MCONTACT hContact, MEVENT hDbEvent) { if (IsOnline()) { DB::EventInfo dbei(hDbEvent, false); - if (dbei && dbei.szId) - PushRequest(new MarkMessageReadRequest(getId(hContact), _atoi64(dbei.szId))); + if (dbei && dbei.szId) { + auto *pReq = new AsyncHttpRequest(REQUEST_PUT, HOST_DEFAULT, "/users/ME/conversations/" + mir_urlEncode(getId(hContact)) + "/properties?name=consumptionhorizon"); + auto msgTimestamp = _atoi64(dbei.szId); + + JSONNode node(JSON_NODE); + node << CHAR_PARAM("consumptionhorizon", CMStringA(::FORMAT, "%lld;%lld;%lld", msgTimestamp, msgTimestamp, msgTimestamp)); + pReq->m_szParam = node.write().c_str(); + + PushRequest(pReq); + } } } diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 6e68c5ce16..094ef23e5e 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -74,8 +74,13 @@ void CSkypeProto::OnEventDeleted(MCONTACT hContact, MEVENT hDbEvent, int flags) return; DB::EventInfo dbei(hDbEvent, false); - if (dbei.szId) - PushRequest(new DeleteMessageRequest(this, getId(hContact), dbei.szId)); + if (dbei.szId) { + auto *pReq = new AsyncHttpRequest(REQUEST_DELETE, HOST_DEFAULT, "/users/ME/conversations/" + mir_urlEncode(getId(hContact)) + "/messages/" + dbei.szId); + pReq->AddAuthentication(this); + pReq->AddHeader("Origin", "https://web.skype.com"); + pReq->AddHeader("Referer", "https://web.skype.com/"); + PushRequest(pReq); + } } void CSkypeProto::OnEventEdited(MCONTACT hContact, MEVENT, const DBEVENTINFO &dbei) @@ -240,9 +245,16 @@ int CSkypeProto::SetStatus(int iNewStatus) return 0; } -int CSkypeProto::UserIsTyping(MCONTACT hContact, int type) +int CSkypeProto::UserIsTyping(MCONTACT hContact, int iState) { - PushRequest(new SendTypingRequest(getId(hContact), type)); + auto *pReq = new AsyncHttpRequest(REQUEST_POST, HOST_DEFAULT, "/users/ME/conversations/" + mir_urlEncode(getId(hContact)) + "/messages"); + + JSONNode node; + node << INT64_PARAM("clientmessageid", getRandomId()) << CHAR_PARAM("contenttype", "text") << CHAR_PARAM("content", "") + << CHAR_PARAM("messagetype", (iState == PROTOTYPE_SELFTYPING_ON) ? "Control/Typing" : "Control/ClearTyping"); + pReq->m_szParam = node.write().c_str(); + + PushRequest(pReq); return 0; } diff --git a/protocols/SkypeWeb/src/stdafx.h b/protocols/SkypeWeb/src/stdafx.h index 917bea0194..ef94f3040c 100644 --- a/protocols/SkypeWeb/src/stdafx.h +++ b/protocols/SkypeWeb/src/stdafx.h @@ -118,7 +118,6 @@ struct AsyncHttpRequest : public MTHttpRequest #include "requests/contacts.h" #include "requests/history.h" #include "requests/login.h" -#include "requests/messages.h" #include "requests/oauth.h" #include "requests/poll.h" #include "requests/profile.h" -- cgit v1.2.3