From 8655fbe5d71d65e8bd9fee378c17b315804313a5 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 26 Dec 2023 13:47:24 +0300 Subject: [PATCH] Add getStoryInteractions.prefer_forwards. --- td/generate/scheme/td_api.tl | 11 ++++++----- td/telegram/StoryManager.cpp | 12 ++++++++---- td/telegram/StoryManager.h | 4 ++-- td/telegram/Td.cpp | 4 ++-- td/telegram/cli.cpp | 5 +++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index fd908dfb3..90f422e18 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3607,14 +3607,14 @@ storyInteractionTypeRepost story:story = StoryInteractionType; //@description Represents interaction with a story //@actor_id Identifier of the user or chat that made the interaction //@interaction_date Approximate point in time (Unix timestamp) when the interaction happenned -//@block_list Block list to which the actor is added; may be null if none +//@block_list Block list to which the actor is added; may be null if none or for chat stories //@type Type of the interaction storyInteraction actor_id:MessageSender interaction_date:int32 block_list:BlockList type:StoryInteractionType = StoryInteraction; //@description Represents a list of interactions with a story //@total_count Approximate total number of interactions found -//@total_forward_count Approximate total number of found forwards and reposts -//@total_reaction_count Approximate total number of found reactions +//@total_forward_count Approximate total number of found forwards and reposts; always 0 for chat stories +//@total_reaction_count Approximate total number of found reactions; always 0 for chat stories //@interactions List of story interactions //@next_offset The offset for the next request. If empty, then there are no more results storyInteractions total_count:int32 total_forward_count:int32 total_reaction_count:int32 interactions:vector next_offset:string = StoryInteractions; @@ -8217,10 +8217,11 @@ setStoryReaction story_sender_chat_id:int53 story_id:int32 reaction_type:Reactio //@story_id Story identifier //@query Query to search for in names, usernames and titles; may be empty to get all relevant interactions //@only_contacts Pass true to get only interactions by contacts; pass false to get all relevant interactions -//@prefer_with_reaction Pass true to get interactions with reaction first; pass false to get interactions sorted just by interaction date +//@prefer_forwards Pass true to get forwards and reposts first, then reactions, then other views; pass false to get interactions sorted just by interaction date +//@prefer_with_reaction Pass true to get interactions with reaction first; pass false to get interactions sorted just by interaction date. Ignored if prefer_forwards == true //@offset Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results //@limit The maximum number of story interactions to return -getStoryInteractions story_id:int32 query:string only_contacts:Bool prefer_with_reaction:Bool offset:string limit:int32 = StoryInteractions; +getStoryInteractions story_id:int32 query:string only_contacts:Bool prefer_forwards:Bool prefer_with_reaction:Bool offset:string limit:int32 = StoryInteractions; //@description Reports a story to the Telegram moderators //@story_sender_chat_id The identifier of the sender of the story to report diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index d6af34e0c..0b2401887 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -348,8 +348,8 @@ class GetStoryViewsListQuery final : public Td::ResultHandler { : promise_(std::move(promise)) { } - void send(DialogId dialog_id, StoryId story_id, const string &query, bool only_contacts, bool prefer_with_reaction, - const string &offset, int32 limit) { + void send(DialogId dialog_id, StoryId story_id, const string &query, bool only_contacts, bool prefer_forwards, + bool prefer_with_reaction, const string &offset, int32 limit) { dialog_id_ = dialog_id; auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Write); if (input_peer == nullptr) { @@ -363,6 +363,9 @@ class GetStoryViewsListQuery final : public Td::ResultHandler { if (only_contacts) { flags |= telegram_api::stories_getStoryViewsList::JUST_CONTACTS_MASK; } + if (prefer_forwards) { + flags |= telegram_api::stories_getStoryViewsList::FORWARDS_FIRST_MASK; + } if (prefer_with_reaction) { flags |= telegram_api::stories_getStoryViewsList::REACTIONS_FIRST_MASK; } @@ -2820,7 +2823,8 @@ void StoryManager::get_channel_differences_if_needed( } void StoryManager::get_story_interactions(StoryId story_id, const string &query, bool only_contacts, - bool prefer_with_reaction, const string &offset, int32 limit, + bool prefer_forwards, bool prefer_with_reaction, const string &offset, + int32 limit, Promise> &&promise) { DialogId owner_dialog_id(td_->contacts_manager_->get_my_id()); StoryFullId story_full_id{owner_dialog_id, story_id}; @@ -2842,7 +2846,7 @@ void StoryManager::get_story_interactions(StoryId story_id, const string &query, }); td_->create_handler(std::move(query_promise)) - ->send(owner_dialog_id, story_id, query, only_contacts, prefer_with_reaction, offset, limit); + ->send(owner_dialog_id, story_id, query, only_contacts, prefer_forwards, prefer_with_reaction, offset, limit); } void StoryManager::on_get_story_interactions( diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 993be4ee7..890b62778 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -263,8 +263,8 @@ class StoryManager final : public Actor { void set_story_reaction(StoryFullId story_full_id, ReactionType reaction_type, bool add_to_recent, Promise &&promise); - void get_story_interactions(StoryId story_id, const string &query, bool only_contacts, bool prefer_with_reaction, - const string &offset, int32 limit, + void get_story_interactions(StoryId story_id, const string &query, bool only_contacts, bool prefer_forwards, + bool prefer_with_reaction, const string &offset, int32 limit, Promise> &&promise); void get_channel_differences_if_needed( diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 952b488c3..7998e1901 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6686,8 +6686,8 @@ void Td::on_request(uint64 id, td_api::getStoryInteractions &request) { CLEAN_INPUT_STRING(request.offset_); CREATE_REQUEST_PROMISE(); story_manager_->get_story_interactions(StoryId(request.story_id_), request.query_, request.only_contacts_, - request.prefer_with_reaction_, request.offset_, request.limit_, - std::move(promise)); + request.prefer_forwards_, request.prefer_with_reaction_, request.offset_, + request.limit_, std::move(promise)); } void Td::on_request(uint64 id, td_api::reportStory &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 5ae0e77b9..352421506 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4424,9 +4424,10 @@ class CliClient final : public Actor { string offset; string query; bool only_contacts; + bool prefer_forwards; bool prefer_with_reaction; - get_args(args, story_id, limit, offset, query, only_contacts, prefer_with_reaction); - send_request(td_api::make_object(story_id, query, only_contacts, + get_args(args, story_id, limit, offset, query, only_contacts, prefer_forwards, prefer_with_reaction); + send_request(td_api::make_object(story_id, query, only_contacts, prefer_forwards, prefer_with_reaction, offset, as_limit(limit))); } else if (op == "rst") { ChatId story_sender_chat_id;