Add log event for story reading.
This commit is contained in:
parent
d3a08e06dc
commit
2aeeb09b4d
@ -715,7 +715,7 @@ void StoryManager::open_story(DialogId owner_dialog_id, StoryId story_id, Promis
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (need_read_story && on_update_read_stories(owner_dialog_id, story_id)) {
|
if (need_read_story && on_update_read_stories(owner_dialog_id, story_id)) {
|
||||||
read_stories_on_server(owner_dialog_id, story_id);
|
read_stories_on_server(owner_dialog_id, story_id, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.set_value(Unit());
|
promise.set_value(Unit());
|
||||||
@ -753,8 +753,36 @@ void StoryManager::on_increment_story_views(DialogId owner_dialog_id) {
|
|||||||
increment_story_views(owner_dialog_id, story_views);
|
increment_story_views(owner_dialog_id, story_views);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StoryManager::read_stories_on_server(DialogId owner_dialog_id, StoryId story_id) {
|
class StoryManager::ReadStoriesOnServerLogEvent {
|
||||||
td_->create_handler<ReadStoriesQuery>(Promise<Unit>())->send(owner_dialog_id, story_id);
|
public:
|
||||||
|
DialogId dialog_id_;
|
||||||
|
StoryId max_story_id_;
|
||||||
|
|
||||||
|
template <class StorerT>
|
||||||
|
void store(StorerT &storer) const {
|
||||||
|
td::store(dialog_id_, storer);
|
||||||
|
td::store(max_story_id_, storer);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ParserT>
|
||||||
|
void parse(ParserT &parser) {
|
||||||
|
td::parse(dialog_id_, parser);
|
||||||
|
td::parse(max_story_id_, parser);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
uint64 StoryManager::save_read_stories_on_server_log_event(DialogId dialog_id, StoryId max_story_id) {
|
||||||
|
ReadStoriesOnServerLogEvent log_event{dialog_id, max_story_id};
|
||||||
|
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadStoriesOnServer,
|
||||||
|
get_log_event_storer(log_event));
|
||||||
|
}
|
||||||
|
|
||||||
|
void StoryManager::read_stories_on_server(DialogId owner_dialog_id, StoryId story_id, uint64 log_event_id) {
|
||||||
|
if (log_event_id == 0 && G()->use_chat_info_database()) {
|
||||||
|
log_event_id = save_read_stories_on_server_log_event(owner_dialog_id, story_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
td_->create_handler<ReadStoriesQuery>(get_erase_log_event_promise(log_event_id))->send(owner_dialog_id, story_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StoryManager::have_story(StoryFullId story_full_id) const {
|
bool StoryManager::have_story(StoryFullId story_full_id) const {
|
||||||
@ -1756,9 +1784,22 @@ void StoryManager::on_binlog_events(vector<BinlogEvent> &&events) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td_->messages_manager_->have_dialog_info_force(dialog_id);
|
||||||
delete_story_on_server(dialog_id, log_event.story_id_, event.id_, Auto());
|
delete_story_on_server(dialog_id, log_event.story_id_, event.id_, Auto());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case LogEvent::HandlerType::ReadStoriesOnServer: {
|
||||||
|
ReadStoriesOnServerLogEvent log_event;
|
||||||
|
log_event_parse(log_event, event.get_data()).ensure();
|
||||||
|
|
||||||
|
auto dialog_id = log_event.dialog_id_;
|
||||||
|
if (!td_->messages_manager_->have_dialog_info_force(dialog_id)) {
|
||||||
|
binlog_erase(G()->td_db()->get_binlog(), event.id_);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
read_stories_on_server(dialog_id, log_event.max_story_id_, event.id_);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
LOG(FATAL) << "Unsupported log event type " << event.type_;
|
LOG(FATAL) << "Unsupported log event type " << event.type_;
|
||||||
}
|
}
|
||||||
|
@ -159,6 +159,7 @@ class StoryManager final : public Actor {
|
|||||||
class EditStoryQuery;
|
class EditStoryQuery;
|
||||||
|
|
||||||
class DeleteStoryOnServerLogEvent;
|
class DeleteStoryOnServerLogEvent;
|
||||||
|
class ReadStoriesOnServerLogEvent;
|
||||||
|
|
||||||
void tear_down() final;
|
void tear_down() final;
|
||||||
|
|
||||||
@ -239,7 +240,9 @@ class StoryManager final : public Actor {
|
|||||||
|
|
||||||
void on_increment_story_views(DialogId owner_dialog_id);
|
void on_increment_story_views(DialogId owner_dialog_id);
|
||||||
|
|
||||||
void read_stories_on_server(DialogId owner_dialog_id, StoryId story_id);
|
static uint64 save_read_stories_on_server_log_event(DialogId dialog_id, StoryId max_story_id);
|
||||||
|
|
||||||
|
void read_stories_on_server(DialogId owner_dialog_id, StoryId story_id, uint64 log_event_id);
|
||||||
|
|
||||||
std::shared_ptr<UploadMediaCallback> upload_media_callback_;
|
std::shared_ptr<UploadMediaCallback> upload_media_callback_;
|
||||||
|
|
||||||
|
@ -127,6 +127,7 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue<Binlog> &binlog_p
|
|||||||
events.to_messages_manager.push_back(event.clone());
|
events.to_messages_manager.push_back(event.clone());
|
||||||
break;
|
break;
|
||||||
case LogEvent::HandlerType::DeleteStoryOnServer:
|
case LogEvent::HandlerType::DeleteStoryOnServer:
|
||||||
|
case LogEvent::HandlerType::ReadStoriesOnServer:
|
||||||
events.to_story_manager.push_back(event.clone());
|
events.to_story_manager.push_back(event.clone());
|
||||||
break;
|
break;
|
||||||
case LogEvent::HandlerType::UpdateScopeNotificationSettingsOnServer:
|
case LogEvent::HandlerType::UpdateScopeNotificationSettingsOnServer:
|
||||||
|
@ -108,6 +108,7 @@ class LogEvent {
|
|||||||
EditMessagePushNotification = 0x201,
|
EditMessagePushNotification = 0x201,
|
||||||
SaveAppLog = 0x300,
|
SaveAppLog = 0x300,
|
||||||
DeleteStoryOnServer = 0x400,
|
DeleteStoryOnServer = 0x400,
|
||||||
|
ReadStoriesOnServer = 0x401,
|
||||||
ConfigPmcMagic = 0x1f18,
|
ConfigPmcMagic = 0x1f18,
|
||||||
BinlogPmcMagic = 0x4327
|
BinlogPmcMagic = 0x4327
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user