Fix notification usage for bots.

GitOrigin-RevId: 4645b1c91e5bb1e6a7ef5429efe690c52a8ee257
This commit is contained in:
levlam 2019-03-05 06:01:49 +03:00
parent d038c6b5c4
commit 063e8872df
4 changed files with 40 additions and 10 deletions

View File

@ -18,6 +18,7 @@
#include "td/telegram/misc.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/net/NetQueryDispatcher.h"
#include "td/telegram/NotificationManager.h"
#include "td/telegram/PasswordManager.h"
#include "td/telegram/Td.h"
#include "td/telegram/TdDb.h"
@ -560,6 +561,7 @@ void AuthManager::on_authorization(tl_object_ptr<telegram_api::auth_authorizatio
if ((auth->flags_ & telegram_api::auth_authorization::TMP_SESSIONS_MASK) != 0) {
G()->shared_config().set_option_integer("session_count", auth->tmp_sessions_);
}
td->notification_manager_->init();
td->updates_manager_->get_difference("on_authorization");
td->on_online_updated(false, true);
td->schedule_get_terms_of_service(0);

View File

@ -8994,8 +8994,10 @@ void MessagesManager::init() {
channels_notification_settings_.disable_pinned_message_notifications = false;
channels_notification_settings_.disable_mention_notifications = false;
channels_notification_settings_.is_synchronized = false;
if (!td_->auth_manager_->is_bot()) {
send_get_scope_notification_settings_query(NotificationSettingsScope::Channel, Promise<>());
}
}
G()->td_db()->get_binlog_pmc()->erase("nsfac");
/*
@ -20030,6 +20032,11 @@ void MessagesManager::send_get_dialog_notification_settings_query(DialogId dialo
void MessagesManager::send_get_scope_notification_settings_query(NotificationSettingsScope scope,
Promise<Unit> &&promise) {
if (td_->auth_manager_->is_bot()) {
LOG(ERROR) << "Can't get notification settings for " << scope;
return promise.set_error(Status::Error(500, "Wrong getScopeNotificationSettings query"));
}
td_->create_handler<GetScopeNotifySettingsQuery>(std::move(promise))->send(scope);
}
@ -23064,7 +23071,7 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
}
if (d->notification_settings.is_synchronized && !d->notification_settings.is_use_default_fixed &&
have_input_peer(dialog_id, AccessRights::Read)) {
have_input_peer(dialog_id, AccessRights::Read) && !td_->auth_manager_->is_bot()) {
LOG(INFO) << "Reget notification settings of " << dialog_id;
if (d->dialog_id.get_type() == DialogType::SecretChat) {
if (d->notification_settings.mute_until == 0 && users_notification_settings_.mute_until == 0) {

View File

@ -141,7 +141,7 @@ void NotificationManager::on_flush_pending_updates_timeout_callback(void *notifi
}
bool NotificationManager::is_disabled() const {
return td_->auth_manager_->is_bot() || G()->close_flag();
return !td_->auth_manager_->is_authorized() || td_->auth_manager_->is_bot() || G()->close_flag();
}
namespace {
@ -179,6 +179,14 @@ string NotificationManager::get_is_contact_registered_notifications_synchronized
}
void NotificationManager::start_up() {
init();
}
void NotificationManager::init() {
if (is_disabled()) {
return;
}
disable_contact_registered_notifications_ =
G()->shared_config().get_option_boolean("disable_contact_registered_notifications");
auto sync_state = G()->td_db()->get_binlog_pmc()->get(get_is_contact_registered_notifications_synchronized_key());
@ -193,10 +201,6 @@ void NotificationManager::start_up() {
run_contact_registered_notifications_sync();
}
if (is_disabled()) {
return;
}
current_notification_id_ =
NotificationId(to_integer<int32>(G()->td_db()->get_binlog_pmc()->get("notification_id_current")));
current_notification_group_id_ =
@ -2136,6 +2140,10 @@ void NotificationManager::on_notification_default_delay_changed() {
}
void NotificationManager::on_disable_contact_registered_notifications_changed() {
if (is_disabled()) {
return;
}
auto is_disabled = G()->shared_config().get_option_boolean("disable_contact_registered_notifications");
if (is_disabled == disable_contact_registered_notifications_) {
@ -2162,6 +2170,10 @@ void NotificationManager::on_get_disable_contact_registered_notifications(bool i
}
void NotificationManager::set_contact_registered_notifications_sync_state(SyncState new_state) {
if (is_disabled()) {
return;
}
contact_registered_notifications_sync_state_ = new_state;
string value;
value += static_cast<char>(static_cast<int32>(new_state) + '0');
@ -2170,6 +2182,10 @@ void NotificationManager::set_contact_registered_notifications_sync_state(SyncSt
}
void NotificationManager::run_contact_registered_notifications_sync() {
if (is_disabled()) {
return;
}
auto is_disabled = disable_contact_registered_notifications_;
if (contact_registered_notifications_sync_state_ == SyncState::NotSynced && !is_disabled) {
set_contact_registered_notifications_sync_state(SyncState::Completed);
@ -2197,13 +2213,16 @@ void NotificationManager::on_contact_registered_notifications_sync(bool is_disab
set_contact_registered_notifications_sync_state(SyncState::Completed);
} else {
// let's resend the query forever
if (!G()->close_flag()) {
run_contact_registered_notifications_sync();
}
}
}
void NotificationManager::get_disable_contact_registered_notifications(Promise<Unit> &&promise) {
if (is_disabled()) {
promise.set_value(Unit());
return;
}
td_->create_handler<GetContactSignUpNotificationQuery>(std::move(promise))->send();
}

View File

@ -46,6 +46,8 @@ class NotificationManager : public Actor {
NotificationManager(Td *td, ActorShared<> parent);
void init();
size_t get_max_notification_group_size() const;
NotificationId get_max_notification_id() const;