diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2016-07-07 11:44:27 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2016-07-07 11:44:27 +0000 |
commit | 320ae2c5255401fa7237307f59064d49b27282a4 (patch) | |
tree | f45d93de2d7b81645387dfebd308af54b028c5af /protocols/SkypeWeb/src | |
parent | 8f5d25a514c3c3bf0080accdfc39b5411ce068c0 (diff) |
SkypeWeb: status messages support
git-svn-id: http://svn.miranda-ng.org/main/trunk@17075 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/SkypeWeb/src')
-rw-r--r-- | protocols/SkypeWeb/src/requests/status.h | 20 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_profile.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.cpp | 25 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 17 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_request.cpp | 38 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/stdafx.h | 57 |
6 files changed, 126 insertions, 33 deletions
diff --git a/protocols/SkypeWeb/src/requests/status.h b/protocols/SkypeWeb/src/requests/status.h index 5d3aef4b78..bb6381391b 100644 --- a/protocols/SkypeWeb/src/requests/status.h +++ b/protocols/SkypeWeb/src/requests/status.h @@ -36,4 +36,24 @@ public: }
};
+class SetStatusMsgRequest : public HttpRequest
+{
+public:
+ SetStatusMsgRequest(const char *status, LoginInfo &li) :
+ HttpRequest(REQUEST_POST, "api.skype.com/users/nikolay200027/profile/partial")
+ {
+ Headers
+ << CHAR_VALUE("Accept", "application/json, text/javascript")
+ << CHAR_VALUE("X-Skypetoken", li.api.szToken)
+ << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
+
+ JSONNode node, payload;
+ payload.set_name("payload");
+ node << (payload << JSONNode("mood", status));
+
+
+ Body << VALUE(node.write().c_str());
+ }
+};
+
#endif //_SKYPE_REQUEST_STATUS_H_
diff --git a/protocols/SkypeWeb/src/skype_profile.cpp b/protocols/SkypeWeb/src/skype_profile.cpp index 1d59c06cf0..0a9bffa133 100644 --- a/protocols/SkypeWeb/src/skype_profile.cpp +++ b/protocols/SkypeWeb/src/skype_profile.cpp @@ -484,4 +484,6 @@ void CSkypeProto::LoadProfile(const NETLIBHTTPREQUEST *response) UpdateProfileStatusMessage(root, hContact);
//richMood
UpdateProfileAvatar(root, hContact);
+
+ setString(hContact, "StatusMsg", root["mood"].as_string().c_str());
}
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index fbe2cfd705..0059de176b 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -114,6 +114,31 @@ DWORD_PTR CSkypeProto::GetCaps(int type, MCONTACT) return 0;
}
+int CSkypeProto::SetAwayMsg(int, const TCHAR *msg)
+{
+ PushRequest(new SetStatusMsgRequest(msg ? T2Utf(msg) : "", li));
+ return 0;
+}
+
+HANDLE CSkypeProto::GetAwayMsg(MCONTACT hContact)
+{
+ PushRequest(new GetProfileRequest(li, Contacts[hContact]), [this, hContact](const NETLIBHTTPREQUEST *response)
+ {
+ if (!response || !response->pData)
+ return;
+
+ JSONNode root = JSONNode::parse(response->pData);
+
+ if (JSONNode &mood = root["mood"])
+ {
+ CMString str = mood.as_mstring();
+ this->ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)str.c_str());
+ }
+ this->ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+ });
+ return (HANDLE)1;
+}
+
MCONTACT CSkypeProto::AddToList(int, PROTOSEARCHRESULT *psr)
{
debugLogA(__FUNCTION__);
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 63693910f9..e42ddd0008 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -54,6 +54,8 @@ public: virtual int __cdecl OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam);
virtual int __cdecl RecvContacts(MCONTACT hContact, PROTORECVEVENT*);
virtual HANDLE __cdecl SendFile(MCONTACT hContact, const TCHAR *szDescription, TCHAR **ppszFiles);
+ virtual HANDLE __cdecl GetAwayMsg(MCONTACT hContact);
+ virtual int __cdecl SetAwayMsg(int m_iStatus, const TCHAR *msg);
// accounts
static CSkypeProto* InitAccount(const char *protoName, const TCHAR *userName);
@@ -121,7 +123,6 @@ private: } Contacts;
-
static UINT_PTR m_timer;
//---Accounts
@@ -192,10 +193,24 @@ private: void PushRequest(HttpRequest *request, SkypeResponseCallback response);
void PushRequest(HttpRequest *request, SkypeResponseWithArgCallback response, void *arg);
+ template<typename F>
+ void PushRequest(HttpRequest *request, F callback)
+ {
+ SkypeResponseDelegateBase *delegate = new SkypeResponseDelegateLambda<F>(this, callback);
+ requestQueue->Push(request, SkypeHttpResponse, delegate);
+ }
+
void SendRequest(HttpRequest *request);
void SendRequest(HttpRequest *request, SkypeResponseCallback response);
void SendRequest(HttpRequest *request, SkypeResponseWithArgCallback response, void *arg);
+ template<typename F>
+ void SendRequest(HttpRequest *request, F callback)
+ {
+ SkypeResponseDelegateBase *delegate = new SkypeResponseDelegateLambda<F>(this, response);
+ requestQueue->Send(request, SkypeHttpResponse, delegate);
+ }
+
// icons
static IconItemT Icons[];
static HICON GetIcon(int iconId);
diff --git a/protocols/SkypeWeb/src/skype_request.cpp b/protocols/SkypeWeb/src/skype_request.cpp index 4ba0fbd43a..9322ef8451 100644 --- a/protocols/SkypeWeb/src/skype_request.cpp +++ b/protocols/SkypeWeb/src/skype_request.cpp @@ -17,35 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h"
-class SkypeResponseDelegate
+void SkypeHttpResponse(const NETLIBHTTPREQUEST *response, void *arg)
{
-private:
- CSkypeProto *proto;
- SkypeResponseCallback responseCallback;
- SkypeResponseWithArgCallback responseWithArgCallback;
-
- void *arg;
- bool hasArg;
-
-public:
- SkypeResponseDelegate(CSkypeProto *proto, SkypeResponseCallback responseCallback)
- : proto(proto), responseCallback(responseCallback), responseWithArgCallback(NULL), arg(NULL), hasArg(false) {}
-
- SkypeResponseDelegate(CSkypeProto *proto, SkypeResponseWithArgCallback responseCallback, void *arg)
- : proto(proto), responseCallback(NULL), responseWithArgCallback(responseCallback), arg(arg), hasArg(true) { }
-
- void Invoke(const NETLIBHTTPREQUEST *response)
- {
- if (hasArg)
- (proto->*(responseWithArgCallback))(response, arg);
- else
- (proto->*(responseCallback))(response);
- }
-};
-
-static void SkypeHttpResponse(const NETLIBHTTPREQUEST *response, void *arg)
-{
- SkypeResponseDelegate *delegate = (SkypeResponseDelegate*)arg;
+ SkypeResponseDelegateBase *delegate = (SkypeResponseDelegateBase*)arg;
delegate->Invoke(response);
delete delegate;
}
@@ -57,13 +31,13 @@ void CSkypeProto::PushRequest(HttpRequest *request) void CSkypeProto::PushRequest(HttpRequest *request, SkypeResponseCallback response)
{
- SkypeResponseDelegate *delegate = new SkypeResponseDelegate(this, response);
+ SkypeResponseDelegateBase *delegate = new SkypeResponseDelegate(this, response);
requestQueue->Push(request, SkypeHttpResponse, delegate);
}
void CSkypeProto::PushRequest(HttpRequest *request, SkypeResponseWithArgCallback response, void *arg)
{
- SkypeResponseDelegate *delegate = new SkypeResponseDelegate(this, response, arg);
+ SkypeResponseDelegateBase *delegate = new SkypeResponseDelegateWithArg(this, response, arg);
requestQueue->Push(request, SkypeHttpResponse, delegate);
}
@@ -74,12 +48,12 @@ void CSkypeProto::SendRequest(HttpRequest *request) void CSkypeProto::SendRequest(HttpRequest *request, SkypeResponseCallback response)
{
- SkypeResponseDelegate *delegate = new SkypeResponseDelegate(this, response);
+ SkypeResponseDelegateBase *delegate = new SkypeResponseDelegate(this, response);
requestQueue->Send(request, SkypeHttpResponse, delegate);
}
void CSkypeProto::SendRequest(HttpRequest *request, SkypeResponseWithArgCallback response, void *arg)
{
- SkypeResponseDelegate *delegate = new SkypeResponseDelegate(this, response, arg);
+ SkypeResponseDelegateBase *delegate = new SkypeResponseDelegateWithArg(this, response, arg);
requestQueue->Send(request, SkypeHttpResponse, delegate);
}
\ No newline at end of file diff --git a/protocols/SkypeWeb/src/stdafx.h b/protocols/SkypeWeb/src/stdafx.h index c4ade57724..a3840cfd3e 100644 --- a/protocols/SkypeWeb/src/stdafx.h +++ b/protocols/SkypeWeb/src/stdafx.h @@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <regex>
#include <map>
#include <memory>
+#include <functional>
#include <newpluginapi.h>
@@ -104,6 +105,7 @@ struct MessageId HANDLE handle;
};
+
//#include "websocket.h"
#include "version.h"
#include "resource.h"
@@ -133,6 +135,61 @@ struct MessageId #include "request_queue.h"
#include "skype_proto.h"
+void SkypeHttpResponse(const NETLIBHTTPREQUEST *response, void *arg);
+
+class SkypeResponseDelegateBase
+{
+protected:
+ CSkypeProto *proto;
+public:
+ SkypeResponseDelegateBase(CSkypeProto *ppro) : proto(ppro) {}
+ virtual void Invoke(const NETLIBHTTPREQUEST *) = 0;
+ virtual ~SkypeResponseDelegateBase(){};
+};
+
+class SkypeResponseDelegate : public SkypeResponseDelegateBase
+{
+ SkypeResponseCallback pfnResponseCallback;
+public:
+ SkypeResponseDelegate(CSkypeProto *ppro, SkypeResponseCallback callback) : SkypeResponseDelegateBase(ppro), pfnResponseCallback(callback) {}
+
+ virtual void Invoke(const NETLIBHTTPREQUEST *response) override
+ {
+ (proto->*(pfnResponseCallback))(response);
+ }
+};
+
+class SkypeResponseDelegateWithArg : public SkypeResponseDelegateBase
+{
+ SkypeResponseWithArgCallback pfnResponseCallback;
+ void *arg;
+public:
+ SkypeResponseDelegateWithArg(CSkypeProto *ppro, SkypeResponseWithArgCallback callback, void *p) :
+ SkypeResponseDelegateBase(ppro),
+ pfnResponseCallback(callback),
+ arg(p)
+ {}
+
+ virtual void Invoke(const NETLIBHTTPREQUEST *response) override
+ {
+ (proto->*(pfnResponseCallback))(response, arg);
+ }
+};
+
+template <typename F>
+class SkypeResponseDelegateLambda : public SkypeResponseDelegateBase
+{
+ F lCallback;
+public:
+ SkypeResponseDelegateLambda(CSkypeProto *ppro, F &callback) : SkypeResponseDelegateBase(ppro), lCallback(callback) {}
+
+ virtual void Invoke(const NETLIBHTTPREQUEST *response) override
+ {
+ lCallback(response);
+ }
+};
+
+
#define MODULE "Skype"
#define SKYPE_MAX_CONNECT_RETRIES 10
|