Add support for scheduled message IDs in MessagesManager.

GitOrigin-RevId: b489f50556450a142427159a80d6488bf36622d1
This commit is contained in:
levlam 2019-11-29 15:03:03 +03:00
parent cce190ae58
commit 9948e41aed
6 changed files with 689 additions and 169 deletions

View File

@ -62,7 +62,7 @@ class MessageId {
MessageId(T message_id) = delete; MessageId(T message_id) = delete;
static constexpr MessageId min() { static constexpr MessageId min() {
return MessageId(static_cast<int64>(MessageId::TYPE_LOCAL)); return MessageId(static_cast<int64>(MessageId::TYPE_YET_UNSENT));
} }
static constexpr MessageId max() { static constexpr MessageId max() {
return MessageId(static_cast<int64>(std::numeric_limits<int32>::max()) << SERVER_ID_SHIFT); return MessageId(static_cast<int64>(std::numeric_limits<int32>::max()) << SERVER_ID_SHIFT);
@ -102,6 +102,10 @@ class MessageId {
return (id & SHORT_TYPE_MASK) == 0; return (id & SHORT_TYPE_MASK) == 0;
} }
bool is_any_server() const {
return is_scheduled() ? is_scheduled_server() : is_server();
}
ServerMessageId get_server_message_id() const { ServerMessageId get_server_message_id() const {
CHECK(id == 0 || is_server()); CHECK(id == 0 || is_server());
return get_server_message_id_force(); return get_server_message_id_force();

File diff suppressed because it is too large Load Diff

View File

@ -1343,30 +1343,31 @@ class MessagesManager : public Actor {
Promise<> success_promise; Promise<> success_promise;
}; };
class ChangeDialogReportSpamStateOnServerLogEvent;
class DeleteAllChannelMessagesFromUserOnServerLogEvent; class DeleteAllChannelMessagesFromUserOnServerLogEvent;
class DeleteDialogHistoryFromServerLogEvent; class DeleteDialogHistoryFromServerLogEvent;
class DeleteMessageLogEvent; class DeleteMessageLogEvent;
class DeleteMessagesFromServerLogEvent; class DeleteMessagesFromServerLogEvent;
class DeleteScheduledMessagesFromServerLogEvent;
class ForwardMessagesLogEvent; class ForwardMessagesLogEvent;
class GetChannelDifferenceLogEvent; class GetChannelDifferenceLogEvent;
class GetDialogFromServerLogEvent;
class ReadAllDialogMentionsOnServerLogEvent; class ReadAllDialogMentionsOnServerLogEvent;
class ReadHistoryOnServerLogEvent; class ReadHistoryOnServerLogEvent;
class ReadHistoryInSecretChatLogEvent; class ReadHistoryInSecretChatLogEvent;
class ReadMessageContentsOnServerLogEvent; class ReadMessageContentsOnServerLogEvent;
class ReorderPinnedDialogsOnServerLogEvent; class ReorderPinnedDialogsOnServerLogEvent;
class SaveDialogDraftMessageOnServerLogEvent;
class UpdateDialogNotificationSettingsOnServerLogEvent;
class UpdateScopeNotificationSettingsOnServerLogEvent;
class ResetAllNotificationSettingsOnServerLogEvent; class ResetAllNotificationSettingsOnServerLogEvent;
class ChangeDialogReportSpamStateOnServerLogEvent; class SaveDialogDraftMessageOnServerLogEvent;
class SetDialogFolderIdOnServerLogEvent;
class SendBotStartMessageLogEvent; class SendBotStartMessageLogEvent;
class SendInlineQueryResultMessageLogEvent; class SendInlineQueryResultMessageLogEvent;
class SendMessageLogEvent; class SendMessageLogEvent;
class SendScreenshotTakenNotificationMessageLogEvent; class SendScreenshotTakenNotificationMessageLogEvent;
class SetDialogFolderIdOnServerLogEvent;
class ToggleDialogIsPinnedOnServerLogEvent; class ToggleDialogIsPinnedOnServerLogEvent;
class ToggleDialogIsMarkedAsUnreadOnServerLogEvent; class ToggleDialogIsMarkedAsUnreadOnServerLogEvent;
class GetDialogFromServerLogEvent; class UpdateDialogNotificationSettingsOnServerLogEvent;
class UpdateScopeNotificationSettingsOnServerLogEvent;
static constexpr size_t MAX_GROUPED_MESSAGES = 10; // server side limit static constexpr size_t MAX_GROUPED_MESSAGES = 10; // server side limit
static constexpr int32 MAX_GET_DIALOGS = 100; // server side limit static constexpr int32 MAX_GET_DIALOGS = 100; // server side limit
@ -1561,6 +1562,8 @@ class MessagesManager : public Actor {
unique_ptr<Message> do_delete_message(Dialog *d, MessageId message_id, bool is_permanently_deleted, unique_ptr<Message> do_delete_message(Dialog *d, MessageId message_id, bool is_permanently_deleted,
bool only_from_memory, bool *need_update_dialog_pos, const char *source); bool only_from_memory, bool *need_update_dialog_pos, const char *source);
unique_ptr<Message> do_delete_scheduled_message(Dialog *d, MessageId message_id, const char *source);
void on_message_deleted(Dialog *d, Message *m, const char *source); void on_message_deleted(Dialog *d, Message *m, const char *source);
int32 get_unload_dialog_delay() const; int32 get_unload_dialog_delay() const;
@ -1571,9 +1574,14 @@ class MessagesManager : public Actor {
void do_delete_all_dialog_messages(Dialog *d, unique_ptr<Message> &m, vector<int64> &deleted_message_ids); void do_delete_all_dialog_messages(Dialog *d, unique_ptr<Message> &m, vector<int64> &deleted_message_ids);
void delete_message_from_server(DialogId dialog_id, MessageId message_ids, bool revoke);
void delete_messages_from_server(DialogId dialog_id, vector<MessageId> message_ids, bool revoke, uint64 logevent_id, void delete_messages_from_server(DialogId dialog_id, vector<MessageId> message_ids, bool revoke, uint64 logevent_id,
Promise<Unit> &&promise); Promise<Unit> &&promise);
void delete_scheduled_messages_from_server(DialogId dialog_id, vector<MessageId> message_ids, uint64 logevent_id,
Promise<Unit> &&promise);
void delete_dialog_history_from_server(DialogId dialog_id, MessageId max_message_id, bool remove_from_dialog_list, void delete_dialog_history_from_server(DialogId dialog_id, MessageId max_message_id, bool remove_from_dialog_list,
bool revoke, bool allow_error, uint64 logevent_id, Promise<Unit> &&promise); bool revoke, bool allow_error, uint64 logevent_id, Promise<Unit> &&promise);
@ -1692,6 +1700,9 @@ class MessagesManager : public Actor {
Message *add_message_to_dialog(Dialog *d, unique_ptr<Message> message, bool from_update, bool *need_update, Message *add_message_to_dialog(Dialog *d, unique_ptr<Message> message, bool from_update, bool *need_update,
bool *need_update_dialog_pos, const char *source); bool *need_update_dialog_pos, const char *source);
Message *add_scheduled_message_to_dialog(Dialog *d, unique_ptr<Message> message, bool from_update,
const char *source);
void on_message_changed(const Dialog *d, const Message *m, bool need_send_update, const char *source); void on_message_changed(const Dialog *d, const Message *m, bool need_send_update, const char *source);
bool need_delete_file(FullMessageId full_message_id, FileId file_id) const; bool need_delete_file(FullMessageId full_message_id, FileId file_id) const;
@ -2009,7 +2020,8 @@ class MessagesManager : public Actor {
void get_message_force_from_server(Dialog *d, MessageId message_id, Promise<Unit> &&promise, void get_message_force_from_server(Dialog *d, MessageId message_id, Promise<Unit> &&promise,
tl_object_ptr<telegram_api::InputMessage> input_message = nullptr); tl_object_ptr<telegram_api::InputMessage> input_message = nullptr);
Message *on_get_message_from_database(DialogId dialog_id, Dialog *d, const BufferSlice &value, const char *source); Message *on_get_message_from_database(DialogId dialog_id, Dialog *d, const BufferSlice &value, bool is_scheduled,
const char *source);
void get_dialog_message_by_date_from_server(const Dialog *d, int32 date, int64 random_id, bool after_database_search, void get_dialog_message_by_date_from_server(const Dialog *d, int32 date, int64 random_id, bool after_database_search,
Promise<Unit> &&promise); Promise<Unit> &&promise);
@ -2256,7 +2268,7 @@ class MessagesManager : public Actor {
string get_search_text(const Message *m) const; string get_search_text(const Message *m) const;
unique_ptr<Message> parse_message(DialogId dialog_id, const BufferSlice &value); unique_ptr<Message> parse_message(DialogId dialog_id, const BufferSlice &value, bool is_scheduled);
unique_ptr<Dialog> parse_dialog(DialogId dialog_id, const BufferSlice &value); unique_ptr<Dialog> parse_dialog(DialogId dialog_id, const BufferSlice &value);
@ -2278,6 +2290,8 @@ class MessagesManager : public Actor {
uint64 save_delete_messages_from_server_logevent(DialogId dialog_id, const vector<MessageId> &message_ids, uint64 save_delete_messages_from_server_logevent(DialogId dialog_id, const vector<MessageId> &message_ids,
bool revoke); bool revoke);
uint64 save_delete_scheduled_messages_from_server_logevent(DialogId dialog_id, const vector<MessageId> &message_ids);
uint64 save_delete_dialog_history_from_server_logevent(DialogId dialog_id, MessageId max_message_id, uint64 save_delete_dialog_history_from_server_logevent(DialogId dialog_id, MessageId max_message_id,
bool remove_from_dialog_list, bool revoke); bool remove_from_dialog_list, bool revoke);

View File

@ -502,6 +502,7 @@ PollId PollManager::create_poll(string &&question, vector<string> &&options) {
void PollManager::register_poll(PollId poll_id, FullMessageId full_message_id) { void PollManager::register_poll(PollId poll_id, FullMessageId full_message_id) {
CHECK(have_poll(poll_id)); CHECK(have_poll(poll_id));
CHECK(!full_message_id.get_message_id().is_scheduled());
if (!full_message_id.get_message_id().is_server()) { if (!full_message_id.get_message_id().is_server()) {
return; return;
} }
@ -515,6 +516,7 @@ void PollManager::register_poll(PollId poll_id, FullMessageId full_message_id) {
void PollManager::unregister_poll(PollId poll_id, FullMessageId full_message_id) { void PollManager::unregister_poll(PollId poll_id, FullMessageId full_message_id) {
CHECK(have_poll(poll_id)); CHECK(have_poll(poll_id));
CHECK(!full_message_id.get_message_id().is_scheduled());
if (!full_message_id.get_message_id().is_server()) { if (!full_message_id.get_message_id().is_server()) {
return; return;
} }

View File

@ -108,6 +108,7 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue<Binlog> &binlog_p
case LogEvent::HandlerType::ReadHistoryInSecretChat: case LogEvent::HandlerType::ReadHistoryInSecretChat:
case LogEvent::HandlerType::ToggleDialogIsMarkedAsUnreadOnServer: case LogEvent::HandlerType::ToggleDialogIsMarkedAsUnreadOnServer:
case LogEvent::HandlerType::SetDialogFolderIdOnServer: case LogEvent::HandlerType::SetDialogFolderIdOnServer:
case LogEvent::HandlerType::DeleteScheduledMessagesFromServer:
events.to_messages_manager.push_back(event.clone()); events.to_messages_manager.push_back(event.clone());
break; break;
case LogEvent::HandlerType::AddMessagePushNotification: case LogEvent::HandlerType::AddMessagePushNotification:

View File

@ -95,6 +95,7 @@ class LogEvent {
ReadHistoryInSecretChat = 0x114, ReadHistoryInSecretChat = 0x114,
ToggleDialogIsMarkedAsUnreadOnServer = 0x115, ToggleDialogIsMarkedAsUnreadOnServer = 0x115,
SetDialogFolderIdOnServer = 0x116, SetDialogFolderIdOnServer = 0x116,
DeleteScheduledMessagesFromServer = 0x117,
GetChannelDifference = 0x140, GetChannelDifference = 0x140,
AddMessagePushNotification = 0x200, AddMessagePushNotification = 0x200,
EditMessagePushNotification = 0x201, EditMessagePushNotification = 0x201,