From f77cc69a03ea7880a780f215c8a77dd285ee6555 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 24 Nov 2023 19:27:51 +0300 Subject: fixes #3943 (NewStory: add proper support for citation) --- protocols/Telegram/res/reply.ico | Bin 0 -> 4286 bytes protocols/Telegram/res/resource.rc | 22 ++++++---- protocols/Telegram/src/main.cpp | 1 + protocols/Telegram/src/menus.cpp | 81 ++++++++++++++++++++++++++++++++----- protocols/Telegram/src/proto.h | 5 ++- protocols/Telegram/src/resource.h | 9 ++++- protocols/Telegram/src/utils.cpp | 4 +- 7 files changed, 99 insertions(+), 23 deletions(-) create mode 100644 protocols/Telegram/res/reply.ico (limited to 'protocols') diff --git a/protocols/Telegram/res/reply.ico b/protocols/Telegram/res/reply.ico new file mode 100644 index 0000000000..16cbee7a06 Binary files /dev/null and b/protocols/Telegram/res/reply.ico differ diff --git a/protocols/Telegram/res/resource.rc b/protocols/Telegram/res/resource.rc index 233ae0c132..6bab6b5e1b 100644 --- a/protocols/Telegram/res/resource.rc +++ b/protocols/Telegram/res/resource.rc @@ -150,6 +150,18 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,158,22,50,14 END +IDD_REPLY DIALOGEX 0, 0, 414, 233 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Reply to a message" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + CONTROL "",IDC_REPLYTO,"NewstoryList",ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP,7,18,400,85 + LTEXT "In reply to:",IDC_STATIC,7,4,400,9 + CONTROL "",IDC_TEXT,"RichEdit50W",ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP,7,105,400,103 + CONTROL "",IDC_ATTACH,"MButtonClass",WS_TABSTOP,7,212,17,14 + DEFPUSHBUTTON "OK",IDOK,301,212,50,14 + PUSHBUTTON "Cancel",IDCANCEL,357,212,50,14 +END ///////////////////////////////////////////////////////////////////////////// // @@ -168,6 +180,9 @@ IDI_REACTION ICON "reaction.ico" IDI_BOT ICON "bot.ico" +IDI_REPLY ICON "reply.ico" + + ///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO @@ -193,11 +208,6 @@ BEGIN BEGIN BOTTOMMARGIN, 262 END - - "IDC_REACTION", DIALOG - BEGIN - BOTTOMMARGIN, 36 - END END #endif // APSTUDIO_INVOKED @@ -235,8 +245,6 @@ END #endif // English (Neutral) resources ///////////////////////////////////////////////////////////////////////////// - - #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // diff --git a/protocols/Telegram/src/main.cpp b/protocols/Telegram/src/main.cpp index 411a286ffc..348a58e0cd 100644 --- a/protocols/Telegram/src/main.cpp +++ b/protocols/Telegram/src/main.cpp @@ -43,6 +43,7 @@ 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 73327f1665..e2be884305 100644 --- a/protocols/Telegram/src/menus.cpp +++ b/protocols/Telegram/src/menus.cpp @@ -21,35 +21,43 @@ along with this program. If not, see . void CTelegramProto::InitMenus() { - if (!ServiceExists(MS_NEWSTORY_GETSELECTION)) + if (!HookProtoEvent(ME_NS_PREBUILDMENU, &CTelegramProto::OnPrebuildNSMenu)) return; CreateProtoService(MenuExecService, &CTelegramProto::SvcExecMenu); - HookProtoEvent(ME_NS_PREBUILDMENU, &CTelegramProto::OnPrebuildMenu); CMStringA szServiceName(FORMAT, "%s%s", m_szModuleName, MenuExecService); CMenuItem mi(&g_plugin); mi.pszService = szServiceName; - mi.position = 1000000; + mi.position = 10000000; mi.hIcolibItem = g_plugin.getIconHandle(IDI_FORWARD); mi.name.a = LPGEN("Forward"); hmiForward = Menu_AddNewStoryMenuItem(&mi, 1); - mi.position = 1000000; + mi.position++; 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::OnPrebuildMenu(WPARAM hContact, LPARAM) +int CTelegramProto::OnPrebuildNSMenu(WPARAM hContact, LPARAM 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, true); + Menu_ShowItem(hmiReply, mir_strlen(pDbei->szId) > 0); auto *pUser = FindUser(GetId(hContact)); Menu_ShowItem(hmiReaction, pUser && pUser->pReactions); @@ -129,6 +137,53 @@ public: } }; +///////////////////////////////////////////////////////////////////////////////////////// +// Dialog for reply to a message + +class CReplyDlg : public CTelegramDlgBase +{ + MEVENT m_hEvent; + TG_USER *m_pUser; + + CCtrlEdit edtText; + CCtrlButton btnOk; + CCtrlMButton btnFile; + +public: + CReplyDlg(CTelegramProto *ppro, MEVENT hEvent) : + CTelegramDlgBase(ppro, IDD_REPLY), + m_hEvent(hEvent), + btnOk(this, IDOK), + edtText(this, IDC_TEXT), + btnFile(this, IDC_ATTACH, IcoLib_GetIcon("attach"), LPGEN("Attach file")) + { + m_pUser = ppro->FindUser(ppro->GetId(db_event_getContact(hEvent))); + } + + bool OnInitDialog() override + { + ::SendDlgItemMessage(m_hwnd, IDC_REPLYTO, NSM_ADDEVENT, m_proto->GetRealContact(m_pUser), m_hEvent); + return true; + } + + bool OnApply() override + { + DB::EventInfo dbei(m_hEvent, false); + + ptrW wszText(edtText.GetText()); + + auto pContent = TD::make_object(); + pContent->text_ = formatBbcodes(T2Utf(wszText)); + + auto *pMessage = new TD::sendMessage(); + pMessage->chat_id_ = m_pUser->chatId; + pMessage->input_message_content_ = std::move(pContent); + pMessage->reply_to_message_id_ = _atoi64(dbei.szId); + m_proto->SendQuery(pMessage, &CTelegramProto::OnSendMessage); + return true; + } +}; + ///////////////////////////////////////////////////////////////////////////////////////// // Dialog for sending reaction @@ -172,6 +227,8 @@ public: INT_PTR CTelegramProto::SvcExecMenu(WPARAM iCommand, LPARAM pHandle) { + MEVENT hCurrentEvent; + switch (iCommand) { case 1: // forward message { std::vector ids = NS_GetSelection(HANDLE(pHandle)); @@ -181,11 +238,15 @@ INT_PTR CTelegramProto::SvcExecMenu(WPARAM iCommand, LPARAM pHandle) break; case 2: // reactions - { - MEVENT hCurrentEvent = NS_GetCurrent((HANDLE)pHandle); - if (hCurrentEvent != -1) - CReactionsDlg(this, hCurrentEvent).DoModal(); - } + hCurrentEvent = NS_GetCurrent((HANDLE)pHandle); + if (hCurrentEvent != -1) + CReactionsDlg(this, hCurrentEvent).DoModal(); + break; + + case 3: // reply + hCurrentEvent = NS_GetCurrent((HANDLE)pHandle); + if (hCurrentEvent != -1) + CReplyDlg(this, hCurrentEvent).DoModal(); break; } return 0; diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 3620ff78f0..dd1723178b 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -147,6 +147,7 @@ struct TG_OWN_MESSAGE class CTelegramProto : public PROTO { + friend class CReplyDlg; friend class CForwardDlg; friend class CReactionsDlg; friend class CAddPhoneContactDlg; @@ -314,12 +315,12 @@ class CTelegramProto : public PROTO MCONTACT GetRealContact(const TG_USER *pUser); // Menus - HGENMENU hmiForward, hmiReaction; + HGENMENU hmiForward, hmiReaction, hmiReply; void InitMenus(); INT_PTR __cdecl SvcExecMenu(WPARAM, LPARAM); - int __cdecl OnPrebuildMenu(WPARAM, LPARAM); + int __cdecl OnPrebuildNSMenu(WPARAM, LPARAM); // Popups HANDLE m_hPopupClass; diff --git a/protocols/Telegram/src/resource.h b/protocols/Telegram/src/resource.h index a1f348c2a0..0ffa5e1a47 100644 --- a/protocols/Telegram/src/resource.h +++ b/protocols/Telegram/src/resource.h @@ -13,6 +13,8 @@ #define IDI_REACTION 108 #define IDD_REACTIONS 109 #define IDI_BOT 110 +#define IDI_REPLY 111 +#define IDD_REPLY 112 #define IDC_PHONE 1001 #define IDC_DEFGROUP 1002 #define IDC_HIDECHATS 1003 @@ -33,14 +35,17 @@ #define IDC_CLIST 1016 #define IDC_COMPRESS_FILES 1017 #define IDC_REACTIONS 1018 +#define IDC_REPLYTO 1019 +#define IDC_TEXT 1020 +#define IDC_ATTACH 1021 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 111 +#define _APS_NEXT_RESOURCE_VALUE 115 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1019 +#define _APS_NEXT_CONTROL_VALUE 1023 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 7212a04d1d..e6f04f22e2 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -37,11 +37,11 @@ TD::object_ptr formatBbcodes(const char *pszText) std::wstring str = Utf2T(pszText).get(); for (auto &it : bbCodes) { while (true) { - size_t i1 = str.find(it.begin); + int i1 = str.find(it.begin); if (i1 == str.npos) break; - size_t i2 = str.find(it.end, i1); + int i2 = str.find(it.end, i1); if (i2 == str.npos) break; -- cgit v1.2.3