diff options
author | George Hazan <george.hazan@gmail.com> | 2024-05-07 16:53:17 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-05-07 16:53:17 +0300 |
commit | 9ae68086db58149b0b582240de8fab33ed1475a7 (patch) | |
tree | 774620d4b3f0b1371447d2c11f53bf50048c7e2a /protocols/Discord | |
parent | e1be49166a3e9b41f41192f5c3e7343f0e82480c (diff) |
fixes #4407 (Discord: загруженная с сервера история не подгружается сама в журнал при открытии окна)
Diffstat (limited to 'protocols/Discord')
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 30 | ||||
-rw-r--r-- | protocols/Discord/src/proto.cpp | 3 | ||||
-rw-r--r-- | protocols/Discord/src/server.cpp | 12 |
3 files changed, 18 insertions, 27 deletions
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;
|