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 | |
parent | 17b6a94812b2dbf4af29fb5d84064ceb1c7d393e (diff) |
fixes #4555 (Задваиваются контакты протоколов, где есть кэш)
-rw-r--r-- | include/m_protoint.h | 6 | ||||
-rw-r--r-- | libs/win32/mir_app.lib | bin | 298050 -> 298356 bytes | |||
-rw-r--r-- | libs/win64/mir_app.lib | bin | 298072 -> 298382 bytes | |||
-rw-r--r-- | plugins/Import/src/import.cpp | 16 | ||||
-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 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 1 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 1 | ||||
-rw-r--r-- | src/mir_app/src/proto_accs.cpp | 5 | ||||
-rw-r--r-- | src/mir_app/src/proto_interface.cpp | 8 |
22 files changed, 214 insertions, 165 deletions
diff --git a/include/m_protoint.h b/include/m_protoint.h index 08a124c2aa..8dc0955a63 100644 --- a/include/m_protoint.h +++ b/include/m_protoint.h @@ -80,8 +80,8 @@ protected: public:
int m_iStatus; // current protocol status
int m_iDesiredStatus; // status to be set after logging in
- int m_iXStatus; // extanded status
- int m_iVersion; // version 2 or higher designate support of Unicode services
+ uint8_t m_iVersion; // version 2 or higher designate support of Unicode services
+ bool m_bCacheInited; // was cache initialized or not
wchar_t* m_tszUserName; // human readable protocol's name
char* m_szModuleName; // internal protocol name, also its database module name
HANDLE m_hProtoIcon = 0; // icon to be displayed in the account manager
@@ -257,6 +257,8 @@ public: // builds the account's protocol menu
virtual void OnBuildProtoMenu(void);
+ virtual void OnCacheInit(void);
+
// called when an account's contact is added
virtual void OnContactAdded(MCONTACT);
diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib Binary files differindex 7b87b669a3..0345088c10 100644 --- a/libs/win32/mir_app.lib +++ b/libs/win32/mir_app.lib diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib Binary files differindex 77260252dc..5757c6d60b 100644 --- a/libs/win64/mir_app.lib +++ b/libs/win64/mir_app.lib diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp index 1297462e3d..e40546ba57 100644 --- a/plugins/Import/src/import.cpp +++ b/plugins/Import/src/import.cpp @@ -1058,6 +1058,22 @@ void CImportBatch::DoImport() AddMessage(L"");
dstDb->Flush();
+ // Create contact's cache for new accounts
+ {
+ int protoCount;
+ PROTOACCOUNT **accs;
+ Proto_EnumAccounts(&protoCount, &accs);
+
+ for (int i = 0; i < protoCount; i++) {
+ auto *pa = accs[i];
+
+ if (!pa->ppro)
+ continue;
+ if (!pa->ppro->m_bCacheInited)
+ pa->ppro->OnCacheInit();
+ }
+ }
+
// Restore database writing mode
dstDb->SetCacheSafetyMode(TRUE);
db_setCurrent(dstDb);
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 //////////////////////////////////////////////////////////////////////////////
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index dc1d1724a8..a719418dc2 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -985,3 +985,4 @@ g_hevEventSetJson @1109 NONAME ??_7MJsonWebSocket@@6B@ @1122 NONAME
?process@MJsonWebSocket@@EAEXPBEI@Z @1123 NONAME
_Proto_CanDeleteHistory@8 @1124 NONAME
+?OnCacheInit@PROTO_INTERFACE@@UAEXXZ @1125 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index ea04f85eaa..75f5b0c3b2 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -985,3 +985,4 @@ g_hevEventSetJson @1103 NONAME ??_7MJsonWebSocket@@6B@ @1116 NONAME
?process@MJsonWebSocket@@EEAAXPEBE_K@Z @1117 NONAME
Proto_CanDeleteHistory @1118 NONAME
+?OnCacheInit@PROTO_INTERFACE@@UEAAXXZ @1119 NONAME
diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp index e0b3f02452..f82ca53dae 100644 --- a/src/mir_app/src/proto_accs.cpp +++ b/src/mir_app/src/proto_accs.cpp @@ -241,12 +241,13 @@ bool ActivateAccount(PROTOACCOUNT *pa, bool bIsDynamic) return false;
pa->ppro = ppi;
+ ppi->OnCacheInit();
if (bIsDynamic) {
if (g_bModulesLoadedFired)
- pa->ppro->OnModulesLoaded();
+ ppi->OnModulesLoaded();
if (!db_get_b(0, "CList", "MoveProtoMenus", true))
- pa->ppro->OnBuildProtoMenu();
+ ppi->OnBuildProtoMenu();
pa->bDynDisabled = false;
}
}
diff --git a/src/mir_app/src/proto_interface.cpp b/src/mir_app/src/proto_interface.cpp index 584c0dbe40..dd8219703d 100644 --- a/src/mir_app/src/proto_interface.cpp +++ b/src/mir_app/src/proto_interface.cpp @@ -32,9 +32,10 @@ static HGENMENU hReqAuth = nullptr, hGrantAuth = nullptr, hRevokeAuth = nullptr, /////////////////////////////////////////////////////////////////////////////////////////
// protocol constructor & destructor
-PROTO_INTERFACE::PROTO_INTERFACE(const char *pszModuleName, const wchar_t *ptszUserName)
+PROTO_INTERFACE::PROTO_INTERFACE(const char *pszModuleName, const wchar_t *ptszUserName) :
+ m_iVersion(2),
+ m_bCacheInited(false)
{
- m_iVersion = 2;
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
m_szModuleName = mir_strdup(pszModuleName);
m_tszUserName = mir_wstrdup(ptszUserName);
@@ -77,6 +78,9 @@ CMStringW PROTO_INTERFACE::GetPreviewPath() const void PROTO_INTERFACE::OnBuildProtoMenu()
{}
+void PROTO_INTERFACE::OnCacheInit()
+{}
+
void PROTO_INTERFACE::OnContactAdded(MCONTACT)
{}
|