summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r--protocols/Telegram/src/main.cpp1
-rw-r--r--protocols/Telegram/src/menus.cpp81
-rw-r--r--protocols/Telegram/src/proto.h5
-rw-r--r--protocols/Telegram/src/resource.h9
-rw-r--r--protocols/Telegram/src/utils.cpp4
5 files changed, 84 insertions, 16 deletions
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 <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;
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<CTelegramProto>
{
+ friend class CReplyDlg;
friend class CForwardDlg;
friend class CReactionsDlg;
friend class CAddPhoneContactDlg;
@@ -314,12 +315,12 @@ class CTelegramProto : public PROTO<CTelegramProto>
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<TD::formattedText> 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;