From b6a037ba8b2bf275bafafd48d472d33c3886c7c6 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 3 May 2024 21:20:54 +0300 Subject: Discord: fix for fake messages appearing when a channel is renamed --- protocols/Discord/src/dispatch.cpp | 67 ++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 604d82a01b..c6efbd151e 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -429,45 +429,50 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) if (wszText.IsEmpty()) return; - // old message? try to restore it from database - bool bOurMessage = userId == m_ownId; - if (!bIsNew) { - MEVENT hOldEvent = db_event_getById(m_szModuleName, szMsgId); - if (hOldEvent) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (!db_event_get(hOldEvent, &dbei)) { - ptrW wszOldText(DbEvent_GetTextW(&dbei)); - if (wszOldText) - wszText.Insert(0, wszOldText); - if (dbei.flags & DBEF_SENT) - bOurMessage = true; + if (pRoot["type"].as_int() == 4 && pUser->si) { + setWString(pUser->si->hContact, "Nick", wszText); + } + else { + // old message? try to restore it from database + bool bOurMessage = userId == m_ownId; + if (!bIsNew) { + MEVENT hOldEvent = db_event_getById(m_szModuleName, szMsgId); + if (hOldEvent) { + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (!db_event_get(hOldEvent, &dbei)) { + ptrW wszOldText(DbEvent_GetTextW(&dbei)); + if (wszOldText) + wszText.Insert(0, wszOldText); + if (dbei.flags & DBEF_SENT) + bOurMessage = true; + } } } - } - const JSONNode &edited = pRoot["edited_timestamp"]; - if (!edited.isnull()) - wszText.AppendFormat(L" (%s %s)", TranslateT("edited at"), edited.as_mstring().c_str()); + const JSONNode &edited = pRoot["edited_timestamp"]; + if (!edited.isnull()) + wszText.AppendFormat(L" (%s %s)", TranslateT("edited at"), edited.as_mstring().c_str()); - // if a message has myself as an author, add some flags - DB::EventInfo dbei; - if (bOurMessage) - dbei.flags = DBEF_READ | DBEF_SENT; + // if a message has myself as an author, add some flags + DB::EventInfo dbei; + if (bOurMessage) + dbei.flags = DBEF_READ | DBEF_SENT; - debugLogA("store a message from private user %lld, channel id %lld", pUser->id, pUser->channelId); - ptrA buf(mir_utf8encodeW(wszText)); + debugLogA("store a message from private user %lld, channel id %lld", pUser->id, pUser->channelId); + ptrA buf(mir_utf8encodeW(wszText)); - dbei.timestamp = (uint32_t)StringToDate(pRoot["timestamp"].as_mstring()); - dbei.pBlob = buf; - dbei.szId = szMsgId; + dbei.timestamp = (uint32_t)StringToDate(pRoot["timestamp"].as_mstring()); + dbei.pBlob = buf; + dbei.szId = szMsgId; - if (!pUser->bIsPrivate || pUser->bIsGroup) { - dbei.szUserId = szUserId; - ProcessChatUser(pUser, userId, pRoot); - } + if (!pUser->bIsPrivate || pUser->bIsGroup) { + dbei.szUserId = szUserId; + ProcessChatUser(pUser, userId, pRoot); + } - ProtoChainRecvMsg(pUser->hContact, dbei); + ProtoChainRecvMsg(pUser->hContact, dbei); + } } pUser->lastMsgId = msgId; -- cgit v1.2.3