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
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/add_contact_box.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-08 14:43:10 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_dialogs.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "messenger.h"
|
2017-07-03 13:57:46 +00:00
|
|
|
#include "mtproto/sender.h"
|
2017-08-14 12:53:49 +00:00
|
|
|
#include "base/flat_set.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/photo_crop_box.h"
|
2017-08-14 12:53:49 +00:00
|
|
|
#include "boxes/peer_list_controllers.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "core/file_utilities.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2016-12-20 13:03:51 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2017-03-07 09:17:37 +00:00
|
|
|
#include "ui/special_buttons.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"
|
2016-05-25 12:09:05 +00:00
|
|
|
#include "observer_peer.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "auth_session.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-07-18 15:15:02 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kMaxGroupChannelTitle = 255;
|
|
|
|
constexpr auto kMaxChannelDescription = 255;
|
|
|
|
constexpr auto kMaxBioLength = 70;
|
|
|
|
|
|
|
|
style::InputField CreateBioFieldStyle() {
|
|
|
|
auto result = st::newGroupDescription;
|
|
|
|
result.textMargins.setRight(st::boxTextFont->spacew + st::boxTextFont->width(QString::number(kMaxBioLength)));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-08-14 12:53:49 +00:00
|
|
|
QString PeerFloodErrorText(PeerFloodType type) {
|
|
|
|
auto link = textcmdLink(
|
|
|
|
Messenger::Instance().createInternalLinkFull(qsl("spambot")),
|
|
|
|
lang(lng_cant_more_info));
|
|
|
|
if (type == PeerFloodType::InviteGroup) {
|
|
|
|
return lng_cant_invite_not_contact(lt_more_info, link);
|
|
|
|
}
|
|
|
|
return lng_cant_send_to_not_contact(lt_more_info, link);
|
|
|
|
}
|
|
|
|
|
2017-07-03 13:57:46 +00:00
|
|
|
class RevokePublicLinkBox::Inner : public TWidget, private MTP::Sender {
|
|
|
|
public:
|
|
|
|
Inner(QWidget *parent, base::lambda<void()> revokeCallback);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct ChatRow {
|
2017-08-17 08:31:24 +00:00
|
|
|
ChatRow(not_null<PeerData*> peer) : peer(peer) {
|
2017-07-03 13:57:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<PeerData*> peer;
|
2017-07-03 13:57:46 +00:00
|
|
|
Text name, status;
|
|
|
|
};
|
|
|
|
void paintChat(Painter &p, const ChatRow &row, bool selected) const;
|
|
|
|
void updateSelected();
|
|
|
|
|
|
|
|
PeerData *_selected = nullptr;
|
|
|
|
PeerData *_pressed = nullptr;
|
|
|
|
|
|
|
|
std::vector<ChatRow> _rows;
|
|
|
|
|
|
|
|
int _rowsTop = 0;
|
|
|
|
int _rowHeight = 0;
|
|
|
|
int _revokeWidth = 0;
|
|
|
|
|
|
|
|
base::lambda<void()> _revokeCallback;
|
|
|
|
mtpRequestId _revokeRequestId = 0;
|
|
|
|
QPointer<ConfirmBox> _weakRevokeConfirmBox;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
AddContactBox::AddContactBox(QWidget*, QString fname, QString lname, QString phone)
|
2017-05-30 15:21:05 +00:00
|
|
|
: _first(this, st::defaultInputField, langFactory(lng_signup_firstname), fname)
|
|
|
|
, _last(this, st::defaultInputField, langFactory(lng_signup_lastname), lname)
|
|
|
|
, _phone(this, st::defaultInputField, langFactory(lng_contact_phone), phone)
|
2016-05-31 19:27:11 +00:00
|
|
|
, _invertOrder(langFirstNameGoesSecond()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (!phone.isEmpty()) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_phone->setDisabled(true);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
AddContactBox::AddContactBox(QWidget*, UserData *user)
|
|
|
|
: _user(user)
|
2017-05-30 15:21:05 +00:00
|
|
|
, _first(this, st::defaultInputField, langFactory(lng_signup_firstname), user->firstName)
|
|
|
|
, _last(this, st::defaultInputField, langFactory(lng_signup_lastname), user->lastName)
|
|
|
|
, _phone(this, st::defaultInputField, langFactory(lng_contact_phone), user->phone())
|
2016-05-31 19:27:11 +00:00
|
|
|
, _invertOrder(langFirstNameGoesSecond()) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_phone->setDisabled(true);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void AddContactBox::prepare() {
|
2015-09-23 17:43:08 +00:00
|
|
|
if (_invertOrder) {
|
2016-10-28 09:20:24 +00:00
|
|
|
setTabOrder(_last, _first);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
if (_user) {
|
2017-05-30 15:21:05 +00:00
|
|
|
setTitle(langFactory(lng_edit_contact_title));
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2017-05-30 15:21:05 +00:00
|
|
|
auto readyToAdd = !_phone->getLastText().isEmpty() && (!_first->getLastText().isEmpty() || !_last->getLastText().isEmpty());
|
|
|
|
setTitle(langFactory(readyToAdd ? lng_confirm_contact_data : lng_enter_contact_data));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
updateButtons();
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
connect(_first, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
|
|
|
|
connect(_last, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
|
|
|
|
connect(_phone, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
setDimensions(st::boxWideWidth, st::contactPadding.top() + _first->height() + st::contactSkip + _last->height() + st::contactPhoneSkip + _phone->height() + st::contactPadding.bottom() + st::boxPadding.bottom());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void AddContactBox::setInnerFocus() {
|
2016-10-28 09:20:24 +00:00
|
|
|
if ((_first->getLastText().isEmpty() && _last->getLastText().isEmpty()) || !_phone->isEnabled()) {
|
2016-12-20 13:03:51 +00:00
|
|
|
(_invertOrder ? _last : _first)->setFocusFast();
|
2017-09-30 19:20:40 +00:00
|
|
|
_phone->finishAnimating();
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
2016-12-20 13:03:51 +00:00
|
|
|
_phone->setFocusFast();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddContactBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-11-19 14:47:28 +00:00
|
|
|
Painter p(this);
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_retrying) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFg);
|
|
|
|
p.setFont(st::boxTextFont);
|
2016-12-13 17:07:56 +00:00
|
|
|
auto textHeight = height() - st::contactPadding.top() - st::contactPadding.bottom() - st::boxPadding.bottom();
|
|
|
|
p.drawText(QRect(st::boxPadding.left(), st::contactPadding.top(), width() - st::boxPadding.left() - st::boxPadding.right(), textHeight), lng_contact_not_joined(lt_name, _sentName), style::al_topleft);
|
|
|
|
} else {
|
|
|
|
st::contactUserIcon.paint(p, st::boxPadding.left(), _first->y() + st::contactIconTop, width());
|
|
|
|
st::contactPhoneIcon.paint(p, st::boxPadding.left(), _phone->y() + st::contactIconTop, width());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
void AddContactBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->resize(width() - st::boxPadding.left() - st::contactPadding.left() - st::boxPadding.right(), _first->height());
|
|
|
|
_last->resize(_first->width(), _last->height());
|
|
|
|
_phone->resize(_first->width(), _last->height());
|
2015-09-23 17:43:08 +00:00
|
|
|
if (_invertOrder) {
|
2016-12-13 17:07:56 +00:00
|
|
|
_last->moveToLeft(st::boxPadding.left() + st::contactPadding.left(), st::contactPadding.top());
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->moveToLeft(st::boxPadding.left() + st::contactPadding.left(), _last->y() + _last->height() + st::contactSkip);
|
|
|
|
_phone->moveToLeft(st::boxPadding.left() + st::contactPadding.left(), _first->y() + _first->height() + st::contactPhoneSkip);
|
2015-09-23 17:43:08 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
_first->moveToLeft(st::boxPadding.left() + st::contactPadding.left(), st::contactPadding.top());
|
2016-10-28 09:20:24 +00:00
|
|
|
_last->moveToLeft(st::boxPadding.left() + st::contactPadding.left(), _first->y() + _first->height() + st::contactSkip);
|
|
|
|
_phone->moveToLeft(st::boxPadding.left() + st::contactPadding.left(), _last->y() + _last->height() + st::contactPhoneSkip);
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
void AddContactBox::onSubmit() {
|
2016-10-28 09:20:24 +00:00
|
|
|
if (_first->hasFocus()) {
|
|
|
|
_last->setFocus();
|
|
|
|
} else if (_last->hasFocus()) {
|
|
|
|
if (_phone->isEnabled()) {
|
|
|
|
_phone->setFocus();
|
2015-10-11 08:37:24 +00:00
|
|
|
} else {
|
|
|
|
onSave();
|
|
|
|
}
|
2016-10-28 09:20:24 +00:00
|
|
|
} else if (_phone->hasFocus()) {
|
2015-10-11 08:37:24 +00:00
|
|
|
onSave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddContactBox::onSave() {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (_addRequest) return;
|
|
|
|
|
2017-07-06 11:37:42 +00:00
|
|
|
auto firstName = TextUtilities::PrepareForSending(_first->getLastText());
|
|
|
|
auto lastName = TextUtilities::PrepareForSending(_last->getLastText());
|
|
|
|
auto phone = _phone->getLastText().trimmed();
|
2014-05-30 08:53:19 +00:00
|
|
|
if (firstName.isEmpty() && lastName.isEmpty()) {
|
2015-09-23 17:43:08 +00:00
|
|
|
if (_invertOrder) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_last->setFocus();
|
|
|
|
_last->showError();
|
2015-09-23 17:43:08 +00:00
|
|
|
} else {
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->setFocus();
|
|
|
|
_first->showError();
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
return;
|
2015-10-11 08:37:24 +00:00
|
|
|
} else if (!_user && !App::isValidPhone(phone)) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_phone->setFocus();
|
|
|
|
_phone->showError();
|
2014-05-30 08:53:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (firstName.isEmpty()) {
|
|
|
|
firstName = lastName;
|
|
|
|
lastName = QString();
|
|
|
|
}
|
|
|
|
_sentName = firstName;
|
2015-10-11 08:37:24 +00:00
|
|
|
if (_user) {
|
2016-03-24 10:12:18 +00:00
|
|
|
_contactId = rand_value<uint64>();
|
2016-05-31 19:27:11 +00:00
|
|
|
QVector<MTPInputContact> v(1, MTP_inputPhoneContact(MTP_long(_contactId), MTP_string(_user->phone()), MTP_string(firstName), MTP_string(lastName)));
|
2017-08-01 10:50:49 +00:00
|
|
|
_addRequest = MTP::send(MTPcontacts_ImportContacts(MTP_vector<MTPInputContact>(v)), rpcDone(&AddContactBox::onSaveUserDone), rpcFail(&AddContactBox::onSaveUserFail));
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2016-03-24 10:12:18 +00:00
|
|
|
_contactId = rand_value<uint64>();
|
2014-05-30 08:53:19 +00:00
|
|
|
QVector<MTPInputContact> v(1, MTP_inputPhoneContact(MTP_long(_contactId), MTP_string(phone), MTP_string(firstName), MTP_string(lastName)));
|
2017-08-01 10:50:49 +00:00
|
|
|
_addRequest = MTP::send(MTPcontacts_ImportContacts(MTP_vector<MTPInputContact>(v)), rpcDone(&AddContactBox::onImportDone));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
bool AddContactBox::onSaveUserFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2014-10-22 18:39:03 +00:00
|
|
|
_addRequest = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
QString err(error.type());
|
2016-10-28 09:20:24 +00:00
|
|
|
QString firstName = _first->getLastText().trimmed(), lastName = _last->getLastText().trimmed();
|
2014-05-30 08:53:19 +00:00
|
|
|
if (err == "CHAT_TITLE_NOT_MODIFIED") {
|
2016-05-25 12:09:05 +00:00
|
|
|
_user->setName(firstName, lastName, _user->nameOrPhone, _user->username);
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
|
|
|
} else if (err == "NO_CHAT_TITLE") {
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->setFocus();
|
|
|
|
_first->showError();
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->setFocus();
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (!isBoxShown() || !App::main()) return;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
auto &d = res.c_contacts_importedContacts();
|
2014-05-30 08:53:19 +00:00
|
|
|
App::feedUsers(d.vusers);
|
|
|
|
|
2017-03-10 19:46:28 +00:00
|
|
|
auto &v = d.vimported.v;
|
2016-03-25 11:29:45 +00:00
|
|
|
UserData *user = nullptr;
|
2014-05-30 08:53:19 +00:00
|
|
|
if (!v.isEmpty()) {
|
2017-03-18 21:06:10 +00:00
|
|
|
auto &c = v.front().c_importedContact();
|
2014-05-30 08:53:19 +00:00
|
|
|
if (c.vclient_id.v != _contactId) return;
|
|
|
|
|
2016-03-25 11:29:45 +00:00
|
|
|
user = App::userLoaded(c.vuser_id.v);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-03-25 11:29:45 +00:00
|
|
|
if (user) {
|
|
|
|
Notify::userIsContactChanged(user, true);
|
2015-12-07 18:09:05 +00:00
|
|
|
Ui::hideLayer();
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2016-11-18 13:34:58 +00:00
|
|
|
hideChildren();
|
2016-12-13 17:07:56 +00:00
|
|
|
_retrying = true;
|
|
|
|
updateButtons();
|
2014-05-30 08:53:19 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddContactBox::onSaveUserDone(const MTPcontacts_ImportedContacts &res) {
|
2016-08-16 16:53:10 +00:00
|
|
|
auto &d = res.c_contacts_importedContacts();
|
2014-05-30 08:53:19 +00:00
|
|
|
App::feedUsers(d.vusers);
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddContactBox::onRetry() {
|
|
|
|
_addRequest = 0;
|
|
|
|
_contactId = 0;
|
2016-11-18 13:34:58 +00:00
|
|
|
showChildren();
|
2016-12-13 17:07:56 +00:00
|
|
|
_retrying = false;
|
|
|
|
updateButtons();
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->setText(QString());
|
|
|
|
_last->setText(QString());
|
|
|
|
_phone->clearText();
|
|
|
|
_phone->setDisabled(false);
|
|
|
|
_first->setFocus();
|
2015-10-11 08:37:24 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void AddContactBox::updateButtons() {
|
|
|
|
clearButtons();
|
|
|
|
if (_retrying) {
|
2017-05-30 15:21:05 +00:00
|
|
|
addButton(langFactory(lng_try_other_contact), [this] { onRetry(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
} else {
|
2017-05-30 15:21:05 +00:00
|
|
|
addButton(langFactory(_user ? lng_settings_save : lng_add_contact), [this] { onSave(); });
|
|
|
|
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupInfoBox::GroupInfoBox(QWidget*, CreatingGroupType creating, bool fromTypeChoose)
|
|
|
|
: _creating(creating)
|
|
|
|
, _fromTypeChoose(fromTypeChoose)
|
2016-11-24 19:28:23 +00:00
|
|
|
, _photo(this, st::newGroupPhotoSize, st::newGroupPhotoIconPosition)
|
2017-05-30 15:21:05 +00:00
|
|
|
, _title(this, st::defaultInputField, langFactory(_creating == CreatingGroupChannel ? lng_dlg_new_channel_name : lng_dlg_new_group_name)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void GroupInfoBox::prepare() {
|
2015-10-11 08:37:24 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
|
2017-07-18 15:15:02 +00:00
|
|
|
_title->setMaxLength(kMaxGroupChannelTitle);
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_creating == CreatingGroupChannel) {
|
2017-05-30 15:21:05 +00:00
|
|
|
_description.create(this, st::newGroupDescription, langFactory(lng_create_group_description));
|
2016-12-13 17:07:56 +00:00
|
|
|
_description->show();
|
2017-07-18 15:15:02 +00:00
|
|
|
_description->setMaxLength(kMaxChannelDescription);
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
connect(_description, SIGNAL(resized()), this, SLOT(onDescriptionResized()));
|
|
|
|
connect(_description, SIGNAL(submitted(bool)), this, SLOT(onNext()));
|
|
|
|
connect(_description, SIGNAL(cancelled()), this, SLOT(onClose()));
|
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
connect(_title, SIGNAL(submitted(bool)), this, SLOT(onNameSubmit()));
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
addButton(langFactory(_creating == CreatingGroupChannel ? lng_create_group_create : lng_create_group_next), [this] { onNext(); });
|
|
|
|
addButton(langFactory(_fromTypeChoose ? lng_create_group_back : lng_cancel), [this] { closeBox(); });
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2017-02-28 15:43:03 +00:00
|
|
|
setupPhotoButton();
|
|
|
|
|
|
|
|
updateMaxHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupInfoBox::setupPhotoButton() {
|
2016-12-09 18:56:01 +00:00
|
|
|
_photo->setClickedCallback(App::LambdaDelayed(st::defaultActiveButton.ripple.hideDuration, this, [this] {
|
|
|
|
auto imgExtensions = cImgExtensions();
|
2017-02-28 15:43:03 +00:00
|
|
|
auto filter = qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + FileDialog::AllFilesFilter();
|
|
|
|
FileDialog::GetOpenPath(lang(lng_choose_image), filter, base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
|
|
|
|
if (result.remoteContent.isEmpty() && result.paths.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2017-02-28 15:43:03 +00:00
|
|
|
QImage img;
|
|
|
|
if (!result.remoteContent.isEmpty()) {
|
|
|
|
img = App::readImage(result.remoteContent);
|
|
|
|
} else {
|
|
|
|
img = App::readImage(result.paths.front());
|
|
|
|
}
|
|
|
|
if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-15 17:34:41 +00:00
|
|
|
auto box = Ui::show(
|
|
|
|
Box<PhotoCropBox>(
|
|
|
|
img,
|
|
|
|
(_creating == CreatingGroupChannel)
|
|
|
|
? peerFromChannel(0)
|
|
|
|
: peerFromChat(0)),
|
|
|
|
LayerOption::KeepOther);
|
2017-02-28 15:43:03 +00:00
|
|
|
connect(box, SIGNAL(ready(const QImage&)), this, SLOT(onPhotoReady(const QImage&)));
|
|
|
|
}));
|
|
|
|
}));
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void GroupInfoBox::setInnerFocus() {
|
2016-12-20 13:03:51 +00:00
|
|
|
_title->setFocusFast();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupInfoBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2016-11-19 14:47:28 +00:00
|
|
|
_photo->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), st::boxPadding.top() + st::newGroupInfoPadding.top());
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
auto nameLeft = st::newGroupPhotoSize + st::newGroupNamePosition.x();
|
2016-10-28 09:20:24 +00:00
|
|
|
_title->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right() - nameLeft, _title->height());
|
|
|
|
_title->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left() + nameLeft, st::boxPadding.top() + st::newGroupInfoPadding.top() + st::newGroupNamePosition.y());
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_description) {
|
|
|
|
_description->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right(), _description->height());
|
|
|
|
_description->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), st::boxPadding.top() + st::newGroupInfoPadding.top() + st::newGroupPhotoSize + st::newGroupDescriptionPadding.top());
|
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupInfoBox::onNameSubmit() {
|
2016-10-28 09:20:24 +00:00
|
|
|
if (_title->getLastText().trimmed().isEmpty()) {
|
|
|
|
_title->setFocus();
|
|
|
|
_title->showError();
|
2016-12-13 17:07:56 +00:00
|
|
|
} else if (_description) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_description->setFocus();
|
2016-12-13 17:07:56 +00:00
|
|
|
} else {
|
|
|
|
onNext();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void GroupInfoBox::createGroup(not_null<PeerListBox*> selectUsersBox, const QString &title, const std::vector<not_null<PeerData*>> &users) {
|
2017-08-14 12:53:49 +00:00
|
|
|
if (_creationRequestId) return;
|
|
|
|
|
|
|
|
auto inputs = QVector<MTPInputUser>();
|
|
|
|
inputs.reserve(users.size());
|
|
|
|
for (auto peer : users) {
|
|
|
|
auto user = peer->asUser();
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(user != nullptr);
|
2017-08-14 12:53:49 +00:00
|
|
|
if (!user->isSelf()) {
|
|
|
|
inputs.push_back(user->inputUser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_creationRequestId = request(MTPmessages_CreateChat(MTP_vector<MTPInputUser>(inputs), MTP_string(title))).done([this](const MTPUpdates &result) {
|
|
|
|
Ui::hideLayer();
|
|
|
|
|
|
|
|
App::main()->sentUpdatesReceived(result);
|
|
|
|
|
|
|
|
auto success = base::make_optional(&result)
|
|
|
|
| [](auto updates) -> base::optional<const QVector<MTPChat>*> {
|
|
|
|
switch (updates->type()) {
|
|
|
|
case mtpc_updates:
|
2017-08-14 12:48:11 +00:00
|
|
|
return &updates->c_updates().vchats.v;
|
2017-08-14 12:53:49 +00:00
|
|
|
case mtpc_updatesCombined:
|
2017-08-14 12:48:11 +00:00
|
|
|
return &updates->c_updatesCombined().vchats.v;
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
LOG(("API Error: unexpected update cons %1 (GroupInfoBox::creationDone)").arg(updates->type()));
|
|
|
|
return base::none;
|
|
|
|
}
|
|
|
|
| [](auto chats) {
|
|
|
|
return (!chats->empty() && chats->front().type() == mtpc_chat)
|
|
|
|
? base::make_optional(chats)
|
|
|
|
: base::none;
|
|
|
|
}
|
|
|
|
| [](auto chats) {
|
|
|
|
return App::chat(chats->front().c_chat().vid.v);
|
|
|
|
}
|
2017-08-17 08:31:24 +00:00
|
|
|
| [this](not_null<ChatData*> chat) {
|
2017-08-14 12:53:49 +00:00
|
|
|
if (!_photoImage.isNull()) {
|
|
|
|
Messenger::Instance().uploadProfilePhoto(_photoImage, chat->id);
|
|
|
|
}
|
|
|
|
Ui::showPeerHistory(chat, ShowAtUnreadMsgId);
|
|
|
|
};
|
|
|
|
if (!success) {
|
|
|
|
LOG(("API Error: chat not found in updates (ContactsBox::creationDone)"));
|
|
|
|
}
|
|
|
|
}).fail([this, selectUsersBox](const RPCError &error) {
|
|
|
|
_creationRequestId = 0;
|
|
|
|
if (error.type() == qstr("NO_CHAT_TITLE")) {
|
|
|
|
auto guard = weak(this);
|
|
|
|
selectUsersBox->closeBox();
|
|
|
|
if (guard) {
|
|
|
|
_title->showError();
|
|
|
|
}
|
|
|
|
} else if (error.type() == qstr("USERS_TOO_FEW")) {
|
|
|
|
} else if (error.type() == qstr("PEER_FLOOD")) {
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<InformBox>(
|
|
|
|
PeerFloodErrorText(PeerFloodType::InviteGroup)),
|
|
|
|
LayerOption::KeepOther);
|
2017-08-14 12:53:49 +00:00
|
|
|
} else if (error.type() == qstr("USER_RESTRICTED")) {
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<InformBox>(lang(lng_cant_do_this)),
|
|
|
|
LayerOption::KeepOther);
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
void GroupInfoBox::onNext() {
|
|
|
|
if (_creationRequestId) return;
|
|
|
|
|
2017-07-06 11:37:42 +00:00
|
|
|
auto title = TextUtilities::PrepareForSending(_title->getLastText());
|
|
|
|
auto description = _description ? TextUtilities::PrepareForSending(_description->getLastText(), TextUtilities::PrepareTextOption::CheckLinks) : QString();
|
2015-10-11 08:37:24 +00:00
|
|
|
if (title.isEmpty()) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_title->setFocus();
|
|
|
|
_title->showError();
|
2015-10-11 08:37:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-08-14 12:53:49 +00:00
|
|
|
if (_creating != CreatingGroupGroup) {
|
|
|
|
createChannel(title, description);
|
2015-10-11 08:37:24 +00:00
|
|
|
} else {
|
2017-08-17 08:31:24 +00:00
|
|
|
auto initBox = [title, weak = weak(this)](not_null<PeerListBox*> box) {
|
2017-08-14 12:53:49 +00:00
|
|
|
box->addButton(langFactory(lng_create_group_create), [box, title, weak] {
|
|
|
|
if (weak) {
|
|
|
|
auto rows = box->peerListCollectSelectedRows();
|
|
|
|
if (!rows.empty()) {
|
|
|
|
weak->createGroup(box, title, rows);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); });
|
|
|
|
};
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<PeerListBox>(
|
|
|
|
std::make_unique<AddParticipantsBoxController>(
|
|
|
|
nullptr),
|
|
|
|
std::move(initBox)),
|
|
|
|
LayerOption::KeepOther);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-14 12:53:49 +00:00
|
|
|
void GroupInfoBox::createChannel(const QString &title, const QString &description) {
|
|
|
|
bool mega = false;
|
|
|
|
auto flags = mega ? MTPchannels_CreateChannel::Flag::f_megagroup : MTPchannels_CreateChannel::Flag::f_broadcast;
|
|
|
|
_creationRequestId = request(MTPchannels_CreateChannel(MTP_flags(flags), MTP_string(title), MTP_string(description))).done([this](const MTPUpdates &result) {
|
|
|
|
App::main()->sentUpdatesReceived(result);
|
|
|
|
|
|
|
|
auto success = base::make_optional(&result)
|
|
|
|
| [](auto updates) -> base::optional<const QVector<MTPChat>*> {
|
|
|
|
switch (updates->type()) {
|
|
|
|
case mtpc_updates:
|
2017-08-14 12:48:11 +00:00
|
|
|
return &updates->c_updates().vchats.v;
|
2017-08-14 12:53:49 +00:00
|
|
|
case mtpc_updatesCombined:
|
2017-08-14 12:48:11 +00:00
|
|
|
return &updates->c_updatesCombined().vchats.v;
|
2017-08-14 12:53:49 +00:00
|
|
|
}
|
|
|
|
LOG(("API Error: unexpected update cons %1 (GroupInfoBox::createChannel)").arg(updates->type()));
|
|
|
|
return base::none;
|
|
|
|
}
|
|
|
|
| [](auto chats) {
|
|
|
|
return (!chats->empty() && chats->front().type() == mtpc_channel)
|
|
|
|
? base::make_optional(chats)
|
|
|
|
: base::none;
|
|
|
|
}
|
|
|
|
| [](auto chats) {
|
|
|
|
return App::channel(chats->front().c_channel().vid.v);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
2017-08-17 08:31:24 +00:00
|
|
|
| [this](not_null<ChannelData*> channel) {
|
2017-08-14 12:53:49 +00:00
|
|
|
if (!_photoImage.isNull()) {
|
|
|
|
Messenger::Instance().uploadProfilePhoto(
|
|
|
|
_photoImage,
|
|
|
|
channel->id);
|
|
|
|
}
|
|
|
|
_createdChannel = channel;
|
|
|
|
_creationRequestId = request(
|
|
|
|
MTPchannels_ExportInvite(_createdChannel->inputChannel)
|
|
|
|
).done([this](const MTPExportedChatInvite &result) {
|
|
|
|
_creationRequestId = 0;
|
|
|
|
if (result.type() == mtpc_chatInviteExported) {
|
|
|
|
auto link = qs(result.c_chatInviteExported().vlink);
|
|
|
|
_createdChannel->setInviteLink(link);
|
|
|
|
}
|
|
|
|
Ui::show(Box<SetupChannelBox>(_createdChannel));
|
|
|
|
}).send();
|
|
|
|
};
|
|
|
|
if (!success) {
|
|
|
|
LOG(("API Error: channel not found in updates (GroupInfoBox::creationDone)"));
|
|
|
|
closeBox();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
2017-08-14 12:53:49 +00:00
|
|
|
}).fail([this](const RPCError &error) {
|
|
|
|
_creationRequestId = 0;
|
|
|
|
if (error.type() == "NO_CHAT_TITLE") {
|
|
|
|
_title->setFocus();
|
|
|
|
_title->showError();
|
|
|
|
} else if (error.type() == qstr("USER_RESTRICTED")) {
|
|
|
|
Ui::show(Box<InformBox>(lang(lng_cant_do_this)));
|
|
|
|
} else if (error.type() == qstr("CHANNELS_TOO_MUCH")) {
|
|
|
|
Ui::show(Box<InformBox>(lang(lng_cant_do_this))); // TODO
|
|
|
|
}
|
|
|
|
}).send();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupInfoBox::onDescriptionResized() {
|
|
|
|
updateMaxHeight();
|
2014-05-30 08:53:19 +00:00
|
|
|
update();
|
|
|
|
}
|
2015-09-21 20:57:42 +00:00
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
void GroupInfoBox::updateMaxHeight() {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto newHeight = st::boxPadding.top() + st::newGroupInfoPadding.top() + st::newGroupPhotoSize + st::boxPadding.bottom() + st::newGroupInfoPadding.bottom();
|
|
|
|
if (_description) {
|
|
|
|
newHeight += st::newGroupDescriptionPadding.top() + _description->height() + st::newGroupDescriptionPadding.bottom();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
setDimensions(st::boxWideWidth, newHeight);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupInfoBox::onPhotoReady(const QImage &img) {
|
2016-11-19 14:47:28 +00:00
|
|
|
_photoImage = img;
|
|
|
|
_photo->setImage(_photoImage);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
SetupChannelBox::SetupChannelBox(QWidget*, ChannelData *channel, bool existing)
|
|
|
|
: _channel(channel)
|
2015-12-08 12:33:37 +00:00
|
|
|
, _existing(existing)
|
2017-03-18 21:06:10 +00:00
|
|
|
, _privacyGroup(std::make_shared<Ui::RadioenumGroup<Privacy>>(Privacy::Public))
|
|
|
|
, _public(this, _privacyGroup, Privacy::Public, lang(channel->isMegagroup() ? lng_create_public_group_title : lng_create_public_channel_title), st::defaultBoxCheckbox)
|
|
|
|
, _private(this, _privacyGroup, Privacy::Private, lang(channel->isMegagroup() ? lng_create_private_group_title : lng_create_private_channel_title), st::defaultBoxCheckbox)
|
2017-07-07 11:27:13 +00:00
|
|
|
, _aboutPublicWidth(st::boxWideWidth - st::boxPadding.left() - st::boxButtonPadding.right() - st::newGroupPadding.left() - st::defaultRadio.diameter - st::defaultBoxCheckbox.textPosition.x())
|
2016-12-23 13:21:01 +00:00
|
|
|
, _aboutPublic(st::defaultTextStyle, lang(channel->isMegagroup() ? lng_create_public_group_about : lng_create_public_channel_about), _defaultOptions, _aboutPublicWidth)
|
|
|
|
, _aboutPrivate(st::defaultTextStyle, lang(channel->isMegagroup() ? lng_create_private_group_about : lng_create_private_channel_about), _defaultOptions, _aboutPublicWidth)
|
2017-05-30 15:21:05 +00:00
|
|
|
, _link(this, st::setupChannelLink, base::lambda<QString()>(), channel->username, true) {
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupChannelBox::prepare() {
|
|
|
|
_aboutPublicHeight = _aboutPublic.countHeight(_aboutPublicWidth);
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
|
|
|
|
_checkRequestId = MTP::send(MTPchannels_CheckUsername(_channel->inputChannel, MTP_string("preston")), RPCDoneHandlerPtr(), rpcFail(&SetupChannelBox::onFirstCheckFail));
|
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
addButton(langFactory(lng_settings_save), [this] { onSave(); });
|
|
|
|
addButton(langFactory(_existing ? lng_cancel : lng_create_group_skip), [this] { closeBox(); });
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
connect(_link, SIGNAL(changed()), this, SLOT(onChange()));
|
2017-03-18 21:06:10 +00:00
|
|
|
_link->setVisible(_privacyGroup->value() == Privacy::Public);
|
2015-10-11 08:37:24 +00:00
|
|
|
|
|
|
|
_checkTimer.setSingleShot(true);
|
|
|
|
connect(&_checkTimer, SIGNAL(timeout()), this, SLOT(onCheck()));
|
|
|
|
|
2017-03-18 21:06:10 +00:00
|
|
|
_privacyGroup->setChangedCallback([this](Privacy value) { privacyChanged(value); });
|
2017-07-14 12:28:08 +00:00
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::InviteLinkChanged, [this](const Notify::PeerUpdate &update) {
|
|
|
|
if (update.peer == _channel) {
|
|
|
|
rtlupdate(_invitationLink);
|
|
|
|
}
|
|
|
|
}));
|
2017-08-13 16:09:14 +00:00
|
|
|
subscribe(boxClosing, [this] {
|
|
|
|
if (!_existing) {
|
2017-08-14 12:48:11 +00:00
|
|
|
AddParticipantsBoxController::Start(_channel);
|
2017-08-13 16:09:14 +00:00
|
|
|
}
|
|
|
|
});
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
updateMaxHeight();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void SetupChannelBox::setInnerFocus() {
|
2016-10-28 09:20:24 +00:00
|
|
|
if (_link->isHidden()) {
|
2016-08-16 16:53:10 +00:00
|
|
|
setFocus();
|
|
|
|
} else {
|
2016-12-20 13:03:51 +00:00
|
|
|
_link->setFocusFast();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 16:47:48 +00:00
|
|
|
void SetupChannelBox::updateMaxHeight() {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto newHeight = st::boxPadding.top() + st::newGroupPadding.top() + _public->heightNoMargins() + _aboutPublicHeight + st::newGroupSkip + _private->heightNoMargins() + _aboutPrivate.countHeight(_aboutPublicWidth) + st::newGroupSkip + st::newGroupPadding.bottom();
|
2017-03-18 21:06:10 +00:00
|
|
|
if (!_channel->isMegagroup() || _privacyGroup->value() == Privacy::Public) {
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += st::newGroupLinkPadding.top() + _link->height() + st::newGroupLinkPadding.bottom();
|
2016-03-04 16:47:48 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
setDimensions(st::boxWideWidth, newHeight);
|
2016-03-04 16:47:48 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
void SetupChannelBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
2016-10-28 09:20:24 +00:00
|
|
|
if (_link->hasFocus()) {
|
|
|
|
if (_link->text().trimmed().isEmpty()) {
|
|
|
|
_link->setFocus();
|
|
|
|
_link->showError();
|
2015-10-11 08:37:24 +00:00
|
|
|
} else {
|
|
|
|
onSave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::keyPressEvent(e);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupChannelBox::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2016-11-19 14:47:28 +00:00
|
|
|
p.fillRect(e->rect(), st::boxBg);
|
2015-10-11 08:37:24 +00:00
|
|
|
p.setPen(st::newGroupAboutFg);
|
|
|
|
|
2017-07-07 11:27:13 +00:00
|
|
|
QRect aboutPublic(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadio.diameter + st::defaultBoxCheckbox.textPosition.x(), _public->bottomNoMargins(), _aboutPublicWidth, _aboutPublicHeight);
|
2015-10-14 11:51:37 +00:00
|
|
|
_aboutPublic.drawLeft(p, aboutPublic.x(), aboutPublic.y(), aboutPublic.width(), width());
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2017-07-07 11:27:13 +00:00
|
|
|
QRect aboutPrivate(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadio.diameter + st::defaultBoxCheckbox.textPosition.x(), _private->bottomNoMargins(), _aboutPublicWidth, _aboutPublicHeight);
|
2015-10-14 11:51:37 +00:00
|
|
|
_aboutPrivate.drawLeft(p, aboutPrivate.x(), aboutPrivate.y(), aboutPrivate.width(), width());
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
if (!_channel->isMegagroup() || !_link->isHidden()) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFg);
|
2016-03-04 16:47:48 +00:00
|
|
|
p.setFont(st::newGroupLinkFont);
|
2016-10-28 09:20:24 +00:00
|
|
|
p.drawTextLeft(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultInputField.textMargins.left(), _link->y() - st::newGroupLinkPadding.top() + st::newGroupLinkTop, width(), lang(_link->isHidden() ? lng_create_group_invite_link : lng_create_group_link));
|
2016-03-04 16:47:48 +00:00
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
if (_link->isHidden()) {
|
2016-03-04 16:47:48 +00:00
|
|
|
if (!_channel->isMegagroup()) {
|
|
|
|
QTextOption option(style::al_left);
|
|
|
|
option.setWrapMode(QTextOption::WrapAnywhere);
|
|
|
|
p.setFont(_linkOver ? st::boxTextFont->underline() : st::boxTextFont);
|
2016-11-11 13:46:04 +00:00
|
|
|
p.setPen(st::defaultLinkButton.color);
|
2017-07-14 12:28:08 +00:00
|
|
|
auto inviteLinkText = _channel->inviteLink().isEmpty() ? lang(lng_group_invite_create) : _channel->inviteLink();
|
|
|
|
p.drawText(_invitationLink, inviteLinkText, option);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!_errorText.isEmpty()) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFgError);
|
2015-10-11 08:37:24 +00:00
|
|
|
p.setFont(st::boxTextFont);
|
2016-10-28 09:20:24 +00:00
|
|
|
p.drawTextRight(st::boxPadding.right(), _link->y() - st::newGroupLinkPadding.top() + st::newGroupLinkTop + st::newGroupLinkFont->ascent - st::boxTextFont->ascent, width(), _errorText);
|
2015-10-11 08:37:24 +00:00
|
|
|
} else if (!_goodText.isEmpty()) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFgGood);
|
2015-10-11 08:37:24 +00:00
|
|
|
p.setFont(st::boxTextFont);
|
2016-10-28 09:20:24 +00:00
|
|
|
p.drawTextRight(st::boxPadding.right(), _link->y() - st::newGroupLinkPadding.top() + st::newGroupLinkTop + st::newGroupLinkFont->ascent - st::boxTextFont->ascent, width(), _goodText);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupChannelBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
_public->moveToLeft(st::boxPadding.left() + st::newGroupPadding.left(), st::boxPadding.top() + st::newGroupPadding.top());
|
2016-12-02 19:16:35 +00:00
|
|
|
_private->moveToLeft(st::boxPadding.left() + st::newGroupPadding.left(), _public->bottomNoMargins() + _aboutPublicHeight + st::newGroupSkip);
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
_link->resize(width() - st::boxPadding.left() - st::newGroupLinkPadding.left() - st::boxPadding.right(), _link->height());
|
2016-12-02 19:16:35 +00:00
|
|
|
_link->moveToLeft(st::boxPadding.left() + st::newGroupLinkPadding.left(), _private->bottomNoMargins() + _aboutPrivate.countHeight(_aboutPublicWidth) + st::newGroupSkip + st::newGroupPadding.bottom() + st::newGroupLinkPadding.top());
|
2016-10-28 09:20:24 +00:00
|
|
|
_invitationLink = QRect(_link->x(), _link->y() + (_link->height() / 2) - st::boxTextFont->height, _link->width(), 2 * st::boxTextFont->height);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupChannelBox::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
updateSelected(e->globalPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupChannelBox::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if (_linkOver) {
|
2017-07-14 12:28:08 +00:00
|
|
|
if (_channel->inviteLink().isEmpty()) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().exportInviteLink(_channel);
|
2017-07-14 12:28:08 +00:00
|
|
|
} else {
|
|
|
|
QGuiApplication::clipboard()->setText(_channel->inviteLink());
|
|
|
|
Ui::Toast::Show(lang(lng_create_channel_link_copied));
|
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void SetupChannelBox::leaveEventHook(QEvent *e) {
|
2015-10-11 08:37:24 +00:00
|
|
|
updateSelected(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupChannelBox::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 SetupChannelBox::onSave() {
|
2017-03-18 21:06:10 +00:00
|
|
|
if (_privacyGroup->value() == Privacy::Private) {
|
2015-10-11 08:37:24 +00:00
|
|
|
if (_existing) {
|
|
|
|
_sentUsername = QString();
|
|
|
|
_saveRequestId = MTP::send(MTPchannels_UpdateUsername(_channel->inputChannel, MTP_string(_sentUsername)), rpcDone(&SetupChannelBox::onUpdateDone), rpcFail(&SetupChannelBox::onUpdateFail));
|
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_saveRequestId) return;
|
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
QString link = _link->text().trimmed();
|
2015-10-11 08:37:24 +00:00
|
|
|
if (link.isEmpty()) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_link->setFocus();
|
|
|
|
_link->showError();
|
2015-10-11 08:37:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_sentUsername = link;
|
|
|
|
_saveRequestId = MTP::send(MTPchannels_UpdateUsername(_channel->inputChannel, MTP_string(_sentUsername)), rpcDone(&SetupChannelBox::onUpdateDone), rpcFail(&SetupChannelBox::onUpdateFail));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupChannelBox::onChange() {
|
2016-10-28 09:20:24 +00:00
|
|
|
QString name = _link->text().trimmed();
|
2015-10-11 08:37:24 +00:00
|
|
|
if (name.isEmpty()) {
|
|
|
|
if (!_errorText.isEmpty() || !_goodText.isEmpty()) {
|
|
|
|
_errorText = _goodText = QString();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
_checkTimer.stop();
|
|
|
|
} else {
|
2016-03-20 08:16:35 +00:00
|
|
|
int32 len = name.size();
|
2015-10-11 08:37:24 +00:00
|
|
|
for (int32 i = 0; i < len; ++i) {
|
|
|
|
QChar ch = name.at(i);
|
|
|
|
if ((ch < 'A' || ch > 'Z') && (ch < 'a' || ch > 'z') && (ch < '0' || ch > '9') && ch != '_') {
|
|
|
|
if (_errorText != lang(lng_create_channel_link_bad_symbols)) {
|
|
|
|
_errorText = lang(lng_create_channel_link_bad_symbols);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
_checkTimer.stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (name.size() < MinUsernameLength) {
|
|
|
|
if (_errorText != lang(lng_create_channel_link_too_short)) {
|
|
|
|
_errorText = lang(lng_create_channel_link_too_short);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
_checkTimer.stop();
|
|
|
|
} else {
|
|
|
|
if (!_errorText.isEmpty() || !_goodText.isEmpty()) {
|
|
|
|
_errorText = _goodText = QString();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
_checkTimer.start(UsernameCheckTimeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupChannelBox::onCheck() {
|
|
|
|
if (_checkRequestId) {
|
|
|
|
MTP::cancel(_checkRequestId);
|
|
|
|
}
|
2016-10-28 09:20:24 +00:00
|
|
|
QString link = _link->text().trimmed();
|
2015-10-11 08:37:24 +00:00
|
|
|
if (link.size() >= MinUsernameLength) {
|
|
|
|
_checkUsername = link;
|
|
|
|
_checkRequestId = MTP::send(MTPchannels_CheckUsername(_channel->inputChannel, MTP_string(link)), rpcDone(&SetupChannelBox::onCheckDone), rpcFail(&SetupChannelBox::onCheckFail));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 21:06:10 +00:00
|
|
|
void SetupChannelBox::privacyChanged(Privacy value) {
|
|
|
|
if (value == Privacy::Public) {
|
2015-10-11 08:37:24 +00:00
|
|
|
if (_tooMuchUsernames) {
|
2017-03-18 21:06:10 +00:00
|
|
|
_privacyGroup->setValue(Privacy::Private);
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<RevokePublicLinkBox>(base::lambda_guarded(this, [this] {
|
2016-08-12 15:22:11 +00:00
|
|
|
_tooMuchUsernames = false;
|
2017-03-18 21:06:10 +00:00
|
|
|
_privacyGroup->setValue(Privacy::Public);
|
2016-08-12 15:22:11 +00:00
|
|
|
onCheck();
|
2017-09-15 17:34:41 +00:00
|
|
|
})), LayerOption::KeepOther);
|
2015-10-11 08:37:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-10-28 09:20:24 +00:00
|
|
|
_link->show();
|
2016-12-20 13:03:51 +00:00
|
|
|
_link->setDisplayFocused(true);
|
2016-10-28 09:20:24 +00:00
|
|
|
_link->setFocus();
|
2015-10-11 08:37:24 +00:00
|
|
|
} else {
|
2016-10-28 09:20:24 +00:00
|
|
|
_link->hide();
|
2015-10-11 08:37:24 +00:00
|
|
|
setFocus();
|
|
|
|
}
|
2016-03-04 16:47:48 +00:00
|
|
|
if (_channel->isMegagroup()) {
|
|
|
|
updateMaxHeight();
|
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupChannelBox::onUpdateDone(const MTPBool &result) {
|
2017-07-06 11:37:42 +00:00
|
|
|
_channel->setName(TextUtilities::SingleLine(_channel->name), _sentUsername);
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SetupChannelBox::onUpdateFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-10-11 08:37:24 +00:00
|
|
|
|
|
|
|
_saveRequestId = 0;
|
|
|
|
QString err(error.type());
|
|
|
|
if (err == "USERNAME_NOT_MODIFIED" || _sentUsername == _channel->username) {
|
2017-07-06 11:37:42 +00:00
|
|
|
_channel->setName(TextUtilities::SingleLine(_channel->name), TextUtilities::SingleLine(_sentUsername));
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2015-10-11 08:37:24 +00:00
|
|
|
return true;
|
|
|
|
} else if (err == "USERNAME_INVALID") {
|
2016-10-28 09:20:24 +00:00
|
|
|
_link->setFocus();
|
|
|
|
_link->showError();
|
2015-10-11 08:37:24 +00:00
|
|
|
_errorText = lang(lng_create_channel_link_invalid);
|
|
|
|
update();
|
|
|
|
return true;
|
|
|
|
} else if (err == "USERNAME_OCCUPIED" || err == "USERNAMES_UNAVAILABLE") {
|
2016-10-28 09:20:24 +00:00
|
|
|
_link->setFocus();
|
|
|
|
_link->showError();
|
2015-10-11 08:37:24 +00:00
|
|
|
_errorText = lang(lng_create_channel_link_occupied);
|
|
|
|
update();
|
|
|
|
return true;
|
|
|
|
}
|
2016-10-28 09:20:24 +00:00
|
|
|
_link->setFocus();
|
2015-10-11 08:37:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupChannelBox::onCheckDone(const MTPBool &result) {
|
|
|
|
_checkRequestId = 0;
|
2015-10-29 00:16:52 +00:00
|
|
|
QString newError = (mtpIsTrue(result) || _checkUsername == _channel->username) ? QString() : lang(lng_create_channel_link_occupied);
|
2015-10-11 08:37:24 +00:00
|
|
|
QString newGood = newError.isEmpty() ? lang(lng_create_channel_link_available) : QString();
|
|
|
|
if (_errorText != newError || _goodText != newGood) {
|
|
|
|
_errorText = newError;
|
|
|
|
_goodText = newGood;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SetupChannelBox::onCheckFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-10-11 08:37:24 +00:00
|
|
|
|
|
|
|
_checkRequestId = 0;
|
|
|
|
QString err(error.type());
|
2016-03-11 15:21:05 +00:00
|
|
|
if (err == qstr("CHANNEL_PUBLIC_GROUP_NA")) {
|
|
|
|
Ui::hideLayer();
|
|
|
|
return true;
|
|
|
|
} else if (err == qstr("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) {
|
2015-10-11 08:37:24 +00:00
|
|
|
if (_existing) {
|
2016-08-12 15:22:11 +00:00
|
|
|
showRevokePublicLinkBoxForEdit();
|
2015-10-11 08:37:24 +00:00
|
|
|
} else {
|
|
|
|
_tooMuchUsernames = true;
|
2017-03-18 21:06:10 +00:00
|
|
|
_privacyGroup->setValue(Privacy::Private);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
return true;
|
2016-03-11 15:21:05 +00:00
|
|
|
} else if (err == qstr("USERNAME_INVALID")) {
|
2015-10-11 08:37:24 +00:00
|
|
|
_errorText = lang(lng_create_channel_link_invalid);
|
|
|
|
update();
|
|
|
|
return true;
|
2016-03-11 15:21:05 +00:00
|
|
|
} else if (err == qstr("USERNAME_OCCUPIED") && _checkUsername != _channel->username) {
|
2015-10-11 08:37:24 +00:00
|
|
|
_errorText = lang(lng_create_channel_link_occupied);
|
|
|
|
update();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
_goodText = QString();
|
2016-10-28 09:20:24 +00:00
|
|
|
_link->setFocus();
|
2015-10-11 08:37:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-12 15:22:11 +00:00
|
|
|
void SetupChannelBox::showRevokePublicLinkBoxForEdit() {
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
|
|
|
Ui::show(Box<RevokePublicLinkBox>([channel = _channel, existing = _existing]() {
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<SetupChannelBox>(channel, existing),
|
|
|
|
LayerOption::KeepOther);
|
|
|
|
}), LayerOption::KeepOther);
|
2016-08-12 15:22:11 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
bool SetupChannelBox::onFirstCheckFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-10-11 08:37:24 +00:00
|
|
|
|
|
|
|
_checkRequestId = 0;
|
|
|
|
QString err(error.type());
|
2016-03-11 15:21:05 +00:00
|
|
|
if (err == qstr("CHANNEL_PUBLIC_GROUP_NA")) {
|
|
|
|
Ui::hideLayer();
|
|
|
|
return true;
|
|
|
|
} else if (err == qstr("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) {
|
2015-10-11 08:37:24 +00:00
|
|
|
if (_existing) {
|
2016-08-12 15:22:11 +00:00
|
|
|
showRevokePublicLinkBoxForEdit();
|
2015-10-11 08:37:24 +00:00
|
|
|
} else {
|
|
|
|
_tooMuchUsernames = true;
|
2017-03-18 21:06:10 +00:00
|
|
|
_privacyGroup->setValue(Privacy::Private);
|
2015-10-11 08:37:24 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
_goodText = QString();
|
2016-10-28 09:20:24 +00:00
|
|
|
_link->setFocus();
|
2015-10-11 08:37:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
EditNameTitleBox::EditNameTitleBox(QWidget*, not_null<PeerData*> peer)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _peer(peer)
|
2017-05-30 15:21:05 +00:00
|
|
|
, _first(this, st::defaultInputField, langFactory(_peer->isUser() ? lng_signup_firstname : lng_dlg_new_group_name), _peer->isUser() ? _peer->asUser()->firstName : _peer->name)
|
|
|
|
, _last(this, st::defaultInputField, langFactory(lng_signup_lastname), peer->isUser() ? peer->asUser()->lastName : QString())
|
2016-12-13 17:07:56 +00:00
|
|
|
, _invertOrder(!peer->isChat() && langFirstNameGoesSecond()) {
|
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void EditNameTitleBox::prepare() {
|
|
|
|
auto newHeight = st::contactPadding.top() + _first->height();
|
2015-10-06 19:49:23 +00:00
|
|
|
if (_peer->isUser()) {
|
2017-05-30 15:21:05 +00:00
|
|
|
setTitle(langFactory(_peer->isSelf() ? lng_edit_self_title : lng_edit_contact_title));
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += st::contactSkip + _last->height();
|
2015-10-06 19:49:23 +00:00
|
|
|
} else if (_peer->isChat()) {
|
2017-05-30 15:21:05 +00:00
|
|
|
setTitle(langFactory(lng_edit_group_title));
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += st::boxPadding.bottom() + st::contactPadding.bottom();
|
|
|
|
setDimensions(st::boxWideWidth, newHeight);
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
addButton(langFactory(lng_settings_save), [this] { onSave(); });
|
|
|
|
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_invertOrder) {
|
|
|
|
setTabOrder(_last, _first);
|
|
|
|
}
|
2017-07-18 15:15:02 +00:00
|
|
|
_first->setMaxLength(kMaxGroupChannelTitle);
|
|
|
|
_last->setMaxLength(kMaxGroupChannelTitle);
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
connect(_first, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
|
|
|
|
connect(_last, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
|
2016-11-18 13:34:58 +00:00
|
|
|
_last->setVisible(!_peer->isChat());
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void EditNameTitleBox::setInnerFocus() {
|
2016-12-20 13:03:51 +00:00
|
|
|
(_invertOrder ? _last : _first)->setFocusFast();
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditNameTitleBox::onSubmit() {
|
2016-10-28 09:20:24 +00:00
|
|
|
if (_first->hasFocus()) {
|
2015-10-06 19:49:23 +00:00
|
|
|
if (_peer->isChat()) {
|
2016-10-28 09:20:24 +00:00
|
|
|
if (_first->getLastText().trimmed().isEmpty()) {
|
|
|
|
_first->setFocus();
|
|
|
|
_first->showError();
|
2015-10-06 19:49:23 +00:00
|
|
|
} else {
|
|
|
|
onSave();
|
|
|
|
}
|
|
|
|
} else {
|
2016-10-28 09:20:24 +00:00
|
|
|
_last->setFocus();
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
2016-10-28 09:20:24 +00:00
|
|
|
} else if (_last->hasFocus()) {
|
|
|
|
if (_first->getLastText().trimmed().isEmpty()) {
|
|
|
|
_first->setFocus();
|
|
|
|
_first->showError();
|
|
|
|
} else if (_last->getLastText().trimmed().isEmpty()) {
|
|
|
|
_last->setFocus();
|
|
|
|
_last->showError();
|
2015-10-06 19:49:23 +00:00
|
|
|
} else {
|
|
|
|
onSave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditNameTitleBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right(), _first->height());
|
|
|
|
_last->resize(_first->size());
|
2015-10-06 19:49:23 +00:00
|
|
|
if (_invertOrder) {
|
2016-12-13 17:07:56 +00:00
|
|
|
_last->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), st::contactPadding.top());
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _last->y() + _last->height() + st::contactSkip);
|
2015-10-06 19:49:23 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
_first->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), st::contactPadding.top());
|
2016-10-28 09:20:24 +00:00
|
|
|
_last->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _first->y() + _first->height() + st::contactSkip);
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditNameTitleBox::onSave() {
|
|
|
|
if (_requestId) return;
|
|
|
|
|
2017-07-06 11:37:42 +00:00
|
|
|
auto first = TextUtilities::PrepareForSending(_first->getLastText());
|
|
|
|
auto last = TextUtilities::PrepareForSending(_last->getLastText());
|
2015-10-06 19:49:23 +00:00
|
|
|
if (first.isEmpty() && last.isEmpty()) {
|
|
|
|
if (_invertOrder) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_last->setFocus();
|
|
|
|
_last->showError();
|
2015-10-06 19:49:23 +00:00
|
|
|
} else {
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->setFocus();
|
|
|
|
_first->showError();
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (first.isEmpty()) {
|
|
|
|
first = last;
|
|
|
|
last = QString();
|
|
|
|
}
|
|
|
|
_sentName = first;
|
|
|
|
if (_peer == App::self()) {
|
2017-03-25 15:42:01 +00:00
|
|
|
auto flags = MTPaccount_UpdateProfile::Flag::f_first_name | MTPaccount_UpdateProfile::Flag::f_last_name;
|
2016-03-19 16:55:15 +00:00
|
|
|
_requestId = MTP::send(MTPaccount_UpdateProfile(MTP_flags(flags), MTP_string(first), MTP_string(last), MTPstring()), rpcDone(&EditNameTitleBox::onSaveSelfDone), rpcFail(&EditNameTitleBox::onSaveSelfFail));
|
2015-10-06 19:49:23 +00:00
|
|
|
} else if (_peer->isChat()) {
|
|
|
|
_requestId = MTP::send(MTPmessages_EditChatTitle(_peer->asChat()->inputChat, MTP_string(first)), rpcDone(&EditNameTitleBox::onSaveChatDone), rpcFail(&EditNameTitleBox::onSaveChatFail));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditNameTitleBox::onSaveSelfDone(const MTPUser &user) {
|
|
|
|
App::feedUsers(MTP_vector<MTPUser>(1, user));
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EditNameTitleBox::onSaveSelfFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2017-07-06 11:37:42 +00:00
|
|
|
auto err = error.type();
|
|
|
|
auto first = TextUtilities::SingleLine(_first->getLastText().trimmed());
|
|
|
|
auto last = TextUtilities::SingleLine(_last->getLastText().trimmed());
|
2015-10-06 19:49:23 +00:00
|
|
|
if (err == "NAME_NOT_MODIFIED") {
|
2017-07-06 11:37:42 +00:00
|
|
|
App::self()->setName(first, last, QString(), TextUtilities::SingleLine(App::self()->username));
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2015-10-06 19:49:23 +00:00
|
|
|
return true;
|
|
|
|
} else if (err == "FIRSTNAME_INVALID") {
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->setFocus();
|
|
|
|
_first->showError();
|
2015-10-06 19:49:23 +00:00
|
|
|
return true;
|
|
|
|
} else if (err == "LASTNAME_INVALID") {
|
2016-10-28 09:20:24 +00:00
|
|
|
_last->setFocus();
|
|
|
|
_last->showError();
|
2015-10-06 19:49:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->setFocus();
|
2015-10-06 19:49:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditNameTitleBox::onSaveChatFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-10-06 19:49:23 +00:00
|
|
|
|
|
|
|
_requestId = 0;
|
|
|
|
QString err(error.type());
|
|
|
|
if (err == qstr("CHAT_TITLE_NOT_MODIFIED") || err == qstr("CHAT_NOT_MODIFIED")) {
|
2016-05-25 12:09:05 +00:00
|
|
|
if (auto chatData = _peer->asChat()) {
|
|
|
|
chatData->setName(_sentName);
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2015-10-06 19:49:23 +00:00
|
|
|
return true;
|
|
|
|
} else if (err == qstr("NO_CHAT_TITLE")) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->setFocus();
|
|
|
|
_first->showError();
|
2015-10-06 19:49:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-10-28 09:20:24 +00:00
|
|
|
_first->setFocus();
|
2015-10-06 19:49:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditNameTitleBox::onSaveChatDone(const MTPUpdates &updates) {
|
|
|
|
App::main()->sentUpdatesReceived(updates);
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2015-10-06 19:49:23 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
EditBioBox::EditBioBox(QWidget*, not_null<UserData*> self) : BoxContent()
|
2017-07-18 15:15:02 +00:00
|
|
|
, _dynamicFieldStyle(CreateBioFieldStyle())
|
|
|
|
, _self(self)
|
|
|
|
, _bio(this, _dynamicFieldStyle, langFactory(lng_bio_placeholder), _self->about())
|
|
|
|
, _countdown(this, QString(), Ui::FlatLabel::InitType::Simple, st::editBioCountdownLabel)
|
|
|
|
, _about(this, lang(lng_bio_about), Ui::FlatLabel::InitType::Simple, st::aboutRevokePublicLabel) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditBioBox::prepare() {
|
|
|
|
setTitle(langFactory(lng_bio_title));
|
|
|
|
|
|
|
|
addButton(langFactory(lng_settings_save), [this] { save(); });
|
|
|
|
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
|
|
|
_bio->setMaxLength(kMaxBioLength);
|
|
|
|
_bio->setCtrlEnterSubmit(Ui::CtrlEnterSubmit::Both);
|
|
|
|
auto cursor = _bio->textCursor();
|
|
|
|
cursor.setPosition(_bio->getLastText().size());
|
|
|
|
_bio->setTextCursor(cursor);
|
|
|
|
connect(_bio, &Ui::InputArea::submitted, this, [this](bool ctrlShiftEnter) { save(); });
|
|
|
|
connect(_bio, &Ui::InputArea::resized, this, [this] { updateMaxHeight(); });
|
|
|
|
connect(_bio, &Ui::InputArea::changed, this, [this] { handleBioUpdated(); });
|
|
|
|
handleBioUpdated();
|
|
|
|
updateMaxHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditBioBox::updateMaxHeight() {
|
|
|
|
auto newHeight = st::contactPadding.top() + _bio->height() + st::boxLittleSkip + _about->height() + st::boxPadding.bottom() + st::contactPadding.bottom();
|
|
|
|
setDimensions(st::boxWideWidth, newHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditBioBox::handleBioUpdated() {
|
|
|
|
auto text = _bio->getLastText();
|
|
|
|
if (text.indexOf('\n') >= 0) {
|
|
|
|
auto position = _bio->textCursor().position();
|
|
|
|
_bio->setText(text.replace('\n', ' '));
|
|
|
|
auto cursor = _bio->textCursor();
|
|
|
|
cursor.setPosition(position);
|
|
|
|
_bio->setTextCursor(cursor);
|
|
|
|
}
|
|
|
|
auto countLeft = qMax(kMaxBioLength - text.size(), 0);
|
|
|
|
_countdown->setText(QString::number(countLeft));
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditBioBox::setInnerFocus() {
|
|
|
|
_bio->setFocusFast();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditBioBox::resizeEvent(QResizeEvent *e) {
|
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
|
|
|
_bio->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right(), _bio->height());
|
|
|
|
_bio->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), st::contactPadding.top());
|
|
|
|
_countdown->moveToRight(st::boxPadding.right(), _bio->y() + _dynamicFieldStyle.textMargins.top());
|
|
|
|
_about->moveToLeft(st::boxPadding.left(), _bio->y() + _bio->height() + st::boxLittleSkip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditBioBox::save() {
|
|
|
|
if (_requestId) return;
|
|
|
|
|
|
|
|
auto text = TextUtilities::PrepareForSending(_bio->getLastText());
|
|
|
|
_sentBio = text;
|
|
|
|
|
|
|
|
auto flags = MTPaccount_UpdateProfile::Flag::f_about;
|
|
|
|
_requestId = request(MTPaccount_UpdateProfile(MTP_flags(flags), MTPstring(), MTPstring(), MTP_string(text))).done([this](const MTPUser &result) {
|
|
|
|
App::feedUsers(MTP_vector<MTPUser>(1, result));
|
|
|
|
_self->setAbout(_sentBio);
|
|
|
|
closeBox();
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
EditChannelBox::EditChannelBox(QWidget*, not_null<ChannelData*> channel)
|
2016-12-13 17:07:56 +00:00
|
|
|
: _channel(channel)
|
2017-05-30 15:21:05 +00:00
|
|
|
, _title(this, st::defaultInputField, langFactory(_channel->isMegagroup() ? lng_dlg_new_group_name : lng_dlg_new_channel_name), _channel->name)
|
|
|
|
, _description(this, st::newGroupDescription, langFactory(lng_create_group_description), _channel->about())
|
2016-06-10 11:18:55 +00:00
|
|
|
, _sign(this, lang(lng_edit_sign_messages), channel->addsSignature(), st::defaultBoxCheckbox)
|
2017-06-16 17:02:27 +00:00
|
|
|
, _inviteGroup(std::make_shared<Ui::RadioenumGroup<Invites>>(channel->anyoneCanAddMembers() ? Invites::Everybody : Invites::OnlyAdmins))
|
|
|
|
, _inviteEverybody(this, _inviteGroup, Invites::Everybody, lang(lng_edit_group_invites_everybody))
|
|
|
|
, _inviteOnlyAdmins(this, _inviteGroup, Invites::OnlyAdmins, lang(lng_edit_group_invites_only_admins))
|
2016-12-13 17:07:56 +00:00
|
|
|
, _publicLink(this, lang(channel->isPublic() ? lng_profile_edit_public_link : lng_profile_create_public_link), st::boxLinkButton) {
|
|
|
|
}
|
2015-09-23 17:43:08 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void EditChannelBox::prepare() {
|
2017-05-30 15:21:05 +00:00
|
|
|
setTitle(langFactory(_channel->isMegagroup() ? lng_edit_group : lng_edit_channel_title));
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
addButton(langFactory(lng_settings_save), [this] { onSave(); });
|
|
|
|
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2017-08-11 10:42:52 +00:00
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::NameChanged, [this](const Notify::PeerUpdate &update) {
|
|
|
|
if (update.peer == _channel) {
|
|
|
|
handleChannelNameChange();
|
|
|
|
}
|
|
|
|
}));
|
2016-11-19 14:47:28 +00:00
|
|
|
|
2015-09-21 20:57:42 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
|
2017-07-18 15:15:02 +00:00
|
|
|
_title->setMaxLength(kMaxGroupChannelTitle);
|
|
|
|
_description->setMaxLength(kMaxChannelDescription);
|
2015-09-21 20:57:42 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
connect(_description, SIGNAL(resized()), this, SLOT(onDescriptionResized()));
|
|
|
|
connect(_description, SIGNAL(submitted(bool)), this, SLOT(onSave()));
|
|
|
|
connect(_description, SIGNAL(cancelled()), this, SLOT(onClose()));
|
2015-09-21 20:57:42 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
connect(_publicLink, SIGNAL(clicked()), this, SLOT(onPublicLink()));
|
2016-11-18 13:34:58 +00:00
|
|
|
_publicLink->setVisible(_channel->canEditUsername());
|
2017-06-09 16:12:02 +00:00
|
|
|
_sign->setVisible(canEditSignatures());
|
2017-06-28 12:44:26 +00:00
|
|
|
_inviteEverybody->setVisible(canEditInvites());
|
|
|
|
_inviteOnlyAdmins->setVisible(canEditInvites());
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
updateMaxHeight();
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void EditChannelBox::setInnerFocus() {
|
2016-12-20 13:03:51 +00:00
|
|
|
_title->setFocusFast();
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditChannelBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
2016-10-28 09:20:24 +00:00
|
|
|
if (_title->hasFocus()) {
|
2015-09-21 20:57:42 +00:00
|
|
|
onSave();
|
|
|
|
}
|
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::keyPressEvent(e);
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 10:42:52 +00:00
|
|
|
void EditChannelBox::handleChannelNameChange() {
|
|
|
|
_publicLink->setText(lang(_channel->isPublic() ? lng_profile_edit_public_link : lng_profile_create_public_link));
|
|
|
|
_sign->setChecked(_channel->addsSignature());
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 20:57:42 +00:00
|
|
|
void EditChannelBox::onDescriptionResized() {
|
|
|
|
updateMaxHeight();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-06-09 16:12:02 +00:00
|
|
|
bool EditChannelBox::canEditSignatures() const {
|
2017-06-16 17:02:27 +00:00
|
|
|
return _channel->canEditInformation() && !_channel->isMegagroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditChannelBox::canEditInvites() const {
|
|
|
|
return _channel->canEditInformation() && _channel->isMegagroup();
|
2017-06-09 16:12:02 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 20:57:42 +00:00
|
|
|
void EditChannelBox::updateMaxHeight() {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto newHeight = st::newGroupInfoPadding.top() + _title->height();
|
|
|
|
newHeight += st::newGroupDescriptionPadding.top() + _description->height() + st::newGroupDescriptionPadding.bottom();
|
2017-06-09 16:12:02 +00:00
|
|
|
if (canEditSignatures()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += st::newGroupPublicLinkPadding.top() + _sign->heightNoMargins() + st::newGroupPublicLinkPadding.bottom();
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
2017-06-16 17:02:27 +00:00
|
|
|
if (canEditInvites()) {
|
|
|
|
newHeight += st::boxTitleHeight + _inviteEverybody->heightNoMargins();
|
|
|
|
newHeight += st::boxLittleSkip + _inviteOnlyAdmins->heightNoMargins();
|
|
|
|
}
|
2016-03-11 15:21:05 +00:00
|
|
|
if (_channel->canEditUsername()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += st::newGroupPublicLinkPadding.top() + _publicLink->height() + st::newGroupPublicLinkPadding.bottom();
|
2016-03-04 22:04:15 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += st::boxPadding.bottom() + st::newGroupInfoPadding.bottom();
|
|
|
|
setDimensions(st::boxWideWidth, newHeight);
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditChannelBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
_title->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right(), _title->height());
|
2016-12-13 17:07:56 +00:00
|
|
|
_title->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), st::newGroupInfoPadding.top() + st::newGroupNamePosition.y());
|
2015-09-21 20:57:42 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
_description->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right(), _description->height());
|
2016-10-28 09:20:24 +00:00
|
|
|
_description->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _title->y() + _title->height() + st::newGroupDescriptionPadding.top());
|
2015-09-21 20:57:42 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
_sign->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description->y() + _description->height() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top());
|
2016-02-21 12:30:16 +00:00
|
|
|
|
2017-06-16 17:02:27 +00:00
|
|
|
_inviteEverybody->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description->y() + _description->height() + st::boxTitleHeight);
|
|
|
|
_inviteOnlyAdmins->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _inviteEverybody->bottomNoMargins() + st::boxLittleSkip);
|
|
|
|
|
2017-06-09 16:12:02 +00:00
|
|
|
if (canEditSignatures()) {
|
2016-12-02 19:16:35 +00:00
|
|
|
_publicLink->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _sign->bottomNoMargins() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top());
|
2017-06-16 17:02:27 +00:00
|
|
|
} else if (canEditInvites()) {
|
|
|
|
_publicLink->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _inviteOnlyAdmins->bottomNoMargins() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top());
|
2017-06-09 16:12:02 +00:00
|
|
|
} else {
|
|
|
|
_publicLink->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description->y() + _description->height() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top());
|
2016-03-04 16:47:48 +00:00
|
|
|
}
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 17:02:27 +00:00
|
|
|
void EditChannelBox::paintEvent(QPaintEvent *e) {
|
|
|
|
BoxContent::paintEvent(e);
|
|
|
|
|
|
|
|
if (canEditInvites()) {
|
|
|
|
Painter p(this);
|
|
|
|
p.setPen(st::boxTitleFg);
|
|
|
|
p.setFont(st::autoDownloadTitleFont);
|
|
|
|
p.drawTextLeft(st::boxTitlePosition.x(), _description->y() + _description->height() + st::boxTitlePosition.y(), width(), lang(lng_edit_group_who_invites));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 20:57:42 +00:00
|
|
|
void EditChannelBox::onSave() {
|
2017-06-16 17:02:27 +00:00
|
|
|
if (_saveTitleRequestId || _saveDescriptionRequestId || _saveSignRequestId || _saveInvitesRequestId) return;
|
2015-09-21 20:57:42 +00:00
|
|
|
|
2017-07-06 11:37:42 +00:00
|
|
|
auto title = TextUtilities::PrepareForSending(_title->getLastText());
|
|
|
|
auto description = TextUtilities::PrepareForSending(_description->getLastText(), TextUtilities::PrepareTextOption::CheckLinks);
|
2015-09-21 20:57:42 +00:00
|
|
|
if (title.isEmpty()) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_title->setFocus();
|
|
|
|
_title->showError();
|
2015-09-21 20:57:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
_sentTitle = title;
|
|
|
|
_sentDescription = description;
|
2016-02-21 12:30:16 +00:00
|
|
|
if (_sentTitle == _channel->name) {
|
|
|
|
saveDescription();
|
|
|
|
} else {
|
|
|
|
_saveTitleRequestId = MTP::send(MTPchannels_EditTitle(_channel->inputChannel, MTP_string(_sentTitle)), rpcDone(&EditChannelBox::onSaveTitleDone), rpcFail(&EditChannelBox::onSaveFail));
|
|
|
|
}
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
|
2015-09-23 17:43:08 +00:00
|
|
|
void EditChannelBox::onPublicLink() {
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<SetupChannelBox>(_channel, true),
|
|
|
|
LayerOption::KeepOther);
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 20:57:42 +00:00
|
|
|
void EditChannelBox::saveDescription() {
|
2016-05-31 19:27:11 +00:00
|
|
|
if (_sentDescription == _channel->about()) {
|
2016-02-21 12:30:16 +00:00
|
|
|
saveSign();
|
|
|
|
} else {
|
|
|
|
_saveDescriptionRequestId = MTP::send(MTPchannels_EditAbout(_channel->inputChannel, MTP_string(_sentDescription)), rpcDone(&EditChannelBox::onSaveDescriptionDone), rpcFail(&EditChannelBox::onSaveFail));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditChannelBox::saveSign() {
|
2017-06-09 16:12:02 +00:00
|
|
|
if (!canEditSignatures() || _channel->addsSignature() == _sign->checked()) {
|
2017-06-16 17:02:27 +00:00
|
|
|
saveInvites();
|
2016-02-21 12:30:16 +00:00
|
|
|
} else {
|
2016-10-28 09:20:24 +00:00
|
|
|
_saveSignRequestId = MTP::send(MTPchannels_ToggleSignatures(_channel->inputChannel, MTP_bool(_sign->checked())), rpcDone(&EditChannelBox::onSaveSignDone), rpcFail(&EditChannelBox::onSaveFail));
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 17:02:27 +00:00
|
|
|
void EditChannelBox::saveInvites() {
|
|
|
|
if (!canEditInvites() || _channel->anyoneCanAddMembers() == (_inviteGroup->value() == Invites::Everybody)) {
|
|
|
|
closeBox();
|
|
|
|
} else {
|
|
|
|
_saveInvitesRequestId = MTP::send(MTPchannels_ToggleInvites(_channel->inputChannel, MTP_bool(_inviteGroup->value() == Invites::Everybody)), rpcDone(&EditChannelBox::onSaveInvitesDone), rpcFail(&EditChannelBox::onSaveFail));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 20:57:42 +00:00
|
|
|
bool EditChannelBox::onSaveFail(const RPCError &error, mtpRequestId req) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-09-21 20:57:42 +00:00
|
|
|
|
|
|
|
QString err(error.type());
|
|
|
|
if (req == _saveTitleRequestId) {
|
|
|
|
_saveTitleRequestId = 0;
|
|
|
|
if (err == qstr("CHAT_NOT_MODIFIED") || err == qstr("CHAT_TITLE_NOT_MODIFIED")) {
|
|
|
|
_channel->setName(_sentTitle, _channel->username);
|
|
|
|
saveDescription();
|
|
|
|
return true;
|
|
|
|
} else if (err == qstr("NO_CHAT_TITLE")) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_title->setFocus();
|
|
|
|
_title->showError();
|
2015-09-21 20:57:42 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2016-10-28 09:20:24 +00:00
|
|
|
_title->setFocus();
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
} else if (req == _saveDescriptionRequestId) {
|
|
|
|
_saveDescriptionRequestId = 0;
|
|
|
|
if (err == qstr("CHAT_ABOUT_NOT_MODIFIED")) {
|
2016-05-31 19:27:11 +00:00
|
|
|
if (_channel->setAbout(_sentDescription)) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().fullPeerUpdated().notify(_channel);
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
saveSign();
|
|
|
|
return true;
|
2015-09-21 20:57:42 +00:00
|
|
|
} else {
|
2016-10-28 09:20:24 +00:00
|
|
|
_description->setFocus();
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
2016-02-21 12:30:16 +00:00
|
|
|
} else if (req == _saveSignRequestId) {
|
|
|
|
_saveSignRequestId = 0;
|
2017-06-16 17:02:27 +00:00
|
|
|
if (err == qstr("CHAT_NOT_MODIFIED")) {
|
|
|
|
saveInvites();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (req == _saveInvitesRequestId) {
|
|
|
|
_saveInvitesRequestId = 0;
|
2016-02-21 12:30:16 +00:00
|
|
|
if (err == qstr("CHAT_NOT_MODIFIED")) {
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2016-02-21 12:30:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-16 17:02:27 +00:00
|
|
|
void EditChannelBox::onSaveTitleDone(const MTPUpdates &result) {
|
2015-09-21 20:57:42 +00:00
|
|
|
_saveTitleRequestId = 0;
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().applyUpdates(result);
|
2015-09-21 20:57:42 +00:00
|
|
|
saveDescription();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditChannelBox::onSaveDescriptionDone(const MTPBool &result) {
|
|
|
|
_saveDescriptionRequestId = 0;
|
2016-05-31 19:27:11 +00:00
|
|
|
if (_channel->setAbout(_sentDescription)) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().fullPeerUpdated().notify(_channel);
|
2016-02-21 12:30:16 +00:00
|
|
|
}
|
|
|
|
saveSign();
|
|
|
|
}
|
|
|
|
|
2017-06-16 17:02:27 +00:00
|
|
|
void EditChannelBox::onSaveSignDone(const MTPUpdates &result) {
|
2016-02-21 12:30:16 +00:00
|
|
|
_saveSignRequestId = 0;
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().applyUpdates(result);
|
2017-06-16 17:02:27 +00:00
|
|
|
saveInvites();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditChannelBox::onSaveInvitesDone(const MTPUpdates &result) {
|
|
|
|
_saveSignRequestId = 0;
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().applyUpdates(result);
|
2016-12-13 17:07:56 +00:00
|
|
|
closeBox();
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
2016-02-21 12:30:16 +00:00
|
|
|
|
2017-07-03 13:57:46 +00:00
|
|
|
RevokePublicLinkBox::Inner::Inner(QWidget *parent, base::lambda<void()> revokeCallback) : TWidget(parent)
|
|
|
|
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom())
|
2016-08-12 15:22:11 +00:00
|
|
|
, _revokeWidth(st::normalFont->width(lang(lng_channels_too_much_public_revoke)))
|
2017-02-21 13:45:56 +00:00
|
|
|
, _revokeCallback(std::move(revokeCallback)) {
|
2017-07-03 13:57:46 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
|
|
|
|
resize(width(), 5 * _rowHeight);
|
|
|
|
|
|
|
|
request(MTPchannels_GetAdminedPublicChannels()).done([this](const MTPmessages_Chats &result) {
|
|
|
|
if (auto chats = Api::getChatsFromMessagesChats(result)) {
|
|
|
|
for_const (auto &chat, chats->v) {
|
|
|
|
if (auto peer = App::feedChat(chat)) {
|
|
|
|
if (!peer->isChannel() || peer->userName().isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto row = ChatRow(peer);
|
|
|
|
row.peer = peer;
|
|
|
|
row.name.setText(st::contactsNameStyle, peer->name, _textNameOptions);
|
|
|
|
row.status.setText(st::defaultTextStyle, Messenger::Instance().createInternalLink(textcmdLink(1, peer->userName())), _textDlgOptions);
|
|
|
|
_rows.push_back(std::move(row));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resize(width(), _rows.size() * _rowHeight);
|
|
|
|
update();
|
|
|
|
}).send();
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 13:57:46 +00:00
|
|
|
RevokePublicLinkBox::RevokePublicLinkBox(QWidget*, base::lambda<void()> revokeCallback)
|
|
|
|
: _aboutRevoke(this, lang(lng_channels_too_much_public_about), Ui::FlatLabel::InitType::Simple, st::aboutRevokePublicLabel)
|
|
|
|
, _revokeCallback(std::move(revokeCallback)) {
|
|
|
|
}
|
2016-08-12 15:22:11 +00:00
|
|
|
|
2017-07-03 13:57:46 +00:00
|
|
|
void RevokePublicLinkBox::prepare() {
|
|
|
|
_innerTop = st::boxPadding.top() + _aboutRevoke->height() + st::boxPadding.top();
|
|
|
|
_inner = setInnerWidget(object_ptr<Inner>(this, [this] {
|
|
|
|
closeBox();
|
|
|
|
if (_revokeCallback) {
|
|
|
|
_revokeCallback();
|
|
|
|
}
|
|
|
|
}), st::boxLayerScroll, _innerTop);
|
2016-08-12 15:22:11 +00:00
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
2016-08-12 15:22:11 +00:00
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
subscribe(Auth().downloaderTaskFinished(), [this] { update(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2017-07-03 13:57:46 +00:00
|
|
|
_inner->resizeToWidth(st::boxWideWidth);
|
|
|
|
setDimensions(st::boxWideWidth, _innerTop + _inner->height());
|
2016-08-12 15:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 13:57:46 +00:00
|
|
|
void RevokePublicLinkBox::Inner::mouseMoveEvent(QMouseEvent *e) {
|
2016-08-12 15:22:11 +00:00
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
|
2017-07-03 13:57:46 +00:00
|
|
|
void RevokePublicLinkBox::Inner::updateSelected() {
|
2016-08-12 15:22:11 +00:00
|
|
|
auto point = mapFromGlobal(QCursor::pos());
|
|
|
|
PeerData *selected = nullptr;
|
|
|
|
auto top = _rowsTop;
|
|
|
|
for_const (auto &row, _rows) {
|
|
|
|
auto revokeLink = rtlrect(width() - st::contactsPadding.right() - st::contactsCheckPosition.x() - _revokeWidth, top + st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, _revokeWidth, st::normalFont->height, width());
|
|
|
|
if (revokeLink.contains(point)) {
|
|
|
|
selected = row.peer;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
top += _rowHeight;
|
|
|
|
}
|
|
|
|
if (selected != _selected) {
|
|
|
|
_selected = selected;
|
|
|
|
setCursor((_selected || _pressed) ? style::cur_pointer : style::cur_default);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-03 13:57:46 +00:00
|
|
|
void RevokePublicLinkBox::Inner::mousePressEvent(QMouseEvent *e) {
|
2016-08-12 15:22:11 +00:00
|
|
|
if (_pressed != _selected) {
|
|
|
|
_pressed = _selected;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-03 13:57:46 +00:00
|
|
|
void RevokePublicLinkBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
2016-10-07 16:45:45 +00:00
|
|
|
auto pressed = base::take(_pressed);
|
2016-08-12 15:22:11 +00:00
|
|
|
setCursor((_selected || _pressed) ? style::cur_pointer : style::cur_default);
|
2016-09-03 14:18:46 +00:00
|
|
|
if (pressed && pressed == _selected) {
|
2016-08-12 15:22:11 +00:00
|
|
|
auto text_method = pressed->isMegagroup() ? lng_channels_too_much_public_revoke_confirm_group : lng_channels_too_much_public_revoke_confirm_channel;
|
2017-03-10 17:25:43 +00:00
|
|
|
auto text = text_method(lt_link, Messenger::Instance().createInternalLink(pressed->userName()), lt_group, pressed->name);
|
2016-12-13 17:07:56 +00:00
|
|
|
auto confirmText = lang(lng_channels_too_much_public_revoke);
|
|
|
|
_weakRevokeConfirmBox = Ui::show(Box<ConfirmBox>(text, confirmText, base::lambda_guarded(this, [this, pressed]() {
|
2016-08-12 15:22:11 +00:00
|
|
|
if (_revokeRequestId) return;
|
2017-07-03 13:57:46 +00:00
|
|
|
_revokeRequestId = request(MTPchannels_UpdateUsername(pressed->asChannel()->inputChannel, MTP_string(""))).done([this](const MTPBool &result) {
|
|
|
|
if (_weakRevokeConfirmBox) {
|
|
|
|
_weakRevokeConfirmBox->closeBox();
|
|
|
|
}
|
|
|
|
if (_revokeCallback) {
|
|
|
|
_revokeCallback();
|
|
|
|
}
|
|
|
|
}).send();
|
2017-09-15 17:34:41 +00:00
|
|
|
})), LayerOption::KeepOther);
|
2016-08-12 15:22:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-03 13:57:46 +00:00
|
|
|
void RevokePublicLinkBox::Inner::paintEvent(QPaintEvent *e) {
|
2016-11-19 14:47:28 +00:00
|
|
|
Painter p(this);
|
2016-08-12 15:22:11 +00:00
|
|
|
p.translate(0, _rowsTop);
|
|
|
|
for_const (auto &row, _rows) {
|
2016-12-20 13:03:51 +00:00
|
|
|
paintChat(p, row, (row.peer == _selected));
|
2016-08-12 15:22:11 +00:00
|
|
|
p.translate(0, _rowHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RevokePublicLinkBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2016-08-12 15:22:11 +00:00
|
|
|
_aboutRevoke->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
|
|
|
|
}
|
|
|
|
|
2017-07-03 13:57:46 +00:00
|
|
|
void RevokePublicLinkBox::Inner::paintChat(Painter &p, const ChatRow &row, bool selected) const {
|
2016-08-12 15:22:11 +00:00
|
|
|
auto peer = row.peer;
|
2016-12-29 09:03:51 +00:00
|
|
|
peer->paintUserpicLeft(p, st::contactsPadding.left(), st::contactsPadding.top(), width(), st::contactsPhotoSize);
|
2016-08-12 15:22:11 +00:00
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::contactsNameFg);
|
2016-08-12 15:22:11 +00:00
|
|
|
|
|
|
|
int32 namex = st::contactsPadding.left() + st::contactsPhotoSize + st::contactsPadding.left();
|
|
|
|
int32 namew = width() - namex - st::contactsPadding.right() - (_revokeWidth + st::contactsCheckPosition.x() * 2);
|
|
|
|
if (peer->isVerified()) {
|
2016-09-30 12:52:03 +00:00
|
|
|
auto icon = &st::dialogsVerifiedIcon;
|
|
|
|
namew -= icon->width();
|
|
|
|
icon->paint(p, namex + qMin(row.name.maxWidth(), namew), st::contactsPadding.top() + st::contactsNameTop, width());
|
2016-08-12 15:22:11 +00:00
|
|
|
}
|
|
|
|
row.name.drawLeftElided(p, namex, st::contactsPadding.top() + st::contactsNameTop, namew, width());
|
|
|
|
|
|
|
|
p.setFont(selected ? st::linkOverFont : st::linkFont);
|
2016-12-20 13:03:51 +00:00
|
|
|
p.setPen(selected ? st::defaultLinkButton.overColor : st::defaultLinkButton.color);
|
2016-08-12 15:22:11 +00:00
|
|
|
p.drawTextRight(st::contactsPadding.right() + st::contactsCheckPosition.x(), st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, width(), lang(lng_channels_too_much_public_revoke), _revokeWidth);
|
|
|
|
|
|
|
|
p.setPen(st::contactsStatusFg);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setTextPalette(st::revokePublicLinkStatusPalette);
|
2016-08-12 15:22:11 +00:00
|
|
|
row.status.drawLeftElided(p, namex, st::contactsPadding.top() + st::contactsStatusTop, namew, width());
|
2016-12-23 13:21:01 +00:00
|
|
|
p.restoreTextPalette();
|
2016-08-12 15:22:11 +00:00
|
|
|
}
|