tdesktop/Telegram/SourceFiles/data/data_message_reactions.h

180 lines
4.3 KiB
C
Raw Normal View History

2019-09-11 09:26:13 +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
2021-12-28 18:20:32 +00:00
#include "base/timer.h"
namespace Lottie {
class Icon;
} // namespace Lottie
2019-09-11 09:26:13 +00:00
namespace Data {
class DocumentMedia;
class Session;
struct Reaction {
QString emoji;
QString title;
not_null<DocumentData*> staticIcon;
2021-12-22 11:56:02 +00:00
not_null<DocumentData*> appearAnimation;
not_null<DocumentData*> selectAnimation;
//not_null<DocumentData*> activateAnimation;
//not_null<DocumentData*> activateEffects;
2022-01-10 09:43:26 +00:00
DocumentData *centerIcon = nullptr;
2022-01-05 10:37:35 +00:00
DocumentData *aroundAnimation = nullptr;
2021-12-22 11:56:02 +00:00
bool active = false;
bool premium = false;
};
class Reactions final {
public:
explicit Reactions(not_null<Session*> owner);
~Reactions();
void refresh();
2021-12-22 11:56:02 +00:00
enum class Type {
Active,
All,
};
[[nodiscard]] const std::vector<Reaction> &list(Type type) const;
[[nodiscard]] QString favorite() const;
void setFavorite(const QString &emoji);
2022-01-10 14:22:43 +00:00
[[nodiscard]] static base::flat_set<QString> ParseAllowed(
const MTPVector<MTPstring> *list);
[[nodiscard]] rpl::producer<> updates() const;
enum class ImageSize {
BottomInfo,
InlineList,
};
void preloadImageFor(const QString &emoji);
2022-01-11 15:33:14 +00:00
void preloadAnimationsFor(const QString &emoji);
[[nodiscard]] QImage resolveImageFor(
const QString &emoji,
ImageSize size);
2021-12-27 21:37:00 +00:00
void send(not_null<HistoryItem*> item, const QString &chosen);
[[nodiscard]] bool sending(not_null<HistoryItem*> item) const;
2021-12-28 18:20:32 +00:00
void poll(not_null<HistoryItem*> item, crl::time now);
void updateAllInHistory(not_null<PeerData*> peer, bool enabled);
[[nodiscard]] static bool HasUnread(const MTPMessageReactions &data);
static void CheckUnknownForUnread(
not_null<Session*> owner,
const MTPMessage &message);
private:
struct ImageSet {
QImage bottomInfo;
QImage inlineList;
std::shared_ptr<DocumentMedia> media;
std::unique_ptr<Lottie::Icon> icon;
2022-01-10 09:43:26 +00:00
bool fromAppearAnimation = false;
};
void request();
void updateFromData(const MTPDmessages_availableReactions &data);
[[nodiscard]] std::optional<Reaction> parse(
const MTPAvailableReaction &entry);
2022-01-10 09:43:26 +00:00
void loadImage(
ImageSet &set,
not_null<DocumentData*> document,
bool fromAppearAnimation);
void setLottie(ImageSet &set);
void resolveImages();
void downloadTaskFinished();
2021-12-28 18:20:32 +00:00
void repaintCollected();
void pollCollected();
const not_null<Session*> _owner;
2021-12-22 11:56:02 +00:00
std::vector<Reaction> _active;
std::vector<Reaction> _available;
QString _favorite;
2022-01-07 13:19:43 +00:00
base::flat_map<
not_null<DocumentData*>,
std::shared_ptr<Data::DocumentMedia>> _iconsCache;
rpl::event_stream<> _updated;
mtpRequestId _requestId = 0;
int32 _hash = 0;
base::flat_map<QString, ImageSet> _images;
rpl::lifetime _imagesLoadLifetime;
bool _waitingForList = false;
2021-12-27 21:37:00 +00:00
base::flat_map<FullMsgId, mtpRequestId> _sentRequests;
2021-12-28 18:20:32 +00:00
base::flat_map<not_null<HistoryItem*>, crl::time> _repaintItems;
base::Timer _repaintTimer;
base::flat_set<not_null<HistoryItem*>> _pollItems;
base::flat_set<not_null<HistoryItem*>> _pollingItems;
mtpRequestId _pollRequestId = 0;
mtpRequestId _saveFaveRequestId = 0;
rpl::lifetime _lifetime;
};
struct RecentReaction {
not_null<PeerData*> peer;
bool unread = false;
bool big = false;
inline friend constexpr bool operator==(
const RecentReaction &a,
const RecentReaction &b) noexcept {
return (a.peer.get() == b.peer.get())
&& (a.unread == b.unread)
&& (a.big == b.big);
}
};
2019-09-11 09:26:13 +00:00
class MessageReactions final {
public:
explicit MessageReactions(not_null<HistoryItem*> item);
void add(const QString &reaction);
void remove();
2022-01-31 08:19:21 +00:00
bool change(
const QVector<MTPReactionCount> &list,
2022-01-21 12:48:14 +00:00
const QVector<MTPMessagePeerReaction> &recent,
bool ignoreChosen);
2022-01-28 07:44:12 +00:00
[[nodiscard]] bool checkIfChanged(
const QVector<MTPReactionCount> &list,
const QVector<MTPMessagePeerReaction> &recent) const;
2019-09-11 09:26:13 +00:00
[[nodiscard]] const base::flat_map<QString, int> &list() const;
[[nodiscard]] auto recent() const
-> const base::flat_map<QString, std::vector<RecentReaction>> &;
2019-09-11 09:26:13 +00:00
[[nodiscard]] QString chosen() const;
[[nodiscard]] bool empty() const;
2019-09-11 09:26:13 +00:00
[[nodiscard]] bool hasUnread() const;
2022-01-27 14:38:59 +00:00
void markRead();
2019-09-11 09:26:13 +00:00
private:
const not_null<HistoryItem*> _item;
QString _chosen;
base::flat_map<QString, int> _list;
base::flat_map<QString, std::vector<RecentReaction>> _recent;
2019-09-11 09:26:13 +00:00
};
} // namespace Data