From 36271d6b85aaa4d82e0862f6604330cc2c5ca15b Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 27 Oct 2021 09:57:37 +0400 Subject: [PATCH] Save recent requester userIds from API. --- Telegram/SourceFiles/api/api_updates.cpp | 5 +++-- Telegram/SourceFiles/data/data_channel.cpp | 23 ++++++++++++++++++---- Telegram/SourceFiles/data/data_channel.h | 11 ++++++++++- Telegram/SourceFiles/data/data_chat.cpp | 23 ++++++++++++++++++---- Telegram/SourceFiles/data/data_chat.h | 11 ++++++++++- 5 files changed, 61 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index ab0749cb53..5dd2d87449 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -1970,10 +1970,11 @@ void Updates::feedUpdate(const MTPUpdate &update) { const auto &d = update.c_updatePendingJoinRequests(); if (const auto peer = session().data().peerLoaded(peerFromMTP(d.vpeer()))) { const auto count = d.vrequests_pending().v; + const auto &requesters = d.vrecent_requesters().v; if (const auto chat = peer->asChat()) { - chat->setPendingRequestsCount(count); + chat->setPendingRequestsCount(count, requesters); } else if (const auto channel = peer->asChannel()) { - channel->setPendingRequestsCount(count); + channel->setPendingRequestsCount(count, requesters); } } } break; diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 03a7a3457f..e16fd4447c 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -195,9 +195,23 @@ void ChannelData::setKickedCount(int newKickedCount) { } } -void ChannelData::setPendingRequestsCount(int count) { - if (_pendingRequestsCount != count) { +void ChannelData::setPendingRequestsCount( + int count, + const QVector &recentRequesters) { + setPendingRequestsCount(count, ranges::views::all( + recentRequesters + ) | ranges::views::transform([&](const MTPlong &value) { + return UserId(value); + }) | ranges::to_vector); +} + +void ChannelData::setPendingRequestsCount( + int count, + std::vector recentRequesters) { + if (_pendingRequestsCount != count + || _recentRequesters != recentRequesters) { _pendingRequestsCount = count; + _recentRequesters = std::move(recentRequesters); session().changes().peerUpdated(this, UpdateFlag::PendingRequests); } } @@ -550,7 +564,7 @@ void ChannelData::setAdminRights(ChatAdminRights rights) { } _adminRights.set(rights); if (!canHaveInviteLink()) { - setPendingRequestsCount(0); + setPendingRequestsCount(0, std::vector{}); } if (isMegagroup()) { const auto self = session().user(); @@ -885,7 +899,8 @@ void ApplyChannelUpdate( channel->setThemeEmoji(qs(update.vtheme_emoticon().value_or_empty())); channel->fullUpdated(); channel->setPendingRequestsCount( - update.vrequests_pending().value_or_empty()); + update.vrequests_pending().value_or_empty(), + update.vrecent_requesters().value_or_empty()); if (canViewAdmins != channel->canViewAdmins() || canViewMembers != channel->canViewMembers()) { diff --git a/Telegram/SourceFiles/data/data_channel.h b/Telegram/SourceFiles/data/data_channel.h index d4980f7f0e..420746b268 100644 --- a/Telegram/SourceFiles/data/data_channel.h +++ b/Telegram/SourceFiles/data/data_channel.h @@ -180,7 +180,15 @@ public: [[nodiscard]] int pendingRequestsCount() const { return _pendingRequestsCount; } - void setPendingRequestsCount(int count); + [[nodiscard]] const std::vector &recentRequesters() const { + return _recentRequesters; + } + void setPendingRequestsCount( + int count, + const QVector &recentRequesters); + void setPendingRequestsCount( + int count, + std::vector recentRequesters); [[nodiscard]] bool haveLeft() const { return flags() & Flag::Left; @@ -433,6 +441,7 @@ private: int _restrictedCount = 0; int _kickedCount = 0; int _pendingRequestsCount = 0; + std::vector _recentRequesters; MsgId _availableMinId = 0; RestrictionFlags _defaultRestrictions; diff --git a/Telegram/SourceFiles/data/data_chat.cpp b/Telegram/SourceFiles/data/data_chat.cpp index 780e97770b..217cac924c 100644 --- a/Telegram/SourceFiles/data/data_chat.cpp +++ b/Telegram/SourceFiles/data/data_chat.cpp @@ -147,7 +147,7 @@ void ChatData::setAdminRights(ChatAdminRights rights) { } _adminRights.set(rights); if (!canHaveInviteLink()) { - setPendingRequestsCount(0); + setPendingRequestsCount(0, std::vector{}); } session().changes().peerUpdated( this, @@ -261,9 +261,23 @@ void ChatData::setBotCommands( } } -void ChatData::setPendingRequestsCount(int count) { - if (_pendingRequestsCount != count) { +void ChatData::setPendingRequestsCount( + int count, + const QVector &recentRequesters) { + setPendingRequestsCount(count, ranges::views::all( + recentRequesters + ) | ranges::views::transform([&](const MTPlong &value) { + return UserId(value); + }) | ranges::to_vector); +} + +void ChatData::setPendingRequestsCount( + int count, + std::vector recentRequesters) { + if (_pendingRequestsCount != count + || _recentRequesters != recentRequesters) { _pendingRequestsCount = count; + _recentRequesters = std::move(recentRequesters); session().changes().peerUpdated(this, UpdateFlag::PendingRequests); } } @@ -442,7 +456,8 @@ void ApplyChatUpdate(not_null chat, const MTPDchatFull &update) { chat->fullUpdated(); chat->setAbout(qs(update.vabout())); chat->setPendingRequestsCount( - update.vrequests_pending().value_or_empty()); + update.vrequests_pending().value_or_empty(), + update.vrecent_requesters().value_or_empty()); chat->session().api().applyNotifySettings( MTP_inputNotifyPeer(chat->input), diff --git a/Telegram/SourceFiles/data/data_chat.h b/Telegram/SourceFiles/data/data_chat.h index fa98af0447..97f022c82e 100644 --- a/Telegram/SourceFiles/data/data_chat.h +++ b/Telegram/SourceFiles/data/data_chat.h @@ -167,7 +167,15 @@ public: [[nodiscard]] int pendingRequestsCount() const { return _pendingRequestsCount; } - void setPendingRequestsCount(int count); + [[nodiscard]] const std::vector &recentRequesters() const { + return _recentRequesters; + } + void setPendingRequestsCount( + int count, + const QVector &recentRequesters); + void setPendingRequestsCount( + int count, + std::vector recentRequesters); // Still public data members. const MTPlong inputChat; @@ -191,6 +199,7 @@ private: AdminRightFlags _adminRights; int _version = 0; int _pendingRequestsCount = 0; + std::vector _recentRequesters; std::unique_ptr _call; PeerId _callDefaultJoinAs = 0;