mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-30 22:16:14 +00:00
Allow reporting / banning from reactions in groups.
This commit is contained in:
@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "info/profile/info_profile_actions.h"
|
||||
|
||||
#include "api/api_chat_participants.h"
|
||||
#include "base/options.h"
|
||||
#include "data/data_peer_values.h"
|
||||
#include "data/data_session.h"
|
||||
@@ -14,12 +15,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_forum_topic.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_chat.h"
|
||||
#include "data/data_user.h"
|
||||
#include "data/notify/data_notify_settings.h"
|
||||
#include "ui/vertical_list.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/shadow.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
@@ -44,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "info/profile/info_profile_phone_menu.h"
|
||||
#include "info/profile/info_profile_values.h"
|
||||
#include "info/profile/info_profile_text.h"
|
||||
#include "info/profile/info_profile_widget.h"
|
||||
#include "support/support_helper.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "window/window_controller.h" // Window::Controller::show.
|
||||
@@ -56,6 +60,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "apiwrap.h"
|
||||
#include "api/api_blocked_peers.h"
|
||||
#include "styles/style_info.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
|
||||
@@ -190,14 +195,15 @@ template <typename Text, typename ToggleOn, typename Callback>
|
||||
Text &&text,
|
||||
ToggleOn &&toggleOn,
|
||||
Callback &&callback,
|
||||
Ui::MultiSlideTracker &tracker) {
|
||||
Ui::MultiSlideTracker &tracker,
|
||||
const style::SettingsButton &st = st::infoMainButton) {
|
||||
tracker.track(AddActionButton(
|
||||
parent,
|
||||
std::move(text) | Ui::Text::ToUpper(),
|
||||
std::move(toggleOn),
|
||||
std::move(callback),
|
||||
nullptr,
|
||||
st::infoMainButton));
|
||||
st));
|
||||
}
|
||||
|
||||
class DetailsFiller {
|
||||
@@ -205,7 +211,8 @@ public:
|
||||
DetailsFiller(
|
||||
not_null<Controller*> controller,
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<PeerData*> peer);
|
||||
not_null<PeerData*> peer,
|
||||
Origin origin);
|
||||
DetailsFiller(
|
||||
not_null<Controller*> controller,
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
@@ -223,6 +230,12 @@ private:
|
||||
Ui::MultiSlideTracker fillChannelButtons(
|
||||
not_null<ChannelData*> channel);
|
||||
|
||||
void addReportReaction(Ui::MultiSlideTracker &tracker);
|
||||
void addReportReaction(
|
||||
GroupReactionOrigin data,
|
||||
bool ban,
|
||||
Ui::MultiSlideTracker &tracker);
|
||||
|
||||
template <
|
||||
typename Widget,
|
||||
typename = std::enable_if_t<
|
||||
@@ -239,6 +252,7 @@ private:
|
||||
not_null<Ui::RpWidget*> _parent;
|
||||
not_null<PeerData*> _peer;
|
||||
Data::ForumTopic *_topic = nullptr;
|
||||
Origin _origin;
|
||||
object_ptr<Ui::VerticalLayout> _wrap;
|
||||
|
||||
};
|
||||
@@ -272,13 +286,65 @@ private:
|
||||
|
||||
};
|
||||
|
||||
void ReportReactionBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<PeerData*> participant,
|
||||
GroupReactionOrigin data,
|
||||
bool ban,
|
||||
Fn<void()> sent) {
|
||||
box->setTitle(tr::lng_report_reaction_title());
|
||||
box->addRow(object_ptr<Ui::FlatLabel>(
|
||||
box,
|
||||
tr::lng_report_reaction_about(),
|
||||
st::boxLabel));
|
||||
const auto check = ban
|
||||
? box->addRow(
|
||||
object_ptr<Ui::Checkbox>(
|
||||
box,
|
||||
tr::lng_report_and_ban_button(tr::now),
|
||||
true),
|
||||
st::boxRowPadding + QMargins{ 0, st::boxLittleSkip, 0, 0 })
|
||||
: nullptr;
|
||||
box->addButton(tr::lng_report_button(), [=] {
|
||||
const auto chat = data.group->asChat();
|
||||
const auto channel = data.group->asMegagroup();
|
||||
if (check && check->checked()) {
|
||||
if (chat) {
|
||||
chat->session().api().chatParticipants().kick(
|
||||
chat,
|
||||
participant);
|
||||
} else if (channel) {
|
||||
channel->session().api().chatParticipants().kick(
|
||||
channel,
|
||||
participant,
|
||||
ChatRestrictionsInfo());
|
||||
}
|
||||
}
|
||||
data.group->session().api().request(MTPmessages_ReportReaction(
|
||||
data.group->input,
|
||||
MTP_int(data.messageId.bare),
|
||||
participant->input
|
||||
)).done(crl::guard(controller, [=] {
|
||||
controller->showToast(tr::lng_report_thanks(tr::now));
|
||||
})).send();
|
||||
sent();
|
||||
box->closeBox();
|
||||
}, st::attentionBoxButton);
|
||||
box->addButton(tr::lng_cancel(), [=] {
|
||||
box->closeBox();
|
||||
});
|
||||
}
|
||||
|
||||
DetailsFiller::DetailsFiller(
|
||||
not_null<Controller*> controller,
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<PeerData*> peer)
|
||||
not_null<PeerData*> peer,
|
||||
Origin origin)
|
||||
: _controller(controller)
|
||||
, _parent(parent)
|
||||
, _peer(peer)
|
||||
, _origin(origin)
|
||||
, _wrap(_parent) {
|
||||
}
|
||||
|
||||
@@ -653,6 +719,58 @@ void DetailsFiller::setupMainButtons() {
|
||||
}
|
||||
}
|
||||
|
||||
void DetailsFiller::addReportReaction(Ui::MultiSlideTracker &tracker) {
|
||||
v::match(_origin.data, [&](GroupReactionOrigin data) {
|
||||
const auto user = _peer->asUser();
|
||||
if (_peer->isSelf()) {
|
||||
return;
|
||||
} else if (const auto chat = data.group->asChat()) {
|
||||
const auto ban = chat->canBanMembers()
|
||||
&& (!user || !chat->admins.contains(_peer))
|
||||
&& (!user || chat->creator != user->id);
|
||||
addReportReaction(data, ban, tracker);
|
||||
} else if (const auto channel = data.group->asMegagroup()) {
|
||||
const auto ban = channel->canBanMembers()
|
||||
&& (!user || !channel->mgInfo->admins.contains(user->id))
|
||||
&& (!user || channel->mgInfo->creator != user);
|
||||
addReportReaction(data, ban, tracker);
|
||||
}
|
||||
}, [](const auto &) {});
|
||||
}
|
||||
|
||||
void DetailsFiller::addReportReaction(
|
||||
GroupReactionOrigin data,
|
||||
bool ban,
|
||||
Ui::MultiSlideTracker &tracker) {
|
||||
const auto peer = _peer;
|
||||
if (!peer) {
|
||||
return;
|
||||
}
|
||||
const auto controller = _controller->parentController();
|
||||
const auto forceHidden = std::make_shared<rpl::variable<bool>>(false);
|
||||
const auto user = peer->asUser();
|
||||
auto shown = user
|
||||
? rpl::combine(
|
||||
Info::Profile::IsContactValue(user),
|
||||
forceHidden->value(),
|
||||
!rpl::mappers::_1 && !rpl::mappers::_2
|
||||
) | rpl::type_erased()
|
||||
: (forceHidden->value() | rpl::map(!rpl::mappers::_1));
|
||||
const auto sent = [=] {
|
||||
*forceHidden = true;
|
||||
};
|
||||
AddMainButton(
|
||||
_wrap,
|
||||
(ban
|
||||
? tr::lng_report_and_ban()
|
||||
: tr::lng_report_reaction()),
|
||||
std::move(shown),
|
||||
[=] { controller->show(
|
||||
Box(ReportReactionBox, controller, peer, data, ban, sent)); },
|
||||
tracker,
|
||||
st::infoMainButtonAttention);
|
||||
}
|
||||
|
||||
Ui::MultiSlideTracker DetailsFiller::fillTopicButtons() {
|
||||
using namespace rpl::mappers;
|
||||
|
||||
@@ -719,6 +837,9 @@ Ui::MultiSlideTracker DetailsFiller::fillUserButtons(
|
||||
} else {
|
||||
addSendMessageButton();
|
||||
}
|
||||
|
||||
addReportReaction(tracker);
|
||||
|
||||
return tracker;
|
||||
}
|
||||
|
||||
@@ -1055,8 +1176,9 @@ const char kOptionShowPeerIdBelowAbout[] = "show-peer-id-below-about";
|
||||
object_ptr<Ui::RpWidget> SetupDetails(
|
||||
not_null<Controller*> controller,
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<PeerData*> peer) {
|
||||
DetailsFiller filler(controller, parent, peer);
|
||||
not_null<PeerData*> peer,
|
||||
Origin origin) {
|
||||
DetailsFiller filler(controller, parent, peer, origin);
|
||||
return filler.fill();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user