2021-09-13 19:34:57 +02:00
|
|
|
//
|
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
2021-09-14 09:16:20 +02:00
|
|
|
#include "td/actor/actor.h"
|
2021-09-13 19:34:57 +02:00
|
|
|
#include "td/actor/MultiPromise.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
|
2021-09-13 20:30:48 +02:00
|
|
|
#include <unordered_set>
|
2021-09-13 19:34:57 +02:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class Td;
|
|
|
|
|
|
|
|
// stores list of Dialog identifiers of a limited size
|
|
|
|
class RecentDialogList : public Actor {
|
|
|
|
public:
|
|
|
|
RecentDialogList(Td *td, const char *name, size_t max_size);
|
|
|
|
|
|
|
|
void add_dialog(DialogId dialog_id);
|
|
|
|
|
|
|
|
void remove_dialog(DialogId dialog_id);
|
|
|
|
|
2021-09-13 19:52:17 +02:00
|
|
|
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_;
|
2021-09-13 20:30:48 +02:00
|
|
|
std::unordered_set<DialogId, DialogIdHash> removed_dialog_ids_;
|
2021-09-13 19:34:57 +02:00
|
|
|
|
|
|
|
int32 dialogs_loaded_ = 0; // 0 - not loaded, 1 - load request was sent, 2 - loaded
|
|
|
|
MultiPromiseActor resolve_dialogs_multipromise_{"ResolveDialogsMultiPromiseActor"};
|
|
|
|
|
2021-09-14 09:16:20 +02:00
|
|
|
void load_dialogs(Promise<Unit> &&promise);
|
2021-09-13 19:52:17 +02:00
|
|
|
|
2021-09-13 19:34:57 +02:00
|
|
|
bool do_add_dialog(DialogId dialog_id);
|
|
|
|
|
|
|
|
string get_binlog_key() const;
|
|
|
|
|
|
|
|
void update_dialogs();
|
|
|
|
|
2021-09-13 19:52:17 +02:00
|
|
|
void save_dialogs() const;
|
2021-09-13 19:34:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|