summaryrefslogtreecommitdiff
path: root/protocols/Facebook/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-04-30 17:52:29 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-04-30 17:52:29 +0300
commit9f00802dfbad293235fc44536069c64b236fdc50 (patch)
treed6d337bdc9334c5516e30f83d5edf9f742be2f35 /protocols/Facebook/src
parent84f2722e07a23656bdc8d1a7f4040e86450fe91d (diff)
fixes #2859 (Импорт: дублируются контакты ICQ и FaceBook)
Diffstat (limited to 'protocols/Facebook/src')
-rw-r--r--protocols/Facebook/src/proto.cpp14
-rw-r--r--protocols/Facebook/src/proto.h8
-rw-r--r--protocols/Facebook/src/server.cpp13
3 files changed, 26 insertions, 9 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);
}