summaryrefslogtreecommitdiff
path: root/protocols/Discord
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-10-29 18:15:09 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-10-29 18:15:09 +0300
commit767c5e08a6e63cba75da64d2d344339ea72d70bd (patch)
tree56236879980d87a1a56e260dc41d8f732832252d /protocols/Discord
parent3217ab9478e5f2a304e44cebd2e6ea7825a42f8c (diff)
fixes #1633 ([Discord] Sending a message with a link causes the message to be discarded)
Diffstat (limited to 'protocols/Discord')
-rw-r--r--protocols/Discord/src/dispatch.cpp31
-rw-r--r--protocols/Discord/src/proto.h4
2 files changed, 31 insertions, 4 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 002f45fb36..f48f789c44 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -43,8 +43,8 @@ static handlers[] = // these structures must me sorted alphabetically
{ L"GUILD_SYNC", &CDiscordProto::OnCommandGuildSync },
{ L"MESSAGE_ACK", &CDiscordProto::OnCommandMessageAck },
- { L"MESSAGE_CREATE", &CDiscordProto::OnCommandMessage },
- { L"MESSAGE_UPDATE", &CDiscordProto::OnCommandMessage },
+ { L"MESSAGE_CREATE", &CDiscordProto::OnCommandMessageCreate },
+ { L"MESSAGE_UPDATE", &CDiscordProto::OnCommandMessageUpdate },
{ L"PRESENCE_UPDATE", &CDiscordProto::OnCommandPresence },
@@ -309,7 +309,17 @@ void CDiscordProto::OnCommandRoleDeleted(const JSONNode &pRoot)
/////////////////////////////////////////////////////////////////////////////////////////
// reading a new message
-void CDiscordProto::OnCommandMessage(const JSONNode &pRoot)
+void CDiscordProto::OnCommandMessageCreate(const JSONNode &pRoot)
+{
+ OnCommandMessage(pRoot, true);
+}
+
+void CDiscordProto::OnCommandMessageUpdate(const JSONNode &pRoot)
+{
+ OnCommandMessage(pRoot, false);
+}
+
+void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew)
{
CMStringW wszMessageId = pRoot["id"].as_mstring();
CMStringW wszUserId = pRoot["author"]["id"].as_mstring();
@@ -341,6 +351,21 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot)
else {
CMStringW wszText = PrepareMessageText(pRoot);
+ if (!bIsNew) {
+ MEVENT hOldEvent = db_event_getById(m_szModuleName, szMsgId);
+ if (hOldEvent) {
+ DBEVENTINFO dbei = {};
+ dbei.cbBlob = db_event_getBlobSize(hOldEvent);
+ dbei.pBlob = (BYTE*)mir_alloc(dbei.cbBlob);
+ if (!db_event_get(hOldEvent, &dbei)) {
+ ptrW wszOldText(DbEvent_GetTextW(&dbei, CP_UTF8));
+ if (wszOldText)
+ wszText.Insert(0, wszOldText);
+ }
+ mir_free(dbei.pBlob);
+ }
+ }
+
const JSONNode &edited = pRoot["edited_timestamp"];
if (!edited.isnull())
wszText.AppendFormat(L" (%s %s)", TranslateT("edited at"), edited.as_mstring().c_str());
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index 5789cebbb3..5fc60038cb 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -336,7 +336,9 @@ public:
void OnCommandGuildSync(const JSONNode&);
void OnCommandFriendAdded(const JSONNode&);
void OnCommandFriendRemoved(const JSONNode&);
- void OnCommandMessage(const JSONNode&);
+ void OnCommandMessage(const JSONNode&, bool);
+ void OnCommandMessageCreate(const JSONNode&);
+ void OnCommandMessageUpdate(const JSONNode&);
void OnCommandMessageAck(const JSONNode&);
void OnCommandPresence(const JSONNode&);
void OnCommandReady(const JSONNode&);