diff options
author | George Hazan <ghazan@miranda.im> | 2023-03-24 14:02:05 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-03-24 14:02:05 +0300 |
commit | a57bbea45f91d66defa6e9a4ca185c6c7656d8c0 (patch) | |
tree | 64e6c11778ceff494cb846785bbe3b23840268bb /protocols/Telegram/src | |
parent | 0e4a45eff4dd8ab29f8dd79e419d33a89a808939 (diff) |
Telegram: fix for basic groups promoted to super groups
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r-- | protocols/Telegram/src/groupchat.cpp | 25 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 6 | ||||
-rw-r--r-- | protocols/Telegram/src/server.cpp | 21 |
3 files changed, 35 insertions, 17 deletions
diff --git a/protocols/Telegram/src/groupchat.cpp b/protocols/Telegram/src/groupchat.cpp index 5b13fe4fe3..076dd28782 100644 --- a/protocols/Telegram/src/groupchat.cpp +++ b/protocols/Telegram/src/groupchat.cpp @@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" -void CTelegramProto::InitGroupChat(TG_USER *pUser, const TD::chat *pChat, bool bUpdateMembers) +void CTelegramProto::InitGroupChat(TG_USER *pUser, const TD::chat *pChat) { if (pUser->m_si) return; @@ -26,7 +26,7 @@ void CTelegramProto::InitGroupChat(TG_USER *pUser, const TD::chat *pChat, bool b _i64tow(pUser->id, wszId, 10); SESSION_INFO *si; - if (bUpdateMembers) { + if (pUser->bLoadMembers) { si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszId, Utf2T(pChat->title_.c_str()), pUser); if (!si->pStatuses) { Chat_AddGroup(si, TranslateT("Creator")); @@ -34,7 +34,10 @@ void CTelegramProto::InitGroupChat(TG_USER *pUser, const TD::chat *pChat, bool b Chat_AddGroup(si, TranslateT("Participant")); // push async query to fetch users - SendQuery(new TD::getBasicGroupFullInfo(pUser->id), &CTelegramProto::StartGroupChat, pUser); + if (m_arBasicGroups.find((TG_BASIC_GROUP*)&pUser->id)) + SendQuery(new TD::getBasicGroupFullInfo(pUser->id), &CTelegramProto::StartGroupChat, pUser); + else + SendQuery(new TD::getSupergroupMembers(pUser->id, 0, 0, 100), &CTelegramProto::StartGroupChat, pUser); } else { Chat_Control(si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); @@ -75,15 +78,25 @@ void CTelegramProto::StartGroupChat(td::ClientManager::Response &response, void if (!response.object) return; - if (response.object->get_id() != TD::basicGroupFullInfo::ID) { + TD::array<TD::object_ptr<TD::chatMember>> *pMembers; + + switch (response.object->get_id()) { + case TD::basicGroupFullInfo::ID: + pMembers = &((TD::basicGroupFullInfo *)response.object.get())->members_; + break; + + case TD::chatMembers::ID: + pMembers = &((TD::chatMembers *)response.object.get())->members_; + break; + + default: debugLogA("Gotten class ID %d instead of %d, exiting", response.object->get_id(), TD::basicGroupFullInfo::ID); return; } - auto *pInfo = ((TD::basicGroupFullInfo *)response.object.get()); auto *pUser = (TG_USER *)pUserData; - for (auto &it : pInfo->members_) { + for (auto &it : *pMembers) { auto *pMember = it.get(); const wchar_t *pwszRole; diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index af6c3d9851..1234bb3ed3 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -76,7 +76,7 @@ struct TG_FILE_REQUEST : public MZeroedObject PROTOFILETRANSFERSTATUS pfts; }; -struct TG_USER +struct TG_USER : public MZeroedObject { TG_USER(int64_t _1, MCONTACT _2, bool _3 = false) : id(_1), @@ -88,7 +88,7 @@ struct TG_USER int64_t id, chatId; MCONTACT hContact; - bool isGroupChat; + bool isGroupChat, bLoadMembers; CMStringA szAvatarHash; CMStringW wszNick, wszFirstName, wszLastName; time_t m_timer1 = 0, m_timer2 = 0; @@ -233,7 +233,7 @@ class CTelegramProto : public PROTO<CTelegramProto> OBJLIST<TG_BASIC_GROUP> m_arBasicGroups; OBJLIST<TG_SUPER_GROUP> m_arSuperGroups; - void InitGroupChat(TG_USER *pUser, const TD::chat *pChat, bool bUpdateMembers); + void InitGroupChat(TG_USER *pUser, const TD::chat *pChat); void StartGroupChat(td::ClientManager::Response &response, void *pUserData); void Chat_SendPrivateMessage(GCHOOK *gch); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 2204be7de6..a42736c049 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -267,13 +267,18 @@ void CTelegramProto::SendQuery(TD::Function *pFunc, TG_QUERY_HANDLER_FULL pHandl void CTelegramProto::ProcessBasicGroup(TD::updateBasicGroup *pObj)
{
- auto iStatusId = pObj->basic_group_->status_->get_id();
+ auto *pBasicGroup = pObj->basic_group_.get();
+ if (pBasicGroup->upgraded_to_supergroup_id_)
+ if (auto *pUser = FindUser(pBasicGroup->upgraded_to_supergroup_id_))
+ pUser->bLoadMembers = true;
+
+ auto iStatusId = pBasicGroup->status_->get_id();
if (iStatusId == TD::chatMemberStatusBanned::ID) {
debugLogA("We are banned here, skipping");
return;
}
- TG_BASIC_GROUP tmp(pObj->basic_group_->id_, 0);
+ TG_BASIC_GROUP tmp(pBasicGroup->id_, 0);
auto *pGroup = m_arBasicGroups.find(&tmp);
if (pGroup == nullptr) {
pGroup = new TG_BASIC_GROUP(tmp.id, std::move(pObj->basic_group_));
@@ -281,16 +286,18 @@ void CTelegramProto::ProcessBasicGroup(TD::updateBasicGroup *pObj) }
else pGroup->group = std::move(pObj->basic_group_);
+ TG_USER *pUser;
if (iStatusId == TD::chatMemberStatusLeft::ID) {
- auto *pUser = AddFakeUser(tmp.id, true);
+ pUser = AddFakeUser(tmp.id, true);
pUser->wszLastName.Format(TranslateT("%d member(s)"), pGroup->group->member_count_);
}
- else AddUser(tmp.id, true);
+ else pUser = AddUser(tmp.id, true);
+
+ pUser->bLoadMembers = true;
}
void CTelegramProto::ProcessChat(TD::updateNewChat *pObj)
{
- bool bIsBasicGroup = false;
int64_t chatId;
auto *pChat = pObj->chat_.get();
std::string szTitle;
@@ -302,13 +309,11 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) break;
case TD::chatTypeBasicGroup::ID:
- bIsBasicGroup = true;
chatId = ((TD::chatTypeBasicGroup*)pChat->type_.get())->basic_group_id_;
szTitle = pChat->title_;
break;
case TD::chatTypeSupergroup::ID:
- bIsBasicGroup = false;
chatId = ((TD::chatTypeSupergroup *)pChat->type_.get())->supergroup_id_;
szTitle = pChat->title_;
break;
@@ -335,7 +340,7 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) return;
if (pUser->isGroupChat && pUser->hContact != INVALID_CONTACT_ID)
- InitGroupChat(pUser, pChat, bIsBasicGroup);
+ InitGroupChat(pUser, pChat);
}
else debugLogA("Unknown chat id %lld, ignoring", chatId);
}
|