Use EditPeerInfoBox for editing groups.

This allows to edit group invite links.
Rename EditNameTitleBox to EditNameBox, used only from Settings.
This commit is contained in:
John Preston 2017-12-02 16:04:22 +04:00
parent da77c10f60
commit 8391d43057
8 changed files with 245 additions and 171 deletions

View File

@ -618,7 +618,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
"lng_info_channel_title" = "Channel Info"; "lng_info_channel_title" = "Channel Info";
"lng_profile_enable_notifications" = "Notifications"; "lng_profile_enable_notifications" = "Notifications";
"lng_profile_send_message" = "Send Message"; "lng_profile_send_message" = "Send Message";
"lng_profile_edit_group_name" = "Edit group name";
"lng_info_add_as_contact" = "Add as contact"; "lng_info_add_as_contact" = "Add as contact";
"lng_profile_shared_media" = "Shared media"; "lng_profile_shared_media" = "Shared media";
"lng_media_type_photos" = "Photos"; "lng_media_type_photos" = "Photos";
@ -1130,7 +1129,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
"lng_contact_phone" = "Phone number"; "lng_contact_phone" = "Phone number";
"lng_enter_contact_data" = "New Contact"; "lng_enter_contact_data" = "New Contact";
"lng_edit_group_title" = "Edit group name";
"lng_edit_contact_title" = "Edit contact name"; "lng_edit_contact_title" = "Edit contact name";
"lng_edit_channel_title" = "Edit channel"; "lng_edit_channel_title" = "Edit channel";
"lng_edit_sign_messages" = "Sign messages"; "lng_edit_sign_messages" = "Sign messages";

View File

