tdesktop/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.h

148 lines
3.9 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 {
class SinglePlayer;
class FrameProvider;
2019-08-07 14:22:51 +00:00
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
namespace HistoryView {
class Element;
} // namespace HistoryView
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:
using ViewElement = HistoryView::Element;
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
bool add(not_null<ViewElement*> view);
void remove(not_null<const ViewElement*> view);
2019-08-01 21:14:19 +00:00
[[nodiscard]] Sticker stickerForEmoji(EmojiPtr emoji);
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
[[nodiscard]] EmojiPtr chooseInteractionEmoji(
not_null<HistoryItem*> item) const;
[[nodiscard]] EmojiPtr chooseInteractionEmoji(
const QString &emoticon) const;
2021-09-14 16:55:35 +00:00
[[nodiscard]] auto animationsForEmoji(EmojiPtr emoji) const
-> const base::flat_map<int, not_null<DocumentData*>> &;
[[nodiscard]] bool hasAnimationsFor(not_null<HistoryItem*> item) const;
[[nodiscard]] bool hasAnimationsFor(const QString &emoticon) const;
[[nodiscard]] int animationsVersion() const {
return _animationsVersion;
}
[[nodiscard]] rpl::producer<> refreshed() const {
return _refreshed.events();
}
2021-09-14 16:55:35 +00:00
[[nodiscard]] std::unique_ptr<Lottie::SinglePlayer> effectPlayer(
not_null<DocumentData*> document,
QByteArray data,
QString filepath,
bool premium);
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);
void refreshItems(const base::flat_set<not_null<ViewElement*>> &list);
void refreshItems(const base::flat_set<not_null<HistoryItem*>> &items);
2019-08-01 14:13:02 +00:00
const not_null<Main::Session*> _session;
2019-08-01 14:13:02 +00:00
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<HistoryView::Element*>>> _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;
base::flat_set<not_null<HistoryView::Element*>> _onlyCustomItems;
int _animationsVersion = 0;
2021-09-14 16:55:35 +00:00
base::flat_map<
EmojiPtr,
base::flat_map<int, not_null<DocumentData*>>> _animations;
mtpRequestId _animationsRequestId = 0;
base::flat_map<
not_null<DocumentData*>,
std::weak_ptr<Lottie::FrameProvider>> _sharedProviders;
rpl::event_stream<> _refreshed;
2019-08-01 14:13:02 +00:00
rpl::lifetime _lifetime;
};
} // namespace Stickers