mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Change the userpic locally while uploading.
This commit is contained in:
parent
b8028886b0
commit
435d451f3f
1 changed files with 14 additions and 3 deletions
|
@ -45,12 +45,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/file_utilities.h"
|
#include "core/file_utilities.h"
|
||||||
#include "base/call_delayed.h"
|
#include "base/call_delayed.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
|
#include "base/random.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_settings.h"
|
#include "styles/style_settings.h"
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
|
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
#include <QtGui/QClipboard>
|
#include <QtGui/QClipboard>
|
||||||
|
#include <QtCore/QBuffer>
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -145,6 +147,17 @@ private:
|
||||||
return upload;
|
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()));
|
||||||
|
user->session().api().peerPhoto().upload(user, std::move(image));
|
||||||
|
}
|
||||||
|
|
||||||
void SetupPhoto(
|
void SetupPhoto(
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
|
@ -162,9 +175,7 @@ void SetupPhoto(
|
||||||
|
|
||||||
upload->chosenImages(
|
upload->chosenImages(
|
||||||
) | rpl::start_with_next([=](QImage &&image) {
|
) | rpl::start_with_next([=](QImage &&image) {
|
||||||
self->session().api().peerPhoto().upload(
|
UploadPhoto(self, image);
|
||||||
self,
|
|
||||||
base::duplicate(image));
|
|
||||||
photo->changeTo(std::move(image));
|
photo->changeTo(std::move(image));
|
||||||
}, upload->lifetime());
|
}, upload->lifetime());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue