Reload attach menu bots once an hour.

This commit is contained in:
levlam 2022-03-25 18:10:25 +03:00
parent 66dfbee537
commit 515000f875
2 changed files with 15 additions and 2 deletions

View File

@ -22,6 +22,7 @@
#include "td/utils/algorithm.h" #include "td/utils/algorithm.h"
#include "td/utils/buffer.h" #include "td/utils/buffer.h"
#include "td/utils/misc.h" #include "td/utils/misc.h"
#include "td/utils/Random.h"
#include "td/utils/tl_helpers.h" #include "td/utils/tl_helpers.h"
namespace td { namespace td {
@ -200,8 +201,16 @@ void AttachMenuManager::init() {
reload_attach_menu_bots(); reload_attach_menu_bots();
} }
void AttachMenuManager::timeout_expired() {
if (!is_active()) {
return;
}
reload_attach_menu_bots();
}
bool AttachMenuManager::is_active() const { bool AttachMenuManager::is_active() const {
return td_->auth_manager_->is_authorized() && !td_->auth_manager_->is_bot(); return !G()->close_flag() && td_->auth_manager_->is_authorized() && !td_->auth_manager_->is_bot();
} }
void AttachMenuManager::reload_attach_menu_bots() { void AttachMenuManager::reload_attach_menu_bots() {
@ -221,12 +230,14 @@ void AttachMenuManager::on_reload_attach_menu_bots(
return; return;
} }
if (result.is_error()) { if (result.is_error()) {
// TODO retry after some time set_timeout_in(Random::fast(60, 120));
return; return;
} }
is_inited_ = true; is_inited_ = true;
set_timeout_in(Random::fast(3600, 4800));
auto attach_menu_bots_ptr = result.move_as_ok(); auto attach_menu_bots_ptr = result.move_as_ok();
auto constructor_id = attach_menu_bots_ptr->get_id(); auto constructor_id = attach_menu_bots_ptr->get_id();
if (constructor_id == telegram_api::attachMenuBotsNotModified::ID) { if (constructor_id == telegram_api::attachMenuBotsNotModified::ID) {

View File

@ -35,6 +35,8 @@ class AttachMenuManager final : public Actor {
private: private:
void start_up() final; void start_up() final;
void timeout_expired() final;
void tear_down() final; void tear_down() final;
bool is_active() const; bool is_active() const;