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;
|
|
|
|
|
|
|
|
struct Reaction {
|
|
|
|
QString emoji;
|
|
|
|
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-01-13 16:39:44 +00:00
|
|
|
[[nodiscard]] QString favorite() const;
|
2022-01-13 19:32:44 +00:00
|
|
|
void setFavorite(const QString &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,
|
|
|
|
};
|
|
|
|
void preloadImageFor(const QString &emoji);
|
2022-01-11 15:33:14 +00:00
|
|
|
void preloadAnimationsFor(const QString &emoji);
|
2021-12-20 15:30:01 +00:00
|
|
|
[[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);
|
|
|
|
|
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-01-13 16:39:44 +00:00
|
|
|
QString _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;
|
|
|
|
|
2021-12-20 15:30:01 +00:00
|
|
|
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;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
void add(const QString &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;
|
2019-09-11 09:26:13 +00:00
|
|
|
[[nodiscard]] const base::flat_map<QString, int> &list() const;
|
2022-01-13 10:13:08 +00:00
|
|
|
[[nodiscard]] auto recent() const
|
2022-01-27 12:55:34 +00:00
|
|
|
-> const base::flat_map<QString, std::vector<RecentReaction>> &;
|
2019-09-11 09:26:13 +00:00
|
|
|
[[nodiscard]] QString 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;
|
|
|
|
|
|
|
|
QString _chosen;
|
|
|
|
base::flat_map<QString, int> _list;
|
2022-01-27 12:55:34 +00:00
|
|
|
base::flat_map<QString, std::vector<RecentReaction>> _recent;
|
2019-09-11 09:26:13 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Data
|