diff options
author | George Hazan <ghazan@miranda.im> | 2021-04-30 17:52:29 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-04-30 17:52:29 +0300 |
commit | 9f00802dfbad293235fc44536069c64b236fdc50 (patch) | |
tree | d6d337bdc9334c5516e30f83d5edf9f742be2f35 /protocols | |
parent | 84f2722e07a23656bdc8d1a7f4040e86450fe91d (diff) |
fixes #2859 (Импорт: дублируются контакты ICQ и FaceBook)
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Facebook/src/proto.cpp | 14 | ||||
-rw-r--r-- | protocols/Facebook/src/proto.h | 8 | ||||
-rw-r--r-- | protocols/Facebook/src/server.cpp | 13 | ||||
-rw-r--r-- | protocols/ICQ-WIM/src/proto.cpp | 9 | ||||
-rw-r--r-- | protocols/ICQ-WIM/src/proto.h | 1 | ||||
-rw-r--r-- | protocols/ICQ-WIM/src/utils.cpp | 7 |
6 files changed, 37 insertions, 15 deletions
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<FacebookProto> OBJLIST<COwnMessage> arOwnMessages; bool ExtractOwnMessage(__int64 msgId, COwnMessage &res); + mir_cs m_csUsers; OBJLIST<FacebookUser> 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<CIcqProto> 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) |