1
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-04-01 14:50:24 +00:00

Implement report spam from ContactStatus bar.

This commit is contained in:
John Preston 2019-06-10 16:58:45 +02:00
parent f49c7ba7ee
commit 213a8d888a
8 changed files with 121 additions and 106 deletions

View File

@ -1189,7 +1189,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_ban_user" = "Ban User";
"lng_delete_all_from" = "Delete all from this user";
"lng_report_spam" = "Report Spam";
"lng_report_spam_sure" = "Are you sure you want to report spam from this user?";
"lng_report_spam_and_leave" = "Report spam and leave";
"lng_report_spam_sure_group" = "Are you sure you want to report spam in this group?";
"lng_report_spam_sure_channel" = "Are you sure you want to report spam in this channel?";
"lng_report_spam_ok" = "Report";

View File

@ -1684,6 +1684,7 @@ void HistoryWidget::showHistory(
_canSendMessages = _peer->canWrite();
_tabbedSelector->setCurrentPeer(_peer);
_contactStatus = std::make_unique<HistoryView::ContactStatus>(
&controller()->window()->controller(),
this,
_peer);
_contactStatus->heightValue() | rpl::start_with_next([=] {

View File

@ -13,9 +13,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h"
#include "data/data_chat.h"
#include "data/data_channel.h"
#include "window/window_peer_menu.h"
#include "window/window_controller.h"
#include "window/window_session_controller.h"
#include "apiwrap.h"
#include "auth_session.h"
#include "boxes/confirm_box.h"
#include "styles/style_history.h"
#include "styles/style_boxes.h"
namespace HistoryView {
namespace {
@ -51,80 +56,13 @@ auto MapToEmpty() {
}
} // namespace
//
//void HistoryWidget::onReportSpamClicked() {
// auto text = lang(_peer->isUser() ? lng_report_spam_sure : ((_peer->isChat() || _peer->isMegagroup()) ? lng_report_spam_sure_group : lng_report_spam_sure_channel));
// Ui::show(Box<ConfirmBox>(text, lang(lng_report_spam_ok), st::attentionBoxButton, crl::guard(this, [this, peer = _peer] {
// if (_reportSpamRequest) return;
//
// Ui::hideLayer();
// _reportSpamRequest = MTP::send(
// MTPmessages_ReportSpam(peer->input),
// rpcDone(&HistoryWidget::reportSpamDone, peer),
// rpcFail(&HistoryWidget::reportSpamFail), 0, 5);
// if (const auto user = peer->asUser()) {
// session().api().blockUser(user);
// }
// })));
//}
//
//void HistoryWidget::reportSpamDone(PeerData *peer, const MTPBool &result, mtpRequestId req) {
// Expects(peer != nullptr);
//
// if (req == _reportSpamRequest) {
// _reportSpamRequest = 0;
// }
// cRefReportSpamStatuses().insert(peer->id, dbiprsReportSent);
// Local::writeReportSpamStatuses();
// if (_peer == peer) {
// setReportSpamStatus(dbiprsReportSent);
// if (_reportSpamPanel) {
// _reportSpamPanel->setReported(_reportSpamStatus == dbiprsReportSent, peer);
// }
// }
//}
//
//bool HistoryWidget::reportSpamFail(const RPCError &error, mtpRequestId req) {
// if (MTP::isDefaultHandledError(error)) return false;
//
// if (req == _reportSpamRequest) {
// _reportSpamRequest = 0;
// }
// return false;
//}
//
//void HistoryWidget::onReportSpamHide() {
// if (_peer) {
// cRefReportSpamStatuses().insert(_peer->id, dbiprsHidden);
// Local::writeReportSpamStatuses();
//
// MTP::send(MTPmessages_HidePeerSettingsBar(_peer->input));
// }
// setReportSpamStatus(dbiprsHidden);
// updateControlsVisibility();
//}
//
//void HistoryWidget::onReportSpamClear() {
// Expects(_peer != nullptr);
//
// InvokeQueued(App::main(), [peer = _peer] {
// Ui::showChatsList();
// if (const auto from = peer->migrateFrom()) {
// peer->session().api().deleteConversation(from, false);
// }
// peer->session().api().deleteConversation(peer, false);
// });
//
// // Invalidates _peer.
// controller()->showBackFromStack();
//}
ContactStatus::Bar::Bar(QWidget *parent, const QString &name)
: RpWidget(parent)
, _name(name)
, _add(
this,
lang(lng_new_contact_add).toUpper(),
QString(),
st::historyContactStatusButton)
, _block(
this,
@ -136,7 +74,7 @@ ContactStatus::Bar::Bar(QWidget *parent, const QString &name)
st::historyContactStatusButton)
, _report(
this,
lang(lng_report_spam).toUpper(),
lang(lng_report_spam_and_leave).toUpper(),
st::historyContactStatusBlock)
, _close(this, st::historyReplyCancel) {
resize(_close->size());
@ -152,6 +90,7 @@ void ContactStatus::Bar::showState(State state) {
: lang(lng_new_contact_add).toUpper());
updateButtonsGeometry();
}
rpl::producer<> ContactStatus::Bar::addClicks() const {
return _add->clicks() | MapToEmpty();
}
@ -241,9 +180,11 @@ void ContactStatus::Bar::updateButtonsGeometry() {
}
ContactStatus::ContactStatus(
not_null<Window::Controller*> window,
not_null<Ui::RpWidget*> parent,
not_null<PeerData*> peer)
: _bar(parent, object_ptr<Bar>(parent, PeerFirstName(peer)))
: _window(window)
, _bar(parent, object_ptr<Bar>(parent, PeerFirstName(peer)))
, _shadow(parent) {
setupWidgets(parent);
setupState(peer);
@ -333,23 +274,67 @@ void ContactStatus::setupState(not_null<PeerData*> peer) {
}
void ContactStatus::setupHandlers(not_null<PeerData*> peer) {
setupAddHandler(peer);
setupBlockHandler(peer);
setupShareHandler(peer);
if (const auto user = peer->asUser()) {
setupAddHandler(user);
setupBlockHandler(user);
setupShareHandler(user);
}
setupReportHandler(peer);
setupCloseHandler(peer);
}
void ContactStatus::setupAddHandler(not_null<PeerData*> peer) {
void ContactStatus::setupAddHandler(not_null<UserData*> peer) {
_bar.entity()->addClicks(
) | rpl::start_with_next([=] {
Expects(peer->isUser());
Window::PeerMenuAddContact(peer->asUser());
}, _bar.lifetime());
}
void ContactStatus::setupBlockHandler(not_null<PeerData*> peer) {
void ContactStatus::setupBlockHandler(not_null<UserData*> peer) {
}
void ContactStatus::setupShareHandler(not_null<PeerData*> peer) {
void ContactStatus::setupShareHandler(not_null<UserData*> peer) {
}
void ContactStatus::setupReportHandler(not_null<PeerData*> peer) {
_bar.entity()->reportClicks(
) | rpl::start_with_next([=] {
Expects(!peer->isUser());
const auto box = std::make_shared<QPointer<BoxContent>>();
const auto callback = crl::guard(&_bar, [=] {
if (*box) {
(*box)->closeBox();
}
peer->session().api().request(MTPmessages_ReportSpam(
peer->input
)).send();
crl::on_main(&peer->session(), [=] {
if (const auto from = peer->migrateFrom()) {
peer->session().api().deleteConversation(from, false);
}
peer->session().api().deleteConversation(peer, false);
});
// Destroys _bar.
_window->sessionController()->showBackFromStack();
});
if (const auto user = peer->asUser()) {
peer->session().api().blockUser(user);
}
const auto text = lang((peer->isChat() || peer->isMegagroup())
? lng_report_spam_sure_group
: lng_report_spam_sure_channel);
_window->show(Box<ConfirmBox>(
text,
lang(lng_report_spam_ok),
st::attentionBoxButton,
callback));
}, _bar.lifetime());
}
void ContactStatus::setupCloseHandler(not_null<PeerData*> peer) {

View File

@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/wrap/slide_wrap.h"
#include "ui/widgets/shadow.h"
namespace Window {
class Controller;
} // namespace Window
namespace Ui {
class FlatButton;
class IconButton;
@ -20,7 +24,10 @@ namespace HistoryView {
class ContactStatus final {
public:
ContactStatus(not_null<Ui::RpWidget*> parent, not_null<PeerData*> peer);
ContactStatus(
not_null<Window::Controller*> window,
not_null<Ui::RpWidget*> parent,
not_null<PeerData*> peer);
void show();
void raise();
@ -72,14 +79,15 @@ private:
void setupWidgets(not_null<Ui::RpWidget*> parent);
void setupState(not_null<PeerData*> peer);
void setupHandlers(not_null<PeerData*> peer);
void setupAddHandler(not_null<PeerData*> peer);
void setupBlockHandler(not_null<PeerData*> peer);
void setupShareHandler(not_null<PeerData*> peer);
void setupAddHandler(not_null<UserData*> peer);
void setupBlockHandler(not_null<UserData*> peer);
void setupShareHandler(not_null<UserData*> peer);
void setupReportHandler(not_null<PeerData*> peer);
void setupCloseHandler(not_null<PeerData*> peer);
static rpl::producer<State> PeerState(not_null<PeerData*> peer);
not_null<Window::Controller*> _window;
State _state = State::None;
Ui::SlideWrap<Bar> _bar;
Ui::PlainShadow _shadow;

View File

@ -154,10 +154,12 @@ rpl::producer<bool> CanShareContactValue(not_null<UserData*> user) {
rpl::producer<bool> CanAddContactValue(not_null<UserData*> user) {
using namespace rpl::mappers;
return rpl::combine(
IsContactValue(user),
CanShareContactValue(user),
!_1 && _2);
if (user->isBot() || user->isSelf()) {
return rpl::single(false);
}
return IsContactValue(
user
) | rpl::map(!_1);
}
rpl::producer<bool> AmInChannelValue(not_null<ChannelData*> channel) {

View File

@ -54,6 +54,13 @@ void Controller::showSettings() {
_widget.showSettings();
}
void Controller::showBox(
object_ptr<BoxContent> content,
LayerOptions options,
anim::type animated) {
_widget.ui_showBox(std::move(content), options, animated);
}
void Controller::activate() {
_widget.activate();
}

View File

@ -42,6 +42,16 @@ public:
void showSettings();
template <typename BoxType>
QPointer<BoxType> show(
object_ptr<BoxType> content,
LayerOptions options = LayerOption::KeepOther,
anim::type animated = anim::type::normal) {
const auto result = QPointer<BoxType>(content.data());
showBox(std::move(content), options, animated);
return result;
}
void activate();
void reActivate();
void updateIsActive(int timeout);
@ -53,6 +63,11 @@ public:
void tempDirDelete(int task);
private:
void showBox(
object_ptr<BoxContent> content,
LayerOptions options,
anim::type animated);
not_null<Main::Account*> _account;
::MainWindow _widget;
std::unique_ptr<SessionController> _sessionController;

View File

@ -360,31 +360,28 @@ void Filler::addUserActions(not_null<UserData*> user) {
Auth().supportHelper().editInfo(user);
});
}
if (user->isContact()) {
if (!user->isSelf()) {
_addAction(
lang(lng_info_share_contact),
[user] { PeerMenuShareContactBox(user); });
_addAction(
lang(lng_info_edit_contact),
[user] { Ui::show(Box<AddContactBox>(user)); });
_addAction(
lang(lng_info_delete_contact),
[user] { PeerMenuDeleteContact(user); });
}
} else if (user->canShareThisContact()) {
if (!user->isSelf()) {
_addAction(
lang(lng_info_add_as_contact),
[user] { PeerMenuAddContact(user); });
}
if (!user->isContact() && !user->isSelf() && !user->isBot()) {
_addAction(
lang(lng_info_add_as_contact),
[=] { PeerMenuAddContact(user); });
}
if (user->canShareThisContact()) {
_addAction(
lang(lng_info_share_contact),
[user] { PeerMenuShareContactBox(user); });
} else if (user->botInfo && !user->botInfo->cantJoinGroups) {
[=] { PeerMenuShareContactBox(user); });
}
if (user->isContact() && !user->isSelf()) {
_addAction(
lang(lng_info_edit_contact),
[=] { Ui::show(Box<AddContactBox>(user)); });
_addAction(
lang(lng_info_delete_contact),
[=] { PeerMenuDeleteContact(user); });
}
if (user->isBot() && !user->botInfo->cantJoinGroups) {
_addAction(
lang(lng_profile_invite_to_group),
[user] { AddBotToGroupBoxController::Start(user); });
[=] { AddBotToGroupBoxController::Start(user); });
}
if (user->canExportChatHistory()) {
_addAction(