Add DeleteStoryOnServerLogEvent.

This commit is contained in:
levlam 2023-06-01 17:41:46 +03:00
parent d929790bad
commit 7ca2061848
6 changed files with 75 additions and 0 deletions

View File

@ -11,6 +11,8 @@
#include "td/telegram/FileReferenceManager.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/logevent/LogEventHelper.h"
#include "td/telegram/MessageEntity.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/StoryContent.h"
@ -18,6 +20,7 @@
#include "td/telegram/Td.h"
#include "td/telegram/UpdatesManager.h"
#include "tddb/td/db/binlog/BinlogEvent.h"
#include "tddb/td/db/binlog/BinlogHelper.h"
#include "td/utils/algorithm.h"
@ -1038,10 +1041,68 @@ void StoryManager::delete_story(StoryId story_id, Promise<Unit> &&promise) {
on_delete_story(dialog_id, story_id);
}
class StoryManager::DeleteStoryOnServerLogEvent {
public:
DialogId dialog_id_;
StoryId story_id_;
template <class StorerT>
void store(StorerT &storer) const {
td::store(dialog_id_, storer);
td::store(story_id_, storer);
}
template <class ParserT>
void parse(ParserT &parser) {
td::parse(dialog_id_, parser);
td::parse(story_id_, parser);
}
};
uint64 StoryManager::save_delete_story_on_server_log_event(DialogId dialog_id, StoryId story_id) {
DeleteStoryOnServerLogEvent log_event{dialog_id, story_id};
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteStoryOnServer,
get_log_event_storer(log_event));
}
void StoryManager::delete_story_on_server(DialogId dialog_id, StoryId story_id, uint64 log_event_id,
Promise<Unit> &&promise) {
LOG(INFO) << "Delete " << story_id << " in " << dialog_id << " from server";
if (log_event_id == 0) {
log_event_id = save_delete_story_on_server_log_event(dialog_id, story_id);
}
auto new_promise = get_erase_log_event_promise(log_event_id, std::move(promise));
promise = std::move(new_promise); // to prevent self-move
td_->create_handler<DeleteStoriesQuery>(std::move(promise))->send({story_id.get()});
}
void StoryManager::on_binlog_events(vector<BinlogEvent> &&events) {
if (G()->close_flag()) {
return;
}
for (auto &event : events) {
CHECK(event.id_ != 0);
switch (event.type_) {
case LogEvent::HandlerType::DeleteStoryOnServer: {
DeleteStoryOnServerLogEvent log_event;
log_event_parse(log_event, event.get_data()).ensure();
auto dialog_id = log_event.dialog_id_;
if (dialog_id != DialogId(td_->contacts_manager_->get_my_id())) {
binlog_erase(G()->td_db()->get_binlog(), event.id_);
break;
}
delete_story_on_server(dialog_id, log_event.story_id_, event.id_, Auto());
break;
}
default:
LOG(FATAL) << "Unsupported log event type " << event.type_;
}
}
}
} // namespace td

View File

@ -27,6 +27,7 @@
namespace td {
struct BinlogEvent;
class StoryContent;
class Td;
@ -109,12 +110,16 @@ class StoryManager final : public Actor {
void reload_story(StoryFullId story_full_id, Promise<Unit> &&promise);
void on_binlog_events(vector<BinlogEvent> &&events);
private:
class UploadMediaCallback;
class SendStoryQuery;
class EditStoryQuery;
class DeleteStoryOnServerLogEvent;
void tear_down() final;
bool is_story_owned(DialogId owner_dialog_id) const;
@ -144,6 +149,8 @@ class StoryManager final : public Actor {
vector<FileId> get_story_file_ids(const Story *story) const;
static uint64 save_delete_story_on_server_log_event(DialogId dialog_id, StoryId story_id);
void delete_story_on_server(DialogId dialog_id, StoryId story_id, uint64 log_event_id, Promise<Unit> &&promise);
void delete_story_files(const Story *story) const;

View File

@ -3728,6 +3728,8 @@ void Td::init(Parameters parameters, Result<TdDb::OpenedDatabase> r_opened_datab
send_closure_later(messages_manager_actor_, &MessagesManager::on_binlog_events,
std::move(events.to_messages_manager));
send_closure_later(story_manager_actor_, &StoryManager::on_binlog_events, std::move(events.to_story_manager));
send_closure_later(notification_manager_actor_, &NotificationManager::on_binlog_events,
std::move(events.to_notification_manager));

View File

@ -126,6 +126,9 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue<Binlog> &binlog_p
case LogEvent::HandlerType::ToggleDialogIsTranslatableOnServer:
events.to_messages_manager.push_back(event.clone());
break;
case LogEvent::HandlerType::DeleteStoryOnServer:
events.to_story_manager.push_back(event.clone());
break;
case LogEvent::HandlerType::UpdateScopeNotificationSettingsOnServer:
events.to_notification_settings_manager.push_back(event.clone());
break;

View File

@ -72,6 +72,7 @@ class TdDb {
vector<BinlogEvent> to_messages_manager;
vector<BinlogEvent> to_notification_manager;
vector<BinlogEvent> to_notification_settings_manager;
vector<BinlogEvent> to_story_manager;
int64 since_last_open = 0;
};

View File

@ -107,6 +107,7 @@ class LogEvent {
AddMessagePushNotification = 0x200,
EditMessagePushNotification = 0x201,
SaveAppLog = 0x300,
DeleteStoryOnServer = 0x400,
ConfigPmcMagic = 0x1f18,
BinlogPmcMagic = 0x4327
};