2
0
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:
John Preston
2022-12-20 17:12:32 +04:00
parent c7c652a277
commit 1dd83f3d34
26 changed files with 484 additions and 182 deletions

View File

@@ -17,6 +17,12 @@ struct FileReferenceAccumulator {
push(item);
}
}
template <typename Type>
void push(const tl::conditional<Type> &data) {
if (data) {
push(*data);
}
}
void push(const MTPPhoto &data) {
data.match([&](const MTPDphoto &data) {
result.data.emplace(
@@ -47,52 +53,34 @@ struct FileReferenceAccumulator {
}
void push(const MTPTheme &data) {
data.match([&](const MTPDtheme &data) {
if (const auto document = data.vdocument()) {
push(*document);
}
push(data.vdocument());
});
}
void push(const MTPWebPageAttribute &data) {
data.match([&](const MTPDwebPageAttributeTheme &data) {
if (const auto documents = data.vdocuments()) {
push(*documents);
}
push(data.vdocuments());
});
}
void push(const MTPWebPage &data) {
data.match([&](const MTPDwebPage &data) {
if (const auto document = data.vdocument()) {
push(*document);
}
if (const auto attributes = data.vattributes()) {
push(*attributes);
}
if (const auto photo = data.vphoto()) {
push(*photo);
}
if (const auto page = data.vcached_page()) {
push(*page);
}
push(data.vdocument());
push(data.vattributes());
push(data.vphoto());
push(data.vcached_page());
}, [](const auto &data) {
});
}
void push(const MTPGame &data) {
data.match([&](const MTPDgame &data) {
if (const auto document = data.vdocument()) {
push(*document);
}
push(data.vdocument());
}, [](const auto &data) {
});
}
void push(const MTPMessageMedia &data) {
data.match([&](const MTPDmessageMediaPhoto &data) {
if (const auto photo = data.vphoto()) {
push(*photo);
}
push(data.vphoto());
}, [&](const MTPDmessageMediaDocument &data) {
if (const auto document = data.vdocument()) {
push(*document);
}
push(data.vdocument());
}, [&](const MTPDmessageMediaWebPage &data) {
push(data.vwebpage());
}, [&](const MTPDmessageMediaGame &data) {
@@ -102,9 +90,7 @@ struct FileReferenceAccumulator {
}
void push(const MTPMessage &data) {
data.match([&](const MTPDmessage &data) {
if (const auto media = data.vmedia()) {
push(*media);
}
push(data.vmedia());
}, [&](const MTPDmessageService &data) {
data.vaction().match(
[&](const MTPDmessageActionChatEditPhoto &data) {
@@ -125,6 +111,11 @@ struct FileReferenceAccumulator {
push(data.vphotos());
});
}
void push(const MTPusers_UserFull &data) {
data.match([&](const auto &data) {
push(data.vfull_user().data().vpersonal_photo());
});
}
void push(const MTPmessages_RecentStickers &data) {
data.match([&](const MTPDmessages_recentStickers &data) {
push(data.vstickers());
@@ -181,6 +172,10 @@ UpdatedFileReferences GetFileReferences(const MTPphotos_Photos &data) {
return GetFileReferencesHelper(data);
}
UpdatedFileReferences GetFileReferences(const MTPusers_UserFull &data) {
return GetFileReferencesHelper(data);
}
UpdatedFileReferences GetFileReferences(
const MTPmessages_RecentStickers &data) {
return GetFileReferencesHelper(data);

View File

@@ -29,6 +29,18 @@ struct FileOriginUserPhoto {
}
};
struct FileOriginFullUser {
FileOriginFullUser(UserId userId)
: userId(userId) {
}
UserId userId = 0;
inline bool operator<(const FileOriginFullUser &other) const {
return userId < other.userId;
}
};
struct FileOriginPeerPhoto {
explicit FileOriginPeerPhoto(PeerId peerId) : peerId(peerId) {
}
@@ -113,6 +125,7 @@ struct FileOrigin {
v::null_t,
FileOriginMessage,
FileOriginUserPhoto,
FileOriginFullUser,
FileOriginPeerPhoto,
FileOriginStickerSet,
FileOriginSavedGifs,
@@ -126,6 +139,8 @@ struct FileOrigin {
}
FileOrigin(FileOriginUserPhoto data) : data(data) {
}
FileOrigin(FileOriginFullUser data) : data(data) {
}
FileOrigin(FileOriginPeerPhoto data) : data(data) {
}
FileOrigin(FileOriginStickerSet data) : data(data) {
@@ -177,6 +192,7 @@ struct UpdatedFileReferences {
UpdatedFileReferences GetFileReferences(const MTPmessages_Messages &data);
UpdatedFileReferences GetFileReferences(const MTPphotos_Photos &data);
UpdatedFileReferences GetFileReferences(const MTPusers_UserFull &data);
UpdatedFileReferences GetFileReferences(
const MTPmessages_RecentStickers &data);
UpdatedFileReferences GetFileReferences(

View File

@@ -15,6 +15,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_emoji_statuses.h"
#include "data/data_user_names.h"
#include "data/notify/data_notify_settings.h"
#include "api/api_peer_photo.h"
#include "apiwrap.h"
#include "ui/text/text_options.h"
#include "lang/lang_keys.h"
#include "styles/style_chat.h"
@@ -365,11 +367,18 @@ bool UserData::hasCalls() const {
namespace Data {
void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
if (const auto photo = update.vprofile_photo()) {
user->owner().processPhoto(*photo);
}
if (const auto photo = update.vpersonal_photo()) {
user->owner().processPhoto(*photo);
const auto profilePhoto = update.vprofile_photo()
? user->owner().processPhoto(*update.vprofile_photo()).get()
: nullptr;
const auto personalPhoto = update.vpersonal_photo()
? user->owner().processPhoto(*update.vpersonal_photo()).get()
: nullptr;
if (personalPhoto && profilePhoto) {
user->session().api().peerPhoto().registerNonPersonalPhoto(
user,
profilePhoto);
} else {
user->session().api().peerPhoto().unregisterNonPersonalPhoto(user);
}
user->setSettings(update.vsettings());
user->owner().notifySettings().apply(user, update.vnotify_settings());