Fix edit name button in Settings.

Regression was introduced in 703b944839.
This commit is contained in:
John Preston 2017-11-30 18:00:25 +04:00
parent a0c8d522ef
commit 0bf854bf18
4 changed files with 39 additions and 31 deletions

View File

@ -547,7 +547,7 @@ void Messenger::chatPhotoDone(PeerId peer, const MTPUpdates &updates) {
emit peerPhotoDone(peer);
}
bool Messenger::peerPhotoFail(PeerId peer, const RPCError &error) {
bool Messenger::peerPhotoFailed(PeerId peer, const RPCError &error) {
if (MTP::isDefaultHandledError(error)) return false;
LOG(("Application Error: update photo failed %1: %2").arg(error.type()).arg(error.description()));
@ -560,12 +560,12 @@ void Messenger::peerClearPhoto(PeerId id) {
if (!AuthSession::Exists()) return;
if (id == Auth().userPeerId()) {
MTP::send(MTPphotos_UpdateProfilePhoto(MTP_inputPhotoEmpty()), rpcDone(&Messenger::selfPhotoCleared), rpcFail(&Messenger::peerPhotoFail, id));
MTP::send(MTPphotos_UpdateProfilePhoto(MTP_inputPhotoEmpty()), rpcDone(&Messenger::selfPhotoCleared), rpcFail(&Messenger::peerPhotoFailed, id));
} else if (peerIsChat(id)) {
MTP::send(MTPmessages_EditChatPhoto(peerToBareMTPInt(id), MTP_inputChatPhotoEmpty()), rpcDone(&Messenger::chatPhotoCleared, id), rpcFail(&Messenger::peerPhotoFail, id));
MTP::send(MTPmessages_EditChatPhoto(peerToBareMTPInt(id), MTP_inputChatPhotoEmpty()), rpcDone(&Messenger::chatPhotoCleared, id), rpcFail(&Messenger::peerPhotoFailed, id));
} else if (peerIsChannel(id)) {
if (auto channel = App::channelLoaded(id)) {
MTP::send(MTPchannels_EditPhoto(channel->inputChannel, MTP_inputChatPhotoEmpty()), rpcDone(&Messenger::chatPhotoCleared, id), rpcFail(&Messenger::peerPhotoFail, id));
MTP::send(MTPchannels_EditPhoto(channel->inputChannel, MTP_inputChatPhotoEmpty()), rpcDone(&Messenger::chatPhotoCleared, id), rpcFail(&Messenger::peerPhotoFailed, id));
}
}
}
@ -655,13 +655,13 @@ void Messenger::photoUpdated(const FullMsgId &msgId, bool silent, const MTPInput
if (i != photoUpdates.end()) {
auto id = i.value();
if (id == Auth().userPeerId()) {
MTP::send(MTPphotos_UploadProfilePhoto(file), rpcDone(&Messenger::selfPhotoDone), rpcFail(&Messenger::peerPhotoFail, id));
MTP::send(MTPphotos_UploadProfilePhoto(file), rpcDone(&Messenger::selfPhotoDone), rpcFail(&Messenger::peerPhotoFailed, id));
} else if (peerIsChat(id)) {
auto history = App::history(id);
history->sendRequestId = MTP::send(MTPmessages_EditChatPhoto(history->peer->asChat()->inputChat, MTP_inputChatUploadedPhoto(file)), rpcDone(&Messenger::chatPhotoDone, id), rpcFail(&Messenger::peerPhotoFail, id), 0, 0, history->sendRequestId);
history->sendRequestId = MTP::send(MTPmessages_EditChatPhoto(history->peer->asChat()->inputChat, MTP_inputChatUploadedPhoto(file)), rpcDone(&Messenger::chatPhotoDone, id), rpcFail(&Messenger::peerPhotoFailed, id), 0, 0, history->sendRequestId);
} else if (peerIsChannel(id)) {
auto history = App::history(id);
history->sendRequestId = MTP::send(MTPchannels_EditPhoto(history->peer->asChannel()->inputChannel, MTP_inputChatUploadedPhoto(file)), rpcDone(&Messenger::chatPhotoDone, id), rpcFail(&Messenger::peerPhotoFail, id), 0, 0, history->sendRequestId);
history->sendRequestId = MTP::send(MTPchannels_EditPhoto(history->peer->asChannel()->inputChannel, MTP_inputChatUploadedPhoto(file)), rpcDone(&Messenger::chatPhotoDone, id), rpcFail(&Messenger::peerPhotoFailed, id), 0, 0, history->sendRequestId);
}
}
}

View File

@ -159,7 +159,7 @@ public:
void chatPhotoCleared(PeerId peer, const MTPUpdates &updates);
void selfPhotoDone(const MTPphotos_Photo &result);
void chatPhotoDone(PeerId peerId, const MTPUpdates &updates);
bool peerPhotoFail(PeerId peerId, const RPCError &e);
bool peerPhotoFailed(PeerId peerId, const RPCError &e);
void peerClearPhoto(PeerId peer);
void writeUserConfigIn(TimeMs ms);

View File

@ -61,19 +61,30 @@ CoverWidget::CoverWidget(QWidget *parent, UserData *self)
_name->setSelectable(true);
_name->setContextCopyText(lang(lng_profile_copy_fullname));
_setPhoto->setClickedCallback(App::LambdaDelayed(st::settingsPrimaryButton.ripple.hideDuration, this, [this] { onSetPhoto(); }));
connect(_editName, SIGNAL(clicked()), this, SLOT(onEditName()));
connect(_editNameInline, SIGNAL(clicked()), this, SLOT(onEditName()));
_setPhoto->setClickedCallback(App::LambdaDelayed(
st::settingsPrimaryButton.ripple.hideDuration,
this,
[this] { chooseNewPhoto(); }));
_editName->addClickHandler([this] { editName(); });
_editNameInline->addClickHandler([this] { editName(); });
auto observeEvents = Notify::PeerUpdate::Flag::NameChanged | Notify::PeerUpdate::Flag::PhotoChanged;
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
notifyPeerUpdated(update);
}));
connect(&Messenger::Instance(), SIGNAL(peerPhotoDone(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
connect(&Messenger::Instance(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
connect(
&Messenger::Instance(),
&Messenger::peerPhotoDone,
this,
&CoverWidget::onPhotoUploadStatusChanged);
connect(
&Messenger::Instance(),
&Messenger::peerPhotoFail,
this,
&CoverWidget::onPhotoUploadStatusChanged);
connect(_userpicButton, SIGNAL(clicked()), this, SLOT(onPhotoShow()));
_userpicButton->addClickHandler([this] { showPhoto(); });
validatePhoto();
refreshNameText();
@ -92,13 +103,13 @@ PhotoData *CoverWidget::validatePhoto() const {
return photo;
}
void CoverWidget::onPhotoShow() {
void CoverWidget::showPhoto() {
if (auto photo = validatePhoto()) {
Messenger::Instance().showPhoto(photo, _self);
}
}
void CoverWidget::onCancelPhotoUpload() {
void CoverWidget::cancelPhotoUpload() {
Messenger::Instance().cancelPhotoUpdate(_self->id);
refreshStatusText();
}
@ -175,8 +186,8 @@ void CoverWidget::refreshNameGeometry(int newWidth) {
newWidth);
_editNameInline->moveToLeft(
margins.left() + nameLeft + _name->widthNoMargins(),
margins.top() + nameTop + st::settingsNameLabel.margin.top(),
margins.left() + nameLeft + _name->widthNoMargins() + st::settingsNameLabel.margin.right(),
margins.top() + nameTop - st::settingsNameLabel.margin.top(),
newWidth);
_editNameInline->setVisible(editNameInlineVisible);
}
@ -310,7 +321,7 @@ void CoverWidget::refreshStatusText() {
if (!_cancelPhotoUpload) {
auto margins = getMargins();
_cancelPhotoUpload.create(this, lang(lng_cancel), st::defaultLinkButton);
connect(_cancelPhotoUpload, SIGNAL(clicked()), this, SLOT(onCancelPhotoUpload()));
_cancelPhotoUpload->addClickHandler([this] { cancelPhotoUpload(); });
_cancelPhotoUpload->show();
_cancelPhotoUpload->moveToLeft(
margins.left()
@ -335,7 +346,7 @@ void CoverWidget::refreshStatusText() {
update();
}
void CoverWidget::onSetPhoto() {
void CoverWidget::chooseNewPhoto() {
auto imageExtensions = cImgExtensions();
auto filter = qsl("Image files (*") + imageExtensions.join(qsl(" *")) + qsl(");;") + FileDialog::AllFilesFilter();
FileDialog::GetOpenPath(lang(lng_choose_image), filter, base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) {
@ -354,7 +365,7 @@ void CoverWidget::onSetPhoto() {
}));
}
void CoverWidget::onEditName() {
void CoverWidget::editName() {
Ui::show(Box<EditNameTitleBox>(self()));
}

View File

@ -41,19 +41,9 @@ class CoverDropArea;
namespace Settings {
class CoverWidget : public BlockWidget {
Q_OBJECT
public:
CoverWidget(QWidget *parent, UserData *self);
private slots:
void onPhotoShow();
void onPhotoUploadStatusChanged(PeerId peerId = 0);
void onCancelPhotoUpload();
void onSetPhoto();
void onEditName();
protected:
void dragEnterEvent(QDragEnterEvent *e) override;
void dragLeaveEvent(QDragLeaveEvent *e) override;
@ -68,6 +58,13 @@ private:
// Observed notifications.
void notifyPeerUpdated(const Notify::PeerUpdate &update);
void showPhoto();
void cancelPhotoUpload();
void chooseNewPhoto();
void editName();
void onPhotoUploadStatusChanged(PeerId peerId = 0);
PhotoData *validatePhoto() const;
void refreshButtonsGeometry(int newWidth);