diff options
author | George Hazan <ghazan@miranda.im> | 2017-02-02 21:20:40 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-02-02 21:20:40 +0300 |
commit | 38d7885b91b6026b1a518e8c7d34172a08da4c87 (patch) | |
tree | e687f597a185097e43f2815600a6ded03e157075 | |
parent | b8b21e44668a2528932dd134f3791f2eabf68cf2 (diff) |
Discord: message formatting now includes the list of attachments (if present)
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 2 | ||||
-rw-r--r-- | protocols/Discord/src/server.cpp | 3 | ||||
-rw-r--r-- | protocols/Discord/src/stdafx.h | 1 | ||||
-rw-r--r-- | protocols/Discord/src/utils.cpp | 23 |
4 files changed, 27 insertions, 2 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 9f9ae06841..17b7a28b98 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -193,7 +193,7 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot) if (_wtoi64(wszUserId) == m_ownId) recv.flags = PREF_CREATEREAD | PREF_SENT; - CMStringW wszText = pRoot["content"].as_mstring(); + CMStringW wszText = PrepareMessageText(pRoot); const JSONNode &edited = pRoot["edited_timestamp"]; if (!edited.isnull()) diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index 5d86ec1721..203380c994 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -92,7 +92,8 @@ void CDiscordProto::OnReceiveHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest else dbei.flags &= ~DBEF_READ; - CMStringA szBody(ptrA(mir_utf8encodeW(p["content"].as_mstring()))); + CMStringW wszText = PrepareMessageText(p); + CMStringA szBody(ptrA(mir_utf8encodeW(wszText))); szBody.AppendFormat("%c%lld", 0, msgid); dbei.timestamp = StringToDate(p["timestamp"].as_mstring()); diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h index 7fe4d87f13..01f35bfb35 100644 --- a/protocols/Discord/src/stdafx.h +++ b/protocols/Discord/src/stdafx.h @@ -64,6 +64,7 @@ extern HWND g_hwndHeartbeat; #define DB_KEY_GROUP "GroupName" #define DB_KEYVAL_GROUP L"Discord" +CMStringW PrepareMessageText(const JSONNode &pRoot); int StrToStatus(const CMStringW &str); time_t StringToDate(const CMStringW &str); int SerialNext(void);
\ No newline at end of file diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index de86bef956..8a2041c534 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -215,6 +215,29 @@ CDiscordUser* CDiscordProto::PrepareUser(const JSONNode &user) ///////////////////////////////////////////////////////////////////////////////////////// +CMStringW PrepareMessageText(const JSONNode &pRoot) +{ + CMStringW wszText = pRoot["content"].as_mstring(); + + bool bDelimiterAdded = false; + const JSONNode &pAttaches = pRoot["attachments"]; + for (auto it = pAttaches.begin(); it != pAttaches.end(); ++it) { + const JSONNode &p = *it; + CMStringW wszUrl = p["url"].as_mstring(); + if (!wszUrl.IsEmpty()) { + if (!bDelimiterAdded) { + bDelimiterAdded = true; + wszText.Append(L"\n-----------------"); + } + wszText.AppendFormat(L"\n%s: %s", TranslateT("Attachment"), wszUrl); + } + } + + return wszText; +} + +///////////////////////////////////////////////////////////////////////////////////////// + void CDiscordProto::ProcessType(CDiscordUser *pUser, const JSONNode &pRoot) { switch (pRoot["type"].as_int()) { |