2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "mainwidget.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "apiwrap.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/history_item.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2018-12-05 08:07:17 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2019-06-18 16:53:27 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2017-12-05 08:43:18 +00:00
|
|
|
#include "ui/empty_userpic.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "core/click_handler_types.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2019-08-08 22:39:42 +00:00
|
|
|
#include "data/data_scheduled_messages.h"
|
2018-01-19 17:10:58 +00:00
|
|
|
#include "data/data_session.h"
|
2019-03-22 14:19:43 +00:00
|
|
|
#include "data/data_photo.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_chat.h"
|
|
|
|
#include "data/data_user.h"
|
2019-12-05 08:32:33 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2020-02-21 10:29:48 +00:00
|
|
|
#include "data/data_histories.h"
|
2020-05-25 14:16:04 +00:00
|
|
|
#include "data/data_photo_media.h"
|
2020-06-12 12:12:34 +00:00
|
|
|
#include "data/data_changes.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2020-06-17 09:36:25 +00:00
|
|
|
#include "mtproto/mtproto_config.h"
|
|
|
|
#include "facades.h" // Ui::showChatsList
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "app.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
|
|
|
#include "styles/style_boxes.h"
|
2015-09-23 17:43:08 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtGui/QGuiApplication>
|
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
2020-03-26 08:10:35 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
TextParseOptions kInformBoxTextOptions = {
|
|
|
|
(TextParseLinks
|
|
|
|
| TextParseMultiline
|
|
|
|
| TextParseMarkdown
|
|
|
|
| TextParseRichText), // flags
|
2014-12-05 13:44:27 +00:00
|
|
|
0, // maxw
|
|
|
|
0, // maxh
|
|
|
|
Qt::LayoutDirectionAuto, // dir
|
|
|
|
};
|
|
|
|
|
2020-03-26 08:10:35 +00:00
|
|
|
TextParseOptions kMarkedTextBoxOptions = {
|
|
|
|
(TextParseLinks
|
|
|
|
| TextParseMultiline
|
|
|
|
| TextParseMarkdown
|
|
|
|
| TextParseRichText
|
|
|
|
| TextParseMentions
|
|
|
|
| TextParseHashtags), // flags
|
|
|
|
0, // maxw
|
|
|
|
0, // maxh
|
|
|
|
Qt::LayoutDirectionAuto, // dir
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
|
|
|
FnMut<void()> confirmedCallback,
|
|
|
|
FnMut<void()> cancelledCallback)
|
2019-06-19 15:09:03 +00:00
|
|
|
: _confirmText(tr::lng_box_ok(tr::now))
|
|
|
|
, _cancelText(tr::lng_cancel(tr::now))
|
2016-12-13 17:07:56 +00:00
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
2019-11-02 17:06:47 +00:00
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::defaultBox.buttonPadding.right())
|
2017-02-21 13:45:56 +00:00
|
|
|
, _confirmedCallback(std::move(confirmedCallback))
|
|
|
|
, _cancelledCallback(std::move(cancelledCallback)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
|
|
|
const QString &confirmText,
|
|
|
|
FnMut<void()> confirmedCallback,
|
|
|
|
FnMut<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(confirmText)
|
2019-06-19 15:09:03 +00:00
|
|
|
, _cancelText(tr::lng_cancel(tr::now))
|
2016-12-13 17:07:56 +00:00
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
2019-11-02 17:06:47 +00:00
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::defaultBox.buttonPadding.right())
|
2017-02-21 13:45:56 +00:00
|
|
|
, _confirmedCallback(std::move(confirmedCallback))
|
|
|
|
, _cancelledCallback(std::move(cancelledCallback)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
QWidget*,
|
|
|
|
const TextWithEntities &text,
|
|
|
|
const QString &confirmText,
|
|
|
|
FnMut<void()> confirmedCallback,
|
|
|
|
FnMut<void()> cancelledCallback)
|
2018-04-18 15:42:02 +00:00
|
|
|
: _confirmText(confirmText)
|
2019-06-19 15:09:03 +00:00
|
|
|
, _cancelText(tr::lng_cancel(tr::now))
|
2018-04-18 15:42:02 +00:00
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
2019-11-02 17:06:47 +00:00
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::defaultBox.buttonPadding.right())
|
2018-04-18 15:42:02 +00:00
|
|
|
, _confirmedCallback(std::move(confirmedCallback))
|
|
|
|
, _cancelledCallback(std::move(cancelledCallback)) {
|
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
|
|
|
const QString &confirmText,
|
|
|
|
const style::RoundButton &confirmStyle,
|
|
|
|
FnMut<void()> confirmedCallback,
|
|
|
|
FnMut<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(confirmText)
|
2019-06-19 15:09:03 +00:00
|
|
|
, _cancelText(tr::lng_cancel(tr::now))
|
2016-12-13 17:07:56 +00:00
|
|
|
, _confirmStyle(confirmStyle)
|
2019-11-02 17:06:47 +00:00
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::defaultBox.buttonPadding.right())
|
2017-02-21 13:45:56 +00:00
|
|
|
, _confirmedCallback(std::move(confirmedCallback))
|
|
|
|
, _cancelledCallback(std::move(cancelledCallback)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
|
|
|
const QString &confirmText,
|
|
|
|
const QString &cancelText,
|
|
|
|
FnMut<void()> confirmedCallback,
|
|
|
|
FnMut<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(confirmText)
|
|
|
|
, _cancelText(cancelText)
|
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
2019-11-02 17:06:47 +00:00
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::defaultBox.buttonPadding.right())
|
2017-02-21 13:45:56 +00:00
|
|
|
, _confirmedCallback(std::move(confirmedCallback))
|
|
|
|
, _cancelledCallback(std::move(cancelledCallback)) {
|
2014-12-05 13:44:27 +00:00
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
|
|
|
const QString &confirmText,
|
|
|
|
const style::RoundButton &confirmStyle,
|
|
|
|
const QString &cancelText,
|
|
|
|
FnMut<void()> confirmedCallback,
|
|
|
|
FnMut<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(confirmText)
|
|
|
|
, _cancelText(cancelText)
|
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
2019-11-02 17:06:47 +00:00
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::defaultBox.buttonPadding.right())
|
2017-02-21 13:45:56 +00:00
|
|
|
, _confirmedCallback(std::move(confirmedCallback))
|
|
|
|
, _cancelledCallback(std::move(cancelledCallback)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
const InformBoxTag &,
|
|
|
|
const QString &text,
|
|
|
|
const QString &doneText,
|
|
|
|
Fn<void()> closedCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(doneText)
|
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
2016-03-04 22:04:15 +00:00
|
|
|
, _informative(true)
|
2019-11-02 17:06:47 +00:00
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::defaultBox.buttonPadding.right())
|
2016-12-20 13:03:51 +00:00
|
|
|
, _confirmedCallback(generateInformCallback(closedCallback))
|
|
|
|
, _cancelledCallback(generateInformCallback(closedCallback)) {
|
2014-12-05 13:44:27 +00:00
|
|
|
init(text);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
ConfirmBox::ConfirmBox(
|
|
|
|
const InformBoxTag &,
|
|
|
|
const TextWithEntities &text,
|
|
|
|
const QString &doneText,
|
|
|
|
Fn<void()> closedCallback)
|
2018-04-18 15:42:02 +00:00
|
|
|
: _confirmText(doneText)
|
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
|
|
|
, _informative(true)
|
2019-11-02 17:06:47 +00:00
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::defaultBox.buttonPadding.right())
|
2018-04-18 15:42:02 +00:00
|
|
|
, _confirmedCallback(generateInformCallback(closedCallback))
|
|
|
|
, _cancelledCallback(generateInformCallback(closedCallback)) {
|
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2019-01-14 17:43:06 +00:00
|
|
|
FnMut<void()> ConfirmBox::generateInformCallback(
|
|
|
|
Fn<void()> closedCallback) {
|
|
|
|
return crl::guard(this, [=] {
|
2016-12-20 13:03:51 +00:00
|
|
|
closeBox();
|
2017-03-17 18:44:55 +00:00
|
|
|
if (closedCallback) {
|
|
|
|
closedCallback();
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-12-05 13:44:27 +00:00
|
|
|
void ConfirmBox::init(const QString &text) {
|
2019-01-14 17:43:06 +00:00
|
|
|
_text.setText(
|
|
|
|
st::boxLabelStyle,
|
|
|
|
text,
|
2020-03-26 08:10:35 +00:00
|
|
|
_informative ? kInformBoxTextOptions : _textPlainOptions);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 15:42:02 +00:00
|
|
|
void ConfirmBox::init(const TextWithEntities &text) {
|
2020-03-26 08:10:35 +00:00
|
|
|
_text.setMarkedText(st::boxLabelStyle, text, kMarkedTextBoxOptions);
|
2018-04-18 15:42:02 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConfirmBox::prepare() {
|
2019-01-14 17:43:06 +00:00
|
|
|
addButton(
|
2019-06-18 16:53:27 +00:00
|
|
|
rpl::single(_confirmText),
|
2019-01-14 17:43:06 +00:00
|
|
|
[=] { confirmed(); },
|
|
|
|
_confirmStyle);
|
2016-12-13 17:07:56 +00:00
|
|
|
if (!_informative) {
|
2019-01-14 17:43:06 +00:00
|
|
|
addButton(
|
2019-06-18 16:53:27 +00:00
|
|
|
rpl::single(_cancelText),
|
2019-01-14 17:43:06 +00:00
|
|
|
[=] { _cancelled = true; closeBox(); });
|
2016-08-12 15:22:11 +00:00
|
|
|
}
|
2018-03-29 19:49:31 +00:00
|
|
|
|
|
|
|
boxClosing() | rpl::start_with_next([=] {
|
2018-11-26 11:00:31 +00:00
|
|
|
if (!_confirmed && (!_strictCancel || _cancelled)) {
|
|
|
|
if (auto callback = std::move(_cancelledCallback)) {
|
|
|
|
callback();
|
|
|
|
}
|
2017-08-13 16:09:14 +00:00
|
|
|
}
|
2018-03-29 19:49:31 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
textUpdated();
|
2016-08-12 15:22:11 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 15:08:12 +00:00
|
|
|
void ConfirmBox::setMaxLineCount(int count) {
|
|
|
|
if (_maxLineCount != count) {
|
|
|
|
_maxLineCount = count;
|
|
|
|
textUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConfirmBox::textUpdated() {
|
2019-11-02 17:06:47 +00:00
|
|
|
_textWidth = st::boxWidth - st::boxPadding.left() - st::defaultBox.buttonPadding.right();
|
2018-05-30 15:08:12 +00:00
|
|
|
_textHeight = _text.countHeight(_textWidth);
|
|
|
|
if (_maxLineCount > 0) {
|
|
|
|
accumulate_min(_textHeight, _maxLineCount * st::boxLabelStyle.lineHeight);
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
setDimensions(st::boxWidth, st::boxPadding.top() + _textHeight + st::boxPadding.bottom());
|
2016-08-12 15:22:11 +00:00
|
|
|
|
|
|
|
setMouseTracking(_text.hasLinks());
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConfirmBox::confirmed() {
|
|
|
|
if (!_confirmed) {
|
|
|
|
_confirmed = true;
|
2018-11-26 11:00:31 +00:00
|
|
|
if (auto callback = std::move(_confirmedCallback)) {
|
|
|
|
callback();
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-12 18:01:32 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 13:44:27 +00:00
|
|
|
void ConfirmBox::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
updateHover();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::mousePressEvent(QMouseEvent *e) {
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
updateHover();
|
2016-03-29 17:17:00 +00:00
|
|
|
ClickHandler::pressed();
|
2016-12-13 17:07:56 +00:00
|
|
|
return BoxContent::mousePressEvent(e);
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
updateHover();
|
2018-11-26 11:00:31 +00:00
|
|
|
if (const auto activated = ClickHandler::unpressed()) {
|
2019-09-16 11:14:06 +00:00
|
|
|
const auto guard = window();
|
2015-12-07 18:09:05 +00:00
|
|
|
Ui::hideLayer();
|
2019-09-16 11:14:06 +00:00
|
|
|
ActivateClickHandler(guard, activated, e->button());
|
2018-11-26 11:00:31 +00:00
|
|
|
return;
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
2018-11-26 11:00:31 +00:00
|
|
|
BoxContent::mouseReleaseEvent(e);
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void ConfirmBox::leaveEventHook(QEvent *e) {
|
2016-03-29 17:17:00 +00:00
|
|
|
ClickHandler::clearActive(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
|
|
|
|
setCursor(active ? style::cur_pointer : style::cur_default);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
|
|
|
|
update();
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::updateLink() {
|
|
|
|
_lastMousePos = QCursor::pos();
|
|
|
|
updateHover();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::updateHover() {
|
2017-06-21 21:38:31 +00:00
|
|
|
auto m = mapFromGlobal(_lastMousePos);
|
|
|
|
auto state = _text.getStateLeft(m - QPoint(st::boxPadding.left(), st::boxPadding.top()), _textWidth, width());
|
2016-03-29 17:17:00 +00:00
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
ClickHandler::setActive(state.link, this);
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void ConfirmBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
2016-12-13 17:07:56 +00:00
|
|
|
confirmed();
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::keyPressEvent(e);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2016-11-19 14:47:28 +00:00
|
|
|
|
|
|
|
Painter p(this);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
// draw box title / text
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFg);
|
2018-05-30 15:08:12 +00:00
|
|
|
if (_maxLineCount > 0) {
|
|
|
|
_text.drawLeftElided(p, st::boxPadding.left(), st::boxPadding.top(), _textWidth, width(), _maxLineCount, style::al_left);
|
|
|
|
} else {
|
|
|
|
_text.drawLeft(p, st::boxPadding.left(), st::boxPadding.top(), _textWidth, width(), style::al_left);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 15:09:03 +00:00
|
|
|
InformBox::InformBox(QWidget*, const QString &text, Fn<void()> closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, tr::lng_box_ok(tr::now), std::move(closedCallback)) {
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
InformBox::InformBox(QWidget*, const QString &text, const QString &doneText, Fn<void()> closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, doneText, std::move(closedCallback)) {
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 15:09:03 +00:00
|
|
|
InformBox::InformBox(QWidget*, const TextWithEntities &text, Fn<void()> closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, tr::lng_box_ok(tr::now), std::move(closedCallback)) {
|
2018-04-18 15:42:02 +00:00
|
|
|
}
|
|
|
|
|
2018-06-04 18:18:52 +00:00
|
|
|
InformBox::InformBox(QWidget*, const TextWithEntities &text, const QString &doneText, Fn<void()> closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, doneText, std::move(closedCallback)) {
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
MaxInviteBox::MaxInviteBox(QWidget*, not_null<ChannelData*> channel) : BoxContent()
|
2017-07-14 12:28:08 +00:00
|
|
|
, _channel(channel)
|
2020-03-26 08:10:35 +00:00
|
|
|
, _text(
|
|
|
|
st::boxLabelStyle,
|
|
|
|
tr::lng_participant_invite_sorry(
|
|
|
|
tr::now,
|
|
|
|
lt_count,
|
2020-06-17 09:36:25 +00:00
|
|
|
channel->session().serverConfig().chatSizeMax),
|
2020-03-26 08:10:35 +00:00
|
|
|
kInformBoxTextOptions,
|
|
|
|
(st::boxWidth
|
|
|
|
- st::boxPadding.left()
|
|
|
|
- st::defaultBox.buttonPadding.right())) {
|
2016-09-15 19:15:49 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void MaxInviteBox::prepare() {
|
2015-09-23 17:43:08 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_box_ok(), [=] { closeBox(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2019-11-02 17:06:47 +00:00
|
|
|
_textWidth = st::boxWidth - st::boxPadding.left() - st::defaultBox.buttonPadding.right();
|
2016-12-31 15:19:22 +00:00
|
|
|
_textHeight = qMin(_text.countHeight(_textWidth), 16 * st::boxLabelStyle.lineHeight);
|
2016-12-13 17:07:56 +00:00
|
|
|
setDimensions(st::boxWidth, st::boxPadding.top() + _textHeight + st::boxTextFont->height + st::boxTextFont->height * 2 + st::newGroupLinkPadding.bottom());
|
2017-07-14 12:28:08 +00:00
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
_channel->session().changes().peerUpdates(
|
|
|
|
_channel,
|
|
|
|
Data::PeerUpdate::Flag::InviteLink
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
rtlupdate(_invitationLink);
|
|
|
|
}, lifetime());
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MaxInviteBox::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
updateSelected(e->globalPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaxInviteBox::mousePressEvent(QMouseEvent *e) {
|
|
|
|
mouseMoveEvent(e);
|
|
|
|
if (_linkOver) {
|
2017-07-14 12:28:08 +00:00
|
|
|
if (_channel->inviteLink().isEmpty()) {
|
2019-01-14 17:43:06 +00:00
|
|
|
_channel->session().api().exportInviteLink(_channel);
|
2017-07-14 12:28:08 +00:00
|
|
|
} else {
|
|
|
|
QGuiApplication::clipboard()->setText(_channel->inviteLink());
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::Toast::Show(tr::lng_create_channel_link_copied(tr::now));
|
2017-07-14 12:28:08 +00:00
|
|
|
}
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void MaxInviteBox::leaveEventHook(QEvent *e) {
|
2015-09-23 17:43:08 +00:00
|
|
|
updateSelected(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaxInviteBox::updateSelected(const QPoint &cursorGlobalPosition) {
|
|
|
|
QPoint p(mapFromGlobal(cursorGlobalPosition));
|
|
|
|
|
|
|
|
bool linkOver = _invitationLink.contains(p);
|
|
|
|
if (linkOver != _linkOver) {
|
|
|
|
_linkOver = linkOver;
|
|
|
|
update();
|
|
|
|
setCursor(_linkOver ? style::cur_pointer : style::cur_default);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaxInviteBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2016-11-19 14:47:28 +00:00
|
|
|
|
2015-09-23 17:43:08 +00:00
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
// draw box title / text
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFg);
|
2015-10-14 11:51:37 +00:00
|
|
|
_text.drawLeftElided(p, st::boxPadding.left(), st::boxPadding.top(), _textWidth, width(), 16, style::al_left);
|
2015-09-23 17:43:08 +00:00
|
|
|
|
|
|
|
QTextOption option(style::al_left);
|
|
|
|
option.setWrapMode(QTextOption::WrapAnywhere);
|
2015-10-12 21:02:10 +00:00
|
|
|
p.setFont(_linkOver ? st::defaultInputField.font->underline() : st::defaultInputField.font);
|
2016-11-11 13:46:04 +00:00
|
|
|
p.setPen(st::defaultLinkButton.color);
|
2019-06-19 15:09:03 +00:00
|
|
|
auto inviteLinkText = _channel->inviteLink().isEmpty() ? tr::lng_group_invite_create(tr::now) : _channel->inviteLink();
|
2017-07-14 12:28:08 +00:00
|
|
|
p.drawText(_invitationLink, inviteLinkText, option);
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MaxInviteBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
2015-10-11 08:37:24 +00:00
|
|
|
_invitationLink = myrtlrect(st::boxPadding.left(), st::boxPadding.top() + _textHeight + st::boxTextFont->height, width() - st::boxPadding.left() - st::boxPadding.right(), 2 * st::boxTextFont->height);
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
2016-03-04 22:04:15 +00:00
|
|
|
|
2018-10-31 11:29:14 +00:00
|
|
|
PinMessageBox::PinMessageBox(
|
|
|
|
QWidget*,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
MsgId msgId)
|
|
|
|
: _peer(peer)
|
2020-06-17 09:36:25 +00:00
|
|
|
, _api(&peer->session().mtp())
|
2016-03-10 10:15:21 +00:00
|
|
|
, _msgId(msgId)
|
2019-06-19 15:09:03 +00:00
|
|
|
, _text(this, tr::lng_pinned_pin_sure(tr::now), st::boxLabel) {
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PinMessageBox::prepare() {
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_pinned_pin(), [this] { pinMessage(); });
|
|
|
|
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2018-10-31 11:29:14 +00:00
|
|
|
if (_peer->isChat() || _peer->isMegagroup()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_notify.create(this, tr::lng_pinned_notify(tr::now), true, st::defaultBoxCheckbox);
|
2017-11-21 13:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto height = st::boxPadding.top() + _text->height() + st::boxPadding.bottom();
|
|
|
|
if (_notify) {
|
|
|
|
height += st::boxMediumSkip + _notify->heightNoMargins();
|
|
|
|
}
|
|
|
|
setDimensions(st::boxWidth, height);
|
2016-03-10 10:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PinMessageBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
2016-10-28 09:20:24 +00:00
|
|
|
_text->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
|
2017-11-21 13:23:56 +00:00
|
|
|
if (_notify) {
|
|
|
|
_notify->moveToLeft(st::boxPadding.left(), _text->y() + _text->height() + st::boxMediumSkip);
|
|
|
|
}
|
2016-03-10 10:15:21 +00:00
|
|
|
}
|
|
|
|
|
2017-01-02 17:11:49 +00:00
|
|
|
void PinMessageBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
|
|
|
pinMessage();
|
|
|
|
} else {
|
|
|
|
BoxContent::keyPressEvent(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void PinMessageBox::pinMessage() {
|
2016-03-10 10:15:21 +00:00
|
|
|
if (_requestId) return;
|
|
|
|
|
2018-10-31 11:29:14 +00:00
|
|
|
auto flags = MTPmessages_UpdatePinnedMessage::Flags(0);
|
2017-11-21 13:23:56 +00:00
|
|
|
if (_notify && !_notify->checked()) {
|
2018-10-31 11:29:14 +00:00
|
|
|
flags |= MTPmessages_UpdatePinnedMessage::Flag::f_silent;
|
2016-03-19 16:55:15 +00:00
|
|
|
}
|
2020-06-11 16:09:46 +00:00
|
|
|
_requestId = _api.request(MTPmessages_UpdatePinnedMessage(
|
|
|
|
MTP_flags(flags),
|
|
|
|
_peer->input,
|
|
|
|
MTP_int(_msgId)
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
_peer->session().api().applyUpdates(result);
|
|
|
|
Ui::hideLayer();
|
|
|
|
}).fail([=](const RPCError &error) {
|
|
|
|
Ui::hideLayer();
|
|
|
|
}).send();
|
2016-03-10 10:15:21 +00:00
|
|
|
}
|
2016-03-10 15:42:01 +00:00
|
|
|
|
2017-11-24 16:28:14 +00:00
|
|
|
DeleteMessagesBox::DeleteMessagesBox(
|
|
|
|
QWidget*,
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
bool suggestModerateActions)
|
2019-07-24 14:00:30 +00:00
|
|
|
: _session(&item->history()->session())
|
|
|
|
, _ids(1, item->fullId()) {
|
2017-06-04 11:09:29 +00:00
|
|
|
if (suggestModerateActions) {
|
|
|
|
_moderateBan = item->suggestBanReport();
|
|
|
|
_moderateDeleteAll = item->suggestDeleteAllReport();
|
|
|
|
if (_moderateBan || _moderateDeleteAll) {
|
|
|
|
_moderateFrom = item->from()->asUser();
|
|
|
|
_moderateInChannel = item->history()->peer->asChannel();
|
|
|
|
}
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-24 16:28:14 +00:00
|
|
|
DeleteMessagesBox::DeleteMessagesBox(
|
|
|
|
QWidget*,
|
2019-07-24 14:00:30 +00:00
|
|
|
not_null<Main::Session*> session,
|
2017-12-06 10:13:38 +00:00
|
|
|
MessageIdsList &&selected)
|
2019-07-24 14:00:30 +00:00
|
|
|
: _session(session)
|
|
|
|
, _ids(std::move(selected)) {
|
2017-11-24 16:28:14 +00:00
|
|
|
Expects(!_ids.empty());
|
|
|
|
}
|
|
|
|
|
2019-03-21 13:48:40 +00:00
|
|
|
DeleteMessagesBox::DeleteMessagesBox(
|
|
|
|
QWidget*,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
bool justClear)
|
2019-07-24 14:00:30 +00:00
|
|
|
: _session(&peer->session())
|
|
|
|
, _wipeHistoryPeer(peer)
|
2019-03-21 13:48:40 +00:00
|
|
|
, _wipeHistoryJustClear(justClear) {
|
|
|
|
}
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
void DeleteMessagesBox::prepare() {
|
2019-03-21 12:49:27 +00:00
|
|
|
auto details = TextWithEntities();
|
|
|
|
const auto appendDetails = [&](TextWithEntities &&text) {
|
2019-04-08 15:10:06 +00:00
|
|
|
details.append(qstr("\n\n")).append(std::move(text));
|
2019-03-21 12:49:27 +00:00
|
|
|
};
|
2019-06-18 16:53:27 +00:00
|
|
|
auto deleteText = tr::lng_box_delete();
|
2019-03-21 13:48:40 +00:00
|
|
|
auto deleteStyle = &st::defaultBoxButton;
|
|
|
|
if (const auto peer = _wipeHistoryPeer) {
|
|
|
|
if (_wipeHistoryJustClear) {
|
|
|
|
details.text = peer->isSelf()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_sure_delete_saved_messages(tr::now)
|
2019-03-21 13:48:40 +00:00
|
|
|
: peer->isUser()
|
2019-06-19 16:39:25 +00:00
|
|
|
? tr::lng_sure_delete_history(tr::now, lt_contact, peer->name)
|
|
|
|
: tr::lng_sure_delete_group_history(tr::now, lt_group, peer->name);
|
2019-03-21 13:48:40 +00:00
|
|
|
deleteStyle = &st::attentionBoxButton;
|
|
|
|
} else {
|
|
|
|
details.text = peer->isSelf()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_sure_delete_saved_messages(tr::now)
|
2019-03-21 13:48:40 +00:00
|
|
|
: peer->isUser()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_sure_delete_history(tr::now, lt_contact, peer->name)
|
2019-03-21 13:48:40 +00:00
|
|
|
: peer->isChat()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_sure_delete_and_exit(tr::now, lt_group, peer->name)
|
|
|
|
: peer->isMegagroup()
|
|
|
|
? tr::lng_sure_leave_group(tr::now)
|
|
|
|
: tr::lng_sure_leave_channel(tr::now);
|
2019-06-18 16:53:27 +00:00
|
|
|
deleteText = _wipeHistoryPeer->isUser()
|
|
|
|
? tr::lng_box_delete()
|
|
|
|
: tr::lng_box_leave();
|
2019-03-21 13:48:40 +00:00
|
|
|
deleteStyle = &(peer->isChannel()
|
|
|
|
? st::defaultBoxButton
|
|
|
|
: st::attentionBoxButton);
|
|
|
|
}
|
|
|
|
if (auto revoke = revokeText(peer)) {
|
|
|
|
_revoke.create(this, revoke->checkbox, false, st::defaultBoxCheckbox);
|
|
|
|
appendDetails(std::move(revoke->description));
|
|
|
|
}
|
|
|
|
} else if (_moderateFrom) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(_moderateInChannel != nullptr);
|
2019-06-18 16:53:27 +00:00
|
|
|
|
2019-06-19 15:09:03 +00:00
|
|
|
details.text = tr::lng_selected_delete_sure_this(tr::now);
|
2017-06-04 11:09:29 +00:00
|
|
|
if (_moderateBan) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_banUser.create(this, tr::lng_ban_user(tr::now), false, st::defaultBoxCheckbox);
|
2017-06-04 11:09:29 +00:00
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
_reportSpam.create(this, tr::lng_report_spam(tr::now), false, st::defaultBoxCheckbox);
|
2017-06-04 11:09:29 +00:00
|
|
|
if (_moderateDeleteAll) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_deleteAll.create(this, tr::lng_delete_all_from(tr::now), false, st::defaultBoxCheckbox);
|
2017-06-04 11:09:29 +00:00
|
|
|
}
|
2016-12-31 15:19:22 +00:00
|
|
|
} else {
|
2019-03-21 12:49:27 +00:00
|
|
|
details.text = (_ids.size() == 1)
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_selected_delete_sure_this(tr::now)
|
2019-06-19 16:39:25 +00:00
|
|
|
: tr::lng_selected_delete_sure(tr::now, lt_count, _ids.size());
|
2019-03-20 13:02:02 +00:00
|
|
|
if (const auto peer = checkFromSinglePeer()) {
|
|
|
|
auto count = int(_ids.size());
|
2019-08-16 15:08:51 +00:00
|
|
|
if (hasScheduledMessages()) {
|
|
|
|
} else if (auto revoke = revokeText(peer)) {
|
2019-03-21 12:49:27 +00:00
|
|
|
_revoke.create(this, revoke->checkbox, false, st::defaultBoxCheckbox);
|
|
|
|
appendDetails(std::move(revoke->description));
|
2019-08-16 15:08:51 +00:00
|
|
|
} else if (peer->isChannel()) {
|
2019-03-20 13:02:02 +00:00
|
|
|
if (peer->isMegagroup()) {
|
2019-06-19 16:39:25 +00:00
|
|
|
appendDetails({ tr::lng_delete_for_everyone_hint(tr::now, lt_count, count) });
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
2019-03-20 13:02:02 +00:00
|
|
|
} else if (peer->isChat()) {
|
2019-06-19 16:39:25 +00:00
|
|
|
appendDetails({ tr::lng_delete_for_me_chat_hint(tr::now, lt_count, count) });
|
2019-03-20 13:02:02 +00:00
|
|
|
} else if (!peer->isSelf()) {
|
2019-06-19 16:39:25 +00:00
|
|
|
appendDetails({ tr::lng_delete_for_me_hint(tr::now, lt_count, count) });
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-21 12:49:27 +00:00
|
|
|
_text.create(this, rpl::single(std::move(details)), st::boxLabel);
|
2016-03-13 15:45:00 +00:00
|
|
|
|
2019-03-21 13:48:40 +00:00
|
|
|
addButton(
|
2019-06-18 16:53:27 +00:00
|
|
|
std::move(deleteText),
|
2019-03-21 13:48:40 +00:00
|
|
|
[=] { deleteAndClear(); },
|
|
|
|
*deleteStyle);
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2016-03-10 15:42:01 +00:00
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
auto fullHeight = st::boxPadding.top() + _text->height() + st::boxPadding.bottom();
|
|
|
|
if (_moderateFrom) {
|
2017-06-04 11:09:29 +00:00
|
|
|
fullHeight += st::boxMediumSkip;
|
|
|
|
if (_banUser) {
|
|
|
|
fullHeight += _banUser->heightNoMargins() + st::boxLittleSkip;
|
|
|
|
}
|
|
|
|
fullHeight += _reportSpam->heightNoMargins();
|
|
|
|
if (_deleteAll) {
|
|
|
|
fullHeight += st::boxLittleSkip + _deleteAll->heightNoMargins();
|
|
|
|
}
|
2019-03-20 13:02:02 +00:00
|
|
|
} else if (_revoke) {
|
|
|
|
fullHeight += st::boxMediumSkip + _revoke->heightNoMargins();
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
|
|
|
setDimensions(st::boxWidth, fullHeight);
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 15:08:51 +00:00
|
|
|
bool DeleteMessagesBox::hasScheduledMessages() const {
|
|
|
|
for (const auto fullId : std::as_const(_ids)) {
|
|
|
|
if (const auto item = _session->data().message(fullId)) {
|
|
|
|
if (item->isScheduled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-20 13:02:02 +00:00
|
|
|
PeerData *DeleteMessagesBox::checkFromSinglePeer() const {
|
|
|
|
auto result = (PeerData*)nullptr;
|
|
|
|
for (const auto fullId : std::as_const(_ids)) {
|
2019-07-24 14:00:30 +00:00
|
|
|
if (const auto item = _session->data().message(fullId)) {
|
2019-03-20 13:02:02 +00:00
|
|
|
const auto peer = item->history()->peer;
|
|
|
|
if (!result) {
|
|
|
|
result = peer;
|
|
|
|
} else if (result != peer) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-03-21 12:49:27 +00:00
|
|
|
auto DeleteMessagesBox::revokeText(not_null<PeerData*> peer) const
|
|
|
|
-> std::optional<RevokeConfig> {
|
2019-03-21 13:48:40 +00:00
|
|
|
auto result = RevokeConfig();
|
|
|
|
if (peer == _wipeHistoryPeer) {
|
|
|
|
if (!peer->canRevokeFullHistory()) {
|
|
|
|
return std::nullopt;
|
|
|
|
} else if (const auto user = peer->asUser()) {
|
2019-06-19 16:39:25 +00:00
|
|
|
result.checkbox = tr::lng_delete_for_other_check(
|
|
|
|
tr::now,
|
2019-03-21 13:48:40 +00:00
|
|
|
lt_user,
|
|
|
|
user->firstName);
|
|
|
|
} else {
|
2019-06-19 15:09:03 +00:00
|
|
|
result.checkbox = tr::lng_delete_for_everyone_check(tr::now);
|
2019-03-21 13:48:40 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-03-20 13:02:02 +00:00
|
|
|
const auto items = ranges::view::all(
|
|
|
|
_ids
|
2019-04-25 12:45:15 +00:00
|
|
|
) | ranges::view::transform([&](FullMsgId id) {
|
|
|
|
return peer->owner().message(id);
|
2019-03-20 13:02:02 +00:00
|
|
|
}) | ranges::view::filter([](HistoryItem *item) {
|
|
|
|
return (item != nullptr);
|
|
|
|
}) | ranges::to_vector;
|
2019-03-21 13:48:40 +00:00
|
|
|
|
2019-03-20 13:02:02 +00:00
|
|
|
if (items.size() != _ids.size()) {
|
|
|
|
// We don't have information about all messages.
|
2019-03-21 12:49:27 +00:00
|
|
|
return std::nullopt;
|
2019-03-20 13:02:02 +00:00
|
|
|
}
|
|
|
|
|
2019-07-10 17:28:33 +00:00
|
|
|
const auto now = base::unixtime::now();
|
2019-03-21 12:49:27 +00:00
|
|
|
const auto canRevoke = [&](HistoryItem * item) {
|
|
|
|
return item->canDeleteForEveryone(now);
|
|
|
|
};
|
2019-03-20 13:02:02 +00:00
|
|
|
const auto cannotRevoke = [&](HistoryItem *item) {
|
|
|
|
return !item->canDeleteForEveryone(now);
|
|
|
|
};
|
|
|
|
const auto canRevokeAll = ranges::find_if(
|
|
|
|
items,
|
|
|
|
cannotRevoke
|
|
|
|
) == end(items);
|
|
|
|
auto outgoing = items | ranges::view::filter(&HistoryItem::out);
|
2019-03-21 12:49:27 +00:00
|
|
|
const auto canRevokeOutgoingCount = canRevokeAll
|
|
|
|
? -1
|
|
|
|
: ranges::count_if(outgoing, canRevoke);
|
2019-03-20 13:02:02 +00:00
|
|
|
|
2019-03-21 12:49:27 +00:00
|
|
|
if (canRevokeAll) {
|
2019-03-21 13:48:40 +00:00
|
|
|
if (const auto user = peer->asUser()) {
|
2019-06-19 16:39:25 +00:00
|
|
|
result.checkbox = tr::lng_delete_for_other_check(
|
|
|
|
tr::now,
|
2019-03-20 13:02:02 +00:00
|
|
|
lt_user,
|
2019-03-21 13:48:40 +00:00
|
|
|
user->firstName);
|
|
|
|
} else {
|
2019-06-18 16:53:27 +00:00
|
|
|
result.checkbox = tr::lng_delete_for_everyone_check(tr::now);
|
2019-03-21 13:48:40 +00:00
|
|
|
}
|
2019-03-21 12:49:27 +00:00
|
|
|
return result;
|
|
|
|
} else if (canRevokeOutgoingCount > 0) {
|
2019-06-18 16:53:27 +00:00
|
|
|
result.checkbox = tr::lng_delete_for_other_my(tr::now);
|
2019-03-21 12:49:27 +00:00
|
|
|
if (const auto user = peer->asUser()) {
|
|
|
|
if (canRevokeOutgoingCount == 1) {
|
2019-06-18 16:53:27 +00:00
|
|
|
result.description = tr::lng_selected_unsend_about_user_one(
|
|
|
|
tr::now,
|
2019-03-21 12:49:27 +00:00
|
|
|
lt_user,
|
2019-06-18 16:53:27 +00:00
|
|
|
Ui::Text::Bold(user->shortName()),
|
|
|
|
Ui::Text::WithEntities);
|
2019-03-21 12:49:27 +00:00
|
|
|
} else {
|
2019-06-18 16:53:27 +00:00
|
|
|
result.description = tr::lng_selected_unsend_about_user(
|
|
|
|
tr::now,
|
2019-03-21 12:49:27 +00:00
|
|
|
lt_count,
|
|
|
|
canRevokeOutgoingCount,
|
|
|
|
lt_user,
|
2019-06-18 16:53:27 +00:00
|
|
|
Ui::Text::Bold(user->shortName()),
|
|
|
|
Ui::Text::WithEntities);
|
2019-03-21 12:49:27 +00:00
|
|
|
}
|
|
|
|
} else if (canRevokeOutgoingCount == 1) {
|
2019-06-18 16:53:27 +00:00
|
|
|
result.description = tr::lng_selected_unsend_about_group_one(
|
|
|
|
tr::now,
|
|
|
|
Ui::Text::WithEntities);
|
2019-03-21 12:49:27 +00:00
|
|
|
} else {
|
2019-06-18 16:53:27 +00:00
|
|
|
result.description = tr::lng_selected_unsend_about_group(
|
|
|
|
tr::now,
|
|
|
|
lt_count,
|
|
|
|
canRevokeOutgoingCount,
|
|
|
|
Ui::Text::WithEntities);
|
2019-03-21 12:49:27 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return std::nullopt;
|
2019-03-20 13:02:02 +00:00
|
|
|
}
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
void DeleteMessagesBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
2017-11-24 16:28:14 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
_text->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
|
2016-12-31 15:19:22 +00:00
|
|
|
if (_moderateFrom) {
|
2017-06-04 11:09:29 +00:00
|
|
|
auto top = _text->bottomNoMargins() + st::boxMediumSkip;
|
|
|
|
if (_banUser) {
|
|
|
|
_banUser->moveToLeft(st::boxPadding.left(), top);
|
|
|
|
top += _banUser->heightNoMargins() + st::boxLittleSkip;
|
|
|
|
}
|
|
|
|
_reportSpam->moveToLeft(st::boxPadding.left(), top);
|
|
|
|
top += _reportSpam->heightNoMargins() + st::boxLittleSkip;
|
|
|
|
if (_deleteAll) {
|
|
|
|
_deleteAll->moveToLeft(st::boxPadding.left(), top);
|
|
|
|
}
|
2019-03-20 13:02:02 +00:00
|
|
|
} else if (_revoke) {
|
|
|
|
const auto availableWidth = width() - 2 * st::boxPadding.left();
|
|
|
|
_revoke->resizeToNaturalWidth(availableWidth);
|
|
|
|
_revoke->moveToLeft(st::boxPadding.left(), _text->bottomNoMargins() + st::boxMediumSkip);
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
|
|
|
|
2017-01-02 17:11:49 +00:00
|
|
|
void DeleteMessagesBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
|
|
|
deleteAndClear();
|
|
|
|
} else {
|
|
|
|
BoxContent::keyPressEvent(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
void DeleteMessagesBox::deleteAndClear() {
|
2019-03-21 13:48:40 +00:00
|
|
|
const auto revoke = _revoke ? _revoke->checked() : false;
|
|
|
|
if (const auto peer = _wipeHistoryPeer) {
|
|
|
|
const auto justClear = _wipeHistoryJustClear;
|
|
|
|
closeBox();
|
|
|
|
|
|
|
|
if (justClear) {
|
|
|
|
peer->session().api().clearHistory(peer, revoke);
|
|
|
|
} else {
|
2019-06-06 10:21:40 +00:00
|
|
|
const auto controller = App::wnd()->sessionController();
|
2019-03-21 13:48:40 +00:00
|
|
|
if (controller->activeChatCurrent().peer() == peer) {
|
|
|
|
Ui::showChatsList();
|
|
|
|
}
|
|
|
|
// Don't delete old history by default,
|
|
|
|
// because Android app doesn't.
|
|
|
|
//
|
|
|
|
//if (const auto from = peer->migrateFrom()) {
|
|
|
|
// peer->session().api().deleteConversation(from, false);
|
|
|
|
//}
|
|
|
|
peer->session().api().deleteConversation(peer, revoke);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2016-12-31 15:19:22 +00:00
|
|
|
if (_moderateFrom) {
|
2017-06-04 11:09:29 +00:00
|
|
|
if (_banUser && _banUser->checked()) {
|
2019-01-14 17:43:06 +00:00
|
|
|
_moderateInChannel->session().api().kickParticipant(
|
2017-12-26 16:12:10 +00:00
|
|
|
_moderateInChannel,
|
|
|
|
_moderateFrom,
|
2019-01-03 14:39:19 +00:00
|
|
|
MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
|
|
|
if (_reportSpam->checked()) {
|
2019-01-14 17:43:06 +00:00
|
|
|
_moderateInChannel->session().api().request(
|
2017-12-26 16:12:10 +00:00
|
|
|
MTPchannels_ReportSpam(
|
|
|
|
_moderateInChannel->inputChannel,
|
|
|
|
_moderateFrom->inputUser,
|
2019-01-14 17:43:06 +00:00
|
|
|
MTP_vector<MTPint>(1, MTP_int(_ids[0].msg)))
|
|
|
|
).send();
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
2017-06-04 11:09:29 +00:00
|
|
|
if (_deleteAll && _deleteAll->checked()) {
|
2019-01-14 17:43:06 +00:00
|
|
|
_moderateInChannel->session().api().deleteAllFromUser(
|
2017-12-26 16:12:10 +00:00
|
|
|
_moderateInChannel,
|
|
|
|
_moderateFrom);
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
2016-12-31 15:19:22 +00:00
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
if (_deleteConfirmedCallback) {
|
|
|
|
_deleteConfirmedCallback();
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
2016-12-31 15:19:22 +00:00
|
|
|
|
2020-02-20 08:51:53 +00:00
|
|
|
auto remove = std::vector<not_null<HistoryItem*>>();
|
|
|
|
remove.reserve(_ids.size());
|
2020-02-21 10:29:48 +00:00
|
|
|
base::flat_map<not_null<History*>, QVector<MTPint>> idsByPeer;
|
2019-08-08 22:39:42 +00:00
|
|
|
base::flat_map<not_null<PeerData*>, QVector<MTPint>> scheduledIdsByPeer;
|
2018-01-26 15:40:11 +00:00
|
|
|
for (const auto itemId : _ids) {
|
2019-07-24 14:00:30 +00:00
|
|
|
if (const auto item = _session->data().message(itemId)) {
|
2019-01-15 11:57:45 +00:00
|
|
|
const auto history = item->history();
|
2019-08-08 22:39:42 +00:00
|
|
|
if (item->isScheduled()) {
|
2019-08-12 16:33:36 +00:00
|
|
|
const auto wasOnServer = !item->isSending()
|
|
|
|
&& !item->hasFailed();
|
|
|
|
if (wasOnServer) {
|
|
|
|
scheduledIdsByPeer[history->peer].push_back(MTP_int(
|
|
|
|
_session->data().scheduledMessages().lookupId(item)));
|
|
|
|
} else {
|
|
|
|
_session->data().scheduledMessages().removeSending(item);
|
|
|
|
}
|
2019-08-08 22:39:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-02-20 08:51:53 +00:00
|
|
|
remove.push_back(item);
|
|
|
|
if (IsServerMsgId(item->id)) {
|
2020-02-21 10:29:48 +00:00
|
|
|
idsByPeer[history].push_back(MTP_int(itemId.msg));
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
2016-03-11 11:13:28 +00:00
|
|
|
}
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
2016-12-31 15:19:22 +00:00
|
|
|
|
2020-02-21 10:29:48 +00:00
|
|
|
for (const auto &[history, ids] : idsByPeer) {
|
|
|
|
history->owner().histories().deleteMessages(history, ids, revoke);
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
2019-08-08 22:39:42 +00:00
|
|
|
for (const auto &[peer, ids] : scheduledIdsByPeer) {
|
|
|
|
peer->session().api().request(MTPmessages_DeleteScheduledMessages(
|
|
|
|
peer->input,
|
|
|
|
MTP_vector<MTPint>(ids)
|
2020-06-11 16:09:46 +00:00
|
|
|
)).done([peer=peer](const MTPUpdates &result) {
|
|
|
|
peer->session().api().applyUpdates(result);
|
2019-08-08 22:39:42 +00:00
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2020-02-20 08:51:53 +00:00
|
|
|
for (const auto item : remove) {
|
|
|
|
const auto history = item->history();
|
|
|
|
const auto wasLast = (history->lastMessage() == item);
|
|
|
|
const auto wasInChats = (history->chatListMessage() == item);
|
|
|
|
item->destroy();
|
|
|
|
|
|
|
|
if (wasLast || wasInChats) {
|
|
|
|
history->requestChatListMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto session = _session;
|
2016-03-13 15:45:00 +00:00
|
|
|
Ui::hideLayer();
|
2019-07-24 14:00:30 +00:00
|
|
|
session->data().sendHistoryChangeNotifications();
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
ConfirmInviteBox::ConfirmInviteBox(
|
|
|
|
QWidget*,
|
2019-07-24 14:00:30 +00:00
|
|
|
not_null<Main::Session*> session,
|
2018-11-26 11:55:02 +00:00
|
|
|
const MTPDchatInvite &data,
|
|
|
|
Fn<void()> submit)
|
2019-07-24 14:00:30 +00:00
|
|
|
: _session(session)
|
|
|
|
, _submit(std::move(submit))
|
2018-11-26 11:55:02 +00:00
|
|
|
, _title(this, st::confirmInviteTitle)
|
2016-07-08 16:59:46 +00:00
|
|
|
, _status(this, st::confirmInviteStatus)
|
2019-07-24 14:00:30 +00:00
|
|
|
, _participants(GetParticipants(_session, data))
|
2018-11-26 11:55:02 +00:00
|
|
|
, _isChannel(data.is_channel() && !data.is_megagroup()) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto title = qs(data.vtitle());
|
|
|
|
const auto count = data.vparticipants_count().v;
|
2018-11-26 11:55:02 +00:00
|
|
|
const auto status = [&] {
|
2019-06-19 15:09:03 +00:00
|
|
|
return (!_participants.empty() && _participants.size() < count)
|
|
|
|
? tr::lng_group_invite_members(tr::now, lt_count, count)
|
|
|
|
: (count > 0)
|
|
|
|
? tr::lng_chat_status_members(tr::now, lt_count_decimal, count)
|
|
|
|
: _isChannel
|
|
|
|
? tr::lng_channel_status(tr::now)
|
|
|
|
: tr::lng_group_status(tr::now);
|
2018-11-26 11:55:02 +00:00
|
|
|
}();
|
|
|
|
_title->setText(title);
|
2016-07-08 16:59:46 +00:00
|
|
|
_status->setText(status);
|
2019-03-22 14:19:43 +00:00
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto photo = _session->data().processPhoto(data.vphoto());
|
2019-03-22 14:19:43 +00:00
|
|
|
if (!photo->isNull()) {
|
2020-05-25 14:16:04 +00:00
|
|
|
_photo = photo->createMediaView();
|
|
|
|
_photo->wanted(Data::PhotoSize::Small, Data::FileOrigin());
|
|
|
|
if (!_photo->image(Data::PhotoSize::Small)) {
|
2019-07-24 14:00:30 +00:00
|
|
|
subscribe(_session->downloaderTaskFinished(), [=] {
|
2019-03-22 14:19:43 +00:00
|
|
|
update();
|
|
|
|
});
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
2019-03-22 14:19:43 +00:00
|
|
|
} else {
|
2017-12-05 08:43:18 +00:00
|
|
|
_photoEmpty = std::make_unique<Ui::EmptyUserpic>(
|
|
|
|
Data::PeerUserpicColor(0),
|
|
|
|
title);
|
2016-12-29 09:03:51 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
auto ConfirmInviteBox::GetParticipants(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const MTPDchatInvite &data)
|
|
|
|
-> std::vector<Participant> {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto participants = data.vparticipants();
|
|
|
|
if (!participants) {
|
2018-11-26 11:55:02 +00:00
|
|
|
return {};
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto &v = participants->v;
|
2020-05-28 14:32:10 +00:00
|
|
|
auto result = std::vector<Participant>();
|
2018-11-26 11:55:02 +00:00
|
|
|
result.reserve(v.size());
|
|
|
|
for (const auto &participant : v) {
|
2019-07-24 14:00:30 +00:00
|
|
|
if (const auto user = session->data().processUser(participant)) {
|
2020-05-28 14:32:10 +00:00
|
|
|
result.push_back(Participant{ user });
|
2018-11-26 11:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConfirmInviteBox::prepare() {
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(
|
|
|
|
(_isChannel
|
|
|
|
? tr::lng_profile_join_channel()
|
|
|
|
: tr::lng_profile_join_group()),
|
|
|
|
_submit);
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2018-11-26 11:55:02 +00:00
|
|
|
while (_participants.size() > 4) {
|
|
|
|
_participants.pop_back();
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto newHeight = st::confirmInviteStatusTop + _status->height() + st::boxPadding.bottom();
|
2018-11-26 11:55:02 +00:00
|
|
|
if (!_participants.empty()) {
|
2016-12-20 13:03:51 +00:00
|
|
|
int skip = (st::boxWideWidth - 4 * st::confirmInviteUserPhotoSize) / 5;
|
2016-07-08 16:59:46 +00:00
|
|
|
int padding = skip / 2;
|
|
|
|
_userWidth = (st::confirmInviteUserPhotoSize + 2 * padding);
|
|
|
|
int sumWidth = _participants.size() * _userWidth;
|
2016-12-20 13:03:51 +00:00
|
|
|
int left = (st::boxWideWidth - sumWidth) / 2;
|
2020-05-28 14:32:10 +00:00
|
|
|
for (const auto &participant : _participants) {
|
2016-11-16 10:44:06 +00:00
|
|
|
auto name = new Ui::FlatLabel(this, st::confirmInviteUserName);
|
2016-07-08 16:59:46 +00:00
|
|
|
name->resizeToWidth(st::confirmInviteUserPhotoSize + padding);
|
2020-05-28 14:32:10 +00:00
|
|
|
name->setText(participant.user->firstName.isEmpty()
|
|
|
|
? participant.user->name
|
|
|
|
: participant.user->firstName);
|
2016-07-08 16:59:46 +00:00
|
|
|
name->moveToLeft(left + (padding / 2), st::confirmInviteUserNameTop);
|
|
|
|
left += _userWidth;
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += st::confirmInviteUserHeight;
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
setDimensions(st::boxWideWidth, newHeight);
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmInviteBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
2016-07-08 16:59:46 +00:00
|
|
|
_title->move((width() - _title->width()) / 2, st::confirmInviteTitleTop);
|
|
|
|
_status->move((width() - _status->width()) / 2, st::confirmInviteStatusTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmInviteBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2016-11-19 14:47:28 +00:00
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
Painter p(this);
|
|
|
|
|
2016-12-29 09:03:51 +00:00
|
|
|
if (_photo) {
|
2020-05-25 14:16:04 +00:00
|
|
|
if (const auto image = _photo->image(Data::PhotoSize::Small)) {
|
|
|
|
p.drawPixmap(
|
|
|
|
(width() - st::confirmInvitePhotoSize) / 2,
|
|
|
|
st::confirmInvitePhotoTop,
|
|
|
|
image->pixCircled(
|
|
|
|
st::confirmInvitePhotoSize,
|
|
|
|
st::confirmInvitePhotoSize));
|
|
|
|
}
|
|
|
|
} else if (_photoEmpty) {
|
2018-07-13 21:25:47 +00:00
|
|
|
_photoEmpty->paint(
|
|
|
|
p,
|
|
|
|
(width() - st::confirmInvitePhotoSize) / 2,
|
|
|
|
st::confirmInvitePhotoTop,
|
|
|
|
width(),
|
|
|
|
st::confirmInvitePhotoSize);
|
2016-12-29 09:03:51 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
|
|
|
|
int sumWidth = _participants.size() * _userWidth;
|
|
|
|
int left = (width() - sumWidth) / 2;
|
2020-05-28 14:32:10 +00:00
|
|
|
for (auto &participant : _participants) {
|
|
|
|
participant.user->paintUserpicLeft(
|
2018-07-13 21:25:47 +00:00
|
|
|
p,
|
2020-05-28 14:32:10 +00:00
|
|
|
participant.userpic,
|
2018-07-13 21:25:47 +00:00
|
|
|
left + (_userWidth - st::confirmInviteUserPhotoSize) / 2,
|
|
|
|
st::confirmInviteUserPhotoTop,
|
|
|
|
width(),
|
|
|
|
st::confirmInviteUserPhotoSize);
|
2016-07-08 16:59:46 +00:00
|
|
|
left += _userWidth;
|
|
|
|
}
|
|
|
|
}
|
2017-12-05 08:43:18 +00:00
|
|
|
|
|
|
|
ConfirmInviteBox::~ConfirmInviteBox() = default;
|
2018-12-05 08:07:17 +00:00
|
|
|
|
|
|
|
ConfirmDontWarnBox::ConfirmDontWarnBox(
|
|
|
|
QWidget*,
|
2019-06-12 20:11:41 +00:00
|
|
|
rpl::producer<TextWithEntities> text,
|
2018-12-05 08:07:17 +00:00
|
|
|
const QString &checkbox,
|
2019-06-18 16:53:27 +00:00
|
|
|
rpl::producer<QString> confirm,
|
2018-12-05 08:07:17 +00:00
|
|
|
FnMut<void(bool)> callback)
|
2019-06-18 16:53:27 +00:00
|
|
|
: _confirm(std::move(confirm))
|
2019-06-12 20:11:41 +00:00
|
|
|
, _content(setupContent(std::move(text), checkbox, std::move(callback))) {
|
2018-12-05 08:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmDontWarnBox::prepare() {
|
|
|
|
setDimensionsToContent(st::boxWidth, _content);
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(std::move(_confirm), [=] { _callback(); });
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2018-12-05 08:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Ui::RpWidget*> ConfirmDontWarnBox::setupContent(
|
2019-06-12 20:11:41 +00:00
|
|
|
rpl::producer<TextWithEntities> text,
|
2018-12-05 08:07:17 +00:00
|
|
|
const QString &checkbox,
|
|
|
|
FnMut<void(bool)> callback) {
|
|
|
|
const auto result = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
result->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
result,
|
2019-06-12 20:11:41 +00:00
|
|
|
std::move(text),
|
2018-12-05 08:07:17 +00:00
|
|
|
st::boxLabel),
|
|
|
|
st::boxPadding);
|
|
|
|
const auto control = result->add(
|
|
|
|
object_ptr<Ui::Checkbox>(
|
|
|
|
result,
|
|
|
|
checkbox,
|
|
|
|
false,
|
|
|
|
st::defaultBoxCheckbox),
|
|
|
|
style::margins(
|
|
|
|
st::boxPadding.left(),
|
|
|
|
st::boxPadding.bottom(),
|
|
|
|
st::boxPadding.right(),
|
|
|
|
st::boxPadding.bottom()));
|
|
|
|
_callback = [=, callback = std::move(callback)]() mutable {
|
|
|
|
const auto checked = control->checked();
|
|
|
|
auto local = std::move(callback);
|
|
|
|
closeBox();
|
|
|
|
local(checked);
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
}
|