Improve updateSpeechRecognitionTrial.

This commit is contained in:
levlam 2023-11-23 15:35:54 +03:00
parent 50a360c147
commit 2dd9da30be
3 changed files with 18 additions and 18 deletions

View File

@ -6419,8 +6419,8 @@ updateDefaultReactionType reaction_type:ReactionType = Update;
//@max_media_duration The maximum allowed duration of media for speech recognition without Telegram Premium subscription //@max_media_duration The maximum allowed duration of media for speech recognition without Telegram Premium subscription
//@weekly_count The total number of allowed speech recognitions per week; 0 if none //@weekly_count The total number of allowed speech recognitions per week; 0 if none
//@left_count Number of left speech recognition attempts this week //@left_count Number of left speech recognition attempts this week
//@next_recognition_date Point in time (Unix timestamp) when the user can use speech recognition without Telegram Premium subscription again; 0 if now or never //@next_reset_date Point in time (Unix timestamp) when the weekly number of tries will reset; 0 if unknown
updateSpeechRecognitionTrial max_media_duration:int32 weekly_count:int32 left_count:int32 next_recognition_date:int32 = Update; updateSpeechRecognitionTrial max_media_duration:int32 weekly_count:int32 left_count:int32 next_reset_date:int32 = Update;
//@description The list of supported dice emojis has changed @emojis The new list of supported dice emojis //@description The list of supported dice emojis has changed @emojis The new list of supported dice emojis
updateDiceEmojis emojis:vector<string> = Update; updateDiceEmojis emojis:vector<string> = Update;

View File

