Add td_api::getRecentlyOpenedChats.

This commit is contained in:
levlam 2021-09-14 14:18:37 +03:00
parent 27d4810cb1
commit ded0b57905
6 changed files with 49 additions and 3 deletions

View File

@ -4130,6 +4130,9 @@ removeRecentlyFoundChat chat_id:int53 = Ok;
//@description Clears the list of recently found chats
clearRecentlyFoundChats = Ok;
//@description Returns recently opened chats, this is an offline request. Returns chats in the order of last opening @limit The maximum number of chats to be returned
getRecentlyOpenedChats limit:int32 = Chats;
//@description Checks whether a username can be set for a chat @chat_id Chat identifier; should be identifier of a supergroup chat, or a channel chat, or a private chat with self, or zero if the chat is being created @username Username to be checked
checkChatUsername chat_id:int53 username:string = CheckChatUsernameResult;

View File

@ -5695,7 +5695,10 @@ MessagesManager::Dialog::~Dialog() {
}
MessagesManager::MessagesManager(Td *td, ActorShared<> parent)
: recently_found_dialogs_{td, "recently_found", MAX_RECENTLY_FOUND_DIALOGS}, td_(td), parent_(std::move(parent)) {
: recently_found_dialogs_{td, "recently_found", MAX_RECENT_DIALOGS}
, recently_opened_dialogs_{td, "recently_opened", MAX_RECENT_DIALOGS}
, td_(td)
, parent_(std::move(parent)) {
upload_media_callback_ = std::make_shared<UploadMediaCallback>();
upload_thumbnail_callback_ = std::make_shared<UploadThumbnailCallback>();
upload_dialog_photo_callback_ = std::make_shared<UploadDialogPhotoCallback>();
@ -10919,6 +10922,7 @@ void MessagesManager::on_dialog_deleted(DialogId dialog_id, Promise<Unit> &&prom
d->need_restore_reply_markup = true;
}
recently_found_dialogs_.remove_dialog(dialog_id);
recently_opened_dialogs_.remove_dialog(dialog_id);
if (dialog_id.get_type() == DialogType::Channel) {
G()->td_db()->get_binlog_pmc()->erase(get_channel_pts_key(dialog_id));
}
@ -16262,6 +16266,10 @@ std::pair<int32, vector<DialogId>> MessagesManager::search_dialogs(const string
return {narrow_cast<int32>(result.first), std::move(dialog_ids)};
}
std::pair<int32, vector<DialogId>> MessagesManager::get_recently_opened_dialogs(int32 limit, Promise<Unit> &&promise) {
return recently_opened_dialogs_.get_dialogs(limit, std::move(promise));
}
vector<DialogId> MessagesManager::sort_dialogs_by_order(const vector<DialogId> &dialog_ids, int32 limit) const {
CHECK(!td_->auth_manager_->is_bot());
int64 fake_order = static_cast<int64>(dialog_ids.size()) + 1;
@ -19525,7 +19533,11 @@ void MessagesManager::read_message_contents_on_server(DialogId dialog_id, vector
void MessagesManager::open_dialog(Dialog *d) {
DialogId dialog_id = d->dialog_id;
if (d->is_opened || !have_input_peer(dialog_id, AccessRights::Read)) {
if (!have_input_peer(dialog_id, AccessRights::Read)) {
return;
}
recently_opened_dialogs_.add_dialog(dialog_id);
if (d->is_opened) {
return;
}
d->is_opened = true;

View File

@ -369,6 +369,8 @@ class MessagesManager final : public Actor {
void clear_recently_found_dialogs();
std::pair<int32, vector<DialogId>> get_recently_opened_dialogs(int32 limit, Promise<Unit> &&promise);
DialogId resolve_dialog_username(const string &username) const;
DialogId search_public_dialog(const string &username_to_search, bool force, Promise<Unit> &&promise);
@ -1652,7 +1654,7 @@ class MessagesManager final : public Actor {
static constexpr int32 MIN_CHANNEL_DIFFERENCE = 1;
static constexpr int32 MAX_CHANNEL_DIFFERENCE = 100;
static constexpr int32 MAX_BOT_CHANNEL_DIFFERENCE = 100000; // server side limit
static constexpr int32 MAX_RECENTLY_FOUND_DIALOGS = 50; // some reasonable value
static constexpr int32 MAX_RECENT_DIALOGS = 50; // some reasonable value
static constexpr size_t MAX_TITLE_LENGTH = 128; // server side limit for chat title
static constexpr size_t MAX_DESCRIPTION_LENGTH = 255; // server side limit for chat description
static constexpr size_t MAX_DIALOG_FILTER_TITLE_LENGTH = 12; // server side limit for dialog filter title
@ -3057,6 +3059,7 @@ class MessagesManager final : public Actor {
static DialogId get_message_original_sender(const Message *m);
RecentDialogList recently_found_dialogs_;
RecentDialogList recently_opened_dialogs_;
class UploadMediaCallback;
class UploadThumbnailCallback;

View File

@ -960,6 +960,25 @@ class GetInactiveSupergroupChatsRequest final : public RequestActor<> {
}
};
class GetRecentlyOpenedChatsRequest final : public RequestActor<> {
int32 limit_;
std::pair<int32, vector<DialogId>> dialog_ids_;
void do_run(Promise<Unit> &&promise) final {
dialog_ids_ = td->messages_manager_->get_recently_opened_dialogs(limit_, std::move(promise));
}
void do_send_result() final {
send_result(MessagesManager::get_chats_object(dialog_ids_));
}
public:
GetRecentlyOpenedChatsRequest(ActorShared<Td> td, uint64 request_id, int32 limit)
: RequestActor(std::move(td), request_id), limit_(limit) {
}
};
class GetMessageRequest final : public RequestOnceActor {
FullMessageId full_message_id_;
@ -5363,6 +5382,11 @@ void Td::on_request(uint64 id, const td_api::clearRecentlyFoundChats &request) {
send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>());
}
void Td::on_request(uint64 id, const td_api::getRecentlyOpenedChats &request) {
CHECK_IS_USER();
CREATE_REQUEST(GetRecentlyOpenedChatsRequest, request.limit_);
}
void Td::on_request(uint64 id, const td_api::openChat &request) {
CHECK_IS_USER();
answer_ok_query(id, messages_manager_->open_dialog(DialogId(request.chat_id_)));

View File

@ -577,6 +577,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::clearRecentlyFoundChats &request);
void on_request(uint64 id, const td_api::getRecentlyOpenedChats &request);
void on_request(uint64 id, const td_api::getGroupsInCommon &request);
void on_request(uint64 id, td_api::checkChatUsername &request);

View File

@ -4049,6 +4049,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::removeRecentlyFoundChat>(as_chat_id(args)));
} else if (op == "crfcs") {
send_request(td_api::make_object<td_api::clearRecentlyFoundChats>());
} else if (op == "groc") {
send_request(td_api::make_object<td_api::getRecentlyOpenedChats>(as_limit(args)));
} else if (op == "gwpp") {
send_request(td_api::make_object<td_api::getWebPagePreview>(as_caption(args)));
} else if (op == "gwpiv") {