tdesktop/Telegram/SourceFiles/data/data_message_reactions.h

135 lines
3.2 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"
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-05 10:37:35 +00:00
DocumentData *aroundAnimation = nullptr;
DocumentData *centerIcon = nullptr;
2021-12-22 11:56:02 +00:00
bool active = false;
};
class Reactions final {
public:
explicit Reactions(not_null<Session*> owner);
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]] std::vector<Reaction> list(not_null<PeerData*> peer) const;
[[nodiscard]] static std::vector<Reaction> Filtered(
const std::vector<Reaction> &reactions,
const std::vector<QString> &emoji);
[[nodiscard]] std::vector<Reaction> filtered(
const std::vector<QString> &emoji) const;
[[nodiscard]] static std::vector<QString> ParseAllowed(
const MTPVector<MTPstring> *list);
[[nodiscard]] rpl::producer<> updates() const;
enum class ImageSize {
BottomInfo,
InlineList,
};
void preloadImageFor(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);
private:
struct ImageSet {
QImage bottomInfo;
QImage inlineList;
std::shared_ptr<DocumentMedia> media;
};
void request();
[[nodiscard]] std::optional<Reaction> parse(
const MTPAvailableReaction &entry);
void loadImage(ImageSet &set, not_null<DocumentData*> document);
void setImage(ImageSet &set, QImage large);
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;
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;
rpl::lifetime _lifetime;
};
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();
2019-09-11 09:26:13 +00:00
void set(const QVector<MTPReactionCount> &list, bool ignoreChosen);
[[nodiscard]] const base::flat_map<QString, int> &list() const;
[[nodiscard]] QString chosen() const;
[[nodiscard]] bool empty() const;
2019-09-11 09:26:13 +00:00
private:
const not_null<HistoryItem*> _item;
QString _chosen;
base::flat_map<QString, int> _list;
};
} // namespace Data