Add td_api::deleteSavedMessagesTopicMessagesByDate.

This commit is contained in:
levlam 2024-01-18 17:29:09 +03:00
parent 5002f25c0a
commit 788d169e69
6 changed files with 106 additions and 12 deletions

View File

@ -7172,14 +7172,20 @@ getSavedMessagesTopics offset:string limit:int32 = FoundSavedMessagesTopics;
//-For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
getSavedMessagesTopicHistory saved_messages_topic:SavedMessagesTopic from_message_id:int53 offset:int32 limit:int32 = Messages;
//@description Deletes all messages in a Saved Messages topic @saved_messages_topic Saved Messages topic which messages will be deleted
deleteSavedMessagesTopicHistory saved_messages_topic:SavedMessagesTopic = Ok;
//@description Returns the last message sent in a Saved Messages topic no later than the specified date
//@saved_messages_topic Saved Messages topic which message will be returned
//@date Point in time (Unix timestamp) relative to which to search for messages
getSavedMessagesTopicMessageByDate saved_messages_topic:SavedMessagesTopic date:int32 = Message;
//@description Deletes all messages in a Saved Messages topic @saved_messages_topic Saved Messages topic which messages will be deleted
deleteSavedMessagesTopicHistory saved_messages_topic:SavedMessagesTopic = Ok;
//@description Deletes all messages between the specified dates in a Saved Messages topic. Messages sent in the last 30 seconds will not be deleted
//@saved_messages_topic Saved Messages topic which messages will be deleted
//@min_date The minimum date of the messages to delete
//@max_date The maximum date of the messages to delete
deleteSavedMessagesTopicMessagesByDate saved_messages_topic:SavedMessagesTopic min_date:int32 max_date:int32 = Ok;
//@description Returns a list of common group chats with a given user. Chats are sorted by their type and creation date
//@user_id User identifier

View File

