summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2025-03-02 16:57:18 +0300
committerGeorge Hazan <george.hazan@gmail.com>2025-03-02 16:57:18 +0300
commitf397526e5fd1d53956caeb97a6178d3449c8c648 (patch)
treeee9e36dce8eb238b19252c4449309c474f3d0f83 /protocols/Telegram/src
parent0de237405acf0a5e26ab6cfddd875338c1e8acd0 (diff)
fixes #4892 (Telegram: добавить показ информации "О себе")
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r--protocols/Telegram/src/proto.cpp2
-rw-r--r--protocols/Telegram/src/proto.h8
-rw-r--r--protocols/Telegram/src/resource.h7
-rw-r--r--protocols/Telegram/src/server.cpp16
-rw-r--r--protocols/Telegram/src/stdafx.h1
-rw-r--r--protocols/Telegram/src/userinfo.cpp118
6 files changed, 144 insertions, 8 deletions
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp
index 627b00c228..3732e1a5e5 100644
--- a/protocols/Telegram/src/proto.cpp
+++ b/protocols/Telegram/src/proto.cpp
@@ -183,6 +183,8 @@ void CTelegramProto::OnModulesLoaded()
{
InitPopups();
+ HookProtoEvent(ME_USERINFO_INITIALISE, &CTelegramProto::OnUserInfoInit);
+
m_bSmileyAdd = ServiceExists(MS_SMILEYADD_REPLACESMILEYS);
if (m_bSmileyAdd)
SmileyAdd_LoadContactSmileys(SMADD_FOLDER, m_szModuleName, GetAvatarPath() + L"\\Stickers\\*.*");
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index 871ef9a790..29cc8b3654 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -154,6 +154,7 @@ class CTelegramProto : public PROTO<CTelegramProto>
friend class CReplyDlg;
friend class CForwardDlg;
friend class CReactionsDlg;
+ friend class CMyProfileDlg;
friend class COptionsDlg;
friend class COptSessionsDlg;
friend class CAddPhoneContactDlg;
@@ -285,7 +286,7 @@ class CTelegramProto : public PROTO<CTelegramProto>
void ProcessSuperGroup(TD::updateSupergroup *pObj);
void ProcessSuperGroupInfo(TD::updateSupergroupFullInfo *pObj);
void ProcessUser(TD::updateUser *pObj);
- void ProcessUserInfo(TD::updateUserFullInfo *pObj);
+ void ProcessUserInfo(TD::int53 userId, TD::userFullInfo *pObj);
void UnregisterSession();
@@ -370,6 +371,9 @@ class CTelegramProto : public PROTO<CTelegramProto>
void RemoveFromClist(TG_USER *pUser);
void MarkRead(MCONTACT hContact, const CMStringA &szMaxId, bool bSent);
+ void RetrieveProfile(CMyProfileDlg *pDlg);
+ void OnReceivedProfile(td::ClientManager::Response &response, void *pUserData);
+
// Menus
HGENMENU hmiForward, hmiReaction;
@@ -430,6 +434,8 @@ public:
int __cdecl GcMuteHook(WPARAM, LPARAM);
int __cdecl GcEventHook(WPARAM, LPARAM);
+ int __cdecl OnUserInfoInit(WPARAM, LPARAM);
+
// Services //////////////////////////////////////////////////////////////////////////
INT_PTR __cdecl SvcAddByPhone(WPARAM, LPARAM);
diff --git a/protocols/Telegram/src/resource.h b/protocols/Telegram/src/resource.h
index 9e6bebafce..b916cc8bec 100644
--- a/protocols/Telegram/src/resource.h
+++ b/protocols/Telegram/src/resource.h
@@ -13,6 +13,7 @@
#define IDI_REACTION 108
#define IDD_REACTIONS 109
#define IDI_BOT 110
+#define IDD_MYPROFILE 111
#define IDD_OPTIONS_SESSIONS 112
#define IDC_PHONE 1001
#define IDC_DEFGROUP 1002
@@ -33,6 +34,8 @@
#define IDC_REACTIONS 1018
#define IDC_USE_PREVIEW 1018
#define IDC_RESIDENT_CHANNELS 1019
+#define IDC_BIO 1020
+#define IDC_BIRTHDAY 1021
#define IDC_SESSIONS 1023
#define IDC_SOFTWARE 1025
#define IDC_LOGOUT 1025
@@ -41,9 +44,9 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 116
+#define _APS_NEXT_RESOURCE_VALUE 119
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1027
+#define _APS_NEXT_CONTROL_VALUE 1029
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp
index 156af0c4ea..ac7d72562d 100644
--- a/protocols/Telegram/src/server.cpp
+++ b/protocols/Telegram/src/server.cpp
@@ -347,7 +347,8 @@ void CTelegramProto::ProcessResponse(td::ClientManager::Response response)
break;
case TD::updateUserFullInfo::ID:
- ProcessUserInfo((TD::updateUserFullInfo*)response.object.get());
+ if (auto *pObj = (TD::updateUserFullInfo *)response.object.get())
+ ProcessUserInfo(pObj->user_id_, pObj->user_full_info_.get());
break;
}
}
@@ -1324,14 +1325,19 @@ void CTelegramProto::ProcessUser(TD::updateUser *pObj)
}
}
-void CTelegramProto::ProcessUserInfo(TD::updateUserFullInfo *pObj)
+void CTelegramProto::ProcessUserInfo(TD::int53 userId, TD::userFullInfo *pObj)
{
- if (auto *pUser = FindUser(pObj->user_id_)) {
- auto *pInfo = pObj->user_full_info_.get();
- if (auto *pBirthday = pInfo->birthdate_.get()) {
+ if (auto *pUser = FindUser(userId)) {
+ if (auto *pBirthday = pObj->birthdate_.get()) {
setWord(pUser->hContact, "BirthDay", pBirthday->day_);
setWord(pUser->hContact, "BirthMonth", pBirthday->month_);
setWord(pUser->hContact, "BirthYear", pBirthday->year_);
}
+
+ if (pObj->bio_) {
+ CMStringA szNotes(GetFormattedText(pObj->bio_));
+ if (!szNotes.IsEmpty())
+ setString(pUser->hContact, "Notes", szNotes);
+ }
}
}
diff --git a/protocols/Telegram/src/stdafx.h b/protocols/Telegram/src/stdafx.h
index ba59150fbb..2db1d8d4b4 100644
--- a/protocols/Telegram/src/stdafx.h
+++ b/protocols/Telegram/src/stdafx.h
@@ -34,6 +34,7 @@
#include <m_skin.h>
#include <m_smileyadd.h>
#include <m_timezones.h>
+#include <m_userinfo.h>
#include "../../libs/freeimage/src/FreeImage.h"
diff --git a/protocols/Telegram/src/userinfo.cpp b/protocols/Telegram/src/userinfo.cpp
new file mode 100644
index 0000000000..4c40c3b662
--- /dev/null
+++ b/protocols/Telegram/src/userinfo.cpp
@@ -0,0 +1,118 @@
+/*
+Copyright (C) 2012-25 Miranda NG team (https://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+class CMyProfileDlg : public CUserInfoPageDlg
+{
+ CTelegramProto *m_proto;
+ CCtrlEdit edtNotes;
+
+public:
+ CMyProfileDlg(CTelegramProto *ppro) :
+ CUserInfoPageDlg(g_plugin, IDD_MYPROFILE),
+ m_proto(ppro),
+ edtNotes(this, IDC_BIO)
+ {}
+
+ bool OnRefresh() override
+ {
+ m_proto->RetrieveProfile(this);
+ return true;
+ }
+
+ bool OnInitDialog() override
+ {
+ m_proto->WindowSubscribe(m_hwnd);
+
+ OnRefresh();
+ Display();
+ return true;
+ }
+
+ int Resizer(UTILRESIZECONTROL *urc) override
+ {
+ switch (urc->wId) {
+ case IDC_BIO:
+ return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT;
+ }
+ return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
+ }
+
+ void OnDestroy() override
+ {
+ m_proto->WindowUnsubscribe(m_hwnd);
+ }
+
+ void Display()
+ {
+ HWND _hwndDate = GetDlgItem(m_hwnd, IDC_BIRTHDAY);
+ SYSTEMTIME st = {};
+ st.wDay = m_proto->getWord(m_hContact, "BirthDay");
+ st.wMonth = m_proto->getWord(m_hContact, "BirthMonth");
+ st.wYear = m_proto->getWord(m_hContact, "BirthYear");
+
+ if (st.wDay && st.wMonth && st.wYear) {
+ DateTime_SetSystemtime(_hwndDate, GDT_VALID, &st);
+ DateTime_SetFormat(_hwndDate, NULL);
+ }
+ else {
+ DateTime_SetSystemtime(_hwndDate, GDT_NONE, NULL);
+ DateTime_SetFormat(_hwndDate, TranslateT("Unspecified"));
+ }
+
+ edtNotes.SetText(m_proto->getMStringW(m_hContact, "Notes"));
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void CTelegramProto::RetrieveProfile(CMyProfileDlg *pDlg)
+{
+ SendQuery(new TD::getUserFullInfo(m_iOwnId), &CTelegramProto::OnReceivedProfile, pDlg);
+}
+
+void CTelegramProto::OnReceivedProfile(td::ClientManager::Response &response, void *pUserData)
+{
+ if (!response.object)
+ return;
+
+ if (response.object->get_id() != TD::userFullInfo::ID) {
+ debugLogA("Gotten class ID %d instead of %d, exiting", response.object->get_id(), TD::updateUserFullInfo::ID);
+ return;
+ }
+
+ ProcessUserInfo(m_iOwnId, (TD::userFullInfo *)response.object.get());
+ ((CMyProfileDlg *)pUserData)->Display();
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// module entry point
+
+int CTelegramProto::OnUserInfoInit(WPARAM wParam, LPARAM hContact)
+{
+ if (hContact != 0)
+ return 0;
+
+ USERINFOPAGE uip = {};
+ uip.flags = ODPF_UNICODE | ODPF_ICON;
+ uip.szProto = m_szModuleName;
+ uip.szTitle.w = m_tszUserName;
+ uip.pDialog = new CMyProfileDlg(this);
+ uip.dwInitParam = (INT_PTR)Skin_GetProtoIcon(m_szModuleName, ID_STATUS_ONLINE);
+ return g_plugin.addUserInfo(wParam, &uip);
+}