@ -18,8 +18,8 @@
namespace td { namespace td {
void TranscriptionManager::TrialParameters::update_left_tries() { void TranscriptionManager::TrialParameters::update_left_tries() {
if (cooldown_until_ <= G()->unix_time()) { if (next_reset_date_ <= G()->unix_time()) {
cooldown_until_ = 0; next_reset_date_ = 0;
left_tries_ = weekly_number_; left_tries_ = weekly_number_;
} else if (left_tries_ > weekly_number_) { } else if (left_tries_ > weekly_number_) {
left_tries_ = weekly_number_; left_tries_ = weekly_number_;
@ -31,12 +31,12 @@ void TranscriptionManager::TrialParameters::store(StorerT &storer) const {
bool has_weekly_number = weekly_number_ != 0; bool has_weekly_number = weekly_number_ != 0;
bool has_duration_max = duration_max_ != 0; bool has_duration_max = duration_max_ != 0;
bool has_left_tries = left_tries_ != 0; bool has_left_tries = left_tries_ != 0;
bool has_cooldown_until = cooldown_until_ != 0; bool has_next_reset_date = next_reset_date_ != 0;
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(has_weekly_number); STORE_FLAG(has_weekly_number);
STORE_FLAG(has_duration_max); STORE_FLAG(has_duration_max);
STORE_FLAG(has_left_tries); STORE_FLAG(has_left_tries);
STORE_FLAG(has_cooldown_until); STORE_FLAG(has_next_reset_date);
END_STORE_FLAGS(); END_STORE_FLAGS();
if (has_weekly_number) { if (has_weekly_number) {
td::store(weekly_number_, storer); td::store(weekly_number_, storer);
@ -47,8 +47,8 @@ void TranscriptionManager::TrialParameters::store(StorerT &storer) const {
if (has_left_tries) { if (has_left_tries) {
td::store(left_tries_, storer); td::store(left_tries_, storer);
} }
if (has_cooldown_until) { if (has_next_reset_date) {
td::store(cooldown_until_, storer); td::store(next_reset_date_, storer);
} }
} }
@ -57,12 +57,12 @@ void TranscriptionManager::TrialParameters::parse(ParserT &parser) {
bool has_weekly_number; bool has_weekly_number;
bool has_duration_max; bool has_duration_max;
bool has_left_tries; bool has_left_tries;
bool has_cooldown_until; bool has_next_reset_date;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_weekly_number); PARSE_FLAG(has_weekly_number);
PARSE_FLAG(has_duration_max); PARSE_FLAG(has_duration_max);
PARSE_FLAG(has_left_tries); PARSE_FLAG(has_left_tries);
PARSE_FLAG(has_cooldown_until); PARSE_FLAG(has_next_reset_date);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
if (has_weekly_number) { if (has_weekly_number) {
td::parse(weekly_number_, parser); td::parse(weekly_number_, parser);
@ -73,14 +73,14 @@ void TranscriptionManager::TrialParameters::parse(ParserT &parser) {
if (has_left_tries) { if (has_left_tries) {
td::parse(left_tries_, parser); td::parse(left_tries_, parser);
} }
if (has_cooldown_until) { if (has_next_reset_date) {
td::parse(cooldown_until_, parser); td::parse(next_reset_date_, parser);
} }
} }
bool operator==(const TranscriptionManager::TrialParameters &lhs, const TranscriptionManager::TrialParameters &rhs) { bool operator==(const TranscriptionManager::TrialParameters &lhs, const TranscriptionManager::TrialParameters &rhs) {
return lhs.weekly_number_ == rhs.weekly_number_ && lhs.duration_max_ == rhs.duration_max_ && return lhs.weekly_number_ == rhs.weekly_number_ && lhs.duration_max_ == rhs.duration_max_ &&
lhs.left_tries_ == rhs.left_tries_ && lhs.cooldown_until_ == rhs.cooldown_until_; lhs.left_tries_ == rhs.left_tries_ && lhs.next_reset_date_ == rhs.next_reset_date_;
} }
TranscriptionManager::TranscriptionManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { TranscriptionManager::TranscriptionManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
@ -149,7 +149,7 @@ void TranscriptionManager::on_update_trial_parameters(int32 weekly_number, int32
TrialParameters new_trial_parameters; TrialParameters new_trial_parameters;
new_trial_parameters.weekly_number_ = max(0, weekly_number); new_trial_parameters.weekly_number_ = max(0, weekly_number);
new_trial_parameters.duration_max_ = max(0, duration_max); new_trial_parameters.duration_max_ = max(0, duration_max);
new_trial_parameters.cooldown_until_ = max(0, cooldown_until); new_trial_parameters.next_reset_date_ = cooldown_until > 0 ? cooldown_until : trial_parameters_.next_reset_date_;
new_trial_parameters.left_tries_ = trial_parameters_.left_tries_; new_trial_parameters.left_tries_ = trial_parameters_.left_tries_;
set_trial_parameters(new_trial_parameters); set_trial_parameters(new_trial_parameters);
} }
@ -179,7 +179,7 @@ TranscriptionManager::get_update_speech_recognition_trial_object() const {
td_api::object_ptr<td_api::updateSpeechRecognitionTrial> td_api::object_ptr<td_api::updateSpeechRecognitionTrial>
TranscriptionManager::TrialParameters::get_update_speech_recognition_trial_object() const { TranscriptionManager::TrialParameters::get_update_speech_recognition_trial_object() const {
return td_api::make_object<td_api::updateSpeechRecognitionTrial>(duration_max_, weekly_number_, left_tries_, return td_api::make_object<td_api::updateSpeechRecognitionTrial>(duration_max_, weekly_number_, left_tries_,
cooldown_until_); next_reset_date_);
} }
void TranscriptionManager::register_voice(FileId file_id, MessageContentType content_type, void TranscriptionManager::register_voice(FileId file_id, MessageContentType content_type,
@ -258,7 +258,7 @@ void TranscriptionManager::on_transcribed_audio(
on_transcribed_audio_update(file_info, true, r_audio.move_as_error()); on_transcribed_audio_update(file_info, true, r_audio.move_as_error());
if (retry_after > 0) { if (retry_after > 0) {
TrialParameters new_trial_parameters = trial_parameters_; TrialParameters new_trial_parameters = trial_parameters_;
new_trial_parameters.cooldown_until_ = G()->unix_time() + retry_after; new_trial_parameters.next_reset_date_ = G()->unix_time() + retry_after;
new_trial_parameters.left_tries_ = 0; new_trial_parameters.left_tries_ = 0;
set_trial_parameters(new_trial_parameters); set_trial_parameters(new_trial_parameters);
} }
@ -276,7 +276,7 @@ void TranscriptionManager::on_transcribed_audio(
if ((audio->flags_ & telegram_api::messages_transcribedAudio::TRIAL_REMAINS_NUM_MASK) != 0) { if ((audio->flags_ & telegram_api::messages_transcribedAudio::TRIAL_REMAINS_NUM_MASK) != 0) {
TrialParameters new_trial_parameters = trial_parameters_; TrialParameters new_trial_parameters = trial_parameters_;
new_trial_parameters.cooldown_until_ = audio->trial_remains_num_ > 0 ? 0 : audio->trial_remains_until_date_; new_trial_parameters.next_reset_date_ = max(0, audio->trial_remains_until_date_);
new_trial_parameters.left_tries_ = audio->trial_remains_num_; new_trial_parameters.left_tries_ = audio->trial_remains_num_;
set_trial_parameters(new_trial_parameters); set_trial_parameters(new_trial_parameters);
} }

View File

@ -63,7 +63,7 @@ class TranscriptionManager final : public Actor {
int32 weekly_number_ = 0; int32 weekly_number_ = 0;
int32 duration_max_ = 0; int32 duration_max_ = 0;
int32 left_tries_ = 0; int32 left_tries_ = 0;
int32 cooldown_until_ = 0; int32 next_reset_date_ = 0;
void update_left_tries(); void update_left_tries();