Add sendStory.active_period.

This commit is contained in:
levlam 2023-06-09 16:41:40 +03:00
parent bd4004e0be
commit 894e246d8f
5 changed files with 30 additions and 15 deletions

View File

@ -7202,8 +7202,9 @@ getStory user_id:int53 story_id:int32 = Story;
//@content Content of the story
//@caption Story caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters
//@privacy_rules The privacy rules for the story
//@active_period Period after which the story is moved to archive, in seconds; must be one of 6 * 3600, 12 * 3600, 86400, 2 * 86400, 3 * 86400, or 7 * 86400 for Telegram Premium users, and 86400 otherwise
//@is_pinned Pass true to keep the story accessible after expiration
sendStory content:InputStoryContent caption:formattedText privacy_rules:userPrivacySettingRules is_pinned:Bool = Story;
sendStory content:InputStoryContent caption:formattedText privacy_rules:userPrivacySettingRules active_period:int32 is_pinned:Bool = Story;
//@description Changes content and caption of a previously sent story
//@story_id Identifier of the story to edit

View File

@ -15,6 +15,7 @@
#include "td/telegram/logevent/LogEventHelper.h"
#include "td/telegram/MessageEntity.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/OptionManager.h"
#include "td/telegram/StoryContent.h"
#include "td/telegram/StoryContentType.h"
#include "td/telegram/Td.h"
@ -278,6 +279,7 @@ class StoryManager::SendStoryQuery final : public Td::ResultHandler {
const FormattedText &caption = story->caption_;
auto entities = get_input_message_entities(td_->contacts_manager_.get(), &caption, "SendStoryQuery");
auto privacy_rules = story->privacy_rules_.get_input_privacy_rules(td_);
auto period = story->expire_date_ - story->date_;
int32 flags = 0;
if (!caption.text.empty()) {
flags |= telegram_api::stories_sendStory::CAPTION_MASK;
@ -288,11 +290,14 @@ class StoryManager::SendStoryQuery final : public Td::ResultHandler {
if (pending_story_->story_->is_pinned_) {
flags |= telegram_api::stories_sendStory::PINNED_MASK;
}
if (period != 86400) {
flags |= telegram_api::stories_sendStory::PERIOD_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::stories_sendStory(flags, false /*ignored*/, false /*ignored*/, std::move(input_media),
caption.text, std::move(entities), std::move(privacy_rules),
pending_story_->random_id_, 86400),
pending_story_->random_id_, period),
{{pending_story_->dialog_id_}}));
}
@ -932,8 +937,8 @@ void StoryManager::do_get_story(StoryFullId story_full_id, Result<Unit> &&result
void StoryManager::send_story(td_api::object_ptr<td_api::InputStoryContent> &&input_story_content,
td_api::object_ptr<td_api::formattedText> &&input_caption,
td_api::object_ptr<td_api::userPrivacySettingRules> &&rules, bool is_pinned,
Promise<td_api::object_ptr<td_api::story>> &&promise) {
td_api::object_ptr<td_api::userPrivacySettingRules> &&rules, int32 active_period,
bool is_pinned, Promise<td_api::object_ptr<td_api::story>> &&promise) {
bool is_bot = td_->auth_manager_->is_bot();
DialogId dialog_id(td_->contacts_manager_->get_my_id());
TRY_RESULT_PROMISE(promise, content, get_input_story_content(td_, std::move(input_story_content), dialog_id));
@ -941,10 +946,16 @@ void StoryManager::send_story(td_api::object_ptr<td_api::InputStoryContent> &&in
get_formatted_text(td_, DialogId(), std::move(input_caption), is_bot, true, false, false));
TRY_RESULT_PROMISE(promise, privacy_rules,
UserPrivacySettingRules::get_user_privacy_setting_rules(td_, std::move(rules)));
bool is_premium = td_->option_manager_->get_option_boolean("is_premium");
if (active_period != 86400 &&
!(is_premium &&
td::contains(vector<int32>{6 * 3600, 12 * 3600, 2 * 86400, 3 * 86400, 7 * 86400}, active_period))) {
return promise.set_error(Status::Error(400, "Invalid story active period specified"));
}
auto story = make_unique<Story>();
story->date_ = G()->unix_time();
story->expire_date_ = std::numeric_limits<int32>::max();
story->expire_date_ = story->date_ + active_period;
story->is_pinned_ = is_pinned;
story->privacy_rules_ = std::move(privacy_rules);
story->content_ = std::move(content);

View File

@ -79,7 +79,7 @@ class StoryManager final : public Actor {
void send_story(td_api::object_ptr<td_api::InputStoryContent> &&input_story_content,
td_api::object_ptr<td_api::formattedText> &&input_caption,
td_api::object_ptr<td_api::userPrivacySettingRules> &&rules, bool is_pinned,
td_api::object_ptr<td_api::userPrivacySettingRules> &&rules, int32 active_period, bool is_pinned,
Promise<td_api::object_ptr<td_api::story>> &&promise);
void on_send_story_file_part_missing(unique_ptr<PendingStory> &&pending_story, int bad_part);

View File

@ -5630,7 +5630,8 @@ void Td::on_request(uint64 id, td_api::sendStory &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
story_manager_->send_story(std::move(request.content_), std::move(request.caption_),
std::move(request.privacy_rules_), request.is_pinned_, std::move(promise));
std::move(request.privacy_rules_), request.active_period_, request.is_pinned_,
std::move(promise));
}
void Td::on_request(uint64 id, td_api::editStory &request) {

View File

@ -3977,23 +3977,25 @@ class CliClient final : public Actor {
string photo;
string caption;
PrivacyRules rules;
int32 active_period;
string sticker_file_ids;
get_args(args, photo, caption, rules, sticker_file_ids);
send_request(
td_api::make_object<td_api::sendStory>(td_api::make_object<td_api::inputStoryContentPhoto>(
as_input_file(photo), to_integers<int32>(sticker_file_ids)),
as_caption(caption), rules, op == "sspp"));
get_args(args, photo, caption, rules, active_period, sticker_file_ids);
send_request(td_api::make_object<td_api::sendStory>(
td_api::make_object<td_api::inputStoryContentPhoto>(as_input_file(photo),
to_integers<int32>(sticker_file_ids)),
as_caption(caption), rules, active_period ? active_period : 86400, op == "sspp"));
} else if (op == "ssv" || op == "ssvp") {
string video;
string caption;
PrivacyRules rules;
int32 active_period;
double duration;
string sticker_file_ids;
get_args(args, video, caption, rules, duration, sticker_file_ids);
get_args(args, video, caption, rules, active_period, duration, sticker_file_ids);
send_request(td_api::make_object<td_api::sendStory>(
td_api::make_object<td_api::inputStoryContentVideo>(as_input_file(video),
to_integers<int32>(sticker_file_ids), duration),
as_caption(caption), rules, op == "ssvp"));
as_caption(caption), rules, active_period ? active_period : 86400, op == "ssvp"));
} else if (op == "esc") {
StoryId story_id;
string caption;