/* 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 "history/history_item.h" #include "base/timer.h" class History; namespace Main { class Session; } // namespace Main namespace Data { struct MessagesSlice; [[nodiscard]] bool IsScheduledMsgId(MsgId id); class ScheduledMessages final { public: explicit ScheduledMessages(not_null session); ScheduledMessages(const ScheduledMessages &other) = delete; ScheduledMessages &operator=(const ScheduledMessages &other) = delete; ~ScheduledMessages(); [[nodiscard]] MsgId lookupId(not_null item) const; [[nodiscard]] HistoryItem *lookupItem(PeerId peer, MsgId msg) const; [[nodiscard]] HistoryItem *lookupItem(FullMsgId itemId) const; [[nodiscard]] int count(not_null history) const; [[nodiscard]] bool hasFor(not_null topic) const; [[nodiscard]] MsgId localMessageId(MsgId remoteId) const; void checkEntitiesAndUpdate(const MTPDmessage &data); void apply(const MTPDupdateNewScheduledMessage &update); void apply(const MTPDupdateDeleteScheduledMessages &update); void apply( const MTPDupdateMessageID &update, not_null local); void appendSending(not_null item); void removeSending(not_null item); void sendNowSimpleMessage( const MTPDupdateShortSentMessage &update, not_null local); [[nodiscard]] rpl::producer<> updates(not_null history); [[nodiscard]] Data::MessagesSlice list(not_null history) const; [[nodiscard]] Data::MessagesSlice list( not_null topic) const; void clear(); private: using OwnedItem = std::unique_ptr; struct List { std::vector items; base::flat_map> itemById; }; struct Request { mtpRequestId requestId = 0; crl::time lastReceived = 0; }; void request(not_null history); void parse( not_null history, const MTPmessages_Messages &list); HistoryItem *append( not_null history, List &list, const MTPMessage &message); void clearNotSending(not_null history); void updated( not_null history, const base::flat_set> &added, const base::flat_set> &clear); void sort(List &list); void remove(not_null item); [[nodiscard]] uint64 countListHash(const List &list) const; void clearOldRequests(); const not_null _session; base::Timer _clearTimer; base::flat_map, List> _data; base::flat_map, Request> _requests; rpl::event_stream> _updates; rpl::lifetime _lifetime; }; } // namespace Data