From 9885bf54f788e831a80c76001340aa68d31d2aaa Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 25 Jan 2023 18:34:51 +0300 Subject: Group chats: ChatRoomID setting replaced with real protocol id --- src/mir_app/src/CMPluginBase.cpp | 6 ++++-- src/mir_app/src/chat.h | 1 - src/mir_app/src/chat_clist.cpp | 42 ++++++++++++++++++++++++---------------- src/mir_app/src/chat_manager.cpp | 28 ++++++++++++++++++++++++++- src/mir_app/src/contacts.cpp | 10 +++------- src/mir_app/src/mir_app.def | 2 +- src/mir_app/src/mir_app64.def | 2 +- src/mir_app/src/miranda.h | 1 + src/mir_app/src/path.cpp | 13 ++----------- src/mir_app/src/proto_utils.cpp | 2 +- 10 files changed, 65 insertions(+), 42 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/src/CMPluginBase.cpp b/src/mir_app/src/CMPluginBase.cpp index 92c444e46c..910b1bbd44 100644 --- a/src/mir_app/src/CMPluginBase.cpp +++ b/src/mir_app/src/CMPluginBase.cpp @@ -332,12 +332,14 @@ void CMPluginBase::RegisterProtocol(int type, pfnInitProto fnInit, pfnUninitProt } } -void CMPluginBase::SetUniqueId(const char *pszUniqueId) +void CMPluginBase::SetUniqueId(const char *pszUniqueId, int type) { if (pszUniqueId == nullptr) return; MBaseProto *pd = g_arProtos.find((MBaseProto*)&m_szModuleName); - if (pd != nullptr) + if (pd != nullptr) { pd->szUniqueId = mir_strdup(pszUniqueId); + pd->iUniqueIdType = (type == 0) ? DBVT_WCHAR : type; + } } diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index cab71e9849..00d2f183fe 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -90,7 +90,6 @@ void UM_SortUser(SESSION_INFO *si); // clist.c MCONTACT AddRoom(const char *pszModule, const wchar_t *pszRoom, const wchar_t *pszDisplayName, int iType); -MCONTACT FindRoom(const char *pszModule, const wchar_t *pszRoom); BOOL SetAllOffline(BOOL bHide, const char *pszModule); BOOL SetOffline(MCONTACT hContact, BOOL bHide); diff --git a/src/mir_app/src/chat_clist.cpp b/src/mir_app/src/chat_clist.cpp index 7358635617..85b56632c7 100644 --- a/src/mir_app/src/chat_clist.cpp +++ b/src/mir_app/src/chat_clist.cpp @@ -22,6 +22,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "chat.h" +static MCONTACT FindRoom(const char *pszModule, const wchar_t *pszRoom) +{ + for (auto &hContact : Contacts(pszModule)) { + if (!Contact::IsGroupChat(hContact, pszModule)) + continue; + + ptrW roomid(Contact::GetInfo(CNF_UNIQUEID, hContact, pszModule)); + if (roomid != nullptr && !mir_wstrcmpi(roomid, pszRoom)) + return hContact; + } + + return 0; +} + MCONTACT AddRoom(const char *pszModule, const wchar_t *pszRoom, const wchar_t *pszDisplayName, int iType) { ptrW pwszGroup(Chat_GetGroup()); @@ -34,7 +48,7 @@ MCONTACT AddRoom(const char *pszModule, const wchar_t *pszRoom, const wchar_t *p } } - MCONTACT hContact = g_chatApi.FindRoom(pszModule, pszRoom); + MCONTACT hContact = FindRoom(pszModule, pszRoom); if (hContact) { // contact exists, let's assign the standard group name if it's missing if (mir_wstrlen(pwszGroup)) { @@ -55,8 +69,16 @@ MCONTACT AddRoom(const char *pszModule, const wchar_t *pszRoom, const wchar_t *p Proto_AddToContact(hContact, pszModule); Clist_SetGroup(hContact, pwszGroup); + if (auto *pa = Proto_GetAccount(pszModule)) { + if (MBaseProto *pd = g_arProtos.find((MBaseProto *)&pa->szProtoName)) { + if (pd->iUniqueIdType == DBVT_DWORD) + db_set_w(hContact, pszModule, pd->szUniqueId, _wtoi(pszRoom)); + else + db_set_ws(hContact, pszModule, pd->szUniqueId, pszRoom); + } + } + db_set_ws(hContact, pszModule, "Nick", pszDisplayName); - db_set_ws(hContact, pszModule, "ChatRoomID", pszRoom); db_set_b(hContact, pszModule, "ChatRoom", (uint8_t)iType); db_set_w(hContact, pszModule, "Status", ID_STATUS_OFFLINE); return hContact; @@ -101,7 +123,7 @@ int RoomDoubleclicked(WPARAM hContact, LPARAM) if (!Contact::IsGroupChat(hContact, szProto)) return 0; - ptrW roomid(db_get_wsa(hContact, szProto, "ChatRoomID")); + ptrW roomid(Contact::GetInfo(CNF_UNIQUEID, hContact, szProto)); if (roomid == nullptr) return 0; @@ -115,17 +137,3 @@ int RoomDoubleclicked(WPARAM hContact, LPARAM) } return 1; } - -MCONTACT FindRoom(const char *pszModule, const wchar_t *pszRoom) -{ - for (auto &hContact : Contacts(pszModule)) { - if (!Contact::IsGroupChat(hContact, pszModule)) - continue; - - ptrW roomid(db_get_wsa(hContact, pszModule, "ChatRoomID")); - if (roomid != nullptr && !mir_wstrcmpi(roomid, pszRoom)) - return hContact; - } - - return 0; -} diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index 7019e3a2a7..9818d1da9b 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -935,7 +935,6 @@ static void ResetApi() g_chatApi.SetOffline = ::SetOffline; g_chatApi.SetAllOffline = ::SetAllOffline; - g_chatApi.FindRoom = ::FindRoom; g_chatApi.DoRtfToTags = ::DoRtfToTags; g_chatApi.Log_CreateRTF = ::Log_CreateRTF; @@ -958,6 +957,32 @@ static void ResetApi() ///////////////////////////////////////////////////////////////////////////////////////// +static void CheckUpdate() +{ + if (db_get_b(0, "Compatibility", "GroupChats") < 1) { + for (auto &cc : Contacts()) { + if (auto *pa = Proto_GetContactAccount(cc)) { + if (!db_get_b(cc, pa->szModuleName, "ChatRoom")) + continue; + + ptrW wszId(db_get_wsa(cc, pa->szModuleName, "ChatRoomID")); + if (wszId == nullptr) + continue; + + if (MBaseProto *pd = g_arProtos.find((MBaseProto *)&pa->szProtoName)) { + if (pd->iUniqueIdType == DBVT_DWORD) + db_set_dw(cc, pa->szModuleName, pd->szUniqueId, _wtoi(wszId)); + else + db_set_ws(cc, pa->szModuleName, pd->szUniqueId, wszId); + + db_unset(cc, pa->szModuleName, "ChatRoomID"); + } + } + } + db_set_b(0, "Compatibility", "GroupChats", 1); + } +} + MIR_APP_DLL(CHAT_MANAGER*) Chat_CustomizeApi(const CHAT_MANAGER_INITDATA *pInit) { if (pInit == nullptr) @@ -1011,6 +1036,7 @@ MIR_APP_DLL(CHAT_MANAGER*) Chat_CustomizeApi(const CHAT_MANAGER_INITDATA *pInit) LoadChatIcons(); RegisterFonts(); OptionsInit(); + CheckUpdate(); return &g_chatApi; } diff --git a/src/mir_app/src/contacts.cpp b/src/mir_app/src/contacts.cpp index 8cec2a273a..376735f87e 100644 --- a/src/mir_app/src/contacts.cpp +++ b/src/mir_app/src/contacts.cpp @@ -82,7 +82,6 @@ MIR_APP_DLL(wchar_t*) Contact::GetInfo(int type, MCONTACT hContact, const char * if (szProto == nullptr) return nullptr; - const char *uid; wchar_t *res; DBVARIANT dbv; switch (type) { @@ -164,8 +163,7 @@ MIR_APP_DLL(wchar_t*) Contact::GetInfo(int type, MCONTACT hContact, const char * return mir_wstrdup(buf); } - uid = Proto_GetUniqueId(szProto); - if (uid) + if (auto *uid = Proto_GetUniqueId(szProto)) return ProcessDatabaseValueDefault(hContact, szProto, uid); break; @@ -173,8 +171,7 @@ MIR_APP_DLL(wchar_t*) Contact::GetInfo(int type, MCONTACT hContact, const char * if (res = ProcessDatabaseValueDefault(hContact, szProto, "display_uid")) return res; - uid = Proto_GetUniqueId(szProto); - if (uid) + if (auto *uid = Proto_GetUniqueId(szProto)) return ProcessDatabaseValueDefault(hContact, szProto, uid); break; @@ -209,8 +206,7 @@ MIR_APP_DLL(wchar_t*) Contact::GetInfo(int type, MCONTACT hContact, const char * case 5: // Unique id // protocol must define a PFLAG_UNIQUEIDSETTING - uid = Proto_GetUniqueId(szProto); - if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid) { + if (auto *uid = Proto_GetUniqueId(szProto)) { if (!db_get_ws(hContact, szProto, uid, &dbv)) { if (dbv.type == DBVT_BYTE || dbv.type == DBVT_WORD || dbv.type == DBVT_DWORD) { long value = (dbv.type == DBVT_BYTE) ? dbv.bVal : (dbv.type == DBVT_WORD ? dbv.wVal : dbv.dVal); diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 694de1eb1f..cc94a44a7c 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -456,7 +456,7 @@ Proto_SetUniqueId @549 ?IsEnabled@PROTOACCOUNT@@QBE_NXZ @552 NONAME ?IsLocked@PROTOACCOUNT@@QBE_NXZ @553 NONAME ?IsVisible@PROTOACCOUNT@@QBE_NXZ @554 NONAME -?SetUniqueId@CMPluginBase@@IAEXPBD@Z @555 NONAME +?SetUniqueId@CMPluginBase@@IAEXPBDH@Z @555 NONAME Clist_GetProtocolVisibility @556 ?Accounts@@YGAAU?$LIST@UPROTOACCOUNT@@@@XZ @557 NONAME Clist_InitAutoRebuild @558 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index e8bfae2ac4..23413c088a 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -456,7 +456,7 @@ Proto_SetUniqueId @549 ?IsEnabled@PROTOACCOUNT@@QEBA_NXZ @552 NONAME ?IsLocked@PROTOACCOUNT@@QEBA_NXZ @553 NONAME ?IsVisible@PROTOACCOUNT@@QEBA_NXZ @554 NONAME -?SetUniqueId@CMPluginBase@@IEAAXPEBD@Z @555 NONAME +?SetUniqueId@CMPluginBase@@IEAAXPEBDH@Z @555 NONAME Clist_GetProtocolVisibility @556 ?Accounts@@YAAEAU?$LIST@UPROTOACCOUNT@@@@XZ @557 NONAME Clist_InitAutoRebuild @558 diff --git a/src/mir_app/src/miranda.h b/src/mir_app/src/miranda.h index b0508c18f3..b2f0605959 100644 --- a/src/mir_app/src/miranda.h +++ b/src/mir_app/src/miranda.h @@ -154,6 +154,7 @@ struct MBaseProto : public PROTOCOLDESCRIPTOR, public MZeroedObject HINSTANCE hInst; char *szUniqueId; // name of the unique setting that identifies a contact + int iUniqueIdType; // DBVT_* }; extern OBJLIST g_arProtos; diff --git a/src/mir_app/src/path.cpp b/src/mir_app/src/path.cpp index 49e5cd7487..9f66a2991d 100644 --- a/src/mir_app/src/path.cpp +++ b/src/mir_app/src/path.cpp @@ -32,15 +32,6 @@ extern wchar_t g_profileDir[MAX_PATH], g_shortProfileName[MAX_PATH]; static HANDLE hAvatarFolder; static wchar_t tszAvatarRoot[MAX_PATH]; -wchar_t* GetContactID(MCONTACT hContact) -{ - char *szProto = Proto_GetBaseAccountName(hContact); - if (Contact::IsGroupChat(hContact, szProto)) - return db_get_wsa(hContact, szProto, "ChatRoomID"); - - return Contact::GetInfo(CNF_UNIQUEID, hContact, szProto); -} - ///////////////////////////////////////////////////////////////////////////////////////// // Variables parser @@ -63,7 +54,7 @@ static __forceinline char *GetContactNickX(const char*, MCONTACT hContact) static __forceinline char* GetContactIDX(const char*, MCONTACT hContact) { - wchar_t *id = GetContactID(hContact); + wchar_t *id = Contact::GetInfo(CNF_UNIQUEID, hContact); char* res = mir_u2a(id); mir_free(id); return res; @@ -151,7 +142,7 @@ static __forceinline wchar_t* GetContactNickX(const wchar_t*, MCONTACT hContact) static __forceinline wchar_t* GetContactIDX(const wchar_t*, MCONTACT hContact) { - return GetContactID(hContact); + return Contact::GetInfo(CNF_UNIQUEID, hContact); } static __forceinline wchar_t* GetEnvironmentVariableX(const wchar_t *variable) diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp index 281d76719e..85ef574e3c 100644 --- a/src/mir_app/src/proto_utils.cpp +++ b/src/mir_app/src/proto_utils.cpp @@ -110,7 +110,7 @@ void PROTO_INTERFACE::setAllContactStatuses(int iStatus, bool bSkipChats) for (auto &hContact : AccContacts()) { if (isChatRoom(hContact)) { if (!bSkipChats && iStatus == ID_STATUS_OFFLINE) { - ptrW wszRoom(getWStringA(hContact, "ChatRoomID")); + ptrW wszRoom(Contact::GetInfo(CNF_UNIQUEID, hContact)); if (wszRoom != nullptr) Chat_Control(m_szModuleName, wszRoom, SESSION_OFFLINE); } -- cgit v1.2.3