Add td_api::reportStory.

This commit is contained in:
levlam 2023-06-21 23:23:19 +03:00
parent 0ac33fa9c0
commit 26c8c0f4fa
8 changed files with 80 additions and 3 deletions

View File

@ -7280,7 +7280,7 @@ getArchivedStories from_story_id:int32 limit:int32 = Stories;
openStory story_sender_user_id:int53 story_id:int32 = Ok;
//@description Informs TDLib that a story is closed by the user
//@story_sender_user_id The identifier of the sender of the closed story
//@story_sender_user_id The identifier of the sender of the story to close
//@story_id The identifier of the story
closeStory story_sender_user_id:int53 story_id:int32 = Ok;
@ -7292,6 +7292,13 @@ closeStory story_sender_user_id:int53 story_id:int32 = Ok;
//-For optimal performance, the number of returned stories is chosen by TDLib and can be smaller than the specified limit
getStoryViewers story_id:int32 offset_viewer:messageViewer limit:int32 = MessageViewers;
//@description Reports a story to the Telegram moderators
//@story_sender_user_id The identifier of the sender of the story to report
//@story_id The identifier of the story to report
//@reason The reason for reporting the story
//@text Additional report details; 0-1024 characters
reportStory story_sender_user_id:int53 story_id:int32 reason:ChatReportReason text:string = Ok;
//@description Returns information about a bot that can be added to attachment menu @bot_user_id Bot's user identifier
getAttachmentMenuBot bot_user_id:int53 = AttachmentMenuBot;

View File

@ -57,6 +57,7 @@
#include "td/telegram/PublicDialogType.h"
#include "td/telegram/ReplyMarkup.h"
#include "td/telegram/ReplyMarkup.hpp"
#include "td/telegram/ReportReason.h"
#include "td/telegram/SecretChatsManager.h"
#include "td/telegram/SponsoredMessageManager.h"
#include "td/telegram/StickerPhotoSize.h"
@ -4371,7 +4372,6 @@ class ReportPeerQuery final : public Td::ResultHandler {
}
void on_error(Status status) final {
LOG(INFO) << "Receive error for report peer: " << status;
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "ReportPeerQuery");
td_->messages_manager_->reget_dialog_action_bar(dialog_id_, "ReportPeerQuery");
promise_.set_error(std::move(status));

View File

@ -56,7 +56,6 @@
#include "td/telegram/Photo.h"
#include "td/telegram/RecentDialogList.h"
#include "td/telegram/ReplyMarkup.h"
#include "td/telegram/ReportReason.h"
#include "td/telegram/RestrictionReason.h"
#include "td/telegram/ScheduledServerMessageId.h"
#include "td/telegram/secret_api.h"
@ -110,6 +109,7 @@ class DraftMessage;
struct InputMessageContent;
class MessageContent;
struct MessageReactions;
class ReportReason;
class Td;
class MessagesManager final : public Actor {

View File

@ -17,6 +17,7 @@
#include "td/telegram/MessageEntity.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/OptionManager.h"
#include "td/telegram/ReportReason.h"
#include "td/telegram/StoryContent.h"
#include "td/telegram/StoryContentType.h"
#include "td/telegram/Td.h"
@ -433,6 +434,43 @@ class GetStoriesViewsQuery final : public Td::ResultHandler {
}
};
class ReportStoryQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
DialogId dialog_id_;
public:
explicit ReportStoryQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(StoryFullId story_full_id, ReportReason &&report_reason) {
dialog_id_ = story_full_id.get_dialog_id();
CHECK(dialog_id_.get_type() == DialogType::User);
auto r_input_user = td_->contacts_manager_->get_input_user(dialog_id_.get_user_id());
if (r_input_user.is_error()) {
return on_error(r_input_user.move_as_error());
}
send_query(G()->net_query_creator().create(
telegram_api::stories_report(r_input_user.move_as_ok(), {story_full_id.get_story_id().get()},
report_reason.get_input_report_reason(), report_reason.get_message())));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::stories_report>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
promise_.set_value(Unit());
}
void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "ReportStoryQuery");
promise_.set_error(std::move(status));
}
};
class StoryManager::SendStoryQuery final : public Td::ResultHandler {
FileId file_id_;
unique_ptr<PendingStory> pending_story_;
@ -1183,6 +1221,14 @@ void StoryManager::on_get_story_viewers(
promise.set_value(story_viewers.get_message_viewers_object(td_->contacts_manager_.get()));
}
void StoryManager::report_story(StoryFullId story_full_id, ReportReason &&reason, Promise<Unit> &&promise) {
if (!have_story(story_full_id)) {
return promise.set_error(Status::Error(400, "Story not found"));
}
td_->create_handler<ReportStoryQuery>(std::move(promise))->send(story_full_id, std::move(reason));
}
bool StoryManager::have_story(StoryFullId story_full_id) const {
return get_story(story_full_id) != nullptr;
}

View File

@ -34,6 +34,7 @@
namespace td {
struct BinlogEvent;
class ReportReason;
class StoryContent;
class Td;
@ -132,6 +133,8 @@ class StoryManager final : public Actor {
void get_story_viewers(StoryId story_id, const td_api::messageViewer *offset, int32 limit,
Promise<td_api::object_ptr<td_api::messageViewers>> &&promise);
void report_story(StoryFullId story_full_id, ReportReason &&reason, Promise<Unit> &&promise);
StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr<telegram_api::StoryItem> &&story_item_ptr);
std::pair<int32, vector<StoryId>> on_get_stories(DialogId owner_dialog_id, vector<StoryId> &&expected_story_ids,

View File

@ -6464,6 +6464,17 @@ void Td::on_request(uint64 id, const td_api::getStoryViewers &request) {
std::move(promise));
}
void Td::on_request(uint64 id, td_api::reportStory &request) {
CHECK_IS_USER();
auto r_report_reason = ReportReason::get_report_reason(std::move(request.reason_), std::move(request.text_));
if (r_report_reason.is_error()) {
return send_error_raw(id, r_report_reason.error().code(), r_report_reason.error().message());
}
CREATE_OK_REQUEST_PROMISE();
story_manager_->report_story({DialogId(UserId(request.story_sender_user_id_)), StoryId(request.story_id_)},
r_report_reason.move_as_ok(), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getAttachmentMenuBot &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();

View File

@ -1012,6 +1012,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getStoryViewers &request);
void on_request(uint64 id, td_api::reportStory &request);
void on_request(uint64 id, const td_api::getAttachmentMenuBot &request);
void on_request(uint64 id, const td_api::toggleBotIsAddedToAttachmentMenu &request);

View File

@ -4076,6 +4076,14 @@ class CliClient final : public Actor {
get_args(args, story_id, limit, offset_date, offset_user_id);
send_request(td_api::make_object<td_api::getStoryViewers>(
story_id, td_api::make_object<td_api::messageViewer>(offset_user_id, offset_date), as_limit(limit)));
} else if (op == "rst") {
UserId story_sender_user_id;
StoryId story_id;
string reason;
string text;
get_args(args, story_sender_user_id, story_id, reason, text);
send_request(td_api::make_object<td_api::reportStory>(story_sender_user_id, story_id,
as_chat_report_reason(reason), text));
} else if (op == "gamb") {
UserId user_id;
get_args(args, user_id);