summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/guilds.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-12-27 19:03:28 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-12-27 19:03:28 +0300
commit0a5de30626a30971cb99387a0624dc19c53f528a (patch)
tree4adef96ee6984260376098ad8d6d0c44694ff49b /protocols/Discord/src/guilds.cpp
parentb06220b86dbfbe321fdf40332c707891fb30f128 (diff)
Discord: first 100 guild users are fetched from the server
Diffstat (limited to 'protocols/Discord/src/guilds.cpp')
-rw-r--r--protocols/Discord/src/guilds.cpp46
1 files changed, 6 insertions, 40 deletions
diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp
index 8ce9ceac61..71ebd098b4 100644
--- a/protocols/Discord/src/guilds.cpp
+++ b/protocols/Discord/src/guilds.cpp
@@ -173,9 +173,6 @@ void CDiscordProto::ProcessGuild(const JSONNode &pRoot)
pGuild->hContact = si->hContact;
setId(pGuild->hContact, DB_KEY_CHANNELID, guildId);
- if (!pGuild->bSynced && getByte(si->hContact, "EnableSync"))
- LoadGuildInfo(pGuild);
-
Chat_Control(m_szModuleName, pGuild->wszName, WINDOW_HIDDEN);
Chat_Control(m_szModuleName, pGuild->wszName, SESSION_ONLINE);
@@ -184,6 +181,12 @@ void CDiscordProto::ProcessGuild(const JSONNode &pRoot)
BuildStatusList(pGuild, si);
+ for (auto &it : pRoot["channels"])
+ ProcessGuildChannel(pGuild, it);
+
+ if (!pGuild->bSynced && getByte(si->hContact, "EnableSync"))
+ GatewaySendGuildInfo(pGuild);
+
// store all guild members
for (auto &it : pRoot["members"]) {
CMStringW wszUserId = it["user"]["id"].as_mstring();
@@ -222,9 +225,6 @@ void CDiscordProto::ProcessGuild(const JSONNode &pRoot)
for (auto &it : pGuild->arChatUsers)
AddGuildUser(pGuild, *it);
- for (auto &it : pRoot["channels"])
- ProcessGuildChannel(pGuild, it);
-
if (m_bUseGroupchats)
ForkThread(&CDiscordProto::BatchChatCreate, pGuild);
@@ -311,37 +311,3 @@ void CDiscordProto::AddGuildUser(CDiscordGuild *pGuild, const CDiscordGuildMembe
if (pUser.userId == m_ownId)
pGuild->pParentSi->pMe = pu;
}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-static CMStringW GetCacheFileName(SnowFlake guildId)
-{
- VARSW wszCacheDir(L"%miranda_userdata%\\Discord");
- CreateDirectoryTreeW(wszCacheDir);
-
- return CMStringW(FORMAT, L"%s\\%lld.cache", wszCacheDir.get(), guildId);
-}
-
-void CDiscordProto::LoadGuildInfo(CDiscordGuild *pGuild)
-{
- CMStringW wszCacheFile(GetCacheFileName(pGuild->id));
- int fileId = _wopen(wszCacheFile, _O_BINARY | _O_RDONLY);
- if (fileId != -1) {
- size_t length = _filelength(fileId);
- ptrA buf((char *)mir_alloc(length+1));
- int result = _read(fileId, buf, (unsigned)length);
- _close(fileId);
- if (result == -1)
- return;
-
- JSONNode root(JSONNode::parse(buf));
- for (auto &cc : root) {
- auto *pUser = new CDiscordGuildMember(_wtoi64(cc["id"].as_mstring()));
- pUser->wszNick = cc["nick"].as_mstring();
- pUser->wszRole = cc["role"].as_mstring();
- pGuild->arChatUsers.insert(pUser);
-
- AddGuildUser(pGuild, *pUser);
- }
- }
-}