mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to set photo for contact from userpic emoji builder.
This commit is contained in:
parent
48b783f6a0
commit
8887b2f542
2 changed files with 28 additions and 23 deletions
|
@ -412,16 +412,18 @@ void PeerPhoto::ready(
|
||||||
)).done(applier).afterRequest(history->sendRequestId).send();
|
)).done(applier).afterRequest(history->sendRequestId).send();
|
||||||
} else if (const auto user = peer->asUser()) {
|
} else if (const auto user = peer->asUser()) {
|
||||||
using Flag = MTPphotos_UploadContactProfilePhoto::Flag;
|
using Flag = MTPphotos_UploadContactProfilePhoto::Flag;
|
||||||
|
const auto none = MTPphotos_UploadContactProfilePhoto::Flags(0);
|
||||||
_api.request(MTPphotos_UploadContactProfilePhoto(
|
_api.request(MTPphotos_UploadContactProfilePhoto(
|
||||||
MTP_flags(Flag::f_file
|
MTP_flags((file ? Flag::f_file : none)
|
||||||
|
| (videoSize ? Flag::f_video_emoji_markup : none)
|
||||||
| ((type == UploadType::Suggestion)
|
| ((type == UploadType::Suggestion)
|
||||||
? Flag::f_suggest
|
? Flag::f_suggest
|
||||||
: Flag::f_save)),
|
: Flag::f_save)),
|
||||||
user->inputUser,
|
user->inputUser,
|
||||||
*file,
|
file ? (*file) : MTPInputFile(),
|
||||||
MTPInputFile(), // video
|
MTPInputFile(), // video
|
||||||
MTPdouble(), // video_start_ts
|
MTPdouble(), // video_start_ts
|
||||||
MTPVideoSize() // video_emoji_markup
|
videoSize ? (*videoSize) : MTPVideoSize() // video_emoji_markup
|
||||||
)).done([=](const MTPphotos_Photo &result) {
|
)).done([=](const MTPphotos_Photo &result) {
|
||||||
result.match([&](const MTPDphotos_photo &data) {
|
result.match([&](const MTPDphotos_photo &data) {
|
||||||
_session->data().processPhoto(data.vphoto());
|
_session->data().processPhoto(data.vphoto());
|
||||||
|
|
|
@ -43,6 +43,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "api/api_peer_photo.h"
|
#include "api/api_peer_photo.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
|
#include "styles/style_chat.h"
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
@ -317,10 +318,28 @@ void UserpicButton::choosePhotoLocally() {
|
||||||
callback(type));
|
callback(type));
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
const auto user = _peer ? _peer->asUser() : nullptr;
|
||||||
|
const auto addUserpicBuilder = [&](ChosenType type) {
|
||||||
|
if (!_controller) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto done = [=](UserpicBuilder::Result data) {
|
||||||
|
auto result = ChosenImage{ base::take(data.image), type };
|
||||||
|
result.markup.documentId = data.id;
|
||||||
|
result.markup.colors = base::take(data.colors);
|
||||||
|
_chosenImages.fire(std::move(result));
|
||||||
|
};
|
||||||
|
UserpicBuilder::AddEmojiBuilderAction(
|
||||||
|
_controller,
|
||||||
|
_menu,
|
||||||
|
_controller->session().api().peerPhoto().emojiListValue(user
|
||||||
|
? Api::PeerPhoto::EmojiListType::Profile
|
||||||
|
: Api::PeerPhoto::EmojiListType::Group),
|
||||||
|
done);
|
||||||
|
};
|
||||||
_menu = base::make_unique_q<Ui::PopupMenu>(
|
_menu = base::make_unique_q<Ui::PopupMenu>(
|
||||||
this,
|
this,
|
||||||
st::popupMenuWithIcons);
|
st::popupMenuWithIcons);
|
||||||
const auto user = _peer ? _peer->asUser() : nullptr;
|
|
||||||
if (user && !user->isSelf()) {
|
if (user && !user->isSelf()) {
|
||||||
_menu->addAction(
|
_menu->addAction(
|
||||||
tr::lng_profile_set_photo_for(tr::now),
|
tr::lng_profile_set_photo_for(tr::now),
|
||||||
|
@ -332,7 +351,9 @@ void UserpicButton::choosePhotoLocally() {
|
||||||
[=] { chooseFile(ChosenType::Suggest); },
|
[=] { chooseFile(ChosenType::Suggest); },
|
||||||
&st::menuIconPhotoSuggest);
|
&st::menuIconPhotoSuggest);
|
||||||
}
|
}
|
||||||
|
addUserpicBuilder(ChosenType::Set);
|
||||||
if (hasPersonalPhotoLocally()) {
|
if (hasPersonalPhotoLocally()) {
|
||||||
|
_menu->addSeparator(&st::expandedMenuSeparator);
|
||||||
_menu->addAction(makeResetToOriginalAction());
|
_menu->addAction(makeResetToOriginalAction());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -351,25 +372,7 @@ void UserpicButton::choosePhotoLocally() {
|
||||||
callback(ChosenType::Set)));
|
callback(ChosenType::Set)));
|
||||||
}, &st::menuIconPhotoSet);
|
}, &st::menuIconPhotoSet);
|
||||||
}
|
}
|
||||||
if (_controller) {
|
addUserpicBuilder(ChosenType::Set);
|
||||||
const auto done = [=](UserpicBuilder::Result data) {
|
|
||||||
auto result = ChosenImage{
|
|
||||||
base::take(data.image),
|
|
||||||
ChosenType::Set,
|
|
||||||
};
|
|
||||||
result.markup.documentId = data.id;
|
|
||||||
result.markup.colors = base::take(data.colors);
|
|
||||||
_chosenImages.fire(std::move(result));
|
|
||||||
};
|
|
||||||
auto &session = _controller->session();
|
|
||||||
UserpicBuilder::AddEmojiBuilderAction(
|
|
||||||
_controller,
|
|
||||||
_menu,
|
|
||||||
session.api().peerPhoto().emojiListValue(user
|
|
||||||
? Api::PeerPhoto::EmojiListType::Profile
|
|
||||||
: Api::PeerPhoto::EmojiListType::Group),
|
|
||||||
done);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
chooseFile();
|
chooseFile();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue