diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-04-09 14:13:10 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-04-09 14:13:10 +0000 |
commit | daa7065cb3023c97d20c86ff0bccaf582a25662f (patch) | |
tree | aeae7438c85e1de6c27823389e3e3e0e4963b6f7 | |
parent | 6d19086e4193e3f3a3272921551d30f23f485879 (diff) |
SkypeWeb: Auto sync history part 1.
git-svn-id: http://svn.miranda-ng.org/main/trunk@12694 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/SkypeWeb/src/requests/messages.h | 23 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_login.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_messages.cpp | 40 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 4 |
4 files changed, 63 insertions, 6 deletions
diff --git a/protocols/SkypeWeb/src/requests/messages.h b/protocols/SkypeWeb/src/requests/messages.h index afb541edbc..43c6155edb 100644 --- a/protocols/SkypeWeb/src/requests/messages.h +++ b/protocols/SkypeWeb/src/requests/messages.h @@ -60,8 +60,8 @@ public: class GetHistoryRequest : public HttpRequest
{
public:
- GetHistoryRequest(const char *regToken, const char *username/* int time*/, const char *server = SKYPE_ENDPOINTS_HOST) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages?startTime=0&pageSize=100&view=msnp24Equivalent&targetType=Passport|Skype|Lync|Thread", server, mir_urlEncode(username)/*, time*/)
+ GetHistoryRequest(const char *regToken, const char *username, LONGLONG timestamp = 0, const char *server = SKYPE_ENDPOINTS_HOST) :
+ HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages?startTime=%d&pageSize=100&view=msnp24Equivalent&targetType=Passport|Skype|Lync|Thread", server, mir_urlEncode(username), timestamp)
{
Headers
<< CHAR_VALUE("Accept", "application/json, text/javascript")
@@ -70,4 +70,23 @@ public: }
};
+class SyncHistoryFirstRequest : public HttpRequest
+{
+public:
+ SyncHistoryFirstRequest(const char *regToken, const char *server = SKYPE_ENDPOINTS_HOST) :
+ HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/conversations?startTime=0&pageSize=100&view=msnp24Equivalent&targetType=Passport|Skype|Lync|Thread", server)
+ {
+ Headers
+ << CHAR_VALUE("Accept", "application/json, text/javascript")
+ << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken)
+ << CHAR_VALUE("Content-Type", "application/json; charset = UTF-8");
+ }
+};
+
+
+
+
+
+
+
#endif //_SKYPE_REQUEST_MESSAGES_H_
diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index d4c5e8b465..12a2c152fa 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -182,6 +182,8 @@ void CSkypeProto::OnSubscriptionsCreated(const NETLIBHTTPREQUEST *response) skypenames.destroy();
m_hPollingThread = ForkThreadEx(&CSkypeProto::PollingThread, 0, NULL);
+
+ SyncHistory();
}
void CSkypeProto::OnStatusChanged(const NETLIBHTTPREQUEST *response)
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 65c444f369..8f1dd3803e 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -34,7 +34,7 @@ MEVENT CSkypeProto::AddMessageToDb(MCONTACT hContact, DWORD timestamp, DWORD fla {
if (MEVENT hDbEvent = GetMessageFromDB(hContact, messageId, timestamp))
return hDbEvent;
-
+ setDword(hContact, "LastMsgId", atoi(messageId));
size_t messageLength = mir_strlen(&content[emoteOffset]) + 1;
size_t messageIdLength = mir_strlen(messageId);
size_t cbBlob = messageLength + messageIdLength;
@@ -51,7 +51,8 @@ MEVENT CSkypeProto::AddMessageToDb(MCONTACT hContact, DWORD timestamp, DWORD fla int CSkypeProto::OnReceiveMessage(const char *messageId, const char *url, time_t timestamp, char *content, int emoteOffset, bool isRead)
{
ptrA skypename(ContactUrlToName(url));
- setDword("LastMsgTime", timestamp);
+ MCONTACT hContact = GetContact(skypename);
+ setDword(hContact, "LastMsgId", atoi(messageId));
PROTORECVEVENT recv = { 0 };
recv.flags = PREF_UTF;
recv.timestamp = timestamp;
@@ -62,7 +63,6 @@ int CSkypeProto::OnReceiveMessage(const char *messageId, const char *url, time_t if (isRead)
recv.flags |= PREF_CREATEREAD;
debugLogA("Incoming message from %s", skypename);
- MCONTACT hContact = GetContact(skypename);
return ProtoChainRecvMsg(hContact, &recv);
}
@@ -126,6 +126,7 @@ void CSkypeProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg) {
SendMessageParam *param = (SendMessageParam*)arg;
MCONTACT hContact = param->hContact;
+ setDword(hContact, "LastMsgId", param->hMessage);
HANDLE hMessage = (HANDLE)param->hMessage;
delete param;
@@ -217,4 +218,37 @@ INT_PTR CSkypeProto::GetContactHistory(WPARAM hContact, LPARAM lParam) {
PushRequest(new GetHistoryRequest(ptrA(getStringA("registrationToken")), ptrA(db_get_sa(hContact, m_szModuleName, "Skypename")), ptrA(getStringA("Server"))), &CSkypeProto::OnGetServerHistory);
return 0;
+}
+
+void CSkypeProto::SyncHistory()
+{
+ PushRequest(new SyncHistoryFirstRequest(ptrA(getStringA("registrationToken")), ptrA(getStringA("Server"))), &CSkypeProto::OnSyncHistory);
+}
+
+void CSkypeProto::OnSyncHistory(const NETLIBHTTPREQUEST *response)
+{
+ if (response == NULL)
+ return;
+ JSONROOT root(response->pData);
+ if (root == NULL)
+ return;
+ JSONNODE *conversations = json_as_array(json_get(root, "conversations"));
+ for (size_t i = 0; i < json_size(conversations); i++)
+ {
+ JSONNODE *conversation = json_at(conversations, i);
+ JSONNODE *lastMessage = json_get(conversation, "lastMessage");
+ if (lastMessage == NULL)
+ continue;
+
+ int clientMsgId(atoi(mir_t2a(ptrT(json_as_string(json_get(lastMessage, "clientmessageid"))))));
+ ptrA conversationLink(mir_t2a(ptrT(json_as_string(json_get(lastMessage, "conversationLink")))));
+
+ ptrA skypename(ContactUrlToName(conversationLink));
+ MCONTACT hContact = GetContact(skypename);
+ if (hContact == NULL && !IsMe(skypename))
+ hContact = AddContact(skypename, true);
+ int lastmsgid = db_get_dw(hContact, m_szModuleName, "LastMsgId", NULL);
+ if (lastmsgid != clientMsgId)
+ PushRequest(new GetHistoryRequest(ptrA(getStringA("registrationToken")), skypename, ptrA(getStringA("Server"))), &CSkypeProto::OnGetServerHistory);
+ }
}
\ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index b294e1bd37..78ee87e342 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -202,8 +202,10 @@ private: int OnSendMessage(MCONTACT hContact, int flags, const char *message);
void OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg);
int __cdecl OnPreCreateMessage(WPARAM, LPARAM lParam);
-
+ //History sync
void OnGetServerHistory(const NETLIBHTTPREQUEST *response);
+ void SyncHistory();
+ void OnSyncHistory(const NETLIBHTTPREQUEST *response);
//chats
MCONTACT GetChat(const char *skypename);
|