Move get_can_send_story_result_object inside StoryManager.
This commit is contained in:
parent
7f0514d492
commit
13187c945a
@ -64,43 +64,6 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
static td_api::object_ptr<td_api::CanSendStoryResult> get_can_send_story_result_object(const Status &error,
|
|
||||||
bool force = false) {
|
|
||||||
CHECK(error.is_error());
|
|
||||||
if (error.message() == "PREMIUM_ACCOUNT_REQUIRED") {
|
|
||||||
return td_api::make_object<td_api::canSendStoryResultPremiumNeeded>();
|
|
||||||
}
|
|
||||||
if (error.message() == "BOOSTS_REQUIRED") {
|
|
||||||
return td_api::make_object<td_api::canSendStoryResultBoostNeeded>();
|
|
||||||
}
|
|
||||||
if (error.message() == "STORIES_TOO_MUCH") {
|
|
||||||
return td_api::make_object<td_api::canSendStoryResultActiveStoryLimitExceeded>();
|
|
||||||
}
|
|
||||||
if (begins_with(error.message(), "STORY_SEND_FLOOD_WEEKLY_")) {
|
|
||||||
auto r_next_date = to_integer_safe<int32>(error.message().substr(Slice("STORY_SEND_FLOOD_WEEKLY_").size()));
|
|
||||||
if (r_next_date.is_ok() && r_next_date.ok() > 0) {
|
|
||||||
auto retry_after = r_next_date.ok() - G()->unix_time();
|
|
||||||
if (retry_after > 0 || force) {
|
|
||||||
return td_api::make_object<td_api::canSendStoryResultWeeklyLimitExceeded>(max(retry_after, 0));
|
|
||||||
} else {
|
|
||||||
return td_api::make_object<td_api::canSendStoryResultOk>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (begins_with(error.message(), "STORY_SEND_FLOOD_MONTHLY_")) {
|
|
||||||
auto r_next_date = to_integer_safe<int32>(error.message().substr(Slice("STORY_SEND_FLOOD_MONTHLY_").size()));
|
|
||||||
if (r_next_date.is_ok() && r_next_date.ok() > 0) {
|
|
||||||
auto retry_after = r_next_date.ok() - G()->unix_time();
|
|
||||||
if (retry_after > 0 || force) {
|
|
||||||
return td_api::make_object<td_api::canSendStoryResultMonthlyLimitExceeded>(max(retry_after, 0));
|
|
||||||
} else {
|
|
||||||
return td_api::make_object<td_api::canSendStoryResultOk>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
class GetAllStoriesQuery final : public Td::ResultHandler {
|
class GetAllStoriesQuery final : public Td::ResultHandler {
|
||||||
Promise<telegram_api::object_ptr<telegram_api::stories_AllStories>> promise_;
|
Promise<telegram_api::object_ptr<telegram_api::stories_AllStories>> promise_;
|
||||||
|
|
||||||
@ -1091,7 +1054,7 @@ class CanSendStoryQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_error(Status status) final {
|
void on_error(Status status) final {
|
||||||
auto result = get_can_send_story_result_object(status);
|
auto result = StoryManager::get_can_send_story_result_object(status);
|
||||||
if (result != nullptr) {
|
if (result != nullptr) {
|
||||||
return promise_.set_value(std::move(result));
|
return promise_.set_value(std::move(result));
|
||||||
}
|
}
|
||||||
@ -3581,6 +3544,43 @@ td_api::object_ptr<td_api::chatActiveStories> StoryManager::get_chat_active_stor
|
|||||||
story_list_id.get_story_list_object(), order, max_read_story_id.get(), std::move(stories));
|
story_list_id.get_story_list_object(), order, max_read_story_id.get(), std::move(stories));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::CanSendStoryResult> StoryManager::get_can_send_story_result_object(const Status &error,
|
||||||
|
bool force) {
|
||||||
|
CHECK(error.is_error());
|
||||||
|
if (error.message() == "PREMIUM_ACCOUNT_REQUIRED") {
|
||||||
|
return td_api::make_object<td_api::canSendStoryResultPremiumNeeded>();
|
||||||
|
}
|
||||||
|
if (error.message() == "BOOSTS_REQUIRED") {
|
||||||
|
return td_api::make_object<td_api::canSendStoryResultBoostNeeded>();
|
||||||
|
}
|
||||||
|
if (error.message() == "STORIES_TOO_MUCH") {
|
||||||
|
return td_api::make_object<td_api::canSendStoryResultActiveStoryLimitExceeded>();
|
||||||
|
}
|
||||||
|
if (begins_with(error.message(), "STORY_SEND_FLOOD_WEEKLY_")) {
|
||||||
|
auto r_next_date = to_integer_safe<int32>(error.message().substr(Slice("STORY_SEND_FLOOD_WEEKLY_").size()));
|
||||||
|
if (r_next_date.is_ok() && r_next_date.ok() > 0) {
|
||||||
|
auto retry_after = r_next_date.ok() - G()->unix_time();
|
||||||
|
if (retry_after > 0 || force) {
|
||||||
|
return td_api::make_object<td_api::canSendStoryResultWeeklyLimitExceeded>(max(retry_after, 0));
|
||||||
|
} else {
|
||||||
|
return td_api::make_object<td_api::canSendStoryResultOk>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (begins_with(error.message(), "STORY_SEND_FLOOD_MONTHLY_")) {
|
||||||
|
auto r_next_date = to_integer_safe<int32>(error.message().substr(Slice("STORY_SEND_FLOOD_MONTHLY_").size()));
|
||||||
|
if (r_next_date.is_ok() && r_next_date.ok() > 0) {
|
||||||
|
auto retry_after = r_next_date.ok() - G()->unix_time();
|
||||||
|
if (retry_after > 0 || force) {
|
||||||
|
return td_api::make_object<td_api::canSendStoryResultMonthlyLimitExceeded>(max(retry_after, 0));
|
||||||
|
} else {
|
||||||
|
return td_api::make_object<td_api::canSendStoryResultOk>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
vector<FileId> StoryManager::get_story_file_ids(const Story *story) const {
|
vector<FileId> StoryManager::get_story_file_ids(const Story *story) const {
|
||||||
if (story == nullptr || story->content_ == nullptr) {
|
if (story == nullptr || story->content_ == nullptr) {
|
||||||
return {};
|
return {};
|
||||||
|
@ -357,6 +357,9 @@ class StoryManager final : public Actor {
|
|||||||
td_api::object_ptr<td_api::stories> get_stories_object(int32 total_count, const vector<StoryFullId> &story_full_ids,
|
td_api::object_ptr<td_api::stories> get_stories_object(int32 total_count, const vector<StoryFullId> &story_full_ids,
|
||||||
const vector<StoryId> &pinned_story_ids) const;
|
const vector<StoryId> &pinned_story_ids) const;
|
||||||
|
|
||||||
|
static td_api::object_ptr<td_api::CanSendStoryResult> get_can_send_story_result_object(const Status &error,
|
||||||
|
bool force = false);
|
||||||
|
|
||||||
FileSourceId get_story_file_source_id(StoryFullId story_full_id);
|
FileSourceId get_story_file_source_id(StoryFullId story_full_id);
|
||||||
|
|
||||||
telegram_api::object_ptr<telegram_api::InputMedia> get_input_media(StoryFullId story_full_id) const;
|
telegram_api::object_ptr<telegram_api::InputMedia> get_input_media(StoryFullId story_full_id) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user