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_profile_enable_notifications" = "Notifications";
"lng_profile_send_message" = "Send Message";
"lng_profile_edit_group_name" = "Edit group name";
"lng_info_add_as_contact" = "Add as contact";
"lng_profile_shared_media" = "Shared media";
"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_enter_contact_data" = "New Contact";
"lng_edit_group_title" = "Edit group name";
"lng_edit_contact_title" = "Edit contact name";
"lng_edit_channel_title" = "Edit channel";
"lng_edit_sign_messages" = "Sign messages";

View File

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

View File

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

View File

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

View File

@ -366,7 +366,7 @@ void CoverWidget::chooseNewPhoto() {
}
void CoverWidget::editName() {
Ui::show(Box<EditNameTitleBox>(self()));
Ui::show(Box<EditNameBox>(self()));
}
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/peer_list_controllers.h"
#include "boxes/peers/manage_peer_box.h"
#include "boxes/peers/edit_peer_info_box.h"
#include "core/tl_help.h"
#include "auth_session.h"
#include "apiwrap.h"
@ -341,19 +342,8 @@ void Filler::addChatActions(not_null<ChatData*> chat) {
if (_source != PeerMenuSource::ChatsList) {
if (chat->canEdit()) {
_addAction(
lang(lng_profile_edit_group_name),
[chat] { Ui::show(Box<EditNameTitleBox>(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()) {
lang(lng_manage_group_title),
[chat] { Ui::show(Box<EditPeerInfoBox>(chat)); });
_addAction(
lang(lng_profile_add_participant),
[chat] { AddChatMembers(chat); });