diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-04-04 20:10:50 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-04-04 20:10:50 +0000 |
commit | c89e8a054ac888b27065916ffde96af73404228c (patch) | |
tree | 5538dfdd531108fb653e107bc6ff54d1aea5a96d /protocols/SkypeWeb/src/skype_messages.cpp | |
parent | 817c5f883a658c4abca078df852ad81f6ec7f861 (diff) |
SkypeWeb:
- history sync (patch from MikalaiR)
- refactored message sending
git-svn-id: http://svn.miranda-ng.org/main/trunk@12599 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/SkypeWeb/src/skype_messages.cpp')
-rw-r--r-- | protocols/SkypeWeb/src/skype_messages.cpp | 116 |
1 files changed, 70 insertions, 46 deletions
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 70436ce0e7..b863fa57fd 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -3,89 +3,113 @@ /* MESSAGE RECEIVING */
// writing message/even into db
-int CSkypeProto::OnReceiveMessage(const char *from, const char *convLink, time_t timeStamp, char *content)
+int CSkypeProto::OnReceiveMessage(const char *from, const char *convLink, time_t timestamp, char *content)
{
+ setDword("LastMsgTime", timestamp);
PROTORECVEVENT recv = { 0 };
recv.flags = PREF_UTF;
- recv.timestamp = timeStamp;
+ recv.timestamp = timestamp;
recv.szMessage = content;
- debugLogA("Incoming message from %s", ContactUrlToName(from));
- if (IsMe(ContactUrlToName(from)))
+
+ ptrA skypename(ContactUrlToName(from));
+ debugLogA("Incoming message from %s", skypename);
+ if (IsMe(skypename))
{
recv.flags |= PREF_SENT;
MCONTACT hContact = GetContact(ContactUrlToName(convLink));
return ProtoChainRecvMsg(hContact, &recv);
}
- MCONTACT hContact = GetContact(ContactUrlToName(from));
+ MCONTACT hContact = GetContact(skypename);
return ProtoChainRecvMsg(hContact, &recv);
}
/* MESSAGE SENDING */
+struct SendMessageParam
+{
+ MCONTACT hContact;
+ HANDLE hMessage;
+};
+
// outcoming message flow
int CSkypeProto::OnSendMessage(MCONTACT hContact, int flags, const char *szMessage)
{
- UINT hMessage = InterlockedIncrement(&hMessageProcess);
+ ULONG hMessage = InterlockedIncrement(&hMessageProcess);
+
+ if (!IsOnline())
+ {
+ ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)"You cannot send when you are offline.");
+ return 0;
+ }
- SendMessageParam *param = (SendMessageParam*)mir_calloc(sizeof(SendMessageParam));
+ SendMessageParam *param = new SendMessageParam();
param->hContact = hContact;
param->hMessage = (HANDLE)hMessage;
- param->msg = szMessage;
- param->flags = flags;
- ForkThread(&CSkypeProto::SendMsgThread, (void*)param);
+ ptrA message;
+ if (flags & PREF_UNICODE)
+ message = mir_utf8encodeW((wchar_t*)&szMessage[mir_strlen(szMessage) + 1]);
+ else if (flags & PREF_UTF)
+ message = mir_strdup(szMessage);
+ else
+ message = mir_utf8encode(szMessage);
+
+ ptrA server(getStringA("Server"));
+ ptrA token(getStringA("registrationToken"));
+ ptrA username(getStringA(hContact, "Skypename"));
+ PushRequest(new SendMsgRequest(token, username, message, server), &CSkypeProto::OnMessageSent, param);
return hMessage;
}
-void CSkypeProto::SendMsgThread(void *arg)
+void CSkypeProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
{
SendMessageParam *param = (SendMessageParam*)arg;
+ MCONTACT hContact = param->hContact;
+ HANDLE hMessage = param->hMessage;
+ delete param;
- if (!IsOnline())
+ if (response->resultCode != 200 || response->resultCode != 201)
{
- ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hMessage, (LPARAM)Translate("You cannot send messages when you are offline."));
- mir_free(param);
+ CMStringA error = "Unknown error";
+ if (response)
+ {
+ JSONROOT root(response->pData);
+ JSONNODE *node = json_get(root, "errorCode");
+ error = _T2A(json_as_string(node));
+ }
+ ptrT username(getTStringA(hContact, "Skypename"));
+ debugLogA(__FUNCTION__": failed to send message for %s (%s)", username, error);
+ ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, hMessage, (LPARAM)error.GetBuffer());
return;
}
- CMStringA message = (param->flags & PREF_UNICODE) ? ptrA(mir_utf8encode(param->msg)) : param->msg; // TODO: mir_utf8encode check taken from FacebookRM, is it needed? Usually we get PREF_UTF8 flag instead.
-
- ptrA token(getStringA("registrationToken"));
- ptrA username(getStringA(param->hContact, "Skypename"));
- PushRequest(
- new SendMsgRequest(token, username, message, getStringA("Server"))/*,
- &CSkypeProto::OnMessageSent*/);
+ ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, hMessage, 0);
}
-void CSkypeProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
+void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response)
{
- SendMessageParam *param = (SendMessageParam*)arg;
-
- ptrT error(mir_tstrdup(TranslateT("Unknown error")));
- ptrT username(getTStringA(param->hContact, "Skypename"));
-
- if (response != NULL && (response->resultCode == 201 || response->resultCode == 200))
- {
- JSONROOT root(response->pData);
- JSONNODE *node = json_get(root, "errorCode");
- if (node)
- error = json_as_string(node);
- }
+ if (response == NULL)
+ return;
- int status = ACKRESULT_FAILED;
+ JSONROOT root(response->pData);
+ if (root == NULL)
+ return;
- if (error == NULL)
+ JSONNODE *conversations = json_as_array(json_get(root, "conversations"));
+ for (size_t i = 0; i < json_size(conversations); i++)
{
- status = ACKRESULT_SUCCESS;
+ JSONNODE *message = json_get(json_at(conversations, i), "lastMessage");
+
+ ptrA clientMsgId(mir_t2a(ptrT(json_as_string(json_get(message, "clientmessageid")))));
+ ptrA skypeEditedId(mir_t2a(ptrT(json_as_string(json_get(message, "skypeeditedid")))));
+ ptrA messageType(mir_t2a(ptrT(json_as_string(json_get(message, "messagetype")))));
+ ptrA from(mir_t2a(ptrT(json_as_string(json_get(message, "from")))));
+ ptrA content(mir_t2a(ptrT(json_as_string(json_get(message, "content")))));
+ ptrT composeTime(json_as_string(json_get(message, "composetime")));
+ ptrA conversationLink(mir_t2a(ptrT(json_as_string(json_get(message, "conversationLink")))));
+ time_t timestamp = IsoToUnixTime(composeTime);
+ if (conversationLink != NULL && strstr(conversationLink, "/8:"))
+ OnReceiveMessage(from, conversationLink, timestamp, content);
}
- else
- debugLog(_T("CSkypeProto::OnMessageSent: failed to send message for %s (%s)"), username, error);
-
- ProtoBroadcastAck(
- param->hContact,
- ACKTYPE_MESSAGE,
- status,
- param->hMessage,
- error);
}
\ No newline at end of file |