summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-05-08 13:35:05 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-05-08 13:35:05 +0300
commite1371137c42bcff3a1281970a0cf3a30e5619a63 (patch)
treedd0780aa5eb54a4b3acd78427b4bf938c5ba74db /protocols/Telegram/src
parent751e36b8878a2aec02c439c8c009cdb6db35d8d0 (diff)
Telegram:
- support for Saved messages contact; - own id is now gotten from my_id option; - CTelegramProto::m_szFullPhone removed; - minor code cleaning
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r--protocols/Telegram/src/auth.cpp6
-rw-r--r--protocols/Telegram/src/proto.cpp16
-rw-r--r--protocols/Telegram/src/proto.h4
-rw-r--r--protocols/Telegram/src/server.cpp66
4 files changed, 49 insertions, 43 deletions
diff --git a/protocols/Telegram/src/auth.cpp b/protocols/Telegram/src/auth.cpp
index 72f9be8698..ed82c99d04 100644
--- a/protocols/Telegram/src/auth.cpp
+++ b/protocols/Telegram/src/auth.cpp
@@ -123,7 +123,11 @@ void CTelegramProto::ProcessAuth(TD::updateAuthorizationState *pObj)
break;
case TD::authorizationStateWaitPhoneNumber::ID:
- SendQuery(new TD::setAuthenticationPhoneNumber(m_szFullPhone.c_str(), nullptr), &CTelegramProto::OnUpdateAuth);
+ {
+ CMStringA m_szFullPhone;
+ m_szFullPhone.Format("%d%S", (int)m_iCountry, (wchar_t *)m_szOwnPhone);
+ SendQuery(new TD::setAuthenticationPhoneNumber(m_szFullPhone.c_str(), nullptr), &CTelegramProto::OnUpdateAuth);
+ }
break;
case TD::authorizationStateWaitCode::ID:
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp
index a32e1571b3..2434df7979 100644
--- a/protocols/Telegram/src/proto.cpp
+++ b/protocols/Telegram/src/proto.cpp
@@ -52,7 +52,7 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) :
m_bUsePopups(this, "UsePopups", true),
m_bHideGroupchats(this, "HideChats", true)
{
- m_iOwnId = _atoi64(getMStringA(DBKEY_ID));
+ m_iOwnId = GetId(0);
CreateProtoService(PS_GETAVATARCAPS, &CTelegramProto::SvcGetAvatarCaps);
CreateProtoService(PS_GETAVATARINFO, &CTelegramProto::SvcGetAvatarInfo);
@@ -123,21 +123,13 @@ int CTelegramProto::OnEmptyHistory(WPARAM hContact, LPARAM)
void CTelegramProto::OnModulesLoaded()
{
- CMStringA szId(getMStringA(DBKEY_ID));
- if (!szId.IsEmpty()) {
- auto *pUser = new TG_USER(_atoi64(szId.c_str()), 0);
- m_arUsers.insert(pUser);
- m_arChats.insert(pUser);
- }
-
int iCompatLevel = getByte(DBKEY_COMPAT);
VARSW cachePath(L"%miranda_userdata%\\ChatCache");
for (auto &cc : AccContacts()) {
- bool isGroupChat = isChatRoom(cc);
- szId = getMStringA(cc, DBKEY_ID);
- if (!szId.IsEmpty()) {
- auto *pUser = new TG_USER(_atoi64(szId.c_str()), cc, isGroupChat);
+ if (int64_t id = GetId(cc)) {
+ bool isGroupChat = isChatRoom(cc);
+ auto *pUser = new TG_USER(id, cc, isGroupChat);
pUser->szAvatarHash = getMStringA(cc, DBKEY_AVATAR_HASH);
m_arUsers.insert(pUser);
if (!isGroupChat)
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index f609445e7a..b5fce735ca 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -175,8 +175,7 @@ class CTelegramProto : public PROTO<CTelegramProto>
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<TG_REQUEST_BASE> m_arRequests;
mir_cs m_csFiles;
@@ -221,6 +220,7 @@ class CTelegramProto : public PROTO<CTelegramProto>
void ProcessGroups(TD::updateChatFilters *pObj);
void ProcessMarkRead(TD::updateChatReadInbox *pObj);
void ProcessMessage(TD::updateNewMessage *pObj);
+ void ProcessOption(TD::updateOption *pObj);
void ProcessStatus(TD::updateUserStatus *pObj);
void ProcessSuperGroup(TD::updateSupergroup *pObj);
void ProcessUser(TD::updateUser *pObj);
diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp
index 469db0e971..1748a87080 100644
--- a/protocols/Telegram/src/server.cpp
+++ b/protocols/Telegram/src/server.cpp
@@ -25,8 +25,6 @@ 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_pClientManager = std::make_unique<td::ClientManager>();
m_iClientId = m_pClientManager->create_client_id();
@@ -182,6 +180,10 @@ void CTelegramProto::ProcessResponse(td::ClientManager::Response response)
ProcessMessage((TD::updateNewMessage *)response.object.get());
break;
+ case TD::updateOption::ID:
+ ProcessOption((TD::updateOption *)response.object.get());
+ break;
+
case TD::updateSupergroup::ID:
ProcessSuperGroup((TD::updateSupergroup *)response.object.get());
break;
@@ -330,13 +332,14 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj)
if (auto *pUser = FindUser(chatId)) {
pUser->chatId = pChat->id_;
+ MCONTACT hContact = (pUser->id == m_iOwnId) ? 0 : pUser->hContact;
if (!m_arChats.find(pUser))
m_arChats.insert(pUser);
if (!szTitle.empty()) {
- if (pUser->hContact != INVALID_CONTACT_ID)
- setUString(pUser->hContact, "Nick", szTitle.c_str());
+ if (hContact != INVALID_CONTACT_ID)
+ setUString(hContact, "Nick", szTitle.c_str());
else if (pUser->wszNick.IsEmpty())
pUser->wszFirstName = Utf2T(szTitle.c_str());
}
@@ -569,6 +572,21 @@ void CTelegramProto::ProcessMessage(TD::updateNewMessage *pObj)
ProtoChainRecvMsg(pUser->hContact, &pre);
}
+void CTelegramProto::ProcessOption(TD::updateOption *pObj)
+{
+ TD::int53 iValue = 0;
+ if (pObj->value_->get_id() == TD::optionValueInteger::ID)
+ iValue = ((TD::optionValueInteger *)pObj->value_.get())->value_;
+
+ if (pObj->name_ == "my_id") {
+ m_iOwnId = iValue;
+ SetId(0, m_iOwnId);
+
+ auto *pUser = AddUser(iValue, false);
+ setWString(pUser->hContact, "Nick", TranslateT("Saved messages"));
+ }
+}
+
void CTelegramProto::ProcessStatus(TD::updateUserStatus *pObj)
{
if (auto *pUser = FindUser(pObj->user_id_)) {
@@ -621,17 +639,7 @@ void CTelegramProto::ProcessUser(TD::updateUser *pObj)
{
auto *pUser = pObj->user_.get();
- if (pUser->phone_number_ == m_szFullPhone.c_str()) {
- m_iOwnId = pUser->id_;
- SetId(0, m_iOwnId);
-
- if (!FindUser(pUser->id_)) {
- auto *pMe = new TG_USER(pUser->id_, 0);
- m_arUsers.insert(pMe);
- m_arChats.insert(pMe);
- }
- }
- else if (!pUser->is_contact_) {
+ if (!pUser->is_contact_) {
auto *pu = AddFakeUser(pUser->id_, false);
if (pu->hContact != INVALID_CONTACT_ID)
Contact::RemoveFromList(pu->hContact);
@@ -655,31 +663,33 @@ void CTelegramProto::ProcessUser(TD::updateUser *pObj)
}
auto *pu = AddUser(pUser->id_, false);
- UpdateString(pu->hContact, "FirstName", pUser->first_name_);
- UpdateString(pu->hContact, "LastName", pUser->last_name_);
- UpdateString(pu->hContact, "Phone", pUser->phone_number_);
+ MCONTACT hContact = (pUser->id_ == m_iOwnId) ? 0 : pu->hContact;
+ UpdateString(hContact, "FirstName", pUser->first_name_);
+ UpdateString(hContact, "LastName", pUser->last_name_);
+ if (hContact)
+ UpdateString(hContact, "Phone", pUser->phone_number_);
+
if (pUser->usernames_)
- UpdateString(pu->hContact, "Nick", pUser->usernames_->editable_username_);
- if (pu->hContact == 0)
- pu->wszNick = Contact::GetInfo(CNF_DISPLAY, 0, m_szModuleName);
- Contact::PutOnList(pu->hContact);
+ UpdateString(hContact, "Nick", pUser->usernames_->editable_username_);
+
+ Contact::PutOnList(hContact);
if (pUser->is_premium_)
- ExtraIcon_SetIconByName(g_plugin.m_hIcon, pu->hContact, "tg_premium");
+ ExtraIcon_SetIconByName(g_plugin.m_hIcon, hContact, "tg_premium");
else
- ExtraIcon_SetIconByName(g_plugin.m_hIcon, pu->hContact, nullptr);
+ ExtraIcon_SetIconByName(g_plugin.m_hIcon, hContact, nullptr);
if (auto *pPhoto = pUser->profile_photo_.get()) {
if (auto *pSmall = pPhoto->small_.get()) {
auto remoteId = pSmall->remote_->unique_id_;
- auto storedId = getMStringA(pu->hContact, DBKEY_AVATAR_HASH);
+ auto storedId = getMStringA(hContact, DBKEY_AVATAR_HASH);
if (remoteId != storedId.c_str()) {
if (!remoteId.empty()) {
pu->szAvatarHash = remoteId.c_str();
- setString(pu->hContact, DBKEY_AVATAR_HASH, remoteId.c_str());
+ setString(hContact, DBKEY_AVATAR_HASH, remoteId.c_str());
SendQuery(new TD::downloadFile(pSmall->id_, 5, 0, 0, false));
}
- else delSetting(pu->hContact, DBKEY_AVATAR_HASH);
+ else delSetting(hContact, DBKEY_AVATAR_HASH);
}
}
}
@@ -687,7 +697,7 @@ void CTelegramProto::ProcessUser(TD::updateUser *pObj)
if (pUser->status_) {
if (pUser->status_->get_id() == TD::userStatusOffline::ID) {
auto *pOffline = (TD::userStatusOffline *)pUser->status_.get();
- setDword(pu->hContact, "LastSeen", pOffline->was_online_);
+ setDword(hContact, "LastSeen", pOffline->was_online_);
}
}
}