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-08-16 15:52:49 +00:00
|
|
|
#include "data/data_message_reaction_id.h"
|
2022-08-24 08:42:01 +00:00
|
|
|
#include "data/stickers/data_custom_emoji.h"
|
2021-12-28 18:20:32 +00:00
|
|
|
|
2022-08-29 12:34:21 +00:00
|
|
|
namespace Ui {
|
|
|
|
class AnimatedIcon;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2022-08-16 17:57:40 +00:00
|
|
|
namespace Ui::Text {
|
|
|
|
class CustomEmoji;
|
|
|
|
} // namespace Ui::Text
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
struct Reaction {
|
2022-08-16 11:28:17 +00:00
|
|
|
ReactionId id;
|
2021-12-07 11:11:27 +00:00
|
|
|
QString title;
|
2022-08-24 08:42:01 +00:00
|
|
|
//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
|
|
|
};
|
|
|
|
|
2022-08-26 09:35:19 +00:00
|
|
|
struct PossibleItemReactionsRef {
|
2022-08-19 12:08:11 +00:00
|
|
|
std::vector<not_null<const Reaction*>> recent;
|
|
|
|
bool morePremiumAvailable = false;
|
|
|
|
bool customAllowed = false;
|
|
|
|
};
|
|
|
|
|
2022-08-26 09:35:19 +00:00
|
|
|
struct PossibleItemReactions {
|
|
|
|
PossibleItemReactions() = default;
|
|
|
|
explicit PossibleItemReactions(const PossibleItemReactionsRef &other);
|
|
|
|
|
|
|
|
std::vector<Reaction> recent;
|
|
|
|
bool morePremiumAvailable = false;
|
|
|
|
bool customAllowed = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] PossibleItemReactionsRef LookupPossibleReactions(
|
2022-08-19 12:08:11 +00:00
|
|
|
not_null<HistoryItem*> item);
|
|
|
|
|
2022-08-24 08:42:01 +00:00
|
|
|
class Reactions final : private CustomEmojiManager::Listener {
|
2021-12-07 11:11:27 +00:00
|
|
|
public:
|
|
|
|
explicit Reactions(not_null<Session*> owner);
|
2022-01-05 12:10:17 +00:00
|
|
|
~Reactions();
|
2021-12-07 11:11:27 +00:00
|
|
|
|
2022-08-26 09:35:19 +00:00
|
|
|
[[nodiscard]] Session &owner() const {
|
|
|
|
return *_owner;
|
|
|
|
}
|
|
|
|
[[nodiscard]] Main::Session &session() const;
|
|
|
|
|
2022-08-24 08:42:01 +00:00
|
|
|
void refreshTop();
|
|
|
|
void refreshRecent();
|
|
|
|
void refreshRecentDelayed();
|
|
|
|
void refreshDefault();
|
2021-12-13 11:26:19 +00:00
|
|
|
|
2021-12-22 11:56:02 +00:00
|
|
|
enum class Type {
|
|
|
|
Active,
|
2022-08-24 08:42:01 +00:00
|
|
|
Recent,
|
|
|
|
Top,
|
2021-12-22 11:56:02 +00:00
|
|
|
All,
|
|
|
|
};
|
|
|
|
[[nodiscard]] const std::vector<Reaction> &list(Type type) const;
|
2022-08-24 08:42:01 +00:00
|
|
|
[[nodiscard]] ReactionId favoriteId() const;
|
|
|
|
[[nodiscard]] const Reaction *favorite() const;
|
|
|
|
void setFavorite(const ReactionId &id);
|
2021-12-07 11:11:27 +00:00
|
|
|
|
2022-08-24 08:42:01 +00:00
|
|
|
[[nodiscard]] rpl::producer<> topUpdates() const;
|
|
|
|
[[nodiscard]] rpl::producer<> recentUpdates() const;
|
|
|
|
[[nodiscard]] rpl::producer<> defaultUpdates() const;
|
|
|
|
[[nodiscard]] rpl::producer<> favoriteUpdates() const;
|
2021-12-07 11:11:27 +00:00
|
|
|
|
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-25 20:56:38 +00:00
|
|
|
void send(not_null<HistoryItem*> item, bool addToRecent);
|
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-08-25 20:56:38 +00:00
|
|
|
void clearTemporary();
|
|
|
|
[[nodiscard]] Reaction *lookupTemporary(const ReactionId &id);
|
|
|
|
|
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-08-29 12:34:21 +00:00
|
|
|
std::unique_ptr<Ui::AnimatedIcon> icon;
|
|
|
|
bool fromSelectAnimation = false;
|
2021-12-20 15:30:01 +00:00
|
|
|
};
|
|
|
|
|
2022-08-24 08:42:01 +00:00
|
|
|
[[nodiscard]] not_null<CustomEmojiManager::Listener*> resolveListener();
|
|
|
|
void customEmojiResolveDone(not_null<DocumentData*> document) override;
|
|
|
|
|
|
|
|
void requestTop();
|
|
|
|
void requestRecent();
|
|
|
|
void requestDefault();
|
|
|
|
|
|
|
|
void updateTop(const MTPDmessages_reactions &data);
|
|
|
|
void updateRecent(const MTPDmessages_reactions &data);
|
|
|
|
void updateDefault(const MTPDmessages_availableReactions &data);
|
|
|
|
|
|
|
|
void recentUpdated();
|
|
|
|
void defaultUpdated();
|
|
|
|
|
|
|
|
[[nodiscard]] std::optional<Reaction> resolveById(const ReactionId &id);
|
|
|
|
[[nodiscard]] std::vector<Reaction> resolveByIds(
|
|
|
|
const std::vector<ReactionId> &ids,
|
|
|
|
base::flat_set<ReactionId> &unresolved);
|
|
|
|
void resolve(const ReactionId &id);
|
|
|
|
void applyFavorite(const ReactionId &id);
|
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,
|
2022-08-29 12:34:21 +00:00
|
|
|
bool fromSelectAnimation);
|
|
|
|
void setAnimatedIcon(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-24 08:42:01 +00:00
|
|
|
std::vector<Reaction> _recent;
|
|
|
|
std::vector<ReactionId> _recentIds;
|
|
|
|
base::flat_set<ReactionId> _unresolvedRecent;
|
|
|
|
std::vector<Reaction> _top;
|
|
|
|
std::vector<ReactionId> _topIds;
|
|
|
|
base::flat_set<ReactionId> _unresolvedTop;
|
|
|
|
ReactionId _favoriteId;
|
|
|
|
ReactionId _unresolvedFavoriteId;
|
|
|
|
std::optional<Reaction> _favorite;
|
2022-01-07 13:19:43 +00:00
|
|
|
base::flat_map<
|
|
|
|
not_null<DocumentData*>,
|
2022-08-19 12:08:11 +00:00
|
|
|
std::shared_ptr<DocumentMedia>> _iconsCache;
|
2022-08-24 08:42:01 +00:00
|
|
|
rpl::event_stream<> _topUpdated;
|
|
|
|
rpl::event_stream<> _recentUpdated;
|
|
|
|
rpl::event_stream<> _defaultUpdated;
|
|
|
|
rpl::event_stream<> _favoriteUpdated;
|
|
|
|
|
2022-08-25 20:56:38 +00:00
|
|
|
// We need &i->second stay valid while inserting new items.
|
|
|
|
// So we use std::map instead of base::flat_map here.
|
|
|
|
// Otherwise we could use flat_map<DocumentId, unique_ptr<Reaction>>.
|
|
|
|
std::map<DocumentId, Reaction> _temporary;
|
|
|
|
|
2022-08-24 08:42:01 +00:00
|
|
|
base::Timer _topRefreshTimer;
|
|
|
|
mtpRequestId _topRequestId = 0;
|
|
|
|
uint64 _topHash = 0;
|
|
|
|
|
|
|
|
mtpRequestId _recentRequestId = 0;
|
|
|
|
bool _recentRequestScheduled = false;
|
|
|
|
uint64 _recentHash = 0;
|
|
|
|
|
|
|
|
mtpRequestId _defaultRequestId = 0;
|
|
|
|
int32 _defaultHash = 0;
|
2021-12-07 11:11:27 +00:00
|
|
|
|
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-25 20:56:38 +00:00
|
|
|
void add(const ReactionId &id, bool addToRecent);
|
|
|
|
void remove(const ReactionId &id);
|
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-25 20:56:38 +00:00
|
|
|
[[nodiscard]] const std::vector<MessageReaction> &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>> &;
|
2022-08-25 20:56:38 +00:00
|
|
|
[[nodiscard]] std::vector<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-25 20:56:38 +00:00
|
|
|
std::vector<MessageReaction> _list;
|
2022-08-16 11:28:17 +00:00
|
|
|
base::flat_map<ReactionId, std::vector<RecentReaction>> _recent;
|
2019-09-11 09:26:13 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Data
|