Add updateSpeechRecognitionTrial.
This commit is contained in:
parent
a83f90448f
commit
e5f457c30f
@ -6415,6 +6415,13 @@ updateActiveEmojiReactions emojis:vector<string> = Update;
|
||||
//@description The type of default reaction has changed @reaction_type The new type of the default reaction
|
||||
updateDefaultReactionType reaction_type:ReactionType = Update;
|
||||
|
||||
//@description The parameters of speech recognition without Telegram Premium subscription has changed
|
||||
//@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
|
||||
//@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
|
||||
updateSpeechRecognitionTrial max_media_duration:int32 weekly_count:int32 left_count:int32 next_recognition_date:int32 = Update;
|
||||
|
||||
//@description The list of supported dice emojis has changed @emojis The new list of supported dice emojis
|
||||
updateDiceEmojis emojis:vector<string> = Update;
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "td/telegram/TdDb.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
#include "td/telegram/ThemeManager.h"
|
||||
#include "td/telegram/TranscriptionManager.h"
|
||||
|
||||
#include "td/mtproto/AuthData.h"
|
||||
#include "td/mtproto/AuthKey.h"
|
||||
@ -1488,6 +1489,9 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors;
|
||||
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors;
|
||||
vector<AccentColorId> accent_color_ids;
|
||||
int32 transcribe_audio_trial_weekly_number = 0;
|
||||
int32 transcribe_audio_trial_duration_max = 0;
|
||||
int32 transcribe_audio_trial_cooldown_until = 0;
|
||||
if (config->get_id() == telegram_api::jsonObject::ID) {
|
||||
for (auto &key_value : static_cast<telegram_api::jsonObject *>(config.get())->value_) {
|
||||
Slice key = key_value->key_;
|
||||
@ -2010,6 +2014,18 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (key == "transcribe_audio_trial_weekly_number") {
|
||||
transcribe_audio_trial_weekly_number = get_json_value_int(std::move(key_value->value_), key);
|
||||
continue;
|
||||
}
|
||||
if (key == "transcribe_audio_trial_duration_max") {
|
||||
transcribe_audio_trial_duration_max = get_json_value_int(std::move(key_value->value_), key);
|
||||
continue;
|
||||
}
|
||||
if (key == "transcribe_audio_trial_cooldown_until") {
|
||||
transcribe_audio_trial_cooldown_until = get_json_value_int(std::move(key_value->value_), key);
|
||||
continue;
|
||||
}
|
||||
|
||||
new_values.push_back(std::move(key_value));
|
||||
}
|
||||
@ -2031,6 +2047,10 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
send_closure(G()->theme_manager(), &ThemeManager::on_update_accent_colors, std::move(light_colors),
|
||||
std::move(dark_colors), std::move(accent_color_ids));
|
||||
|
||||
send_closure(G()->transcription_manager(), &TranscriptionManager::on_update_trial_parameters,
|
||||
transcribe_audio_trial_weekly_number, transcribe_audio_trial_duration_max,
|
||||
transcribe_audio_trial_cooldown_until);
|
||||
|
||||
Global &options = *G();
|
||||
|
||||
if (ignored_restriction_reasons.empty()) {
|
||||
|
@ -102,7 +102,7 @@ class ConfigManager final : public NetQueryCallback {
|
||||
|
||||
private:
|
||||
struct AppConfig {
|
||||
static constexpr int32 CURRENT_VERSION = 22;
|
||||
static constexpr int32 CURRENT_VERSION = 23;
|
||||
int32 version_ = 0;
|
||||
int32 hash_ = 0;
|
||||
telegram_api::object_ptr<telegram_api::JSONValue> config_;
|
||||
|
@ -68,6 +68,7 @@ class TdDb;
|
||||
class TempAuthKeyWatchdog;
|
||||
class ThemeManager;
|
||||
class TopDialogManager;
|
||||
class TranscriptionManager;
|
||||
class UpdatesManager;
|
||||
class WebPagesManager;
|
||||
|
||||
@ -394,6 +395,13 @@ class Global final : public ActorContext {
|
||||
top_dialog_manager_ = top_dialog_manager;
|
||||
}
|
||||
|
||||
ActorId<TranscriptionManager> transcription_manager() const {
|
||||
return transcription_manager_;
|
||||
}
|
||||
void set_transcription_manager(ActorId<TranscriptionManager> transcription_manager) {
|
||||
transcription_manager_ = transcription_manager;
|
||||
}
|
||||
|
||||
ActorId<UpdatesManager> updates_manager() const {
|
||||
return updates_manager_;
|
||||
}
|
||||
@ -554,6 +562,7 @@ class Global final : public ActorContext {
|
||||
ActorId<StoryManager> story_manager_;
|
||||
ActorId<ThemeManager> theme_manager_;
|
||||
ActorId<TopDialogManager> top_dialog_manager_;
|
||||
ActorId<TranscriptionManager> transcription_manager_;
|
||||
ActorId<UpdatesManager> updates_manager_;
|
||||
ActorId<WebPagesManager> web_pages_manager_;
|
||||
ActorOwn<ConnectionCreator> connection_creator_;
|
||||
|
@ -4045,6 +4045,7 @@ void Td::init_managers() {
|
||||
G()->set_top_dialog_manager(top_dialog_manager_actor_.get());
|
||||
transcription_manager_ = make_unique<TranscriptionManager>(this, create_reference());
|
||||
transcription_manager_actor_ = register_actor("TranscriptionManager", transcription_manager_.get());
|
||||
G()->set_transcription_manager(transcription_manager_actor_.get());
|
||||
translation_manager_ = make_unique<TranslationManager>(this, create_reference());
|
||||
translation_manager_actor_ = register_actor("TranslationManager", translation_manager_.get());
|
||||
updates_manager_ = make_unique<UpdatesManager>(this, create_reference());
|
||||
|
@ -6,6 +6,10 @@
|
||||
//
|
||||
#include "td/telegram/TranscriptionManager.h"
|
||||
|
||||
#include "td/telegram/AuthManager.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/Td.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
TranscriptionManager::TranscriptionManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
||||
@ -15,4 +19,39 @@ void TranscriptionManager::tear_down() {
|
||||
parent_.reset();
|
||||
}
|
||||
|
||||
void TranscriptionManager::on_update_trial_parameters(int32 weekly_number, int32 duration_max, int32 cooldown_until) {
|
||||
CHECK(!td_->auth_manager_->is_bot());
|
||||
weekly_number = max(0, weekly_number);
|
||||
duration_max = max(0, duration_max);
|
||||
cooldown_until = max(0, cooldown_until);
|
||||
int32 left_tries = trial_left_tries_;
|
||||
if (cooldown_until <= G()->unix_time()) {
|
||||
cooldown_until = 0;
|
||||
left_tries = weekly_number;
|
||||
} else if (left_tries > weekly_number) {
|
||||
left_tries = weekly_number;
|
||||
}
|
||||
if (weekly_number == trial_weekly_number_ && duration_max == trial_duration_max_ && left_tries == trial_left_tries_ &&
|
||||
cooldown_until == trial_cooldown_until_) {
|
||||
return;
|
||||
}
|
||||
|
||||
trial_weekly_number_ = weekly_number;
|
||||
trial_duration_max_ = duration_max;
|
||||
trial_left_tries_ = left_tries;
|
||||
trial_cooldown_until_ = cooldown_until;
|
||||
send_update_speech_recognition_trial();
|
||||
}
|
||||
|
||||
void TranscriptionManager::send_update_speech_recognition_trial() const {
|
||||
CHECK(!td_->auth_manager_->is_bot());
|
||||
send_closure(G()->td(), &Td::send_update, get_update_speech_recognition_trial_object());
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::updateSpeechRecognitionTrial>
|
||||
TranscriptionManager::get_update_speech_recognition_trial_object() const {
|
||||
return td_api::make_object<td_api::updateSpeechRecognitionTrial>(trial_duration_max_, trial_weekly_number_,
|
||||
trial_left_tries_, trial_cooldown_until_);
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -6,6 +6,8 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/td_api.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
@ -18,11 +20,22 @@ class TranscriptionManager final : public Actor {
|
||||
public:
|
||||
TranscriptionManager(Td *td, ActorShared<> parent);
|
||||
|
||||
void on_update_trial_parameters(int32 weekly_number, int32 duration_max, int32 cooldown_until);
|
||||
|
||||
private:
|
||||
void tear_down() final;
|
||||
|
||||
void send_update_speech_recognition_trial() const;
|
||||
|
||||
td_api::object_ptr<td_api::updateSpeechRecognitionTrial> get_update_speech_recognition_trial_object() const;
|
||||
|
||||
Td *td_;
|
||||
ActorShared<> parent_;
|
||||
|
||||
int32 trial_weekly_number_ = 0;
|
||||
int32 trial_duration_max_ = 0;
|
||||
int32 trial_left_tries_ = 0;
|
||||
int32 trial_cooldown_until_ = 0;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
Loading…
Reference in New Issue
Block a user