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 {
|
2022-05-19 15:05:07 +00:00
|
|
|
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
|
|
|
|
|
2022-09-21 14:55:27 +00:00
|
|
|
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:
|
2022-09-21 14:55:27 +00:00
|
|
|
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
|
|
|
|
2022-09-21 14:55:27 +00:00
|
|
|
bool add(not_null<ViewElement*> view);
|
|
|
|
void remove(not_null<const ViewElement*> view);
|
2019-08-01 21:14:19 +00:00
|
|
|
|
2022-06-23 13:52:15 +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
|
|
|
|
2022-08-04 12:55:25 +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*>> &;
|
2022-08-04 12:55:25 +00:00
|
|
|
[[nodiscard]] bool hasAnimationsFor(not_null<HistoryItem*> item) const;
|
|
|
|
[[nodiscard]] bool hasAnimationsFor(const QString &emoticon) const;
|
|
|
|
[[nodiscard]] int animationsVersion() const {
|
|
|
|
return _animationsVersion;
|
|
|
|
}
|
2023-01-24 11:09:11 +00:00
|
|
|
[[nodiscard]] rpl::producer<> refreshed() const {
|
|
|
|
return _refreshed.events();
|
|
|
|
}
|
2021-09-14 16:55:35 +00:00
|
|
|
|
2022-05-19 15:05:07 +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);
|
2022-09-21 14:55:27 +00:00
|
|
|
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
|
|
|
|
2022-09-21 14:55:27 +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,
|
2022-09-21 14:55:27 +00:00
|
|
|
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;
|
|
|
|
|
2022-09-21 14:55:27 +00:00
|
|
|
base::flat_set<not_null<HistoryView::Element*>> _onlyCustomItems;
|
2022-08-03 17:26:39 +00:00
|
|
|
|
2022-08-04 12:55:25 +00:00
|
|
|
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;
|
|
|
|
|
2022-05-19 15:05:07 +00:00
|
|
|
base::flat_map<
|
|
|
|
not_null<DocumentData*>,
|
|
|
|
std::weak_ptr<Lottie::FrameProvider>> _sharedProviders;
|
|
|
|
|
2023-01-24 11:09:11 +00:00
|
|
|
rpl::event_stream<> _refreshed;
|
|
|
|
|
2019-08-01 14:13:02 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Stickers
|