From 97aaa26b16121281291acf58c26e1032a24d85bf Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 3 Feb 2023 18:48:11 +0300 Subject: fixes #3324 (Telegram: phone number) --- protocols/Telegram/src/auth.cpp | 2 +- protocols/Telegram/src/options.cpp | 23 ++++++++++++++++++++++- protocols/Telegram/src/proto.cpp | 1 + protocols/Telegram/src/proto.h | 2 ++ protocols/Telegram/src/resource.h | 3 ++- protocols/Telegram/src/server.cpp | 3 ++- 6 files changed, 30 insertions(+), 4 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/auth.cpp b/protocols/Telegram/src/auth.cpp index d1cfb85211..b6af34a657 100644 --- a/protocols/Telegram/src/auth.cpp +++ b/protocols/Telegram/src/auth.cpp @@ -117,7 +117,7 @@ void CTelegramProto::ProcessAuth(TD::updateAuthorizationState *pObj) break; case TD::authorizationStateWaitPhoneNumber::ID: - SendQuery(new TD::setAuthenticationPhoneNumber(_T2A(m_szOwnPhone).get(), nullptr), &CTelegramProto::OnUpdateAuth); + SendQuery(new TD::setAuthenticationPhoneNumber(m_szFullPhone.c_str(), nullptr), &CTelegramProto::OnUpdateAuth); break; case TD::authorizationStateWaitCode::ID: diff --git a/protocols/Telegram/src/options.cpp b/protocols/Telegram/src/options.cpp index 9986ba7c45..e66da19f0c 100644 --- a/protocols/Telegram/src/options.cpp +++ b/protocols/Telegram/src/options.cpp @@ -22,12 +22,14 @@ along with this program. If not, see . class COptionsDlg : public CProtoDlgBase { CCtrlCheck chkHideChats, chkUsePopups; + CCtrlCombo cmbCountry; CCtrlEdit edtGroup, edtPhone, edtDeviceName; ptrW m_wszOldGroup; public: COptionsDlg(CTelegramProto *ppro, int iDlgID, bool bFullDlg) : CProtoDlgBase(ppro, iDlgID), + cmbCountry(this, IDC_COUNTRY), chkUsePopups(this, IDC_POPUPS), chkHideChats(this, IDC_HIDECHATS), edtPhone(this, IDC_PHONE), @@ -44,13 +46,32 @@ public: CreateLink(chkUsePopups, ppro->m_bUsePopups); } + bool OnInitDialog() override + { + int iCount; + CountryListEntry *pList; + CallService(MS_UTILS_GETCOUNTRYLIST, (WPARAM)&iCount, (LPARAM)&pList); + + for (int i = 0; i < iCount; i++) { + int countryCode = pList[i].id; + int idx = cmbCountry.AddString(TranslateW(_A2T(pList[i].szName).get()), countryCode); + if (countryCode == m_proto->m_iCountry) + cmbCountry.SetCurSel(idx); + } + + return true; + } + bool OnApply() override { - if (!mir_wstrlen(m_proto->m_szOwnPhone)) { + int iCountry = cmbCountry.GetCurData(); + if (iCountry == 9999 || mir_wstrlen(m_proto->m_szOwnPhone)) { SetFocus(edtPhone.GetHwnd()); return false; } + m_proto->m_iCountry = iCountry; + if (mir_wstrcmp(m_proto->m_wszDefaultGroup, m_wszOldGroup)) Clist_GroupCreate(0, m_proto->m_wszDefaultGroup); return true; diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index 2044462846..06ac895087 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -37,6 +37,7 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) : m_arBasicGroups(10, CompareBasicGroups), m_arSuperGroups(10, CompareSuperGroups), m_szOwnPhone(this, "Phone"), + m_iCountry(this, "Country", 9999), m_iStatus1(this, "Status1", ID_STATUS_AWAY), m_iStatus2(this, "Status2", ID_STATUS_NA), m_iTimeDiff1(this, "TimeDiff1", 600), diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index d77c5d04fc..476deea871 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -153,6 +153,7 @@ class CTelegramProto : public PROTO bool m_bAuthorized, m_bTerminated, m_bUnregister = false, m_bSmileyAdd = false; int32_t m_iClientId, m_iMsgId; int64_t m_iQueryId; + CMStringA m_szFullPhone; OBJLIST m_arRequests; OBJLIST m_arFiles; @@ -255,6 +256,7 @@ public: // Options /////////////////////////////////////////////////////////////////////////// + CMOption m_iCountry; // set this status to m_iStatus1 after this interval of secs CMOption m_szOwnPhone; // our own phone number CMOption m_wszDefaultGroup; // clist group to store contacts CMOption m_wszDeviceName; // how do you see this session in Device List diff --git a/protocols/Telegram/src/resource.h b/protocols/Telegram/src/resource.h index 5bd28839a5..4c8deb0dcd 100644 --- a/protocols/Telegram/src/resource.h +++ b/protocols/Telegram/src/resource.h @@ -19,6 +19,7 @@ #define IDC_SPIN2 1009 #define IDC_STATUS1 1010 #define IDC_STATUS2 1011 +#define IDC_COUNTRY 1012 // Next default values for new objects // @@ -26,7 +27,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 106 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1006 +#define _APS_NEXT_CONTROL_VALUE 1013 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index e039628284..aab8a3a49e 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -25,6 +25,7 @@ void CTelegramProto::OnEndSession(td::ClientManager::Response&) void __cdecl CTelegramProto::ServerThread(void *) { m_bTerminated = m_bAuthorized = false; + m_szFullPhone.Format("%d%S", (int)m_iCountry, (wchar_t *)m_szOwnPhone); m_pClientMmanager = std::make_unique(); m_iClientId = m_pClientMmanager->create_client_id(); @@ -457,7 +458,7 @@ void CTelegramProto::ProcessUser(TD::updateUser *pObj) { auto *pUser = pObj->user_.get(); - if (pUser->phone_number_ == _T2A(m_szOwnPhone).get()) { + if (pUser->phone_number_ == m_szFullPhone.c_str()) { m_iOwnId = pUser->id_; if (!FindUser(pUser->id_)) -- cgit v1.2.3