summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Discord/src/utils.cpp')
-rw-r--r--protocols/Discord/src/utils.cpp43
1 files changed, 31 insertions, 12 deletions
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp
index e26317d0f8..07b293d1b4 100644
--- a/protocols/Discord/src/utils.cpp
+++ b/protocols/Discord/src/utils.cpp
@@ -129,6 +129,30 @@ CDiscordUser* CDiscordProto::FindUserByChannel(SnowFlake channelId)
return nullptr;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Common JSON processing routines
+
+void CDiscordProto::PreparePrivateChannel(const JSONNode &root)
+{
+ CDiscordUser *pUser = nullptr;
+ for (auto &it : root["recipients"])
+ pUser = PrepareUser(it);
+
+ if (pUser == nullptr)
+ return;
+
+ CMStringW wszChannelId = root["id"].as_mstring();
+ pUser->channelId = _wtoi64(wszChannelId);
+ pUser->lastMsgId = ::getId(root["last_message_id"]);
+ pUser->bIsPrivate = true;
+
+ setId(pUser->hContact, DB_KEY_CHANNELID, pUser->channelId);
+
+ SnowFlake oldMsgId = getId(pUser->hContact, DB_KEY_LASTMSGID);
+ if (pUser->lastMsgId > oldMsgId)
+ RetrieveHistory(pUser, MSG_AFTER, oldMsgId, 99);
+}
+
CDiscordUser* CDiscordProto::PrepareUser(const JSONNode &user)
{
SnowFlake id = ::getId(user["id"]);
@@ -184,10 +208,8 @@ CMStringW PrepareMessageText(const JSONNode &pRoot)
CMStringW wszText = pRoot["content"].as_mstring();
bool bDelimiterAdded = false;
- const JSONNode &pAttaches = pRoot["attachments"];
- for (auto it = pAttaches.begin(); it != pAttaches.end(); ++it) {
- const JSONNode &p = *it;
- CMStringW wszUrl = p["url"].as_mstring();
+ for (auto &it : pRoot["attachments"]) {
+ CMStringW wszUrl = it["url"].as_mstring();
if (!wszUrl.IsEmpty()) {
if (!bDelimiterAdded) {
bDelimiterAdded = true;
@@ -197,24 +219,21 @@ CMStringW PrepareMessageText(const JSONNode &pRoot)
}
}
- const JSONNode &pEmbeds = pRoot["embeds"];
- for (auto it = pEmbeds.begin(); it != pEmbeds.end(); ++it) {
- const JSONNode &p = *it;
-
+ for (auto &it : pRoot["embeds"]) {
wszText.Append(L"\n-----------------");
- CMStringW str = p["url"].as_mstring();
+ CMStringW str = it["url"].as_mstring();
wszText.AppendFormat(L"\n%s: %s", TranslateT("Embed"), str.c_str());
- str = p["provider"]["name"].as_mstring() + L" " + p["type"].as_mstring();
+ str = it["provider"]["name"].as_mstring() + L" " + it["type"].as_mstring();
if (str.GetLength() > 1)
wszText.AppendFormat(L"\n\t%s", str.c_str());
- str = p["description"].as_mstring();
+ str = it["description"].as_mstring();
if (!str.IsEmpty())
wszText.AppendFormat(L"\n\t%s", str.c_str());
- str = p["thumbnail"]["url"].as_mstring();
+ str = it["thumbnail"]["url"].as_mstring();
if (!str.IsEmpty())
wszText.AppendFormat(L"\n%s: %s", TranslateT("Preview"), str.c_str());
}