From c4a013eb138c4fe3e181751ca5a5b596e5961dd4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 7 Dec 2023 14:42:57 +0300 Subject: since Reply menu item does not depend on a protocol, it's moved to NewStory --- include/m_protosvc.h | 1 + plugins/ExternalAPI/m_NewStory.h | 2 + plugins/NewStory/res/reply.ico | Bin 0 -> 4286 bytes plugins/NewStory/res/resource.rc | 2 + plugins/NewStory/src/history_control.cpp | 7 ++++ plugins/NewStory/src/history_control.h | 1 + plugins/NewStory/src/history_menus.cpp | 19 ++++++++- plugins/NewStory/src/main.cpp | 1 + plugins/NewStory/src/resource.h | 3 +- protocols/Telegram/res/reply.ico | Bin 4286 -> 0 bytes protocols/Telegram/res/resource.rc | 3 -- protocols/Telegram/src/main.cpp | 1 - protocols/Telegram/src/menus.cpp | 21 ++-------- protocols/Telegram/src/proto.cpp | 2 +- protocols/Telegram/src/proto.h | 2 +- protocols/Telegram/src/resource.h | 1 - protocols/VKontakte/res/reply.ico | Bin 4286 -> 0 bytes protocols/VKontakte/res/resource.rc | 2 - protocols/VKontakte/src/misc.cpp | 1 - protocols/VKontakte/src/resource.h | 1 - protocols/VKontakte/src/vk_proto.cpp | 69 ++++++++++++------------------- protocols/VKontakte/src/vk_proto.h | 1 - 22 files changed, 64 insertions(+), 76 deletions(-) create mode 100644 plugins/NewStory/res/reply.ico delete mode 100644 protocols/Telegram/res/reply.ico delete mode 100644 protocols/VKontakte/res/reply.ico diff --git a/include/m_protosvc.h b/include/m_protosvc.h index b6fdc4f315..7c312217dc 100644 --- a/include/m_protosvc.h +++ b/include/m_protosvc.h @@ -141,6 +141,7 @@ static __inline unsigned long Proto_Status2Flag(int status) #define PF4_SINGLEFILEONLY 0x00001000 // protocol supports sending files one by one only #define PF4_READNOTIFY 0x00002000 // protocol supports receiving notify of message reading #define PF4_SERVERMSGID 0x00004000 // protocol uses server message ids +#define PF4_REPLY 0x00008000 // protocol supports replies to messages #define PFLAG_UNIQUEIDTEXT 100 // returns a static buffer of text describing the unique field by which this protocol identifies users (already translated), or NULL #define PFLAG_MAXCONTACTSPERPACKET 200 // returns the maximum number of contacts which can be sent in a single PSS_CONTACTS, lParam = (LPARAM)hContact. diff --git a/plugins/ExternalAPI/m_NewStory.h b/plugins/ExternalAPI/m_NewStory.h index ef2a247426..00bf7b6e44 100644 --- a/plugins/ExternalAPI/m_NewStory.h +++ b/plugins/ExternalAPI/m_NewStory.h @@ -2,6 +2,8 @@ #include +#define NS_PROTO_MENU_POS 1000001 + enum { NSM_FIRST = WM_USER + 100, diff --git a/plugins/NewStory/res/reply.ico b/plugins/NewStory/res/reply.ico new file mode 100644 index 0000000000..16cbee7a06 Binary files /dev/null and b/plugins/NewStory/res/reply.ico differ diff --git a/plugins/NewStory/res/resource.rc b/plugins/NewStory/res/resource.rc index 9cbb0b2603..7caf81eff9 100644 --- a/plugins/NewStory/res/resource.rc +++ b/plugins/NewStory/res/resource.rc @@ -72,6 +72,8 @@ IDI_OK ICON "ok.ico" IDI_USERS ICON "users.ico" +IDI_REPLY ICON "reply.ico" + ///////////////////////////////////////////////////////////////////////////// // diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index dfa7669dee..8de1503e1b 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -637,6 +637,13 @@ void NewstoryListData::Quote() } } +void NewstoryListData::Reply() +{ + if (pMsgDlg) + if (auto *pItem = GetItem(caret)) + pMsgDlg->SetQuoteEvent(pItem->hEvent); +} + void NewstoryListData::ScheduleDraw() { bWasAtBottom = AtBottom(); diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index 85bc06f2aa..a6c87e6622 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -70,6 +70,7 @@ struct NewstoryListData : public MZeroedObject int PaintItem(HDC hdc, int index, int top, int width); void Quote(); void RecalcScrollBar(); + void Reply(); void ScheduleDraw(); void ScrollBottom(); void ScrollDown(int deltaY); diff --git a/plugins/NewStory/src/history_menus.cpp b/plugins/NewStory/src/history_menus.cpp index 4e6f67d1c4..df6ae94f48 100644 --- a/plugins/NewStory/src/history_menus.cpp +++ b/plugins/NewStory/src/history_menus.cpp @@ -22,14 +22,14 @@ enum { MENU_COPY, MENU_COPYTEXT, MENU_COPYURL, MENU_OPENFOLDER, MENU_QUOTE, MENU_SAVEAS, MENU_DOWNLOAD, - MENU_EDIT, MENU_DELETE, + MENU_EDIT, MENU_DELETE, MENU_REPLY, MENU_SELECTALL, MENU_BOOKMARK, }; static int hMenuObject; static HANDLE hEventPreBuildMenu; static HGENMENU hmiHistory, hmiOpenFolder, hmiCopyUrl, hmiSaveAs, hmiDownload, hmiQuote; -static HGENMENU hmiCopy, hmiCopyText, hmiEdit, hmiBookmark, hmiDelete; +static HGENMENU hmiCopy, hmiCopyText, hmiEdit, hmiBookmark, hmiDelete, hmiReply; HMENU NSMenu_Build(NewstoryListData *data, ItemData *item) { @@ -42,6 +42,7 @@ HMENU NSMenu_Build(NewstoryListData *data, ItemData *item) Menu_ShowItem(hmiCopyText, bNotProtected); Menu_ShowItem(hmiQuote, bNotProtected && data->pMsgDlg != nullptr); + Menu_ShowItem(hmiReply, false); Menu_ShowItem(hmiSaveAs, false); Menu_ShowItem(hmiCopyUrl, false); Menu_ShowItem(hmiDownload, false); @@ -62,6 +63,11 @@ HMENU NSMenu_Build(NewstoryListData *data, ItemData *item) DB::EventInfo dbei(item->hEvent); NotifyEventHooks(hEventPreBuildMenu, item->hContact, (LPARAM)&dbei); + + if (data->pMsgDlg) { + INT_PTR caps = CallProtoService(Proto_GetBaseAccountName(item->hContact), PS_GETCAPS, PFLAGNUM_4, 0); + Menu_ShowItem(hmiReply, (caps & PF4_REPLY) != 0 && mir_strlen(dbei.szId) > 0 && !Contact::IsReadonly(item->hContact)); + } } else { bShowEventActions = bEditable = false; @@ -118,6 +124,10 @@ static INT_PTR NSMenuHelper(WPARAM wParam, LPARAM lParam) pData->Quote(); break; + case MENU_REPLY: + pData->Reply(); + break; + case MENU_EDIT: pData->BeginEditItem(); break; @@ -274,4 +284,9 @@ void InitMenus() mi.position = 300000; mi.name.a = LPGEN("Select all"); Menu_AddNewStoryMenuItem(&mi, MENU_SELECTALL); + + mi.position = NS_PROTO_MENU_POS - 1; + mi.hIcolibItem = g_plugin.getIconHandle(IDI_REPLY); + mi.name.a = LPGEN("Reply"); + hmiReply = Menu_AddNewStoryMenuItem(&mi, MENU_REPLY); } diff --git a/plugins/NewStory/src/main.cpp b/plugins/NewStory/src/main.cpp index dbcadd015e..bb09d38e40 100644 --- a/plugins/NewStory/src/main.cpp +++ b/plugins/NewStory/src/main.cpp @@ -64,6 +64,7 @@ static IconItem icons[] = { LPGEN("Filter"), "filter", IDI_FILTER }, { LPGEN("Export"), "export", IDI_EXPORT }, { LPGEN("Copy"), "copy", IDI_COPY }, + { LPGEN("Reply"), "reply", IDI_REPLY }, { LPGEN("Bookmark"), "bookmark", IDI_BOOKMARK }, { LPGEN("Send message"), "message", IDI_SENDMSG }, diff --git a/plugins/NewStory/src/resource.h b/plugins/NewStory/src/resource.h index 647d4d360c..6d9166f5ec 100644 --- a/plugins/NewStory/src/resource.h +++ b/plugins/NewStory/src/resource.h @@ -30,6 +30,7 @@ #define IDI_USERS 127 #define IDI_VARHELP 128 #define IDI_TIMETREE 129 +#define IDI_REPLY 130 #define IDC_USERINFO 1000 #define IDC_USERMENU 1001 #define IDC_MESSAGE 1002 @@ -111,7 +112,7 @@ // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 130 +#define _APS_NEXT_RESOURCE_VALUE 131 #define _APS_NEXT_COMMAND_VALUE 40019 #define _APS_NEXT_CONTROL_VALUE 1061 #define _APS_NEXT_SYMED_VALUE 101 diff --git a/protocols/Telegram/res/reply.ico b/protocols/Telegram/res/reply.ico deleted file mode 100644 index 16cbee7a06..0000000000 Binary files a/protocols/Telegram/res/reply.ico and /dev/null differ diff --git a/protocols/Telegram/res/resource.rc b/protocols/Telegram/res/resource.rc index 2dea61f66b..23ea531835 100644 --- a/protocols/Telegram/res/resource.rc +++ b/protocols/Telegram/res/resource.rc @@ -179,9 +179,6 @@ IDI_REACTION ICON "reaction.ico" IDI_BOT ICON "bot.ico" -IDI_REPLY ICON "reply.ico" - - ///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO diff --git a/protocols/Telegram/src/main.cpp b/protocols/Telegram/src/main.cpp index 348a58e0cd..411a286ffc 100644 --- a/protocols/Telegram/src/main.cpp +++ b/protocols/Telegram/src/main.cpp @@ -43,7 +43,6 @@ static IconItem iconList[] = { LPGEN("Telegram Premium user"), "premuim", IDI_PREMIUM }, { LPGEN("Forward"), "forward", IDI_FORWARD }, { LPGEN("Reaction"), "reaction", IDI_REACTION }, - { LPGEN("Reply"), "reply", IDI_REPLY }, { LPGEN("Bot"), "bot", IDI_BOT }, }; diff --git a/protocols/Telegram/src/menus.cpp b/protocols/Telegram/src/menus.cpp index ac87355f29..ded59ff5ed 100644 --- a/protocols/Telegram/src/menus.cpp +++ b/protocols/Telegram/src/menus.cpp @@ -30,7 +30,7 @@ void CTelegramProto::InitMenus() CMenuItem mi(&g_plugin); mi.pszService = szServiceName; - mi.position = 10000000; + mi.position = NS_PROTO_MENU_POS; mi.hIcolibItem = g_plugin.getIconHandle(IDI_FORWARD); mi.name.a = LPGEN("Forward"); hmiForward = Menu_AddNewStoryMenuItem(&mi, 1); @@ -39,25 +39,16 @@ void CTelegramProto::InitMenus() mi.hIcolibItem = g_plugin.getIconHandle(IDI_REACTION); mi.name.a = LPGEN("Reaction"); hmiReaction = Menu_AddNewStoryMenuItem(&mi, 2); - - mi.position++; - mi.hIcolibItem = g_plugin.getIconHandle(IDI_REPLY); - mi.name.a = LPGEN("Reply"); - hmiReply = Menu_AddNewStoryMenuItem(&mi, 3); } -int CTelegramProto::OnPrebuildNSMenu(WPARAM hContact, LPARAM lParam) +int CTelegramProto::OnPrebuildNSMenu(WPARAM hContact, LPARAM) { if (!Proto_IsProtoOnContact(hContact, m_szModuleName)) { Menu_ShowItem(hmiForward, false); Menu_ShowItem(hmiReaction, false); - Menu_ShowItem(hmiReply, false); } else { - auto *pDbei = (DB::EventInfo *)lParam; - - Menu_ShowItem(hmiForward, getByte("Protected")); - Menu_ShowItem(hmiReply, mir_strlen(pDbei->szId) > 0 && !Contact::IsReadonly(hContact)); + Menu_ShowItem(hmiForward, 0 == getByte(hContact, "Protected")); auto *pUser = FindUser(GetId(hContact)); Menu_ShowItem(hmiReaction, pUser && pUser->pReactions); @@ -195,12 +186,6 @@ INT_PTR CTelegramProto::SvcExecMenu(WPARAM iCommand, LPARAM pHandle) if (hCurrentEvent != -1) CReactionsDlg(this, hCurrentEvent).DoModal(); break; - - case 3: // reply - if (hCurrentEvent != -1) - if (auto *pDlg = NS_GetSrmm((HANDLE)pHandle)) - pDlg->SetQuoteEvent(hCurrentEvent); - break; } return 0; } diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index d23574b4e3..c7836d4e03 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -330,7 +330,7 @@ INT_PTR CTelegramProto::GetCaps(int type, MCONTACT) return PF2_ONLINE | PF2_SHORTAWAY | PF2_LONGAWAY; case PFLAGNUM_4: - return PF4_NOCUSTOMAUTH | PF4_FORCEAUTH | PF4_OFFLINEFILES | PF4_NOAUTHDENYREASON | PF4_SUPPORTTYPING | PF4_AVATARS | PF4_SERVERMSGID; + return PF4_NOCUSTOMAUTH | PF4_FORCEAUTH | PF4_OFFLINEFILES | PF4_NOAUTHDENYREASON | PF4_SUPPORTTYPING | PF4_AVATARS | PF4_SERVERMSGID | PF4_REPLY; case PFLAGNUM_5: return PF2_SHORTAWAY | PF2_LONGAWAY; diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 172024ccdf..8cf525801a 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -327,7 +327,7 @@ class CTelegramProto : public PROTO MCONTACT GetRealContact(const TG_USER *pUser); // Menus - HGENMENU hmiForward, hmiReaction, hmiReply; + HGENMENU hmiForward, hmiReaction; void InitMenus(); diff --git a/protocols/Telegram/src/resource.h b/protocols/Telegram/src/resource.h index ed68daa9f4..dd6b5a8f0f 100644 --- a/protocols/Telegram/src/resource.h +++ b/protocols/Telegram/src/resource.h @@ -13,7 +13,6 @@ #define IDI_REACTION 108 #define IDD_REACTIONS 109 #define IDI_BOT 110 -#define IDI_REPLY 111 #define IDD_OPTIONS_SESSIONS 112 #define IDC_PHONE 1001 #define IDC_DEFGROUP 1002 diff --git a/protocols/VKontakte/res/reply.ico b/protocols/VKontakte/res/reply.ico deleted file mode 100644 index 754a6324b3..0000000000 Binary files a/protocols/VKontakte/res/reply.ico and /dev/null differ diff --git a/protocols/VKontakte/res/resource.rc b/protocols/VKontakte/res/resource.rc index 46b2720f1a..6121a986bf 100644 --- a/protocols/VKontakte/res/resource.rc +++ b/protocols/VKontakte/res/resource.rc @@ -49,8 +49,6 @@ IDI_WALL ICON "wall.ico" IDI_MARKMESSAGESASREAD ICON "markread.ico" -IDI_REPLY ICON "reply.ico" - IDI_FORWARD ICON "forward.ico" diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 885f270381..eed2b096c8 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -62,7 +62,6 @@ static IconItem iconList[] = { LPGEN("Status icon"), "status", IDI_STATUS }, { LPGEN("Wall message icon"), "wall", IDI_WALL }, { LPGEN("Mark messages as read icon"), "markread", IDI_MARKMESSAGESASREAD }, - { LPGEN("Reply icon"), "reply", IDI_REPLY }, { LPGEN("Forward icon"), "forward", IDI_FORWARD } }; diff --git a/protocols/VKontakte/src/resource.h b/protocols/VKontakte/src/resource.h index 6dcb35d31d..a5f53ada9d 100644 --- a/protocols/VKontakte/src/resource.h +++ b/protocols/VKontakte/src/resource.h @@ -26,7 +26,6 @@ #define IDD_OPT_MENU 122 #define IDD_CONTACTDELETE 123 #define IDD_VKUSERFORM 124 -#define IDI_REPLY 125 #define IDI_FORWARD 126 #define IDC_LOGIN 1001 #define IDC_PASSWORD 1002 diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 0fb74bf1d9..9627f12be2 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -219,14 +219,9 @@ void CVkProto::InitMenus() mi.pszService = szServiceName; mi.hIcolibItem = g_plugin.getIconHandle(IDI_FORWARD); - mi.position = 10000000 + NSMI_FORWARD; + mi.position = NS_PROTO_MENU_POS + NSMI_FORWARD; mi.name.a = LPGEN("Forward"); m_hNewStoryMenuItems[NSMI_FORWARD] = Menu_AddNewStoryMenuItem(&mi, NSMI_FORWARD); - - mi.hIcolibItem = g_plugin.getIconHandle(IDI_REPLY); - mi.position = 10000000 + NSMI_REPLY; - mi.name.a = LPGEN("Reply"); - m_hNewStoryMenuItems[NSMI_REPLY] = Menu_AddNewStoryMenuItem(&mi, NSMI_REPLY); }; //Contact Menu Services @@ -423,13 +418,6 @@ int CVkProto::OnPreBuildContactMenu(WPARAM hContact, LPARAM) int CVkProto::OnPrebuildNSMenu(WPARAM hContact, LPARAM lParam) { Menu_ShowItem(m_hNewStoryMenuItems[NSMI_FORWARD], true); - - if (!Proto_IsProtoOnContact(hContact, m_szModuleName)) - Menu_ShowItem(m_hNewStoryMenuItems[NSMI_REPLY], false); - else { - auto* pDbei = (DB::EventInfo *)lParam; - Menu_ShowItem(m_hNewStoryMenuItems[NSMI_REPLY], mir_strlen(pDbei->szId) > 0 && !Contact::IsReadonly(hContact)); - } return 0; } @@ -441,36 +429,31 @@ INT_PTR CVkProto::SvcNSExecMenu(WPARAM iCommand, LPARAM pHandle) switch (iCommand) { case NSMI_FORWARD: - { - std::vector vIds = NS_GetSelection(HANDLE(pHandle)); - wchar_t wszMsg[2048] = L""; - if (auto* pDlg = NS_GetSrmm((HANDLE)pHandle)) - GetWindowText(pDlg->GetInput(), wszMsg, 2048); - - CVkUserListForm dlg( - this, - wszMsg, - TranslateT("Mark contacts for forwarding messages"), - TranslateT("Mark contacts you want to forward messages"), - TranslateT("Enter accompanying messages"), - 0 - ); - - if (!dlg.DoModal()) - break; - - if (!vIds.size()) - vIds.push_back(hCurrentEvent); - T2Utf pszMsg(dlg.wszMessage.c_str()); - for (auto &hContact : dlg.lContacts) - ForwardMsg((UINT_PTR)hContact, vIds, pszMsg); + { + std::vector vIds = NS_GetSelection(HANDLE(pHandle)); + wchar_t wszMsg[2048] = L""; + if (auto *pDlg = NS_GetSrmm((HANDLE)pHandle)) + GetWindowText(pDlg->GetInput(), wszMsg, 2048); + + CVkUserListForm dlg( + this, + wszMsg, + TranslateT("Mark contacts for forwarding messages"), + TranslateT("Mark contacts you want to forward messages"), + TranslateT("Enter accompanying messages"), + 0 + ); + + if (!dlg.DoModal()) + break; - } - break; - case NSMI_REPLY: - if (auto* pDlg = NS_GetSrmm((HANDLE)pHandle)) - pDlg->SetQuoteEvent(hCurrentEvent); - + if (!vIds.size()) + vIds.push_back(hCurrentEvent); + T2Utf pszMsg(dlg.wszMessage.c_str()); + for (auto &hContact : dlg.lContacts) + ForwardMsg((UINT_PTR)hContact, vIds, pszMsg); + + } break; } return 0; @@ -610,7 +593,7 @@ INT_PTR CVkProto::GetCaps(int type, MCONTACT) case PFLAGNUM_4: return PF4_AVATARS | PF4_SUPPORTTYPING | PF4_NOAUTHDENYREASON | PF4_IMSENDOFFLINE - | PF4_OFFLINEFILES | PF4_READNOTIFY | PF4_GROUPCHATFILES | PF4_SERVERMSGID; + | PF4_OFFLINEFILES | PF4_READNOTIFY | PF4_GROUPCHATFILES | PF4_SERVERMSGID | PF4_REPLY; case PFLAG_MAXLENOFMESSAGE: return 4096; diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index d71bf32576..ca061083c6 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -195,7 +195,6 @@ private: enum NewStoryMenuIndexes { NSMI_FORWARD, - NSMI_REPLY, NSMI_COUNT }; -- cgit v1.2.3