From 9ae68086db58149b0b582240de8fab33ed1475a7 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 7 May 2024 16:53:17 +0300 Subject: =?UTF-8?q?fixes=20#4407=20(Discord:=20=D0=B7=D0=B0=D0=B3=D1=80?= =?UTF-8?q?=D1=83=D0=B6=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20=D1=81=20=D1=81?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0=20=D0=B8=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D1=8F=20=D0=BD=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=B3?= =?UTF-8?q?=D1=80=D1=83=D0=B6=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D1=81=D0=B0?= =?UTF-8?q?=D0=BC=D0=B0=20=D0=B2=20=D0=B6=D1=83=D1=80=D0=BD=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=BE=D1=82=D0=BA=D1=80=D1=8B=D1=82=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=BE=D0=BA=D0=BD=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Discord/src/dispatch.cpp | 30 +++++++++++++----------------- protocols/Discord/src/proto.cpp | 3 ++- protocols/Discord/src/server.cpp | 12 +++--------- 3 files changed, 18 insertions(+), 27 deletions(-) (limited to 'protocols/Discord/src') diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 01e976be2b..9ad3d83457 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -508,29 +508,22 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) 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; - } - } - } + MEVENT hOldEvent = (bIsNew) ? 0 : db_event_getById(m_szModuleName, szMsgId); 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; + DB::EventInfo dbei(hOldEvent); if (bOurMessage) - dbei.flags = DBEF_READ | DBEF_SENT; + dbei.flags |= DBEF_READ | DBEF_SENT; + + if (dbei) { + ptrW wszOldText(DbEvent_GetTextW(&dbei)); + if (wszOldText) + wszText.Insert(0, wszOldText); + } debugLogA("store a message from private user %lld, channel id %lld", pUser->id, pUser->channelId); ptrA buf(mir_utf8encodeW(wszText)); @@ -544,7 +537,10 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) ProcessChatUser(pUser, userId, pRoot); } - ProtoChainRecvMsg(pUser->hContact, dbei); + if (dbei) + db_event_edit(dbei.getEvent(), &dbei, true); + else + ProtoChainRecvMsg(pUser->hContact, dbei); } } diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 6e084dee1d..7d260bf6dd 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -224,7 +224,8 @@ INT_PTR CDiscordProto::GetCaps(int type, MCONTACT) case PFLAGNUM_3: return PF2_ONLINE | PF2_SHORTAWAY | PF2_HEAVYDND | PF2_INVISIBLE; case PFLAGNUM_4: - return PF4_FORCEAUTH | PF4_NOCUSTOMAUTH | PF4_NOAUTHDENYREASON | PF4_SUPPORTTYPING | PF4_SUPPORTIDLE | PF4_AVATARS | PF4_IMSENDOFFLINE | PF4_SERVERMSGID | PF4_OFFLINEFILES; + return PF4_FORCEAUTH | PF4_NOCUSTOMAUTH | PF4_NOAUTHDENYREASON | PF4_SUPPORTTYPING | PF4_SUPPORTIDLE | PF4_AVATARS | + PF4_IMSENDOFFLINE | PF4_SERVERMSGID | PF4_OFFLINEFILES | PF4_GROUPCHATFILES; case PFLAG_UNIQUEIDTEXT: return (INT_PTR)TranslateT("User ID"); } diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index fc406e600c..3d538dda53 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -110,7 +110,7 @@ void CDiscordProto::OnReceiveHistory(MHttpResponse *pReply, AsyncHttpRequest *pR else dbei.flags &= ~DBEF_READ; - if (!pUser->bIsPrivate) { + if (!pUser->bIsPrivate || pUser->bIsGroup) { dbei.szUserId = szUserId; ProcessChatUser(pUser, _atoi64(szUserId), pNode); } @@ -122,14 +122,8 @@ void CDiscordProto::OnReceiveHistory(MHttpResponse *pReply, AsyncHttpRequest *pR bool bSucceeded = false; char szMsgId[100]; _i64toa_s(msgid, szMsgId, _countof(szMsgId), 10); - MEVENT hDbEvent = db_event_getById(m_szModuleName, szMsgId); - if (hDbEvent != 0) - bSucceeded = 0 == db_event_edit(hDbEvent, &dbei, true); - - if (!bSucceeded) { - dbei.szId = szMsgId; - db_event_add(pUser->hContact, &dbei); - } + dbei.szId = szMsgId; + db_event_replace(pUser->hContact, &dbei); if (lastId < msgid) lastId = msgid; -- cgit v1.2.3