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"
|
2019-08-29 17:16:37 +00:00
|
|
|
#include "base/timer.h"
|
2019-08-08 14:13:26 +00:00
|
|
|
|
|
|
|
class History;
|
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
2019-08-08 17:07:55 +00:00
|
|
|
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:
|
2024-04-13 15:16:07 +00:00
|
|
|
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();
|
|
|
|
|
2022-03-11 07:25:30 +00:00
|
|
|
[[nodiscard]] MsgId lookupId(not_null<const HistoryItem*> item) const;
|
2020-01-26 18:32:19 +00:00
|
|
|
[[nodiscard]] HistoryItem *lookupItem(PeerId peer, MsgId msg) const;
|
2020-05-28 07:59:13 +00:00
|
|
|
[[nodiscard]] HistoryItem *lookupItem(FullMsgId itemId) const;
|
2019-08-08 17:07:55 +00:00
|
|
|
[[nodiscard]] int count(not_null<History*> history) const;
|
2024-03-12 12:36:36 +00:00
|
|
|
[[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
|
|
|
|
2020-01-25 19:19:20 +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
|
|
|
|
2020-01-25 22:41:02 +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);
|
2024-03-12 12:36:36 +00:00
|
|
|
[[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
|
|
|
|
2024-04-16 15:32:07 +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;
|
2019-08-29 17:16:37 +00:00
|
|
|
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;
|
2019-08-29 17:16:37 +00:00
|
|
|
void clearOldRequests();
|
2019-08-08 14:13:26 +00:00
|
|
|
|
|
|
|
const not_null<Main::Session*> _session;
|
|
|
|
|
2019-08-29 17:16:37 +00:00
|
|
|
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
|