data_send_action.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "ui/effects/animations.h"
  9. class History;
  10. namespace HistoryView {
  11. class SendActionPainter;
  12. } // namespace HistoryView
  13. namespace Data {
  14. class Thread;
  15. class SendActionManager final {
  16. public:
  17. struct AnimationUpdate {
  18. not_null<Thread*> thread;
  19. int left = 0;
  20. int width = 0;
  21. int height = 0;
  22. bool textUpdated = false;
  23. };
  24. explicit SendActionManager();
  25. void registerFor(
  26. not_null<History*> history,
  27. MsgId rootId,
  28. not_null<UserData*> user,
  29. const MTPSendMessageAction &action,
  30. TimeId when);
  31. [[nodiscard]] auto animationUpdated() const
  32. -> rpl::producer<AnimationUpdate>;
  33. void updateAnimation(AnimationUpdate &&update);
  34. [[nodiscard]] auto speakingAnimationUpdated() const
  35. -> rpl::producer<not_null<History*>>;
  36. void updateSpeakingAnimation(not_null<History*> history);
  37. using SendActionPainter = HistoryView::SendActionPainter;
  38. [[nodiscard]] std::shared_ptr<SendActionPainter> repliesPainter(
  39. not_null<History*> history,
  40. MsgId rootId);
  41. void repliesPainterRemoved(
  42. not_null<History*> history,
  43. MsgId rootId);
  44. void repliesPaintersClear(
  45. not_null<History*> history,
  46. not_null<UserData*> user);
  47. void clear();
  48. private:
  49. bool callback(crl::time now);
  50. [[nodiscard]] SendActionPainter *lookupPainter(
  51. not_null<History*> history,
  52. MsgId rootId);
  53. // When typing in this history started.
  54. base::flat_map<
  55. std::pair<not_null<History*>, MsgId>,
  56. crl::time> _sendActions;
  57. Ui::Animations::Basic _animation;
  58. rpl::event_stream<AnimationUpdate> _animationUpdate;
  59. rpl::event_stream<not_null<History*>> _speakingAnimationUpdate;
  60. base::flat_map<
  61. not_null<History*>,
  62. base::flat_map<
  63. MsgId,
  64. std::weak_ptr<SendActionPainter>>> _painters;
  65. };
  66. } // namespace Data