2021-10-20 16:54:22 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mtproto/sender.h"
|
|
|
|
|
|
|
|
class ApiWrap;
|
|
|
|
class PeerData;
|
2022-05-16 01:05:17 +00:00
|
|
|
class UserData;
|
2021-10-20 16:54:22 +00:00
|
|
|
|
2022-12-14 08:20:01 +00:00
|
|
|
namespace Data {
|
|
|
|
struct FileOrigin;
|
|
|
|
} // namespace Data
|
|
|
|
|
2021-10-20 16:54:22 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
|
|
|
namespace Api {
|
|
|
|
|
|
|
|
class PeerPhoto final {
|
|
|
|
public:
|
2022-05-16 01:05:17 +00:00
|
|
|
using UserPhotoId = PhotoId;
|
2021-10-20 16:54:22 +00:00
|
|
|
explicit PeerPhoto(not_null<ApiWrap*> api);
|
|
|
|
|
2023-01-30 14:59:40 +00:00
|
|
|
enum class EmojiListType {
|
|
|
|
Profile,
|
|
|
|
Group,
|
2023-10-27 19:40:39 +00:00
|
|
|
Background,
|
2023-01-30 14:59:40 +00:00
|
|
|
};
|
|
|
|
|
2023-01-30 20:02:02 +00:00
|
|
|
struct UserPhoto {
|
|
|
|
QImage image;
|
|
|
|
DocumentId markupDocumentId = 0;
|
|
|
|
std::vector<QColor> markupColors;
|
|
|
|
};
|
|
|
|
|
2022-12-22 15:02:51 +00:00
|
|
|
void upload(
|
|
|
|
not_null<PeerData*> peer,
|
2023-01-30 20:02:02 +00:00
|
|
|
UserPhoto &&photo,
|
2022-12-22 15:02:51 +00:00
|
|
|
Fn<void()> done = nullptr);
|
2023-01-30 20:02:02 +00:00
|
|
|
void uploadFallback(not_null<PeerData*> peer, UserPhoto &&photo);
|
2022-12-14 08:20:01 +00:00
|
|
|
void updateSelf(
|
|
|
|
not_null<PhotoData*> photo,
|
2022-12-22 15:02:51 +00:00
|
|
|
Data::FileOrigin origin,
|
|
|
|
Fn<void()> done = nullptr);
|
2023-01-30 20:02:02 +00:00
|
|
|
void suggest(not_null<PeerData*> peer, UserPhoto &&photo);
|
2021-10-20 16:54:22 +00:00
|
|
|
void clear(not_null<PhotoData*> photo);
|
2022-12-09 12:34:34 +00:00
|
|
|
void clearPersonal(not_null<UserData*> user);
|
2022-04-06 22:41:26 +00:00
|
|
|
void set(not_null<PeerData*> peer, not_null<PhotoData*> photo);
|
2021-10-20 16:54:22 +00:00
|
|
|
|
2022-05-16 01:05:17 +00:00
|
|
|
void requestUserPhotos(not_null<UserData*> user, UserPhotoId afterId);
|
|
|
|
|
2023-01-30 14:59:40 +00:00
|
|
|
void requestEmojiList(EmojiListType type);
|
|
|
|
using EmojiList = std::vector<DocumentId>;
|
|
|
|
[[nodiscard]] rpl::producer<EmojiList> emojiListValue(EmojiListType type);
|
2023-01-24 09:23:21 +00:00
|
|
|
|
2022-12-19 11:48:24 +00:00
|
|
|
// Non-personal photo in case a personal photo is set.
|
|
|
|
void registerNonPersonalPhoto(
|
|
|
|
not_null<UserData*> user,
|
|
|
|
not_null<PhotoData*> photo);
|
|
|
|
void unregisterNonPersonalPhoto(not_null<UserData*> user);
|
|
|
|
[[nodiscard]] PhotoData *nonPersonalPhoto(
|
|
|
|
not_null<UserData*> user) const;
|
|
|
|
|
2021-10-20 16:54:22 +00:00
|
|
|
private:
|
2022-12-19 15:54:05 +00:00
|
|
|
enum class UploadType {
|
|
|
|
Default,
|
|
|
|
Suggestion,
|
|
|
|
Fallback,
|
|
|
|
};
|
2023-10-27 19:40:39 +00:00
|
|
|
struct EmojiListData {
|
|
|
|
rpl::variable<EmojiList> list;
|
|
|
|
mtpRequestId requestId = 0;
|
|
|
|
};
|
2022-12-19 15:54:05 +00:00
|
|
|
|
2023-01-30 20:02:02 +00:00
|
|
|
void ready(
|
|
|
|
const FullMsgId &msgId,
|
|
|
|
std::optional<MTPInputFile> file,
|
|
|
|
std::optional<MTPVideoSize> videoSize);
|
2022-12-19 15:54:05 +00:00
|
|
|
void upload(
|
|
|
|
not_null<PeerData*> peer,
|
2023-01-30 20:02:02 +00:00
|
|
|
UserPhoto &&photo,
|
2022-12-22 15:02:51 +00:00
|
|
|
UploadType type,
|
|
|
|
Fn<void()> done);
|
2021-10-20 16:54:22 +00:00
|
|
|
|
2023-10-27 19:40:39 +00:00
|
|
|
[[nodiscard]] EmojiListData &emojiList(EmojiListType type);
|
|
|
|
[[nodiscard]] const EmojiListData &emojiList(EmojiListType type) const;
|
|
|
|
|
2021-10-20 16:54:22 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
|
|
|
MTP::Sender _api;
|
|
|
|
|
2022-12-19 15:54:05 +00:00
|
|
|
struct UploadValue {
|
|
|
|
not_null<PeerData*> peer;
|
2022-12-22 15:02:51 +00:00
|
|
|
UploadType type = UploadType::Default;
|
|
|
|
Fn<void()> done;
|
2022-12-19 15:54:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
base::flat_map<FullMsgId, UploadValue> _uploads;
|
2021-10-20 16:54:22 +00:00
|
|
|
|
2022-05-16 01:05:17 +00:00
|
|
|
base::flat_map<not_null<UserData*>, mtpRequestId> _userPhotosRequests;
|
|
|
|
|
2022-12-19 11:48:24 +00:00
|
|
|
base::flat_map<
|
|
|
|
not_null<UserData*>,
|
|
|
|
not_null<PhotoData*>> _nonPersonalPhotos;
|
|
|
|
|
2023-10-27 19:40:39 +00:00
|
|
|
EmojiListData _profileEmojiList;
|
|
|
|
EmojiListData _groupEmojiList;
|
|
|
|
EmojiListData _backgroundEmojiList;
|
2023-01-24 09:23:21 +00:00
|
|
|
|
2021-10-20 16:54:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Api
|