Replace deleteSupergroup with universal deleteChat method.

This commit is contained in:
levlam 2021-01-20 14:49:18 +03:00
parent c7e4abb0a5
commit dbf1253075
13 changed files with 75 additions and 35 deletions

View File

@ -3821,6 +3821,9 @@ getMessageThreadHistory chat_id:int53 message_id:int53 from_message_id:int53 off
//@chat_id Chat identifier @remove_from_chat_list Pass true if the chat should be removed from the chat list @revoke Pass true to try to delete chat history for all users
deleteChatHistory chat_id:int53 remove_from_chat_list:Bool revoke:Bool = Ok;
//@description Deletes a chat along with all messages in the corresponding chat for all chat members; requires owner privileges. For group chats this will release the username and remove all members. Chats with more than 1000 members can't be deleted using this method @chat_id Chat identifier
deleteChat chat_id:int53 = Ok;
//@description Searches for messages with given words in the chat. Returns the results in reverse chronological order, i.e. in order of decreasing message_id. Cannot be used in secret chats with a non-empty query
//-(searchSecretMessages should be used instead), or without an enabled message database. For optimal performance the number of returned messages is chosen by the library
//@chat_id Identifier of the chat in which to search messages
@ -4695,9 +4698,6 @@ reportSupergroupSpam supergroup_id:int32 user_id:int32 message_ids:vector<int53>
//@filter The type of users to return. By default, supergroupMembersFilterRecent @offset Number of users to skip @limit The maximum number of users be returned; up to 200
getSupergroupMembers supergroup_id:int32 filter:SupergroupMembersFilter offset:int32 limit:int32 = ChatMembers;
//@description Deletes a supergroup or channel along with all messages in the corresponding chat. This will release the supergroup or channel username and remove all members; requires owner privileges in the supergroup or channel. Chats with more than 1000 members can't be deleted using this method @supergroup_id Identifier of the supergroup or channel
deleteSupergroup supergroup_id:int32 = Ok;
//@description Closes a secret chat, effectively transferring its state to secretChatStateClosed @secret_chat_id Secret chat identifier
closeSecretChat secret_chat_id:int32 = Ok;

Binary file not shown.

View File