@ -2583,6 +2583,38 @@ class DeleteMessagesByDateQuery final : public Td::ResultHandler {
}
};
class DeleteSavedMessagesByDateQuery final : public Td::ResultHandler {
Promise<AffectedHistory> promise_;
public:
explicit DeleteSavedMessagesByDateQuery(Promise<AffectedHistory> &&promise) : promise_(std::move(promise)) {
}
void send(SavedMessagesTopicId saved_messages_topic_id, int32 min_date, int32 max_date) {
auto saved_input_peer = saved_messages_topic_id.get_input_peer(td_);
CHECK(saved_input_peer != nullptr);
int32 flags =
telegram_api::messages_deleteHistory::MIN_DATE_MASK | telegram_api::messages_deleteHistory::MAX_DATE_MASK;
send_query(G()->net_query_creator().create(
telegram_api::messages_deleteSavedHistory(flags, std::move(saved_input_peer), 0, min_date, max_date)));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_deleteSavedHistory>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
promise_.set_value(AffectedHistory(result_ptr.move_as_ok()));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class DeletePhoneCallHistoryQuery final : public Td::ResultHandler {
Promise<AffectedHistory> promise_;
@ -16220,8 +16252,7 @@ void MessagesManager::delete_saved_messages_topic_history(SavedMessagesTopicId s
auto my_dialog_id = td_->dialog_manager_->get_my_dialog_id();
TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_in(td_, my_dialog_id));
AffectedHistoryQuery query = [td = td_, saved_messages_topic_id](DialogId dialog_id,
Promise<AffectedHistory> &&query_promise) {
AffectedHistoryQuery query = [td = td_, saved_messages_topic_id](DialogId, Promise<AffectedHistory> &&query_promise) {
td->create_handler<DeleteSavedHistoryQuery>(std::move(query_promise))->send(saved_messages_topic_id);
};
run_affected_history_query_until_complete(my_dialog_id, std::move(query), true, std::move(promise));
@ -16242,6 +16273,44 @@ void MessagesManager::get_saved_messages_topic_message_by_date(SavedMessagesTopi
td_->create_handler<GetSavedMessageByDateQuery>(std::move(promise))->send(saved_messages_topic_id, date);
}
void MessagesManager::delete_saved_messages_topic_messages_by_date(SavedMessagesTopicId saved_messages_topic_id,
int32 min_date, int32 max_date,
Promise<Unit> &&promise) {
if (!saved_messages_topic_id.is_valid()) {
return promise.set_error(Status::Error(400, "Invalid Saved Messages topic specified"));
}
auto my_dialog_id = td_->dialog_manager_->get_my_dialog_id();
TRY_STATUS_PROMISE(promise, saved_messages_topic_id.is_valid_in(td_, my_dialog_id));
if (min_date > max_date) {
return promise.set_error(Status::Error(400, "Wrong date interval specified"));
}
const int32 telegram_launch_date = 1376438400;
if (max_date < telegram_launch_date) {
return promise.set_value(Unit());
}
if (min_date < telegram_launch_date) {
min_date = telegram_launch_date;
}
auto current_date = max(G()->unix_time(), 1635000000);
if (min_date >= current_date - 30) {
return promise.set_value(Unit());
}
if (max_date >= current_date - 30) {
max_date = current_date - 31;
}
CHECK(min_date <= max_date);
AffectedHistoryQuery query = [td = td_, saved_messages_topic_id, min_date, max_date](
DialogId, Promise<AffectedHistory> &&query_promise) {
td->create_handler<DeleteSavedMessagesByDateQuery>(std::move(query_promise))
->send(saved_messages_topic_id, min_date, max_date);
};
run_affected_history_query_until_complete(my_dialog_id, std::move(query), true, std::move(promise));
}
vector<DialogId> MessagesManager::search_public_dialogs(const string &query, Promise<Unit> &&promise) {
LOG(INFO) << "Search public chats with query = \"" << query << '"';

View File

@ -546,6 +546,9 @@ class MessagesManager final : public Actor {
void get_saved_messages_topic_message_by_date(SavedMessagesTopicId saved_messages_topic_id, int32 date,
Promise<td_api::object_ptr<td_api::message>> &&promise);
void delete_saved_messages_topic_messages_by_date(SavedMessagesTopicId saved_messages_topic_id, int32 min_date,
int32 max_date, Promise<Unit> &&promise);
vector<DialogId> search_public_dialogs(const string &query, Promise<Unit> &&promise);
std::pair<int32, vector<DialogId>> search_dialogs(const string &query, int32 limit, Promise<Unit> &&promise);

View File

@ -5042,6 +5042,13 @@ void Td::on_request(uint64 id, const td_api::getSavedMessagesTopicHistory &reque
request.limit_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getSavedMessagesTopicMessageByDate &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
messages_manager_->get_saved_messages_topic_message_by_date(SavedMessagesTopicId(this, request.saved_messages_topic_),
request.date_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::deleteSavedMessagesTopicHistory &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
@ -5049,11 +5056,12 @@ void Td::on_request(uint64 id, const td_api::deleteSavedMessagesTopicHistory &re
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getSavedMessagesTopicMessageByDate &request) {
void Td::on_request(uint64 id, const td_api::deleteSavedMessagesTopicMessagesByDate &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
messages_manager_->get_saved_messages_topic_message_by_date(SavedMessagesTopicId(this, request.saved_messages_topic_),
request.date_, std::move(promise));
CREATE_OK_REQUEST_PROMISE();
messages_manager_->delete_saved_messages_topic_messages_by_date(
SavedMessagesTopicId(this, request.saved_messages_topic_), request.min_date_, request.max_date_,
std::move(promise));
}
void Td::on_request(uint64 id, td_api::searchPublicChat &request) {

View File

@ -677,9 +677,11 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getSavedMessagesTopicHistory &request);
void on_request(uint64 id, const td_api::getSavedMessagesTopicMessageByDate &request);
void on_request(uint64 id, const td_api::deleteSavedMessagesTopicHistory &request);
void on_request(uint64 id, const td_api::getSavedMessagesTopicMessageByDate &request);
void on_request(uint64 id, const td_api::deleteSavedMessagesTopicMessagesByDate &request);
void on_request(uint64 id, td_api::searchPublicChat &request);

View File

@ -2764,11 +2764,17 @@ class CliClient final : public Actor {
get_args(args, from_message_id, offset, limit);
send_request(td_api::make_object<td_api::getSavedMessagesTopicHistory>(get_saved_messages_topic(),
from_message_id, offset, as_limit(limit)));
} else if (op == "dsmth" && args.empty()) {
send_request(td_api::make_object<td_api::deleteSavedMessagesTopicHistory>(get_saved_messages_topic()));
} else if (op == "gsmtmbd") {
send_request(td_api::make_object<td_api::getSavedMessagesTopicMessageByDate>(get_saved_messages_topic(),
to_integer<int32>(args)));
} else if (op == "dsmth" && args.empty()) {
send_request(td_api::make_object<td_api::deleteSavedMessagesTopicHistory>(get_saved_messages_topic()));
} else if (op == "dsmtmbd") {
int32 min_date;
int32 max_date;
get_args(args, min_date, max_date);
send_request(td_api::make_object<td_api::deleteSavedMessagesTopicMessagesByDate>(get_saved_messages_topic(),
min_date, max_date));
} else if (op == "gcc" || op == "GetCommonChats") {
UserId user_id;
ChatId offset_chat_id;