Use string offset in getStoryViewers.

This commit is contained in:
levlam 2023-08-07 19:40:15 +03:00
parent 0eec3dda94
commit d72e9cc68f
8 changed files with 30 additions and 41 deletions

View File

@ -4938,8 +4938,8 @@ messageLinkInfo is_public:Bool chat_id:int53 message_thread_id:int53 message:mes
//@chosen_reaction_type Type of the reaction that was chosen by the user; may be null if none
storyViewer user_id:int53 view_date:int32 block_list:BlockList chosen_reaction_type:ReactionType = StoryViewer;
//@description Represents a list of story viewers @viewers List of story viewers
storyViewers viewers:vector<storyViewer> = StoryViewers;
//@description Represents a list of story viewers @viewers List of story viewers @next_offset The offset for the next request. If empty, there are no more results
storyViewers viewers:vector<storyViewer> next_offset:string = StoryViewers;
//@description Describes position of a clickable rectangle area on a story media
@ -6928,7 +6928,7 @@ shareChatWithBot chat_id:int53 message_id:int53 button_id:int32 shared_chat_id:i
//@chat_id Identifier of the chat where the query was sent
//@user_location Location of the user; pass null if unknown or the bot doesn't need user's location
//@query Text of the query
//@offset Offset of the first entry to return
//@offset Offset of the first entry to return; use empty string to get the first chunk of results
getInlineQueryResults bot_user_id:int53 chat_id:int53 user_location:location query:string offset:string = InlineQueryResults;
//@description Sets the result of an inline query; for bots only
@ -7478,13 +7478,11 @@ closeStory story_sender_chat_id:int53 story_id:int32 = Ok;
//@update_recent_reactions Pass true if the reaction needs to be added to recent reactions
setStoryReaction story_sender_chat_id:int53 story_id:int32 reaction_type:ReactionType update_recent_reactions:Bool = Ok;
//@description Returns viewers of a recent outgoing story. The method can be called if story.can_get_viewers == true. The views are returned in a reverse chronological order (i.e., in order of decreasing view_date)
//-For optimal performance, the number of returned stories is chosen by TDLib
//@description Returns viewers of a story. The method can be called if story.can_get_viewers == true. The views are returned in a reverse chronological order (i.e., in order of decreasing view_date)
//@story_id Story identifier
//@offset_viewer A viewer from which to return next viewers; pass null to get results from the beginning
//@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 viewers to return
//-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:storyViewer limit:int32 = StoryViewers;
getStoryViewers story_id:int32 offset:string limit:int32 = StoryViewers;
//@description Reports a story to the Telegram moderators
//@story_sender_chat_id The identifier of the sender of the story to report

View File

