Add StoryDb::get_active_story_list.
This commit is contained in:
parent
caaf0ce0dc
commit
99d38d9fc6
@ -107,6 +107,12 @@ class StoryDbImpl final : public StoryDbSyncInterface {
|
|||||||
TRY_RESULT_ASSIGN(delete_active_stories_stmt_,
|
TRY_RESULT_ASSIGN(delete_active_stories_stmt_,
|
||||||
db_.get_statement("DELETE FROM active_stories WHERE dialog_id = ?1"));
|
db_.get_statement("DELETE FROM active_stories WHERE dialog_id = ?1"));
|
||||||
|
|
||||||
|
TRY_RESULT_ASSIGN(
|
||||||
|
get_active_story_list_stmt_,
|
||||||
|
db_.get_statement("SELECT data, dialog_id, dialog_order FROM active_stories WHERE "
|
||||||
|
"story_list_id = ?1 AND (dialog_order < ?2 OR (dialog_order = ?2 AND dialog_id < ?3)) ORDER "
|
||||||
|
"BY dialog_order DESC, dialog_id DESC LIMIT ?4"));
|
||||||
|
|
||||||
TRY_RESULT_ASSIGN(get_active_stories_stmt_,
|
TRY_RESULT_ASSIGN(get_active_stories_stmt_,
|
||||||
db_.get_statement("SELECT data FROM active_stories WHERE dialog_id = ?1"));
|
db_.get_statement("SELECT data FROM active_stories WHERE dialog_id = ?1"));
|
||||||
|
|
||||||
@ -257,6 +263,33 @@ class StoryDbImpl final : public StoryDbSyncInterface {
|
|||||||
return BufferSlice(get_active_stories_stmt_.view_blob(0));
|
return BufferSlice(get_active_stories_stmt_.view_blob(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StoryDbGetActiveStoryListResult get_active_story_list(StoryListId story_list_id, int64 order, DialogId dialog_id,
|
||||||
|
int32 limit) final {
|
||||||
|
SCOPE_EXIT {
|
||||||
|
get_active_story_list_stmt_.reset();
|
||||||
|
};
|
||||||
|
|
||||||
|
get_active_story_list_stmt_.bind_int32(1, story_list_id == StoryListId::archive() ? 1 : 0).ensure();
|
||||||
|
get_active_story_list_stmt_.bind_int64(2, order).ensure();
|
||||||
|
get_active_story_list_stmt_.bind_int64(3, dialog_id.get()).ensure();
|
||||||
|
get_active_story_list_stmt_.bind_int32(4, limit).ensure();
|
||||||
|
|
||||||
|
StoryDbGetActiveStoryListResult result;
|
||||||
|
result.next_dialog_id_ = dialog_id;
|
||||||
|
result.next_order_ = order;
|
||||||
|
get_active_story_list_stmt_.step().ensure();
|
||||||
|
while (get_active_story_list_stmt_.has_row()) {
|
||||||
|
BufferSlice data(get_active_story_list_stmt_.view_blob(0));
|
||||||
|
result.next_dialog_id_ = DialogId(get_active_story_list_stmt_.view_int64(1));
|
||||||
|
result.next_order_ = get_active_story_list_stmt_.view_int64(2);
|
||||||
|
LOG(INFO) << "Load active stories in " << result.next_dialog_id_ << " with order " << result.next_order_;
|
||||||
|
result.active_stories_.emplace_back(result.next_dialog_id_, std::move(data));
|
||||||
|
get_active_story_list_stmt_.step().ensure();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void add_active_story_list_state(StoryListId story_list_id, BufferSlice data) final {
|
void add_active_story_list_state(StoryListId story_list_id, BufferSlice data) final {
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
add_active_story_list_state_stmt_.reset();
|
add_active_story_list_state_stmt_.reset();
|
||||||
@ -298,6 +331,7 @@ class StoryDbImpl final : public StoryDbSyncInterface {
|
|||||||
SqliteStatement add_active_stories_stmt_;
|
SqliteStatement add_active_stories_stmt_;
|
||||||
SqliteStatement delete_active_stories_stmt_;
|
SqliteStatement delete_active_stories_stmt_;
|
||||||
SqliteStatement get_active_stories_stmt_;
|
SqliteStatement get_active_stories_stmt_;
|
||||||
|
SqliteStatement get_active_story_list_stmt_;
|
||||||
|
|
||||||
SqliteStatement add_active_story_list_state_stmt_;
|
SqliteStatement add_active_story_list_state_stmt_;
|
||||||
SqliteStatement get_active_story_list_state_stmt_;
|
SqliteStatement get_active_story_list_state_stmt_;
|
||||||
@ -366,6 +400,11 @@ class StoryDbAsync final : public StoryDbAsyncInterface {
|
|||||||
send_closure_later(impl_, &Impl::get_active_stories, dialog_id, std::move(promise));
|
send_closure_later(impl_, &Impl::get_active_stories, dialog_id, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_active_story_list(StoryListId story_list_id, int64 order, DialogId dialog_id, int32 limit,
|
||||||
|
Promise<StoryDbGetActiveStoryListResult> promise) final {
|
||||||
|
send_closure_later(impl_, &Impl::get_active_story_list, story_list_id, order, dialog_id, limit, std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
void add_active_story_list_state(StoryListId story_list_id, BufferSlice data, Promise<Unit> promise) final {
|
void add_active_story_list_state(StoryListId story_list_id, BufferSlice data, Promise<Unit> promise) final {
|
||||||
send_closure_later(impl_, &Impl::add_active_story_list_state, story_list_id, std::move(data), std::move(promise));
|
send_closure_later(impl_, &Impl::add_active_story_list_state, story_list_id, std::move(data), std::move(promise));
|
||||||
}
|
}
|
||||||
@ -445,6 +484,12 @@ class StoryDbAsync final : public StoryDbAsyncInterface {
|
|||||||
promise.set_result(sync_db_->get_active_stories(dialog_id));
|
promise.set_result(sync_db_->get_active_stories(dialog_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_active_story_list(StoryListId story_list_id, int64 order, DialogId dialog_id, int32 limit,
|
||||||
|
Promise<StoryDbGetActiveStoryListResult> promise) {
|
||||||
|
add_read_query();
|
||||||
|
promise.set_value(sync_db_->get_active_story_list(story_list_id, order, dialog_id, limit));
|
||||||
|
}
|
||||||
|
|
||||||
void add_active_story_list_state(StoryListId story_list_id, BufferSlice data, Promise<Unit> promise) {
|
void add_active_story_list_state(StoryListId story_list_id, BufferSlice data, Promise<Unit> promise) {
|
||||||
add_write_query([this, story_list_id, data = std::move(data), promise = std::move(promise)](Unit) mutable {
|
add_write_query([this, story_list_id, data = std::move(data), promise = std::move(promise)](Unit) mutable {
|
||||||
sync_db_->add_active_story_list_state(story_list_id, std::move(data));
|
sync_db_->add_active_story_list_state(story_list_id, std::move(data));
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
@ -31,6 +32,12 @@ struct StoryDbStory {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct StoryDbGetActiveStoryListResult {
|
||||||
|
vector<std::pair<DialogId, BufferSlice>> active_stories_;
|
||||||
|
int64 next_order_ = 0;
|
||||||
|
DialogId next_dialog_id_;
|
||||||
|
};
|
||||||
|
|
||||||
class StoryDbSyncInterface {
|
class StoryDbSyncInterface {
|
||||||
public:
|
public:
|
||||||
StoryDbSyncInterface() = default;
|
StoryDbSyncInterface() = default;
|
||||||
@ -57,6 +64,9 @@ class StoryDbSyncInterface {
|
|||||||
|
|
||||||
virtual Result<BufferSlice> get_active_stories(DialogId dialog_id) = 0;
|
virtual Result<BufferSlice> get_active_stories(DialogId dialog_id) = 0;
|
||||||
|
|
||||||
|
virtual StoryDbGetActiveStoryListResult get_active_story_list(StoryListId story_list_id, int64 order,
|
||||||
|
DialogId dialog_id, int32 limit) = 0;
|
||||||
|
|
||||||
virtual void add_active_story_list_state(StoryListId story_list_id, BufferSlice data) = 0;
|
virtual void add_active_story_list_state(StoryListId story_list_id, BufferSlice data) = 0;
|
||||||
|
|
||||||
virtual Result<BufferSlice> get_active_story_list_state(StoryListId story_list_id) = 0;
|
virtual Result<BufferSlice> get_active_story_list_state(StoryListId story_list_id) = 0;
|
||||||
@ -101,6 +111,9 @@ class StoryDbAsyncInterface {
|
|||||||
|
|
||||||
virtual void get_active_stories(DialogId dialog_id, Promise<BufferSlice> promise) = 0;
|
virtual void get_active_stories(DialogId dialog_id, Promise<BufferSlice> promise) = 0;
|
||||||
|
|
||||||
|
virtual void get_active_story_list(StoryListId story_list_id, int64 order, DialogId dialog_id, int32 limit,
|
||||||
|
Promise<StoryDbGetActiveStoryListResult> promise) = 0;
|
||||||
|
|
||||||
virtual void add_active_story_list_state(StoryListId story_list_id, BufferSlice data, Promise<Unit> promise) = 0;
|
virtual void add_active_story_list_state(StoryListId story_list_id, BufferSlice data, Promise<Unit> promise) = 0;
|
||||||
|
|
||||||
virtual void get_active_story_list_state(StoryListId story_list_id, Promise<BufferSlice> promise) = 0;
|
virtual void get_active_story_list_state(StoryListId story_list_id, Promise<BufferSlice> promise) = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user