Open settings when done changing photo.

This commit is contained in:
John Preston 2022-12-10 07:21:27 +04:00
parent 48cf0a4382
commit ae819eb1a6
4 changed files with 25 additions and 17 deletions

View file

@ -184,11 +184,12 @@ LayerWidget::LayerWidget(
closeLayer();
}, lifetime());
const auto weak = Ui::MakeWeak(_content.get());
_content->doneRequests(
) | rpl::start_with_next([=, done = std::move(doneCallback)](
const PhotoModifications &mods) {
done(mods);
closeLayer();
if (weak) closeLayer();
}, lifetime());
sizeValue(

View file

@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwidget.h"
#include "apiwrap.h"
#include "api/api_peer_photo.h"
#include "settings/settings_information.h" // UpdatePhotoLocally
#include "styles/style_chat.h"
namespace HistoryView {
@ -76,8 +77,10 @@ ClickHandlerPtr UserpicSuggestion::createViewLink() {
const auto original = std::make_shared<QImage>(
media->image(Data::PhotoSize::Large)->original());
const auto callback = [=](QImage &&image) {
using namespace Settings;
const auto session = &photo->session();
const auto user = session->user();
UpdatePhotoLocally(user, image);
auto &peerPhotos = session->api().peerPhoto();
if (original->size() == image.size()
&& original->constBits() == image.constBits()) {
@ -85,6 +88,7 @@ ClickHandlerPtr UserpicSuggestion::createViewLink() {
} else {
peerPhotos.upload(user, std::move(image));
}
controller->showSettings(Information::Id());
};
Editor::PrepareProfilePhoto(
controller->content(),

View file

@ -266,20 +266,6 @@ private:
return upload;
}
void UploadPhoto(not_null<UserData*> user, QImage image) {
auto bytes = QByteArray();
auto buffer = QBuffer(&bytes);
image.save(&buffer, "JPG", 87);
user->setUserpic(
base::RandomValue<PhotoId>(),
ImageLocation(
{ .data = InMemoryLocation{ .bytes = bytes } },
image.width(),
image.height()),
false);
user->session().api().peerPhoto().upload(user, std::move(image));
}
void SetupPhoto(
not_null<Ui::VerticalLayout*> container,
not_null<Window::SessionController*> controller,
@ -297,8 +283,10 @@ void SetupPhoto(
upload->chosenImages(
) | rpl::start_with_next([=](Ui::UserpicButton::ChosenImage &&chosen) {
UploadPhoto(self, chosen.image);
photo->changeTo(std::move(chosen.image));
auto &image = chosen.image;
UpdatePhotoLocally(self, image);
photo->changeTo(base::duplicate(image));
self->session().api().peerPhoto().upload(self, std::move(image));
}, upload->lifetime());
const auto name = Ui::CreateChild<Ui::FlatLabel>(
@ -976,6 +964,19 @@ AccountsEvents SetupAccounts(
};
}
void UpdatePhotoLocally(not_null<UserData*> user, const QImage &image) {
auto bytes = QByteArray();
auto buffer = QBuffer(&bytes);
image.save(&buffer, "JPG", 87);
user->setUserpic(
base::RandomValue<PhotoId>(),
ImageLocation(
{ .data = InMemoryLocation{ .bytes = bytes } },
image.width(),
image.height()),
false);
}
namespace Badge {
Dialogs::Ui::UnreadBadgeStyle Style() {

View file

@ -40,6 +40,8 @@ AccountsEvents SetupAccounts(
not_null<Ui::VerticalLayout*> container,
not_null<Window::SessionController*> controller);
void UpdatePhotoLocally(not_null<UserData*> user, const QImage &image);
namespace Badge {
[[nodiscard]] Dialogs::Ui::UnreadBadgeStyle Style();