From 9f00802dfbad293235fc44536069c64b236fdc50 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 30 Apr 2021 17:52:29 +0300 Subject: =?UTF-8?q?fixes=20#2859=20(=D0=98=D0=BC=D0=BF=D0=BE=D1=80=D1=82:?= =?UTF-8?q?=20=D0=B4=D1=83=D0=B1=D0=BB=D0=B8=D1=80=D1=83=D1=8E=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B0=D0=BA=D1=82=D1=8B=20ICQ?= =?UTF-8?q?=20=D0=B8=20FaceBook)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Facebook/src/proto.cpp | 14 +++++++++++++- protocols/Facebook/src/proto.h | 8 ++++---- protocols/Facebook/src/server.cpp | 13 +++++++++---- protocols/ICQ-WIM/src/proto.cpp | 9 +++++++++ protocols/ICQ-WIM/src/proto.h | 1 + protocols/ICQ-WIM/src/utils.cpp | 7 +------ 6 files changed, 37 insertions(+), 15 deletions(-) (limited to 'protocols') diff --git a/protocols/Facebook/src/proto.cpp b/protocols/Facebook/src/proto.cpp index 2873b2d8d3..3b9eb5101b 100644 --- a/protocols/Facebook/src/proto.cpp +++ b/protocols/Facebook/src/proto.cpp @@ -122,6 +122,18 @@ FacebookProto::~FacebookProto() { } +///////////////////////////////////////////////////////////////////////////////////////// +// protocol events + +void FacebookProto::OnContactAdded(MCONTACT hContact) +{ + __int64 userId = _atoi64(getMStringA(hContact, DBKEY_ID)); + if (userId && !FindUser(userId)) { + mir_cslock lck(m_csUsers); + m_users.insert(new FacebookUser(userId, hContact)); + } +} + void FacebookProto::OnModulesLoaded() { VARSW wszCache(L"%miranda_avatarcache%"); @@ -162,8 +174,8 @@ MCONTACT FacebookProto::AddToList(int, PROTOSEARCHRESULT *psr) return pUser->hContact; MCONTACT hContact = db_add_contact(); - Proto_AddToContact(hContact, m_szModuleName); setWString(hContact, DBKEY_ID, psr->id.w); + Proto_AddToContact(hContact, m_szModuleName); return hContact; } diff --git a/protocols/Facebook/src/proto.h b/protocols/Facebook/src/proto.h index a1beb850e3..e2dffa6513 100644 --- a/protocols/Facebook/src/proto.h +++ b/protocols/Facebook/src/proto.h @@ -466,11 +466,10 @@ class FacebookProto : public PROTO OBJLIST arOwnMessages; bool ExtractOwnMessage(__int64 msgId, COwnMessage &res); + mir_cs m_csUsers; OBJLIST m_users; - FacebookUser *FindUser(__int64 id) - { - return m_users.find((FacebookUser *)&id); - } + + FacebookUser* FindUser(__int64 id); FacebookUser *UserFromJson(const JSONNode &root, CMStringW &wszId, bool &bIsChat); @@ -521,6 +520,7 @@ public: //////////////////////////////////////////////////////////////////////////////////////// // PROTO_INTERFACE + void OnContactAdded(MCONTACT) override; void OnModulesLoaded() override; void OnShutdown() override; diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp index 013993c741..2df81a34e3 100644 --- a/protocols/Facebook/src/server.cpp +++ b/protocols/Facebook/src/server.cpp @@ -89,15 +89,19 @@ void FacebookProto::OnLoggedOut() FacebookUser* FacebookProto::AddContact(const CMStringW &wszId, bool bTemp) { MCONTACT hContact = db_add_contact(); - Proto_AddToContact(hContact, m_szModuleName); setWString(hContact, DBKEY_ID, wszId); + Proto_AddToContact(hContact, m_szModuleName); Clist_SetGroup(hContact, m_wszDefaultGroup); if (bTemp) Contact_RemoveFromList(hContact); - auto *ret = new FacebookUser(_wtoi64(wszId), hContact); - m_users.insert(ret); - return ret; + return FindUser(_wtoi64(wszId)); +} + +FacebookUser* FacebookProto::FindUser(__int64 id) +{ + mir_cslock lck(m_csUsers); + return m_users.find((FacebookUser *)&id); } FacebookUser* FacebookProto::UserFromJson(const JSONNode &root, CMStringW &wszUserId, bool &bIsChat) @@ -267,6 +271,7 @@ FacebookUser* FacebookProto::RefreshThread(JSONNode &n) auto *pUser = FindUser(userId); if (pUser == nullptr) { + mir_cslock lck(m_csUsers); pUser = new FacebookUser(userId, si->hContact, true, true); m_users.insert(pUser); } diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp index 87a33e0502..d7bf399154 100644 --- a/protocols/ICQ-WIM/src/proto.cpp +++ b/protocols/ICQ-WIM/src/proto.cpp @@ -142,6 +142,15 @@ void CIcqProto::OnShutdown() m_bTerminated = true; } +void CIcqProto::OnContactAdded(MCONTACT hContact) +{ + CMStringW wszId(getMStringW(hContact, DB_KEY_ID)); + if (!wszId.IsEmpty() && !FindContactByUIN(wszId)) { + mir_cslock l(m_csCache); + m_arCache.insert(new IcqCacheItem(wszId, hContact)); + } +} + void CIcqProto::OnContactDeleted(MCONTACT hContact) { CMStringW szId(GetUserId(hContact)); diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h index ef83185830..163fc56b3a 100644 --- a/protocols/ICQ-WIM/src/proto.h +++ b/protocols/ICQ-WIM/src/proto.h @@ -441,6 +441,7 @@ class CIcqProto : public PROTO int UserIsTyping(MCONTACT hContact, int type) override; void OnBuildProtoMenu(void) override; + void OnContactAdded(MCONTACT) override; void OnContactDeleted(MCONTACT) override; void OnEventEdited(MCONTACT, MEVENT) override; void OnModulesLoaded() override; diff --git a/protocols/ICQ-WIM/src/utils.cpp b/protocols/ICQ-WIM/src/utils.cpp index e01b94c9b4..30e1dcc575 100644 --- a/protocols/ICQ-WIM/src/utils.cpp +++ b/protocols/ICQ-WIM/src/utils.cpp @@ -91,13 +91,8 @@ MCONTACT CIcqProto::CreateContact(const CMStringW &wszId, bool bTemporary) return pCache->m_hContact; MCONTACT hContact = db_add_contact(); - Proto_AddToContact(hContact, m_szModuleName); setWString(hContact, DB_KEY_ID, wszId); - pCache = new IcqCacheItem(wszId, hContact); - { - mir_cslock l(m_csCache); - m_arCache.insert(pCache); - } + Proto_AddToContact(hContact, m_szModuleName); RetrieveUserInfo(hContact); if (bTemporary) -- cgit v1.2.3