From b5036975b8366181a229a56557e3f7fadc3f2467 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 2 Mar 2018 19:21:43 +0300 Subject: [PATCH] Allow to specify message_ids in td_api::reportSpam. GitOrigin-RevId: c77dcd89e58c38ac218204230620513c2cdda60d --- CMakeLists.txt | 2 +- README.md | 2 +- example/cpp/CMakeLists.txt | 2 +- example/uwp/extension.vsixmanifest | 2 +- td/generate/scheme/td_api.tl | 4 ++-- td/generate/scheme/td_api.tlo | Bin 111992 -> 112048 bytes td/telegram/MessagesManager.cpp | 27 +++++++++++++++++---- td/telegram/MessagesManager.h | 2 +- td/telegram/Td.cpp | 12 ++++++---- td/telegram/Td.h | 2 +- td/telegram/cli.cpp | 37 ++++++++++++++++------------- 11 files changed, 58 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fde8c4aef..a66c4adb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR) -project(TDLib VERSION 1.1.3 LANGUAGES CXX C) +project(TDLib VERSION 1.1.4 LANGUAGES CXX C) option(TD_ENABLE_JNI "Use \"ON\" to enable JNI-compatible TDLib API.") option(TD_ENABLE_DOTNET "Use \"ON\" to enable generation of C++/CLI or C++/CX TDLib API bindings.") diff --git a/README.md b/README.md index 5231ec048..719d80027 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ target_link_libraries(YourTarget PRIVATE Td::TdStatic) Or you could install `TDLib` and then reference it in your CMakeLists.txt like this: ``` -find_package(Td 1.1.3 REQUIRED) +find_package(Td 1.1.4 REQUIRED) target_link_libraries(YourTarget PRIVATE Td::TdStatic) ``` See [example/cpp/CMakeLists.txt](https://github.com/tdlib/td/tree/master/example/cpp/CMakeLists.txt). diff --git a/example/cpp/CMakeLists.txt b/example/cpp/CMakeLists.txt index 36aff073a..26e5bae9b 100644 --- a/example/cpp/CMakeLists.txt +++ b/example/cpp/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR) project(TdExample VERSION 1.0 LANGUAGES CXX) -find_package(Td 1.1.3 REQUIRED) +find_package(Td 1.1.4 REQUIRED) add_executable(tdjson_example tdjson_example.cpp) target_link_libraries(tdjson_example PRIVATE Td::TdJson) diff --git a/example/uwp/extension.vsixmanifest b/example/uwp/extension.vsixmanifest index eb95ad712..0d7a62f7d 100644 --- a/example/uwp/extension.vsixmanifest +++ b/example/uwp/extension.vsixmanifest @@ -1,6 +1,6 @@ - + TDLib for Universal Windows Platform TDLib is a library for building Telegram clients https://core.telegram.org/tdlib diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index f90d17e21..8893471f1 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2758,8 +2758,8 @@ getChatReportSpamState chat_id:int53 = ChatReportSpamState; //@description Used to let the server know whether a chat is spam or not. Can be used only if ChatReportSpamState.can_report_spam is true. After this request, ChatReportSpamState.can_report_spam becomes false forever @chat_id Chat identifier @is_spam_chat If true, the chat will be reported as spam; otherwise it will be marked as not spam changeChatReportSpamState chat_id:int53 is_spam_chat:Bool = Ok; -//@description Reports a chat to the Telegram moderators. Supported only for supergroups, channels, or private chats with bots, since other chats can't be checked by moderators @chat_id Chat identifier @reason The reason for reporting the chat -reportChat chat_id:int53 reason:ChatReportReason = Ok; +//@description Reports a chat to the Telegram moderators. Supported only for supergroups, channels, or private chats with bots, 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 +reportChat chat_id:int53 reason:ChatReportReason message_ids:vector = Ok; //@description Returns storage usage statistics @chat_limit Maximum number of chats with the largest storage usage for which separate statistics should be returned. All other chats will be grouped in entries with chat_id == 0. If the chat info database is not used, the chat_limit is ignored and is always set to 0 diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 0f30a701bcc383841953b07e6e880cb124ce663a..fa28816c4030f8441b423deed48ba8ea4e45d208 100644 GIT binary patch delta 64 zcmezIifzMdwuUW?U)%UHfF1yDsTijK delta 42 ycmdn+n(fCcwuUW?U)%UZera &&promise) : promise_(std::move(promise)) { } - void send(DialogId dialog_id, tl_object_ptr &&report_reason) { + void send(DialogId dialog_id, tl_object_ptr &&report_reason, + const vector &message_ids) { 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( - create_storer(telegram_api::account_reportPeer(std::move(input_peer), std::move(report_reason))))); + if (message_ids.empty()) { + send_query(G()->net_query_creator().create( + create_storer(telegram_api::account_reportPeer(std::move(input_peer), std::move(report_reason))))); + } else { + send_query(G()->net_query_creator().create(create_storer(telegram_api::messages_report( + std::move(input_peer), MessagesManager::get_server_message_ids(message_ids), std::move(report_reason))))); + } } void on_result(uint64 id, BufferSlice packet) override { + static_assert( + std::is_same::value, + ""); auto result_ptr = fetch_result(packet); if (result_ptr.is_error()) { return on_error(id, result_ptr.move_as_error()); @@ -6060,7 +6069,7 @@ void MessagesManager::change_dialog_report_spam_state(DialogId dialog_id, bool i } void MessagesManager::report_dialog(DialogId dialog_id, const tl_object_ptr &reason, - Promise &&promise) { + const vector &message_ids, Promise &&promise) { Dialog *d = get_dialog_force(dialog_id); if (d == nullptr) { return promise.set_error(Status::Error(3, "Chat not found")); @@ -6093,6 +6102,13 @@ void MessagesManager::report_dialog(DialogId dialog_id, const tl_object_ptr server_message_ids; + for (auto message_id : message_ids) { + if (message_id.is_valid() && message_id.is_server()) { + server_message_ids.push_back(message_id); + } + } + tl_object_ptr report_reason; switch (reason->get_id()) { case td_api::chatReportReasonSpam::ID: @@ -6119,7 +6135,8 @@ void MessagesManager::report_dialog(DialogId dialog_id, const tl_object_ptrcreate_handler(std::move(promise))->send(dialog_id, std::move(report_reason)); + td_->create_handler(std::move(promise)) + ->send(dialog_id, std::move(report_reason), server_message_ids); } void MessagesManager::on_get_peer_settings(DialogId dialog_id, diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 7bd6cc36e..d45861dcf 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1268,7 +1268,7 @@ class MessagesManager : public Actor { void change_dialog_report_spam_state(DialogId dialog_id, bool is_spam_dialog, Promise &&promise); void report_dialog(DialogId dialog_id, const tl_object_ptr &reason, - Promise &&promise); + const vector &message_ids, Promise &&promise); void on_get_peer_settings(DialogId dialog_id, tl_object_ptr &&peer_settings); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 6a1f1cc44..1bc6c4c73 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -2707,15 +2707,19 @@ class ChangeChatReportSpamStateRequest : public RequestOnceActor { class ReportChatRequest : public RequestOnceActor { DialogId dialog_id_; tl_object_ptr reason_; + vector message_ids_; void do_run(Promise &&promise) override { - td->messages_manager_->report_dialog(dialog_id_, reason_, std::move(promise)); + td->messages_manager_->report_dialog(dialog_id_, reason_, message_ids_, std::move(promise)); } public: ReportChatRequest(ActorShared td, uint64 request_id, int64 dialog_id, - tl_object_ptr reason) - : RequestOnceActor(std::move(td), request_id), dialog_id_(dialog_id), reason_(std::move(reason)) { + tl_object_ptr reason, const vector &message_ids) + : RequestOnceActor(std::move(td), request_id) + , dialog_id_(dialog_id) + , reason_(std::move(reason)) + , message_ids_(MessagesManager::get_message_ids(message_ids)) { } }; @@ -6353,7 +6357,7 @@ void Td::on_request(uint64 id, const td_api::changeChatReportSpamState &request) void Td::on_request(uint64 id, td_api::reportChat &request) { CHECK_AUTH(); CHECK_IS_USER(); - CREATE_REQUEST(ReportChatRequest, request.chat_id_, std::move(request.reason_)); + CREATE_REQUEST(ReportChatRequest, request.chat_id_, std::move(request.reason_), request.message_ids_); } void Td::on_request(uint64 id, td_api::setNotificationSettings &request) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 9cdcfe83e..f1b7386e0 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -192,7 +192,7 @@ class Td final : public NetQueryCallback { static td_api::object_ptr static_request(td_api::object_ptr function); private: - static constexpr const char *tdlib_version = "1.1.3"; + static constexpr const char *tdlib_version = "1.1.4"; static constexpr int64 ONLINE_ALARM_ID = 0; static constexpr int32 ONLINE_TIMEOUT = 240; static constexpr int64 PING_SERVER_ALARM_ID = -1; diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index fb7a66e4c..7382fbffa 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -404,8 +404,8 @@ class CliClient final : public Actor { return to_integer(str); } - static vector as_message_ids(Slice message_ids_string, char delimiter = ' ') { - return transform(full_split(message_ids_string, delimiter), as_message_id); + static vector as_message_ids(Slice message_ids, char delimiter = ' ') { + return transform(full_split(message_ids, delimiter), as_message_id); } int32 as_user_id(Slice str) const { @@ -1899,23 +1899,23 @@ class CliClient final : public Actor { send_request(make_tl_object(as_file_id(file_id))); } else if (op == "dm") { string chat_id; - string message_ids_string; + string message_ids; string revoke; std::tie(chat_id, args) = split(args); - std::tie(message_ids_string, revoke) = split(args); + std::tie(message_ids, revoke) = split(args); - send_request(make_tl_object(as_chat_id(chat_id), as_message_ids(message_ids_string, ','), + send_request(make_tl_object(as_chat_id(chat_id), as_message_ids(message_ids, ','), as_bool(revoke))); } else if (op == "fm" || op == "fmg") { string chat_id; string from_chat_id; - string message_ids_string; + string message_ids; std::tie(chat_id, args) = split(args); - std::tie(from_chat_id, message_ids_string) = split(args); + std::tie(from_chat_id, message_ids) = split(args); auto chat = as_chat_id(chat_id); - send_request(make_tl_object( - chat, as_chat_id(from_chat_id), as_message_ids(message_ids_string), false, false, op == "fmg")); + send_request(make_tl_object(chat, as_chat_id(from_chat_id), as_message_ids(message_ids), + false, false, op == "fmg")); } else if (op == "csc" || op == "CreateSecretChat") { send_request(make_tl_object(to_integer(args))); } else if (op == "cnsc" || op == "CreateNewSecretChat") { @@ -2728,10 +2728,10 @@ class CliClient final : public Actor { send_request(make_tl_object(hashtag)); } else if (op == "view") { string chat_id; - string message_ids_string; - std::tie(chat_id, message_ids_string) = split(args); + string message_ids; + std::tie(chat_id, message_ids) = split(args); - send_request(make_tl_object(as_chat_id(chat_id), as_message_ids(message_ids_string), true)); + send_request(make_tl_object(as_chat_id(chat_id), as_message_ids(message_ids), true)); } else if (op == "omc") { string chat_id; string message_id; @@ -2774,7 +2774,9 @@ class CliClient final : public Actor { } else if (op == "rc") { string chat_id; string reason_str; - std::tie(chat_id, reason_str) = split(args); + string message_ids; + std::tie(chat_id, args) = split(args); + std::tie(reason_str, message_ids) = split(args); tl_object_ptr reason; if (reason_str == "spam") { @@ -2787,16 +2789,17 @@ class CliClient final : public Actor { reason = make_tl_object(reason_str); } - send_request(make_tl_object(as_chat_id(chat_id), std::move(reason))); + send_request( + make_tl_object(as_chat_id(chat_id), std::move(reason), as_message_ids(message_ids))); } else if (op == "rsgs" || op == "rchs") { string supergroup_id; string user_id; - string message_ids_string; + string message_ids; std::tie(supergroup_id, args) = split(args); - std::tie(user_id, message_ids_string) = split(args); + std::tie(user_id, message_ids) = split(args); send_request(make_tl_object(to_integer(supergroup_id), as_user_id(user_id), - as_message_ids(message_ids_string))); + as_message_ids(message_ids))); } else if (op == "gdiff") { send_request(make_tl_object()); } else if (op == "cproxy") {