From babe62f61852bb292c4eef1e64c316f21b789ef6 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Sat, 25 Apr 2015 18:43:32 +0000 Subject: SkypeWeb: "/me" in chats. git-svn-id: http://svn.miranda-ng.org/main/trunk@13144 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/requests/chatrooms.h | 25 ++++++++++++++ protocols/SkypeWeb/src/skype_chatrooms.cpp | 50 ++++++++++++++++++--------- protocols/SkypeWeb/src/skype_history_sync.cpp | 16 ++------- protocols/SkypeWeb/src/skype_proto.h | 2 +- 4 files changed, 63 insertions(+), 30 deletions(-) (limited to 'protocols/SkypeWeb') diff --git a/protocols/SkypeWeb/src/requests/chatrooms.h b/protocols/SkypeWeb/src/requests/chatrooms.h index 49a3ef9892..8ef23481ce 100644 --- a/protocols/SkypeWeb/src/requests/chatrooms.h +++ b/protocols/SkypeWeb/src/requests/chatrooms.h @@ -42,6 +42,31 @@ public: } }; +class SendChatActionRequest : public HttpRequest +{ +public: + SendChatActionRequest(const char *regToken, const char *id, time_t timestamp, const char *message, const char *server = SKYPE_ENDPOINTS_HOST) : + HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/19:%s/messages", server, id) + { + Headers + << CHAR_VALUE("Accept", "application/json, text/javascript") + << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) + << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); + + JSONNODE *node = json_new(5); + json_push_back(node, json_new_i("clientmessageid", timestamp)); + json_push_back(node, json_new_a("messagetype", "RichText")); + json_push_back(node, json_new_a("contenttype", "text")); + json_push_back(node, json_new_a("content", message)); + json_push_back(node, json_new_i("skypeemoteoffset", 4)); + + ptrA data(mir_utf8encodeT(ptrT(json_write(node)))); + Body << VALUE(data); + + json_delete(node); + } +}; + class CreateChatroomRequest : public HttpRequest { public: diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index d4fa10d41c..8b9e18e3fe 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -265,12 +265,13 @@ void CSkypeProto::OnChatEvent(JSONNODE *node) ptrA clientMsgId(mir_t2a(ptrT(json_as_string(json_get(node, "clientmessageid"))))); ptrA skypeEditedId(mir_t2a(ptrT(json_as_string(json_get(node, "skypeeditedid"))))); - ptrA from(mir_t2a(ptrT(json_as_string(json_get(node, "from"))))); + ptrA fromLink(mir_t2a(ptrT(json_as_string(json_get(node, "from"))))); + ptrA from(ContactUrlToName(fromLink)); time_t timestamp = IsoToUnixTime(ptrT(json_as_string(json_get(node, "composetime")))); ptrA content(mir_t2a(ptrT(json_as_string(json_get(node, "content"))))); - //int emoteOffset = json_as_int(json_get(node, "skypeemoteoffset")); + int emoteOffset = atoi(ptrA(mir_t2a(ptrT(json_as_string(json_get(node, "skypeemoteoffset")))))); ptrA conversationLink(mir_t2a(ptrT(json_as_string(json_get(node, "conversationLink"))))); ptrA chatname(ChatUrlToName(conversationLink)); @@ -282,19 +283,7 @@ void CSkypeProto::OnChatEvent(JSONNODE *node) ptrA messageType(mir_t2a(ptrT(json_as_string(json_get(node, "messagetype"))))); if (!mir_strcmpi(messageType, "Text") || !mir_strcmpi(messageType, "RichText")) { - GCDEST gcd = { m_szModuleName, ptrT(mir_a2t(chatname)), GC_EVENT_MESSAGE }; - GCEVENT gce = { sizeof(GCEVENT), &gcd }; - ptrA contactName(ContactUrlToName(from)); - ptrT tszName(mir_a2t(contactName)); - ptrA szHtml(RemoveHtml(content)); - ptrT tszHtml(mir_a2t(szHtml)); - gce.bIsMe = IsMe(contactName); - gce.ptszUID = tszName; - gce.time = timestamp; - gce.ptszNick = tszName; - gce.ptszText = tszHtml; - gce.dwFlags = GCEF_ADDTOLOG; - CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); + AddMessageToChat(_A2T(chatname), _A2T(from), content, emoteOffset != NULL, emoteOffset, timestamp); } else if (!mir_strcmpi(messageType, "ThreadActivity/AddMember")) { @@ -413,7 +402,36 @@ void CSkypeProto::OnSendChatMessage(const TCHAR *chat_id, const TCHAR * tszMessa return; ptrA szChatId(mir_t2a(chat_id)); ptrA szMessage(mir_t2a(tszMessage)); - SendRequest(new SendChatMessageRequest(RegToken, szChatId, time(NULL), szMessage, Server)); + if (strncmp(szMessage, "/me ", 4) == 0) + SendRequest(new SendChatActionRequest(RegToken, szChatId, time(NULL), szMessage, Server)); + else + SendRequest(new SendChatMessageRequest(RegToken, szChatId, time(NULL), szMessage, Server)); +} + +void CSkypeProto::AddMessageToChat(const TCHAR *chat_id, const TCHAR *from, const char *content, bool isAction, int emoteOffset, time_t timestamp, bool isLoading) +{ + GCDEST gcd = { m_szModuleName, chat_id, isAction? GC_EVENT_ACTION : GC_EVENT_MESSAGE }; + GCEVENT gce = { sizeof(GCEVENT), &gcd }; + + gce.bIsMe = IsMe(_T2A(from)); + gce.ptszNick = from; + gce.time = timestamp; + gce.ptszUID = from; + ptrA szHtml(RemoveHtml(content)); + ptrT tszHtml(mir_a2t(szHtml)); + if (!isAction) + { + gce.ptszText = tszHtml; + gce.dwFlags = GCEF_ADDTOLOG; + } + else + { + gce.ptszText = &tszHtml[emoteOffset]; + } + + if (isLoading) gce.dwFlags = GCEF_NOTNOTIFY; + + CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); } void CSkypeProto::OnGetChatInfo(const NETLIBHTTPREQUEST *response, void *p) diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index d0a119d5da..8621cce056 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -49,18 +49,16 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) 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"))))); + int emoteOffset = atoi(ptrA(mir_t2a(ptrT(json_as_string(json_get(message, "skypeemoteoffset")))))); time_t timestamp = IsoToUnixTime(composeTime); + ptrA skypename(ContactUrlToName(from)); bool isEdited = (json_get(message, "skypeeditedid") != NULL); if (conversationLink != NULL && strstr(conversationLink, "/8:")) { if (!mir_strcmpi(messageType, "Text") || !mir_strcmpi(messageType, "RichText")) { - int emoteOffset = json_as_int(json_get(message, "skypeemoteoffset")); - int flags = DBEF_UTF | DBEF_READ; - ptrA skypename(ContactUrlToName(from)); - bool isMe = IsMe(skypename); if (isMe) flags |= DBEF_SENT; @@ -149,15 +147,7 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) ptrA chatname(ChatUrlToName(conversationLink)); if (!mir_strcmpi(messageType, "Text") || !mir_strcmpi(messageType, "RichText")) { - GCDEST gcd = { m_szModuleName, _A2T(chatname), GC_EVENT_MESSAGE }; - GCEVENT gce = { sizeof(GCEVENT), &gcd }; - gce.bIsMe = IsMe(ContactUrlToName(from)); - gce.ptszUID = mir_a2t(ContactUrlToName(from)); - gce.time = timestamp; - gce.ptszNick = mir_a2t(ContactUrlToName(from)); - gce.ptszText = mir_a2t(RemoveHtml(content)); - gce.dwFlags = GCEF_NOTNOTIFY; - CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); + AddMessageToChat(_A2T(chatname), _A2T(skypename), content, emoteOffset != NULL, emoteOffset, timestamp, true); } } } diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index d82d0bfbae..bd10b13f9d 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -232,7 +232,7 @@ private: void OnSendChatMessage(const TCHAR *chat_id, const TCHAR * tszMessage); char *GetChatUsers(const TCHAR *chat_id); bool IsChatContact(const TCHAR *chat_id, const char *id); - + void AddMessageToChat(const TCHAR *chat_id, const TCHAR *from, const char *content, bool isAction, int emoteOffset, time_t timestamp, bool isLoading = false); void AddChatContact(const TCHAR *tchat_id, const char *id, const char *name, const TCHAR *role, bool isChange = false); void RemoveChatContact(const TCHAR *tchat_id, const char *id, const char *name, bool isKick = false, const char *initiator = ""); -- cgit v1.2.3