diff options
-rw-r--r-- | protocols/SkypeWeb/src/requests/chatrooms.h | 29 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_chatrooms.cpp | 20 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_messages.cpp | 49 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.cpp | 15 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.h | 2 |
5 files changed, 41 insertions, 74 deletions
diff --git a/protocols/SkypeWeb/src/requests/chatrooms.h b/protocols/SkypeWeb/src/requests/chatrooms.h index 81151fd97a..4bad87bc8a 100644 --- a/protocols/SkypeWeb/src/requests/chatrooms.h +++ b/protocols/SkypeWeb/src/requests/chatrooms.h @@ -18,35 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #ifndef _SKYPE_REQUEST_CHATS_H_
#define _SKYPE_REQUEST_CHATS_H_
-struct SendChatMessageRequest : public AsyncHttpRequest
-{
- SendChatMessageRequest(const char *to, time_t timestamp, const char *message) :
- AsyncHttpRequest(REQUEST_POST, HOST_DEFAULT)
- {
- m_szUrl.AppendFormat("/users/ME/conversations/%s/messages", to);
-
- JSONNode node;
- node << CHAR_PARAM("clientmessageid", CMStringA(::FORMAT, "%llu000", (ULONGLONG)timestamp))
- << CHAR_PARAM("messagetype", "RichText") << CHAR_PARAM("contenttype", "text") << CHAR_PARAM("content", message);
- m_szParam = node.write().c_str();
- }
-};
-
-struct SendChatActionRequest : public AsyncHttpRequest
-{
- SendChatActionRequest(const char *to, time_t timestamp, const char *message) :
- AsyncHttpRequest(REQUEST_POST, HOST_DEFAULT)
- {
- m_szUrl.AppendFormat("/users/ME/conversations/%s/messages", to);
-
- JSONNode node(JSON_NODE);
- node << CHAR_PARAM("clientmessageid", CMStringA(::FORMAT, "%llu000", (ULONGLONG)timestamp))
- << CHAR_PARAM("messagetype", "RichText") << CHAR_PARAM("contenttype", "text")
- << CHAR_PARAM("content", message) << INT_PARAM("skypeemoteoffset", 4);
- m_szParam = node.write().c_str();
- }
-};
-
struct CreateChatroomRequest : public AsyncHttpRequest
{
CreateChatroomRequest(const LIST<char> &skypenames, CSkypeProto *ppro) :
diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index de34a66fa8..e73fc74629 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -325,22 +325,32 @@ bool CSkypeProto::OnChatEvent(const JSONNode &node) return false;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
void CSkypeProto::SendChatMessage(SESSION_INFO *si, const wchar_t *tszMessage)
{
if (!IsOnline())
return;
- T2Utf chat_id(si->ptszID);
CMStringA szMessage(ptrA(mir_utf8encodeW(tszMessage)));
szMessage.TrimRight();
- AddBbcodes(szMessage);
+ bool bRich = AddBbcodes(szMessage);
+
+ CMStringA szUrl = "/users/ME/conversations/" + mir_urlEncode(T2Utf(si->ptszID)) + "/messages";
+ AsyncHttpRequest *pReq = new AsyncHttpRequest(REQUEST_POST, HOST_DEFAULT, szUrl, &CSkypeProto::OnMessageSent);
+ JSONNode node;
+ node << CHAR_PARAM("clientmessageid", CMStringA(::FORMAT, "%llu000", (ULONGLONG)time(0)))
+ << CHAR_PARAM("messagetype", bRich ? "RichText" : "Text") << CHAR_PARAM("contenttype", "text") << CHAR_PARAM("content", szMessage);
if (strncmp(szMessage, "/me ", 4) == 0)
- PushRequest(new SendChatActionRequest(chat_id, time(0), szMessage));
- else
- PushRequest(new SendChatMessageRequest(chat_id, time(0), szMessage));
+ node << INT_PARAM("skypeemoteoffset", 4);
+ pReq->m_szParam = node.write().c_str();
+
+ PushRequest(pReq);
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
void CSkypeProto::OnGetChatMembers(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
JsonReply reply(response);
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 6ec31d0df5..7296e9d7eb 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -20,37 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /////////////////////////////////////////////////////////////////////////////////////////
// MESSAGE SENDING
-struct SendMessageRequest : public AsyncHttpRequest
-{
- SendMessageRequest(const char *username, time_t timestamp, const char *message, const char *MessageType = nullptr) :
- AsyncHttpRequest(REQUEST_POST, HOST_DEFAULT, 0, &CSkypeProto::OnMessageSent)
- {
- m_szUrl.AppendFormat("/users/ME/conversations/%s/messages", mir_urlEncode(username).c_str());
-
- JSONNode node;
- node << INT64_PARAM("clientmessageid", timestamp) << CHAR_PARAM("messagetype", MessageType ? MessageType : "Text")
- << CHAR_PARAM("contenttype", "text") << CHAR_PARAM("content", message);
- m_szParam = node.write().c_str();
- }
-};
-
-struct SendActionRequest : public AsyncHttpRequest
-{
- SendActionRequest(const char *username, time_t timestamp, const char *message, CSkypeProto *ppro) :
- AsyncHttpRequest(REQUEST_POST, HOST_DEFAULT, 0, &CSkypeProto::OnMessageSent)
- {
- m_szUrl.AppendFormat("/users/ME/conversations/%s/messages", mir_urlEncode(username).c_str());
-
- CMStringA content;
- content.AppendFormat("%s %s", ppro->m_szSkypename.c_str(), message);
-
- JSONNode node;
- node << INT64_PARAM("clientmessageid", timestamp) << CHAR_PARAM("messagetype", "RichText") << CHAR_PARAM("contenttype", "text")
- << CHAR_PARAM("content", content) << INT_PARAM("skypeemoteoffset", ppro->m_szSkypename.GetLength() + 1);
- m_szParam = node.write().c_str();
- }
-};
-
void CSkypeProto::OnMessageSent(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
MCONTACT hContact = pRequest->hContact;
@@ -84,15 +53,21 @@ int CSkypeProto::SendMsg(MCONTACT hContact, MEVENT, const char *szMessage) hMessage &= ~0x80000000;
CMStringA str(szMessage);
- AddBbcodes(str);
+ bool bRich = AddBbcodes(str);
- AsyncHttpRequest *pReq;
- if (strncmp(str, "/me ", 4) == 0)
- pReq = new SendActionRequest(getId(hContact), hMessage, str.c_str() + 4, this);
- else
- pReq = new SendMessageRequest(getId(hContact), hMessage, str);
+ CMStringA szUrl = "/users/ME/conversations/" + mir_urlEncode(getId(hContact)) + "/messages";
+ AsyncHttpRequest *pReq = new AsyncHttpRequest(REQUEST_POST, HOST_DEFAULT, szUrl, &CSkypeProto::OnMessageSent);
pReq->hContact = hContact;
pReq->pUserInfo = (HANDLE)hMessage;
+
+ JSONNode node;
+ node << INT64_PARAM("clientmessageid", hMessage) << CHAR_PARAM("messagetype", bRich ? "RichText" : "Text") << CHAR_PARAM("contenttype", "text");
+ if (strncmp(str, "/me ", 4) == 0)
+ node << CHAR_PARAM("content", m_szSkypename + " " + str);
+ else
+ node << CHAR_PARAM("content", str);
+ pReq->m_szParam = node.write().c_str();
+
PushRequest(pReq);
mir_cslock lck(m_lckOutMessagesList);
diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index 0866a2cc75..06b2706f41 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -476,8 +476,9 @@ CMStringW CSkypeProto::RemoveHtml(const CMStringW &data, bool bCheckSS) return new_string;
}
-void AddBbcodes(CMStringA &str)
+bool AddBbcodes(CMStringA &str)
{
+ bool bUsed = false;
CMStringA ret;
for (const char *p = str; *p; p++) {
@@ -486,40 +487,50 @@ void AddBbcodes(CMStringA &str) if (!strncmp(p, "b]", 2)) {
p++;
ret.Append("<b _pre=\"*\" _post=\"*\">");
+ bUsed = true;
}
else if (!strncmp(p, "/b]", 3)) {
p += 2;
ret.Append("</b>");
+ bUsed = true;
}
else if (!strncmp(p, "i]", 2)) {
p++;
ret.Append("<i _pre=\"_\" _post=\"_\">");
+ bUsed = true;
}
else if (!strncmp(p, "/i]", 3)) {
p += 2;
ret.Append("</i>");
+ bUsed = true;
}
else if (!strncmp(p, "s]", 2)) {
p++;
ret.Append("<s _pre=\"~\" _post=\"~\">");
+ bUsed = true;
}
else if (!strncmp(p, "/s]", 3)) {
p += 2;
ret.Append("</s>");
+ bUsed = true;
}
else if (!strncmp(p, "code]", 5)) {
p += 4;
ret.Append("<pre _pre=\"```\" _post=\"```\">");
+ bUsed = true;
}
else if (!strncmp(p, "/code]", 6)) {
p += 5;
ret.Append("</pre>");
+ bUsed = true;
}
}
else ret.AppendChar(*p);
}
- str = ret;
+ if (bUsed)
+ str = ret;
+ return bUsed;
}
//////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/SkypeWeb/src/skype_utils.h b/protocols/SkypeWeb/src/skype_utils.h index 718cbc68d4..fcc6d17788 100644 --- a/protocols/SkypeWeb/src/skype_utils.h +++ b/protocols/SkypeWeb/src/skype_utils.h @@ -26,7 +26,7 @@ const wchar_t* GetSkypeNick(const wchar_t *szSkypeId); CMStringA ParseUrl(const char *url, const char *token);
-void AddBbcodes(CMStringA &str);
+bool AddBbcodes(CMStringA &str);
bool IsPossibleUserType(const char *pszUserId);
|