diff options
Diffstat (limited to 'protocols/Telegram/src/menus.cpp')
-rw-r--r-- | protocols/Telegram/src/menus.cpp | 81 |
1 files changed, 71 insertions, 10 deletions
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 <http://www.gnu.org/licenses/>. 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); @@ -130,6 +138,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<TD::inputMessageText>(); + 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 class CReactionsDlg : public CTelegramDlgBase @@ -172,6 +227,8 @@ public: INT_PTR CTelegramProto::SvcExecMenu(WPARAM iCommand, LPARAM pHandle) { + MEVENT hCurrentEvent; + switch (iCommand) { case 1: // forward message { std::vector<MEVENT> 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; |