tdesktop/Telegram/SourceFiles/data/components/scheduled_messages.h

101 lines
2.9 KiB
C
Raw Normal View History

2019-08-08 14:13:26 +00:00
/*
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"
2019-08-08 14:13:26 +00:00
class History;
namespace Main {
class Session;
} // namespace Main
namespace Data {
struct MessagesSlice;
2019-08-08 14:13:26 +00:00
2022-05-13 14:54:35 +00:00
[[nodiscard]] bool IsScheduledMsgId(MsgId id);
2019-08-08 14:13:26 +00:00
class ScheduledMessages final {
public:
explicit ScheduledMessages(not_null<Main::Session*> session);
2019-08-08 14:13:26 +00:00
ScheduledMessages(const ScheduledMessages &other) = delete;
ScheduledMessages &operator=(const ScheduledMessages &other) = delete;
~ScheduledMessages();
[[nodiscard]] MsgId lookupId(not_null<const HistoryItem*> item) const;
[[nodiscard]] HistoryItem *lookupItem(PeerId peer, MsgId msg) const;
[[nodiscard]] HistoryItem *lookupItem(FullMsgId itemId) const;
[[nodiscard]] int count(not_null<History*> history) const;
[[nodiscard]] bool hasFor(not_null<Data::ForumTopic*> topic) const;
2022-05-13 14:54:35 +00:00
[[nodiscard]] MsgId localMessageId(MsgId remoteId) const;
2019-08-08 14:13:26 +00:00
void checkEntitiesAndUpdate(const MTPDmessage &data);
2019-08-08 14:13:26 +00:00
void apply(const MTPDupdateNewScheduledMessage &update);
void apply(const MTPDupdateDeleteScheduledMessages &update);
2019-08-12 16:33:36 +00:00
void apply(
const MTPDupdateMessageID &update,
not_null<HistoryItem*> local);
void appendSending(not_null<HistoryItem*> item);
void removeSending(not_null<HistoryItem*> item);
2019-08-08 14:13:26 +00:00
void sendNowSimpleMessage(
const MTPDupdateShortSentMessage &update,
not_null<HistoryItem*> local);
2019-08-08 14:13:26 +00:00
[[nodiscard]] rpl::producer<> updates(not_null<History*> history);
[[nodiscard]] Data::MessagesSlice list(not_null<History*> history) const;
[[nodiscard]] Data::MessagesSlice list(
not_null<const Data::ForumTopic*> topic) const;
2019-08-08 14:13:26 +00:00
void clear();
2019-08-08 14:13:26 +00:00
private:
using OwnedItem = std::unique_ptr<HistoryItem, HistoryItem::Destroyer>;
struct List {
std::vector<OwnedItem> items;
base::flat_map<MsgId, not_null<HistoryItem*>> itemById;
};
struct Request {
mtpRequestId requestId = 0;
crl::time lastReceived = 0;
2019-08-08 14:13:26 +00:00
};
void request(not_null<History*> history);
void parse(
not_null<History*> history,
const MTPmessages_Messages &list);
2019-08-12 16:33:36 +00:00
HistoryItem *append(
2019-08-08 14:13:26 +00:00
not_null<History*> history,
List &list,
const MTPMessage &message);
2019-08-20 13:21:10 +00:00
void clearNotSending(not_null<History*> history);
void updated(
not_null<History*> history,
const base::flat_set<not_null<HistoryItem*>> &added,
const base::flat_set<not_null<HistoryItem*>> &clear);
2019-08-09 13:12:03 +00:00
void sort(List &list);
2019-08-08 14:13:26 +00:00
void remove(not_null<const HistoryItem*> item);
2021-08-25 08:15:05 +00:00
[[nodiscard]] uint64 countListHash(const List &list) const;
void clearOldRequests();
2019-08-08 14:13:26 +00:00
const not_null<Main::Session*> _session;
base::Timer _clearTimer;
2019-08-08 14:13:26 +00:00
base::flat_map<not_null<History*>, List> _data;
base::flat_map<not_null<History*>, Request> _requests;
rpl::event_stream<not_null<History*>> _updates;
rpl::lifetime _lifetime;
};
} // namespace Data