Skip to content

Commit

Permalink
f Migrated Api::ChatParticipants from MTP to TDLib.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Sep 11, 2024
1 parent 514e3cb commit 807a207
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions Telegram/SourceFiles/api/api_chat_participants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void ApplyBotsList(
Data::PeerUpdate::Flag::FullInfo);
}

#if 0 // mtp
[[nodiscard]] ChatParticipants::Channels ParseSimilar(
not_null<Main::Session*> session,
const MTPmessages_Chats &chats) {
Expand Down Expand Up @@ -250,6 +251,34 @@ void ApplyBotsList(
const MTPmessages_Chats &chats) {
return ParseSimilar(&channel->session(), chats);
}
#endif

[[nodiscard]] ChatParticipants::Channels ParseSimilar(
not_null<Main::Session*> session,
const TLchats &chats) {
auto result = ChatParticipants::Channels();
const auto &data = chats.data();
const auto &list = data.vchat_ids().v;
result.list.reserve(list.size());
for (const auto chatId : list) {
const auto peer = session->data().peer(peerFromTdbChat(chatId));
if (const auto channel = peer->asChannel()) {
result.list.push_back(channel);
}
}
if (session->premiumPossible()) {
result.more = std::max(
int(data.vtotal_count().v) - int(data.vchat_ids().v.size()),
0);
}
return result;
}

[[nodiscard]] ChatParticipants::Channels ParseSimilar(
not_null<ChannelData*> channel,
const TLchats &chats) {
return ParseSimilar(&channel->session(), chats);
}

} // namespace

Expand Down Expand Up @@ -614,7 +643,11 @@ void ChatParticipants::add(
done(true);
}
}).fail([=](const Error &error) {
ShowAddParticipantsError(error.message, peer, { 1, user });
ShowAddParticipantsError(
show,
error.message,
peer,
user);
if (done) {
done(false);
}
Expand Down Expand Up @@ -666,7 +699,11 @@ void ChatParticipants::add(
callback(true);
}
}).fail([=](const Error &error) {
ShowAddParticipantsError(error.message, peer, users);
ShowAddParticipantsError(
show,
error.message,
peer,
{ .users = users });
if (callback) {
callback(false);
}
Expand Down Expand Up @@ -966,12 +1003,17 @@ void ChatParticipants::loadSimilarChannels(not_null<ChannelData*> channel) {
return;
}
}
#if 0 // mtp
using Flag = MTPchannels_GetChannelRecommendations::Flag;
_similar[channel].requestId = _api.request(
MTPchannels_GetChannelRecommendations(
MTP_flags(Flag::f_channel),
channel->inputChannel)
).done([=](const MTPmessages_Chats &result) {
#endif
_similar[channel].requestId = _api.request(TLgetChatSimilarChats(
peerToTdbChat(channel->id)
)).done([=](const TLchats &result) {
auto &similar = _similar[channel];
similar.requestId = 0;
auto parsed = ParseSimilar(channel, result);
Expand Down Expand Up @@ -1009,6 +1051,15 @@ void ChatParticipants::loadRecommendations() {
if (_recommendationsLoaded.current() || _recommendations.requestId) {
return;
}
_recommendations.requestId = _api.request(TLgetRecommendedChats(
)).done([=](const TLchats &result) {
_recommendations.requestId = 0;
auto parsed = ParseSimilar(_session, result);
_recommendations.channels = std::move(parsed);
_recommendations.channels.more = 0;
_recommendationsLoaded = true;
}).send();
#if 0 // mtp
_recommendations.requestId = _api.request(
MTPchannels_GetChannelRecommendations(
MTP_flags(0),
Expand All @@ -1020,6 +1071,7 @@ void ChatParticipants::loadRecommendations() {
_recommendations.channels.more = 0;
_recommendationsLoaded = true;
}).send();
#endif
}

const ChatParticipants::Channels &ChatParticipants::recommendations() const {
Expand Down

0 comments on commit 807a207

Please sign in to comment.