summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src/options.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/src/options.cpp')
-rw-r--r--protocols/Telegram/src/options.cpp142
1 files changed, 142 insertions, 0 deletions
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;
}