2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/telegram/DialogId.h"
|
2019-08-22 17:24:02 +02:00
|
|
|
#include "td/telegram/FolderId.h"
|
2018-11-27 15:39:13 +01:00
|
|
|
#include "td/telegram/NotificationGroupId.h"
|
2018-12-20 18:24:49 +01:00
|
|
|
#include "td/telegram/NotificationGroupKey.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-05-03 00:10:54 +02:00
|
|
|
#include "td/db/KeyValueSyncInterface.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/buffer.h"
|
|
|
|
#include "td/utils/common.h"
|
2022-06-27 12:30:18 +02:00
|
|
|
#include "td/utils/Promise.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace td {
|
2019-01-07 01:17:11 +01:00
|
|
|
|
|
|
|
class SqliteConnectionSafe;
|
|
|
|
class SqliteDb;
|
|
|
|
|
2019-09-15 03:15:46 +02:00
|
|
|
struct DialogDbGetDialogsResult {
|
|
|
|
vector<BufferSlice> dialogs;
|
|
|
|
int64 next_order = 0;
|
|
|
|
DialogId next_dialog_id;
|
|
|
|
};
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class DialogDbSyncInterface {
|
|
|
|
public:
|
|
|
|
DialogDbSyncInterface() = default;
|
|
|
|
DialogDbSyncInterface(const DialogDbSyncInterface &) = delete;
|
|
|
|
DialogDbSyncInterface &operator=(const DialogDbSyncInterface &) = delete;
|
|
|
|
virtual ~DialogDbSyncInterface() = default;
|
|
|
|
|
2019-08-26 19:08:51 +02:00
|
|
|
virtual Status add_dialog(DialogId dialog_id, FolderId folder_id, int64 order, BufferSlice data,
|
2018-12-22 21:24:18 +01:00
|
|
|
vector<NotificationGroupKey> notification_groups) = 0;
|
2018-12-20 18:24:49 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
virtual Result<BufferSlice> get_dialog(DialogId dialog_id) = 0;
|
2018-12-20 18:24:49 +01:00
|
|
|
|
2019-09-15 03:15:46 +02:00
|
|
|
virtual Result<DialogDbGetDialogsResult> get_dialogs(FolderId folder_id, int64 order, DialogId dialog_id,
|
|
|
|
int32 limit) = 0;
|
2018-12-20 18:24:49 +01:00
|
|
|
|
2018-12-22 21:24:18 +01:00
|
|
|
virtual Result<vector<NotificationGroupKey>> get_notification_groups_by_last_notification_date(
|
2018-12-20 18:24:49 +01:00
|
|
|
NotificationGroupKey notification_group_key, int32 limit) = 0;
|
|
|
|
|
|
|
|
virtual Result<NotificationGroupKey> get_notification_group(NotificationGroupId notification_group_id) = 0;
|
|
|
|
|
2019-12-26 02:12:26 +01:00
|
|
|
virtual Result<int32> get_secret_chat_count(FolderId folder_id) = 0;
|
|
|
|
|
2021-10-07 12:18:00 +02:00
|
|
|
virtual Status begin_read_transaction() = 0;
|
|
|
|
virtual Status begin_write_transaction() = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
virtual Status commit_transaction() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DialogDbSyncSafeInterface {
|
|
|
|
public:
|
|
|
|
DialogDbSyncSafeInterface() = default;
|
|
|
|
DialogDbSyncSafeInterface(const DialogDbSyncSafeInterface &) = delete;
|
|
|
|
DialogDbSyncSafeInterface &operator=(const DialogDbSyncSafeInterface &) = delete;
|
|
|
|
virtual ~DialogDbSyncSafeInterface() = default;
|
|
|
|
|
|
|
|
virtual DialogDbSyncInterface &get() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DialogDbAsyncInterface {
|
|
|
|
public:
|
|
|
|
DialogDbAsyncInterface() = default;
|
|
|
|
DialogDbAsyncInterface(const DialogDbAsyncInterface &) = delete;
|
|
|
|
DialogDbAsyncInterface &operator=(const DialogDbAsyncInterface &) = delete;
|
|
|
|
virtual ~DialogDbAsyncInterface() = default;
|
|
|
|
|
2019-08-26 19:08:51 +02:00
|
|
|
virtual void add_dialog(DialogId dialog_id, FolderId folder_id, int64 order, BufferSlice data,
|
2018-12-22 21:24:18 +01:00
|
|
|
vector<NotificationGroupKey> notification_groups, Promise<> promise) = 0;
|
2018-12-20 18:24:49 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
virtual void get_dialog(DialogId dialog_id, Promise<BufferSlice> promise) = 0;
|
2018-12-20 18:24:49 +01:00
|
|
|
|
2019-08-22 17:24:02 +02:00
|
|
|
virtual void get_dialogs(FolderId folder_id, int64 order, DialogId dialog_id, int32 limit,
|
2019-09-15 03:15:46 +02:00
|
|
|
Promise<DialogDbGetDialogsResult> promise) = 0;
|
2018-12-20 18:24:49 +01:00
|
|
|
|
2018-12-22 21:24:18 +01:00
|
|
|
virtual void get_notification_groups_by_last_notification_date(NotificationGroupKey notification_group_key,
|
|
|
|
int32 limit,
|
|
|
|
Promise<vector<NotificationGroupKey>> promise) = 0;
|
2018-12-20 18:24:49 +01:00
|
|
|
|
|
|
|
virtual void get_notification_group(NotificationGroupId notification_group_id,
|
|
|
|
Promise<NotificationGroupKey> promise) = 0;
|
|
|
|
|
2019-12-26 02:12:26 +01:00
|
|
|
virtual void get_secret_chat_count(FolderId folder_id, Promise<int32> promise) = 0;
|
|
|
|
|
2018-12-20 18:24:49 +01:00
|
|
|
virtual void close(Promise<> promise) = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2020-05-03 00:10:54 +02:00
|
|
|
Status init_dialog_db(SqliteDb &db, int version, KeyValueSyncInterface &binlog_pmc,
|
|
|
|
bool &was_created) TD_WARN_UNUSED_RESULT;
|
2018-12-31 20:04:05 +01:00
|
|
|
Status drop_dialog_db(SqliteDb &db, int version) TD_WARN_UNUSED_RESULT;
|
|
|
|
|
|
|
|
std::shared_ptr<DialogDbSyncSafeInterface> create_dialog_db_sync(
|
|
|
|
std::shared_ptr<SqliteConnectionSafe> sqlite_connection);
|
|
|
|
|
|
|
|
std::shared_ptr<DialogDbAsyncInterface> create_dialog_db_async(std::shared_ptr<DialogDbSyncSafeInterface> sync_db,
|
2022-06-29 23:46:02 +02:00
|
|
|
int32 scheduler_id = -1);
|
2019-01-07 01:17:11 +01:00
|
|
|
|
2018-07-18 03:30:29 +02:00
|
|
|
} // namespace td
|