@ -303,10 +303,10 @@ class GetStoryViewsListQuery final : public Td::ResultHandler {
: promise_(std::move(promise)) {
}
void send(StoryId story_id, int32 offset_date, int64 offset_user_id, int32 limit) {
void send(StoryId story_id, const string &offset, int32 limit) {
int32 flags = 0;
send_query(G()->net_query_creator().create(telegram_api::stories_getStoryViewsList(
flags, false /*ignored*/, false /*ignored*/, string(), story_id.get(), string(), limit)));
flags, false /*ignored*/, false /*ignored*/, string(), story_id.get(), offset, limit)));
}
void on_result(BufferSlice packet) final {
@ -2320,7 +2320,7 @@ Status StoryManager::can_get_story_viewers(StoryFullId story_full_id, const Stor
return Status::OK();
}
void StoryManager::get_story_viewers(StoryId story_id, const td_api::storyViewer *offset, int32 limit,
void StoryManager::get_story_viewers(StoryId story_id, const string &offset, int32 limit,
Promise<td_api::object_ptr<td_api::storyViewers>> &&promise) {
DialogId owner_dialog_id(td_->contacts_manager_->get_my_id());
StoryFullId story_full_id{owner_dialog_id, story_id};
@ -2335,14 +2335,7 @@ void StoryManager::get_story_viewers(StoryId story_id, const td_api::storyViewer
return promise.set_value(td_api::make_object<td_api::storyViewers>());
}
int32 offset_date = 0;
int64 offset_user_id = 0;
if (offset != nullptr) {
offset_date = offset->view_date_;
offset_user_id = offset->user_id_;
}
bool is_first = offset_user_id <= 0 && offset_date <= 0;
bool is_first = offset.empty();
auto query_promise = PromiseCreator::lambda(
[actor_id = actor_id(this), story_id, is_first, promise = std::move(promise)](
Result<telegram_api::object_ptr<telegram_api::stories_storyViewsList>> result) mutable {
@ -2351,7 +2344,7 @@ void StoryManager::get_story_viewers(StoryId story_id, const td_api::storyViewer
});
td_->create_handler<GetStoryViewsListQuery>(std::move(query_promise))
->send(story_full_id.get_story_id(), offset_date, offset_user_id, limit);
->send(story_full_id.get_story_id(), offset, limit);
}
void StoryManager::on_get_story_viewers(
@ -2379,7 +2372,7 @@ void StoryManager::on_get_story_viewers(
total_count = static_cast<int32>(view_list->views_.size());
}
StoryViewers story_viewers(std::move(view_list->views_));
StoryViewers story_viewers(std::move(view_list->views_), std::move(view_list->next_offset_));
if (story->content_ != nullptr) {
bool is_changed = false;
if (story->interaction_info_.set_view_count(view_list->count_)) {

View File

@ -244,7 +244,7 @@ class StoryManager final : public Actor {
void set_story_reaction(StoryFullId story_full_id, ReactionType reaction_type, bool add_to_recent,
Promise<Unit> &&promise);
void get_story_viewers(StoryId story_id, const td_api::storyViewer *offset, int32 limit,
void get_story_viewers(StoryId story_id, const string &offset, int32 limit,
Promise<td_api::object_ptr<td_api::storyViewers>> &&promise);
void report_story(StoryFullId story_full_id, ReportReason &&reason, Promise<Unit> &&promise);

View File

@ -25,7 +25,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const StoryViewer &view
return string_builder << '[' << viewer.user_id_ << " with " << viewer.reaction_type_ << " at " << viewer.date_ << ']';
}
StoryViewers::StoryViewers(vector<telegram_api::object_ptr<telegram_api::storyView>> &&story_views) {
StoryViewers::StoryViewers(vector<telegram_api::object_ptr<telegram_api::storyView>> &&story_views,
string &&next_offset)
: next_offset_(std::move(next_offset)) {
for (auto &story_view : story_views) {
story_viewers_.emplace_back(std::move(story_view));
auto user_id = story_viewers_.back().get_user_id();
@ -43,9 +45,11 @@ vector<UserId> StoryViewers::get_user_ids() const {
td_api::object_ptr<td_api::storyViewers> StoryViewers::get_story_viewers_object(
ContactsManager *contacts_manager) const {
return td_api::make_object<td_api::storyViewers>(
transform(story_viewers_, [contacts_manager](const StoryViewer &story_viewer) {
return story_viewer.get_story_viewer_object(contacts_manager);
}));
transform(story_viewers_,
[contacts_manager](const StoryViewer &story_viewer) {
return story_viewer.get_story_viewer_object(contacts_manager);
}),
next_offset_);
}
StringBuilder &operator<<(StringBuilder &string_builder, const StoryViewers &viewers) {

View File

@ -47,17 +47,14 @@ StringBuilder &operator<<(StringBuilder &string_builder, const StoryViewer &view
class StoryViewers {
vector<StoryViewer> story_viewers_;
string next_offset_;
friend StringBuilder &operator<<(StringBuilder &string_builder, const StoryViewers &viewers);
public:
StoryViewers() = default;
explicit StoryViewers(vector<telegram_api::object_ptr<telegram_api::storyView>> &&story_views);
bool is_empty() const {
return story_viewers_.empty();
}
StoryViewers(vector<telegram_api::object_ptr<telegram_api::storyView>> &&story_views, string &&next_offset);
vector<UserId> get_user_ids() const;

View File

@ -6492,11 +6492,11 @@ void Td::on_request(uint64 id, const td_api::setStoryReaction &request) {
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getStoryViewers &request) {
void Td::on_request(uint64 id, td_api::getStoryViewers &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.offset_);
CREATE_REQUEST_PROMISE();
story_manager_->get_story_viewers(StoryId(request.story_id_), request.offset_viewer_.get(), request.limit_,
std::move(promise));
story_manager_->get_story_viewers(StoryId(request.story_id_), request.offset_, request.limit_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::reportStory &request) {

View File

@ -1023,7 +1023,7 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::setStoryReaction &request);
void on_request(uint64 id, const td_api::getStoryViewers &request);
void on_request(uint64 id, td_api::getStoryViewers &request);
void on_request(uint64 id, td_api::reportStory &request);

View File

@ -4151,12 +4151,9 @@ class CliClient final : public Actor {
} else if (op == "gsv") {
StoryId story_id;
string limit;
int32 offset_date;
UserId offset_user_id;
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::storyViewer>(offset_user_id, offset_date, nullptr, nullptr),
as_limit(limit)));
string offset;
get_args(args, story_id, limit, offset);
send_request(td_api::make_object<td_api::getStoryViewers>(story_id, offset, as_limit(limit)));
} else if (op == "rst") {
ChatId story_sender_chat_id;
StoryId story_id;