tdlight/td/telegram/RecentDialogList.h

60 lines
1.3 KiB
C
Raw Normal View History

2021-09-13 19:34:57 +02:00
//
2022-01-01 01:35:39 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
2021-09-13 19:34:57 +02: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"
#include "td/actor/actor.h"
2021-09-13 19:34:57 +02:00
#include "td/utils/common.h"
2022-03-11 19:38:48 +01:00
#include "td/utils/FlatHashSet.h"
2022-06-27 12:30:18 +02:00
#include "td/utils/Promise.h"
2021-09-13 19:34:57 +02:00
#include <utility>
namespace td {
class Td;
// stores list of Dialog identifiers of a limited size
2021-09-18 23:47:05 +02:00
class RecentDialogList final : public Actor {
2021-09-13 19:34:57 +02:00
public:
RecentDialogList(Td *td, const char *name, size_t max_size);
void add_dialog(DialogId dialog_id);
void remove_dialog(DialogId dialog_id);
std::pair<int32, vector<DialogId>> get_dialogs(int32 limit, Promise<Unit> &&promise);
2021-09-13 19:34:57 +02:00
void clear_dialogs();
private:
Td *td_;
const char *name_;
size_t max_size_;
vector<DialogId> dialog_ids_;
2022-03-11 19:38:48 +01:00
FlatHashSet<DialogId, DialogIdHash> removed_dialog_ids_;
2021-09-13 19:34:57 +02:00
2021-09-14 10:31:21 +02:00
bool is_loaded_ = false;
vector<Promise<Unit>> load_list_queries_;
2021-09-13 19:34:57 +02:00
void load_dialogs(Promise<Unit> &&promise);
2021-09-14 10:31:21 +02:00
void on_load_dialogs(vector<string> &&found_dialogs);
2021-09-13 19:34:57 +02:00
bool do_add_dialog(DialogId dialog_id);
string get_binlog_key() const;
void update_dialogs();
void save_dialogs() const;
2021-09-13 19:34:57 +02:00
};
} // namespace td