@ -34,6 +34,7 @@
#include "td/telegram/Photo.hpp"
#include "td/telegram/RestrictionReason.h"
#include "td/telegram/SecretChatActor.h"
#include "td/telegram/SecretChatsManager.h"
#include "td/telegram/ServerMessageId.h"
#include "td/telegram/StickerSetId.hpp"
#include "td/telegram/StickersManager.h"
@ -6724,6 +6725,27 @@ void ContactsManager::delete_channel(ChannelId channel_id, Promise<Unit> &&promi
td_->create_handler<DeleteChannelQuery>(std::move(promise))->send(channel_id);
}
void ContactsManager::delete_dialog(DialogId dialog_id, Promise<Unit> &&promise) {
if (!td_->messages_manager_->have_dialog_force(dialog_id)) {
return promise.set_error(Status::Error(3, "Chat not found"));
}
switch (dialog_id.get_type()) {
case DialogType::User:
return td_->messages_manager_->delete_dialog_history(dialog_id, true, true, std::move(promise));
case DialogType::Chat:
return delete_chat(dialog_id.get_chat_id(), std::move(promise));
case DialogType::Channel:
return delete_channel(dialog_id.get_channel_id(), std::move(promise));
case DialogType::SecretChat:
send_closure(td_->secret_chats_manager_, &SecretChatsManager::cancel_chat, dialog_id.get_secret_chat_id(), true,
std::move(promise));
return;
default:
UNREACHABLE();
}
}
void ContactsManager::add_chat_participant(ChatId chat_id, UserId user_id, int32 forward_limit,
Promise<Unit> &&promise) {
const Chat *c = get_chat(chat_id);

View File

@ -359,7 +359,7 @@ class ContactsManager : public Actor {
void report_channel_spam(ChannelId channel_id, UserId user_id, const vector<MessageId> &message_ids,
Promise<Unit> &&promise);
void delete_channel(ChannelId channel_id, Promise<Unit> &&promise);
void delete_dialog(DialogId dialog_id, Promise<Unit> &&promise);
void get_channel_statistics(DialogId dialog_id, bool is_dark,
Promise<td_api::object_ptr<td_api::ChatStatistics>> &&promise);
@ -379,8 +379,6 @@ class ContactsManager : public Actor {
void add_channel_participants(ChannelId channel_id, const vector<UserId> &user_ids, Promise<Unit> &&promise);
void delete_chat(ChatId chat_id, Promise<Unit> &&promise);
void change_chat_participant_status(ChatId chat_id, UserId user_id, DialogParticipantStatus status,
Promise<Unit> &&promise);
@ -1132,6 +1130,10 @@ class ContactsManager : public Actor {
tl_object_ptr<telegram_api::InputCheckPasswordSRP> input_check_password,
Promise<Unit> &&promise);
void delete_chat(ChatId chat_id, Promise<Unit> &&promise);
void delete_channel(ChannelId channel_id, Promise<Unit> &&promise);
void get_channel_statistics_dc_id(DialogId dialog_id, bool for_full_statistics, Promise<DcId> &&promise);
void get_channel_statistics_dc_id_impl(ChannelId channel_id, bool for_full_statistics, Promise<DcId> &&promise);

View File

@ -12255,9 +12255,9 @@ void MessagesManager::finish_delete_secret_messages(DialogId dialog_id, std::vec
delete_dialog_messages_from_updates(dialog_id, to_delete_message_ids, false);
}
void MessagesManager::delete_secret_chat_history(SecretChatId secret_chat_id, MessageId last_message_id,
Promise<> promise) {
LOG(DEBUG) << "On delete history in " << secret_chat_id << " up to " << last_message_id;
void MessagesManager::delete_secret_chat_history(SecretChatId secret_chat_id, bool remove_from_dialog_list,
MessageId last_message_id, Promise<> promise) {
LOG(DEBUG) << "Delete history in " << secret_chat_id << " up to " << last_message_id;
CHECK(secret_chat_id.is_valid());
CHECK(!last_message_id.is_scheduled());
@ -12273,19 +12273,20 @@ void MessagesManager::delete_secret_chat_history(SecretChatId secret_chat_id, Me
pending_secret_message->type = PendingSecretMessage::Type::DeleteHistory;
pending_secret_message->dialog_id = dialog_id;
pending_secret_message->last_message_id = last_message_id;
pending_secret_message->remove_from_dialog_list = remove_from_dialog_list;
add_secret_message(std::move(pending_secret_message));
}
void MessagesManager::finish_delete_secret_chat_history(DialogId dialog_id, MessageId last_message_id,
Promise<> promise) {
void MessagesManager::finish_delete_secret_chat_history(DialogId dialog_id, bool remove_from_dialog_list,
MessageId last_message_id, Promise<> promise) {
LOG(DEBUG) << "Delete history in " << dialog_id << " up to " << last_message_id;
promise.set_value(Unit()); // TODO: set after event is saved
Dialog *d = get_dialog(dialog_id);
CHECK(d != nullptr);
// TODO: probably last_message_id is not needed
delete_all_dialog_messages(d, false, true);
delete_all_dialog_messages(d, remove_from_dialog_list, true);
promise.set_value(Unit()); // TODO: set after event is saved
}
void MessagesManager::read_secret_chat_outbox(SecretChatId secret_chat_id, int32 up_to_date, int32 read_date) {
@ -12560,8 +12561,9 @@ void MessagesManager::finish_add_secret_message(unique_ptr<PendingSecretMessage>
std::move(pending_secret_message->success_promise));
}
if (pending_secret_message->type == PendingSecretMessage::Type::DeleteHistory) {
return finish_delete_secret_chat_history(pending_secret_message->dialog_id, pending_secret_message->last_message_id,
std::move(pending_secret_message->success_promise));
return finish_delete_secret_chat_history(
pending_secret_message->dialog_id, pending_secret_message->remove_from_dialog_list,
pending_secret_message->last_message_id, std::move(pending_secret_message->success_promise));
}
auto d = get_dialog(pending_secret_message->message_info.dialog_id);

View File

@ -234,7 +234,8 @@ class MessagesManager : public Actor {
void delete_secret_messages(SecretChatId secret_chat_id, std::vector<int64> random_ids, Promise<> promise);
void delete_secret_chat_history(SecretChatId secret_chat_id, MessageId last_message_id, Promise<> promise);
void delete_secret_chat_history(SecretChatId secret_chat_id, bool remove_from_dialog_list, MessageId last_message_id,
Promise<> promise);
void read_secret_chat_outbox(SecretChatId secret_chat_id, int32 up_to_date, int32 read_date);
@ -1574,6 +1575,7 @@ class MessagesManager : public Actor {
DialogId dialog_id;
vector<int64> random_ids;
MessageId last_message_id;
bool remove_from_dialog_list = false;
Promise<> success_promise;
};
@ -1709,7 +1711,8 @@ class MessagesManager : public Actor {
void finish_delete_secret_messages(DialogId dialog_id, std::vector<int64> random_ids, Promise<> promise);
void finish_delete_secret_chat_history(DialogId dialog_id, MessageId last_message_id, Promise<> promise);
void finish_delete_secret_chat_history(DialogId dialog_id, bool remove_from_dialog_list, MessageId last_message_id,
Promise<> promise);
MessageInfo parse_telegram_api_message(tl_object_ptr<telegram_api::Message> message_ptr, bool is_scheduled,
const char *source) const;

View File

@ -770,7 +770,7 @@ void SecretChatActor::do_close_chat_impl(bool delete_history, bool is_already_di
auto lock = mpas.get_promise();
if (delete_history) {
context_->on_flush_history(MessageId::max(), mpas.get_promise());
context_->on_flush_history(true, MessageId::max(), mpas.get_promise());
}
send_update_secret_chat();
@ -1349,7 +1349,8 @@ Status SecretChatActor::do_inbound_message_decrypted(unique_ptr<log_event::Inbou
std::move(save_message_finish));
break;
case secret_api::decryptedMessageActionFlushHistory::ID:
context_->on_flush_history(MessageId(ServerMessageId(message->message_id)), std::move(save_message_finish));
context_->on_flush_history(false, MessageId(ServerMessageId(message->message_id)),
std::move(save_message_finish));
break;
case secret_api::decryptedMessageActionReadMessages::ID: {
const auto &random_ids =

View File

@ -96,7 +96,7 @@ class SecretChatActor : public NetQueryCallback {
tl_object_ptr<telegram_api::encryptedFile> file,
tl_object_ptr<secret_api::decryptedMessage> message, Promise<> promise) = 0;
virtual void on_delete_messages(std::vector<int64> random_id, Promise<> promise) = 0;
virtual void on_flush_history(MessageId message_id, Promise<> promise) = 0;
virtual void on_flush_history(bool remove_from_dialog_list, MessageId message_id, Promise<> promise) = 0;
virtual void on_read_message(int64 random_id, Promise<> promise) = 0;
virtual void on_screenshot_taken(UserId user_id, MessageId message_id, int32 date, int64 random_id,
Promise<> promise) = 0;

View File

@ -373,9 +373,9 @@ unique_ptr<SecretChatActor::Context> SecretChatsManager::make_secret_chat_contex
send_closure(G()->messages_manager(), &MessagesManager::delete_secret_messages, secret_chat_id_,
std::move(random_ids), std::move(promise));
}
void on_flush_history(MessageId message_id, Promise<> promise) override {
send_closure(G()->messages_manager(), &MessagesManager::delete_secret_chat_history, secret_chat_id_, message_id,
std::move(promise));
void on_flush_history(bool remove_from_dialog_list, MessageId message_id, Promise<> promise) override {
send_closure(G()->messages_manager(), &MessagesManager::delete_secret_chat_history, secret_chat_id_,
remove_from_dialog_list, message_id, std::move(promise));
}
void on_read_message(int64 random_id, Promise<> promise) override {
send_closure(G()->messages_manager(), &MessagesManager::open_secret_message, secret_chat_id_, random_id,

View File

@ -5472,6 +5472,22 @@ void Td::on_request(uint64 id, const td_api::deleteChatHistory &request) {
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::deleteChat &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
DialogId dialog_id(request.chat_id_);
auto query_promise = [actor_id = messages_manager_actor_.get(), dialog_id,
promise = std::move(promise)](Result<Unit> &&result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
send_closure(actor_id, &MessagesManager::delete_dialog, dialog_id);
promise.set_value(Unit());
}
};
contacts_manager_->delete_dialog(dialog_id, std::move(query_promise));
}
void Td::on_request(uint64 id, const td_api::getMessageThreadHistory &request) {
CHECK_IS_USER();
CREATE_REQUEST(GetMessageThreadHistoryRequest, request.chat_id_, request.message_id_, request.from_message_id_,
@ -6699,12 +6715,6 @@ void Td::on_request(uint64 id, td_api::getSupergroupMembers &request) {
request.offset_, request.limit_, -1, false, std::move(query_promise));
}
void Td::on_request(uint64 id, const td_api::deleteSupergroup &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
contacts_manager_->delete_channel(ChannelId(request.supergroup_id_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::closeSecretChat &request) {
CREATE_OK_REQUEST_PROMISE();
send_closure(secret_chats_manager_, &SecretChatsManager::cancel_chat, SecretChatId(request.secret_chat_id_), false,

View File

@ -578,6 +578,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::deleteChatHistory &request);
void on_request(uint64 id, const td_api::deleteChat &request);
void on_request(uint64 id, const td_api::getMessageThreadHistory &request);
void on_request(uint64 id, td_api::searchChatMessages &request);
@ -884,8 +886,6 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::getSupergroupMembers &request);
void on_request(uint64 id, const td_api::deleteSupergroup &request);
void on_request(uint64 id, td_api::closeSecretChat &request);
void on_request(uint64 id, td_api::getStickers &request);

View File

@ -3417,8 +3417,8 @@ class CliClient final : public Actor {
td_api::make_object<td_api::chatLocation>(as_location("40.0", "60.0"), "address")));
} else if (op == "UpgradeBasicGroupChatToSupergroupChat") {
send_request(td_api::make_object<td_api::upgradeBasicGroupChatToSupergroupChat>(as_chat_id(args)));
} else if (op == "DeleteSupergroup") {
send_request(td_api::make_object<td_api::deleteSupergroup>(as_supergroup_id(args)));
} else if (op == "DeleteChat") {
send_request(td_api::make_object<td_api::deleteChat>(as_chat_id(args)));
} else if (op == "gcpc") {
send_request(td_api::make_object<td_api::getCreatedPublicChats>());
} else if (op == "gcpcl") {

View File

@ -545,7 +545,7 @@ class FakeSecretChatContext : public SecretChatActor::Context {
void on_send_message_ok(int64 random_id, MessageId message_id, int32 date,
tl_object_ptr<telegram_api::EncryptedFile> file, Promise<>) override;
void on_delete_messages(std::vector<int64> random_id, Promise<>) override;
void on_flush_history(MessageId, Promise<>) override;
void on_flush_history(bool, MessageId, Promise<>) override;
void on_read_message(int64, Promise<>) override;
void on_screenshot_taken(UserId user_id, MessageId message_id, int32 date, int64 random_id,
@ -992,7 +992,7 @@ void FakeSecretChatContext::on_send_message_ok(int64 random_id, MessageId messag
void FakeSecretChatContext::on_delete_messages(std::vector<int64> random_id, Promise<> promise) {
promise.set_value(Unit());
}
void FakeSecretChatContext::on_flush_history(MessageId, Promise<> promise) {
void FakeSecretChatContext::on_flush_history(bool, MessageId, Promise<> promise) {
promise.set_error(Status::Error("Unsupported"));
}
void FakeSecretChatContext::on_read_message(int64, Promise<> promise) {