mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Show similar channels under join message.
This commit is contained in:
@@ -211,6 +211,23 @@ void ApplyBotsList(
|
||||
Data::PeerUpdate::Flag::FullInfo);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<not_null<ChannelData*>> ParseSimilar(
|
||||
not_null<ChannelData*> channel,
|
||||
const MTPmessages_Chats &chats) {
|
||||
auto result = std::vector<not_null<ChannelData*>>();
|
||||
chats.match([&](const auto &data) {
|
||||
const auto &list = data.vchats().v;
|
||||
result.reserve(list.size());
|
||||
for (const auto &chat : list) {
|
||||
const auto peer = channel->owner().processChat(chat);
|
||||
if (const auto channel = peer->asChannel()) {
|
||||
result.push_back(channel);
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ChatParticipant::ChatParticipant(
|
||||
@@ -559,6 +576,7 @@ void ChatParticipants::requestSelf(not_null<ChannelData*> channel) {
|
||||
UserId inviter = -1,
|
||||
TimeId inviteDate = 0,
|
||||
bool inviteViaRequest = false) {
|
||||
const auto dateChanged = (channel->inviteDate != inviteDate);
|
||||
channel->inviter = inviter;
|
||||
channel->inviteDate = inviteDate;
|
||||
channel->inviteViaRequest = inviteViaRequest;
|
||||
@@ -569,6 +587,9 @@ void ChatParticipants::requestSelf(not_null<ChannelData*> channel) {
|
||||
} else {
|
||||
history->owner().histories().requestDialogEntry(history);
|
||||
}
|
||||
if (dateChanged) {
|
||||
loadSimilarChannels(channel);
|
||||
}
|
||||
}
|
||||
};
|
||||
_selfParticipantRequests.emplace(channel);
|
||||
@@ -685,4 +706,35 @@ void ChatParticipants::unblock(
|
||||
_kickRequests.emplace(kick, requestId);
|
||||
}
|
||||
|
||||
void ChatParticipants::loadSimilarChannels(not_null<ChannelData*> channel) {
|
||||
if (!channel->isBroadcast() || _similar.contains(channel)) {
|
||||
return;
|
||||
}
|
||||
_similar[channel].requestId = _api.request(
|
||||
MTPchannels_GetChannelRecommendations(channel->inputChannel)
|
||||
).done([=](const MTPmessages_Chats &result) {
|
||||
_similar[channel] = {
|
||||
.list = ParseSimilar(channel, result),
|
||||
};
|
||||
_similarLoaded.fire_copy(channel);
|
||||
}).send();
|
||||
}
|
||||
|
||||
const std::vector<not_null<ChannelData*>> &ChatParticipants::similar(
|
||||
not_null<ChannelData*> channel) {
|
||||
const auto i = channel->isBroadcast()
|
||||
? _similar.find(channel)
|
||||
: end(_similar);
|
||||
if (i != end(_similar)) {
|
||||
return i->second.list;
|
||||
}
|
||||
static const auto empty = std::vector<not_null<ChannelData*>>();
|
||||
return empty;
|
||||
}
|
||||
|
||||
auto ChatParticipants::similarLoaded() const
|
||||
-> rpl::producer<not_null<ChannelData*>> {
|
||||
return _similarLoaded.events();
|
||||
}
|
||||
|
||||
} // namespace Api
|
||||
|
||||
Reference in New Issue
Block a user