From 8550b783b31d7aeb8ac6de4c1e2d013ddca377b3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 10 May 2024 13:11:04 +0300 Subject: =?UTF-8?q?fixes=20#4410=20(Discord:=20=D0=B7=D0=B0=D0=B3=D1=80?= =?UTF-8?q?=D1=83=D0=B7=D0=BA=D0=B0=20=D0=B8=D1=81=D1=82=D0=BE=D1=80=D0=B8?= =?UTF-8?q?=D0=B8=20=D1=81=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B6=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B5?= =?UTF-8?q?=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D1=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Discord/src/utils.cpp | 44 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'protocols/Discord/src/utils.cpp') diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index 952e5d8261..2e7c5defe7 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -114,6 +114,8 @@ SnowFlake CDiscordProto::getId(MCONTACT hContact, const char *szSetting) case DBVT_WCHAR: result = _wtoi64(dbv.pwszVal); break; + default: + result = 0; } db_free(&dbv); return result; @@ -230,7 +232,7 @@ void CDiscordProto::PreparePrivateChannel(const JSONNode &root) Chat_AddGroup(si, LPGENW("Owners")); Chat_AddGroup(si, LPGENW("Participants")); { - SnowFlake ownerId = _wtoi64(root["owner_id"].as_mstring()); + SnowFlake ownerId = ::getId(root["owner_id"]); setId(pUser->hContact, DB_KEY_OWNERID, ownerId); CheckAvatarChange(si->hContact, root["icon"].as_mstring()); @@ -339,7 +341,7 @@ CDiscordUser* CDiscordProto::PrepareUser(const JSONNode &user) ///////////////////////////////////////////////////////////////////////////////////////// -CMStringW PrepareMessageText(const JSONNode &pRoot) +CMStringW CDiscordProto::PrepareMessageText(const JSONNode &pRoot, CDiscordUser *pUser) { CMStringW wszText = pRoot["content"].as_mstring(); @@ -374,6 +376,44 @@ CMStringW PrepareMessageText(const JSONNode &pRoot) wszText.AppendFormat(L"\n%s: %s", TranslateT("Preview"), str.c_str()); } + auto &nAuthor = pRoot["author"]; + SnowFlake mentionId = 0, userId = ::getId(nAuthor["id"]); + CMStringW wszMentioned, wszAuthor = getName(nAuthor); + + for (auto &it : pRoot["mentions"]) { + wszMentioned = getName(it); + mentionId = ::getId(it["id"]); + break; + } + + switch (pRoot["type"].as_int()) { + case 1: // user was added to chat + if (mentionId != userId) + wszText.Format(TranslateT("%s added %s to the group"), wszAuthor.c_str(), wszMentioned.c_str()); + else + wszText.Format(TranslateT("%s joined the group"), wszMentioned.c_str()); + break; + + case 2: // user was removed from chat + if (mentionId != userId) + wszText.Format(TranslateT("%s removed %s from the group"), wszAuthor.c_str(), wszMentioned.c_str()); + else + wszText.Format(TranslateT("%s left the group"), wszMentioned.c_str()); + break; + + case 3: // call + break; + + case 4: // chat was renamed + if (pUser->si) + setWString(pUser->si->hContact, "Nick", wszText); + break; + + case 5: // chat icon is changed + wszText.Format(TranslateT("%s changed the group icon"), wszAuthor.c_str()); + break; + } + return wszText; } -- cgit v1.2.3