diff options
-rw-r--r-- | protocols/Telegram/res/resource.rc | 29 | ||||
-rw-r--r-- | protocols/Telegram/src/options.cpp | 142 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 3 | ||||
-rw-r--r-- | protocols/Telegram/src/resource.h | 8 | ||||
-rw-r--r-- | protocols/Telegram/src/stdafx.h | 1 |
5 files changed, 179 insertions, 4 deletions
diff --git a/protocols/Telegram/res/resource.rc b/protocols/Telegram/res/resource.rc index 6bab6b5e1b..3b90bb61f7 100644 --- a/protocols/Telegram/res/resource.rc +++ b/protocols/Telegram/res/resource.rc @@ -112,6 +112,18 @@ BEGIN COMBOBOX IDC_STATUS2,221,61,81,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
END
+IDD_OPTIONS_SESSIONS DIALOGEX 0, 0, 310, 226
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+EXSTYLE WS_EX_CONTROLPARENT
+FONT 8, "MS Shell Dlg", 0, 0, 0x1
+BEGIN
+ CONTROL "",IDC_SESSIONS,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,1,0,309,182
+ LTEXT "IP address",IDC_STATIC,0,188,75,8
+ LTEXT "Software",IDC_STATIC,0,204,75,8
+ EDITTEXT IDC_IPADDRESS,87,187,75,12,ES_AUTOHSCROLL | WS_DISABLED
+ EDITTEXT IDC_SOFTWARE,87,202,217,12,ES_AUTOHSCROLL | WS_DISABLED
+END
+
IDD_ADD_PHONE DIALOGEX 0, 0, 343, 105
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Add phone contact"
@@ -155,14 +167,15 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTI 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
+ CONTROL "",IDC_REPLYTO,"NewstoryList",WS_BORDER | WS_TABSTOP | 0x80,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_TEXT,"RichEdit50W",WS_BORDER | WS_TABSTOP | 0x80,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
+
/////////////////////////////////////////////////////////////////////////////
//
// Icon
@@ -199,6 +212,11 @@ BEGIN BEGIN
END
+ IDD_OPTIONS_SESSIONS, DIALOG
+ BEGIN
+ BOTTOMMARGIN, 86
+ END
+
IDD_ADD_PHONE, DIALOG
BEGIN
BOTTOMMARGIN, 84
@@ -242,9 +260,16 @@ BEGIN 0
END
+IDD_OPTIONS_SESSIONS AFX_DIALOG_LAYOUT
+BEGIN
+ 0
+END
+
#endif // English (Neutral) resources
/////////////////////////////////////////////////////////////////////////////
+
+
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
diff --git a/protocols/Telegram/src/options.cpp b/protocols/Telegram/src/options.cpp index e1c8d89c68..4960ad124d 100644 --- a/protocols/Telegram/src/options.cpp +++ b/protocols/Telegram/src/options.cpp @@ -180,6 +180,143 @@ public: };
/////////////////////////////////////////////////////////////////////////////////////////
+// Session list
+
+class COptSessionsDlg : public CTelegramDlgBase
+{
+ CCtrlBase m_ipAddress, m_software;
+ CCtrlListView m_list;
+
+public:
+ COptSessionsDlg(CTelegramProto *ppro) :
+ CTelegramDlgBase(ppro, IDD_OPTIONS_SESSIONS),
+ m_list(this, IDC_SESSIONS),
+ m_software(this, IDC_SOFTWARE),
+ m_ipAddress(this, IDC_IPADDRESS)
+ {
+ m_list.OnBuildMenu = Callback(this, &COptSessionsDlg::onContextMenu);
+ m_list.OnDeleteItem = Callback(this, &COptSessionsDlg::onDeleteItem);
+ m_list.OnItemChanged = Callback(this, &COptSessionsDlg::onItemChanged);
+ }
+
+ bool OnInitDialog() override
+ {
+ LVCOLUMN lvc = {};
+ lvc.mask = LVCF_TEXT | LVCF_WIDTH;
+
+ lvc.pszText = TranslateT("Name");
+ lvc.cx = 150;
+ m_list.InsertColumn(0, &lvc);
+
+ lvc.pszText = TranslateT("Platform");
+ lvc.cx = 110;
+ m_list.InsertColumn(1, &lvc);
+
+ lvc.pszText = TranslateT("Country");
+ lvc.cx = 120;
+ m_list.InsertColumn(2, &lvc);
+
+ lvc.pszText = TranslateT("Last active");
+ lvc.cx = 110;
+ m_list.InsertColumn(3, &lvc);
+
+ BuildList();
+ return true;
+ }
+
+ void OnDestroy() override
+ {
+ int iCount = m_list.GetItemCount();
+ for (int i = 0; i < iCount; i++) {
+ auto *pSession = (TD::session *)m_list.GetItemData(i);
+ delete pSession;
+ }
+ }
+
+ void onContextMenu(CContextMenuPos *pos)
+ {
+ HMENU hMenu = CreatePopupMenu();
+ AppendMenuW(hMenu, MF_STRING, 100, TranslateT("Kill session"));
+
+ if (100 == TrackPopupMenu(hMenu, TPM_RETURNCMD, pos->pt.x, pos->pt.y, 0, m_hwnd, 0)) {
+ auto *pSession = (TD::session *)m_list.GetItemData(pos->iCurr);
+ m_proto->SendQuery(new TD::terminateSession(pSession->id_), &CTelegramProto::OnKillSession, this);
+ }
+ }
+
+ void onDeleteItem(CCtrlListView::TEventInfo *ev)
+ {
+ auto *pSession = (TD::session *)m_list.GetItemData(ev->nmlv->iItem);
+ delete pSession;
+ }
+
+ void onItemChanged(CCtrlListView::TEventInfo *ev)
+ {
+ auto *pSession = (TD::session*)m_list.GetItemData(ev->nmlv->iItem);
+ m_ipAddress.SetTextA(pSession->ip_.c_str());
+ m_software.SetTextA((pSession->application_name_ + " " + pSession->application_version_).c_str());
+ }
+
+ void BuildList()
+ {
+ m_list.DeleteAllItems();
+
+ m_proto->SendQuery(new TD::getActiveSessions(), &CTelegramProto::OnGetSessions, &m_list);
+ }
+};
+
+void CTelegramProto::OnGetSessions(td::ClientManager::Response &response, void *pUserInfo)
+{
+ if (!response.object)
+ return;
+
+ if (response.object->get_id() != TD::sessions::ID) {
+ debugLogA("Gotten class ID %d instead of %d, exiting", response.object->get_id(), TD::chats::ID);
+ return;
+ }
+
+ auto *pSessions = (TD::sessions *)response.object.get();
+ auto *pList = (CCtrlListView *)pUserInfo;
+
+ for (auto &it : pSessions->sessions_) {
+ auto *pSession = it.release();
+ int iItem = pList->AddItem(Utf2T(pSession->device_model_.c_str()), 0, (LPARAM)pSession);
+
+ const wchar_t *pwszType;
+ switch (pSession->type_->get_id()) {
+ case TD::sessionTypeAndroid::ID: pwszType = L"Android"; break;
+ case TD::sessionTypeApple::ID: pwszType = L"Apple"; break;
+ case TD::sessionTypeChrome::ID: pwszType = L"Chrome"; break;
+ case TD::sessionTypeEdge::ID: pwszType = L"MS Edge"; break;
+ case TD::sessionTypeFirefox::ID: pwszType = L"Firefox"; break;
+ case TD::sessionTypeIpad::ID: pwszType = L"Ipad"; break;
+ case TD::sessionTypeIphone::ID: pwszType = L"Iphone"; break;
+ case TD::sessionTypeLinux::ID: pwszType = L"Linux"; break;
+ case TD::sessionTypeMac::ID: pwszType = L"Mac"; break;
+ case TD::sessionTypeOpera::ID: pwszType = L"Opera"; break;
+ case TD::sessionTypeSafari::ID: pwszType = L"Safari"; break;
+ case TD::sessionTypeUbuntu::ID: pwszType = L"Ubuntu"; break;
+ case TD::sessionTypeVivaldi::ID: pwszType = L"Vivaldi"; break;
+ case TD::sessionTypeWindows::ID: pwszType = L"Windows"; break;
+ default:
+ pwszType = TranslateT("Unknown");
+ }
+ pList->SetItemText(iItem, 1, pwszType);
+ pList->SetItemText(iItem, 2, Utf2T(pSession->country_.c_str()));
+
+ wchar_t wszLastLogin[100];
+ TimeZone_PrintTimeStamp(0, pSession->last_active_date_, L"d t", wszLastLogin, _countof(wszLastLogin), 0);
+ pList->SetItemText(iItem, 3, wszLastLogin);
+ }
+}
+
+void CTelegramProto::OnKillSession(td::ClientManager::Response&, void *pUserInfo)
+{
+ auto *pDlg = (COptSessionsDlg *)pUserInfo;
+ pDlg->BuildList();
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
MWindow CTelegramProto::OnCreateAccMgrUI(MWindow hwndParent)
{
@@ -205,5 +342,10 @@ int CTelegramProto::OnOptionsInit(WPARAM wParam, LPARAM) odp.szTab.w = LPGENW("Advanced");
odp.pDialog = new CAdvOptionsDlg(this);
g_plugin.addOptions(wParam, &odp);
+
+ odp.position = 3;
+ odp.szTab.w = LPGENW("Sessions");
+ odp.pDialog = new COptSessionsDlg(this);
+ g_plugin.addOptions(wParam, &odp);
return 0;
}
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 32cec7fa60..db995e49be 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -150,6 +150,7 @@ class CTelegramProto : public PROTO<CTelegramProto> friend class CReplyDlg; friend class CForwardDlg; friend class CReactionsDlg; + friend class COptSessionsDlg; friend class CAddPhoneContactDlg; class CProtoImpl @@ -224,6 +225,8 @@ class CTelegramProto : public PROTO<CTelegramProto> void OnGetFileInfo(td::ClientManager::Response &response, void *pUserInfo); void OnGetFileLink(td::ClientManager::Response &response); void OnGetHistory(td::ClientManager::Response &response, void *pUserInfo); + void OnGetSessions(td::ClientManager::Response &response, void *pUserInfo); + void OnKillSession(td::ClientManager::Response &response, void *pUserInfo); void OnSendFile(td::ClientManager::Response &response, void *pUserInfo); void OnSendMessage(td::ClientManager::Response &response); void OnUpdateAuth(td::ClientManager::Response &response); diff --git a/protocols/Telegram/src/resource.h b/protocols/Telegram/src/resource.h index 0ffa5e1a47..9838a6cb40 100644 --- a/protocols/Telegram/src/resource.h +++ b/protocols/Telegram/src/resource.h @@ -15,6 +15,7 @@ #define IDI_BOT 110
#define IDI_REPLY 111
#define IDD_REPLY 112
+#define IDD_OPTIONS_SESSIONS 113
#define IDC_PHONE 1001
#define IDC_DEFGROUP 1002
#define IDC_HIDECHATS 1003
@@ -38,14 +39,17 @@ #define IDC_REPLYTO 1019
#define IDC_TEXT 1020
#define IDC_ATTACH 1021
+#define IDC_SESSIONS 1023
+#define IDC_IPADDRESS 1024
+#define IDC_SOFTWARE 1025
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 115
+#define _APS_NEXT_RESOURCE_VALUE 116
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1023
+#define _APS_NEXT_CONTROL_VALUE 1025
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/protocols/Telegram/src/stdafx.h b/protocols/Telegram/src/stdafx.h index f6e7100f53..bb331c192a 100644 --- a/protocols/Telegram/src/stdafx.h +++ b/protocols/Telegram/src/stdafx.h @@ -30,6 +30,7 @@ #include <m_popup.h>
#include <m_skin.h>
#include <m_smileyadd.h>
+#include <m_timezones.h>
#include "../../libs/freeimage/src/FreeImage.h"
|