/* 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 #include "base/timer.h" namespace Data { class DocumentMedia; class Session; struct Reaction { QString emoji; QString title; not_null staticIcon; not_null appearAnimation; not_null selectAnimation; not_null activateAnimation; not_null activateEffects; bool active = false; }; class Reactions final { public: explicit Reactions(not_null owner); void refresh(); enum class Type { Active, All, }; [[nodiscard]] const std::vector &list(Type type) const; [[nodiscard]] std::vector list(not_null peer) const; [[nodiscard]] static std::vector Filtered( const std::vector &reactions, const std::vector &emoji); [[nodiscard]] std::vector filtered( const std::vector &emoji) const; [[nodiscard]] static std::vector ParseAllowed( const MTPVector *list); [[nodiscard]] rpl::producer<> updates() const; enum class ImageSize { BottomInfo, InlineList, }; void preloadImageFor(const QString &emoji); [[nodiscard]] QImage resolveImageFor( const QString &emoji, ImageSize size); void send(not_null item, const QString &chosen); [[nodiscard]] bool sending(not_null item) const; void poll(not_null item, crl::time now); void updateAllInHistory(not_null peer, bool enabled); private: struct ImageSet { QImage bottomInfo; QImage inlineList; std::shared_ptr media; }; void request(); [[nodiscard]] std::optional parse( const MTPAvailableReaction &entry); void loadImage(ImageSet &set, not_null document); void setImage(ImageSet &set, QImage large); void resolveImages(); void downloadTaskFinished(); void repaintCollected(); void pollCollected(); const not_null _owner; std::vector _active; std::vector _available; rpl::event_stream<> _updated; mtpRequestId _requestId = 0; int32 _hash = 0; base::flat_map _images; rpl::lifetime _imagesLoadLifetime; bool _waitingForList = false; base::flat_map _sentRequests; base::flat_map, crl::time> _repaintItems; base::Timer _repaintTimer; base::flat_set> _pollItems; base::flat_set> _pollingItems; mtpRequestId _pollRequestId = 0; rpl::lifetime _lifetime; }; class MessageReactions final { public: explicit MessageReactions(not_null item); void add(const QString &reaction); void remove(); void set(const QVector &list, bool ignoreChosen); [[nodiscard]] const base::flat_map &list() const; [[nodiscard]] QString chosen() const; [[nodiscard]] bool empty() const; private: const not_null _item; QString _chosen; base::flat_map _list; }; } // namespace Data