summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Discord/src/dispatch.cpp42
-rw-r--r--protocols/Discord/src/guilds.cpp2
-rw-r--r--protocols/Discord/src/proto.h1
-rw-r--r--protocols/Discord/src/server.cpp4
-rw-r--r--protocols/Discord/src/stdafx.h1
-rw-r--r--protocols/Discord/src/utils.cpp44
6 files changed, 48 insertions, 46 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index f251abaa53..e2dcb9d30d 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -444,10 +444,9 @@ void CDiscordProto::OnCommandMessageUpdate(const JSONNode &pRoot)
void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew)
{
- CMStringW wszMessageId = pRoot["id"].as_mstring();
CMStringA szUserId = pRoot["author"]["id"].as_mstring();
SnowFlake userId = _atoi64(szUserId);
- SnowFlake msgId = _wtoi64(wszMessageId);
+ SnowFlake msgId = ::getId(pRoot["id"]);
// try to find a sender by his channel
SnowFlake channelId = ::getId(pRoot["channel_id"]);
@@ -474,43 +473,7 @@ 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), wszMentioned, wszAuthor = getName(pRoot["author"]);
- SnowFlake mentionId = 0;
-
- for (auto &it : pRoot["mentions"]) {
- wszMentioned = getName(it);
- mentionId = _wtoi64(it["id"].as_mstring());
- 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);
- return;
-
- case 5: // chat icon is changed
- wszText.Format(TranslateT("%s changed the group icon"), wszAuthor.c_str());
- break;
- }
-
+ CMStringW wszText = PrepareMessageText(pRoot, pUser);
if (wszText.IsEmpty())
return;
@@ -552,7 +515,6 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew)
ProtoChainRecvMsg(pUser->hContact, dbei);
}
}
-
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp
index 67fb04928b..a4e5a8ee3b 100644
--- a/protocols/Discord/src/guilds.cpp
+++ b/protocols/Discord/src/guilds.cpp
@@ -226,7 +226,7 @@ CDiscordUser* CDiscordProto::ProcessGuildChannel(CDiscordGuild *pGuild, const JS
pUser->wszTopic = pch["topic"].as_mstring();
pUser->pGuild = pGuild;
pUser->lastMsgId = ::getId(pch["last_message_id"]);
- pUser->parentId = _wtoi64(pch["parent_id"].as_mstring());
+ pUser->parentId = ::getId(pch["parent_id"]);
return pUser;
}
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index 48664c424d..7099600f52 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -347,6 +347,7 @@ class CDiscordProto : public PROTO<CDiscordProto>
CDiscordUser* FindUser(const wchar_t *pwszUsername, int iDiscriminator);
CDiscordUser* FindUserByChannel(SnowFlake channelId);
+ CMStringW PrepareMessageText(const JSONNode &pRoot, CDiscordUser *pUser);
void PreparePrivateChannel(const JSONNode &);
CDiscordUser* PrepareUser(const JSONNode &);
diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp
index c083e9b91d..0b48dc3ab9 100644
--- a/protocols/Discord/src/server.cpp
+++ b/protocols/Discord/src/server.cpp
@@ -85,10 +85,10 @@ void CDiscordProto::OnReceiveHistory(MHttpResponse *pReply, AsyncHttpRequest *pR
for (auto &it : arNodes) {
auto &pNode = *it;
- if (pNode["type"].as_int() != 0)
+ CMStringW wszText = PrepareMessageText(pNode, pUser);
+ if (wszText.IsEmpty())
continue;
- CMStringW wszText = PrepareMessageText(pNode);
CMStringA szUserId = pNode["author"]["id"].as_mstring();
SnowFlake msgid = ::getId(pNode["id"]);
SnowFlake authorid = _atoi64(szUserId);
diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h
index 7bfd1425e9..1623cbafa6 100644
--- a/protocols/Discord/src/stdafx.h
+++ b/protocols/Discord/src/stdafx.h
@@ -80,7 +80,6 @@ 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);
time_t StringToDate(const CMStringW &str);
int SerialNext(void);
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;
}