diff options
author | George Hazan <george.hazan@gmail.com> | 2024-07-21 16:17:48 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-07-21 16:17:48 +0300 |
commit | 5fd260b7c4c98bfa2d17a301d832a859c2af1f92 (patch) | |
tree | 648dfe9336191c8fafdf7772f376f8e60337388a /protocols | |
parent | 17b6a94812b2dbf4af29fb5d84064ceb1c7d393e (diff) |
fixes #4555 (Задваиваются контакты протоколов, где есть кэш)
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Discord/src/proto.cpp | 79 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 1 | ||||
-rw-r--r-- | protocols/Facebook/src/proto.cpp | 18 | ||||
-rw-r--r-- | protocols/Facebook/src/proto.h | 7 | ||||
-rw-r--r-- | protocols/ICQ-WIM/src/proto.cpp | 37 | ||||
-rw-r--r-- | protocols/ICQ-WIM/src/proto.h | 58 | ||||
-rw-r--r-- | protocols/ICQ-WIM/src/utils.cpp | 34 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_events.cpp | 24 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_proto.cpp | 17 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_proto.h | 1 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.cpp | 35 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 1 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.cpp | 28 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.h | 2 |
14 files changed, 183 insertions, 159 deletions
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) {
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 2946e677f8..4a5c17a49b 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -544,6 +544,7 @@ public: int SetStatus(int iNewStatus) override;
void OnBuildProtoMenu() override;
+ void OnCacheInit() override;
bool OnContactDeleted(MCONTACT, uint32_t flags) override;
void OnEventDeleted(MCONTACT, MEVENT, int flags) override;
MWindow OnCreateAccMgrUI(MWindow) override;
diff --git a/protocols/Facebook/src/proto.cpp b/protocols/Facebook/src/proto.cpp index ef8fdbbaa3..68b408d64b 100644 --- a/protocols/Facebook/src/proto.cpp +++ b/protocols/Facebook/src/proto.cpp @@ -118,6 +118,17 @@ FacebookProto::~FacebookProto() /////////////////////////////////////////////////////////////////////////////////////////
// protocol events
+void FacebookProto::OnCacheInit()
+{
+ for (auto &cc : AccContacts()) {
+ m_bCacheInited = true;
+
+ CMStringA szId(getMStringA(cc, DBKEY_ID));
+ if (!szId.IsEmpty())
+ m_users.insert(new FacebookUser(_atoi64(szId), cc, isChatRoom(cc)));
+ }
+}
+
void FacebookProto::OnContactAdded(MCONTACT hContact)
{
__int64 userId = _atoi64(getMStringA(hContact, DBKEY_ID));
@@ -137,13 +148,6 @@ void FacebookProto::OnModulesLoaded() wszPath.Format(L"%s\\%S\\Stickers\\*.webp", wszCache.get(), m_szModuleName);
SmileyAdd_LoadContactSmileys(SMADD_FOLDER, m_szModuleName, wszPath);
- // contacts cache
- for (auto &cc : AccContacts()) {
- CMStringA szId(getMStringA(cc, DBKEY_ID));
- if (!szId.IsEmpty())
- m_users.insert(new FacebookUser(_atoi64(szId), cc, isChatRoom(cc)));
- }
-
// Default group
Clist_GroupCreate(0, m_wszDefaultGroup);
}
diff --git a/protocols/Facebook/src/proto.h b/protocols/Facebook/src/proto.h index fe11debae7..d82cc80335 100644 --- a/protocols/Facebook/src/proto.h +++ b/protocols/Facebook/src/proto.h @@ -522,9 +522,10 @@ public: ////////////////////////////////////////////////////////////////////////////////////////
// PROTO_INTERFACE
- void OnContactAdded(MCONTACT) override;
- void OnModulesLoaded() override;
- void OnShutdown() override;
+ void OnCacheInit() override;
+ void OnContactAdded(MCONTACT) override;
+ void OnModulesLoaded() override;
+ void OnShutdown() override;
MCONTACT AddToList(int flags, PROTOSEARCHRESULT *psr) override;
INT_PTR GetCaps(int type, MCONTACT hContact) override;
diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp index cba66077db..d224b7d265 100644 --- a/protocols/ICQ-WIM/src/proto.cpp +++ b/protocols/ICQ-WIM/src/proto.cpp @@ -134,7 +134,6 @@ CIcqProto::~CIcqProto() void CIcqProto::OnModulesLoaded()
{
- InitContactCache();
InitMenus();
HookProtoEvent(ME_USERINFO_INITIALISE, &CIcqProto::OnUserInfoInit);
@@ -148,6 +147,42 @@ void CIcqProto::OnShutdown() m_bTerminated = true;
}
+void CIcqProto::OnCacheInit()
+{
+ mir_cslock l(m_csCache);
+ for (auto &it : AccContacts()) {
+ m_bCacheInited = true;
+
+ if (isChatRoom(it))
+ continue;
+
+ // that was previously an ICQ contact
+ ptrW wszUin(GetUIN(it));
+ if (wszUin != nullptr) {
+ delSetting(it, "UIN");
+ setWString(it, DB_KEY_ID, wszUin);
+ }
+ // that was previously a MRA contact
+ else {
+ CMStringW wszEmail(getMStringW(it, "e-mail"));
+ if (!wszEmail.IsEmpty()) {
+ delSetting(it, "e-mail");
+ setWString(it, DB_KEY_ID, wszEmail);
+ }
+ }
+
+ CMStringW wszId = GetUserId(it);
+ auto *pUser = FindUser(wszId);
+ if (pUser == nullptr) {
+ pUser = new IcqUser(wszId, it);
+
+ mir_cslock lck(m_csCache);
+ m_arCache.insert(pUser);
+ }
+ pUser->m_iProcessedMsgId = getId(it, DB_KEY_LASTMSGID);
+ }
+}
+
void CIcqProto::OnContactAdded(MCONTACT hContact)
{
CMStringW wszId(getMStringW(hContact, DB_KEY_ID));
diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h index 27bc6b2490..778a8a5236 100644 --- a/protocols/ICQ-WIM/src/proto.h +++ b/protocols/ICQ-WIM/src/proto.h @@ -378,7 +378,6 @@ class CIcqProto : public PROTO<CIcqProto> mir_cs m_csCache;
OBJLIST<IcqUser> m_arCache;
- void InitContactCache(void);
IcqUser* FindUser(const CMStringW &pwszId);
MCONTACT CreateContact(const CMStringW &pwszId, bool bTemporary);
@@ -431,34 +430,35 @@ class CIcqProto : public PROTO<CIcqProto> ////////////////////////////////////////////////////////////////////////////////////////
// PROTO_INTERFACE
- MCONTACT AddToList( int flags, PROTOSEARCHRESULT *psr) override;
-
- int AuthRecv(MCONTACT, DB::EventInfo &dbei) override;
- int AuthRequest(MCONTACT hContact, const wchar_t *szMessage) override;
-
- INT_PTR GetCaps(int type, MCONTACT hContact = NULL) override;
- int GetInfo(MCONTACT hContact, int infoType) override;
-
- HANDLE SearchBasic(const wchar_t *id) override;
-
- HANDLE SendFile(MCONTACT hContact, const wchar_t *szDescription, wchar_t **ppszFiles) override;
- int SendMsg(MCONTACT hContact, MEVENT hReplyEvent, const char *msg) override;
-
- int SetStatus(int iNewStatus) override;
-
- int UserIsTyping(MCONTACT hContact, int type) override;
-
- void OnBuildProtoMenu(void) override;
- void OnContactAdded(MCONTACT) override;
- bool OnContactDeleted(MCONTACT, uint32_t flags) override;
- MWindow OnCreateAccMgrUI(MWindow) override;
- void OnEventDeleted(MCONTACT, MEVENT, int) override;
- void OnEventEdited(MCONTACT, MEVENT, const DBEVENTINFO &dbei) override;
- void OnMarkRead(MCONTACT, MEVENT) override;
- void OnModulesLoaded() override;
- void OnReceiveOfflineFile(DB::FILE_BLOB &blob) override;
- void OnSendOfflineFile(DB::EventInfo &dbei, DB::FILE_BLOB &blob, void *ft) override;
- void OnShutdown() override;
+ MCONTACT AddToList( int flags, PROTOSEARCHRESULT *psr) override;
+
+ int AuthRecv(MCONTACT, DB::EventInfo &dbei) override;
+ int AuthRequest(MCONTACT hContact, const wchar_t *szMessage) override;
+
+ INT_PTR GetCaps(int type, MCONTACT hContact = NULL) override;
+ int GetInfo(MCONTACT hContact, int infoType) override;
+
+ HANDLE SearchBasic(const wchar_t *id) override;
+
+ HANDLE SendFile(MCONTACT hContact, const wchar_t *szDescription, wchar_t **ppszFiles) override;
+ int SendMsg(MCONTACT hContact, MEVENT hReplyEvent, const char *msg) override;
+
+ int SetStatus(int iNewStatus) override;
+
+ int UserIsTyping(MCONTACT hContact, int type) override;
+
+ void OnBuildProtoMenu(void) override;
+ void OnCacheInit() override;
+ void OnContactAdded(MCONTACT) override;
+ bool OnContactDeleted(MCONTACT, uint32_t flags) override;
+ MWindow OnCreateAccMgrUI(MWindow) override;
+ void OnEventDeleted(MCONTACT, MEVENT, int) override;
+ void OnEventEdited(MCONTACT, MEVENT, const DBEVENTINFO &dbei) override;
+ void OnMarkRead(MCONTACT, MEVENT) override;
+ void OnModulesLoaded() override;
+ void OnReceiveOfflineFile(DB::FILE_BLOB &blob) override;
+ void OnSendOfflineFile(DB::EventInfo &dbei, DB::FILE_BLOB &blob, void *ft) override;
+ void OnShutdown() override;
public:
CIcqProto(const char*, const wchar_t*);
diff --git a/protocols/ICQ-WIM/src/utils.cpp b/protocols/ICQ-WIM/src/utils.cpp index 460e20ff2f..722314bc55 100644 --- a/protocols/ICQ-WIM/src/utils.cpp +++ b/protocols/ICQ-WIM/src/utils.cpp @@ -20,40 +20,6 @@ #include "stdafx.h"
-void CIcqProto::InitContactCache()
-{
- mir_cslock l(m_csCache);
- for (auto &it : AccContacts()) {
- if (isChatRoom(it))
- continue;
-
- // that was previously an ICQ contact
- ptrW wszUin(GetUIN(it));
- if (wszUin != nullptr) {
- delSetting(it, "UIN");
- setWString(it, DB_KEY_ID, wszUin);
- }
- // that was previously a MRA contact
- else {
- CMStringW wszEmail(getMStringW(it, "e-mail"));
- if (!wszEmail.IsEmpty()) {
- delSetting(it, "e-mail");
- setWString(it, DB_KEY_ID, wszEmail);
- }
- }
-
- CMStringW wszId = GetUserId(it);
- auto *pUser = FindUser(wszId);
- if (pUser == nullptr) {
- pUser = new IcqUser(wszId, it);
-
- mir_cslock lck(m_csCache);
- m_arCache.insert(pUser);
- }
- pUser->m_iProcessedMsgId = getId(it, DB_KEY_LASTMSGID);
- }
-}
-
IcqUser* CIcqProto::FindUser(const CMStringW &wszId)
{
IcqUser tmp(wszId, -1);
diff --git a/protocols/JabberG/src/jabber_events.cpp b/protocols/JabberG/src/jabber_events.cpp index cf3c2f92a7..161cc4f427 100644 --- a/protocols/JabberG/src/jabber_events.cpp +++ b/protocols/JabberG/src/jabber_events.cpp @@ -29,6 +29,30 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "jabber_disco.h"
/////////////////////////////////////////////////////////////////////////////////////////
+// OnCacheInit - cache initialization
+
+void CJabberProto::OnCacheInit()
+{
+ for (auto &hContact : AccContacts()) {
+ m_bCacheInited = true;
+
+ SetContactOfflineStatus(hContact);
+
+ if (getByte(hContact, "IsTransport", 0)) {
+ ptrA jid(getUStringA(hContact, "jid"));
+ if (jid == nullptr)
+ continue;
+
+ char *resourcepos = strchr(jid, '/');
+ if (resourcepos != nullptr)
+ *resourcepos = '\0';
+
+ m_lstTransports.insert(mir_strdup(jid));
+ }
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
// OnContactDeleted - processes a contact deletion
bool CJabberProto::OnContactDeleted(MCONTACT hContact, uint32_t)
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 0f038b9344..a6127ac83c 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -311,23 +311,6 @@ void CJabberProto::OnModulesLoaded() HookProtoEvent(ME_IDLE_CHANGED, &CJabberProto::OnIdleChanged);
CheckAllContactsAreTransported();
-
- // Set all contacts to offline
- for (auto &hContact : AccContacts()) {
- SetContactOfflineStatus(hContact);
-
- if (getByte(hContact, "IsTransport", 0)) {
- ptrA jid(getUStringA(hContact, "jid"));
- if (jid == nullptr)
- continue;
-
- char *resourcepos = strchr(jid, '/');
- if (resourcepos != nullptr)
- *resourcepos = '\0';
-
- m_lstTransports.insert(mir_strdup(jid));
- }
- }
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 17fc45c80e..f3f591f4b9 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -149,6 +149,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface int UserIsTyping(MCONTACT hContact, int type) override;
void OnBuildProtoMenu(void) override;
+ void OnCacheInit() override;
bool OnContactDeleted(MCONTACT, uint32_t flags) override;
MWindow OnCreateAccMgrUI(MWindow) override;
void OnMarkRead(MCONTACT, MEVENT) override;
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index f321758700..05690aa8c0 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -109,6 +109,26 @@ CTelegramProto::~CTelegramProto() { } +void CTelegramProto::OnCacheInit() +{ + int iCompatLevel = getByte(DBKEY_COMPAT); + VARSW cachePath(L"%miranda_userdata%\\ChatCache"); + + for (auto &cc : AccContacts()) { + m_bCacheInited = true; + + if (int64_t id = GetId(cc)) { + bool isGroupChat = isChatRoom(cc); + auto *pUser = new TG_USER(id, cc, isGroupChat); + pUser->szAvatarHash = getMStringA(cc, DBKEY_AVATAR_HASH); + m_arUsers.insert(pUser); + if (isGroupChat && iCompatLevel < 3) + _wremove(CMStringW(FORMAT, L"%s\\%d.json", cachePath.get(), cc)); + } + } + setByte(DBKEY_COMPAT, 3); +} + void CTelegramProto::OnContactAdded(MCONTACT hContact) { if (int64_t id = GetId(hContact)) { @@ -146,21 +166,6 @@ bool CTelegramProto::OnContactDeleted(MCONTACT hContact, uint32_t flags) void CTelegramProto::OnModulesLoaded() { - int iCompatLevel = getByte(DBKEY_COMPAT); - VARSW cachePath(L"%miranda_userdata%\\ChatCache"); - - for (auto &cc : AccContacts()) { - if (int64_t id = GetId(cc)) { - bool isGroupChat = isChatRoom(cc); - auto *pUser = new TG_USER(id, cc, isGroupChat); - pUser->szAvatarHash = getMStringA(cc, DBKEY_AVATAR_HASH); - m_arUsers.insert(pUser); - if (isGroupChat && iCompatLevel < 3) - _wremove(CMStringW(FORMAT, L"%s\\%d.json", cachePath.get(), cc)); - } - } - setByte(DBKEY_COMPAT, 3); - m_bSmileyAdd = ServiceExists(MS_SMILEYADD_REPLACESMILEYS); if (m_bSmileyAdd) SmileyAdd_LoadContactSmileys(SMADD_FOLDER, m_szModuleName, GetAvatarPath() + L"\\Stickers\\*.*"); diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 2216a3dc2b..988c2071b8 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -394,6 +394,7 @@ public: int UserIsTyping(MCONTACT hContact, int type) override; void OnBuildProtoMenu() override; + void OnCacheInit() override; void OnContactAdded(MCONTACT hContact) override; bool OnContactDeleted(MCONTACT hContact, uint32_t flags) override; MWindow OnCreateAccMgrUI(MWindow hwndParent) override; diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index 38071deaf6..2dafb64065 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -136,32 +136,30 @@ void WhatsAppProto::RemoveCachedSettings() m_szJid.Empty();
}
-void WhatsAppProto::OnErase()
-{
- m_bUnregister = true;
- ServerThreadWorker();
-
- RemoveCachedSettings();
-
- DeleteDirectoryTreeW(CMStringW(VARSW(L"%miranda_userdata%")) + L"\\" + _A2T(m_szModuleName), false);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// OnModulesLoaded emulator for an account
-
-void WhatsAppProto::OnModulesLoaded()
+void WhatsAppProto::OnCacheInit()
{
- // initialize contacts cache
if (!m_szJid.IsEmpty())
m_arUsers.insert(new WAUser(0, m_szJid, false));
for (auto &cc : AccContacts()) {
+ m_bCacheInited = true;
+
CMStringA szId(getMStringA(cc, DBKEY_ID));
if (!szId.IsEmpty())
m_arUsers.insert(new WAUser(cc, szId, isChatRoom(cc)));
}
}
+void WhatsAppProto::OnErase()
+{
+ m_bUnregister = true;
+ ServerThreadWorker();
+
+ RemoveCachedSettings();
+
+ DeleteDirectoryTreeW(CMStringW(VARSW(L"%miranda_userdata%")) + L"\\" + _A2T(m_szModuleName), false);
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// PROTO_INTERFACE implementation
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h index c85bd73088..8d3ebf94cb 100644 --- a/protocols/WhatsApp/src/proto.h +++ b/protocols/WhatsApp/src/proto.h @@ -472,9 +472,9 @@ public: int SetStatus(int iNewStatus) override;
int UserIsTyping(MCONTACT hContact, int type) override;
+ void OnCacheInit() override;
MWindow OnCreateAccMgrUI(MWindow) override;
void OnErase() override;
- void OnModulesLoaded() override;
// Events //////////////////////////////////////////////////////////////////////////////
|