api_send_progress.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 "api/api_common.h"
  9. #include "base/timer.h"
  10. class History;
  11. namespace Main {
  12. class Session;
  13. } // namespace Main
  14. namespace Api {
  15. enum class SendProgressType {
  16. Typing,
  17. RecordVideo,
  18. UploadVideo,
  19. RecordVoice,
  20. UploadVoice,
  21. RecordRound,
  22. UploadRound,
  23. UploadPhoto,
  24. UploadFile,
  25. ChooseLocation,
  26. ChooseContact,
  27. ChooseSticker,
  28. PlayGame,
  29. Speaking,
  30. };
  31. struct SendProgress {
  32. SendProgress(
  33. SendProgressType type,
  34. crl::time until,
  35. int progress = 0)
  36. : type(type)
  37. , until(until)
  38. , progress(progress) {
  39. }
  40. SendProgressType type = SendProgressType::Typing;
  41. crl::time until = 0;
  42. int progress = 0;
  43. };
  44. class SendProgressManager final {
  45. public:
  46. SendProgressManager(not_null<Main::Session*> session);
  47. void update(
  48. not_null<History*> history,
  49. SendProgressType type,
  50. int progress = 0);
  51. void update(
  52. not_null<History*> history,
  53. MsgId topMsgId,
  54. SendProgressType type,
  55. int progress = 0);
  56. void cancel(
  57. not_null<History*> history,
  58. MsgId topMsgId,
  59. SendProgressType type);
  60. void cancel(
  61. not_null<History*> history,
  62. SendProgressType type);
  63. void cancelTyping(not_null<History*> history);
  64. private:
  65. struct Key {
  66. not_null<History*> history;
  67. MsgId topMsgId = 0;
  68. SendProgressType type = SendProgressType();
  69. inline bool operator<(const Key &other) const {
  70. return (history < other.history)
  71. || (history == other.history && topMsgId < other.topMsgId)
  72. || (history == other.history
  73. && topMsgId == other.topMsgId
  74. && type < other.type);
  75. }
  76. };
  77. bool updated(const Key &key, bool doing);
  78. void send(const Key &key, int progress);
  79. void done(mtpRequestId requestId);
  80. [[nodiscard]] bool skipRequest(const Key &key) const;
  81. const not_null<Main::Session*> _session;
  82. base::flat_map<Key, mtpRequestId> _requests;
  83. base::flat_map<Key, crl::time> _updated;
  84. base::Timer _stopTypingTimer;
  85. History *_stopTypingHistory = nullptr;
  86. };
  87. } // namespace Api