From 0ae260c6e109786699b81b3ff33c013103ca4a4e Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 2 Aug 2021 01:57:36 +0300 Subject: [PATCH] Moved MTP blocked peers from ApiWrap to Api::BlockedPeers. --- Telegram/CMakeLists.txt | 2 + .../SourceFiles/api/api_blocked_peers.cpp | 173 ++++++++++++++++++ Telegram/SourceFiles/api/api_blocked_peers.h | 60 ++++++ Telegram/SourceFiles/apiwrap.cpp | 136 +------------- Telegram/SourceFiles/apiwrap.h | 30 +-- .../view/history_view_contact_status.cpp | 3 +- .../info/profile/info_profile_actions.cpp | 3 +- .../settings/settings_privacy_controllers.cpp | 75 +++----- .../settings/settings_privacy_controllers.h | 8 +- .../settings/settings_privacy_security.cpp | 7 +- .../SourceFiles/window/window_peer_menu.cpp | 7 +- 11 files changed, 283 insertions(+), 221 deletions(-) create mode 100644 Telegram/SourceFiles/api/api_blocked_peers.cpp create mode 100644 Telegram/SourceFiles/api/api_blocked_peers.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 9542f86aa9..fd80c5555a 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -91,6 +91,8 @@ PRIVATE api/api_attached_stickers.h api/api_authorizations.cpp api/api_authorizations.h + api/api_blocked_peers.cpp + api/api_blocked_peers.h api/api_bot.cpp api/api_bot.h api/api_chat_filters.cpp diff --git a/Telegram/SourceFiles/api/api_blocked_peers.cpp b/Telegram/SourceFiles/api/api_blocked_peers.cpp new file mode 100644 index 0000000000..8231478949 --- /dev/null +++ b/Telegram/SourceFiles/api/api_blocked_peers.cpp @@ -0,0 +1,173 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "api/api_blocked_peers.h" + +#include "apiwrap.h" +#include "base/unixtime.h" +#include "data/data_changes.h" +#include "data/data_peer.h" +#include "data/data_peer_id.h" +#include "data/data_session.h" +#include "main/main_session.h" + +namespace Api { +namespace { + +constexpr auto kBlockedFirstSlice = 16; +constexpr auto kBlockedPerPage = 40; + +BlockedPeers::Slice TLToSlice( + const MTPcontacts_Blocked &blocked, + Data::Session &owner) { + const auto create = [&](int count, const QVector &list) { + auto slice = BlockedPeers::Slice(); + slice.total = std::max(count, list.size()); + slice.list.reserve(list.size()); + for (const auto &contact : list) { + contact.match([&](const MTPDpeerBlocked &data) { + slice.list.push_back({ + .id = peerFromMTP(data.vpeer_id()), + .date = data.vdate().v, + }); + }); + } + return slice; + }; + return blocked.match([&](const MTPDcontacts_blockedSlice &data) { + owner.processUsers(data.vusers()); + owner.processChats(data.vchats()); + return create(data.vcount().v, data.vblocked().v); + }, [&](const MTPDcontacts_blocked &data) { + owner.processUsers(data.vusers()); + owner.processChats(data.vchats()); + return create(0, data.vblocked().v); + }); +} + +} // namespace + +BlockedPeers::BlockedPeers(not_null api) +: _session(&api->session()) +, _api(&api->instance()) { +} + +bool BlockedPeers::Slice::Item::operator==(const Item &other) const { + return (id == other.id) && (date == other.date); +} + +bool BlockedPeers::Slice::Item::operator!=(const Item &other) const { + return !(*this == other); +} + +bool BlockedPeers::Slice::operator==(const BlockedPeers::Slice &other) const { + return (total == other.total) && (list == other.list); +} + +bool BlockedPeers::Slice::operator!=(const BlockedPeers::Slice &other) const { + return !(*this == other); +} + +void BlockedPeers::block(not_null peer) { + if (peer->isBlocked()) { + _session->changes().peerUpdated( + peer, + Data::PeerUpdate::Flag::IsBlocked); + } else if (_blockRequests.find(peer) == end(_blockRequests)) { + const auto requestId = _api.request(MTPcontacts_Block( + peer->input + )).done([=](const MTPBool &result) { + _blockRequests.erase(peer); + peer->setIsBlocked(true); + if (_slice) { + _slice->list.insert( + _slice->list.begin(), + { peer->id, base::unixtime::now() }); + ++_slice->total; + _changes.fire_copy(*_slice); + } + }).fail([=](const MTP::Error &error) { + _blockRequests.erase(peer); + }).send(); + + _blockRequests.emplace(peer, requestId); + } +} + +void BlockedPeers::unblock(not_null peer, Fn onDone) { + if (!peer->isBlocked()) { + _session->changes().peerUpdated( + peer, + Data::PeerUpdate::Flag::IsBlocked); + return; + } else if (_blockRequests.find(peer) != end(_blockRequests)) { + return; + } + const auto requestId = _api.request(MTPcontacts_Unblock( + peer->input + )).done([=](const MTPBool &result) { + _blockRequests.erase(peer); + peer->setIsBlocked(false); + if (_slice) { + auto &list = _slice->list; + for (auto i = list.begin(); i != list.end(); ++i) { + if (i->id == peer->id) { + list.erase(i); + break; + } + } + if (_slice->total > list.size()) { + --_slice->total; + } + _changes.fire_copy(*_slice); + } + if (onDone) { + onDone(); + } + }).fail([=](const MTP::Error &error) { + _blockRequests.erase(peer); + }).send(); + _blockRequests.emplace(peer, requestId); +} + +void BlockedPeers::reload() { + if (_requestId) { + return; + } + request(0, [=](Slice &&slice) { + if (!_slice || *_slice != slice) { + _slice = slice; + _changes.fire(std::move(slice)); + } + }); +} + +auto BlockedPeers::slice() -> rpl::producer { + if (!_slice) { + reload(); + } + return _slice + ? _changes.events_starting_with_copy(*_slice) + : (_changes.events() | rpl::type_erased()); +} + +void BlockedPeers::request(int offset, Fn onDone) { + if (_requestId) { + return; + } + _requestId = _api.request(MTPcontacts_GetBlocked( + MTP_int(offset), + MTP_int(offset ? kBlockedPerPage : kBlockedFirstSlice) + )).done([=](const MTPcontacts_Blocked &result) { + _requestId = 0; + onDone(TLToSlice(result, _session->data())); + }).fail([=](const MTP::Error &error) { + _requestId = 0; + }).send(); +} + +} // namespace Api diff --git a/Telegram/SourceFiles/api/api_blocked_peers.h b/Telegram/SourceFiles/api/api_blocked_peers.h new file mode 100644 index 0000000000..ae506bbc92 --- /dev/null +++ b/Telegram/SourceFiles/api/api_blocked_peers.h @@ -0,0 +1,60 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "mtproto/sender.h" + +class ApiWrap; + +namespace Main { +class Session; +} // namespace Main + +namespace Api { + +class BlockedPeers final { +public: + struct Slice { + struct Item { + PeerId id; + TimeId date = 0; + + bool operator==(const Item &other) const; + bool operator!=(const Item &other) const; + }; + + QVector list; + int total = 0; + + bool operator==(const Slice &other) const; + bool operator!=(const Slice &other) const; + }; + + explicit BlockedPeers(not_null api); + + void reload(); + rpl::producer slice(); + void request(int offset, Fn onDone); + + void block(not_null peer); + void unblock(not_null peer, Fn onDone = nullptr); + +private: + const not_null _session; + + MTP::Sender _api; + + base::flat_map, mtpRequestId> _blockRequests; + mtpRequestId _requestId = 0; + std::optional _slice; + rpl::event_stream _changes; + + +}; + +} // namespace Api diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 09dcd2ddbb..f0ab9be410 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_authorizations.h" #include "api/api_attached_stickers.h" +#include "api/api_blocked_peers.h" #include "api/api_hash.h" #include "api/api_invite_links.h" #include "api/api_media.h" @@ -109,7 +110,6 @@ constexpr auto kStickersByEmojiInvalidateTimeout = crl::time(60 * 60 * 1000); constexpr auto kNotifySettingSaveTimeout = crl::time(1000); constexpr auto kDialogsFirstLoad = 20; constexpr auto kDialogsPerPage = 500; -constexpr auto kBlockedFirstSlice = 16; using PhotoFileLocationId = Data::PhotoFileLocationId; using DocumentFileLocationId = Data::DocumentFileLocationId; @@ -121,22 +121,6 @@ using UpdatedFileReferences = Data::UpdatedFileReferences; } // namespace -bool ApiWrap::BlockedPeersSlice::Item::operator==(const Item &other) const { - return (peer == other.peer) && (date == other.date); -} - -bool ApiWrap::BlockedPeersSlice::Item::operator!=(const Item &other) const { - return !(*this == other); -} - -bool ApiWrap::BlockedPeersSlice::operator==(const BlockedPeersSlice &other) const { - return (total == other.total) && (list == other.list); -} - -bool ApiWrap::BlockedPeersSlice::operator!=(const BlockedPeersSlice &other) const { - return !(*this == other); -} - ApiWrap::ApiWrap(not_null session) : MTP::Sender(&session->account().mtp()) , _session(session) @@ -150,6 +134,7 @@ ApiWrap::ApiWrap(not_null session) , _updateNotifySettingsTimer([=] { sendNotifySettingsUpdates(); }) , _authorizations(std::make_unique(this)) , _attachedStickers(std::make_unique(this)) +, _blockedPeers(std::make_unique(this)) , _selfDestruct(std::make_unique(this)) , _sensitiveContent(std::make_unique(this)) , _globalPrivacy(std::make_unique(this)) @@ -2134,68 +2119,6 @@ void ApiWrap::leaveChannel(not_null channel) { } } -void ApiWrap::blockPeer(not_null peer) { - if (peer->isBlocked()) { - session().changes().peerUpdated( - peer, - Data::PeerUpdate::Flag::IsBlocked); - } else if (_blockRequests.find(peer) == end(_blockRequests)) { - const auto requestId = request(MTPcontacts_Block( - peer->input - )).done([=](const MTPBool &result) { - _blockRequests.erase(peer); - peer->setIsBlocked(true); - if (_blockedPeersSlice) { - _blockedPeersSlice->list.insert( - _blockedPeersSlice->list.begin(), - { peer, base::unixtime::now() }); - ++_blockedPeersSlice->total; - _blockedPeersChanges.fire_copy(*_blockedPeersSlice); - } - }).fail([=](const MTP::Error &error) { - _blockRequests.erase(peer); - }).send(); - - _blockRequests.emplace(peer, requestId); - } -} - -void ApiWrap::unblockPeer(not_null peer, Fn onDone) { - if (!peer->isBlocked()) { - session().changes().peerUpdated( - peer, - Data::PeerUpdate::Flag::IsBlocked); - return; - } else if (_blockRequests.find(peer) != end(_blockRequests)) { - return; - } - const auto requestId = request(MTPcontacts_Unblock( - peer->input - )).done([=](const MTPBool &result) { - _blockRequests.erase(peer); - peer->setIsBlocked(false); - if (_blockedPeersSlice) { - auto &list = _blockedPeersSlice->list; - for (auto i = list.begin(); i != list.end(); ++i) { - if (i->peer == peer) { - list.erase(i); - break; - } - } - if (_blockedPeersSlice->total > list.size()) { - --_blockedPeersSlice->total; - } - _blockedPeersChanges.fire_copy(*_blockedPeersSlice); - } - if (onDone) { - onDone(); - } - }).fail([=](const MTP::Error &error) { - _blockRequests.erase(peer); - }).send(); - _blockRequests.emplace(peer, requestId); -} - void ApiWrap::requestNotifySettings(const MTPInputNotifyPeer &peer) { const auto key = [&] { switch (peer.type()) { @@ -4799,57 +4722,6 @@ void ApiWrap::saveSelfBio(const QString &text, FnMut done) { }).send(); } -void ApiWrap::reloadBlockedPeers() { - if (_blockedPeersRequestId) { - return; - } - _blockedPeersRequestId = request(MTPcontacts_GetBlocked( - MTP_int(0), - MTP_int(kBlockedFirstSlice) - )).done([=](const MTPcontacts_Blocked &result) { - _blockedPeersRequestId = 0; - const auto push = [&]( - int count, - const QVector &list) { - auto slice = BlockedPeersSlice(); - slice.total = std::max(count, list.size()); - slice.list.reserve(list.size()); - for (const auto &contact : list) { - contact.match([&](const MTPDpeerBlocked &data) { - const auto peer = _session->data().peerLoaded( - peerFromMTP(data.vpeer_id())); - if (peer) { - peer->setIsBlocked(true); - slice.list.push_back({ peer, data.vdate().v }); - } - }); - } - if (!_blockedPeersSlice || *_blockedPeersSlice != slice) { - _blockedPeersSlice = slice; - _blockedPeersChanges.fire(std::move(slice)); - } - }; - result.match([&](const MTPDcontacts_blockedSlice &data) { - _session->data().processUsers(data.vusers()); - push(data.vcount().v, data.vblocked().v); - }, [&](const MTPDcontacts_blocked &data) { - _session->data().processUsers(data.vusers()); - push(0, data.vblocked().v); - }); - }).fail([=](const MTP::Error &error) { - _blockedPeersRequestId = 0; - }).send(); -} - -auto ApiWrap::blockedPeersSlice() -> rpl::producer { - if (!_blockedPeersSlice) { - reloadBlockedPeers(); - } - return _blockedPeersSlice - ? _blockedPeersChanges.events_starting_with_copy(*_blockedPeersSlice) - : (_blockedPeersChanges.events() | rpl::type_erased()); -} - Api::Authorizations &ApiWrap::authorizations() { return *_authorizations; } @@ -4858,6 +4730,10 @@ Api::AttachedStickers &ApiWrap::attachedStickers() { return *_attachedStickers; } +Api::BlockedPeers &ApiWrap::blockedPeers() { + return *_blockedPeers; +} + Api::SelfDestruct &ApiWrap::selfDestruct() { return *_selfDestruct; } diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index fe9fb4a79f..af88287134 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -58,6 +58,7 @@ namespace Api { class Updates; class Authorizations; class AttachedStickers; +class BlockedPeers; class SelfDestruct; class SensitiveContent; class GlobalPrivacy; @@ -114,22 +115,6 @@ public: using SendAction = Api::SendAction; using MessageToSend = Api::MessageToSend; - struct BlockedPeersSlice { - struct Item { - PeerData *peer = nullptr; - TimeId date = 0; - - bool operator==(const Item &other) const; - bool operator!=(const Item &other) const; - }; - - QVector list; - int total = 0; - - bool operator==(const BlockedPeersSlice &other) const; - bool operator!=(const BlockedPeersSlice &other) const; - }; - explicit ApiWrap(not_null session); ~ApiWrap(); @@ -272,9 +257,6 @@ public: void joinChannel(not_null channel); void leaveChannel(not_null channel); - void blockPeer(not_null peer); - void unblockPeer(not_null peer, Fn onDone = nullptr); - void requestNotifySettings(const MTPInputNotifyPeer &peer); void updateNotifySettingsDelayed(not_null peer); void saveDraftToCloudDelayed(not_null history); @@ -417,11 +399,9 @@ public: void saveSelfBio(const QString &text, FnMut done); - void reloadBlockedPeers(); - rpl::producer blockedPeersSlice(); - [[nodiscard]] Api::Authorizations &authorizations(); [[nodiscard]] Api::AttachedStickers &attachedStickers(); + [[nodiscard]] Api::BlockedPeers &blockedPeers(); [[nodiscard]] Api::SelfDestruct &selfDestruct(); [[nodiscard]] Api::SensitiveContent &sensitiveContent(); [[nodiscard]] Api::GlobalPrivacy &globalPrivacy(); @@ -641,7 +621,6 @@ private: QMap > _stickerSetRequests; QMap _channelAmInRequests; - base::flat_map, mtpRequestId> _blockRequests; base::flat_map _notifySettingRequests; base::flat_map, mtpRequestId> _draftsSaveRequestIds; base::Timer _draftsSaveTimer; @@ -736,12 +715,9 @@ private: FnMut _saveBioDone; QString _saveBioText; - mtpRequestId _blockedPeersRequestId = 0; - std::optional _blockedPeersSlice; - rpl::event_stream _blockedPeersChanges; - const std::unique_ptr _authorizations; const std::unique_ptr _attachedStickers; + const std::unique_ptr _blockedPeers; const std::unique_ptr _selfDestruct; const std::unique_ptr _sensitiveContent; const std::unique_ptr _globalPrivacy; diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp index ee9c02df6a..1df574ee63 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_controller.h" #include "window/window_session_controller.h" #include "apiwrap.h" +#include "api/api_blocked_peers.h" #include "main/main_session.h" #include "boxes/confirm_box.h" #include "boxes/peers/edit_contact_box.h" @@ -393,7 +394,7 @@ void ContactStatus::setupReportHandler(not_null peer) { _controller->showBackFromStack(); }); if (const auto user = peer->asUser()) { - peer->session().api().blockPeer(user); + peer->session().api().blockedPeers().block(user); } const auto text = ((peer->isChat() || peer->isMegagroup()) ? tr::lng_report_spam_sure_group diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 1c28c34c19..0f36d14f6d 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -48,6 +48,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/click_handler_types.h" #include "apiwrap.h" +#include "api/api_blocked_peers.h" #include "facades.h" #include "styles/style_info.h" #include "styles/style_boxes.h" @@ -647,7 +648,7 @@ void ActionsFiller::addBlockAction(not_null user) { Ui::showPeerHistory(user, ShowAtUnreadMsgId); } } else if (user->isBot()) { - user->session().api().blockPeer(user); + user->session().api().blockedPeers().block(user); } else { window->show(Box( Window::PeerMenuBlockUserBox, diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 4df730c03a..758c577223 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -48,8 +48,6 @@ namespace { using UserPrivacy = Api::UserPrivacy; using PrivacyRule = Api::UserPrivacy::Rule; -constexpr auto kBlockedPerPage = 40; - class BlockPeerBoxController final : public ChatsListBoxController { public: explicit BlockPeerBoxController(not_null session); @@ -180,8 +178,7 @@ AdminLog::OwnedItem GenerateForwardedItem( BlockedBoxController::BlockedBoxController( not_null window) -: _window(window) -, _api(&_window->session().mtp()) { +: _window(window) { } Main::Session &BlockedBoxController::session() const { @@ -199,52 +196,26 @@ void BlockedBoxController::prepare() { handleBlockedEvent(update.peer); }, lifetime()); - _loadRequestId = -1; - _window->session().api().blockedPeersSlice( + session().api().blockedPeers().slice( ) | rpl::take( 1 - ) | rpl::start_with_next([=](const ApiWrap::BlockedPeersSlice &result) { + ) | rpl::start_with_next([=](const Api::BlockedPeers::Slice &result) { setDescriptionText(tr::lng_blocked_list_about(tr::now)); - _loadRequestId = 0; - _offset = result.list.size(); - _allLoaded = (_offset >= result.total); - for (const auto item : result.list) { - appendRow(item.peer); - }; - delegate()->peerListRefreshRows(); + applySlice(result); loadMoreRows(); }, lifetime()); } void BlockedBoxController::loadMoreRows() { - if (_loadRequestId || _allLoaded) { + if (_allLoaded) { return; } - _loadRequestId = _api.request(MTPcontacts_GetBlocked( - MTP_int(_offset), - MTP_int(kBlockedPerPage) - )).done([=](const MTPcontacts_Blocked &result) { - _loadRequestId = 0; - - auto handleContactsBlocked = [&](auto &list) { - _window->session().data().processUsers(list.vusers()); - _window->session().data().processChats(list.vchats()); - return list.vblocked().v; - }; - switch (result.type()) { - case mtpc_contacts_blockedSlice: { - receivedPeers(handleContactsBlocked(result.c_contacts_blockedSlice())); - } break; - case mtpc_contacts_blocked: { - _allLoaded = true; - receivedPeers(handleContactsBlocked(result.c_contacts_blocked())); - } break; - default: Unexpected("Bad type() in MTPcontacts_GetBlocked() result."); - } - }).fail([this](const MTP::Error &error) { - _loadRequestId = 0; - }).send(); + session().api().blockedPeers().request( + _offset, + crl::guard(&_guard, [=](const Api::BlockedPeers::Slice &slice) { + applySlice(slice); + })); } void BlockedBoxController::rowClicked(not_null row) { @@ -255,23 +226,23 @@ void BlockedBoxController::rowClicked(not_null row) { } void BlockedBoxController::rowActionClicked(not_null row) { - _window->session().api().unblockPeer(row->peer()); + session().api().blockedPeers().unblock(row->peer()); } -void BlockedBoxController::receivedPeers( - const QVector &result) { - if (result.empty()) { +void BlockedBoxController::applySlice(const Api::BlockedPeers::Slice &slice) { + if (slice.list.empty()) { _allLoaded = true; } - _offset += result.size(); - for (const auto &item : result) { - item.match([&](const MTPDpeerBlocked &data) { - if (const auto peer = _window->session().data().peerLoaded(peerFromMTP(data.vpeer_id()))) { - appendRow(peer); - peer->setIsBlocked(true); - } - }); + _offset += slice.list.size(); + for (const auto &item : slice.list) { + if (const auto peer = session().data().peerLoaded(item.id)) { + appendRow(peer); + peer->setIsBlocked(true); + } + } + if (_offset >= slice.total) { + _allLoaded = true; } delegate()->peerListRefreshRows(); } @@ -295,7 +266,7 @@ void BlockedBoxController::BlockNewPeer( auto initBox = [=, controller = controller.get()]( not_null box) { controller->setBlockPeerCallback([=](not_null peer) { - window->session().api().blockPeer(peer); + window->session().api().blockedPeers().block(peer); box->closeBox(); }); box->addButton(tr::lng_cancel(), [box] { box->closeBox(); }); diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.h b/Telegram/SourceFiles/settings/settings_privacy_controllers.h index bfc6203097..ee2460ff7c 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.h +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.h @@ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peer_list_box.h" #include "boxes/edit_privacy_box.h" #include "history/view/history_view_element.h" -#include "mtproto/sender.h" +#include "api/api_blocked_peers.h" namespace Window { class SessionController; @@ -32,7 +32,7 @@ public: static void BlockNewPeer(not_null window); private: - void receivedPeers(const QVector &result); + void applySlice(const Api::BlockedPeers::Slice &slice); void handleBlockedEvent(not_null peer); bool appendRow(not_null peer); @@ -40,12 +40,12 @@ private: std::unique_ptr createRow(not_null peer) const; const not_null _window; - MTP::Sender _api; int _offset = 0; - mtpRequestId _loadRequestId = 0; bool _allLoaded = false; + base::has_weak_ptr _guard; + }; class PhoneNumberPrivacyController : public EditPrivacyController { diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index 2a2bc65910..7c13bf4587 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_privacy_security.h" #include "api/api_authorizations.h" +#include "api/api_blocked_peers.h" #include "api/api_self_destruct.h" #include "api/api_sensitive_content.h" #include "api/api_global_privacy.h" @@ -107,8 +108,8 @@ rpl::producer PrivacyString( } rpl::producer BlockedPeersCount(not_null<::Main::Session*> session) { - return session->api().blockedPeersSlice( - ) | rpl::map([=](const ApiWrap::BlockedPeersSlice &data) { + return session->api().blockedPeers().slice( + ) | rpl::map([](const Api::BlockedPeers::Slice &data) { return data.total; }); } @@ -148,7 +149,7 @@ void SetupPrivacy( std::move( updateTrigger ) | rpl::start_with_next([=] { - session->api().reloadBlockedPeers(); + session->api().blockedPeers().reload(); }, blockedPeers->lifetime()); using Key = Privacy::Key; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 78bfcd0233..8a1a867da1 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "mainwidget.h" #include "mainwindow.h" +#include "api/api_blocked_peers.h" #include "api/api_chat_filters.h" #include "api/api_updates.h" #include "mtproto/mtproto_config.h" @@ -428,7 +429,7 @@ void Filler::addBlockUser(not_null user) { if (user->isBlocked()) { PeerMenuUnblockUserWithBotRestart(user); } else if (user->isBot()) { - user->session().api().blockPeer(user); + user->session().api().blockedPeers().block(user); } else { window->show(Box( PeerMenuBlockUserBox, @@ -914,7 +915,7 @@ void PeerMenuBlockUserBox( peer->session().updates().applyUpdates(result); }).send(); } else { - peer->session().api().blockPeer(peer); + peer->session().api().blockedPeers().block(peer); if (reportChecked) { peer->session().api().request(MTPmessages_ReportSpam( peer->input @@ -938,7 +939,7 @@ void PeerMenuBlockUserBox( } void PeerMenuUnblockUserWithBotRestart(not_null user) { - user->session().api().unblockPeer(user, [=] { + user->session().api().blockedPeers().unblock(user, [=] { if (user->isBot() && !user->isSupport()) { user->session().api().sendBotStart(user); }