From 85f62df34eb1a5c5310178cc0d08ad13132f5c7b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 15 Feb 2023 13:37:01 +0300 Subject: minor code optimization --- protocols/Telegram/src/proto.h | 1 + protocols/Telegram/src/server.cpp | 8 ++++++-- protocols/Telegram/src/utils.cpp | 13 ++++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'protocols') diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index b0dc9645a0..4b5c1afa13 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -231,6 +231,7 @@ class CTelegramProto : public PROTO TG_USER* FindUser(int64_t id); TG_USER* AddUser(int64_t id, bool bIsChat); TG_USER* AddFakeUser(int64_t id, bool bIsChat); + void SetId(MCONTACT, int64_t id); // Popups HANDLE m_hPopupClass; diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 291cf9e056..66fcd2f6f8 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -480,9 +480,13 @@ void CTelegramProto::ProcessUser(TD::updateUser *pObj) if (pUser->phone_number_ == m_szFullPhone.c_str()) { m_iOwnId = pUser->id_; + SetId(0, m_iOwnId); - if (!FindUser(pUser->id_)) - m_arUsers.insert(new TG_USER(pUser->id_, 0)); + if (!FindUser(pUser->id_)) { + auto *pMe = new TG_USER(pUser->id_, 0); + m_arUsers.insert(pMe); + m_arChats.insert(pMe); + } } if (!pUser->is_contact_) { diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 7dfe0c3096..8a5a1ddb87 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -82,6 +82,15 @@ void CTelegramProto::ReportSearchUser(TG_USER *pUser) ///////////////////////////////////////////////////////////////////////////////////////// +void CTelegramProto::SetId(MCONTACT hContact, int64_t id) +{ + char szId[100]; + _i64toa(id, szId, 10); + setString(hContact, DBKEY_ID, szId); +} + +///////////////////////////////////////////////////////////////////////////////////////// + void CTelegramProto::UpdateString(MCONTACT hContact, const char *pszSetting, const std::string &str) { if (str.empty()) @@ -126,9 +135,7 @@ TG_USER* CTelegramProto::AddUser(int64_t id, bool bIsChat) MCONTACT hContact = db_add_contact(); Proto_AddToContact(hContact, m_szModuleName); - char szId[100]; - _i64toa(id, szId, 10); - setString(hContact, DBKEY_ID, szId); + SetId(hContact, id); if (bIsChat) { Clist_SetGroup(hContact, TranslateT("Chat rooms")); -- cgit v1.2.3