summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-04-04 23:59:15 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-04-04 23:59:15 +0000
commitc7dee6cae5b897d62749430a33cba0351b1f0ace (patch)
tree12e38b58a6c4629ce29971efaaeaba61a5bd8d91
parent04da76c5fae4f4ef3eda995641b0251671d6edd0 (diff)
SkypeWeb: code cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@12601 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--protocols/SkypeWeb/src/requests/messages.h6
-rw-r--r--protocols/SkypeWeb/src/skype_messages.cpp36
-rw-r--r--protocols/SkypeWeb/src/skype_proto.h2
-rw-r--r--protocols/SkypeWeb/src/skype_utils.cpp2
4 files changed, 25 insertions, 21 deletions
diff --git a/protocols/SkypeWeb/src/requests/messages.h b/protocols/SkypeWeb/src/requests/messages.h
index c3ac040579..8dde3f9b5a 100644
--- a/protocols/SkypeWeb/src/requests/messages.h
+++ b/protocols/SkypeWeb/src/requests/messages.h
@@ -4,7 +4,7 @@
class SendMsgRequest : public HttpRequest
{
public:
- SendMsgRequest(const char *regToken, const char *username, const char *clientMsgId, const char *message, const char *server = "client-s.gateway.messenger.live.com") :
+ SendMsgRequest(const char *regToken, const char *username, time_t timestamp, const char *message, const char *server = "client-s.gateway.messenger.live.com") :
HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages", server, username)
{
Headers
@@ -18,7 +18,7 @@ public:
<< CHAR_VALUE("Connection", "keep-alive");
CMStringA data;
- data.AppendFormat("{\"clientmessageid\":\"%s\",\"content\":\"%s\",\"messagetype\":\"RichText\",\"contenttype\":\"text\"}", clientMsgId, message);
+ data.AppendFormat("{\"clientmessageid\":\"%lld\",\"content\":\"%s\",\"messagetype\":\"RichText\",\"contenttype\":\"text\"}", timestamp, message);
Body << VALUE(data);
}
@@ -43,7 +43,7 @@ public:
if (bstate) state = "Control/Typing";
else state = "Control/ClearTyping";
CMStringA data;
- data.AppendFormat("{\"clienmessageid\":%d, \"content\":\"\", \"messagetype\":\"%s\", \"contenttype\":\"text\"}", time(NULL), state);
+ data.AppendFormat("{\"clienmessageid\":%lld, \"content\":\"\", \"messagetype\":\"%s\", \"contenttype\":\"text\"}", time(NULL), state);
Body << VALUE(data);
}
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp
index 66c53fc29d..89231ff905 100644
--- a/protocols/SkypeWeb/src/skype_messages.cpp
+++ b/protocols/SkypeWeb/src/skype_messages.cpp
@@ -3,7 +3,7 @@
/* MESSAGE RECEIVING */
// incoming message flow
-int CSkypeProto::OnReceiveMessage(const char *messageId, const char *from, const char *to, time_t timestamp, char *content, int emoteOffset)
+int CSkypeProto::OnReceiveMessage(const char *messageId, const char *from, const char *to, time_t timestamp, char *content, int emoteOffset, bool isRead)
{
setDword("LastMsgTime", timestamp);
PROTORECVEVENT recv = { 0 };
@@ -15,14 +15,15 @@ int CSkypeProto::OnReceiveMessage(const char *messageId, const char *from, const
: SKYPE_DB_EVENT_TYPE_ACTION;
recv.pCustomData = (void*)messageId;
recv.cbCustomDataSize = mir_strlen(messageId);
-
+ if (isRead)
+ recv.flags |= PREF_CREATEREAD;
ptrA skypename(ContactUrlToName(from));
debugLogA("Incoming message from %s", skypename);
if (IsMe(skypename))
{
recv.flags |= PREF_SENT;
MCONTACT hContact = GetContact(ptrA(ContactUrlToName(to)));
- return ProtoChainRecvMsg(hContact, &recv);
+ return SaveMessageToDb(hContact, &recv);
}
MCONTACT hContact = GetContact(skypename);
return ProtoChainRecvMsg(hContact, &recv);
@@ -39,6 +40,10 @@ int CSkypeProto::SaveMessageToDb(MCONTACT hContact, PROTORECVEVENT *pre)
dbei.szModule = GetContactProto(hContact);
dbei.timestamp = pre->timestamp;
dbei.flags = DBEF_UTF;
+ if ((pre->flags & PREF_CREATEREAD) == PREF_CREATEREAD)
+ dbei.flags |= DBEF_READ;
+ if ((pre->flags & PREF_SENT) == PREF_SENT)
+ dbei.flags |= DBEF_SENT;
dbei.eventType = pre->lParam;
dbei.cbBlob = (DWORD)strlen(pre->szMessage) + 1;
dbei.pBlob = (PBYTE)pre->szMessage;
@@ -52,13 +57,12 @@ struct SendMessageParam
{
MCONTACT hContact;
HANDLE hMessage;
- char *clientMsgId;
};
// outcoming message flow
int CSkypeProto::OnSendMessage(MCONTACT hContact, int flags, const char *szMessage)
{
- ULONG hMessage = InterlockedIncrement(&hMessageProcess);
+ time_t timestamp = time(NULL); //InterlockedIncrement(&hMessageProcess);
if (!IsOnline())
{
@@ -66,11 +70,9 @@ int CSkypeProto::OnSendMessage(MCONTACT hContact, int flags, const char *szMessa
return 0;
}
- CMStringA clientMsgId(FORMAT, "%d000", time(NULL));
SendMessageParam *param = new SendMessageParam();
param->hContact = hContact;
- param->hMessage = (HANDLE)hMessage;
- param->clientMsgId = mir_strdup(clientMsgId);
+ param->hMessage = (HANDLE)timestamp;
ptrA message;
if (flags & PREF_UNICODE)
@@ -87,9 +89,9 @@ int CSkypeProto::OnSendMessage(MCONTACT hContact, int flags, const char *szMessa
{
// TODO: make /me action send when it will work in skype web
}
- PushRequest(new SendMsgRequest(token, username, clientMsgId, message, server), &CSkypeProto::OnMessageSent, param);
+ PushRequest(new SendMsgRequest(token, username, timestamp, message, server), &CSkypeProto::OnMessageSent, param);
- return hMessage;
+ return timestamp;
}
void CSkypeProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
@@ -97,7 +99,6 @@ void CSkypeProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
SendMessageParam *param = (SendMessageParam*)arg;
MCONTACT hContact = param->hContact;
HANDLE hMessage = param->hMessage;
- ptrA clientMsgId(param->clientMsgId);
delete param;
if (response->resultCode != 200 && response->resultCode != 201)
@@ -129,12 +130,15 @@ int CSkypeProto::OnPreCreateMessage(WPARAM, LPARAM lParam)
if (strncmp(message, "/me ", 4) == 0)
{
evt->dbei->cbBlob = evt->dbei->cbBlob - 4;
- PBYTE action = (PBYTE)mir_alloc(evt->dbei->cbBlob);
- memcpy(action, &evt->dbei->pBlob[4], evt->dbei->cbBlob);
- mir_free(evt->dbei->pBlob);
- evt->dbei->pBlob = action;
+ memcpy(&evt->dbei->pBlob, &evt->dbei->pBlob[4], evt->dbei->cbBlob);
evt->dbei->eventType = SKYPE_DB_EVENT_TYPE_ACTION;
}
+ char messageId[20];
+ itoa(evt->seq, messageId, 10);
+ int messageIdLength = mir_strlen(messageId);
+ evt->dbei->pBlob = (PBYTE)mir_realloc(evt->dbei->pBlob, evt->dbei->cbBlob + messageIdLength);
+ memcpy((char *)&evt->dbei->pBlob[evt->dbei->cbBlob], messageId, messageIdLength);
+ evt->dbei->cbBlob += messageIdLength;
return 1;
}
@@ -166,7 +170,7 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response)
if (conversationLink != NULL && strstr(conversationLink, "/8:"))
{
int emoteOffset = json_as_int(json_get(message, "skypeemoteoffset"));
- OnReceiveMessage(clientMsgId, from, conversationLink, timestamp, content, emoteOffset);
+ OnReceiveMessage(clientMsgId, from, conversationLink, timestamp, content, emoteOffset, true);
}
}
} \ No newline at end of file
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h
index 6de26e05d5..52219480d1 100644
--- a/protocols/SkypeWeb/src/skype_proto.h
+++ b/protocols/SkypeWeb/src/skype_proto.h
@@ -174,7 +174,7 @@ private:
int __cdecl OnContactDeleted(MCONTACT, LPARAM);
// messages
- int OnReceiveMessage(const char *messageId, const char *from, const char *to, time_t timestamp, char *content, int emoteOffset = 0);
+ int OnReceiveMessage(const char *messageId, const char *from, const char *to, time_t timestamp, char *content, int emoteOffset = 0, bool isRead = false);
int SaveMessageToDb(MCONTACT hContact, PROTORECVEVENT *pre);
int OnSendMessage(MCONTACT hContact, int flags, const char *message);
diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp
index 4b3723dfe3..0ec221a7e5 100644
--- a/protocols/SkypeWeb/src/skype_utils.cpp
+++ b/protocols/SkypeWeb/src/skype_utils.cpp
@@ -70,7 +70,7 @@ bool CSkypeProto::IsMe(const char *skypeName)
{
ptrA mySkypeName(getStringA("Skypename"));
ptrA SelfEndpointName(getStringA("SelfEndpointName"));
- if (!lstrcmpA(skypeName, mySkypeName) || !lstrcmpA(skypeName, SelfEndpointName))
+ if (!mir_strcmp(skypeName, mySkypeName) || !mir_strcmp(skypeName, SelfEndpointName))
return true;
return false;