info_profile_badge.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "base/flags.h"
  9. #include "base/object_ptr.h"
  10. namespace style {
  11. struct InfoPeerBadge;
  12. } // namespace style
  13. namespace Data {
  14. enum class CustomEmojiSizeTag : uchar;
  15. } // namespace Data
  16. namespace Main {
  17. class Session;
  18. } // namespace Main
  19. namespace Ui {
  20. class RpWidget;
  21. class AbstractButton;
  22. } // namespace Ui
  23. namespace Ui::Text {
  24. class CustomEmoji;
  25. } // namespace Ui::Text
  26. namespace Info::Profile {
  27. class EmojiStatusPanel;
  28. enum class BadgeType {
  29. None = 0x00,
  30. Verified = 0x01,
  31. BotVerified = 0x02,
  32. Premium = 0x04,
  33. Scam = 0x08,
  34. Fake = 0x10,
  35. };
  36. inline constexpr bool is_flag_type(BadgeType) { return true; }
  37. class Badge final {
  38. public:
  39. struct Content {
  40. BadgeType badge = BadgeType::None;
  41. EmojiStatusId emojiStatusId;
  42. friend inline bool operator==(Content, Content) = default;
  43. };
  44. Badge(
  45. not_null<QWidget*> parent,
  46. const style::InfoPeerBadge &st,
  47. not_null<Main::Session*> session,
  48. rpl::producer<Content> content,
  49. EmojiStatusPanel *emojiStatusPanel,
  50. Fn<bool()> animationPaused,
  51. int customStatusLoopsLimit = 0,
  52. base::flags<BadgeType> allowed
  53. = base::flags<BadgeType>::from_raw(-1));
  54. ~Badge();
  55. [[nodiscard]] Ui::RpWidget *widget() const;
  56. void setPremiumClickCallback(Fn<void()> callback);
  57. [[nodiscard]] rpl::producer<> updated() const;
  58. void move(int left, int top, int bottom);
  59. [[nodiscard]] Data::CustomEmojiSizeTag sizeTag() const;
  60. private:
  61. void setContent(Content content);
  62. const not_null<QWidget*> _parent;
  63. const style::InfoPeerBadge &_st;
  64. const not_null<Main::Session*> _session;
  65. EmojiStatusPanel *_emojiStatusPanel = nullptr;
  66. const int _customStatusLoopsLimit = 0;
  67. std::unique_ptr<Ui::Text::CustomEmoji> _emojiStatus;
  68. base::flags<BadgeType> _allowed;
  69. Content _content;
  70. Fn<void()> _premiumClickCallback;
  71. Fn<bool()> _animationPaused;
  72. object_ptr<Ui::AbstractButton> _view = { nullptr };
  73. rpl::event_stream<> _updated;
  74. rpl::lifetime _lifetime;
  75. };
  76. [[nodiscard]] rpl::producer<Badge::Content> BadgeContentForPeer(
  77. not_null<PeerData*> peer);
  78. [[nodiscard]] rpl::producer<Badge::Content> VerifiedContentForPeer(
  79. not_null<PeerData*> peer);
  80. } // namespace Info::Profile