From 8a557bb6c7119e9a8d196d76e144727b1b861c1d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 7 Dec 2020 10:20:29 +0300 Subject: Discord: fix for a possible contact duplication --- protocols/Discord/src/proto.cpp | 14 +++++++++++--- protocols/Discord/src/stdafx.h | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'protocols/Discord/src') diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 898f30ff8b..27cf9b4cf6 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -134,6 +134,8 @@ CDiscordProto::~CDiscordProto() void CDiscordProto::OnModulesLoaded() { + std::vector lostIds; + // Fill users list for (auto &hContact : AccContacts()) { CDiscordUser *pNew = new CDiscordUser(getId(hContact, DB_KEY_ID)); @@ -141,7 +143,6 @@ void CDiscordProto::OnModulesLoaded() pNew->lastMsgId = getId(hContact, DB_KEY_LASTMSGID); pNew->wszUsername = ptrW(getWStringA(hContact, DB_KEY_NICK)); pNew->iDiscriminator = getDword(hContact, DB_KEY_DISCR); - arUsers.insert(pNew); // set EnableSync = 1 by default for all existing guilds switch (getByte(hContact, "ChatRoom")) { @@ -153,16 +154,23 @@ void CDiscordProto::OnModulesLoaded() case 1: // group chat pNew->channelId = getId(hContact, DB_KEY_CHANNELID); - if (!pNew->channelId) - db_delete_contact(hContact); + 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); diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h index 7e04081d2c..acf9ec0dfc 100644 --- a/protocols/Discord/src/stdafx.h +++ b/protocols/Discord/src/stdafx.h @@ -16,6 +16,8 @@ #include #include +#include + #include "resource.h" #include -- cgit v1.2.3