diff options
author | George Hazan <ghazan@miranda.im> | 2022-07-16 21:23:06 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-07-16 21:23:06 +0300 |
commit | cd4272ca22d47cdf673bfb0e5ec353acca3d9569 (patch) | |
tree | 0e2a4879766d8197cdf8a8fb6d5f5033399a0ea4 /src | |
parent | d6a052756f58211067a7a67d7e3c1dbe7e6c9465 (diff) |
Contact_IsGroupChat - a helper to detect chat rooms
Diffstat (limited to 'src')
-rw-r--r-- | src/core/stdaway/src/awaymsg.cpp | 3 | ||||
-rw-r--r-- | src/core/stdfile/src/file.cpp | 4 | ||||
-rw-r--r-- | src/core/stdmsg/src/msgs.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/chat_clist.cpp | 8 | ||||
-rw-r--r-- | src/mir_app/src/chat_manager.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/contacts.cpp | 15 | ||||
-rw-r--r-- | src/mir_app/src/ei_defaulticons.cpp | 7 | ||||
-rw-r--r-- | src/mir_app/src/meta_menu.cpp | 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/path.cpp | 2 |
11 files changed, 30 insertions, 17 deletions
diff --git a/src/core/stdaway/src/awaymsg.cpp b/src/core/stdaway/src/awaymsg.cpp index 1b4d5d25f9..a2dcca0220 100644 --- a/src/core/stdaway/src/awaymsg.cpp +++ b/src/core/stdaway/src/awaymsg.cpp @@ -131,8 +131,7 @@ static int AwayMsgPreBuildMenu(WPARAM hContact, LPARAM) {
char *szProto = Proto_GetBaseAccountName(hContact);
if (szProto != nullptr) {
- int chatRoom = db_get_b(hContact, szProto, "ChatRoom", 0);
- if (!chatRoom) {
+ if (!Contact_IsGroupChat(hContact, szProto)) {
int status = db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE);
if (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGRECV) {
if (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_3, 0) & Proto_Status2Flag(status)) {
diff --git a/src/core/stdfile/src/file.cpp b/src/core/stdfile/src/file.cpp index e257013663..39e24e7c50 100644 --- a/src/core/stdfile/src/file.cpp +++ b/src/core/stdfile/src/file.cpp @@ -35,7 +35,7 @@ static HGENMENU hSRFileMenuItem; wchar_t* GetContactID(MCONTACT hContact)
{
char *szProto = Proto_GetBaseAccountName(hContact);
- if (db_get_b(hContact, szProto, "ChatRoom", 0) == 1)
+ if (Contact_IsGroupChat(hContact, szProto))
if (wchar_t *theValue = db_get_wsa(hContact, szProto, "ChatRoomID"))
return theValue;
@@ -288,7 +288,7 @@ static int SRFilePreBuildMenu(WPARAM wParam, LPARAM) bool bEnabled = false;
char *szProto = Proto_GetBaseAccountName(wParam);
if (szProto != nullptr) {
- bool isChat = db_get_b(wParam, szProto, "ChatRoom", false) != 0;
+ bool isChat = Contact_IsGroupChat(wParam, szProto);
if (CallProtoService(szProto, PS_GETCAPS, isChat ? PFLAGNUM_4 : PFLAGNUM_1, 0) & (isChat ? PF4_GROUPCHATFILES : PF1_FILESEND)) {
if (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_OFFLINEFILES)
bEnabled = true;
diff --git a/src/core/stdmsg/src/msgs.cpp b/src/core/stdmsg/src/msgs.cpp index 89e5395ace..fbe29a10b3 100644 --- a/src/core/stdmsg/src/msgs.cpp +++ b/src/core/stdmsg/src/msgs.cpp @@ -488,7 +488,7 @@ static int PrebuildContactMenu(WPARAM hContact, LPARAM) char *szProto = Proto_GetBaseAccountName(hContact);
if (szProto) {
// leave this menu item hidden for chats
- if (!db_get_b(hContact, szProto, "ChatRoom", 0))
+ if (!Contact_IsGroupChat(hContact, szProto))
if (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND)
bEnabled = true;
}
diff --git a/src/mir_app/src/chat_clist.cpp b/src/mir_app/src/chat_clist.cpp index 76fc40e721..86f6e451ec 100644 --- a/src/mir_app/src/chat_clist.cpp +++ b/src/mir_app/src/chat_clist.cpp @@ -79,8 +79,8 @@ BOOL SetAllOffline(BOOL, const char *pszModule) char *szProto = Proto_GetBaseAccountName(hContact);
if (!MM_FindModule(szProto))
continue;
- int i = db_get_b(hContact, szProto, "ChatRoom", 0);
- if (i != 0) {
+
+ if (Contact_IsGroupChat(hContact, szProto)) {
db_set_w(hContact, szProto, "ApparentMode", 0);
db_set_w(hContact, szProto, "Status", ID_STATUS_OFFLINE);
}
@@ -97,7 +97,7 @@ int RoomDoubleclicked(WPARAM hContact, LPARAM) char *szProto = Proto_GetBaseAccountName(hContact);
if (MM_FindModule(szProto) == nullptr)
return 0;
- if (db_get_b(hContact, szProto, "ChatRoom", 0) == 0)
+ if (!Contact_IsGroupChat(hContact, szProto))
return 0;
ptrW roomid(db_get_wsa(hContact, szProto, "ChatRoomID"));
@@ -118,7 +118,7 @@ int RoomDoubleclicked(WPARAM hContact, LPARAM) MCONTACT FindRoom(const char *pszModule, const wchar_t *pszRoom)
{
for (auto &hContact : Contacts(pszModule)) {
- if (!db_get_b(hContact, pszModule, "ChatRoom", 0))
+ if (!Contact_IsGroupChat(hContact, pszModule))
continue;
ptrW roomid(db_get_wsa(hContact, pszModule, "ChatRoomID"));
diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index 142f8c162a..0b5485a03a 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -199,7 +199,7 @@ static void SM_FreeSession(SESSION_INFO *si, bool bRemoveContact = false) // contact may have been deleted here already, since function may be called after deleting
// contact so the handle may be invalid, therefore db_get_b shall return 0
- if (si->hContact && db_get_b(si->hContact, si->pszModule, "ChatRoom", 0) != 0) {
+ if (si->hContact && Contact_IsGroupChat(si->hContact, si->pszModule)) {
g_chatApi.SetOffline(si->hContact, (si->iType == GCW_CHATROOM || si->iType == GCW_PRIVMESS) ? TRUE : FALSE);
db_set_s(si->hContact, si->pszModule, "Topic", "");
db_set_s(si->hContact, si->pszModule, "StatusBar", "");
diff --git a/src/mir_app/src/contacts.cpp b/src/mir_app/src/contacts.cpp index 57a1833b72..81a899368c 100644 --- a/src/mir_app/src/contacts.cpp +++ b/src/mir_app/src/contacts.cpp @@ -280,9 +280,22 @@ MIR_APP_DLL(int) Contact_GetStatus(MCONTACT hContact) ///////////////////////////////////////////////////////////////////////////////
+MIR_APP_DLL(bool) Contact_IsGroupChat(MCONTACT hContact, const char *szProto)
+{
+ if (szProto == nullptr) {
+ szProto = Proto_GetBaseAccountName(hContact);
+ if (szProto == nullptr)
+ return false;
+ }
+
+ return db_get_b(hContact, szProto, "ChatRoom") != 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
MIR_APP_DLL(bool) Contact_IsHidden(MCONTACT hContact)
{
- return db_get_b(hContact, "CList", "Hidden", 0) != 0;
+ return db_get_b(hContact, "CList", "Hidden") != 0;
}
MIR_APP_DLL(void) Contact_Hide(MCONTACT hContact, bool bHidden)
diff --git a/src/mir_app/src/ei_defaulticons.cpp b/src/mir_app/src/ei_defaulticons.cpp index 5a7b945d1a..8cfe52defb 100644 --- a/src/mir_app/src/ei_defaulticons.cpp +++ b/src/mir_app/src/ei_defaulticons.cpp @@ -45,14 +45,13 @@ static void SetVisibility(MCONTACT hContact, int apparentMode, bool clear) HANDLE hExtraIcon, hIcolib = nullptr; - if (db_get_b(hContact, proto, "ChatRoom", 0)) { - // Is chat + // Is chat + if (Contact_IsGroupChat(hContact, proto)) { hExtraIcon = hExtraChat; if (apparentMode == ID_STATUS_OFFLINE) hIcolib = IcoLib_GetIconHandle("ChatActivity"); } - else { - // Not chat + else { // Not chat hExtraIcon = hExtraVisibility; if (apparentMode == ID_STATUS_OFFLINE) hIcolib = Skin_GetIconHandle(SKINICON_OTHER_INVISIBLE_ALL); diff --git a/src/mir_app/src/meta_menu.cpp b/src/mir_app/src/meta_menu.cpp index 7956574fd5..f337b699bb 100644 --- a/src/mir_app/src/meta_menu.cpp +++ b/src/mir_app/src/meta_menu.cpp @@ -318,7 +318,7 @@ int Meta_ModifyMenu(WPARAM hMeta, LPARAM) }
else {
// The contact is neutral
- bool bHideChat = db_get_b(hMeta, cc->szProto, "ChatRoom", 0) == 0;
+ bool bHideChat = !Contact_IsGroupChat(hMeta, cc->szProto);
Menu_ShowItem(hMenuAdd, bHideChat);
Menu_ShowItem(hMenuConvert, bHideChat);
Menu_ShowItem(hMenuEdit, false);
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 6b3cc265a2..ac4c2904f3 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -798,3 +798,4 @@ Srmm_CreateHotkey @886 NONAME ??_7CUserInfoPageDlg@@6B@ @891 NONAME
?OnRefresh@CUserInfoPageDlg@@UAE_NXZ @892 NONAME
?SetContact@CUserInfoPageDlg@@QAEXI@Z @893 NONAME
+?Contact_IsGroupChat@@YG_NIPBD@Z @894 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 229b99bbc1..ed227d6adb 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -798,3 +798,4 @@ Srmm_CreateHotkey @886 NONAME ??_7CUserInfoPageDlg@@6B@ @891 NONAME
?OnRefresh@CUserInfoPageDlg@@UEAA_NXZ @892 NONAME
?SetContact@CUserInfoPageDlg@@QEAAXI@Z @893 NONAME
+?Contact_IsGroupChat@@YA_NIPEBD@Z @894 NONAME
diff --git a/src/mir_app/src/path.cpp b/src/mir_app/src/path.cpp index ced42f99b6..aebc78e66b 100644 --- a/src/mir_app/src/path.cpp +++ b/src/mir_app/src/path.cpp @@ -35,7 +35,7 @@ static wchar_t tszAvatarRoot[MAX_PATH]; wchar_t* GetContactID(MCONTACT hContact)
{
char *szProto = Proto_GetBaseAccountName(hContact);
- if (db_get_b(hContact, szProto, "ChatRoom", 0) == 1)
+ if (Contact_IsGroupChat(hContact, szProto))
return db_get_wsa(hContact, szProto, "ChatRoomID");
return Contact_GetInfo(CNF_UNIQUEID, hContact, szProto);
|