mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Moved MTP blocked peers from ApiWrap to Api::BlockedPeers.
This commit is contained in:
@@ -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<Main::Session*> session);
|
||||
@@ -180,8 +178,7 @@ AdminLog::OwnedItem GenerateForwardedItem(
|
||||
|
||||
BlockedBoxController::BlockedBoxController(
|
||||
not_null<Window::SessionController*> 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<PeerListRow*> row) {
|
||||
@@ -255,23 +226,23 @@ void BlockedBoxController::rowClicked(not_null<PeerListRow*> row) {
|
||||
}
|
||||
|
||||
void BlockedBoxController::rowActionClicked(not_null<PeerListRow*> row) {
|
||||
_window->session().api().unblockPeer(row->peer());
|
||||
session().api().blockedPeers().unblock(row->peer());
|
||||
}
|
||||
|
||||
void BlockedBoxController::receivedPeers(
|
||||
const QVector<MTPPeerBlocked> &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<PeerListBox*> box) {
|
||||
controller->setBlockPeerCallback([=](not_null<PeerData*> peer) {
|
||||
window->session().api().blockPeer(peer);
|
||||
window->session().api().blockedPeers().block(peer);
|
||||
box->closeBox();
|
||||
});
|
||||
box->addButton(tr::lng_cancel(), [box] { box->closeBox(); });
|
||||
|
Reference in New Issue
Block a user