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"
|
|
|
|
|
2022-01-05 12:10:17 +00:00
|
|
|
namespace Lottie {
|
|
|
|
class Icon;
|
|
|
|
} // namespace Lottie
|
|
|
|
|
2019-09-11 09:26:13 +00:00
|
|
|
namespace Data {
|
|
|
|
|
2021-12-20 15:30:01 +00:00
|
|
|
class DocumentMedia;
|
2021-12-07 11:11:27 +00:00
|
|
|
class Session;
|
|
|
|
|
2022-08-16 11:28:17 +00:00
|
|
|
struct ReactionId {
|
|
|
|
std::variant<QString, DocumentId> data;
|
|
|
|
|
|
|
|
[[nodiscard]] bool empty() const {
|
|
|
|
const auto emoji = std::get_if<QString>(&data);
|
|
|
|
return emoji && emoji->isEmpty();
|
|
|
|
}
|
|
|
|
[[nodiscard]] QString emoji() const {
|
|
|
|
const auto emoji = std::get_if<QString>(&data);
|
|
|
|
return emoji ? *emoji : QString();
|
|
|
|
}
|
|
|
|
[[nodiscard]] DocumentId custom() const {
|
|
|
|
const auto custom = std::get_if<DocumentId>(&data);
|
|
|
|
return custom ? *custom : DocumentId();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(ReactionId);
|
|
|
|
|
|
|
|
inline bool operator<(const ReactionId &a, const ReactionId &b) {
|
|
|
|
return a.data < b.data;
|
|
|
|
}
|
|
|
|
inline bool operator==(const ReactionId &a, const ReactionId &b) {
|
|
|
|
return a.data == b.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ReactionId ReactionFromMTP(const MTPReaction &reaction);
|
|
|
|
[[nodiscard]] MTPReaction ReactionToMTP(ReactionId id);
|
|
|
|
|
2021-12-07 11:11:27 +00:00
|
|
|
struct Reaction {
|
2022-08-16 11:28:17 +00:00
|
|
|
ReactionId id;
|
2021-12-07 11:11:27 +00:00
|
|
|
QString title;
|
|
|
|
not_null<DocumentData*> staticIcon;
|
2021-12-22 11:56:02 +00:00
|
|
|
not_null<DocumentData*> appearAnimation;
|
2021-12-07 11:11:27 +00:00
|
|
|
not_null<DocumentData*> selectAnimation;
|
2022-01-11 14:13:04 +00:00
|
|
|
//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;
|
2022-04-21 15:34:00 +00:00
|
|
|
bool premium = false;
|
2021-12-07 11:11:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Reactions final {
|
|
|
|
public:
|
|
|
|
explicit Reactions(not_null<Session*> owner);
|
2022-01-05 12:10:17 +00:00
|
|
|
~Reactions();
|
2021-12-07 11:11:27 +00:00
|
|
|
|
2021-12-13 11:26:19 +00:00
|
|
|
void refresh();
|
|
|
|
|
2021-12-22 11:56:02 +00:00
|
|
|
enum class Type {
|
|
|
|
Active,
|
|
|
|
All,
|
|
|
|
};
|
|
|
|
[[nodiscard]] const std::vector<Reaction> &list(Type type) const;
|
2022-08-16 11:28:17 +00:00
|
|
|
[[nodiscard]] ReactionId favorite() const;
|
|
|
|
void setFavorite(const ReactionId &emoji);
|
2021-12-07 11:11:27 +00:00
|
|
|
|
2022-01-10 14:22:43 +00:00
|
|
|
[[nodiscard]] static base::flat_set<QString> ParseAllowed(
|
2021-12-07 11:11:27 +00:00
|
|
|
const MTPVector<MTPstring> *list);
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<> updates() const;
|
|
|
|
|
2021-12-20 15:30:01 +00:00
|
|
|
enum class ImageSize {
|
|
|
|
BottomInfo,
|
|
|
|
InlineList,
|
|
|
|
};
|
2022-08-16 11:28:17 +00:00
|
|
|
void preloadImageFor(const ReactionId &emoji);
|
|
|
|
void preloadAnimationsFor(const ReactionId &emoji);
|
2021-12-20 15:30:01 +00:00
|
|
|
[[nodiscard]] QImage resolveImageFor(
|
2022-08-16 11:28:17 +00:00
|
|
|
const ReactionId &emoji,
|
2021-12-20 15:30:01 +00:00
|
|
|
ImageSize size);
|
|
|
|
|
2022-08-16 11:28:17 +00:00
|
|
|
void send(not_null<HistoryItem*> item, const ReactionId &chosen);
|
2021-12-27 21:37:00 +00:00
|
|
|
[[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);
|
|
|
|
|
2021-12-28 22:06:01 +00:00
|
|
|
void updateAllInHistory(not_null<PeerData*> peer, bool enabled);
|
|
|
|
|
2022-01-28 14:11:38 +00:00
|
|
|
[[nodiscard]] static bool HasUnread(const MTPMessageReactions &data);
|
|
|
|
static void CheckUnknownForUnread(
|
|
|
|
not_null<Session*> owner,
|
|
|
|
const MTPMessage &message);
|
|
|
|
|
2021-12-07 11:11:27 +00:00
|
|
|
private:
|
2021-12-20 15:30:01 +00:00
|
|
|
struct ImageSet {
|
|
|
|
QImage bottomInfo;
|
|
|
|
QImage inlineList;
|
|
|
|
std::shared_ptr<DocumentMedia> media;
|
2022-01-05 12:10:17 +00:00
|
|
|
std::unique_ptr<Lottie::Icon> icon;
|
2022-01-10 09:43:26 +00:00
|
|
|
bool fromAppearAnimation = false;
|
2021-12-20 15:30:01 +00:00
|
|
|
};
|
|
|
|
|
2021-12-07 11:11:27 +00:00
|
|
|
void request();
|
2022-01-15 09:38:47 +00:00
|
|
|
void updateFromData(const MTPDmessages_availableReactions &data);
|
2021-12-07 11:11:27 +00:00
|
|
|
|
|
|
|
[[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);
|
2022-01-05 12:10:17 +00:00
|
|
|
void setLottie(ImageSet &set);
|
2021-12-20 15:30:01 +00:00
|
|
|
void resolveImages();
|
|
|
|
void downloadTaskFinished();
|
|
|
|
|
2021-12-28 18:20:32 +00:00
|
|
|
void repaintCollected();
|
|
|
|
void pollCollected();
|
|
|
|
|
2021-12-07 11:11:27 +00:00
|
|
|
const not_null<Session*> _owner;
|
|
|
|
|
2021-12-22 11:56:02 +00:00
|
|
|
std::vector<Reaction> _active;
|
2021-12-07 11:11:27 +00:00
|
|
|
std::vector<Reaction> _available;
|
2022-08-16 11:28:17 +00:00
|
|
|
ReactionId _favorite;
|
2022-01-07 13:19:43 +00:00
|
|
|
base::flat_map<
|
|
|
|
not_null<DocumentData*>,
|
|
|
|
std::shared_ptr<Data::DocumentMedia>> _iconsCache;
|
2021-12-07 11:11:27 +00:00
|
|
|
rpl::event_stream<> _updated;
|
|
|
|
|
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
int32 _hash = 0;
|
|
|
|
|
2022-08-16 11:28:17 +00:00
|
|
|
base::flat_map<ReactionId, ImageSet> _images;
|
2021-12-20 15:30:01 +00:00
|
|
|
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;
|
|
|
|
|
2022-01-13 19:32:44 +00:00
|
|
|
mtpRequestId _saveFaveRequestId = 0;
|
|
|
|
|
2021-12-07 11:11:27 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-01-27 12:55:34 +00:00
|
|
|
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);
|
|
|
|
|
2022-08-16 11:28:17 +00:00
|
|
|
void add(const ReactionId &reaction);
|
2021-12-21 13:23:59 +00:00
|
|
|
void remove();
|
2022-01-31 08:19:21 +00:00
|
|
|
bool change(
|
2022-01-13 10:13:08 +00:00
|
|
|
const QVector<MTPReactionCount> &list,
|
2022-01-21 12:48:14 +00:00
|
|
|
const QVector<MTPMessagePeerReaction> &recent,
|
2022-01-13 10:13:08 +00:00
|
|
|
bool ignoreChosen);
|
2022-01-28 07:44:12 +00:00
|
|
|
[[nodiscard]] bool checkIfChanged(
|
|
|
|
const QVector<MTPReactionCount> &list,
|
|
|
|
const QVector<MTPMessagePeerReaction> &recent) const;
|
2022-08-16 11:28:17 +00:00
|
|
|
[[nodiscard]] const base::flat_map<ReactionId, int> &list() const;
|
2022-01-13 10:13:08 +00:00
|
|
|
[[nodiscard]] auto recent() const
|
2022-08-16 11:28:17 +00:00
|
|
|
-> const base::flat_map<ReactionId, std::vector<RecentReaction>> &;
|
|
|
|
[[nodiscard]] ReactionId chosen() const;
|
2021-12-21 13:23:59 +00:00
|
|
|
[[nodiscard]] bool empty() const;
|
2019-09-11 09:26:13 +00:00
|
|
|
|
2022-01-31 15:29:46 +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;
|
|
|
|
|
2022-08-16 11:28:17 +00:00
|
|
|
ReactionId _chosen;
|
|
|
|
base::flat_map<ReactionId, int> _list;
|
|
|
|
base::flat_map<ReactionId, std::vector<RecentReaction>> _recent;
|
2019-09-11 09:26:13 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Data
|