2018-09-29 02:29:57 +02:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2018-09-29 02:29:57 +02:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
2022-10-25 00:22:04 +02:00
|
|
|
#include "td/telegram/DialogNotificationSettings.h"
|
2019-01-06 20:59:17 +01:00
|
|
|
#include "td/telegram/Global.h"
|
2022-04-11 19:01:44 +02:00
|
|
|
#include "td/telegram/NotificationSound.h"
|
2018-09-29 02:29:57 +02:00
|
|
|
|
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const DialogNotificationSettings ¬ification_settings, StorerT &storer) {
|
|
|
|
bool is_muted = !notification_settings.use_default_mute_until && notification_settings.mute_until != 0 &&
|
|
|
|
notification_settings.mute_until > G()->unix_time();
|
2022-04-11 19:01:44 +02:00
|
|
|
bool has_sound = notification_settings.sound != nullptr;
|
|
|
|
bool has_ringtone_support = true;
|
2023-06-12 19:09:23 +02:00
|
|
|
bool use_mute_stories = !notification_settings.use_default_mute_stories;
|
2023-06-27 18:09:43 +02:00
|
|
|
bool has_story_sound = notification_settings.story_sound != nullptr;
|
|
|
|
bool use_hide_story_sender = !notification_settings.use_default_hide_story_sender;
|
2018-09-29 02:29:57 +02:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(is_muted);
|
|
|
|
STORE_FLAG(has_sound);
|
|
|
|
STORE_FLAG(notification_settings.show_preview);
|
|
|
|
STORE_FLAG(notification_settings.silent_send_message);
|
|
|
|
STORE_FLAG(notification_settings.is_synchronized);
|
|
|
|
STORE_FLAG(notification_settings.use_default_mute_until);
|
2022-04-11 19:01:44 +02:00
|
|
|
STORE_FLAG(false); // use_default_sound
|
2018-09-29 02:29:57 +02:00
|
|
|
STORE_FLAG(notification_settings.use_default_show_preview);
|
|
|
|
STORE_FLAG(notification_settings.is_use_default_fixed);
|
2019-01-10 18:54:46 +01:00
|
|
|
STORE_FLAG(!notification_settings.use_default_disable_pinned_message_notifications);
|
|
|
|
STORE_FLAG(notification_settings.disable_pinned_message_notifications);
|
|
|
|
STORE_FLAG(!notification_settings.use_default_disable_mention_notifications);
|
|
|
|
STORE_FLAG(notification_settings.disable_mention_notifications);
|
2019-02-18 00:41:53 +01:00
|
|
|
STORE_FLAG(notification_settings.is_secret_chat_show_preview_fixed);
|
2022-04-11 19:01:44 +02:00
|
|
|
STORE_FLAG(has_ringtone_support);
|
2023-06-12 19:09:23 +02:00
|
|
|
STORE_FLAG(notification_settings.mute_stories);
|
|
|
|
STORE_FLAG(use_mute_stories);
|
2023-06-27 18:09:43 +02:00
|
|
|
STORE_FLAG(has_story_sound);
|
|
|
|
STORE_FLAG(notification_settings.hide_story_sender);
|
|
|
|
STORE_FLAG(use_hide_story_sender);
|
2018-09-29 02:29:57 +02:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
if (is_muted) {
|
|
|
|
store(notification_settings.mute_until, storer);
|
|
|
|
}
|
|
|
|
if (has_sound) {
|
|
|
|
store(notification_settings.sound, storer);
|
|
|
|
}
|
2023-06-27 18:09:43 +02:00
|
|
|
if (has_story_sound) {
|
|
|
|
store(notification_settings.story_sound, storer);
|
|
|
|
}
|
2018-09-29 02:29:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(DialogNotificationSettings ¬ification_settings, ParserT &parser) {
|
|
|
|
bool is_muted;
|
|
|
|
bool has_sound;
|
2022-04-11 19:01:44 +02:00
|
|
|
bool use_default_sound;
|
2019-01-10 18:54:46 +01:00
|
|
|
bool use_disable_pinned_message_notifications;
|
|
|
|
bool use_disable_mention_notifications;
|
2022-04-11 19:01:44 +02:00
|
|
|
bool has_ringtone_support;
|
2023-06-12 19:09:23 +02:00
|
|
|
bool use_mute_stories;
|
2023-06-27 18:09:43 +02:00
|
|
|
bool has_story_sound;
|
|
|
|
bool use_hide_story_sender;
|
2018-09-29 02:29:57 +02:00
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(is_muted);
|
|
|
|
PARSE_FLAG(has_sound);
|
|
|
|
PARSE_FLAG(notification_settings.show_preview);
|
|
|
|
PARSE_FLAG(notification_settings.silent_send_message);
|
|
|
|
PARSE_FLAG(notification_settings.is_synchronized);
|
|
|
|
PARSE_FLAG(notification_settings.use_default_mute_until);
|
2022-04-11 19:01:44 +02:00
|
|
|
PARSE_FLAG(use_default_sound);
|
2018-09-29 02:29:57 +02:00
|
|
|
PARSE_FLAG(notification_settings.use_default_show_preview);
|
|
|
|
PARSE_FLAG(notification_settings.is_use_default_fixed);
|
2019-01-10 18:54:46 +01:00
|
|
|
PARSE_FLAG(use_disable_pinned_message_notifications);
|
|
|
|
PARSE_FLAG(notification_settings.disable_pinned_message_notifications);
|
|
|
|
PARSE_FLAG(use_disable_mention_notifications);
|
|
|
|
PARSE_FLAG(notification_settings.disable_mention_notifications);
|
2019-02-18 00:41:53 +01:00
|
|
|
PARSE_FLAG(notification_settings.is_secret_chat_show_preview_fixed);
|
2022-04-11 19:01:44 +02:00
|
|
|
PARSE_FLAG(has_ringtone_support);
|
2023-06-12 19:09:23 +02:00
|
|
|
PARSE_FLAG(notification_settings.mute_stories);
|
|
|
|
PARSE_FLAG(use_mute_stories);
|
2023-06-27 18:09:43 +02:00
|
|
|
PARSE_FLAG(has_story_sound);
|
|
|
|
PARSE_FLAG(notification_settings.hide_story_sender);
|
|
|
|
PARSE_FLAG(use_hide_story_sender);
|
2018-09-29 02:29:57 +02:00
|
|
|
END_PARSE_FLAGS();
|
2019-01-10 18:54:46 +01:00
|
|
|
notification_settings.use_default_disable_pinned_message_notifications = !use_disable_pinned_message_notifications;
|
|
|
|
notification_settings.use_default_disable_mention_notifications = !use_disable_mention_notifications;
|
2023-06-12 19:09:23 +02:00
|
|
|
notification_settings.use_default_mute_stories = !use_mute_stories;
|
2023-06-27 18:09:43 +02:00
|
|
|
notification_settings.use_default_hide_story_sender = !use_hide_story_sender;
|
2018-09-29 02:29:57 +02:00
|
|
|
if (is_muted) {
|
|
|
|
parse(notification_settings.mute_until, parser);
|
|
|
|
}
|
|
|
|
if (has_sound) {
|
2022-04-11 19:01:44 +02:00
|
|
|
if (has_ringtone_support) {
|
|
|
|
parse_notification_sound(notification_settings.sound, parser);
|
|
|
|
} else {
|
|
|
|
string sound;
|
|
|
|
parse(sound, parser);
|
|
|
|
notification_settings.sound = use_default_sound ? nullptr : get_legacy_notification_sound(sound);
|
|
|
|
}
|
2018-09-29 02:29:57 +02:00
|
|
|
}
|
2023-06-27 18:09:43 +02:00
|
|
|
if (has_story_sound) {
|
|
|
|
parse_notification_sound(notification_settings.story_sound, parser);
|
|
|
|
}
|
2018-09-29 02:29:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|