@ -929,25 +929,23 @@ bool SetupChannelBox::onFirstCheckFail(const RPCError &error) {
return true; return true;
} }
EditNameTitleBox::EditNameTitleBox(QWidget*, not_null<PeerData*> peer) EditNameBox::EditNameBox(QWidget*, not_null<UserData*> user)
: _peer(peer) : _user(user)
, _first(this, st::defaultInputField, langFactory(_peer->isUser() ? lng_signup_firstname : lng_dlg_new_group_name), _peer->isUser() ? _peer->asUser()->firstName : _peer->name) , _first(this, st::defaultInputField, langFactory(lng_signup_firstname), _user->firstName)
, _last(this, st::defaultInputField, langFactory(lng_signup_lastname), peer->isUser() ? peer->asUser()->lastName : QString()) , _last(this, st::defaultInputField, langFactory(lng_signup_lastname), _user->lastName)
, _invertOrder(!peer->isChat() && langFirstNameGoesSecond()) { , _invertOrder(langFirstNameGoesSecond()) {
} }
void EditNameTitleBox::prepare() { void EditNameBox::prepare() {
auto newHeight = st::contactPadding.top() + _first->height(); auto newHeight = st::contactPadding.top() + _first->height();
if (_peer->isUser()) {
setTitle(langFactory(_peer->isSelf() ? lng_edit_self_title : lng_edit_contact_title)); setTitle(langFactory(lng_edit_self_title));
newHeight += st::contactSkip + _last->height(); newHeight += st::contactSkip + _last->height();
} else if (_peer->isChat()) {
setTitle(langFactory(lng_edit_group_title));
}
newHeight += st::boxPadding.bottom() + st::contactPadding.bottom(); newHeight += st::boxPadding.bottom() + st::contactPadding.bottom();
setDimensions(st::boxWideWidth, newHeight); setDimensions(st::boxWideWidth, newHeight);
addButton(langFactory(lng_settings_save), [this] { onSave(); }); addButton(langFactory(lng_settings_save), [this] { save(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); }); addButton(langFactory(lng_cancel), [this] { closeBox(); });
if (_invertOrder) { if (_invertOrder) {
setTabOrder(_last, _first); setTabOrder(_last, _first);
@ -955,27 +953,17 @@ void EditNameTitleBox::prepare() {
_first->setMaxLength(kMaxGroupChannelTitle); _first->setMaxLength(kMaxGroupChannelTitle);
_last->setMaxLength(kMaxGroupChannelTitle); _last->setMaxLength(kMaxGroupChannelTitle);
connect(_first, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); connect(_first, &Ui::InputField::submitted, this, [this] { submit(); });
connect(_last, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); connect(_last, &Ui::InputField::submitted, this, [this] { submit(); });
_last->setVisible(!_peer->isChat());
} }
void EditNameTitleBox::setInnerFocus() { void EditNameBox::setInnerFocus() {
(_invertOrder ? _last : _first)->setFocusFast(); (_invertOrder ? _last : _first)->setFocusFast();
} }
void EditNameTitleBox::onSubmit() { void EditNameBox::submit() {
if (_first->hasFocus()) { if (_first->hasFocus()) {
if (_peer->isChat()) { _last->setFocus();
if (_first->getLastText().trimmed().isEmpty()) {
_first->setFocus();
_first->showError();
} else {
onSave();
}
} else {
_last->setFocus();
}
} else if (_last->hasFocus()) { } else if (_last->hasFocus()) {
if (_first->getLastText().trimmed().isEmpty()) { if (_first->getLastText().trimmed().isEmpty()) {
_first->setFocus(); _first->setFocus();
@ -984,12 +972,12 @@ void EditNameTitleBox::onSubmit() {
_last->setFocus(); _last->setFocus();
_last->showError(); _last->showError();
} else { } else {
onSave(); save();
} }
} }
} }
void EditNameTitleBox::resizeEvent(QResizeEvent *e) { void EditNameBox::resizeEvent(QResizeEvent *e) {
BoxContent::resizeEvent(e); BoxContent::resizeEvent(e);
_first->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right(), _first->height()); _first->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right(), _first->height());
@ -1003,7 +991,7 @@ void EditNameTitleBox::resizeEvent(QResizeEvent *e) {
} }
} }
void EditNameTitleBox::onSave() { void EditNameBox::save() {
if (_requestId) return; if (_requestId) return;
auto first = TextUtilities::PrepareForSending(_first->getLastText()); auto first = TextUtilities::PrepareForSending(_first->getLastText());
@ -1023,27 +1011,31 @@ void EditNameTitleBox::onSave() {
last = QString(); last = QString();
} }
_sentName = first; _sentName = first;
if (_peer == App::self()) { auto flags = MTPaccount_UpdateProfile::Flag::f_first_name
auto flags = MTPaccount_UpdateProfile::Flag::f_first_name | MTPaccount_UpdateProfile::Flag::f_last_name; | MTPaccount_UpdateProfile::Flag::f_last_name;
_requestId = MTP::send(MTPaccount_UpdateProfile(MTP_flags(flags), MTP_string(first), MTP_string(last), MTPstring()), rpcDone(&EditNameTitleBox::onSaveSelfDone), rpcFail(&EditNameTitleBox::onSaveSelfFail)); _requestId = MTP::send(
} else if (_peer->isChat()) { MTPaccount_UpdateProfile(
_requestId = MTP::send(MTPmessages_EditChatTitle(_peer->asChat()->inputChat, MTP_string(first)), rpcDone(&EditNameTitleBox::onSaveChatDone), rpcFail(&EditNameTitleBox::onSaveChatFail)); MTP_flags(flags),
} MTP_string(first),
MTP_string(last),
MTPstring()),
rpcDone(&EditNameBox::saveSelfDone),
rpcFail(&EditNameBox::saveSelfFail));
} }
void EditNameTitleBox::onSaveSelfDone(const MTPUser &user) { void EditNameBox::saveSelfDone(const MTPUser &user) {
App::feedUsers(MTP_vector<MTPUser>(1, user)); App::feedUsers(MTP_vector<MTPUser>(1, user));
closeBox(); closeBox();
} }
bool EditNameTitleBox::onSaveSelfFail(const RPCError &error) { bool EditNameBox::saveSelfFail(const RPCError &error) {
if (MTP::isDefaultHandledError(error)) return false; if (MTP::isDefaultHandledError(error)) return false;
auto err = error.type(); auto err = error.type();
auto first = TextUtilities::SingleLine(_first->getLastText().trimmed()); auto first = TextUtilities::SingleLine(_first->getLastText().trimmed());
auto last = TextUtilities::SingleLine(_last->getLastText().trimmed()); auto last = TextUtilities::SingleLine(_last->getLastText().trimmed());
if (err == "NAME_NOT_MODIFIED") { if (err == "NAME_NOT_MODIFIED") {
App::self()->setName(first, last, QString(), TextUtilities::SingleLine(App::self()->username)); _user->setName(first, last, QString(), TextUtilities::SingleLine(_user->username));
closeBox(); closeBox();
return true; return true;
} else if (err == "FIRSTNAME_INVALID") { } else if (err == "FIRSTNAME_INVALID") {
@ -1059,31 +1051,6 @@ bool EditNameTitleBox::onSaveSelfFail(const RPCError &error) {
return true; return true;
} }
bool EditNameTitleBox::onSaveChatFail(const RPCError &error) {
if (MTP::isDefaultHandledError(error)) return false;
_requestId = 0;
QString err(error.type());
if (err == qstr("CHAT_TITLE_NOT_MODIFIED") || err == qstr("CHAT_NOT_MODIFIED")) {
if (auto chatData = _peer->asChat()) {
chatData->setName(_sentName);
}
closeBox();
return true;
} else if (err == qstr("NO_CHAT_TITLE")) {
_first->setFocus();
_first->showError();
return true;
}
_first->setFocus();
return true;
}
void EditNameTitleBox::onSaveChatDone(const MTPUpdates &updates) {
App::main()->sentUpdatesReceived(updates);
closeBox();
}
EditBioBox::EditBioBox(QWidget*, not_null<UserData*> self) : BoxContent() EditBioBox::EditBioBox(QWidget*, not_null<UserData*> self) : BoxContent()
, _dynamicFieldStyle(CreateBioFieldStyle()) , _dynamicFieldStyle(CreateBioFieldStyle())
, _self(self) , _self(self)

View File

@ -198,11 +198,9 @@ private:
}; };
class EditNameTitleBox : public BoxContent, public RPCSender { class EditNameBox : public BoxContent, public RPCSender {
Q_OBJECT
public: public:
EditNameTitleBox(QWidget*, not_null<PeerData*> peer); EditNameBox(QWidget*, not_null<UserData*> user);
protected: protected:
void setInnerFocus() override; void setInnerFocus() override;
@ -210,18 +208,13 @@ protected:
void resizeEvent(QResizeEvent *e) override; void resizeEvent(QResizeEvent *e) override;
private slots:
void onSave();
void onSubmit();
private: private:
void onSaveSelfDone(const MTPUser &user); void submit();
bool onSaveSelfFail(const RPCError &error); void save();
void saveSelfDone(const MTPUser &user);
bool saveSelfFail(const RPCError &error);
void onSaveChatDone(const MTPUpdates &updates); not_null<UserData*> _user;
bool onSaveChatFail(const RPCError &e);
not_null<PeerData*> _peer;
object_ptr<Ui::InputField> _first; object_ptr<Ui::InputField> _first;
object_ptr<Ui::InputField> _last; object_ptr<Ui::InputField> _last;

View File

@ -703,7 +703,9 @@ void EditChatAdminsBoxController::Start(not_null<ChatData*> chat) {
}); });
box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); }); box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); });
}; };
Ui::show(Box<PeerListBox>(std::move(controller), std::move(initBox))); Ui::show(
Box<PeerListBox>(std::move(controller), std::move(initBox)),
LayerOption::KeepOther);
} }
void AddBotToGroupBoxController::Start(not_null<UserData*> bot) { void AddBotToGroupBoxController::Start(not_null<UserData*> bot) {

View File

@ -35,6 +35,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "boxes/photo_crop_box.h" #include "boxes/photo_crop_box.h"
#include "boxes/add_contact_box.h" #include "boxes/add_contact_box.h"
#include "boxes/stickers_box.h" #include "boxes/stickers_box.h"
#include "boxes/peer_list_controllers.h"
#include "mtproto/sender.h" #include "mtproto/sender.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "mainwidget.h" #include "mainwidget.h"
@ -56,7 +57,7 @@ class Controller
public: public:
Controller( Controller(
not_null<BoxContent*> box, not_null<BoxContent*> box,
not_null<ChannelData*> channel); not_null<PeerData*> peer);
object_ptr<Ui::VerticalLayout> createContent(); object_ptr<Ui::VerticalLayout> createContent();
void setFocus(); void setFocus();
@ -123,8 +124,12 @@ private:
object_ptr<Ui::RpWidget> createSignaturesEdit(); object_ptr<Ui::RpWidget> createSignaturesEdit();
object_ptr<Ui::RpWidget> createInvitesEdit(); object_ptr<Ui::RpWidget> createInvitesEdit();
object_ptr<Ui::RpWidget> createStickersEdit(); object_ptr<Ui::RpWidget> createStickersEdit();
object_ptr<Ui::RpWidget> createManageAdminsButton();
object_ptr<Ui::RpWidget> createUpgradeButton();
object_ptr<Ui::RpWidget> createDeleteButton(); object_ptr<Ui::RpWidget> createDeleteButton();
QString inviteLinkText() const;
void submitTitle(); void submitTitle();
void submitDescription(); void submitDescription();
void deleteWithConfirmation(); void deleteWithConfirmation();
@ -169,8 +174,8 @@ private:
void cancelSave(); void cancelSave();
not_null<BoxContent*> _box; not_null<BoxContent*> _box;
not_null<ChannelData*> _channel; not_null<PeerData*> _peer;
bool _isGroup; bool _isGroup = false;
base::unique_qptr<Ui::VerticalLayout> _wrap; base::unique_qptr<Ui::VerticalLayout> _wrap;
Controls _controls; Controls _controls;
@ -186,10 +191,10 @@ private:
Controller::Controller( Controller::Controller(
not_null<BoxContent*> box, not_null<BoxContent*> box,
not_null<ChannelData*> channel) not_null<PeerData*> peer)
: _box(box) : _box(box)
, _channel(channel) , _peer(peer)
, _isGroup(_channel->isMegagroup()) , _isGroup(_peer->isChat() || _peer->isMegagroup())
, _checkUsernameTimer([this] { checkUsernameAvailability(); }) { , _checkUsernameTimer([this] { checkUsernameAvailability(); }) {
_box->setTitle(computeTitle()); _box->setTitle(computeTitle());
_box->addButton(langFactory(lng_settings_save), [this] { _box->addButton(langFactory(lng_settings_save), [this] {
@ -220,6 +225,8 @@ object_ptr<Ui::VerticalLayout> Controller::createContent() {
_wrap->add(createSignaturesEdit()); _wrap->add(createSignaturesEdit());
_wrap->add(createInvitesEdit()); _wrap->add(createInvitesEdit());
_wrap->add(createStickersEdit()); _wrap->add(createStickersEdit());
_wrap->add(createManageAdminsButton());
_wrap->add(createUpgradeButton());
_wrap->add(createDeleteButton()); _wrap->add(createDeleteButton());
_wrap->resizeToWidth(st::boxWideWidth); _wrap->resizeToWidth(st::boxWideWidth);
@ -236,7 +243,15 @@ void Controller::setFocus() {
object_ptr<Ui::RpWidget> Controller::createPhotoAndTitleEdit() { object_ptr<Ui::RpWidget> Controller::createPhotoAndTitleEdit() {
Expects(_wrap != nullptr); Expects(_wrap != nullptr);
if (!_channel->canEditInformation()) { auto canEdit = [&] {
if (auto channel = _peer->asChannel()) {
return channel->canEditInformation();
} else if (auto chat = _peer->asChat()) {
return chat->canEdit();
}
return false;
}();
if (!canEdit) {
return nullptr; return nullptr;
} }
@ -273,7 +288,7 @@ object_ptr<Ui::RpWidget> Controller::createPhotoEdit() {
object_ptr<Ui::UserpicButton>( object_ptr<Ui::UserpicButton>(
_wrap, _wrap,
_box->controller(), _box->controller(),
_channel, _peer,
Ui::UserpicButton::Role::ChangePhoto, Ui::UserpicButton::Role::ChangePhoto,
st::defaultUserpicButton), st::defaultUserpicButton),
st::editPeerPhotoMargins); st::editPeerPhotoMargins);
@ -293,7 +308,7 @@ object_ptr<Ui::RpWidget> Controller::createTitleEdit() {
langFactory(_isGroup langFactory(_isGroup
? lng_dlg_new_group_name ? lng_dlg_new_group_name
: lng_dlg_new_channel_name), : lng_dlg_new_channel_name),
_channel->name), _peer->name),
st::editPeerTitleMargins); st::editPeerTitleMargins);
QObject::connect( QObject::connect(
@ -308,13 +323,18 @@ object_ptr<Ui::RpWidget> Controller::createTitleEdit() {
object_ptr<Ui::RpWidget> Controller::createDescriptionEdit() { object_ptr<Ui::RpWidget> Controller::createDescriptionEdit() {
Expects(_wrap != nullptr); Expects(_wrap != nullptr);
auto channel = _peer->asChannel();
if (!channel || !channel->canEditInformation()) {
return nullptr;
}
auto result = object_ptr<Ui::PaddingWrap<Ui::InputArea>>( auto result = object_ptr<Ui::PaddingWrap<Ui::InputArea>>(
_wrap, _wrap,
object_ptr<Ui::InputArea>( object_ptr<Ui::InputArea>(
_wrap, _wrap,
st::editPeerDescription, st::editPeerDescription,
langFactory(lng_create_group_description), langFactory(lng_create_group_description),
_channel->about()), channel->about()),
st::editPeerDescriptionMargins); st::editPeerDescriptionMargins);
QObject::connect( QObject::connect(
@ -329,7 +349,8 @@ object_ptr<Ui::RpWidget> Controller::createDescriptionEdit() {
object_ptr<Ui::RpWidget> Controller::createPrivaciesEdit() { object_ptr<Ui::RpWidget> Controller::createPrivaciesEdit() {
Expects(_wrap != nullptr); Expects(_wrap != nullptr);
if (!_channel->canEditUsername()) { auto channel = _peer->asChannel();
if (!channel || !channel->canEditUsername()) {
return nullptr; return nullptr;
} }
auto result = object_ptr<Ui::PaddingWrap<Ui::VerticalLayout>>( auto result = object_ptr<Ui::PaddingWrap<Ui::VerticalLayout>>(
@ -339,7 +360,7 @@ object_ptr<Ui::RpWidget> Controller::createPrivaciesEdit() {
auto container = result->entity(); auto container = result->entity();
_controls.privacy = std::make_shared<Ui::RadioenumGroup<Privacy>>( _controls.privacy = std::make_shared<Ui::RadioenumGroup<Privacy>>(
_channel->isPublic() ? Privacy::Public : Privacy::Private); channel->isPublic() ? Privacy::Public : Privacy::Private);
auto addButton = [&]( auto addButton = [&](
Privacy value, Privacy value,
LangKey groupTextKey, LangKey groupTextKey,
@ -383,7 +404,7 @@ object_ptr<Ui::RpWidget> Controller::createPrivaciesEdit() {
_controls.privacy->setChangedCallback([this](Privacy value) { _controls.privacy->setChangedCallback([this](Privacy value) {
privacyChanged(value); privacyChanged(value);
}); });
if (!_channel->isPublic()) { if (!channel->isPublic()) {
checkUsernameAvailability(); checkUsernameAvailability();
} }
@ -391,6 +412,11 @@ object_ptr<Ui::RpWidget> Controller::createPrivaciesEdit() {
} }
object_ptr<Ui::RpWidget> Controller::createUsernameEdit() { object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
Expects(_wrap != nullptr);
auto channel = _peer->asChannel();
Assert(channel != nullptr);
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>( auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
_wrap, _wrap,
object_ptr<Ui::VerticalLayout>(_wrap), object_ptr<Ui::VerticalLayout>(_wrap),
@ -411,7 +437,7 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
container, container,
st::setupChannelLink, st::setupChannelLink,
base::lambda<QString()>(), base::lambda<QString()>(),
_channel->username, channel->username,
true)); true));
_controls.username->heightValue() _controls.username->heightValue()
| rpl::start_with_next([placeholder](int height) { | rpl::start_with_next([placeholder](int height) {
@ -483,6 +509,9 @@ void Controller::checkUsernameAvailability() {
if (!_controls.username) { if (!_controls.username) {
return; return;
} }
auto channel = _peer->asChannel();
Assert(channel != nullptr);
auto initial = (_controls.privacy->value() != Privacy::Public); auto initial = (_controls.privacy->value() != Privacy::Public);
auto checking = initial auto checking = initial
? qsl(".bad.") ? qsl(".bad.")
@ -494,14 +523,14 @@ void Controller::checkUsernameAvailability() {
request(_checkUsernameRequestId).cancel(); request(_checkUsernameRequestId).cancel();
} }
_checkUsernameRequestId = request(MTPchannels_CheckUsername( _checkUsernameRequestId = request(MTPchannels_CheckUsername(
_channel->inputChannel, channel->inputChannel,
MTP_string(checking) MTP_string(checking)
)).done([=](const MTPBool &result) { )).done([=](const MTPBool &result) {
_checkUsernameRequestId = 0; _checkUsernameRequestId = 0;
if (initial) { if (initial) {
return; return;
} }
if (!mtpIsTrue(result) && checking != _channel->username) { if (!mtpIsTrue(result) && checking != channel->username) {
showUsernameError( showUsernameError(
Lang::Viewer(lng_create_channel_link_occupied)); Lang::Viewer(lng_create_channel_link_occupied));
} else { } else {
@ -529,7 +558,7 @@ void Controller::checkUsernameAvailability() {
showUsernameError( showUsernameError(
Lang::Viewer(lng_create_channel_link_invalid)); Lang::Viewer(lng_create_channel_link_invalid));
} else if (type == qstr("USERNAME_OCCUPIED") } else if (type == qstr("USERNAME_OCCUPIED")
&& checking != _channel->username) { && checking != channel->username) {
showUsernameError( showUsernameError(
Lang::Viewer(lng_create_channel_link_occupied)); Lang::Viewer(lng_create_channel_link_occupied));
} }
@ -621,7 +650,7 @@ void Controller::exportInviteLink(const QString &confirmation) {
if (auto strong = *boxPointer) { if (auto strong = *boxPointer) {
strong->closeBox(); strong->closeBox();
} }
Auth().api().exportInviteLink(_channel); Auth().api().exportInviteLink(_peer);
}); });
auto box = Box<ConfirmBox>( auto box = Box<ConfirmBox>(
confirmation, confirmation,
@ -630,10 +659,15 @@ void Controller::exportInviteLink(const QString &confirmation) {
} }
bool Controller::canEditInviteLink() const { bool Controller::canEditInviteLink() const {
if (_channel->canEditUsername()) { if (auto channel = _peer->asChannel()) {
return true; if (channel->canEditUsername()) {
return true;
}
return (!channel->isPublic() && channel->canAddMembers());
} else if (auto chat = _peer->asChat()) {
return !chat->inviteLink().isEmpty() || chat->canEdit();
} }
return (!_channel->isPublic() && _channel->canAddMembers()); return false;
} }
bool Controller::inviteLinkShown() const { bool Controller::inviteLinkShown() const {
@ -641,6 +675,15 @@ bool Controller::inviteLinkShown() const {
|| (_controls.privacy->value() == Privacy::Private); || (_controls.privacy->value() == Privacy::Private);
} }
QString Controller::inviteLinkText() const {
if (auto channel = _peer->asChannel()) {
return channel->inviteLink();
} else if (auto chat = _peer->asChat()) {
return chat->inviteLink();
}
return QString();
}
object_ptr<Ui::RpWidget> Controller::createInviteLinkEdit() { object_ptr<Ui::RpWidget> Controller::createInviteLinkEdit() {
Expects(_wrap != nullptr); Expects(_wrap != nullptr);
@ -670,7 +713,7 @@ object_ptr<Ui::RpWidget> Controller::createInviteLinkEdit() {
_controls.inviteLink->setContextCopyText(QString()); _controls.inviteLink->setContextCopyText(QString());
_controls.inviteLink->setBreakEverywhere(true); _controls.inviteLink->setBreakEverywhere(true);
_controls.inviteLink->setClickHandlerHook([this](auto&&...) { _controls.inviteLink->setClickHandlerHook([this](auto&&...) {
Application::clipboard()->setText(_channel->inviteLink()); Application::clipboard()->setText(inviteLinkText());
Ui::Toast::Show(lang(lng_group_invite_copied)); Ui::Toast::Show(lang(lng_group_invite_copied));
return false; return false;
}); });
@ -685,7 +728,7 @@ object_ptr<Ui::RpWidget> Controller::createInviteLinkEdit() {
)->addClickHandler([this] { revokeInviteLink(); }); )->addClickHandler([this] { revokeInviteLink(); });
Notify::PeerUpdateValue( Notify::PeerUpdateValue(
_channel, _peer,
Notify::PeerUpdate::Flag::InviteLinkChanged) Notify::PeerUpdate::Flag::InviteLinkChanged)
| rpl::start_with_next([this] { | rpl::start_with_next([this] {
refreshEditInviteLink(); refreshEditInviteLink();
@ -695,7 +738,7 @@ object_ptr<Ui::RpWidget> Controller::createInviteLinkEdit() {
} }
void Controller::refreshEditInviteLink() { void Controller::refreshEditInviteLink() {
auto link = _channel->inviteLink(); auto link = inviteLinkText();
auto text = TextWithEntities(); auto text = TextWithEntities();
if (!link.isEmpty()) { if (!link.isEmpty()) {
text.text = link; text.text = link;
@ -750,7 +793,7 @@ object_ptr<Ui::RpWidget> Controller::createInviteLinkCreate() {
_controls.createInviteLinkWrap = result.data(); _controls.createInviteLinkWrap = result.data();
Notify::PeerUpdateValue( Notify::PeerUpdateValue(
_channel, _peer,
Notify::PeerUpdate::Flag::InviteLinkChanged) Notify::PeerUpdate::Flag::InviteLinkChanged)
| rpl::start_with_next([this] { | rpl::start_with_next([this] {
refreshCreateInviteLink(); refreshCreateInviteLink();
@ -760,17 +803,18 @@ object_ptr<Ui::RpWidget> Controller::createInviteLinkCreate() {
} }
void Controller::refreshCreateInviteLink() { void Controller::refreshCreateInviteLink() {
auto link = _channel->inviteLink();
_controls.createInviteLinkWrap->toggle( _controls.createInviteLinkWrap->toggle(
inviteLinkShown() && link.isEmpty(), inviteLinkShown() && inviteLinkText().isEmpty(),
anim::type::instant); anim::type::instant);
} }
object_ptr<Ui::RpWidget> Controller::createHistoryVisibilityEdit() { object_ptr<Ui::RpWidget> Controller::createHistoryVisibilityEdit() {
Expects(_wrap != nullptr); Expects(_wrap != nullptr);
if (!_channel->canEditPreHistoryHidden() auto channel = _peer->asChannel();
|| !_channel->isMegagroup()) { if (!channel
|| !channel->canEditPreHistoryHidden()
|| !channel->isMegagroup()) {
return nullptr; return nullptr;
} }
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>( auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
@ -782,7 +826,7 @@ object_ptr<Ui::RpWidget> Controller::createHistoryVisibilityEdit() {
_controls.historyVisibility _controls.historyVisibility
= std::make_shared<Ui::RadioenumGroup<HistoryVisibility>>( = std::make_shared<Ui::RadioenumGroup<HistoryVisibility>>(
_channel->hiddenPreHistory() channel->hiddenPreHistory()
? HistoryVisibility::Hidden ? HistoryVisibility::Hidden
: HistoryVisibility::Visible); : HistoryVisibility::Visible);
auto addButton = [&]( auto addButton = [&](
@ -839,8 +883,10 @@ void Controller::refreshHistoryVisibility() {
object_ptr<Ui::RpWidget> Controller::createSignaturesEdit() { object_ptr<Ui::RpWidget> Controller::createSignaturesEdit() {
Expects(_wrap != nullptr); Expects(_wrap != nullptr);
if (!_channel->canEditSignatures() auto channel = _peer->asChannel();
|| _channel->isMegagroup()) { if (!channel
|| !channel->canEditSignatures()
|| channel->isMegagroup()) {
return nullptr; return nullptr;
} }
auto result = object_ptr<Ui::VerticalLayout>(_wrap); auto result = object_ptr<Ui::VerticalLayout>(_wrap);
@ -854,7 +900,7 @@ object_ptr<Ui::RpWidget> Controller::createSignaturesEdit() {
object_ptr<Ui::Checkbox>( object_ptr<Ui::Checkbox>(
container, container,
lang(lng_edit_sign_messages), lang(lng_edit_sign_messages),
_channel->addsSignature(), channel->addsSignature(),
st::defaultBoxCheckbox), st::defaultBoxCheckbox),
st::editPeerSignaturesMargins))->entity(); st::editPeerSignaturesMargins))->entity();
container->add(object_ptr<Ui::FixedHeightWidget>( container->add(object_ptr<Ui::FixedHeightWidget>(
@ -866,8 +912,10 @@ object_ptr<Ui::RpWidget> Controller::createSignaturesEdit() {
object_ptr<Ui::RpWidget> Controller::createInvitesEdit() { object_ptr<Ui::RpWidget> Controller::createInvitesEdit() {
Expects(_wrap != nullptr); Expects(_wrap != nullptr);
if (!_channel->canEditInvites() auto channel = _peer->asChannel();
|| !_channel->isMegagroup()) { if (!channel
|| !channel->canEditInvites()
|| !channel->isMegagroup()) {
return nullptr; return nullptr;
} }
@ -883,7 +931,7 @@ object_ptr<Ui::RpWidget> Controller::createInvitesEdit() {
st::editPeerSectionLabel)); st::editPeerSectionLabel));
_controls.invites = std::make_shared<Ui::RadioenumGroup<Invites>>( _controls.invites = std::make_shared<Ui::RadioenumGroup<Invites>>(
_channel->anyoneCanAddMembers() channel->anyoneCanAddMembers()
? Invites::Everyone ? Invites::Everyone
: Invites::OnlyAdmins); : Invites::OnlyAdmins);
auto addButton = [&]( auto addButton = [&](
@ -915,7 +963,8 @@ object_ptr<Ui::RpWidget> Controller::createInvitesEdit() {
object_ptr<Ui::RpWidget> Controller::createStickersEdit() { object_ptr<Ui::RpWidget> Controller::createStickersEdit() {
Expects(_wrap != nullptr); Expects(_wrap != nullptr);
if (!_channel->canEditStickers()) { auto channel = _peer->asChannel();
if (!channel || !channel->canEditStickers()) {
return nullptr; return nullptr;
} }
@ -945,17 +994,58 @@ object_ptr<Ui::RpWidget> Controller::createStickersEdit() {
_wrap, _wrap,
lang(lng_group_stickers_add), lang(lng_group_stickers_add),
st::editPeerInviteLinkButton) st::editPeerInviteLinkButton)
)->addClickHandler([this] { )->addClickHandler([channel] {
Ui::show(Box<StickersBox>(_channel), LayerOption::KeepOther); Ui::show(Box<StickersBox>(channel), LayerOption::KeepOther);
}); });
return std::move(result); return std::move(result);
} }
object_ptr<Ui::RpWidget> Controller::createManageAdminsButton() {
Expects(_wrap != nullptr);
auto chat = _peer->asChat();
if (!chat || !chat->amCreator() || chat->isDeactivated()) {
return nullptr;
}
auto result = object_ptr<Ui::PaddingWrap<Ui::LinkButton>>(
_wrap,
object_ptr<Ui::LinkButton>(
_wrap,
lang(lng_profile_manage_admins),
st::editPeerInviteLinkButton),
st::editPeerDeleteButtonMargins);
result->entity()->addClickHandler([=] {
EditChatAdminsBoxController::Start(chat);
});
return std::move(result);
}
object_ptr<Ui::RpWidget> Controller::createUpgradeButton() {
Expects(_wrap != nullptr);
auto chat = _peer->asChat();
if (!chat || !chat->amCreator() || chat->isDeactivated()) {
return nullptr;
}
auto result = object_ptr<Ui::PaddingWrap<Ui::LinkButton>>(
_wrap,
object_ptr<Ui::LinkButton>(
_wrap,
lang(lng_profile_migrate_button),
st::editPeerInviteLinkButton),
st::editPeerDeleteButtonMargins);
result->entity()->addClickHandler([=] {
Ui::show(Box<ConvertToSupergroupBox>(chat), LayerOption::KeepOther);
});
return std::move(result);
}
object_ptr<Ui::RpWidget> Controller::createDeleteButton() { object_ptr<Ui::RpWidget> Controller::createDeleteButton() {
Expects(_wrap != nullptr); Expects(_wrap != nullptr);
if (!_channel->canDelete()) { auto channel = _peer->asChannel();
if (!channel || !channel->canDelete()) {
return nullptr; return nullptr;
} }
auto text = lang(_isGroup auto text = lang(_isGroup
@ -1114,23 +1204,25 @@ void Controller::cancelSave() {
} }
void Controller::saveUsername() { void Controller::saveUsername() {
auto channel = _peer->asChannel();
if (!_savingData.username if (!_savingData.username
|| *_savingData.username == _channel->username) { || !channel
|| *_savingData.username == channel->username) {
return continueSave(); return continueSave();
} }
request(MTPchannels_UpdateUsername( request(MTPchannels_UpdateUsername(
_channel->inputChannel, channel->inputChannel,
MTP_string(*_savingData.username) MTP_string(*_savingData.username)
)).done([this](const MTPBool &result) { )).done([=](const MTPBool &result) {
_channel->setName( channel->setName(
TextUtilities::SingleLine(_channel->name), TextUtilities::SingleLine(channel->name),
*_savingData.username); *_savingData.username);
continueSave(); continueSave();
}).fail([this](const RPCError &error) { }).fail([=](const RPCError &error) {
auto type = error.type(); auto type = error.type();
if (type == qstr("USERNAME_NOT_MODIFIED")) { if (type == qstr("USERNAME_NOT_MODIFIED")) {
_channel->setName( channel->setName(
TextUtilities::SingleLine(_channel->name), TextUtilities::SingleLine(channel->name),
TextUtilities::SingleLine(*_savingData.username)); TextUtilities::SingleLine(*_savingData.username));
continueSave(); continueSave();
return; return;
@ -1152,20 +1244,23 @@ void Controller::saveUsername() {
} }
void Controller::saveTitle() { void Controller::saveTitle() {
if (!_savingData.title || *_savingData.title == _channel->name) { if (!_savingData.title || *_savingData.title == _peer->name) {
return continueSave(); return continueSave();
} }
request(MTPchannels_EditTitle(
_channel->inputChannel, auto onDone = [this](const MTPUpdates &result) {
MTP_string(*_savingData.title)
)).done([this](const MTPUpdates &result) {
Auth().api().applyUpdates(result); Auth().api().applyUpdates(result);
continueSave(); continueSave();
}).fail([this](const RPCError &error) { };
auto onFail = [this](const RPCError &error) {
auto type = error.type(); auto type = error.type();
if (type == qstr("CHAT_NOT_MODIFIED") if (type == qstr("CHAT_NOT_MODIFIED")
|| type == qstr("CHAT_TITLE_NOT_MODIFIED")) { || type == qstr("CHAT_TITLE_NOT_MODIFIED")) {
_channel->setName(*_savingData.title, _channel->username); if (auto channel = _peer->asChannel()) {
channel->setName(*_savingData.title, channel->username);
} else if (auto chat = _peer->asChat()) {
chat->setName(*_savingData.title);
}
continueSave(); continueSave();
return; return;
} }
@ -1176,20 +1271,40 @@ void Controller::saveTitle() {
_controls.title->setFocus(); _controls.title->setFocus();
} }
cancelSave(); cancelSave();
}).send(); };
if (auto channel = _peer->asChannel()) {
request(MTPchannels_EditTitle(
channel->inputChannel,
MTP_string(*_savingData.title)
)).done(std::move(onDone)
).fail(std::move(onFail)
).send();
} else if (auto chat = _peer->asChat()) {
request(MTPmessages_EditChatTitle(
chat->inputChat,
MTP_string(*_savingData.title)
)).done(std::move(onDone)
).fail(std::move(onFail)
).send();
} else {
continueSave();
}
} }
void Controller::saveDescription() { void Controller::saveDescription() {
auto channel = _peer->asChannel();
if (!_savingData.description if (!_savingData.description
|| *_savingData.description == _channel->about()) { || !channel
|| *_savingData.description == channel->about()) {
return continueSave(); return continueSave();
} }
auto successCallback = [this] { auto successCallback = [=] {
_channel->setAbout(*_savingData.description); channel->setAbout(*_savingData.description);
continueSave(); continueSave();
}; };
request(MTPchannels_EditAbout( request(MTPchannels_EditAbout(
_channel->inputChannel, channel->inputChannel,
MTP_string(*_savingData.description) MTP_string(*_savingData.description)
)).done([=](const MTPBool &result) { )).done([=](const MTPBool &result) {
successCallback(); successCallback();
@ -1205,18 +1320,20 @@ void Controller::saveDescription() {
} }
void Controller::saveHistoryVisibility() { void Controller::saveHistoryVisibility() {
auto channel = _peer->asChannel();
if (!_savingData.hiddenPreHistory if (!_savingData.hiddenPreHistory
|| *_savingData.hiddenPreHistory == _channel->hiddenPreHistory()) { || !channel
|| *_savingData.hiddenPreHistory == channel->hiddenPreHistory()) {
return continueSave(); return continueSave();
} }
request(MTPchannels_TogglePreHistoryHidden( request(MTPchannels_TogglePreHistoryHidden(
_channel->inputChannel, channel->inputChannel,
MTP_bool(*_savingData.hiddenPreHistory) MTP_bool(*_savingData.hiddenPreHistory)
)).done([this](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
// Update in the result doesn't contain the // Update in the result doesn't contain the
// channelFull:flags field which holds this value. // channelFull:flags field which holds this value.
// So after saving we need to update it manually. // So after saving we need to update it manually.
_channel->updateFullForced(); channel->updateFullForced();
Auth().api().applyUpdates(result); Auth().api().applyUpdates(result);
continueSave(); continueSave();
@ -1230,12 +1347,14 @@ void Controller::saveHistoryVisibility() {
} }
void Controller::saveInvites() { void Controller::saveInvites() {
auto channel = _peer->asChannel();
if (!_savingData.everyoneInvites if (!_savingData.everyoneInvites
|| *_savingData.everyoneInvites == _channel->anyoneCanAddMembers()) { || !channel
|| *_savingData.everyoneInvites == channel->anyoneCanAddMembers()) {
return continueSave(); return continueSave();
} }
request(MTPchannels_ToggleInvites( request(MTPchannels_ToggleInvites(
_channel->inputChannel, channel->inputChannel,
MTP_bool(*_savingData.everyoneInvites) MTP_bool(*_savingData.everyoneInvites)
)).done([this](const MTPUpdates &result) { )).done([this](const MTPUpdates &result) {
Auth().api().applyUpdates(result); Auth().api().applyUpdates(result);
@ -1250,12 +1369,14 @@ void Controller::saveInvites() {
} }
void Controller::saveSignatures() { void Controller::saveSignatures() {
auto channel = _peer->asChannel();
if (!_savingData.signatures if (!_savingData.signatures
|| *_savingData.signatures == _channel->addsSignature()) { || !channel
|| *_savingData.signatures == channel->addsSignature()) {
return continueSave(); return continueSave();
} }
request(MTPchannels_ToggleSignatures( request(MTPchannels_ToggleSignatures(
_channel->inputChannel, channel->inputChannel,
MTP_bool(*_savingData.signatures) MTP_bool(*_savingData.signatures)
)).done([this](const MTPUpdates &result) { )).done([this](const MTPUpdates &result) {
Auth().api().applyUpdates(result); Auth().api().applyUpdates(result);
@ -1276,16 +1397,19 @@ void Controller::savePhoto() {
if (!image.isNull()) { if (!image.isNull()) {
Messenger::Instance().uploadProfilePhoto( Messenger::Instance().uploadProfilePhoto(
std::move(image), std::move(image),
_channel->id); _peer->id);
} }
_box->closeBox(); _box->closeBox();
} }
void Controller::deleteWithConfirmation() { void Controller::deleteWithConfirmation() {
auto channel = _peer->asChannel();
Assert(channel != nullptr);
auto text = lang(_isGroup auto text = lang(_isGroup
? lng_sure_delete_group ? lng_sure_delete_group
: lng_sure_delete_channel); : lng_sure_delete_channel);
auto deleteCallback = [channel = _channel] { auto deleteCallback = [=] {
Ui::hideLayer(); Ui::hideLayer();
Ui::showChatsList(); Ui::showChatsList();
if (auto chat = channel->migrateFrom()) { if (auto chat = channel->migrateFrom()) {
@ -1307,12 +1431,12 @@ void Controller::deleteWithConfirmation() {
EditPeerInfoBox::EditPeerInfoBox( EditPeerInfoBox::EditPeerInfoBox(
QWidget*, QWidget*,
not_null<ChannelData*> channel) not_null<PeerData*> peer)
: _channel(channel) { : _peer(peer) {
} }
void EditPeerInfoBox::prepare() { void EditPeerInfoBox::prepare() {
auto controller = std::make_unique<Controller>(this, _channel); auto controller = std::make_unique<Controller>(this, _peer);
_focusRequests.events() _focusRequests.events()
| rpl::start_with_next( | rpl::start_with_next(
[c = controller.get()] { c->setFocus(); }, [c = controller.get()] { c->setFocus(); },

View File

@ -25,7 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
class EditPeerInfoBox : public BoxContent { class EditPeerInfoBox : public BoxContent {
public: public:
EditPeerInfoBox(QWidget*, not_null<ChannelData*> channel); EditPeerInfoBox(QWidget*, not_null<PeerData*> peer);
void setInnerFocus() override { void setInnerFocus() override {
_focusRequests.fire({}); _focusRequests.fire({});
@ -35,7 +35,7 @@ protected:
void prepare() override; void prepare() override;
private: private:
not_null<ChannelData*> _channel; not_null<PeerData*> _peer;
rpl::event_stream<> _focusRequests; rpl::event_stream<> _focusRequests;
}; };

View File

@ -366,7 +366,7 @@ void CoverWidget::chooseNewPhoto() {
} }
void CoverWidget::editName() { void CoverWidget::editName() {
Ui::show(Box<EditNameTitleBox>(self())); Ui::show(Box<EditNameBox>(self()));
} }
void CoverWidget::showSetPhotoBox(const QImage &img) { void CoverWidget::showSetPhotoBox(const QImage &img) {

View File

@ -27,6 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "boxes/report_box.h" #include "boxes/report_box.h"
#include "boxes/peer_list_controllers.h" #include "boxes/peer_list_controllers.h"
#include "boxes/peers/manage_peer_box.h" #include "boxes/peers/manage_peer_box.h"
#include "boxes/peers/edit_peer_info_box.h"
#include "core/tl_help.h" #include "core/tl_help.h"
#include "auth_session.h" #include "auth_session.h"
#include "apiwrap.h" #include "apiwrap.h"
@ -341,19 +342,8 @@ void Filler::addChatActions(not_null<ChatData*> chat) {
if (_source != PeerMenuSource::ChatsList) { if (_source != PeerMenuSource::ChatsList) {
if (chat->canEdit()) { if (chat->canEdit()) {
_addAction( _addAction(
lang(lng_profile_edit_group_name), lang(lng_manage_group_title),
[chat] { Ui::show(Box<EditNameTitleBox>(chat)); }); [chat] { Ui::show(Box<EditPeerInfoBox>(chat)); });
}
if (chat->amCreator()
&& !chat->isDeactivated()) {
_addAction(
lang(lng_profile_manage_admins),
[chat] { EditChatAdminsBoxController::Start(chat); });
_addAction(
lang(lng_profile_migrate_button),
[chat] { Ui::show(Box<ConvertToSupergroupBox>(chat)); });
}
if (chat->canEdit()) {
_addAction( _addAction(
lang(lng_profile_add_participant), lang(lng_profile_add_participant),
[chat] { AddChatMembers(chat); }); [chat] { AddChatMembers(chat); });