From 0b084cff5bb71a140d5181caa452a95b74ac8103 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 8 Dec 2018 18:35:02 +0300 Subject: chats: - Chat_GetGroup & Chat_SetGroup functions added to stop the zoo with chat default group name; - fixes #1655 (custom chat group name doesn't work in Discord) --- include/m_chat.h | 3 +++ libs/win32/mir_app.lib | Bin 186008 -> 186428 bytes libs/win64/mir_app.lib | Bin 181270 -> 181650 bytes plugins/Scriver/src/chat_options.cpp | 25 +++++-------------------- plugins/TabSRMM/src/chat_options.cpp | 14 ++++---------- protocols/Discord/src/guilds.cpp | 9 +++++++-- src/core/stdmsg/src/chat_options.cpp | 17 ++--------------- src/mir_app/src/chat_clist.cpp | 26 ++++++++++---------------- src/mir_app/src/chat_tools.cpp | 16 ++++++++++++++++ src/mir_app/src/mir_app.def | 2 ++ src/mir_app/src/mir_app64.def | 2 ++ 11 files changed, 51 insertions(+), 63 deletions(-) diff --git a/include/m_chat.h b/include/m_chat.h index 6eccba6551..818883ff62 100644 --- a/include/m_chat.h +++ b/include/m_chat.h @@ -378,6 +378,9 @@ EXTERN_C MIR_APP_DLL(int) Chat_ChangeUserId(const char *szModule, const wchar_t EXTERN_C MIR_APP_DLL(int) Chat_SendUserMessage(const char *szModule, const wchar_t *wszId, const wchar_t *wszText); EXTERN_C MIR_APP_DLL(int) Chat_SetStatusbarText(const char *szModule, const wchar_t *wszId, const wchar_t *wszText); +EXTERN_C MIR_APP_DLL(wchar_t*) Chat_GetGroup(void); +EXTERN_C MIR_APP_DLL(void) Chat_SetGroup(const wchar_t*); + EXTERN_C MIR_APP_DLL(wchar_t*) Chat_UnescapeTags(wchar_t *str_in); ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib index 78f4913b84..0b3694c692 100644 Binary files a/libs/win32/mir_app.lib and b/libs/win32/mir_app.lib differ diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib index ad15a3a617..c03d0b753b 100644 Binary files a/libs/win64/mir_app.lib and b/libs/win64/mir_app.lib differ diff --git a/plugins/Scriver/src/chat_options.cpp b/plugins/Scriver/src/chat_options.cpp index d128a7d832..fdf53a98f9 100644 --- a/plugins/Scriver/src/chat_options.cpp +++ b/plugins/Scriver/src/chat_options.cpp @@ -221,16 +221,6 @@ static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM p return 0; } -static void InitSetting(wchar_t **ppPointer, char *pszSetting, wchar_t *pszDefault) -{ - DBVARIANT dbv; - if (!db_get_ws(0, CHAT_MODULE, pszSetting, &dbv)) { - replaceStrW(*ppPointer, dbv.pwszVal); - db_free(&dbv); - } - else replaceStrW(*ppPointer, pszDefault); -} - #define OPT_FIXHEADINGS (WM_USER+1) INT_PTR CALLBACK DlgProcOptions1(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) @@ -248,12 +238,7 @@ INT_PTR CALLBACK DlgProcOptions1(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading1, branch1, _countof(branch1), 0); FillBranch(GetDlgItem(hwndDlg, IDC_CHAT_CHECKBOXES), hListHeading4, branch4, _countof(branch4), 0x1000); SendMessage(hwndDlg, OPT_FIXHEADINGS, 0, 0); - { - wchar_t* pszGroup = nullptr; - InitSetting(&pszGroup, "AddToGroup", L"Chat rooms"); - SetDlgItemText(hwndDlg, IDC_CHAT_GROUP, pszGroup); - mir_free(pszGroup); - } + SetDlgItemText(hwndDlg, IDC_CHAT_GROUP, ptrW(Chat_GetGroup())); break; case OPT_FIXHEADINGS: @@ -316,11 +301,11 @@ INT_PTR CALLBACK DlgProcOptions1(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM case PSN_APPLY: int iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_CHAT_GROUP)); if (iLen > 0) { - ptrA pszText((char*)mir_alloc(iLen + 1)); - GetDlgItemTextA(hwndDlg, IDC_CHAT_GROUP, pszText, iLen + 1); - db_set_s(0, CHAT_MODULE, "AddToGroup", pszText); + ptrW pszText((wchar_t*)mir_alloc(sizeof(wchar_t)*(iLen + 1))); + GetDlgItemTextW(hwndDlg, IDC_CHAT_GROUP, pszText, iLen + 1); + Chat_SetGroup(pszText); } - else db_set_s(0, CHAT_MODULE, "AddToGroup", ""); + else Chat_SetGroup(nullptr); iLen = SendDlgItemMessage(hwndDlg, IDC_CHAT_SPIN2, UDM_GETPOS, 0, 0); if (iLen > 0) diff --git a/plugins/TabSRMM/src/chat_options.cpp b/plugins/TabSRMM/src/chat_options.cpp index e6329e9ce7..3b973cc1b2 100644 --- a/plugins/TabSRMM/src/chat_options.cpp +++ b/plugins/TabSRMM/src/chat_options.cpp @@ -535,6 +535,7 @@ class CChatSettingsDlg : public CChatBaseOptionDlg HTREEITEM hListHeading2 = nullptr; CCtrlTreeView treeCheck; + CCtrlEdit edtGroup; HTREEITEM InsertBranch(wchar_t* pszDescr, BOOL bExpanded) { @@ -594,6 +595,7 @@ class CChatSettingsDlg : public CChatBaseOptionDlg public: CChatSettingsDlg() : CChatBaseOptionDlg(IDD_OPTIONS1), + edtGroup(this, IDC_GROUP), treeCheck(this, IDC_CHECKBOXES) {} @@ -610,21 +612,13 @@ public: FillBranch(hListHeading1, branch1, _countof(branch1), 0x0000); FillBranch(hListHeading2, branch2, _countof(branch2), 0x0000); - ptrW pszGroup(db_get_wsa(0, CHAT_MODULE, "AddToGroup")); - SetDlgItemText(m_hwnd, IDC_GROUP, (pszGroup != nullptr) ? pszGroup : TranslateT("Chat rooms")); + edtGroup.SetText(ptrW(Chat_GetGroup())); return true; } bool OnApply() override { - int iLen = GetWindowTextLength(GetDlgItem(m_hwnd, IDC_GROUP)); - if (iLen > 0) { - wchar_t *pszText = (wchar_t*)mir_alloc((iLen + 2) * sizeof(wchar_t)); - GetDlgItemText(m_hwnd, IDC_GROUP, pszText, iLen + 1); - db_set_ws(0, CHAT_MODULE, "AddToGroup", pszText); - mir_free(pszText); - } - else db_set_ws(0, CHAT_MODULE, "AddToGroup", L""); + Chat_SetGroup(ptrW(edtGroup.GetText())); SaveBranch(branch1, _countof(branch1)); SaveBranch(branch2, _countof(branch2)); diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index b77f2b67b0..232d18d6bd 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -71,8 +71,13 @@ void CDiscordProto::ProcessRole(CDiscordGuild *guild, const JSONNode &role) static void sttSetGroupName(MCONTACT hContact, const wchar_t *pwszGroupName) { ptrW wszOldName(db_get_wsa(hContact, "CList", "Group")); - if (wszOldName == nullptr || !mir_wstrcmpi(wszOldName, TranslateT("Chat rooms"))) - db_set_ws(hContact, "CList", "Group", pwszGroupName); + if (wszOldName != nullptr) { + ptrW wszChatGroup(Chat_GetGroup()); + if (mir_wstrcmpi(wszOldName, wszChatGroup)) + return; // custom group, don't touch it + } + + db_set_ws(hContact, "CList", "Group", pwszGroupName); } void CDiscordProto::BatchChatCreate(void *param) diff --git a/src/core/stdmsg/src/chat_options.cpp b/src/core/stdmsg/src/chat_options.cpp index 932ca3f07b..91a6d735c5 100644 --- a/src/core/stdmsg/src/chat_options.cpp +++ b/src/core/stdmsg/src/chat_options.cpp @@ -200,16 +200,6 @@ HANDLE GetIconHandle(const char *pszIcoLibName) return IcoLib_GetIconHandle(szTemp); } -static void InitSetting(wchar_t** ppPointer, char* pszSetting, wchar_t* pszDefault) -{ - DBVARIANT dbv; - if (!db_get_ws(0, CHAT_MODULE, pszSetting, &dbv)) { - replaceStrW(*ppPointer, dbv.pwszVal); - db_free(&dbv); - } - else replaceStrW(*ppPointer, pszDefault); -} - ///////////////////////////////////////////////////////////////////////////////////////// // General options @@ -475,10 +465,7 @@ public: spin4.SetRange(255, 10); spin4.SetPosition(db_get_b(0, CHAT_MODULE, "NicklistRowDist", 12)); - wchar_t* pszGroup = nullptr; - InitSetting(&pszGroup, "AddToGroup", L"Chat rooms"); - edtGroup.SetText(pszGroup); - mir_free(pszGroup); + edtGroup.SetText(ptrW(Chat_GetGroup())); wchar_t szTemp[MAX_PATH]; PathToRelativeW(g_Settings.pszLogDir, szTemp); @@ -539,7 +526,7 @@ public: else db_unset(0, CHAT_MODULE, "HeaderOutgoing"); - db_set_ws(0, CHAT_MODULE, "AddToGroup", ptrW(rtrimw(edtGroup.GetText()))); + Chat_SetGroup(ptrW(rtrimw(edtGroup.GetText()))); g_Settings.bHighlightEnabled = chkHighlight.GetState(); db_set_b(0, CHAT_MODULE, "HighlightEnabled", g_Settings.bHighlightEnabled); diff --git a/src/mir_app/src/chat_clist.cpp b/src/mir_app/src/chat_clist.cpp index 2c6b74cf1f..43944f535b 100644 --- a/src/mir_app/src/chat_clist.cpp +++ b/src/mir_app/src/chat_clist.cpp @@ -24,28 +24,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. MCONTACT AddRoom(const char *pszModule, const wchar_t *pszRoom, const wchar_t *pszDisplayName, int iType) { - wchar_t pszGroup[50]; *pszGroup = '\0'; - ptrW groupName(db_get_wsa(0, CHAT_MODULE, "AddToGroup")); - if (groupName) - wcsncpy_s(pszGroup, groupName, _TRUNCATE); - else - mir_wstrcpy(pszGroup, L"Chat rooms"); - - if (pszGroup[0]) { - MGROUP hGroup = Clist_GroupExists(pszGroup); + ptrW wszGroup(Chat_GetGroup()); + if (mir_wstrlen(wszGroup)) { + MGROUP hGroup = Clist_GroupExists(wszGroup); if (hGroup == 0) { - hGroup = Clist_GroupCreate(0, pszGroup); + hGroup = Clist_GroupCreate(0, wszGroup); if (hGroup) Clist_GroupSetExpanded(hGroup, 1); } } MCONTACT hContact = g_chatApi.FindRoom(pszModule, pszRoom); - if (hContact) { //contact exist, make sure it is in the right group - if (pszGroup[0]) { + if (hContact) { // contact exist, make sure it is in the right group + if (mir_wstrlen(wszGroup)) { ptrW grpName(db_get_wsa(hContact, "CList", "Group")); - if (!mir_wstrcmp(pszGroup, grpName)) - db_set_ws(hContact, "CList", "Group", pszGroup); + if (!mir_wstrcmp(wszGroup, grpName)) + db_set_ws(hContact, "CList", "Group", wszGroup); } db_set_w(hContact, pszModule, "Status", ID_STATUS_OFFLINE); @@ -58,8 +52,8 @@ MCONTACT AddRoom(const char *pszModule, const wchar_t *pszRoom, const wchar_t *p return 0; Proto_AddToContact(hContact, pszModule); - if (pszGroup[0]) - db_set_ws(hContact, "CList", "Group", pszGroup); + if (mir_wstrlen(wszGroup)) + db_set_ws(hContact, "CList", "Group", wszGroup); else db_unset(hContact, "CList", "Group"); db_set_ws(hContact, pszModule, "Nick", pszDisplayName); diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index 8bc297ec50..deba485f86 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -685,6 +685,22 @@ wchar_t* GetChatLogsFilename(SESSION_INFO *si, time_t tTime) ///////////////////////////////////////////////////////////////////////////////////////// +MIR_APP_DLL(wchar_t*) Chat_GetGroup() +{ + ptrW pszGroup(db_get_wsa(0, CHAT_MODULE, "AddToGroup")); + return (pszGroup) ? pszGroup.detach() : mir_wstrdup(TranslateT("Chat rooms")); +} + +MIR_APP_DLL(void) Chat_SetGroup(const wchar_t *pwszGroupName) +{ + if (mir_wstrlen(pwszGroupName)) + db_set_ws(0, CHAT_MODULE, "AddToGroup", pwszGroupName); + else + db_unset(0, CHAT_MODULE, "AddToGroup"); +} + +///////////////////////////////////////////////////////////////////////////////////////// + MIR_APP_DLL(wchar_t*) Chat_UnescapeTags(wchar_t *str_in) { wchar_t *s = str_in, *d = str_in; diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index f758a80cce..e3be5f3916 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -669,3 +669,5 @@ g_hevSettingChanged @696 NONAME ?getMe@GCSessionInfoBase@@QBEPAUUSERINFO@@XZ @702 NONAME ?MetaRemoveSubHistory@MDatabaseCommon@@UAGHPAUDBCachedContact@@@Z @703 NONAME ?MetaRemoveSubHistory@MDatabaseReadonly@@UAGHPAUDBCachedContact@@@Z @704 NONAME +Chat_GetGroup @705 +Chat_SetGroup @706 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 55a947a380..bb0746bc4e 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -669,3 +669,5 @@ g_hevSettingChanged @696 NONAME ?getMe@GCSessionInfoBase@@QEBAPEAUUSERINFO@@XZ @702 NONAME ?MetaRemoveSubHistory@MDatabaseCommon@@UEAAHPEAUDBCachedContact@@@Z @703 NONAME ?MetaRemoveSubHistory@MDatabaseReadonly@@UEAAHPEAUDBCachedContact@@@Z @704 NONAME +Chat_GetGroup @705 +Chat_SetGroup @706 -- cgit v1.2.3