Add td_api::reportChatPhoto.

This commit is contained in:
levlam 2021-02-19 19:11:27 +03:00
parent 2e943a6c85
commit 3774b13ca1
8 changed files with 154 additions and 24 deletions

View File

@ -377,7 +377,7 @@ chatPhotos total_count:int32 photos:vector<chatPhoto> = ChatPhotos;
//@class InputChatPhoto @description Describes a photo to be set as a user profile or chat photo
//@description A previously used profile photo of the current user @chat_photo_id Identifier of the profile photo to reuse
//@description A previously used profile photo of the current user @chat_photo_id Identifier of the current user's profile photo to reuse
inputChatPhotoPrevious chat_photo_id:int64 = InputChatPhoto;
//@description A static photo in JPEG format @photo Photo to be set as profile photo. Only inputFileLocal and inputFileGenerated are allowed
@ -904,7 +904,7 @@ chatPosition list:ChatList order:int64 is_pinned:Bool source:ChatSource = ChatPo
//@has_scheduled_messages True, if the chat has scheduled messages
//@can_be_deleted_only_for_self True, if the chat messages can be deleted only for the current user while other users will continue to see the messages
//@can_be_deleted_for_all_users True, if the chat messages can be deleted for all users
//@can_be_reported True, if the chat can be reported to Telegram moderators through reportChat
//@can_be_reported True, if the chat can be reported to Telegram moderators through reportChat or reportChatPhoto
//@default_disable_notification Default value of the disable_notification parameter, used when a message is sent to the chat
//@unread_count Number of unread messages in the chat
//@last_read_inbox_message_id Identifier of the last read incoming message
@ -4932,9 +4932,12 @@ deleteAccount reason:string = Ok;
removeChatActionBar chat_id:int53 = Ok;
//@description Reports a chat to the Telegram moderators. A chat can be reported only from the chat action bar, or if this is a private chat with a bot, a private chat with a user sharing their location, a supergroup, or a channel, since other chats can't be checked by moderators
//@chat_id Chat identifier @reason The reason for reporting the chat @message_ids Identifiers of reported messages, if any @text Additional report details; 0-1024 characters
reportChat chat_id:int53 reason:ChatReportReason message_ids:vector<int53> text:string = Ok;
//@chat_id Chat identifier @message_ids Identifiers of reported messages, if any @reason The reason for reporting the chat @text Additional report details; 0-1024 characters
reportChat chat_id:int53 message_ids:vector<int53> reason:ChatReportReason text:string = Ok;
//@description Reports a chat photo to the Telegram moderators. A chat photo can be reported only if this is a private chat with a bot, a private chat with a user sharing their location, a supergroup, or a channel, since other chats can't be checked by moderators
//@chat_id Chat identifier @file_id Identifier of the photo to report. Only full photos from chatPhoto can be reported @reason The reason for reporting the chat photo @text Additional report details; 0-1024 characters
reportChatPhoto chat_id:int53 file_id:int32 reason:ChatReportReason text:string = Ok;
//@description Returns an HTTP URL with the chat statistics. Currently this method of getting the statistics are disabled and can be deleted in the future @chat_id Chat identifier @parameters Parameters from "tg://statsrefresh?params=******" link @is_dark Pass true if a URL with the dark theme must be returned
getChatStatisticsUrl chat_id:int53 parameters:string is_dark:Bool = HttpUrl;

Binary file not shown.

View File

