Use struct MessagesDbDialogMessage to return messages in a known chat from database.
This commit is contained in:
parent
813e32a265
commit
ad3b9c822d
@ -436,7 +436,7 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<BufferSlice> get_message(FullMessageId full_message_id) final {
|
Result<MessagesDbDialogMessage> get_message(FullMessageId full_message_id) final {
|
||||||
auto dialog_id = full_message_id.get_dialog_id();
|
auto dialog_id = full_message_id.get_dialog_id();
|
||||||
auto message_id = full_message_id.get_message_id();
|
auto message_id = full_message_id.get_message_id();
|
||||||
CHECK(dialog_id.is_valid());
|
CHECK(dialog_id.is_valid());
|
||||||
@ -459,7 +459,7 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
if (!stmt.has_row()) {
|
if (!stmt.has_row()) {
|
||||||
return Status::Error("Not found");
|
return Status::Error("Not found");
|
||||||
}
|
}
|
||||||
return BufferSlice(stmt.view_blob(0));
|
return MessagesDbDialogMessage{BufferSlice(stmt.view_blob(0))};
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<MessagesDbMessage> get_message_by_unique_message_id(ServerMessageId unique_message_id) final {
|
Result<MessagesDbMessage> get_message_by_unique_message_id(ServerMessageId unique_message_id) final {
|
||||||
@ -478,7 +478,7 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
return MessagesDbMessage{dialog_id, BufferSlice(get_message_by_unique_message_id_stmt_.view_blob(1))};
|
return MessagesDbMessage{dialog_id, BufferSlice(get_message_by_unique_message_id_stmt_.view_blob(1))};
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<BufferSlice> get_message_by_random_id(DialogId dialog_id, int64 random_id) final {
|
Result<MessagesDbDialogMessage> get_message_by_random_id(DialogId dialog_id, int64 random_id) final {
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
get_message_by_random_id_stmt_.reset();
|
get_message_by_random_id_stmt_.reset();
|
||||||
};
|
};
|
||||||
@ -488,10 +488,10 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
if (!get_message_by_random_id_stmt_.has_row()) {
|
if (!get_message_by_random_id_stmt_.has_row()) {
|
||||||
return Status::Error("Not found");
|
return Status::Error("Not found");
|
||||||
}
|
}
|
||||||
return BufferSlice(get_message_by_random_id_stmt_.view_blob(0));
|
return MessagesDbDialogMessage{BufferSlice(get_message_by_random_id_stmt_.view_blob(0))};
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<BufferSlice> get_dialog_message_by_date(DialogId dialog_id, MessageId first_message_id,
|
Result<MessagesDbDialogMessage> get_dialog_message_by_date(DialogId dialog_id, MessageId first_message_id,
|
||||||
MessageId last_message_id, int32 date) final {
|
MessageId last_message_id, int32 date) final {
|
||||||
int64 left_message_id = first_message_id.get();
|
int64 left_message_id = first_message_id.get();
|
||||||
int64 right_message_id = last_message_id.get();
|
int64 right_message_id = last_message_id.get();
|
||||||
@ -554,14 +554,14 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
return Status::Error("Not found");
|
return Status::Error("Not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<std::pair<std::vector<MessagesDbMessage>, int32>> get_expiring_messages(int32 expires_from, int32 expires_till,
|
Result<std::pair<vector<MessagesDbMessage>, int32>> get_expiring_messages(int32 expires_from, int32 expires_till,
|
||||||
int32 limit) final {
|
int32 limit) final {
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
get_expiring_messages_stmt_.reset();
|
get_expiring_messages_stmt_.reset();
|
||||||
get_expiring_messages_helper_stmt_.reset();
|
get_expiring_messages_helper_stmt_.reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<MessagesDbMessage> messages;
|
vector<MessagesDbMessage> messages;
|
||||||
// load messages
|
// load messages
|
||||||
if (expires_from <= expires_till) {
|
if (expires_from <= expires_till) {
|
||||||
get_expiring_messages_stmt_.bind_int32(1, expires_from).ensure();
|
get_expiring_messages_stmt_.bind_int32(1, expires_from).ensure();
|
||||||
@ -589,7 +589,7 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
return std::make_pair(std::move(messages), next_expires_till);
|
return std::make_pair(std::move(messages), next_expires_till);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<std::vector<BufferSlice>> get_messages(MessagesDbMessagesQuery query) final {
|
Result<vector<MessagesDbDialogMessage>> get_messages(MessagesDbMessagesQuery query) final {
|
||||||
if (query.index_mask != 0) {
|
if (query.index_mask != 0) {
|
||||||
return get_messages_from_index(query.dialog_id, query.from_message_id, query.index_mask, query.offset,
|
return get_messages_from_index(query.dialog_id, query.from_message_id, query.index_mask, query.offset,
|
||||||
query.limit);
|
query.limit);
|
||||||
@ -597,11 +597,12 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
return get_messages_impl(get_messages_stmt_, query.dialog_id, query.from_message_id, query.offset, query.limit);
|
return get_messages_impl(get_messages_stmt_, query.dialog_id, query.from_message_id, query.offset, query.limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<std::vector<BufferSlice>> get_scheduled_messages(DialogId dialog_id, int32 limit) final {
|
Result<vector<MessagesDbDialogMessage>> get_scheduled_messages(DialogId dialog_id, int32 limit) final {
|
||||||
return get_messages_inner(get_scheduled_messages_stmt_, dialog_id, std::numeric_limits<int64>::max(), limit);
|
return get_messages_inner(get_scheduled_messages_stmt_, dialog_id, std::numeric_limits<int64>::max(), limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<vector<BufferSlice>> get_messages_from_notification_id(DialogId dialog_id, NotificationId from_notification_id,
|
Result<vector<MessagesDbDialogMessage>> get_messages_from_notification_id(DialogId dialog_id,
|
||||||
|
NotificationId from_notification_id,
|
||||||
int32 limit) final {
|
int32 limit) final {
|
||||||
auto &stmt = get_messages_from_notification_id_stmt_;
|
auto &stmt = get_messages_from_notification_id_stmt_;
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
@ -611,11 +612,11 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
stmt.bind_int32(2, from_notification_id.get()).ensure();
|
stmt.bind_int32(2, from_notification_id.get()).ensure();
|
||||||
stmt.bind_int32(3, limit).ensure();
|
stmt.bind_int32(3, limit).ensure();
|
||||||
|
|
||||||
std::vector<BufferSlice> result;
|
vector<MessagesDbDialogMessage> result;
|
||||||
stmt.step().ensure();
|
stmt.step().ensure();
|
||||||
while (stmt.has_row()) {
|
while (stmt.has_row()) {
|
||||||
auto data_slice = stmt.view_blob(0);
|
auto data_slice = stmt.view_blob(0);
|
||||||
result.emplace_back(data_slice);
|
result.push_back(MessagesDbDialogMessage{BufferSlice(data_slice)});
|
||||||
auto message_id = stmt.view_int64(1);
|
auto message_id = stmt.view_int64(1);
|
||||||
LOG(INFO) << "Load " << MessageId(message_id) << " in " << dialog_id << " from database";
|
LOG(INFO) << "Load " << MessageId(message_id) << " in " << dialog_id << " from database";
|
||||||
stmt.step().ensure();
|
stmt.step().ensure();
|
||||||
@ -724,7 +725,7 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
return std::move(result);
|
return std::move(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<std::vector<BufferSlice>> get_messages_from_index(DialogId dialog_id, MessageId from_message_id,
|
Result<vector<MessagesDbDialogMessage>> get_messages_from_index(DialogId dialog_id, MessageId from_message_id,
|
||||||
int32 index_mask, int32 offset, int32 limit) {
|
int32 index_mask, int32 offset, int32 limit) {
|
||||||
CHECK(index_mask != 0);
|
CHECK(index_mask != 0);
|
||||||
LOG_CHECK(index_mask < (1 << MESSAGES_DB_INDEX_COUNT)) << tag("index_mask", index_mask);
|
LOG_CHECK(index_mask < (1 << MESSAGES_DB_INDEX_COUNT)) << tag("index_mask", index_mask);
|
||||||
@ -825,7 +826,7 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
SqliteStatement delete_scheduled_message_stmt_;
|
SqliteStatement delete_scheduled_message_stmt_;
|
||||||
SqliteStatement delete_scheduled_server_message_stmt_;
|
SqliteStatement delete_scheduled_server_message_stmt_;
|
||||||
|
|
||||||
Result<std::vector<BufferSlice>> get_messages_impl(GetMessagesStmt &stmt, DialogId dialog_id,
|
Result<vector<MessagesDbDialogMessage>> get_messages_impl(GetMessagesStmt &stmt, DialogId dialog_id,
|
||||||
MessageId from_message_id, int32 offset, int32 limit) {
|
MessageId from_message_id, int32 offset, int32 limit) {
|
||||||
LOG_CHECK(dialog_id.is_valid()) << dialog_id;
|
LOG_CHECK(dialog_id.is_valid()) << dialog_id;
|
||||||
CHECK(from_message_id.is_valid());
|
CHECK(from_message_id.is_valid());
|
||||||
@ -845,8 +846,8 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
auto right_message_id = message_id - 1;
|
auto right_message_id = message_id - 1;
|
||||||
auto right_cnt = -offset;
|
auto right_cnt = -offset;
|
||||||
|
|
||||||
std::vector<BufferSlice> left;
|
vector<MessagesDbDialogMessage> left;
|
||||||
std::vector<BufferSlice> right;
|
vector<MessagesDbDialogMessage> right;
|
||||||
|
|
||||||
if (left_cnt != 0) {
|
if (left_cnt != 0) {
|
||||||
if (right_cnt == 1 && false) {
|
if (right_cnt == 1 && false) {
|
||||||
@ -877,8 +878,8 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
return std::move(right);
|
return std::move(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<std::vector<BufferSlice>> get_messages_inner(SqliteStatement &stmt, DialogId dialog_id, int64 from_message_id,
|
Result<vector<MessagesDbDialogMessage>> get_messages_inner(SqliteStatement &stmt, DialogId dialog_id,
|
||||||
int32 limit) {
|
int64 from_message_id, int32 limit) {
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
stmt.reset();
|
stmt.reset();
|
||||||
};
|
};
|
||||||
@ -888,11 +889,11 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
|
|
||||||
LOG(INFO) << "Begin to load " << limit << " messages in " << dialog_id << " from " << MessageId(from_message_id)
|
LOG(INFO) << "Begin to load " << limit << " messages in " << dialog_id << " from " << MessageId(from_message_id)
|
||||||
<< " from database";
|
<< " from database";
|
||||||
std::vector<BufferSlice> result;
|
vector<MessagesDbDialogMessage> result;
|
||||||
stmt.step().ensure();
|
stmt.step().ensure();
|
||||||
while (stmt.has_row()) {
|
while (stmt.has_row()) {
|
||||||
auto data_slice = stmt.view_blob(0);
|
auto data_slice = stmt.view_blob(0);
|
||||||
result.emplace_back(data_slice);
|
result.push_back(MessagesDbDialogMessage{BufferSlice(data_slice)});
|
||||||
auto message_id = stmt.view_int64(1);
|
auto message_id = stmt.view_int64(1);
|
||||||
LOG(INFO) << "Loaded " << MessageId(message_id) << " in " << dialog_id << " from database";
|
LOG(INFO) << "Loaded " << MessageId(message_id) << " in " << dialog_id << " from database";
|
||||||
stmt.step().ensure();
|
stmt.step().ensure();
|
||||||
@ -900,8 +901,8 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
|
|||||||
return std::move(result);
|
return std::move(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::tuple<MessageId, int32> get_message_info(const BufferSlice &message) {
|
static std::tuple<MessageId, int32> get_message_info(const MessagesDbDialogMessage &message) {
|
||||||
LogEventParser message_date_parser(message.as_slice());
|
LogEventParser message_date_parser(message.data.as_slice());
|
||||||
int32 flags;
|
int32 flags;
|
||||||
td::parse(flags, message_date_parser);
|
td::parse(flags, message_date_parser);
|
||||||
int32 flags2 = 0;
|
int32 flags2 = 0;
|
||||||
@ -969,29 +970,29 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface {
|
|||||||
send_closure_later(impl_, &Impl::delete_dialog_messages_from_user, dialog_id, sender_user_id, std::move(promise));
|
send_closure_later(impl_, &Impl::delete_dialog_messages_from_user, dialog_id, sender_user_id, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_message(FullMessageId full_message_id, Promise<BufferSlice> promise) final {
|
void get_message(FullMessageId full_message_id, Promise<MessagesDbDialogMessage> promise) final {
|
||||||
send_closure_later(impl_, &Impl::get_message, full_message_id, std::move(promise));
|
send_closure_later(impl_, &Impl::get_message, full_message_id, std::move(promise));
|
||||||
}
|
}
|
||||||
void get_message_by_unique_message_id(ServerMessageId unique_message_id, Promise<MessagesDbMessage> promise) final {
|
void get_message_by_unique_message_id(ServerMessageId unique_message_id, Promise<MessagesDbMessage> promise) final {
|
||||||
send_closure_later(impl_, &Impl::get_message_by_unique_message_id, unique_message_id, std::move(promise));
|
send_closure_later(impl_, &Impl::get_message_by_unique_message_id, unique_message_id, std::move(promise));
|
||||||
}
|
}
|
||||||
void get_message_by_random_id(DialogId dialog_id, int64 random_id, Promise<BufferSlice> promise) final {
|
void get_message_by_random_id(DialogId dialog_id, int64 random_id, Promise<MessagesDbDialogMessage> promise) final {
|
||||||
send_closure_later(impl_, &Impl::get_message_by_random_id, dialog_id, random_id, std::move(promise));
|
send_closure_later(impl_, &Impl::get_message_by_random_id, dialog_id, random_id, std::move(promise));
|
||||||
}
|
}
|
||||||
void get_dialog_message_by_date(DialogId dialog_id, MessageId first_message_id, MessageId last_message_id, int32 date,
|
void get_dialog_message_by_date(DialogId dialog_id, MessageId first_message_id, MessageId last_message_id, int32 date,
|
||||||
Promise<BufferSlice> promise) final {
|
Promise<MessagesDbDialogMessage> promise) final {
|
||||||
send_closure_later(impl_, &Impl::get_dialog_message_by_date, dialog_id, first_message_id, last_message_id, date,
|
send_closure_later(impl_, &Impl::get_dialog_message_by_date, dialog_id, first_message_id, last_message_id, date,
|
||||||
std::move(promise));
|
std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_messages(MessagesDbMessagesQuery query, Promise<std::vector<BufferSlice>> promise) final {
|
void get_messages(MessagesDbMessagesQuery query, Promise<vector<MessagesDbDialogMessage>> promise) final {
|
||||||
send_closure_later(impl_, &Impl::get_messages, std::move(query), std::move(promise));
|
send_closure_later(impl_, &Impl::get_messages, std::move(query), std::move(promise));
|
||||||
}
|
}
|
||||||
void get_scheduled_messages(DialogId dialog_id, int32 limit, Promise<std::vector<BufferSlice>> promise) final {
|
void get_scheduled_messages(DialogId dialog_id, int32 limit, Promise<vector<MessagesDbDialogMessage>> promise) final {
|
||||||
send_closure_later(impl_, &Impl::get_scheduled_messages, dialog_id, limit, std::move(promise));
|
send_closure_later(impl_, &Impl::get_scheduled_messages, dialog_id, limit, std::move(promise));
|
||||||
}
|
}
|
||||||
void get_messages_from_notification_id(DialogId dialog_id, NotificationId from_notification_id, int32 limit,
|
void get_messages_from_notification_id(DialogId dialog_id, NotificationId from_notification_id, int32 limit,
|
||||||
Promise<vector<BufferSlice>> promise) final {
|
Promise<vector<MessagesDbDialogMessage>> promise) final {
|
||||||
send_closure_later(impl_, &Impl::get_messages_from_notification_id, dialog_id, from_notification_id, limit,
|
send_closure_later(impl_, &Impl::get_messages_from_notification_id, dialog_id, from_notification_id, limit,
|
||||||
std::move(promise));
|
std::move(promise));
|
||||||
}
|
}
|
||||||
@ -1002,7 +1003,7 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface {
|
|||||||
send_closure_later(impl_, &Impl::get_messages_fts, std::move(query), std::move(promise));
|
send_closure_later(impl_, &Impl::get_messages_fts, std::move(query), std::move(promise));
|
||||||
}
|
}
|
||||||
void get_expiring_messages(int32 expires_from, int32 expires_till, int32 limit,
|
void get_expiring_messages(int32 expires_from, int32 expires_till, int32 limit,
|
||||||
Promise<std::pair<std::vector<MessagesDbMessage>, int32>> promise) final {
|
Promise<std::pair<vector<MessagesDbMessage>, int32>> promise) final {
|
||||||
send_closure_later(impl_, &Impl::get_expiring_messages, expires_from, expires_till, limit, std::move(promise));
|
send_closure_later(impl_, &Impl::get_expiring_messages, expires_from, expires_till, limit, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1057,7 +1058,7 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface {
|
|||||||
promise.set_result(sync_db_->delete_dialog_messages_from_user(dialog_id, sender_user_id));
|
promise.set_result(sync_db_->delete_dialog_messages_from_user(dialog_id, sender_user_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_message(FullMessageId full_message_id, Promise<BufferSlice> promise) {
|
void get_message(FullMessageId full_message_id, Promise<MessagesDbDialogMessage> promise) {
|
||||||
add_read_query();
|
add_read_query();
|
||||||
promise.set_result(sync_db_->get_message(full_message_id));
|
promise.set_result(sync_db_->get_message(full_message_id));
|
||||||
}
|
}
|
||||||
@ -1065,26 +1066,26 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface {
|
|||||||
add_read_query();
|
add_read_query();
|
||||||
promise.set_result(sync_db_->get_message_by_unique_message_id(unique_message_id));
|
promise.set_result(sync_db_->get_message_by_unique_message_id(unique_message_id));
|
||||||
}
|
}
|
||||||
void get_message_by_random_id(DialogId dialog_id, int64 random_id, Promise<BufferSlice> promise) {
|
void get_message_by_random_id(DialogId dialog_id, int64 random_id, Promise<MessagesDbDialogMessage> promise) {
|
||||||
add_read_query();
|
add_read_query();
|
||||||
promise.set_result(sync_db_->get_message_by_random_id(dialog_id, random_id));
|
promise.set_result(sync_db_->get_message_by_random_id(dialog_id, random_id));
|
||||||
}
|
}
|
||||||
void get_dialog_message_by_date(DialogId dialog_id, MessageId first_message_id, MessageId last_message_id,
|
void get_dialog_message_by_date(DialogId dialog_id, MessageId first_message_id, MessageId last_message_id,
|
||||||
int32 date, Promise<BufferSlice> promise) {
|
int32 date, Promise<MessagesDbDialogMessage> promise) {
|
||||||
add_read_query();
|
add_read_query();
|
||||||
promise.set_result(sync_db_->get_dialog_message_by_date(dialog_id, first_message_id, last_message_id, date));
|
promise.set_result(sync_db_->get_dialog_message_by_date(dialog_id, first_message_id, last_message_id, date));
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_messages(MessagesDbMessagesQuery query, Promise<std::vector<BufferSlice>> promise) {
|
void get_messages(MessagesDbMessagesQuery query, Promise<vector<MessagesDbDialogMessage>> promise) {
|
||||||
add_read_query();
|
add_read_query();
|
||||||
promise.set_result(sync_db_->get_messages(std::move(query)));
|
promise.set_result(sync_db_->get_messages(std::move(query)));
|
||||||
}
|
}
|
||||||
void get_scheduled_messages(DialogId dialog_id, int32 limit, Promise<std::vector<BufferSlice>> promise) {
|
void get_scheduled_messages(DialogId dialog_id, int32 limit, Promise<vector<MessagesDbDialogMessage>> promise) {
|
||||||
add_read_query();
|
add_read_query();
|
||||||
promise.set_result(sync_db_->get_scheduled_messages(dialog_id, limit));
|
promise.set_result(sync_db_->get_scheduled_messages(dialog_id, limit));
|
||||||
}
|
}
|
||||||
void get_messages_from_notification_id(DialogId dialog_id, NotificationId from_notification_id, int32 limit,
|
void get_messages_from_notification_id(DialogId dialog_id, NotificationId from_notification_id, int32 limit,
|
||||||
Promise<vector<BufferSlice>> promise) {
|
Promise<vector<MessagesDbDialogMessage>> promise) {
|
||||||
add_read_query();
|
add_read_query();
|
||||||
promise.set_result(sync_db_->get_messages_from_notification_id(dialog_id, from_notification_id, limit));
|
promise.set_result(sync_db_->get_messages_from_notification_id(dialog_id, from_notification_id, limit));
|
||||||
}
|
}
|
||||||
@ -1097,7 +1098,7 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface {
|
|||||||
promise.set_result(sync_db_->get_messages_fts(std::move(query)));
|
promise.set_result(sync_db_->get_messages_fts(std::move(query)));
|
||||||
}
|
}
|
||||||
void get_expiring_messages(int32 expires_from, int32 expires_till, int32 limit,
|
void get_expiring_messages(int32 expires_from, int32 expires_till, int32 limit,
|
||||||
Promise<std::pair<std::vector<MessagesDbMessage>, int32>> promise) {
|
Promise<std::pair<vector<MessagesDbMessage>, int32>> promise) {
|
||||||
add_read_query();
|
add_read_query();
|
||||||
promise.set_result(sync_db_->get_expiring_messages(expires_from, expires_till, limit));
|
promise.set_result(sync_db_->get_expiring_messages(expires_from, expires_till, limit));
|
||||||
}
|
}
|
||||||
@ -1123,8 +1124,8 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface {
|
|||||||
static constexpr double MAX_PENDING_QUERIES_DELAY{0.01};
|
static constexpr double MAX_PENDING_QUERIES_DELAY{0.01};
|
||||||
|
|
||||||
//NB: order is important, destructor of pending_writes_ will change pending_write_results_
|
//NB: order is important, destructor of pending_writes_ will change pending_write_results_
|
||||||
std::vector<std::pair<Promise<>, Status>> pending_write_results_;
|
vector<std::pair<Promise<>, Status>> pending_write_results_;
|
||||||
std::vector<Promise<>> pending_writes_;
|
vector<Promise<>> pending_writes_;
|
||||||
double wakeup_at_ = 0;
|
double wakeup_at_ = 0;
|
||||||
template <class F>
|
template <class F>
|
||||||
void add_write_query(F &&f) {
|
void add_write_query(F &&f) {
|
||||||
|
@ -34,6 +34,10 @@ struct MessagesDbMessagesQuery {
|
|||||||
int32 limit{100};
|
int32 limit{100};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct MessagesDbDialogMessage {
|
||||||
|
BufferSlice data;
|
||||||
|
};
|
||||||
|
|
||||||
struct MessagesDbMessage {
|
struct MessagesDbMessage {
|
||||||
DialogId dialog_id;
|
DialogId dialog_id;
|
||||||
BufferSlice data;
|
BufferSlice data;
|
||||||
@ -47,7 +51,7 @@ struct MessagesDbFtsQuery {
|
|||||||
int32 limit{100};
|
int32 limit{100};
|
||||||
};
|
};
|
||||||
struct MessagesDbFtsResult {
|
struct MessagesDbFtsResult {
|
||||||
std::vector<MessagesDbMessage> messages;
|
vector<MessagesDbMessage> messages;
|
||||||
int64 next_search_id{1};
|
int64 next_search_id{1};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57,7 +61,7 @@ struct MessagesDbCallsQuery {
|
|||||||
int32 limit{100};
|
int32 limit{100};
|
||||||
};
|
};
|
||||||
struct MessagesDbCallsResult {
|
struct MessagesDbCallsResult {
|
||||||
std::vector<MessagesDbMessage> messages;
|
vector<MessagesDbMessage> messages;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MessagesDbSyncInterface {
|
class MessagesDbSyncInterface {
|
||||||
@ -76,19 +80,19 @@ class MessagesDbSyncInterface {
|
|||||||
virtual Status delete_all_dialog_messages(DialogId dialog_id, MessageId from_message_id) = 0;
|
virtual Status delete_all_dialog_messages(DialogId dialog_id, MessageId from_message_id) = 0;
|
||||||
virtual Status delete_dialog_messages_from_user(DialogId dialog_id, UserId sender_user_id) = 0;
|
virtual Status delete_dialog_messages_from_user(DialogId dialog_id, UserId sender_user_id) = 0;
|
||||||
|
|
||||||
virtual Result<BufferSlice> get_message(FullMessageId full_message_id) = 0;
|
virtual Result<MessagesDbDialogMessage> get_message(FullMessageId full_message_id) = 0;
|
||||||
virtual Result<MessagesDbMessage> get_message_by_unique_message_id(ServerMessageId unique_message_id) = 0;
|
virtual Result<MessagesDbMessage> get_message_by_unique_message_id(ServerMessageId unique_message_id) = 0;
|
||||||
virtual Result<BufferSlice> get_message_by_random_id(DialogId dialog_id, int64 random_id) = 0;
|
virtual Result<MessagesDbDialogMessage> get_message_by_random_id(DialogId dialog_id, int64 random_id) = 0;
|
||||||
virtual Result<BufferSlice> get_dialog_message_by_date(DialogId dialog_id, MessageId first_message_id,
|
virtual Result<MessagesDbDialogMessage> get_dialog_message_by_date(DialogId dialog_id, MessageId first_message_id,
|
||||||
MessageId last_message_id, int32 date) = 0;
|
MessageId last_message_id, int32 date) = 0;
|
||||||
|
|
||||||
virtual Result<std::vector<BufferSlice>> get_messages(MessagesDbMessagesQuery query) = 0;
|
virtual Result<vector<MessagesDbDialogMessage>> get_messages(MessagesDbMessagesQuery query) = 0;
|
||||||
virtual Result<std::vector<BufferSlice>> get_scheduled_messages(DialogId dialog_id, int32 limit) = 0;
|
virtual Result<vector<MessagesDbDialogMessage>> get_scheduled_messages(DialogId dialog_id, int32 limit) = 0;
|
||||||
virtual Result<vector<BufferSlice>> get_messages_from_notification_id(DialogId dialog_id,
|
virtual Result<vector<MessagesDbDialogMessage>> get_messages_from_notification_id(DialogId dialog_id,
|
||||||
NotificationId from_notification_id,
|
NotificationId from_notification_id,
|
||||||
int32 limit) = 0;
|
int32 limit) = 0;
|
||||||
|
|
||||||
virtual Result<std::pair<std::vector<MessagesDbMessage>, int32>> get_expiring_messages(int32 expires_from,
|
virtual Result<std::pair<vector<MessagesDbMessage>, int32>> get_expiring_messages(int32 expires_from,
|
||||||
int32 expires_till,
|
int32 expires_till,
|
||||||
int32 limit) = 0;
|
int32 limit) = 0;
|
||||||
virtual Result<MessagesDbCallsResult> get_calls(MessagesDbCallsQuery query) = 0;
|
virtual Result<MessagesDbCallsResult> get_calls(MessagesDbCallsQuery query) = 0;
|
||||||
@ -125,23 +129,25 @@ class MessagesDbAsyncInterface {
|
|||||||
virtual void delete_all_dialog_messages(DialogId dialog_id, MessageId from_message_id, Promise<> promise) = 0;
|
virtual void delete_all_dialog_messages(DialogId dialog_id, MessageId from_message_id, Promise<> promise) = 0;
|
||||||
virtual void delete_dialog_messages_from_user(DialogId dialog_id, UserId sender_user_id, Promise<> promise) = 0;
|
virtual void delete_dialog_messages_from_user(DialogId dialog_id, UserId sender_user_id, Promise<> promise) = 0;
|
||||||
|
|
||||||
virtual void get_message(FullMessageId full_message_id, Promise<BufferSlice> promise) = 0;
|
virtual void get_message(FullMessageId full_message_id, Promise<MessagesDbDialogMessage> promise) = 0;
|
||||||
virtual void get_message_by_unique_message_id(ServerMessageId unique_message_id,
|
virtual void get_message_by_unique_message_id(ServerMessageId unique_message_id,
|
||||||
Promise<MessagesDbMessage> promise) = 0;
|
Promise<MessagesDbMessage> promise) = 0;
|
||||||
virtual void get_message_by_random_id(DialogId dialog_id, int64 random_id, Promise<BufferSlice> promise) = 0;
|
virtual void get_message_by_random_id(DialogId dialog_id, int64 random_id,
|
||||||
|
Promise<MessagesDbDialogMessage> promise) = 0;
|
||||||
virtual void get_dialog_message_by_date(DialogId dialog_id, MessageId first_message_id, MessageId last_message_id,
|
virtual void get_dialog_message_by_date(DialogId dialog_id, MessageId first_message_id, MessageId last_message_id,
|
||||||
int32 date, Promise<BufferSlice> promise) = 0;
|
int32 date, Promise<MessagesDbDialogMessage> promise) = 0;
|
||||||
|
|
||||||
virtual void get_messages(MessagesDbMessagesQuery query, Promise<std::vector<BufferSlice>> promise) = 0;
|
virtual void get_messages(MessagesDbMessagesQuery query, Promise<vector<MessagesDbDialogMessage>> promise) = 0;
|
||||||
virtual void get_scheduled_messages(DialogId dialog_id, int32 limit, Promise<std::vector<BufferSlice>> promise) = 0;
|
virtual void get_scheduled_messages(DialogId dialog_id, int32 limit,
|
||||||
|
Promise<vector<MessagesDbDialogMessage>> promise) = 0;
|
||||||
virtual void get_messages_from_notification_id(DialogId dialog_id, NotificationId from_notification_id, int32 limit,
|
virtual void get_messages_from_notification_id(DialogId dialog_id, NotificationId from_notification_id, int32 limit,
|
||||||
Promise<vector<BufferSlice>> promise) = 0;
|
Promise<vector<MessagesDbDialogMessage>> promise) = 0;
|
||||||
|
|
||||||
virtual void get_calls(MessagesDbCallsQuery, Promise<MessagesDbCallsResult> promise) = 0;
|
virtual void get_calls(MessagesDbCallsQuery, Promise<MessagesDbCallsResult> promise) = 0;
|
||||||
virtual void get_messages_fts(MessagesDbFtsQuery query, Promise<MessagesDbFtsResult> promise) = 0;
|
virtual void get_messages_fts(MessagesDbFtsQuery query, Promise<MessagesDbFtsResult> promise) = 0;
|
||||||
|
|
||||||
virtual void get_expiring_messages(int32 expires_from, int32 expires_till, int32 limit,
|
virtual void get_expiring_messages(int32 expires_from, int32 expires_till, int32 limit,
|
||||||
Promise<std::pair<std::vector<MessagesDbMessage>, int32>> promise) = 0;
|
Promise<std::pair<vector<MessagesDbMessage>, int32>> promise) = 0;
|
||||||
|
|
||||||
virtual void close(Promise<> promise) = 0;
|
virtual void close(Promise<> promise) = 0;
|
||||||
virtual void force_flush() = 0;
|
virtual void force_flush() = 0;
|
||||||
|
@ -19830,7 +19830,7 @@ void MessagesManager::open_dialog(Dialog *d) {
|
|||||||
d->is_has_scheduled_database_messages_checked = true;
|
d->is_has_scheduled_database_messages_checked = true;
|
||||||
G()->td_db()->get_messages_db_async()->get_scheduled_messages(
|
G()->td_db()->get_messages_db_async()->get_scheduled_messages(
|
||||||
dialog_id, 1,
|
dialog_id, 1,
|
||||||
PromiseCreator::lambda([dialog_id, actor_id = actor_id(this)](std::vector<BufferSlice> messages) {
|
PromiseCreator::lambda([dialog_id, actor_id = actor_id(this)](vector<MessagesDbDialogMessage> messages) {
|
||||||
if (messages.empty()) {
|
if (messages.empty()) {
|
||||||
send_closure(actor_id, &MessagesManager::set_dialog_has_scheduled_database_messages, dialog_id, false);
|
send_closure(actor_id, &MessagesManager::set_dialog_has_scheduled_database_messages, dialog_id, false);
|
||||||
}
|
}
|
||||||
@ -21187,7 +21187,7 @@ std::pair<int32, vector<MessageId>> MessagesManager::search_dialog_messages(
|
|||||||
<< " and with limit " << limit;
|
<< " and with limit " << limit;
|
||||||
auto new_promise = PromiseCreator::lambda(
|
auto new_promise = PromiseCreator::lambda(
|
||||||
[random_id, dialog_id, fixed_from_message_id, first_db_message_id, filter, offset, limit,
|
[random_id, dialog_id, fixed_from_message_id, first_db_message_id, filter, offset, limit,
|
||||||
promise = std::move(promise)](Result<std::vector<BufferSlice>> r_messages) mutable {
|
promise = std::move(promise)](Result<vector<MessagesDbDialogMessage>> r_messages) mutable {
|
||||||
send_closure(G()->messages_manager(), &MessagesManager::on_search_dialog_messages_db_result, random_id,
|
send_closure(G()->messages_manager(), &MessagesManager::on_search_dialog_messages_db_result, random_id,
|
||||||
dialog_id, fixed_from_message_id, first_db_message_id, filter, offset, limit,
|
dialog_id, fixed_from_message_id, first_db_message_id, filter, offset, limit,
|
||||||
std::move(r_messages), std::move(promise));
|
std::move(r_messages), std::move(promise));
|
||||||
@ -21732,7 +21732,7 @@ MessageId MessagesManager::get_first_database_message_id_by_index(const Dialog *
|
|||||||
void MessagesManager::on_search_dialog_messages_db_result(int64 random_id, DialogId dialog_id,
|
void MessagesManager::on_search_dialog_messages_db_result(int64 random_id, DialogId dialog_id,
|
||||||
MessageId from_message_id, MessageId first_db_message_id,
|
MessageId from_message_id, MessageId first_db_message_id,
|
||||||
MessageSearchFilter filter, int32 offset, int32 limit,
|
MessageSearchFilter filter, int32 offset, int32 limit,
|
||||||
Result<std::vector<BufferSlice>> r_messages,
|
Result<vector<MessagesDbDialogMessage>> r_messages,
|
||||||
Promise<> promise) {
|
Promise<> promise) {
|
||||||
if (G()->close_flag()) {
|
if (G()->close_flag()) {
|
||||||
return promise.set_error(Status::Error(500, "Request aborted"));
|
return promise.set_error(Status::Error(500, "Request aborted"));
|
||||||
@ -21759,7 +21759,7 @@ void MessagesManager::on_search_dialog_messages_db_result(int64 random_id, Dialo
|
|||||||
|
|
||||||
res.reserve(messages.size());
|
res.reserve(messages.size());
|
||||||
for (auto &message : messages) {
|
for (auto &message : messages) {
|
||||||
auto m = on_get_message_from_database(d, dialog_id, message, false, "on_search_dialog_messages_db_result");
|
auto m = on_get_message_from_database(d, message, false, "on_search_dialog_messages_db_result");
|
||||||
if (m != nullptr && first_db_message_id <= m->message_id) {
|
if (m != nullptr && first_db_message_id <= m->message_id) {
|
||||||
if (filter == MessageSearchFilter::UnreadMention && !m->contains_unread_mention) {
|
if (filter == MessageSearchFilter::UnreadMention && !m->contains_unread_mention) {
|
||||||
// skip already read by d->last_read_all_mentions_message_id mentions
|
// skip already read by d->last_read_all_mentions_message_id mentions
|
||||||
@ -22043,7 +22043,7 @@ int64 MessagesManager::get_dialog_message_by_date(DialogId dialog_id, int32 date
|
|||||||
G()->td_db()->get_messages_db_async()->get_dialog_message_by_date(
|
G()->td_db()->get_messages_db_async()->get_dialog_message_by_date(
|
||||||
dialog_id, d->first_database_message_id, d->last_database_message_id, date,
|
dialog_id, d->first_database_message_id, d->last_database_message_id, date,
|
||||||
PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, date, random_id,
|
PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, date, random_id,
|
||||||
promise = std::move(promise)](Result<BufferSlice> result) mutable {
|
promise = std::move(promise)](Result<MessagesDbDialogMessage> result) mutable {
|
||||||
send_closure(actor_id, &MessagesManager::on_get_dialog_message_by_date_from_database, dialog_id, date,
|
send_closure(actor_id, &MessagesManager::on_get_dialog_message_by_date_from_database, dialog_id, date,
|
||||||
random_id, std::move(result), std::move(promise));
|
random_id, std::move(result), std::move(promise));
|
||||||
}));
|
}));
|
||||||
@ -22071,15 +22071,15 @@ MessageId MessagesManager::find_message_by_date(const Message *m, int32 date) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::on_get_dialog_message_by_date_from_database(DialogId dialog_id, int32 date, int64 random_id,
|
void MessagesManager::on_get_dialog_message_by_date_from_database(DialogId dialog_id, int32 date, int64 random_id,
|
||||||
Result<BufferSlice> result, Promise<Unit> promise) {
|
Result<MessagesDbDialogMessage> result,
|
||||||
|
Promise<Unit> promise) {
|
||||||
if (G()->close_flag()) {
|
if (G()->close_flag()) {
|
||||||
return promise.set_error(Status::Error(500, "Request aborted"));
|
return promise.set_error(Status::Error(500, "Request aborted"));
|
||||||
}
|
}
|
||||||
Dialog *d = get_dialog(dialog_id);
|
Dialog *d = get_dialog(dialog_id);
|
||||||
CHECK(d != nullptr);
|
CHECK(d != nullptr);
|
||||||
if (result.is_ok()) {
|
if (result.is_ok()) {
|
||||||
Message *m =
|
Message *m = on_get_message_from_database(d, result.ok(), false, "on_get_dialog_message_by_date_from_database");
|
||||||
on_get_message_from_database(d, dialog_id, result.ok(), false, "on_get_dialog_message_by_date_from_database");
|
|
||||||
if (m != nullptr) {
|
if (m != nullptr) {
|
||||||
auto message_id = find_message_by_date(d->messages.get(), date);
|
auto message_id = find_message_by_date(d->messages.get(), date);
|
||||||
if (!message_id.is_valid()) {
|
if (!message_id.is_valid()) {
|
||||||
@ -22300,7 +22300,8 @@ unique_ptr<MessagesManager::Message> MessagesManager::parse_message(DialogId dia
|
|||||||
|
|
||||||
void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId from_message_id,
|
void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId from_message_id,
|
||||||
MessageId old_last_database_message_id, int32 offset, int32 limit,
|
MessageId old_last_database_message_id, int32 offset, int32 limit,
|
||||||
bool from_the_end, bool only_local, vector<BufferSlice> &&messages,
|
bool from_the_end, bool only_local,
|
||||||
|
vector<MessagesDbDialogMessage> &&messages,
|
||||||
Promise<Unit> &&promise) {
|
Promise<Unit> &&promise) {
|
||||||
CHECK(-limit < offset && offset <= 0);
|
CHECK(-limit < offset && offset <= 0);
|
||||||
CHECK(offset < 0 || from_the_end);
|
CHECK(offset < 0 || from_the_end);
|
||||||
@ -22364,7 +22365,7 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId
|
|||||||
if (!d->first_database_message_id.is_valid() && !d->have_full_history) {
|
if (!d->first_database_message_id.is_valid() && !d->have_full_history) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
auto message = parse_message(dialog_id, std::move(message_slice), false);
|
auto message = parse_message(dialog_id, message_slice.data, false);
|
||||||
if (message == nullptr) {
|
if (message == nullptr) {
|
||||||
if (d->have_full_history) {
|
if (d->have_full_history) {
|
||||||
d->have_full_history = false;
|
d->have_full_history = false;
|
||||||
@ -22568,8 +22569,8 @@ void MessagesManager::get_history_from_the_end_impl(const Dialog *d, bool from_d
|
|||||||
db_query.limit = limit;
|
db_query.limit = limit;
|
||||||
G()->td_db()->get_messages_db_async()->get_messages(
|
G()->td_db()->get_messages_db_async()->get_messages(
|
||||||
db_query, PromiseCreator::lambda([dialog_id, old_last_database_message_id = d->last_database_message_id,
|
db_query, PromiseCreator::lambda([dialog_id, old_last_database_message_id = d->last_database_message_id,
|
||||||
only_local, limit, actor_id = actor_id(this),
|
only_local, limit, actor_id = actor_id(this), promise = std::move(promise)](
|
||||||
promise = std::move(promise)](std::vector<BufferSlice> messages) mutable {
|
vector<MessagesDbDialogMessage> messages) mutable {
|
||||||
send_closure(actor_id, &MessagesManager::on_get_history_from_database, dialog_id, MessageId::max(),
|
send_closure(actor_id, &MessagesManager::on_get_history_from_database, dialog_id, MessageId::max(),
|
||||||
old_last_database_message_id, 0, limit, true, only_local, std::move(messages),
|
old_last_database_message_id, 0, limit, true, only_local, std::move(messages),
|
||||||
std::move(promise));
|
std::move(promise));
|
||||||
@ -22626,7 +22627,7 @@ void MessagesManager::get_history_impl(const Dialog *d, MessageId from_message_i
|
|||||||
db_query,
|
db_query,
|
||||||
PromiseCreator::lambda([dialog_id, from_message_id, old_last_database_message_id = d->last_database_message_id,
|
PromiseCreator::lambda([dialog_id, from_message_id, old_last_database_message_id = d->last_database_message_id,
|
||||||
offset, limit, only_local, actor_id = actor_id(this),
|
offset, limit, only_local, actor_id = actor_id(this),
|
||||||
promise = std::move(promise)](std::vector<BufferSlice> messages) mutable {
|
promise = std::move(promise)](vector<MessagesDbDialogMessage> messages) mutable {
|
||||||
send_closure(actor_id, &MessagesManager::on_get_history_from_database, dialog_id, from_message_id,
|
send_closure(actor_id, &MessagesManager::on_get_history_from_database, dialog_id, from_message_id,
|
||||||
old_last_database_message_id, offset, limit, false, only_local, std::move(messages),
|
old_last_database_message_id, offset, limit, false, only_local, std::move(messages),
|
||||||
std::move(promise));
|
std::move(promise));
|
||||||
@ -22771,7 +22772,7 @@ void MessagesManager::load_dialog_scheduled_messages(DialogId dialog_id, bool fr
|
|||||||
if (queries.size() == 1) {
|
if (queries.size() == 1) {
|
||||||
G()->td_db()->get_messages_db_async()->get_scheduled_messages(
|
G()->td_db()->get_messages_db_async()->get_scheduled_messages(
|
||||||
dialog_id, 1000,
|
dialog_id, 1000,
|
||||||
PromiseCreator::lambda([dialog_id, actor_id = actor_id(this)](std::vector<BufferSlice> messages) {
|
PromiseCreator::lambda([dialog_id, actor_id = actor_id(this)](vector<MessagesDbDialogMessage> messages) {
|
||||||
send_closure(actor_id, &MessagesManager::on_get_scheduled_messages_from_database, dialog_id,
|
send_closure(actor_id, &MessagesManager::on_get_scheduled_messages_from_database, dialog_id,
|
||||||
std::move(messages));
|
std::move(messages));
|
||||||
}));
|
}));
|
||||||
@ -22782,7 +22783,8 @@ void MessagesManager::load_dialog_scheduled_messages(DialogId dialog_id, bool fr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::on_get_scheduled_messages_from_database(DialogId dialog_id, vector<BufferSlice> &&messages) {
|
void MessagesManager::on_get_scheduled_messages_from_database(DialogId dialog_id,
|
||||||
|
vector<MessagesDbDialogMessage> &&messages) {
|
||||||
if (G()->close_flag()) {
|
if (G()->close_flag()) {
|
||||||
auto it = load_scheduled_messages_from_database_queries_.find(dialog_id);
|
auto it = load_scheduled_messages_from_database_queries_.find(dialog_id);
|
||||||
CHECK(it != load_scheduled_messages_from_database_queries_.end());
|
CHECK(it != load_scheduled_messages_from_database_queries_.end());
|
||||||
@ -22804,7 +22806,7 @@ void MessagesManager::on_get_scheduled_messages_from_database(DialogId dialog_id
|
|||||||
Dependencies dependencies;
|
Dependencies dependencies;
|
||||||
vector<MessageId> added_message_ids;
|
vector<MessageId> added_message_ids;
|
||||||
for (auto &message_slice : messages) {
|
for (auto &message_slice : messages) {
|
||||||
auto message = parse_message(dialog_id, std::move(message_slice), true);
|
auto message = parse_message(dialog_id, message_slice.data, true);
|
||||||
if (message == nullptr) {
|
if (message == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -27505,8 +27507,7 @@ vector<Notification> MessagesManager::get_message_notifications_from_database_fo
|
|||||||
<< " messages with notifications from database in " << group_info.group_id << '/'
|
<< " messages with notifications from database in " << group_info.group_id << '/'
|
||||||
<< d->dialog_id;
|
<< d->dialog_id;
|
||||||
for (auto &message : messages) {
|
for (auto &message : messages) {
|
||||||
auto m = on_get_message_from_database(d, d->dialog_id, message, false,
|
auto m = on_get_message_from_database(d, message, false, "get_message_notifications_from_database_force");
|
||||||
"get_message_notifications_from_database_force");
|
|
||||||
if (m == nullptr) {
|
if (m == nullptr) {
|
||||||
VLOG(notifications) << "Receive from database a broken message";
|
VLOG(notifications) << "Receive from database a broken message";
|
||||||
continue;
|
continue;
|
||||||
@ -27589,7 +27590,7 @@ vector<Notification> MessagesManager::get_message_notifications_from_database_fo
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<vector<BufferSlice>> MessagesManager::do_get_message_notifications_from_database_force(
|
Result<vector<MessagesDbDialogMessage>> MessagesManager::do_get_message_notifications_from_database_force(
|
||||||
Dialog *d, bool from_mentions, NotificationId from_notification_id, MessageId from_message_id, int32 limit) {
|
Dialog *d, bool from_mentions, NotificationId from_notification_id, MessageId from_message_id, int32 limit) {
|
||||||
CHECK(G()->parameters().use_message_db);
|
CHECK(G()->parameters().use_message_db);
|
||||||
CHECK(!from_message_id.is_scheduled());
|
CHECK(!from_message_id.is_scheduled());
|
||||||
@ -27709,7 +27710,7 @@ void MessagesManager::do_get_message_notifications_from_database(Dialog *d, bool
|
|||||||
auto dialog_id = d->dialog_id;
|
auto dialog_id = d->dialog_id;
|
||||||
auto new_promise =
|
auto new_promise =
|
||||||
PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, from_mentions, initial_from_notification_id, limit,
|
PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, from_mentions, initial_from_notification_id, limit,
|
||||||
promise = std::move(promise)](Result<vector<BufferSlice>> result) mutable {
|
promise = std::move(promise)](Result<vector<MessagesDbDialogMessage>> result) mutable {
|
||||||
send_closure(actor_id, &MessagesManager::on_get_message_notifications_from_database, dialog_id, from_mentions,
|
send_closure(actor_id, &MessagesManager::on_get_message_notifications_from_database, dialog_id, from_mentions,
|
||||||
initial_from_notification_id, limit, std::move(result), std::move(promise));
|
initial_from_notification_id, limit, std::move(result), std::move(promise));
|
||||||
});
|
});
|
||||||
@ -27736,7 +27737,8 @@ void MessagesManager::do_get_message_notifications_from_database(Dialog *d, bool
|
|||||||
|
|
||||||
void MessagesManager::on_get_message_notifications_from_database(DialogId dialog_id, bool from_mentions,
|
void MessagesManager::on_get_message_notifications_from_database(DialogId dialog_id, bool from_mentions,
|
||||||
NotificationId initial_from_notification_id,
|
NotificationId initial_from_notification_id,
|
||||||
int32 limit, Result<vector<BufferSlice>> result,
|
int32 limit,
|
||||||
|
Result<vector<MessagesDbDialogMessage>> result,
|
||||||
Promise<vector<Notification>> promise) {
|
Promise<vector<Notification>> promise) {
|
||||||
if (G()->close_flag()) {
|
if (G()->close_flag()) {
|
||||||
result = Status::Error(500, "Request aborted");
|
result = Status::Error(500, "Request aborted");
|
||||||
@ -27761,7 +27763,7 @@ void MessagesManager::on_get_message_notifications_from_database(DialogId dialog
|
|||||||
VLOG(notifications) << "Loaded " << messages.size() << " messages with notifications in " << group_info.group_id
|
VLOG(notifications) << "Loaded " << messages.size() << " messages with notifications in " << group_info.group_id
|
||||||
<< '/' << dialog_id << " from database";
|
<< '/' << dialog_id << " from database";
|
||||||
for (auto &message : messages) {
|
for (auto &message : messages) {
|
||||||
auto m = on_get_message_from_database(d, dialog_id, message, false, "on_get_message_notifications_from_database");
|
auto m = on_get_message_from_database(d, message, false, "on_get_message_notifications_from_database");
|
||||||
if (m == nullptr) {
|
if (m == nullptr) {
|
||||||
VLOG(notifications) << "Receive from database a broken message";
|
VLOG(notifications) << "Receive from database a broken message";
|
||||||
continue;
|
continue;
|
||||||
@ -27883,8 +27885,8 @@ void MessagesManager::remove_message_notification(DialogId dialog_id, Notificati
|
|||||||
if (G()->parameters().use_message_db) {
|
if (G()->parameters().use_message_db) {
|
||||||
G()->td_db()->get_messages_db_async()->get_messages_from_notification_id(
|
G()->td_db()->get_messages_db_async()->get_messages_from_notification_id(
|
||||||
dialog_id, NotificationId(notification_id.get() + 1), 1,
|
dialog_id, NotificationId(notification_id.get() + 1), 1,
|
||||||
PromiseCreator::lambda(
|
PromiseCreator::lambda([dialog_id, from_mentions, notification_id,
|
||||||
[dialog_id, from_mentions, notification_id, actor_id = actor_id(this)](vector<BufferSlice> result) {
|
actor_id = actor_id(this)](vector<MessagesDbDialogMessage> result) {
|
||||||
send_closure(actor_id, &MessagesManager::do_remove_message_notification, dialog_id, from_mentions,
|
send_closure(actor_id, &MessagesManager::do_remove_message_notification, dialog_id, from_mentions,
|
||||||
notification_id, std::move(result));
|
notification_id, std::move(result));
|
||||||
}));
|
}));
|
||||||
@ -27926,7 +27928,8 @@ void MessagesManager::remove_message_notifications_by_message_ids(DialogId dialo
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::do_remove_message_notification(DialogId dialog_id, bool from_mentions,
|
void MessagesManager::do_remove_message_notification(DialogId dialog_id, bool from_mentions,
|
||||||
NotificationId notification_id, vector<BufferSlice> result) {
|
NotificationId notification_id,
|
||||||
|
vector<MessagesDbDialogMessage> result) {
|
||||||
if (result.empty() || G()->close_flag()) {
|
if (result.empty() || G()->close_flag()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -27935,7 +27938,7 @@ void MessagesManager::do_remove_message_notification(DialogId dialog_id, bool fr
|
|||||||
Dialog *d = get_dialog(dialog_id);
|
Dialog *d = get_dialog(dialog_id);
|
||||||
CHECK(d != nullptr);
|
CHECK(d != nullptr);
|
||||||
|
|
||||||
auto m = on_get_message_from_database(d, dialog_id, result[0], false, "do_remove_message_notification");
|
auto m = on_get_message_from_database(d, result[0], false, "do_remove_message_notification");
|
||||||
if (m != nullptr && m->notification_id == notification_id &&
|
if (m != nullptr && m->notification_id == notification_id &&
|
||||||
is_from_mention_notification_group(d, m) == from_mentions && is_message_notification_active(d, m)) {
|
is_from_mention_notification_group(d, m) == from_mentions && is_message_notification_active(d, m)) {
|
||||||
remove_message_notification_id(d, m, false, false);
|
remove_message_notification_id(d, m, false, false);
|
||||||
@ -32120,7 +32123,7 @@ MessagesManager::Message *MessagesManager::get_message_force(Dialog *d, MessageI
|
|||||||
if (r_value.is_error()) {
|
if (r_value.is_error()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return on_get_message_from_database(d, d->dialog_id, r_value.ok(), message_id.is_scheduled(), source);
|
return on_get_message_from_database(d, r_value.ok(), message_id.is_scheduled(), source);
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagesManager::Message *MessagesManager::on_get_message_from_database(const MessagesDbMessage &message,
|
MessagesManager::Message *MessagesManager::on_get_message_from_database(const MessagesDbMessage &message,
|
||||||
@ -32129,6 +32132,11 @@ MessagesManager::Message *MessagesManager::on_get_message_from_database(const Me
|
|||||||
is_scheduled, source);
|
is_scheduled, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MessagesManager::Message *MessagesManager::on_get_message_from_database(Dialog *d, const MessagesDbDialogMessage &value,
|
||||||
|
bool is_scheduled, const char *source) {
|
||||||
|
return on_get_message_from_database(d, d->dialog_id, value.data, is_scheduled, source);
|
||||||
|
}
|
||||||
|
|
||||||
MessagesManager::Message *MessagesManager::on_get_message_from_database(Dialog *d, DialogId dialog_id,
|
MessagesManager::Message *MessagesManager::on_get_message_from_database(Dialog *d, DialogId dialog_id,
|
||||||
const BufferSlice &value, bool is_scheduled,
|
const BufferSlice &value, bool is_scheduled,
|
||||||
const char *source) {
|
const char *source) {
|
||||||
@ -32136,7 +32144,7 @@ MessagesManager::Message *MessagesManager::on_get_message_from_database(Dialog *
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto m = parse_message(dialog_id, std::move(value), is_scheduled);
|
auto m = parse_message(dialog_id, value, is_scheduled);
|
||||||
if (m == nullptr) {
|
if (m == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -34095,7 +34103,7 @@ MessageId MessagesManager::get_message_id_by_random_id(Dialog *d, int64 random_i
|
|||||||
auto r_value = G()->td_db()->get_messages_db_sync()->get_message_by_random_id(d->dialog_id, random_id);
|
auto r_value = G()->td_db()->get_messages_db_sync()->get_message_by_random_id(d->dialog_id, random_id);
|
||||||
if (r_value.is_ok()) {
|
if (r_value.is_ok()) {
|
||||||
debug_add_message_to_dialog_fail_reason_ = "not called";
|
debug_add_message_to_dialog_fail_reason_ = "not called";
|
||||||
Message *m = on_get_message_from_database(d, d->dialog_id, r_value.ok(), false, "get_message_id_by_random_id");
|
Message *m = on_get_message_from_database(d, r_value.ok(), false, "get_message_id_by_random_id");
|
||||||
if (m != nullptr) {
|
if (m != nullptr) {
|
||||||
LOG_CHECK(m->random_id == random_id)
|
LOG_CHECK(m->random_id == random_id)
|
||||||
<< random_id << " " << m->random_id << " " << d->random_id_to_message_id[random_id] << " "
|
<< random_id << " " << m->random_id << " " << d->random_id_to_message_id[random_id] << " "
|
||||||
|
@ -2077,7 +2077,7 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
void on_get_history_from_database(DialogId dialog_id, MessageId from_message_id,
|
void on_get_history_from_database(DialogId dialog_id, MessageId from_message_id,
|
||||||
MessageId old_last_database_message_id, int32 offset, int32 limit,
|
MessageId old_last_database_message_id, int32 offset, int32 limit,
|
||||||
bool from_the_end, bool only_local, vector<BufferSlice> &&messages,
|
bool from_the_end, bool only_local, vector<MessagesDbDialogMessage> &&messages,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
void get_history_from_the_end(DialogId dialog_id, bool from_database, bool only_local, Promise<Unit> &&promise);
|
void get_history_from_the_end(DialogId dialog_id, bool from_database, bool only_local, Promise<Unit> &&promise);
|
||||||
@ -2098,7 +2098,7 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
void load_dialog_scheduled_messages(DialogId dialog_id, bool from_database, int64 hash, Promise<Unit> &&promise);
|
void load_dialog_scheduled_messages(DialogId dialog_id, bool from_database, int64 hash, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void on_get_scheduled_messages_from_database(DialogId dialog_id, vector<BufferSlice> &&messages);
|
void on_get_scheduled_messages_from_database(DialogId dialog_id, vector<MessagesDbDialogMessage> &&messages);
|
||||||
|
|
||||||
static int32 get_random_y(MessageId message_id);
|
static int32 get_random_y(MessageId message_id);
|
||||||
|
|
||||||
@ -2240,9 +2240,8 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
vector<Notification> get_message_notifications_from_database_force(Dialog *d, bool from_mentions, int32 limit);
|
vector<Notification> get_message_notifications_from_database_force(Dialog *d, bool from_mentions, int32 limit);
|
||||||
|
|
||||||
Result<vector<BufferSlice>> do_get_message_notifications_from_database_force(Dialog *d, bool from_mentions,
|
Result<vector<MessagesDbDialogMessage>> do_get_message_notifications_from_database_force(
|
||||||
NotificationId from_notification_id,
|
Dialog *d, bool from_mentions, NotificationId from_notification_id, MessageId from_message_id, int32 limit);
|
||||||
MessageId from_message_id, int32 limit);
|
|
||||||
|
|
||||||
void do_get_message_notifications_from_database(Dialog *d, bool from_mentions,
|
void do_get_message_notifications_from_database(Dialog *d, bool from_mentions,
|
||||||
NotificationId initial_from_notification_id,
|
NotificationId initial_from_notification_id,
|
||||||
@ -2251,11 +2250,11 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
void on_get_message_notifications_from_database(DialogId dialog_id, bool from_mentions,
|
void on_get_message_notifications_from_database(DialogId dialog_id, bool from_mentions,
|
||||||
NotificationId initial_from_notification_id, int32 limit,
|
NotificationId initial_from_notification_id, int32 limit,
|
||||||
Result<vector<BufferSlice>> result,
|
Result<vector<MessagesDbDialogMessage>> result,
|
||||||
Promise<vector<Notification>> promise);
|
Promise<vector<Notification>> promise);
|
||||||
|
|
||||||
void do_remove_message_notification(DialogId dialog_id, bool from_mentions, NotificationId notification_id,
|
void do_remove_message_notification(DialogId dialog_id, bool from_mentions, NotificationId notification_id,
|
||||||
vector<BufferSlice> result);
|
vector<MessagesDbDialogMessage> result);
|
||||||
|
|
||||||
int32 get_dialog_pending_notification_count(const Dialog *d, bool from_mentions) const;
|
int32 get_dialog_pending_notification_count(const Dialog *d, bool from_mentions) const;
|
||||||
|
|
||||||
@ -2661,6 +2660,9 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
Message *on_get_message_from_database(const MessagesDbMessage &message, bool is_scheduled, const char *source);
|
Message *on_get_message_from_database(const MessagesDbMessage &message, bool is_scheduled, const char *source);
|
||||||
|
|
||||||
|
Message *on_get_message_from_database(Dialog *d, const MessagesDbDialogMessage &value, bool is_scheduled,
|
||||||
|
const char *source);
|
||||||
|
|
||||||
Message *on_get_message_from_database(Dialog *d, DialogId dialog_id, const BufferSlice &value, bool is_scheduled,
|
Message *on_get_message_from_database(Dialog *d, DialogId dialog_id, const BufferSlice &value, bool is_scheduled,
|
||||||
const char *source);
|
const char *source);
|
||||||
|
|
||||||
@ -2668,7 +2670,7 @@ class MessagesManager final : public Actor {
|
|||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
void on_get_dialog_message_by_date_from_database(DialogId dialog_id, int32 date, int64 random_id,
|
void on_get_dialog_message_by_date_from_database(DialogId dialog_id, int32 date, int64 random_id,
|
||||||
Result<BufferSlice> result, Promise<Unit> promise);
|
Result<MessagesDbDialogMessage> result, Promise<Unit> promise);
|
||||||
|
|
||||||
std::pair<bool, int32> get_dialog_mute_until(DialogId dialog_id, const Dialog *d) const;
|
std::pair<bool, int32> get_dialog_mute_until(DialogId dialog_id, const Dialog *d) const;
|
||||||
|
|
||||||
@ -2760,7 +2762,8 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
void on_search_dialog_messages_db_result(int64 random_id, DialogId dialog_id, MessageId from_message_id,
|
void on_search_dialog_messages_db_result(int64 random_id, DialogId dialog_id, MessageId from_message_id,
|
||||||
MessageId first_db_message_id, MessageSearchFilter filter, int32 offset,
|
MessageId first_db_message_id, MessageSearchFilter filter, int32 offset,
|
||||||
int32 limit, Result<std::vector<BufferSlice>> r_messages, Promise<> promise);
|
int32 limit, Result<vector<MessagesDbDialogMessage>> r_messages,
|
||||||
|
Promise<> promise);
|
||||||
|
|
||||||
void on_messages_db_fts_result(Result<MessagesDbFtsResult> result, string offset, int32 limit, int64 random_id,
|
void on_messages_db_fts_result(Result<MessagesDbFtsResult> result, string offset, int32 limit, int64 random_id,
|
||||||
Promise<> &&promise);
|
Promise<> &&promise);
|
||||||
|
Loading…
Reference in New Issue
Block a user