tdesktop/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.h

111 lines
2.7 KiB
C
Raw Normal View History

2019-08-01 14:13:02 +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
2019-08-02 18:19:14 +00:00
#include "ui/text/text_isolated_emoji.h"
2020-05-29 14:29:21 +00:00
#include "ui/image/image.h"
2019-08-05 14:08:20 +00:00
#include "base/timer.h"
2019-08-02 18:19:14 +00:00
#include <crl/crl_object_on_queue.h>
2019-08-07 14:22:51 +00:00
class HistoryItem;
class DocumentData;
2019-08-01 14:13:02 +00:00
namespace Main {
class Session;
} // namespace Main
2019-08-07 14:22:51 +00:00
namespace Lottie {
struct ColorReplacements;
} // namespace Lottie
2019-08-01 14:13:02 +00:00
2019-08-02 18:19:14 +00:00
namespace Ui {
namespace Text {
class String;
} // namespace Text
2019-08-05 14:08:20 +00:00
namespace Emoji {
class UniversalImages;
} // namespace Emoji
2019-08-02 18:19:14 +00:00
} // namespace Ui
2019-08-01 14:13:02 +00:00
namespace Stickers {
2019-08-02 18:19:14 +00:00
using IsolatedEmoji = Ui::Text::IsolatedEmoji;
2019-08-01 14:13:02 +00:00
2020-05-29 14:29:21 +00:00
struct LargeEmojiImage {
std::optional<Image> image;
FnMut<void()> load;
[[nodiscard]] static QSize Size();
};
2019-08-01 14:13:02 +00:00
class EmojiPack final {
public:
2019-08-07 14:22:51 +00:00
struct Sticker {
DocumentData *document = nullptr;
const Lottie::ColorReplacements *replacements = nullptr;
[[nodiscard]] bool empty() const {
return (document == nullptr);
}
[[nodiscard]] explicit operator bool() const {
return !empty();
}
};
2019-08-01 14:13:02 +00:00
explicit EmojiPack(not_null<Main::Session*> session);
2019-08-02 18:19:14 +00:00
~EmojiPack();
2019-08-01 14:13:02 +00:00
2019-08-02 18:19:14 +00:00
bool add(not_null<HistoryItem*> item);
void remove(not_null<const HistoryItem*> item);
2019-08-01 21:14:19 +00:00
2019-08-07 14:22:51 +00:00
[[nodiscard]] Sticker stickerForEmoji(const IsolatedEmoji &emoji);
2020-05-29 14:29:21 +00:00
[[nodiscard]] std::shared_ptr<LargeEmojiImage> image(EmojiPtr emoji);
2019-08-01 14:13:02 +00:00
2021-09-14 16:55:35 +00:00
[[nodiscard]] auto animationsForEmoji(EmojiPtr emoji) const
-> const base::flat_map<int, not_null<DocumentData*>> &;
2019-08-01 14:13:02 +00:00
private:
2019-08-02 18:19:14 +00:00
class ImageLoader;
2019-08-01 14:13:02 +00:00
void refresh();
void refreshDelayed();
2021-09-14 16:55:35 +00:00
void refreshAnimations();
2019-08-01 21:14:19 +00:00
void applySet(const MTPDmessages_stickerSet &data);
void applyPack(
const MTPDstickerPack &data,
const base::flat_map<uint64, not_null<DocumentData*>> &map);
2021-09-14 16:55:35 +00:00
void applyAnimationsSet(const MTPDmessages_stickerSet &data);
[[nodiscard]] auto collectStickers(const QVector<MTPDocument> &list) const
-> base::flat_map<uint64, not_null<DocumentData*>>;
[[nodiscard]] auto collectAnimationsIndices(
const QVector<MTPStickerPack> &packs) const
-> base::flat_map<uint64, base::flat_set<int>>;
2019-08-02 18:19:14 +00:00
void refreshAll();
2019-08-01 21:14:19 +00:00
void refreshItems(EmojiPtr emoji);
2019-08-02 18:19:14 +00:00
void refreshItems(const base::flat_set<not_null<HistoryItem*>> &list);
2019-08-01 14:13:02 +00:00
not_null<Main::Session*> _session;
base::flat_map<EmojiPtr, not_null<DocumentData*>> _map;
2019-08-02 18:19:14 +00:00
base::flat_map<
IsolatedEmoji,
base::flat_set<not_null<HistoryItem*>>> _items;
2020-05-29 14:29:21 +00:00
base::flat_map<EmojiPtr, std::weak_ptr<LargeEmojiImage>> _images;
2019-08-01 14:13:02 +00:00
mtpRequestId _requestId = 0;
2021-09-14 16:55:35 +00:00
base::flat_map<
EmojiPtr,
base::flat_map<int, not_null<DocumentData*>>> _animations;
mtpRequestId _animationsRequestId = 0;
2019-08-01 14:13:02 +00:00
rpl::lifetime _lifetime;
};
} // namespace Stickers