summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-05-04 18:05:48 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-05-04 18:05:48 +0300
commit9b76086084dcba0ef24ea2b0a94f438127f9eff5 (patch)
treeb5aa37cfe6df27a13367cc9c5dd1b2a1a8a0e3a0
parent7e1ecf7d6f1006e6e74c5c726cd873032948a141 (diff)
fixes #4399 (Discord: показывать, кто пригласил или выгнал участника)
-rw-r--r--protocols/Discord/src/dispatch.cpp43
-rw-r--r--protocols/Discord/src/stdafx.h1
-rw-r--r--protocols/Discord/src/utils.cpp16
-rw-r--r--src/mir_app/src/chat_svc.cpp37
4 files changed, 64 insertions, 33 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 0ba56aa29b..df6c9b2d7d 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -133,6 +133,7 @@ void CDiscordProto::OnCommandChannelUserAdded(const JSONNode &pRoot)
CMStringW wszNick = getNick(nUser);
GCEVENT gce = { pUser->si, GC_EVENT_JOIN };
+ gce.dwFlags = GCEF_SILENT;
gce.pszUID.w = wszUserId;
gce.pszNick.w = wszNick;
gce.time = time(0);
@@ -148,6 +149,7 @@ void CDiscordProto::OnCommandChannelUserLeft(const JSONNode &pRoot)
CMStringW wszUserId = pRoot["user"]["id"].as_mstring();
GCEVENT gce = { pUser->si, GC_EVENT_PART };
+ gce.dwFlags = GCEF_SILENT;
gce.pszUID.w = wszUserId;
gce.time = time(0);
Chat_Event(&gce);
@@ -432,6 +434,13 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew)
return;
}
+ // shift & store LastMsgId field
+ pUser->lastMsgId = msgId;
+
+ SnowFlake lastId = getId(pUser->hContact, DB_KEY_LASTMSGID); // as stored in a database
+ if (lastId < msgId)
+ setId(pUser->hContact, DB_KEY_LASTMSGID, msgId);
+
char szMsgId[100];
_i64toa_s(msgId, szMsgId, _countof(szMsgId), 10);
@@ -442,13 +451,34 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew)
debugLogA("skipping own message with nonce=%lld, id=%lld", ownMsg.nonce, msgId);
}
else {
- CMStringW wszText = PrepareMessageText(pRoot);
- if (wszText.IsEmpty())
+ CMStringW wszText = PrepareMessageText(pRoot), wszMentioned;
+ for (auto &it : pRoot["mentions"]) {
+ wszMentioned = getName(it);
+ break;
+ }
+
+ switch (pRoot["type"].as_int()) {
+ case 4: // chat was renamed
+ if (pUser->si)
+ setWString(pUser->si->hContact, "Nick", wszText);
return;
- if (pRoot["type"].as_int() == 4 && pUser->si) {
- setWString(pUser->si->hContact, "Nick", wszText);
+ case 1: // user was added to chat
+ wszText.Format(TranslateT("%s added %s to the group"), getName(pRoot["author"]).c_str(), wszMentioned.c_str());
+ break;
+
+ case 2: // user was removed from chat
+ wszText.Format(TranslateT("%s removed %s from the group"), getName(pRoot["author"]).c_str(), wszMentioned.c_str());
+ break;
+
+ case 3: // user left chat
+ wszText.Format(TranslateT("%s left group"), wszMentioned.c_str());
+ break;
}
+
+ if (wszText.IsEmpty())
+ return;
+
else {
// old message? try to restore it from database
bool bOurMessage = userId == m_ownId;
@@ -492,11 +522,6 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew)
}
}
- pUser->lastMsgId = msgId;
-
- SnowFlake lastId = getId(pUser->hContact, DB_KEY_LASTMSGID); // as stored in a database
- if (lastId < msgId)
- setId(pUser->hContact, DB_KEY_LASTMSGID, msgId);
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h
index dfea7e61dd..6e241a4dc6 100644
--- a/protocols/Discord/src/stdafx.h
+++ b/protocols/Discord/src/stdafx.h
@@ -77,6 +77,7 @@ void BuildStatusList(const CDiscordGuild *pGuild, SESSION_INFO *si);
void CopyId(const CMStringW &nick);
SnowFlake getId(const JSONNode &pNode);
+CMStringW getName(const JSONNode &pNode);
CMStringW getNick(const JSONNode &pNode);
CMStringW PrepareMessageText(const JSONNode &pRoot);
int StrToStatus(const CMStringW &str);
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp
index a3cf8f9f5d..bcc5c5225b 100644
--- a/protocols/Discord/src/utils.cpp
+++ b/protocols/Discord/src/utils.cpp
@@ -59,6 +59,14 @@ int SerialNext()
/////////////////////////////////////////////////////////////////////////////////////////
+CMStringW getName(const JSONNode &pNode)
+{
+ CMStringW wszNick = pNode["global_name"].as_mstring();
+ if (wszNick.IsEmpty())
+ wszNick = pNode["username"].as_mstring();
+ return wszNick;
+}
+
CMStringW getNick(const JSONNode &pNode)
{
CMStringW name = pNode["username"].as_mstring(), discriminator = pNode["discriminator"].as_mstring();
@@ -191,15 +199,13 @@ void CDiscordProto::PreparePrivateChannel(const JSONNode &root)
if (pUser->wszChannelName.IsEmpty()) {
int i = 0;
for (auto &it : root["recipients"]) {
- CMStringW wszNick = it["global_name"].as_mstring();
- if (wszNick.IsEmpty())
- wszNick = it["username"].as_mstring();
- if (wszNick.IsEmpty())
+ CMStringW wszName = getName(it);
+ if (wszName.IsEmpty())
continue;
if (!pUser->wszChannelName.IsEmpty())
pUser->wszChannelName += L", ";
- pUser->wszChannelName += wszNick;
+ pUser->wszChannelName += wszName;
if (i++ > 3)
break;
diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp
index 1d50558150..1368e9761c 100644
--- a/src/mir_app/src/chat_svc.cpp
+++ b/src/mir_app/src/chat_svc.cpp
@@ -538,30 +538,29 @@ static BOOL HandleChatEvent(GCEVENT &gce, int bManyFix)
}
// add to log
- if (gce.dwFlags & GCEF_SILENT)
- return 0;
-
- // fix for IRC's old style mode notifications. Should not affect any other protocol
- if ((gce.iType == GC_EVENT_ADDSTATUS || gce.iType == GC_EVENT_REMOVESTATUS) && !(gce.dwFlags & GCEF_ADDTOLOG))
- return 0;
+ if (!(gce.dwFlags & GCEF_SILENT)) {
+ // fix for IRC's old style mode notifications. Should not affect any other protocol
+ if ((gce.iType == GC_EVENT_ADDSTATUS || gce.iType == GC_EVENT_REMOVESTATUS) && !(gce.dwFlags & GCEF_ADDTOLOG))
+ return 0;
- if (gce.iType == GC_EVENT_JOIN && gce.time == 0)
- return 0;
+ if (gce.iType == GC_EVENT_JOIN && gce.time == 0)
+ return 0;
- if (si && (si->bInitDone || gce.iType == GC_EVENT_TOPIC || (gce.iType == GC_EVENT_JOIN && gce.bIsMe))) {
- if (gce.pszNick.w == nullptr && gce.pszUID.w != nullptr)
- if (USERINFO *ui = g_chatApi.UM_FindUser(si, gce.pszUID.w))
- gce.pszNick.w = ui->pszNick;
+ if (si && (si->bInitDone || gce.iType == GC_EVENT_TOPIC || (gce.iType == GC_EVENT_JOIN && gce.bIsMe))) {
+ if (gce.pszNick.w == nullptr && gce.pszUID.w != nullptr)
+ if (USERINFO *ui = g_chatApi.UM_FindUser(si, gce.pszUID.w))
+ gce.pszNick.w = ui->pszNick;
- if (auto *lin = SM_AddEvent(si, &gce, bIsHighlighted))
- if (si->pDlg)
- si->pDlg->AddLog(*lin);
+ if (auto *lin = SM_AddEvent(si, &gce, bIsHighlighted))
+ if (si->pDlg)
+ si->pDlg->AddLog(*lin);
- if (!(gce.dwFlags & GCEF_NOTNOTIFY))
- g_chatApi.DoSoundsFlashPopupTrayStuff(si, &gce, bIsHighlighted, bManyFix);
+ if (!(gce.dwFlags & GCEF_NOTNOTIFY))
+ g_chatApi.DoSoundsFlashPopupTrayStuff(si, &gce, bIsHighlighted, bManyFix);
- if ((gce.dwFlags & GCEF_ADDTOLOG) && g_Settings->bLoggingEnabled)
- LogToFile(si, &gce);
+ if ((gce.dwFlags & GCEF_ADDTOLOG) && g_Settings->bLoggingEnabled)
+ LogToFile(si, &gce);
+ }
}
if (bRemoveFlag)