mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Support personal photo edit in EditContactBox.
This commit is contained in:
@@ -465,7 +465,7 @@ void GroupInfoBox::prepare() {
|
||||
_photo.create(
|
||||
this,
|
||||
&_navigation->parentController()->window(),
|
||||
Ui::UserpicButton::Role::ChangePhoto,
|
||||
Ui::UserpicButton::Role::ChoosePhoto,
|
||||
st::defaultUserpicButton);
|
||||
_title.create(
|
||||
this,
|
||||
|
@@ -86,7 +86,6 @@ void GiftBox(
|
||||
const auto userpic = Ui::CreateChild<Ui::UserpicButton>(
|
||||
top,
|
||||
user,
|
||||
Ui::UserpicButton::Role::Custom,
|
||||
st::defaultUserpicButton);
|
||||
userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
top->widthValue(
|
||||
|
@@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/toast/toast.h"
|
||||
#include "main/main_session.h"
|
||||
#include "apiwrap.h"
|
||||
#include "api/api_peer_photo.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_info.h"
|
||||
@@ -41,7 +42,8 @@ void SendRequest(
|
||||
bool sharePhone,
|
||||
const QString &first,
|
||||
const QString &last,
|
||||
const QString &phone) {
|
||||
const QString &phone,
|
||||
Fn<void()> done) {
|
||||
const auto wasContact = user->isContact();
|
||||
using Flag = MTPcontacts_AddContact::Flag;
|
||||
user->session().api().request(MTPcontacts_AddContact(
|
||||
@@ -73,6 +75,7 @@ void SendRequest(
|
||||
}
|
||||
box->closeBox();
|
||||
}
|
||||
done();
|
||||
}).send();
|
||||
}
|
||||
|
||||
@@ -103,6 +106,7 @@ private:
|
||||
QString _phone;
|
||||
Fn<void()> _focus;
|
||||
Fn<void()> _save;
|
||||
Fn<std::optional<QImage>()> _updatedPersonalPhoto;
|
||||
|
||||
};
|
||||
|
||||
@@ -146,6 +150,7 @@ void Controller::setupCover() {
|
||||
? tr::lng_contact_mobile_hidden()
|
||||
: rpl::single(Ui::FormatPhone(_phone)))),
|
||||
style::margins());
|
||||
_updatedPersonalPhoto = [=] { return cover->updatedPersonalPhoto(); };
|
||||
}
|
||||
|
||||
void Controller::setupNameFields() {
|
||||
@@ -199,13 +204,29 @@ void Controller::initNameFields(
|
||||
(inverted ? last : first)->showError();
|
||||
return;
|
||||
}
|
||||
const auto user = _user;
|
||||
const auto personal = _updatedPersonalPhoto
|
||||
? _updatedPersonalPhoto()
|
||||
: std::nullopt;
|
||||
const auto done = [=] {
|
||||
if (personal) {
|
||||
if (personal->isNull()) {
|
||||
user->session().api().peerPhoto().clearPersonal(user);
|
||||
} else {
|
||||
user->session().api().peerPhoto().upload(
|
||||
user,
|
||||
base::duplicate(*personal));
|
||||
}
|
||||
}
|
||||
};
|
||||
SendRequest(
|
||||
Ui::MakeWeak(_box),
|
||||
_user,
|
||||
user,
|
||||
_sharePhone && _sharePhone->checked(),
|
||||
firstValue,
|
||||
lastValue,
|
||||
_phone);
|
||||
_phone,
|
||||
done);
|
||||
};
|
||||
const auto submit = [=] {
|
||||
const auto firstValue = first->getLastText().trimmed();
|
||||
|
@@ -85,11 +85,7 @@ EditParticipantBox::Inner::Inner(
|
||||
: RpWidget(parent)
|
||||
, _peer(peer)
|
||||
, _user(user)
|
||||
, _userPhoto(
|
||||
this,
|
||||
_user,
|
||||
Ui::UserpicButton::Role::Custom,
|
||||
st::rightsPhotoButton)
|
||||
, _userPhoto(this, _user, st::rightsPhotoButton)
|
||||
, _hasAdminRights(hasAdminRights)
|
||||
, _rows(this) {
|
||||
_rows->heightValue(
|
||||
@@ -97,7 +93,7 @@ EditParticipantBox::Inner::Inner(
|
||||
resizeToWidth(width());
|
||||
}, lifetime());
|
||||
|
||||
_userPhoto->setPointerCursor(false);
|
||||
_userPhoto->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
_userName.setText(
|
||||
st::rightsNameStyle,
|
||||
_user->name(),
|
||||
|
@@ -470,9 +470,10 @@ object_ptr<Ui::RpWidget> Controller::createPhotoEdit() {
|
||||
_wrap,
|
||||
object_ptr<Ui::UserpicButton>(
|
||||
_wrap,
|
||||
&_navigation->parentController()->window(),
|
||||
_navigation->parentController(),
|
||||
_peer,
|
||||
Ui::UserpicButton::Role::ChangePhoto,
|
||||
Ui::UserpicButton::Source::PeerPhoto,
|
||||
st::defaultUserpicButton),
|
||||
st::editPeerPhotoMargins);
|
||||
_controls.photo = photoWrap->entity();
|
||||
|
Reference in New Issue
Block a user