scheduled_messages.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "history/history_item.h"
  9. #include "base/timer.h"
  10. class History;
  11. namespace Main {
  12. class Session;
  13. } // namespace Main
  14. namespace Data {
  15. struct MessagesSlice;
  16. [[nodiscard]] bool IsScheduledMsgId(MsgId id);
  17. class ScheduledMessages final {
  18. public:
  19. explicit ScheduledMessages(not_null<Main::Session*> session);
  20. ScheduledMessages(const ScheduledMessages &other) = delete;
  21. ScheduledMessages &operator=(const ScheduledMessages &other) = delete;
  22. ~ScheduledMessages();
  23. [[nodiscard]] MsgId lookupId(not_null<const HistoryItem*> item) const;
  24. [[nodiscard]] HistoryItem *lookupItem(PeerId peer, MsgId msg) const;
  25. [[nodiscard]] HistoryItem *lookupItem(FullMsgId itemId) const;
  26. [[nodiscard]] int count(not_null<History*> history) const;
  27. [[nodiscard]] bool hasFor(not_null<Data::ForumTopic*> topic) const;
  28. [[nodiscard]] MsgId localMessageId(MsgId remoteId) const;
  29. void checkEntitiesAndUpdate(const MTPDmessage &data);
  30. void apply(const MTPDupdateNewScheduledMessage &update);
  31. void apply(const MTPDupdateDeleteScheduledMessages &update);
  32. void apply(
  33. const MTPDupdateMessageID &update,
  34. not_null<HistoryItem*> local);
  35. void appendSending(not_null<HistoryItem*> item);
  36. void removeSending(not_null<HistoryItem*> item);
  37. void sendNowSimpleMessage(
  38. const MTPDupdateShortSentMessage &update,
  39. not_null<HistoryItem*> local);
  40. [[nodiscard]] rpl::producer<> updates(not_null<History*> history);
  41. [[nodiscard]] Data::MessagesSlice list(not_null<History*> history) const;
  42. [[nodiscard]] Data::MessagesSlice list(
  43. not_null<const Data::ForumTopic*> topic) const;
  44. void clear();
  45. private:
  46. using OwnedItem = std::unique_ptr<HistoryItem, HistoryItem::Destroyer>;
  47. struct List {
  48. std::vector<OwnedItem> items;
  49. base::flat_map<MsgId, not_null<HistoryItem*>> itemById;
  50. };
  51. struct Request {
  52. mtpRequestId requestId = 0;
  53. crl::time lastReceived = 0;
  54. };
  55. void request(not_null<History*> history);
  56. void parse(
  57. not_null<History*> history,
  58. const MTPmessages_Messages &list);
  59. HistoryItem *append(
  60. not_null<History*> history,
  61. List &list,
  62. const MTPMessage &message);
  63. void clearNotSending(not_null<History*> history);
  64. void updated(
  65. not_null<History*> history,
  66. const base::flat_set<not_null<HistoryItem*>> &added,
  67. const base::flat_set<not_null<HistoryItem*>> &clear);
  68. void sort(List &list);
  69. void remove(not_null<const HistoryItem*> item);
  70. [[nodiscard]] uint64 countListHash(const List &list) const;
  71. void clearOldRequests();
  72. const not_null<Main::Session*> _session;
  73. base::Timer _clearTimer;
  74. base::flat_map<not_null<History*>, List> _data;
  75. base::flat_map<not_null<History*>, Request> _requests;
  76. rpl::event_stream<not_null<History*>> _updates;
  77. rpl::lifetime _lifetime;
  78. };
  79. } // namespace Data