Remove error-prone server_time_cached.

This commit is contained in:
levlam 2023-10-04 12:24:58 +03:00
parent 2a0d757ec6
commit 74679944af
14 changed files with 97 additions and 97 deletions

View File

@ -150,7 +150,7 @@ static void save_app_log_impl(Td *td, telegram_api::object_ptr<telegram_api::inp
void save_app_log(Td *td, const string &type, DialogId dialog_id, tl_object_ptr<telegram_api::JSONValue> &&data,
Promise<Unit> &&promise) {
CHECK(data != nullptr);
auto input_app_event = telegram_api::make_object<telegram_api::inputAppEvent>(G()->server_time_cached(), type,
auto input_app_event = telegram_api::make_object<telegram_api::inputAppEvent>(G()->server_time(), type,
dialog_id.get(), std::move(data));
save_app_log_impl(td, std::move(input_app_event), 0, std::move(promise));
}

View File

@ -3868,8 +3868,9 @@ ContactsManager::ContactsManager(Td *td, ActorShared<> parent) : td_(td), parent
was_online_local_ = to_integer<int32>(G()->td_db()->get_binlog_pmc()->get("my_was_online_local"));
was_online_remote_ = to_integer<int32>(G()->td_db()->get_binlog_pmc()->get("my_was_online_remote"));
if (was_online_local_ >= G()->unix_time_cached() && !td_->is_online()) {
was_online_local_ = G()->unix_time_cached() - 1;
auto unix_time = G()->unix_time();
if (was_online_local_ >= unix_time && !td_->is_online()) {
was_online_local_ = unix_time - 1;
}
location_visibility_expire_date_ =
@ -3998,7 +3999,8 @@ void ContactsManager::on_user_online_timeout(UserId user_id) {
LOG(INFO) << "Update " << user_id << " online status to offline";
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateUserStatus>(user_id.get(), get_user_status_object(user_id, u)));
td_api::make_object<td_api::updateUserStatus>(user_id.get(),
get_user_status_object(user_id, u, G()->unix_time())));
update_user_online_member_count(u);
}
@ -5960,14 +5962,14 @@ void ContactsManager::set_my_online_status(bool is_online, bool send_update, boo
User *u = get_user_force(my_id, "set_my_online_status");
if (u != nullptr) {
int32 new_online;
int32 now = G()->unix_time();
int32 unix_time = G()->unix_time();
if (is_online) {
new_online = now + 300;
new_online = unix_time + 300;
} else {
new_online = now - 1;
new_online = unix_time - 1;
}
auto old_was_online = get_user_was_online(u, my_id);
auto old_was_online = get_user_was_online(u, my_id, unix_time);
if (is_local) {
LOG(INFO) << "Update my local online from " << my_was_online_local_ << " to " << new_online;
if (!is_online) {
@ -5984,7 +5986,7 @@ void ContactsManager::set_my_online_status(bool is_online, bool send_update, boo
u->need_save_to_database = true;
}
}
if (old_was_online != get_user_was_online(u, my_id)) {
if (old_was_online != get_user_was_online(u, my_id, unix_time)) {
u->is_status_changed = true;
u->is_online_status_changed = true;
}
@ -6004,7 +6006,7 @@ void ContactsManager::set_my_online_status(bool is_online, bool send_update, boo
ContactsManager::MyOnlineStatusInfo ContactsManager::get_my_online_status() const {
MyOnlineStatusInfo status_info;
status_info.is_online_local = td_->is_online();
status_info.is_online_remote = was_online_remote_ > G()->unix_time_cached();
status_info.is_online_remote = was_online_remote_ > G()->unix_time();
status_info.was_online_local = was_online_local_;
status_info.was_online_remote = was_online_remote_;
@ -6184,7 +6186,7 @@ bool ContactsManager::is_allowed_username(const string &username) {
return true;
}
int32 ContactsManager::get_user_was_online(const User *u, UserId user_id) const {
int32 ContactsManager::get_user_was_online(const User *u, UserId user_id, int32 unix_time) const {
if (u == nullptr || u->is_deleted) {
return 0;
}
@ -6195,7 +6197,7 @@ int32 ContactsManager::get_user_was_online(const User *u, UserId user_id) const
was_online = my_was_online_local_;
}
} else {
if (u->local_was_online > 0 && u->local_was_online > was_online && u->local_was_online > G()->unix_time_cached()) {
if (u->local_was_online > 0 && u->local_was_online > was_online && u->local_was_online > unix_time) {
was_online = u->local_was_online;
}
}
@ -11738,8 +11740,9 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
}
u->is_phone_number_changed = false;
}
auto unix_time = G()->unix_time();
if (u->is_status_changed && user_id != get_my_id()) {
auto left_time = get_user_was_online(u, user_id) - G()->server_time_cached();
auto left_time = get_user_was_online(u, user_id, unix_time) - G()->server_time();
if (left_time >= 0 && left_time < 30 * 86400) {
left_time += 2.0; // to guarantee expiration
LOG(DEBUG) << "Set online timeout for " << user_id << " in " << left_time << " seconds";
@ -11762,7 +11765,6 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
}
}
auto unix_time = G()->unix_time();
auto effective_emoji_status = u->emoji_status.get_effective_emoji_status(u->is_premium, unix_time);
if (effective_emoji_status != u->last_sent_emoji_status) {
u->last_sent_emoji_status = effective_emoji_status;
@ -11812,8 +11814,9 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
u->is_status_saved = false;
}
CHECK(u->is_update_user_sent);
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateUserStatus>(user_id.get(), get_user_status_object(user_id, u)));
send_closure(
G()->td(), &Td::send_update,
make_tl_object<td_api::updateUserStatus>(user_id.get(), get_user_status_object(user_id, u, unix_time)));
u->is_status_changed = false;
}
if (u->is_online_status_changed) {
@ -11980,7 +11983,7 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
auto until_date = c->status.get_until_date();
int32 left_time = 0;
if (until_date > 0) {
left_time = until_date - G()->unix_time_cached() + 1;
left_time = until_date - G()->unix_time() + 1;
CHECK(left_time > 0);
}
if (left_time > 0 && left_time < 366 * 86400) {
@ -13581,8 +13584,9 @@ void ContactsManager::on_update_user_online(User *u, UserId user_id, tl_object_p
if (new_online != u->was_online) {
LOG(DEBUG) << "Update " << user_id << " online from " << u->was_online << " to " << new_online;
bool old_is_online = u->was_online > G()->unix_time_cached();
bool new_is_online = new_online > G()->unix_time_cached();
auto unix_time = G()->unix_time();
bool old_is_online = u->was_online > unix_time;
bool new_is_online = new_online > unix_time;
u->was_online = new_online;
u->is_status_changed = true;
if (u->was_online > 0) {
@ -13623,20 +13627,21 @@ void ContactsManager::on_update_user_local_was_online(User *u, UserId user_id, i
if (u->is_deleted || u->is_bot || u->is_support || user_id == get_my_id()) {
return;
}
if (u->was_online > G()->unix_time_cached()) {
int32 unix_time = G()->unix_time();
if (u->was_online > unix_time) {
// if user is currently online, ignore local online
return;
}
// bring users online for 30 seconds
local_was_online += 30;
if (local_was_online < G()->unix_time_cached() + 2 || local_was_online <= u->local_was_online ||
if (local_was_online < unix_time + 2 || local_was_online <= u->local_was_online ||
local_was_online <= u->was_online) {
return;
}
LOG(DEBUG) << "Update " << user_id << " local online from " << u->local_was_online << " to " << local_was_online;
bool old_is_online = u->local_was_online > G()->unix_time_cached();
bool old_is_online = u->local_was_online > unix_time;
u->local_was_online = local_was_online;
u->is_status_changed = true;
@ -14097,7 +14102,7 @@ void ContactsManager::update_user_online_member_count(User *u) {
return;
}
auto now = G()->unix_time_cached();
auto now = G()->unix_time();
vector<DialogId> expired_dialog_ids;
for (const auto &it : u->online_member_dialogs) {
auto dialog_id = it.first;
@ -14160,7 +14165,7 @@ void ContactsManager::update_dialog_online_member_count(const vector<DialogParti
CHECK(dialog_id.is_valid());
int32 online_member_count = 0;
int32 time = G()->unix_time();
int32 unix_time = G()->unix_time();
for (const auto &participant : participants) {
if (participant.dialog_id_.get_type() != DialogType::User) {
continue;
@ -14168,11 +14173,11 @@ void ContactsManager::update_dialog_online_member_count(const vector<DialogParti
auto user_id = participant.dialog_id_.get_user_id();
auto u = get_user(user_id);
if (u != nullptr && !u->is_deleted && !u->is_bot) {
if (get_user_was_online(u, user_id) > time) {
if (get_user_was_online(u, user_id, unix_time) > unix_time) {
online_member_count++;
}
if (is_from_server) {
u->online_member_dialogs[dialog_id] = time;
u->online_member_dialogs[dialog_id] = unix_time;
}
}
}
@ -16737,8 +16742,9 @@ Result<ContactsManager::BotData> ContactsManager::get_bot_data(UserId user_id) c
}
bool ContactsManager::is_user_online(UserId user_id, int32 tolerance) const {
int32 was_online = get_user_was_online(get_user(user_id), user_id);
return was_online > G()->unix_time() - tolerance;
auto unix_time = G()->unix_time();
int32 was_online = get_user_was_online(get_user(user_id), user_id, unix_time);
return was_online > unix_time - tolerance;
}
bool ContactsManager::is_user_status_exact(UserId user_id) const {
@ -17858,6 +17864,7 @@ std::pair<int32, vector<DialogId>> ContactsManager::search_among_dialogs(const v
const string &query, int32 limit) const {
Hints hints; // TODO cache Hints
auto unix_time = G()->unix_time();
for (auto dialog_id : dialog_ids) {
int64 rating = 0;
if (dialog_id.get_type() == DialogType::User) {
@ -17871,7 +17878,7 @@ std::pair<int32, vector<DialogId>> ContactsManager::search_among_dialogs(const v
} else {
hints.add(dialog_id.get(), get_user_search_text(u));
}
rating = -get_user_was_online(u, user_id);
rating = -get_user_was_online(u, user_id, unix_time);
} else {
if (!td_->messages_manager_->have_dialog_info(dialog_id)) {
continue;
@ -19085,12 +19092,13 @@ void ContactsManager::on_upload_profile_photo_error(FileId file_id, Status statu
promise.set_error(std::move(status)); // TODO check that status has valid error code
}
td_api::object_ptr<td_api::UserStatus> ContactsManager::get_user_status_object(UserId user_id, const User *u) const {
td_api::object_ptr<td_api::UserStatus> ContactsManager::get_user_status_object(UserId user_id, const User *u,
int32 unix_time) const {
if (u->is_bot) {
return make_tl_object<td_api::userStatusOnline>(std::numeric_limits<int32>::max());
}
int32 was_online = get_user_was_online(u, user_id);
int32 was_online = get_user_was_online(u, user_id, unix_time);
switch (was_online) {
case -3:
return make_tl_object<td_api::userStatusLastMonth>();
@ -19164,9 +19172,10 @@ tl_object_ptr<td_api::user> ContactsManager::get_user_object(UserId user_id, con
auto have_access = user_id == get_my_id() || have_input_peer_user(u, user_id, AccessRights::Know);
return td_api::make_object<td_api::user>(
user_id.get(), u->first_name, u->last_name, u->usernames.get_usernames_object(), u->phone_number,
get_user_status_object(user_id, u), get_profile_photo_object(td_->file_manager_.get(), u->photo),
std::move(emoji_status), u->is_contact, u->is_mutual_contact, u->is_close_friend, u->is_verified, u->is_premium,
u->is_support, get_restriction_reason_description(u->restriction_reasons), u->is_scam, u->is_fake,
get_user_status_object(user_id, u, G()->unix_time()),
get_profile_photo_object(td_->file_manager_.get(), u->photo), std::move(emoji_status), u->is_contact,
u->is_mutual_contact, u->is_close_friend, u->is_verified, u->is_premium, u->is_support,
get_restriction_reason_description(u->restriction_reasons), u->is_scam, u->is_fake,
u->max_active_story_id.is_valid(), get_user_has_unread_stories(u), have_access, std::move(type), u->language_code,
u->attach_menu_enabled);
}

View File

@ -1614,7 +1614,7 @@ class ContactsManager final : public Actor {
static bool is_user_bot(const User *u);
int32 get_user_was_online(const User *u, UserId user_id) const;
int32 get_user_was_online(const User *u, UserId user_id, int32 unix_time) const;
int64 get_contacts_hash();
@ -1758,7 +1758,7 @@ class ContactsManager final : public Actor {
td_api::object_ptr<td_api::updateUser> get_update_unknown_user_object(UserId user_id) const;
td_api::object_ptr<td_api::UserStatus> get_user_status_object(UserId user_id, const User *u) const;
td_api::object_ptr<td_api::UserStatus> get_user_status_object(UserId user_id, const User *u, int32 unix_time) const;
tl_object_ptr<td_api::user> get_user_object(UserId user_id, const User *u) const;

View File

@ -146,21 +146,12 @@ class Global final : public ActorContext {
bool is_server_time_reliable() const {
return server_time_difference_was_updated_.load(std::memory_order_relaxed);
}
double to_server_time(double now) const {
return now + get_server_time_difference();
}
double server_time() const {
return to_server_time(Time::now());
}
double server_time_cached() const {
return to_server_time(Time::now_cached());
return Time::now() + get_server_time_difference();
}
int32 unix_time() const {
return to_unix_time(server_time());
}
int32 unix_time_cached() const {
return to_unix_time(server_time_cached());
}
void update_server_time_difference(double diff, bool force);

View File

@ -1095,8 +1095,8 @@ void InlineQueriesManager::loop() {
pending_inline_query_ = nullptr;
} else {
if (!has_timeout()) {
LOG(INFO) << "Schedule send inline query " << pending_inline_query_->query_hash << " at "
<< G()->to_server_time(next_inline_query_time_);
LOG(INFO) << "Schedule send inline query " << pending_inline_query_->query_hash << " in "
<< next_inline_query_time_ - now;
set_timeout_at(next_inline_query_time_);
}
}

View File

@ -5787,7 +5787,7 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
}
case MessageContentType::LiveLocation: {
const auto *m = static_cast<const MessageLiveLocation *>(content);
auto passed = max(G()->unix_time_cached() - message_date, 0);
auto passed = max(G()->unix_time() - message_date, 0);
auto expires_in = max(0, m->period - passed);
auto heading = expires_in == 0 ? 0 : m->heading;
auto proximity_alert_radius = expires_in == 0 ? 0 : m->proximity_alert_radius;

View File

@ -7632,7 +7632,7 @@ void MessagesManager::on_dialog_action(DialogId dialog_id, MessageId top_thread_
active_dialog_action_timeout_.cancel_timeout(dialog_id.get());
}
} else {
if (date < G()->unix_time_cached() - DIALOG_ACTION_TIMEOUT - 60) {
if (date < G()->unix_time() - DIALOG_ACTION_TIMEOUT - 60) {
LOG(DEBUG) << "Ignore too old action of " << typing_dialog_id << " in " << dialog_id << " sent at " << date;
return;
}
@ -8060,10 +8060,9 @@ bool MessagesManager::update_dialog_notification_settings(DialogId dialog_id,
return need_update.need_update_server;
}
void MessagesManager::schedule_dialog_unmute(DialogId dialog_id, bool use_default, int32 mute_until) {
auto now = G()->unix_time_cached();
if (!use_default && mute_until >= now && mute_until < now + 366 * 86400) {
dialog_unmute_timeout_.set_timeout_in(dialog_id.get(), mute_until - now + 1);
void MessagesManager::schedule_dialog_unmute(DialogId dialog_id, bool use_default, int32 mute_until, int32 unix_time) {
if (!use_default && mute_until >= unix_time && mute_until < unix_time + 366 * 86400) {
dialog_unmute_timeout_.set_timeout_in(dialog_id.get(), mute_until - unix_time + 1);
} else {
dialog_unmute_timeout_.cancel_timeout(dialog_id.get());
}
@ -8082,7 +8081,7 @@ void MessagesManager::update_dialog_unmute_timeout(Dialog *d, bool &old_use_defa
CHECK(d != nullptr);
CHECK(old_mute_until >= 0);
schedule_dialog_unmute(d->dialog_id, new_use_default, new_mute_until);
schedule_dialog_unmute(d->dialog_id, new_use_default, new_mute_until, G()->unix_time());
auto scope = get_dialog_notification_setting_scope(d->dialog_id);
auto scope_mute_until = td_->notification_settings_manager_->get_scope_mute_until(scope);
@ -8208,11 +8207,11 @@ void MessagesManager::on_dialog_unmute(DialogId dialog_id) {
return;
}
auto now = G()->unix_time();
if (d->notification_settings.mute_until > now) {
LOG(ERROR) << "Failed to unmute " << dialog_id << " in " << now << ", will be unmuted in "
auto unix_time = G()->unix_time();
if (d->notification_settings.mute_until > unix_time) {
LOG(INFO) << "Failed to unmute " << dialog_id << " in " << unix_time << ", will be unmuted in "
<< d->notification_settings.mute_until;
schedule_dialog_unmute(dialog_id, false, d->notification_settings.mute_until);
schedule_dialog_unmute(dialog_id, false, d->notification_settings.mute_until, unix_time);
return;
}
@ -10737,7 +10736,7 @@ bool MessagesManager::can_delete_channel_message(const DialogParticipantStatus &
return true;
}
if (is_bot && G()->unix_time_cached() >= m->date + 2 * 86400) {
if (is_bot && G()->unix_time() >= m->date + 2 * 86400) {
// bots can't delete messages older than 2 days
return false;
}
@ -10818,12 +10817,12 @@ bool MessagesManager::can_revoke_message(DialogId dialog_id, const Message *m) c
int64 revoke_time_limit =
td_->option_manager_->get_option_integer("revoke_pm_time_limit", DEFAULT_REVOKE_TIME_LIMIT);
if (G()->unix_time_cached() - m->date < 86400 && content_type == MessageContentType::Dice) {
if (G()->unix_time() - m->date < 86400 && content_type == MessageContentType::Dice) {
return false;
}
return ((m->is_outgoing && !is_service_message_content(content_type)) ||
(can_revoke_incoming && content_type != MessageContentType::ScreenshotTaken)) &&
G()->unix_time_cached() - m->date <= revoke_time_limit;
G()->unix_time() - m->date <= revoke_time_limit;
}
case DialogType::Chat: {
bool is_appointed_administrator =
@ -10832,7 +10831,7 @@ bool MessagesManager::can_revoke_message(DialogId dialog_id, const Message *m) c
td_->option_manager_->get_option_integer("revoke_time_limit", DEFAULT_REVOKE_TIME_LIMIT);
return ((m->is_outgoing && !is_service_message_content(content_type)) || is_appointed_administrator) &&
G()->unix_time_cached() - m->date <= revoke_time_limit;
G()->unix_time() - m->date <= revoke_time_limit;
}
case DialogType::Channel:
return true; // any server message that can be deleted will be deleted for all participants
@ -11734,8 +11733,7 @@ void MessagesManager::unload_dialog(DialogId dialog_id, int32 delay) {
}
bool has_left_to_unload_messages = false;
auto to_unload_message_ids =
find_unloadable_messages(d, G()->unix_time_cached() - delay, has_left_to_unload_messages);
auto to_unload_message_ids = find_unloadable_messages(d, G()->unix_time() - delay, has_left_to_unload_messages);
vector<int64> unloaded_message_ids;
vector<unique_ptr<Message>> unloaded_messages;
@ -26191,7 +26189,7 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo
if (has_edit_time_limit) {
const int32 DEFAULT_EDIT_TIME_LIMIT = 2 * 86400;
int64 edit_time_limit = td_->option_manager_->get_option_integer("edit_time_limit", DEFAULT_EDIT_TIME_LIMIT);
if (G()->unix_time_cached() - m->date - (is_editing ? 300 : 0) >= edit_time_limit) {
if (G()->unix_time() - m->date - (is_editing ? 300 : 0) >= edit_time_limit) {
return false;
}
}
@ -26211,7 +26209,7 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo
// there is no caption to edit, but bot can edit inline reply_markup
return true;
}
return G()->unix_time_cached() - m->date < get_message_content_live_location_period(m->content.get());
return G()->unix_time() - m->date < get_message_content_live_location_period(m->content.get());
}
case MessageContentType::Poll: {
if (is_bot && only_reply_markup) {
@ -34026,7 +34024,7 @@ const MessagesManager::Message *MessagesManager::get_message(const Dialog *d, Me
} else {
result = d->messages.get_pointer(message_id);
if (result != nullptr) {
auto unix_time = G()->unix_time_cached();
auto unix_time = G()->unix_time();
if (unix_time > result->last_access_date + 5) {
result->last_access_date = unix_time;
auto list_node = const_cast<ListNode *>(static_cast<const ListNode *>(result));
@ -34263,7 +34261,7 @@ void MessagesManager::fix_new_message(const Dialog *d, Message *m, bool from_dat
}
}
m->last_access_date = G()->unix_time_cached();
m->last_access_date = G()->unix_time();
if (m->contains_mention) {
CHECK(!td_->auth_manager_->is_bot());
@ -34287,7 +34285,7 @@ void MessagesManager::fix_new_message(const Dialog *d, Message *m, bool from_dat
if (dialog_type == DialogType::Channel && !m->contains_unread_mention) {
auto channel_read_media_period =
td_->option_manager_->get_option_integer("channels_read_media_period", (G()->is_test_dc() ? 300 : 7 * 86400));
if (m->date < G()->unix_time_cached() - channel_read_media_period) {
if (m->date < G()->unix_time() - channel_read_media_period) {
update_opened_message_content(m->content.get());
}
}
@ -34815,7 +34813,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
}
if (from_update && !m->is_failed_to_send && dialog_type == DialogType::Channel) {
auto now = max(G()->unix_time_cached(), m->date);
auto now = max(G()->unix_time(), m->date);
if (m->date < now - 2 * 86400 && Slice(source) == Slice("updateNewChannelMessage")) {
// if the message is pretty old, we might have missed the update that the message has already been read
repair_channel_server_unread_count(d);
@ -36604,7 +36602,7 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
d->notification_settings.mute_until <= G()->unix_time()) {
d->notification_settings.mute_until = 0;
} else {
schedule_dialog_unmute(dialog_id, false, d->notification_settings.mute_until);
schedule_dialog_unmute(dialog_id, false, d->notification_settings.mute_until, G()->unix_time());
}
if (d->notification_info != nullptr && d->notification_info->pinned_message_notification_message_id_.is_valid()) {
auto pinned_message_id = d->notification_info->pinned_message_notification_message_id_;

View File

@ -2634,7 +2634,7 @@ class MessagesManager final : public Actor {
bool update_dialog_notification_settings(DialogId dialog_id, DialogNotificationSettings *current_settings,
DialogNotificationSettings &&new_settings);
void schedule_dialog_unmute(DialogId dialog_id, bool use_default, int32 mute_until);
void schedule_dialog_unmute(DialogId dialog_id, bool use_default, int32 mute_until, int32 unix_time);
void update_dialog_unmute_timeout(Dialog *d, bool &old_use_default, int32 &old_mute_until, bool new_use_default,
int32 new_mute_until);

View File

@ -843,6 +843,7 @@ int32 NotificationManager::get_notification_delay_ms(DialogId dialog_id, const P
return MIN_NOTIFICATION_DELAY_MS;
}
auto server_time = G()->server_time();
auto delay_ms = [&] {
auto online_info = td_->contacts_manager_->get_my_online_status();
if (!online_info.is_online_local && online_info.is_online_remote) {
@ -852,8 +853,8 @@ int32 NotificationManager::get_notification_delay_ms(DialogId dialog_id, const P
}
if (!online_info.is_online_local &&
online_info.was_online_remote > max(static_cast<double>(online_info.was_online_local),
G()->server_time_cached() - online_cloud_timeout_ms_ * 1e-3)) {
online_info.was_online_remote >
max(static_cast<double>(online_info.was_online_local), server_time - online_cloud_timeout_ms_ * 1e-3)) {
// If we are offline, but was online from some other client in last 'online_cloud_timeout' seconds
// after we had gone offline, then delay notification for 'notification_cloud_delay' seconds.
return notification_cloud_delay_ms_;
@ -868,8 +869,7 @@ int32 NotificationManager::get_notification_delay_ms(DialogId dialog_id, const P
return 0;
}();
auto passed_time_ms =
static_cast<int32>(clamp(G()->server_time_cached() - notification.date - 1, 0.0, 1000000.0) * 1000);
auto passed_time_ms = static_cast<int32>(clamp(server_time - notification.date - 1, 0.0, 1000000.0) * 1000);
return max(max(min_delay_ms, delay_ms) - passed_time_ms, MIN_NOTIFICATION_DELAY_MS);
}

View File

@ -590,7 +590,7 @@ void NotificationSettingsManager::init() {
VLOG(notifications) << "Loaded notification settings in " << scope << ": " << *current_settings;
schedule_scope_unmute(scope, current_settings->mute_until);
schedule_scope_unmute(scope, current_settings->mute_until, G()->unix_time());
send_closure(G()->td(), &Td::send_update, get_update_scope_notification_settings_object(scope));
}
@ -728,11 +728,11 @@ void NotificationSettingsManager::on_scope_unmute(NotificationSettingsScope scop
return;
}
auto now = G()->unix_time();
if (notification_settings->mute_until > now) {
LOG(ERROR) << "Failed to unmute " << scope << " in " << now << ", will be unmuted in "
auto unix_time = G()->unix_time();
if (notification_settings->mute_until > unix_time) {
LOG(INFO) << "Failed to unmute " << scope << " in " << unix_time << ", will be unmuted in "
<< notification_settings->mute_until;
schedule_scope_unmute(scope, notification_settings->mute_until);
schedule_scope_unmute(scope, notification_settings->mute_until, unix_time);
return;
}
@ -824,10 +824,10 @@ bool NotificationSettingsManager::update_scope_notification_settings(Notificatio
return need_update_server;
}
void NotificationSettingsManager::schedule_scope_unmute(NotificationSettingsScope scope, int32 mute_until) {
auto now = G()->unix_time_cached();
if (mute_until >= now && mute_until < now + 366 * 86400) {
scope_unmute_timeout_.set_timeout_in(static_cast<int64>(scope) + 1, mute_until - now + 1);
void NotificationSettingsManager::schedule_scope_unmute(NotificationSettingsScope scope, int32 mute_until,
int32 unix_time) {
if (mute_until >= unix_time && mute_until < unix_time + 366 * 86400) {
scope_unmute_timeout_.set_timeout_in(static_cast<int64>(scope) + 1, mute_until - unix_time + 1);
} else {
scope_unmute_timeout_.cancel_timeout(static_cast<int64>(scope) + 1);
}
@ -846,7 +846,7 @@ void NotificationSettingsManager::update_scope_unmute_timeout(NotificationSettin
}
CHECK(old_mute_until >= 0);
schedule_scope_unmute(scope, new_mute_until);
schedule_scope_unmute(scope, new_mute_until, G()->unix_time());
auto was_muted = old_mute_until != 0;
auto is_muted = new_mute_until != 0;

View File

@ -188,7 +188,7 @@ class NotificationSettingsManager final : public Actor {
void update_scope_notification_settings_on_server(NotificationSettingsScope scope, uint64 log_event_id);
void schedule_scope_unmute(NotificationSettingsScope scope, int32 mute_until);
void schedule_scope_unmute(NotificationSettingsScope scope, int32 mute_until, int32 unix_time);
void update_scope_unmute_timeout(NotificationSettingsScope scope, int32 &old_mute_until, int32 new_mute_until);

View File

@ -32,10 +32,11 @@
namespace td {
tl_object_ptr<td_api::temporaryPasswordState> TempPasswordState::get_temporary_password_state_object() const {
if (!has_temp_password || valid_until <= G()->unix_time()) {
auto unix_time = G()->unix_time();
if (!has_temp_password || valid_until <= unix_time) {
return make_tl_object<td_api::temporaryPasswordState>(false, 0);
}
return make_tl_object<td_api::temporaryPasswordState>(true, valid_until - G()->unix_time_cached());
return make_tl_object<td_api::temporaryPasswordState>(true, valid_until - unix_time);
}
static void hash_sha256(Slice data, Slice salt, MutableSlice dest) {

View File

@ -351,14 +351,15 @@ double TopDialogManager::rating_add(double now, double rating_timestamp) const {
return std::exp((now - rating_timestamp) / rating_e_decay_);
}
double TopDialogManager::current_rating_add(double rating_timestamp) const {
return rating_add(G()->server_time_cached(), rating_timestamp);
double TopDialogManager::current_rating_add(double server_time, double rating_timestamp) const {
return rating_add(server_time, rating_timestamp);
}
void TopDialogManager::normalize_rating() {
auto server_time = G()->server_time();
for (auto &top_dialogs : by_category_) {
auto div_by = current_rating_add(top_dialogs.rating_timestamp);
top_dialogs.rating_timestamp = G()->server_time_cached();
auto div_by = current_rating_add(server_time, top_dialogs.rating_timestamp);
top_dialogs.rating_timestamp = server_time;
for (auto &dialog : top_dialogs.dialogs) {
dialog.rating /= div_by;
}

View File

@ -99,7 +99,7 @@ class TopDialogManager final : public Actor {
std::array<TopDialogs, static_cast<size_t>(TopDialogCategory::Size)> by_category_;
double rating_add(double now, double rating_timestamp) const;
double current_rating_add(double rating_timestamp) const;
double current_rating_add(double server_time, double rating_timestamp) const;
void normalize_rating();
bool set_is_enabled(bool is_enabled);