From 5fd260b7c4c98bfa2d17a301d832a859c2af1f92 Mon Sep 17 00:00:00 2001 From: George Hazan <george.hazan@gmail.com> Date: Sun, 21 Jul 2024 16:17:48 +0300 Subject: =?UTF-8?q?fixes=20#4555=20(=D0=97=D0=B0=D0=B4=D0=B2=D0=B0=D0=B8?= =?UTF-8?q?=D0=B2=D0=B0=D1=8E=D1=82=D1=81=D1=8F=20=D0=BA=D0=BE=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=D0=BA=D1=82=D1=8B=20=D0=BF=D1=80=D0=BE=D1=82=D0=BE=D0=BA?= =?UTF-8?q?=D0=BE=D0=BB=D0=BE=D0=B2,=20=D0=B3=D0=B4=D0=B5=20=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BA=D1=8D=D1=88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Discord/src/proto.cpp | 79 ++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 37 deletions(-) (limited to 'protocols/Discord/src/proto.cpp') diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 7cfeba6d56..7bf3dbcf0d 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -136,43 +136,6 @@ CDiscordProto::~CDiscordProto() void CDiscordProto::OnModulesLoaded() { - std::vector<MCONTACT> lostIds; - - // Fill users list - for (auto &hContact : AccContacts()) { - CDiscordUser *pNew = new CDiscordUser(getId(hContact, DB_KEY_ID)); - pNew->hContact = hContact; - pNew->lastMsgId = getId(hContact, DB_KEY_LASTMSGID); - pNew->wszUsername = ptrW(getWStringA(hContact, DB_KEY_NICK)); - pNew->iDiscriminator = getDword(hContact, DB_KEY_DISCR); - - // set EnableSync = 1 by default for all existing guilds - switch (getByte(hContact, "ChatRoom")) { - case 2: // guild - delSetting(hContact, DB_KEY_CHANNELID); - surelyGetBool(hContact, DB_KEY_ENABLE_HIST); - surelyGetBool(hContact, DB_KEY_ENABLE_SYNC); - break; - - case 1: // group chat - pNew->channelId = getId(hContact, DB_KEY_CHANNELID); - if (!pNew->channelId) { - lostIds.push_back(hContact); - delete pNew; - continue; - } - break; - - default: - pNew->channelId = getId(hContact, DB_KEY_CHANNELID); - break; - } - arUsers.insert(pNew); - } - - for (auto &hContact: lostIds) - db_delete_contact(hContact); - // Clist Clist_GroupCreate(0, m_wszDefaultGroup); @@ -640,6 +603,48 @@ int CDiscordProto::OnAccountChanged(WPARAM iAction, LPARAM lParam) ///////////////////////////////////////////////////////////////////////////////////////// +void CDiscordProto::OnCacheInit() +{ + std::vector<MCONTACT> lostIds; + + // Fill users list + for (auto &hContact : AccContacts()) { + m_bCacheInited = true; + + CDiscordUser *pNew = new CDiscordUser(getId(hContact, DB_KEY_ID)); + pNew->hContact = hContact; + pNew->lastMsgId = getId(hContact, DB_KEY_LASTMSGID); + pNew->wszUsername = ptrW(getWStringA(hContact, DB_KEY_NICK)); + pNew->iDiscriminator = getDword(hContact, DB_KEY_DISCR); + + // set EnableSync = 1 by default for all existing guilds + switch (getByte(hContact, "ChatRoom")) { + case 2: // guild + delSetting(hContact, DB_KEY_CHANNELID); + surelyGetBool(hContact, DB_KEY_ENABLE_HIST); + surelyGetBool(hContact, DB_KEY_ENABLE_SYNC); + break; + + case 1: // group chat + pNew->channelId = getId(hContact, DB_KEY_CHANNELID); + if (!pNew->channelId) { + lostIds.push_back(hContact); + delete pNew; + continue; + } + break; + + default: + pNew->channelId = getId(hContact, DB_KEY_CHANNELID); + break; + } + arUsers.insert(pNew); + } + + for (auto &hContact : lostIds) + db_delete_contact(hContact); +} + bool CDiscordProto::OnContactDeleted(MCONTACT hContact, uint32_t flags) { if (flags & CDF_DEL_CONTACT) { -- cgit v1.2.3