Add static get_mute_until function.

GitOrigin-RevId: 8b265d6a76ca9741b6c5177597cc717dbcac9fe5
This commit is contained in:
levlam 2019-12-29 04:08:10 +03:00
parent 6903886372
commit 104623f179

View File

@ -115,6 +115,18 @@ NotificationSettingsScope get_notification_settings_scope(
} }
} }
static int32 get_mute_until(int32 mute_for) {
if (mute_for <= 0) {
return 0;
}
int32 current_time = G()->unix_time();
if (mute_for >= std::numeric_limits<int32>::max() - current_time) {
return std::numeric_limits<int32>::max();
}
return mute_for + current_time;
}
Result<DialogNotificationSettings> get_dialog_notification_settings( Result<DialogNotificationSettings> get_dialog_notification_settings(
td_api::object_ptr<td_api::chatNotificationSettings> &&notification_settings, bool old_silent_send_message) { td_api::object_ptr<td_api::chatNotificationSettings> &&notification_settings, bool old_silent_send_message) {
if (notification_settings == nullptr) { if (notification_settings == nullptr) {
@ -127,18 +139,8 @@ Result<DialogNotificationSettings> get_dialog_notification_settings(
notification_settings->sound_ = "default"; notification_settings->sound_ = "default";
} }
int32 current_time = G()->unix_time(); int32 mute_until =
if (notification_settings->mute_for_ > std::numeric_limits<int32>::max() - current_time) { notification_settings->use_default_mute_for_ ? 0 : get_mute_until(notification_settings->mute_for_);
notification_settings->mute_for_ = std::numeric_limits<int32>::max() - current_time;
}
int32 mute_until;
if (notification_settings->use_default_mute_for_ || notification_settings->mute_for_ <= 0) {
mute_until = 0;
} else {
mute_until = notification_settings->mute_for_ + current_time;
}
return DialogNotificationSettings(notification_settings->use_default_mute_for_, mute_until, return DialogNotificationSettings(notification_settings->use_default_mute_for_, mute_until,
notification_settings->use_default_sound_, std::move(notification_settings->sound_), notification_settings->use_default_sound_, std::move(notification_settings->sound_),
notification_settings->use_default_show_preview_, notification_settings->use_default_show_preview_,
@ -161,18 +163,7 @@ Result<ScopeNotificationSettings> get_scope_notification_settings(
notification_settings->sound_ = "default"; notification_settings->sound_ = "default";
} }
int32 current_time = G()->unix_time(); auto mute_until = get_mute_until(notification_settings->mute_for_);
if (notification_settings->mute_for_ > std::numeric_limits<int32>::max() - current_time) {
notification_settings->mute_for_ = std::numeric_limits<int32>::max() - current_time;
}
int32 mute_until;
if (notification_settings->mute_for_ <= 0) {
mute_until = 0;
} else {
mute_until = notification_settings->mute_for_ + current_time;
}
return ScopeNotificationSettings(mute_until, std::move(notification_settings->sound_), return ScopeNotificationSettings(mute_until, std::move(notification_settings->sound_),
notification_settings->show_preview_, notification_settings->show_preview_,
notification_settings->disable_pinned_message_notifications_, notification_settings->disable_pinned_message_notifications_,