mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to use previous peer userpics.
This commit is contained in:
parent
e033337b26
commit
f5164fe3e4
5 changed files with 76 additions and 0 deletions
|
@ -2043,6 +2043,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_mediaview_today" = "today at {time}";
|
"lng_mediaview_today" = "today at {time}";
|
||||||
"lng_mediaview_yesterday" = "yesterday at {time}";
|
"lng_mediaview_yesterday" = "yesterday at {time}";
|
||||||
"lng_mediaview_date_time" = "{date} at {time}";
|
"lng_mediaview_date_time" = "{date} at {time}";
|
||||||
|
"lng_mediaview_set_userpic" = "Set as Main";
|
||||||
|
|
||||||
"lng_mediaview_saved_to" = "Image was saved to your {downloads} folder";
|
"lng_mediaview_saved_to" = "Image was saved to your {downloads} folder";
|
||||||
"lng_mediaview_downloads" = "Downloads";
|
"lng_mediaview_downloads" = "Downloads";
|
||||||
|
|
|
@ -165,6 +165,37 @@ void PeerPhoto::clear(not_null<PhotoData*> photo) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PeerPhoto::set(not_null<PeerData*> peer, not_null<PhotoData*> photo) {
|
||||||
|
if (peer->userpicPhotoId() == photo->id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (peer == _session->user()) {
|
||||||
|
_api.request(MTPphotos_UpdateProfilePhoto(
|
||||||
|
photo->mtpInput()
|
||||||
|
)).done([=](const MTPphotos_Photo &result) {
|
||||||
|
result.match([&](const MTPDphotos_photo &data) {
|
||||||
|
_session->data().processPhoto(data.vphoto());
|
||||||
|
_session->data().processUsers(data.vusers());
|
||||||
|
});
|
||||||
|
}).send();
|
||||||
|
} else {
|
||||||
|
const auto applier = [=](const MTPUpdates &result) {
|
||||||
|
_session->updates().applyUpdates(result);
|
||||||
|
};
|
||||||
|
if (const auto chat = peer->asChat()) {
|
||||||
|
_api.request(MTPmessages_EditChatPhoto(
|
||||||
|
chat->inputChat,
|
||||||
|
MTP_inputChatPhoto(photo->mtpInput())
|
||||||
|
)).done(applier).send();
|
||||||
|
} else if (const auto channel = peer->asChannel()) {
|
||||||
|
_api.request(MTPchannels_EditPhoto(
|
||||||
|
channel->inputChannel,
|
||||||
|
MTP_inputChatPhoto(photo->mtpInput())
|
||||||
|
)).done(applier).send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PeerPhoto::ready(const FullMsgId &msgId, const MTPInputFile &file) {
|
void PeerPhoto::ready(const FullMsgId &msgId, const MTPInputFile &file) {
|
||||||
const auto maybePeer = _uploads.take(msgId);
|
const auto maybePeer = _uploads.take(msgId);
|
||||||
if (!maybePeer) {
|
if (!maybePeer) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ public:
|
||||||
|
|
||||||
void upload(not_null<PeerData*> peer, QImage &&image);
|
void upload(not_null<PeerData*> peer, QImage &&image);
|
||||||
void clear(not_null<PhotoData*> photo);
|
void clear(not_null<PhotoData*> photo);
|
||||||
|
void set(not_null<PeerData*> peer, not_null<PhotoData*> photo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ready(const FullMsgId &msgId, const MTPInputFile &file);
|
void ready(const FullMsgId &msgId, const MTPInputFile &file);
|
||||||
|
|
|
@ -46,6 +46,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/view/media/history_view_media.h"
|
#include "history/view/media/history_view_media.h"
|
||||||
#include "data/data_media_types.h"
|
#include "data/data_media_types.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
#include "data/data_changes.h"
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
#include "data/data_chat.h"
|
#include "data/data_chat.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
|
@ -995,6 +996,47 @@ void OverlayWidget::fillContextMenuActions(const MenuCallback &addAction) {
|
||||||
[=] { showMediaOverview(); },
|
[=] { showMediaOverview(); },
|
||||||
&st::mediaMenuIconShowAll);
|
&st::mediaMenuIconShowAll);
|
||||||
}
|
}
|
||||||
|
[&] { // Set userpic.
|
||||||
|
if (!_peer || !_photo || (_peer->userpicPhotoId() == _photo->id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
using Type = SharedMediaType;
|
||||||
|
if (sharedMediaType().value_or(Type::File) == Type::ChatPhoto) {
|
||||||
|
if (const auto chat = _peer->asChat()) {
|
||||||
|
if (!chat->canEditInformation()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (const auto channel = _peer->asChannel()) {
|
||||||
|
if (!channel->canEditInformation()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (userPhotosKey()) {
|
||||||
|
if (_user != _user->session().user()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto photo = _photo;
|
||||||
|
const auto peer = _peer;
|
||||||
|
addAction(tr::lng_mediaview_set_userpic(tr::now), [=] {
|
||||||
|
auto lifetime = std::make_shared<rpl::lifetime>();
|
||||||
|
peer->session().changes().peerFlagsValue(
|
||||||
|
peer,
|
||||||
|
Data::PeerUpdate::Flag::Photo
|
||||||
|
) | rpl::start_with_next([=]() mutable {
|
||||||
|
if (lifetime) {
|
||||||
|
base::take(lifetime)->destroy();
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
}, *lifetime);
|
||||||
|
|
||||||
|
peer->session().api().peerPhoto().set(peer, photo);
|
||||||
|
}, &st::mediaMenuIconProfile);
|
||||||
|
}();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto OverlayWidget::computeOverviewType() const
|
auto OverlayWidget::computeOverviewType() const
|
||||||
|
|
|
@ -129,6 +129,7 @@ mediaMenuIconCopy: icon {{ "menu/copy", mediaviewMenuFg }};
|
||||||
mediaMenuIconForward: icon {{ "menu/forward", mediaviewMenuFg }};
|
mediaMenuIconForward: icon {{ "menu/forward", mediaviewMenuFg }};
|
||||||
mediaMenuIconDelete: icon {{ "menu/delete", mediaviewMenuFg }};
|
mediaMenuIconDelete: icon {{ "menu/delete", mediaviewMenuFg }};
|
||||||
mediaMenuIconShowAll: icon {{ "menu/all_media", mediaviewMenuFg }};
|
mediaMenuIconShowAll: icon {{ "menu/all_media", mediaviewMenuFg }};
|
||||||
|
mediaMenuIconProfile: icon {{ "menu/profile", mediaviewMenuFg }};
|
||||||
|
|
||||||
menuIconStartStream: icon {{ "menu/start_stream", menuIconColor }};
|
menuIconStartStream: icon {{ "menu/start_stream", menuIconColor }};
|
||||||
menuIconStartStreamWith: icon {{ "menu/start_stream_with", menuIconColor }};
|
menuIconStartStreamWith: icon {{ "menu/start_stream_with", menuIconColor }};
|
||||||
|
|
Loading…
Add table
Reference in a new issue