2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2016-09-15 19:15:49 +00:00
|
|
|
#include "boxes/confirmbox.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-08 14:43:10 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2016-09-15 19:15:49 +00:00
|
|
|
#include "lang.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"
|
2015-09-23 17:43:08 +00:00
|
|
|
#include "application.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"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "core/click_handler_types.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "auth_session.h"
|
2015-09-23 17:43:08 +00:00
|
|
|
|
2014-12-05 13:44:27 +00:00
|
|
|
TextParseOptions _confirmBoxTextOptions = {
|
|
|
|
TextParseLinks | TextParseMultiline | TextParseRichText, // flags
|
|
|
|
0, // maxw
|
|
|
|
0, // maxh
|
|
|
|
Qt::LayoutDirectionAuto, // dir
|
|
|
|
};
|
|
|
|
|
2017-03-17 18:44:55 +00:00
|
|
|
ConfirmBox::ConfirmBox(QWidget*, const QString &text, base::lambda_once<void()> confirmedCallback, base::lambda_once<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(lang(lng_box_ok))
|
|
|
|
, _cancelText(lang(lng_cancel))
|
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.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);
|
|
|
|
}
|
|
|
|
|
2017-03-17 18:44:55 +00:00
|
|
|
ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, base::lambda_once<void()> confirmedCallback, base::lambda_once<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(confirmText)
|
|
|
|
, _cancelText(lang(lng_cancel))
|
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.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);
|
|
|
|
}
|
|
|
|
|
2017-03-17 18:44:55 +00:00
|
|
|
ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, base::lambda_once<void()> confirmedCallback, base::lambda_once<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(confirmText)
|
|
|
|
, _cancelText(lang(lng_cancel))
|
|
|
|
, _confirmStyle(confirmStyle)
|
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.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);
|
|
|
|
}
|
|
|
|
|
2017-03-17 18:44:55 +00:00
|
|
|
ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, base::lambda_once<void()> confirmedCallback, base::lambda_once<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(confirmText)
|
|
|
|
, _cancelText(cancelText)
|
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.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);
|
|
|
|
}
|
|
|
|
|
2017-03-17 18:44:55 +00:00
|
|
|
ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, base::lambda_once<void()> confirmedCallback, base::lambda_once<void()> cancelledCallback)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _confirmText(confirmText)
|
|
|
|
, _cancelText(cancelText)
|
|
|
|
, _confirmStyle(st::defaultBoxButton)
|
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.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);
|
|
|
|
}
|
|
|
|
|
2017-02-26 11:32:13 +00:00
|
|
|
ConfirmBox::ConfirmBox(const InformBoxTag &, const QString &text, const QString &doneText, base::lambda<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)
|
2016-12-13 17:07:56 +00:00
|
|
|
, _text(st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.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
|
|
|
|
2017-03-17 18:44:55 +00:00
|
|
|
base::lambda_once<void()> ConfirmBox::generateInformCallback(base::lambda<void()> closedCallback) {
|
|
|
|
return base::lambda_guarded(this, [this, closedCallback] {
|
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) {
|
2016-12-31 15:19:22 +00:00
|
|
|
_text.setText(st::boxLabelStyle, text, _informative ? _confirmBoxTextOptions : _textPlainOptions);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConfirmBox::prepare() {
|
|
|
|
addButton(_confirmText, [this] { confirmed(); }, _confirmStyle);
|
|
|
|
if (!_informative) {
|
|
|
|
addButton(_cancelText, [this] { _cancelled = true; closeBox(); });
|
2016-08-12 15:22:11 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
textUpdated();
|
2016-08-12 15:22:11 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConfirmBox::textUpdated() {
|
2016-08-12 15:22:11 +00:00
|
|
|
_textWidth = st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.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::boxPadding.bottom());
|
2016-08-12 15:22:11 +00:00
|
|
|
|
|
|
|
setMouseTracking(_text.hasLinks());
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConfirmBox::closeHook() {
|
|
|
|
if (!_confirmed && (!_strictCancel || _cancelled) && _cancelledCallback) {
|
|
|
|
_cancelledCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::confirmed() {
|
|
|
|
if (!_confirmed) {
|
|
|
|
_confirmed = true;
|
|
|
|
if (_confirmedCallback) {
|
|
|
|
_confirmedCallback();
|
|
|
|
}
|
|
|
|
}
|
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();
|
2017-02-10 14:16:50 +00:00
|
|
|
if (auto activated = ClickHandler::unpressed()) {
|
2015-12-07 18:09:05 +00:00
|
|
|
Ui::hideLayer();
|
2016-03-29 17:17:00 +00:00
|
|
|
App::activateClickHandler(activated, e->button());
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
return 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() {
|
|
|
|
QPoint m(mapFromGlobal(_lastMousePos));
|
2016-03-29 17:17:00 +00:00
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
auto state = _text.getStateLeft(m.x() - st::boxPadding.left(), m.y() - 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);
|
2015-10-14 11:51:37 +00:00
|
|
|
_text.drawLeftElided(p, st::boxPadding.left(), st::boxPadding.top(), _textWidth, width(), 16, style::al_left);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-26 11:32:13 +00:00
|
|
|
InformBox::InformBox(QWidget*, const QString &text, base::lambda<void()> closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, lang(lng_box_ok), std::move(closedCallback)) {
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
|
|
|
|
2017-02-26 11:32:13 +00:00
|
|
|
InformBox::InformBox(QWidget*, const QString &text, const QString &doneText, base::lambda<void()> closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, doneText, std::move(closedCallback)) {
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
MaxInviteBox::MaxInviteBox(QWidget*, const QString &link)
|
2016-12-31 15:19:22 +00:00
|
|
|
: _text(st::boxLabelStyle, lng_participant_invite_sorry(lt_count, Global::ChatSizeMax()), _confirmBoxTextOptions, st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right())
|
2016-12-13 17:07:56 +00:00
|
|
|
, _link(link) {
|
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);
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
addButton(lang(lng_box_ok), [this] { closeBox(); });
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
_textWidth = st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.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());
|
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) {
|
2016-01-30 18:24:18 +00:00
|
|
|
Application::clipboard()->setText(_link);
|
2017-02-03 20:07:26 +00:00
|
|
|
Ui::Toast::Show(lang(lng_create_channel_link_copied));
|
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);
|
2015-09-23 17:43:08 +00:00
|
|
|
p.drawText(_invitationLink, _link, option);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
ConvertToSupergroupBox::ConvertToSupergroupBox(QWidget*, ChatData *chat)
|
|
|
|
: _chat(chat)
|
2016-03-04 22:04:15 +00:00
|
|
|
, _text(100)
|
2016-12-13 17:07:56 +00:00
|
|
|
, _note(100) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertToSupergroupBox::prepare() {
|
2016-03-04 22:04:15 +00:00
|
|
|
QStringList text;
|
|
|
|
text.push_back(lang(lng_profile_convert_feature1));
|
|
|
|
text.push_back(lang(lng_profile_convert_feature2));
|
|
|
|
text.push_back(lang(lng_profile_convert_feature3));
|
|
|
|
text.push_back(lang(lng_profile_convert_feature4));
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
setTitle(lang(lng_profile_convert_title));
|
|
|
|
|
|
|
|
addButton(lang(lng_profile_convert_confirm), [this] { convertToSupergroup(); });
|
|
|
|
addButton(lang(lng_cancel), [this] { closeBox(); });
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
_text.setText(st::boxLabelStyle, text.join('\n'), _confirmBoxTextOptions);
|
|
|
|
_note.setText(st::boxLabelStyle, lng_profile_convert_warning(lt_bold_start, textcmdStartSemibold(), lt_bold_end, textcmdStopSemibold()), _confirmBoxTextOptions);
|
2016-03-04 22:04:15 +00:00
|
|
|
_textWidth = st::boxWideWidth - st::boxPadding.left() - st::boxButtonPadding.right();
|
|
|
|
_textHeight = _text.countHeight(_textWidth);
|
2016-12-13 17:07:56 +00:00
|
|
|
setDimensions(st::boxWideWidth, _textHeight + st::boxPadding.bottom() + _note.countHeight(_textWidth));
|
2016-03-04 22:04:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConvertToSupergroupBox::convertToSupergroup() {
|
2016-03-04 22:04:15 +00:00
|
|
|
MTP::send(MTPmessages_MigrateChat(_chat->inputChat), rpcDone(&ConvertToSupergroupBox::convertDone), rpcFail(&ConvertToSupergroupBox::convertFail));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertToSupergroupBox::convertDone(const MTPUpdates &updates) {
|
|
|
|
Ui::hideLayer();
|
|
|
|
App::main()->sentUpdatesReceived(updates);
|
|
|
|
const QVector<MTPChat> *v = 0;
|
|
|
|
switch (updates.type()) {
|
2017-03-10 19:46:28 +00:00
|
|
|
case mtpc_updates: v = &updates.c_updates().vchats.v; break;
|
|
|
|
case mtpc_updatesCombined: v = &updates.c_updatesCombined().vchats.v; break;
|
2016-03-04 22:04:15 +00:00
|
|
|
default: LOG(("API Error: unexpected update cons %1 (ConvertToSupergroupBox::convertDone)").arg(updates.type())); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerData *peer = 0;
|
|
|
|
if (v && !v->isEmpty()) {
|
|
|
|
for (int32 i = 0, l = v->size(); i < l; ++i) {
|
|
|
|
if (v->at(i).type() == mtpc_channel) {
|
|
|
|
peer = App::channel(v->at(i).c_channel().vid.v);
|
|
|
|
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
|
|
|
|
QTimer::singleShot(ReloadChannelMembersTimeout, App::api(), SLOT(delayedRequestParticipantsCount()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!peer) {
|
|
|
|
LOG(("API Error: channel not found in updates (ProfileInner::migrateDone)"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConvertToSupergroupBox::convertFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2016-03-04 22:04:15 +00:00
|
|
|
Ui::hideLayer();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertToSupergroupBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
2016-12-13 17:07:56 +00:00
|
|
|
convertToSupergroup();
|
2016-03-04 22:04:15 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::keyPressEvent(e);
|
2016-03-04 22:04:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertToSupergroupBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2016-03-04 22:04:15 +00:00
|
|
|
|
2016-11-19 14:47:28 +00:00
|
|
|
Painter p(this);
|
2016-03-04 22:04:15 +00:00
|
|
|
|
|
|
|
// draw box title / text
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFg);
|
2016-12-13 17:07:56 +00:00
|
|
|
_text.drawLeft(p, st::boxPadding.left(), 0, _textWidth, width());
|
|
|
|
_note.drawLeft(p, st::boxPadding.left(), _textHeight + st::boxPadding.bottom(), _textWidth, width());
|
2016-03-04 22:04:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
PinMessageBox::PinMessageBox(QWidget*, ChannelData *channel, MsgId msgId)
|
|
|
|
: _channel(channel)
|
2016-03-10 10:15:21 +00:00
|
|
|
, _msgId(msgId)
|
2016-11-16 10:44:06 +00:00
|
|
|
, _text(this, lang(lng_pinned_pin_sure), Ui::FlatLabel::InitType::Simple, st::boxLabel)
|
2016-12-13 17:07:56 +00:00
|
|
|
, _notify(this, lang(lng_pinned_notify), true, st::defaultBoxCheckbox) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void PinMessageBox::prepare() {
|
|
|
|
addButton(lang(lng_pinned_pin), [this] { pinMessage(); });
|
|
|
|
addButton(lang(lng_cancel), [this] { closeBox(); });
|
|
|
|
|
|
|
|
setDimensions(st::boxWidth, st::boxPadding.top() + _text->height() + st::boxMediumSkip + _notify->heightNoMargins() + st::boxPadding.bottom());
|
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());
|
|
|
|
_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;
|
|
|
|
|
2017-03-25 15:42:01 +00:00
|
|
|
auto flags = MTPchannels_UpdatePinnedMessage::Flags(0);
|
2016-10-28 09:20:24 +00:00
|
|
|
if (!_notify->checked()) {
|
2016-03-19 16:55:15 +00:00
|
|
|
flags |= MTPchannels_UpdatePinnedMessage::Flag::f_silent;
|
|
|
|
}
|
|
|
|
_requestId = MTP::send(MTPchannels_UpdatePinnedMessage(MTP_flags(flags), _channel->inputChannel, MTP_int(_msgId)), rpcDone(&PinMessageBox::pinDone), rpcFail(&PinMessageBox::pinFail));
|
2016-03-10 10:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PinMessageBox::pinDone(const MTPUpdates &updates) {
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->sentUpdatesReceived(updates);
|
|
|
|
}
|
|
|
|
Ui::hideLayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PinMessageBox::pinFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2016-03-10 10:15:21 +00:00
|
|
|
Ui::hideLayer();
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-10 15:42:01 +00:00
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
DeleteMessagesBox::DeleteMessagesBox(QWidget*, HistoryItem *item, bool suggestModerateActions) : _singleItem(true) {
|
|
|
|
_ids.push_back(item->fullId());
|
|
|
|
if (suggestModerateActions && item->suggestBanReportDeleteAll()) {
|
|
|
|
_moderateFrom = item->from()->asUser();
|
|
|
|
_moderateInChannel = item->history()->peer->asChannel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DeleteMessagesBox::DeleteMessagesBox(QWidget*, const SelectedItemSet &selected) {
|
|
|
|
auto count = selected.size();
|
|
|
|
t_assert(count > 0);
|
|
|
|
_ids.reserve(count);
|
|
|
|
for_const (auto item, selected) {
|
|
|
|
_ids.push_back(item->fullId());
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
void DeleteMessagesBox::prepare() {
|
|
|
|
auto text = QString();
|
|
|
|
if (_moderateFrom) {
|
|
|
|
t_assert(_moderateInChannel != nullptr);
|
|
|
|
text = lang(lng_selected_delete_sure_this);
|
|
|
|
_banUser.create(this, lang(lng_ban_user), false, st::defaultBoxCheckbox);
|
|
|
|
_reportSpam.create(this, lang(lng_report_spam), false, st::defaultBoxCheckbox);
|
|
|
|
_deleteAll.create(this, lang(lng_delete_all_from), false, st::defaultBoxCheckbox);
|
|
|
|
} else {
|
|
|
|
text = _singleItem ? lang(lng_selected_delete_sure_this) : lng_selected_delete_sure(lt_count, _ids.size());
|
|
|
|
auto canDeleteAllForEveryone = true;
|
|
|
|
auto now = ::date(unixtime());
|
|
|
|
auto deleteForUser = (UserData*)nullptr;
|
|
|
|
auto peer = (PeerData*)nullptr;
|
|
|
|
auto forEveryoneText = lang(lng_delete_for_everyone_check);
|
|
|
|
for_const (auto fullId, _ids) {
|
|
|
|
if (auto item = App::histItemById(fullId)) {
|
|
|
|
peer = item->history()->peer;
|
|
|
|
if (!item->canDeleteForEveryone(now)) {
|
|
|
|
canDeleteAllForEveryone = false;
|
|
|
|
break;
|
|
|
|
} else if (auto user = item->history()->peer->asUser()) {
|
|
|
|
if (!deleteForUser || deleteForUser == user) {
|
|
|
|
deleteForUser = user;
|
|
|
|
forEveryoneText = lng_delete_for_other_check(lt_user, user->firstName);
|
|
|
|
} else {
|
|
|
|
forEveryoneText = lang(lng_delete_for_everyone_check);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
canDeleteAllForEveryone = false;
|
|
|
|
}
|
|
|
|
}
|
2017-01-02 17:11:49 +00:00
|
|
|
auto count = qMax(1, _ids.size());
|
2016-12-31 15:19:22 +00:00
|
|
|
if (canDeleteAllForEveryone) {
|
|
|
|
_forEveryone.create(this, forEveryoneText, false, st::defaultBoxCheckbox);
|
|
|
|
} else if (peer && peer->isChannel()) {
|
|
|
|
if (peer->isMegagroup()) {
|
2017-01-02 17:11:49 +00:00
|
|
|
text += qsl("\n\n") + lng_delete_for_everyone_hint(lt_count, count);
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
|
|
|
} else if (peer->isChat()) {
|
2017-01-02 17:11:49 +00:00
|
|
|
text += qsl("\n\n") + lng_delete_for_me_chat_hint(lt_count, count);
|
|
|
|
} else if (!peer->isSelf()) {
|
|
|
|
text += qsl("\n\n") + lng_delete_for_me_hint(lt_count, count);
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_text.create(this, text, Ui::FlatLabel::InitType::Simple, st::boxLabel);
|
2016-03-13 15:45:00 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
addButton(lang(lng_box_delete), [this] { deleteAndClear(); });
|
|
|
|
addButton(lang(lng_cancel), [this] { 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) {
|
|
|
|
fullHeight += st::boxMediumSkip + _banUser->heightNoMargins() + st::boxLittleSkip + _reportSpam->heightNoMargins() + st::boxLittleSkip + _deleteAll->heightNoMargins();
|
|
|
|
} else if (_forEveryone) {
|
|
|
|
fullHeight += st::boxMediumSkip + _forEveryone->heightNoMargins();
|
|
|
|
}
|
|
|
|
setDimensions(st::boxWidth, fullHeight);
|
2016-03-10 15:42:01 +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);
|
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) {
|
|
|
|
_banUser->moveToLeft(st::boxPadding.left(), _text->bottomNoMargins() + st::boxMediumSkip);
|
|
|
|
_reportSpam->moveToLeft(st::boxPadding.left(), _banUser->bottomNoMargins() + st::boxLittleSkip);
|
|
|
|
_deleteAll->moveToLeft(st::boxPadding.left(), _reportSpam->bottomNoMargins() + st::boxLittleSkip);
|
|
|
|
} else if (_forEveryone) {
|
|
|
|
_forEveryone->moveToLeft(st::boxPadding.left(), _text->bottomNoMargins() + st::boxMediumSkip);
|
|
|
|
}
|
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() {
|
|
|
|
if (!App::main()) {
|
|
|
|
return;
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
2016-12-31 15:19:22 +00:00
|
|
|
|
|
|
|
if (_moderateFrom) {
|
|
|
|
if (_banUser->checked()) {
|
|
|
|
MTP::send(MTPchannels_KickFromChannel(_moderateInChannel->inputChannel, _moderateFrom->inputUser, MTP_boolTrue()), App::main()->rpcDone(&MainWidget::sentUpdatesReceived));
|
|
|
|
}
|
|
|
|
if (_reportSpam->checked()) {
|
|
|
|
MTP::send(MTPchannels_ReportSpam(_moderateInChannel->inputChannel, _moderateFrom->inputUser, MTP_vector<MTPint>(1, MTP_int(_ids[0].msg))));
|
|
|
|
}
|
|
|
|
if (_deleteAll->checked()) {
|
|
|
|
App::main()->deleteAllFromUser(_moderateInChannel, _moderateFrom);
|
|
|
|
}
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
2016-12-31 15:19:22 +00:00
|
|
|
|
|
|
|
if (!_singleItem) {
|
|
|
|
App::main()->clearSelectedItems();
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
2016-12-31 15:19:22 +00:00
|
|
|
|
|
|
|
QMap<PeerData*, QVector<MTPint>> idsByPeer;
|
|
|
|
for_const (auto fullId, _ids) {
|
|
|
|
if (auto item = App::histItemById(fullId)) {
|
|
|
|
auto history = item->history();
|
|
|
|
auto wasOnServer = (item->id > 0);
|
|
|
|
auto wasLast = (history->lastMsg == item);
|
|
|
|
item->destroy();
|
|
|
|
|
|
|
|
if (wasOnServer) {
|
|
|
|
idsByPeer[history->peer].push_back(MTP_int(fullId.msg));
|
|
|
|
} else if (wasLast) {
|
|
|
|
App::main()->checkPeerHistory(history->peer);
|
|
|
|
}
|
2016-03-11 11:13:28 +00:00
|
|
|
}
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
2016-12-31 15:19:22 +00:00
|
|
|
|
|
|
|
auto forEveryone = _forEveryone ? _forEveryone->checked() : false;
|
|
|
|
for (auto i = idsByPeer.cbegin(), e = idsByPeer.cend(); i != e; ++i) {
|
|
|
|
App::main()->deleteMessages(i.key(), i.value(), forEveryone);
|
|
|
|
}
|
2016-03-13 15:45:00 +00:00
|
|
|
Ui::hideLayer();
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
ConfirmInviteBox::ConfirmInviteBox(QWidget*, const QString &title, const MTPChatPhoto &photo, int count, const QVector<UserData*> &participants)
|
|
|
|
: _title(this, st::confirmInviteTitle)
|
2016-07-08 16:59:46 +00:00
|
|
|
, _status(this, st::confirmInviteStatus)
|
2016-12-13 17:07:56 +00:00
|
|
|
, _participants(participants) {
|
2016-07-08 16:59:46 +00:00
|
|
|
_title->setText(title);
|
|
|
|
QString status;
|
|
|
|
if (_participants.isEmpty() || _participants.size() >= count) {
|
|
|
|
status = lng_chat_status_members(lt_count, count);
|
|
|
|
} else {
|
|
|
|
status = lng_group_invite_members(lt_count, count);
|
|
|
|
}
|
|
|
|
_status->setText(status);
|
|
|
|
if (photo.type() == mtpc_chatPhoto) {
|
|
|
|
auto &d = photo.c_chatPhoto();
|
|
|
|
auto location = App::imageLocation(160, 160, d.vphoto_small);
|
|
|
|
if (!location.isNull()) {
|
|
|
|
_photo = ImagePtr(location);
|
|
|
|
if (!_photo->loaded()) {
|
2017-03-04 19:36:59 +00:00
|
|
|
subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { update(); });
|
2016-07-08 16:59:46 +00:00
|
|
|
_photo->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-29 09:03:51 +00:00
|
|
|
if (!_photo) {
|
|
|
|
_photoEmpty.set(0, title);
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ConfirmInviteBox::prepare() {
|
|
|
|
addButton(lang(lng_group_invite_join), [this] {
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
main->onInviteImport();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
addButton(lang(lng_cancel), [this] { closeBox(); });
|
|
|
|
|
|
|
|
if (_participants.size() > 4) {
|
|
|
|
_participants.resize(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto newHeight = st::confirmInviteStatusTop + _status->height() + st::boxPadding.bottom();
|
2016-07-08 16:59:46 +00:00
|
|
|
if (!_participants.isEmpty()) {
|
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;
|
2016-07-08 16:59:46 +00:00
|
|
|
for_const (auto user, _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);
|
|
|
|
name->setText(user->firstName.isEmpty() ? App::peerName(user) : user->firstName);
|
|
|
|
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) {
|
|
|
|
p.drawPixmap((width() - st::confirmInvitePhotoSize) / 2, st::confirmInvitePhotoTop, _photo->pixCircled(st::confirmInvitePhotoSize, st::confirmInvitePhotoSize));
|
|
|
|
} else {
|
|
|
|
_photoEmpty.paint(p, (width() - st::confirmInvitePhotoSize) / 2, st::confirmInvitePhotoTop, width(), st::confirmInvitePhotoSize);
|
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
|
|
|
|
int sumWidth = _participants.size() * _userWidth;
|
|
|
|
int left = (width() - sumWidth) / 2;
|
|
|
|
for_const (auto user, _participants) {
|
2016-12-29 09:03:51 +00:00
|
|
|
user->paintUserpicLeft(p, left + (_userWidth - st::confirmInviteUserPhotoSize) / 2, st::confirmInviteUserPhotoTop, width(), st::confirmInviteUserPhotoSize);
|
2016-07-08 16:59:46 +00:00
|
|
|
left += _userWidth;
|
|
|
|
}
|
|
|
|
}
|