Fix blocking users in channel direct messages.

Fixes #29549.
This commit is contained in:
John Preston 2025-07-14 17:15:25 +04:00
parent 01e313e56b
commit e62881e08b

View file

@ -361,9 +361,14 @@ void CreateModerateMessagesBox(
}); });
} }
if (allCanBan) { if (allCanBan) {
auto ownedWrap = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>( const auto peer = items.front()->history()->peer;
auto ownedWrap = peer->isMonoforum()
? nullptr
: object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
inner, inner,
object_ptr<Ui::VerticalLayout>(inner)); object_ptr<Ui::VerticalLayout>(inner));
auto computeRestrictions = Fn<ChatRestrictions()>();
const auto wrap = ownedWrap.data();
Ui::AddSkip(inner); Ui::AddSkip(inner);
Ui::AddSkip(inner); Ui::AddSkip(inner);
@ -371,7 +376,9 @@ void CreateModerateMessagesBox(
object_ptr<Ui::Checkbox>( object_ptr<Ui::Checkbox>(
box, box,
rpl::conditional( rpl::conditional(
ownedWrap->toggledValue(), (ownedWrap
? ownedWrap->toggledValue()
: rpl::single(false)),
tr::lng_restrict_user( tr::lng_restrict_user(
lt_count, lt_count,
rpl::single(participants.size()) | tr::to_count()), rpl::single(participants.size()) | tr::to_count()),
@ -390,7 +397,9 @@ void CreateModerateMessagesBox(
Ui::AddSkip(inner); Ui::AddSkip(inner);
Ui::AddSkip(inner); Ui::AddSkip(inner);
const auto wrap = inner->add(std::move(ownedWrap)); if (ownedWrap) {
inner->add(std::move(ownedWrap));
const auto container = wrap->entity(); const auto container = wrap->entity();
wrap->toggle(false, anim::type::instant); wrap->toggle(false, anim::type::instant);
@ -468,7 +477,6 @@ void CreateModerateMessagesBox(
using Flag = ChatRestriction; using Flag = ChatRestriction;
using Flags = ChatRestrictions; using Flags = ChatRestrictions;
const auto peer = items.front()->history()->peer;
const auto chat = peer->asChat(); const auto chat = peer->asChat();
const auto channel = peer->asChannel(); const auto channel = peer->asChannel();
const auto defaultRestrictions = chat const auto defaultRestrictions = chat
@ -507,6 +515,7 @@ void CreateModerateMessagesBox(
prepareFlags, prepareFlags,
disabledMessages, disabledMessages,
{ .isForum = peer->isForum() }); { .isForum = peer->isForum() });
computeRestrictions = getRestrictions;
std::move(changes) | rpl::start_with_next([=] { std::move(changes) | rpl::start_with_next([=] {
ban->setChecked(true); ban->setChecked(true);
}, ban->lifetime()); }, ban->lifetime());
@ -514,12 +523,15 @@ void CreateModerateMessagesBox(
Ui::AddDivider(container); Ui::AddDivider(container);
Ui::AddSkip(container); Ui::AddSkip(container);
container->add(std::move(checkboxes)); container->add(std::move(checkboxes));
}
// Handle confirmation manually. // Handle confirmation manually.
confirms->events() | rpl::start_with_next([=] { confirms->events() | rpl::start_with_next([=] {
if (ban->checked() && controller->collectRequests) { if (ban->checked() && controller->collectRequests) {
const auto kick = !wrap->toggled(); const auto kick = !wrap || !wrap->toggled();
const auto restrictions = getRestrictions(); const auto restrictions = computeRestrictions
? computeRestrictions()
: ChatRestrictions();
const auto request = [=]( const auto request = [=](
not_null<PeerData*> peer, not_null<PeerData*> peer,
not_null<ChannelData*> channel) { not_null<ChannelData*> channel) {
@ -532,10 +544,15 @@ void CreateModerateMessagesBox(
nullptr, nullptr,
nullptr); nullptr);
} else { } else {
channel->session().api().chatParticipants().kick( const auto block = channel->isMonoforum()
channel, ? channel->monoforumBroadcast()
: channel.get();
if (block) {
block->session().api().chatParticipants().kick(
block,
peer, peer,
{ channel->restrictions(), 0 }); { block->restrictions(), 0 });
}
} }
}; };
sequentiallyRequest(request, controller->collectRequests()); sequentiallyRequest(request, controller->collectRequests());