Add get_active_stories.
This commit is contained in:
parent
fe2e34d8bc
commit
4df51fdcdd
@ -86,8 +86,10 @@ class StoryDbImpl final : public StoryDbSyncInterface {
|
||||
|
||||
Status init() {
|
||||
TRY_RESULT_ASSIGN(add_story_stmt_, db_.get_statement("INSERT OR REPLACE INTO stories VALUES(?1, ?2, ?3, ?4, ?5)"));
|
||||
|
||||
TRY_RESULT_ASSIGN(delete_story_stmt_,
|
||||
db_.get_statement("DELETE FROM stories WHERE dialog_id = ?1 AND story_id = ?2"));
|
||||
|
||||
TRY_RESULT_ASSIGN(get_story_stmt_,
|
||||
db_.get_statement("SELECT data FROM stories WHERE dialog_id = ?1 AND story_id = ?2"));
|
||||
|
||||
@ -105,6 +107,9 @@ class StoryDbImpl final : public StoryDbSyncInterface {
|
||||
TRY_RESULT_ASSIGN(delete_active_stories_stmt_,
|
||||
db_.get_statement("DELETE FROM active_stories WHERE dialog_id = ?1"));
|
||||
|
||||
TRY_RESULT_ASSIGN(get_active_stories_stmt_,
|
||||
db_.get_statement("SELECT data FROM active_stories WHERE dialog_id = ?1"));
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -233,6 +238,19 @@ class StoryDbImpl final : public StoryDbSyncInterface {
|
||||
delete_active_stories_stmt_.step().ensure();
|
||||
}
|
||||
|
||||
Result<BufferSlice> get_active_stories(DialogId dialog_id) final {
|
||||
SCOPE_EXIT {
|
||||
get_active_stories_stmt_.reset();
|
||||
};
|
||||
|
||||
get_active_stories_stmt_.bind_int64(1, dialog_id.get()).ensure();
|
||||
get_active_stories_stmt_.step().ensure();
|
||||
if (!get_active_stories_stmt_.has_row()) {
|
||||
return Status::Error("Not found");
|
||||
}
|
||||
return BufferSlice(get_active_stories_stmt_.view_blob(0));
|
||||
}
|
||||
|
||||
Status begin_write_transaction() final {
|
||||
return db_.begin_write_transaction();
|
||||
}
|
||||
@ -251,6 +269,7 @@ class StoryDbImpl final : public StoryDbSyncInterface {
|
||||
|
||||
SqliteStatement add_active_stories_stmt_;
|
||||
SqliteStatement delete_active_stories_stmt_;
|
||||
SqliteStatement get_active_stories_stmt_;
|
||||
};
|
||||
|
||||
std::shared_ptr<StoryDbSyncSafeInterface> create_story_db_sync(
|
||||
@ -312,6 +331,10 @@ class StoryDbAsync final : public StoryDbAsyncInterface {
|
||||
send_closure_later(impl_, &Impl::delete_active_stories, dialog_id, std::move(promise));
|
||||
}
|
||||
|
||||
void get_active_stories(DialogId dialog_id, Promise<BufferSlice> promise) final {
|
||||
send_closure_later(impl_, &Impl::get_active_stories, dialog_id, std::move(promise));
|
||||
}
|
||||
|
||||
void close(Promise<Unit> promise) final {
|
||||
send_closure_later(impl_, &Impl::close, std::move(promise));
|
||||
}
|
||||
@ -378,6 +401,11 @@ class StoryDbAsync final : public StoryDbAsyncInterface {
|
||||
});
|
||||
}
|
||||
|
||||
void get_active_stories(DialogId dialog_id, Promise<BufferSlice> promise) {
|
||||
add_read_query();
|
||||
promise.set_result(sync_db_->get_active_stories(dialog_id));
|
||||
}
|
||||
|
||||
void close(Promise<Unit> promise) {
|
||||
do_flush();
|
||||
sync_db_safe_.reset();
|
||||
|
@ -55,6 +55,8 @@ class StoryDbSyncInterface {
|
||||
|
||||
virtual void delete_active_stories(DialogId dialog_id) = 0;
|
||||
|
||||
virtual Result<BufferSlice> get_active_stories(DialogId dialog_id) = 0;
|
||||
|
||||
virtual Status begin_write_transaction() = 0;
|
||||
virtual Status commit_transaction() = 0;
|
||||
};
|
||||
@ -93,6 +95,8 @@ class StoryDbAsyncInterface {
|
||||
|
||||
virtual void delete_active_stories(DialogId dialog_id, Promise<Unit> promise) = 0;
|
||||
|
||||
virtual void get_active_stories(DialogId dialog_id, Promise<BufferSlice> promise) = 0;
|
||||
|
||||
virtual void close(Promise<Unit> promise) = 0;
|
||||
virtual void force_flush() = 0;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user