diff options
author | George Hazan <george.hazan@gmail.com> | 2024-05-03 21:20:54 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-05-03 21:20:54 +0300 |
commit | b6a037ba8b2bf275bafafd48d472d33c3886c7c6 (patch) | |
tree | ca24ed11c49da5b8d9aacfab67aac3b0be54e137 | |
parent | e0b13265d8b6c888bfe87047b2f895a8e0f6d2a7 (diff) |
Discord: fix for fake messages appearing when a channel is renamed
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 67 |
1 files 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;
|