@ -9883,10 +9883,8 @@ void ContactsManager::on_get_user_full(tl_object_ptr<telegram_api::userFull> &&u
register_user_photo(u, user_id, user->photo);
}
if (user_full->bot_info_ != nullptr) {
if (on_update_bot_info(std::move(user_full->bot_info_), false)) {
user->need_send_update = true;
}
if (user_full->bot_info_ != nullptr && on_update_bot_info(std::move(user_full->bot_info_), false)) {
user->need_send_update = true;
}
update_user_full(user, user_id);

View File

@ -4388,8 +4388,8 @@ class ReportPeerQuery : public Td::ResultHandler {
explicit ReportPeerQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, tl_object_ptr<telegram_api::ReportReason> &&report_reason,
const vector<MessageId> &message_ids, const string &message) {
void send(DialogId dialog_id, const vector<MessageId> &message_ids,
tl_object_ptr<telegram_api::ReportReason> &&report_reason, const string &message) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
@ -4430,6 +4430,47 @@ class ReportPeerQuery : public Td::ResultHandler {
}
};
class ReportProfilePhotoQuery : public Td::ResultHandler {
Promise<Unit> promise_;
DialogId dialog_id_;
public:
explicit ReportProfilePhotoQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, tl_object_ptr<telegram_api::InputPhoto> &&input_photo,
tl_object_ptr<telegram_api::ReportReason> &&report_reason, const string &message) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
CHECK(input_peer != nullptr);
send_query(G()->net_query_creator().create(telegram_api::account_reportProfilePhoto(
std::move(input_peer), std::move(input_photo), std::move(report_reason), message)));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::account_reportProfilePhoto>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
bool result = result_ptr.ok();
if (!result) {
return on_error(id, Status::Error(400, "Receive false as result"));
}
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) override {
LOG(INFO) << "Receive error for report chat photo: " << status;
// TODO support FILE_REFERENCE errors
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "ReportProfilePhotoQuery");
promise_.set_error(std::move(status));
}
};
class EditPeerFoldersQuery : public Td::ResultHandler {
Promise<Unit> promise_;
DialogId dialog_id_;
@ -8168,8 +8209,8 @@ bool MessagesManager::can_report_dialog(DialogId dialog_id) const {
}
}
void MessagesManager::report_dialog(DialogId dialog_id, const tl_object_ptr<td_api::ChatReportReason> &reason,
const vector<MessageId> &message_ids, const string &message,
void MessagesManager::report_dialog(DialogId dialog_id, const vector<MessageId> &message_ids,
const tl_object_ptr<td_api::ChatReportReason> &reason, const string &message,
Promise<Unit> &&promise) {
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
@ -8261,7 +8302,74 @@ void MessagesManager::report_dialog(DialogId dialog_id, const tl_object_ptr<td_a
CHECK(report_reason != nullptr);
td_->create_handler<ReportPeerQuery>(std::move(promise))
->send(dialog_id, std::move(report_reason), server_message_ids, message);
->send(dialog_id, server_message_ids, std::move(report_reason), message);
}
void MessagesManager::report_dialog_photo(DialogId dialog_id, FileId file_id,
const tl_object_ptr<td_api::ChatReportReason> &reason, const string &message,
Promise<Unit> &&promise) {
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
return promise.set_error(Status::Error(3, "Chat not found"));
}
if (!have_input_peer(dialog_id, AccessRights::Read)) {
return promise.set_error(Status::Error(3, "Can't access the chat"));
}
if (reason == nullptr) {
return promise.set_error(Status::Error(3, "Reason must be non-empty"));
}
if (!can_report_dialog(dialog_id)) {
return promise.set_error(Status::Error(3, "Chat photo can't be reported"));
}
auto file_view = td_->file_manager_->get_file_view(file_id);
if (file_view.empty()) {
return promise.set_error(Status::Error(400, "Unknown file ID"));
}
if (file_view.get_type() != FileType::Photo || !file_view.has_remote_location() ||
!file_view.remote_location().is_photo()) {
return promise.set_error(Status::Error(400, "Only full chat photos can be reported"));
}
tl_object_ptr<telegram_api::ReportReason> report_reason;
switch (reason->get_id()) {
case td_api::chatReportReasonSpam::ID:
report_reason = make_tl_object<telegram_api::inputReportReasonSpam>();
break;
case td_api::chatReportReasonViolence::ID:
report_reason = make_tl_object<telegram_api::inputReportReasonViolence>();
break;
case td_api::chatReportReasonPornography::ID:
report_reason = make_tl_object<telegram_api::inputReportReasonPornography>();
break;
case td_api::chatReportReasonChildAbuse::ID:
report_reason = make_tl_object<telegram_api::inputReportReasonChildAbuse>();
break;
case td_api::chatReportReasonCopyright::ID:
report_reason = make_tl_object<telegram_api::inputReportReasonCopyright>();
break;
case td_api::chatReportReasonFake::ID:
report_reason = make_tl_object<telegram_api::inputReportReasonFake>();
break;
case td_api::chatReportReasonUnrelatedLocation::ID:
report_reason = make_tl_object<telegram_api::inputReportReasonGeoIrrelevant>();
if (dialog_id.get_type() == DialogType::Channel) {
hide_dialog_action_bar(d);
}
break;
case td_api::chatReportReasonCustom::ID:
report_reason = make_tl_object<telegram_api::inputReportReasonOther>();
break;
default:
UNREACHABLE();
}
CHECK(report_reason != nullptr);
td_->create_handler<ReportProfilePhotoQuery>(std::move(promise))
->send(dialog_id, file_view.remote_location().as_input_photo(), std::move(report_reason), message);
}
void MessagesManager::on_get_peer_settings(DialogId dialog_id,

View File

@ -775,8 +775,12 @@ class MessagesManager : public Actor {
void reget_dialog_action_bar(DialogId dialog_id, const char *source);
void report_dialog(DialogId dialog_id, const tl_object_ptr<td_api::ChatReportReason> &reason,
const vector<MessageId> &message_ids, const string &message, Promise<Unit> &&promise);
void report_dialog(DialogId dialog_id, const vector<MessageId> &message_ids,
const tl_object_ptr<td_api::ChatReportReason> &reason, const string &message,
Promise<Unit> &&promise);
void report_dialog_photo(DialogId dialog_id, FileId file_id, const tl_object_ptr<td_api::ChatReportReason> &reason,
const string &message, Promise<Unit> &&promise);
void on_get_peer_settings(DialogId dialog_id, tl_object_ptr<telegram_api::peerSettings> &&peer_settings,
bool ignore_privacy_exception = false);

View File

@ -6973,9 +6973,16 @@ void Td::on_request(uint64 id, td_api::reportChat &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.text_);
CREATE_OK_REQUEST_PROMISE();
messages_manager_->report_dialog(DialogId(request.chat_id_), request.reason_,
MessagesManager::get_message_ids(request.message_ids_), request.text_,
std::move(promise));
messages_manager_->report_dialog(DialogId(request.chat_id_), MessagesManager::get_message_ids(request.message_ids_),
request.reason_, request.text_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::reportChatPhoto &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.text_);
CREATE_OK_REQUEST_PROMISE();
messages_manager_->report_dialog_photo(DialogId(request.chat_id_), FileId(request.file_id_, 0), request.reason_,
request.text_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::getChatStatisticsUrl &request) {

View File

@ -978,6 +978,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::reportChat &request);
void on_request(uint64 id, td_api::reportChatPhoto &request);
void on_request(uint64 id, td_api::getChatStatisticsUrl &request);
void on_request(uint64 id, const td_api::getChatStatistics &request);

View File

@ -2267,7 +2267,7 @@ class CliClient final : public Actor {
} else if (op == "gatss") {
send_request(td_api::make_object<td_api::getAttachedStickerSets>(as_file_id(args)));
} else if (op == "storage") {
send_request(td_api::make_object<td_api::getStorageStatistics>(as_limit(args)));
send_request(td_api::make_object<td_api::getStorageStatistics>(to_integer<int32>(args)));
} else if (op == "storage_fast") {
send_request(td_api::make_object<td_api::getStorageStatisticsFast>());
} else if (op == "database") {
@ -2544,7 +2544,7 @@ class CliClient final : public Actor {
int32 max_file_id = as_file_id(file_id);
int32 min_file_id = (op == "dff" ? 1 : max_file_id);
for (int32 i = min_file_id; i <= max_file_id; i++) {
send_request(td_api::make_object<td_api::downloadFile>(i, priority, offset, as_limit(limit), op == "dfs"));
send_request(td_api::make_object<td_api::downloadFile>(i, priority, offset, to_integer<int32>(limit), op == "dfs"));
}
} else if (op == "cdf") {
send_request(td_api::make_object<td_api::cancelDownloadFile>(as_file_id(args), false));
@ -3907,12 +3907,20 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::removeChatActionBar>(as_chat_id(chat_id)));
} else if (op == "rc") {
string chat_id;
string reason;
string message_ids;
string reason;
string text;
get_args(args, chat_id, reason, message_ids, text);
send_request(td_api::make_object<td_api::reportChat>(as_chat_id(chat_id), get_chat_report_reason(reason),
as_message_ids(message_ids), text));
get_args(args, chat_id, message_ids, reason, text);
send_request(td_api::make_object<td_api::reportChat>(as_chat_id(chat_id), as_message_ids(message_ids),
get_chat_report_reason(reason), text));
} else if (op == "rcp") {
string chat_id;
string file_id;
string reason;
string text;
get_args(args, chat_id, file_id, reason, text);
send_request(td_api::make_object<td_api::reportChatPhoto>(as_chat_id(chat_id), as_file_id(file_id),
get_chat_report_reason(reason), text));
} else if (op == "gcsu") {
string chat_id;
string parameters;