diff --git a/CMakeLists.txt b/CMakeLists.txt index 6097dbe13..affd6ca02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -427,6 +427,7 @@ set(TDLIB_SOURCE td/telegram/net/SessionMultiProxy.cpp td/telegram/NewPasswordState.cpp td/telegram/NotificationGroupInfo.cpp + td/telegram/NotificationGroupType.cpp td/telegram/NotificationManager.cpp td/telegram/NotificationSettingsScope.cpp td/telegram/NotificationSettingsManager.cpp diff --git a/td/telegram/NotificationGroupType.cpp b/td/telegram/NotificationGroupType.cpp new file mode 100644 index 000000000..efc5eecaa --- /dev/null +++ b/td/telegram/NotificationGroupType.cpp @@ -0,0 +1,88 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// 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) +// +#include "td/telegram/NotificationGroupType.h" + +namespace td { + +bool is_database_notification_group_type(NotificationGroupType type) { + switch (type) { + case NotificationGroupType::Messages: + case NotificationGroupType::Mentions: + case NotificationGroupType::SecretChat: + return true; + case NotificationGroupType::Calls: + return false; + default: + UNREACHABLE(); + return false; + } +} + +bool is_partial_notification_group_type(NotificationGroupType type) { + switch (type) { + case NotificationGroupType::Messages: + case NotificationGroupType::Mentions: + return true; + case NotificationGroupType::SecretChat: + case NotificationGroupType::Calls: + return false; + default: + UNREACHABLE(); + return false; + } +} + +td_api::object_ptr get_notification_group_type_object(NotificationGroupType type) { + switch (type) { + case NotificationGroupType::Messages: + return td_api::make_object(); + case NotificationGroupType::Mentions: + return td_api::make_object(); + case NotificationGroupType::SecretChat: + return td_api::make_object(); + case NotificationGroupType::Calls: + return td_api::make_object(); + default: + UNREACHABLE(); + return nullptr; + } +} + +NotificationGroupType get_notification_group_type(const td_api::object_ptr &type) { + CHECK(type != nullptr); + switch (type->get_id()) { + case td_api::notificationGroupTypeMessages::ID: + return NotificationGroupType::Messages; + case td_api::notificationGroupTypeMentions::ID: + return NotificationGroupType::Mentions; + case td_api::notificationGroupTypeSecretChat::ID: + return NotificationGroupType::SecretChat; + case td_api::notificationGroupTypeCalls::ID: + return NotificationGroupType::Calls; + default: + UNREACHABLE(); + return NotificationGroupType::Calls; + } +} + +StringBuilder &operator<<(StringBuilder &string_builder, const NotificationGroupType &type) { + switch (type) { + case NotificationGroupType::Messages: + return string_builder << "Messages"; + case NotificationGroupType::Mentions: + return string_builder << "Mentions"; + case NotificationGroupType::SecretChat: + return string_builder << "SecretChat"; + case NotificationGroupType::Calls: + return string_builder << "Calls"; + default: + UNREACHABLE(); + return string_builder; + } +} + +} // namespace td diff --git a/td/telegram/NotificationGroupType.h b/td/telegram/NotificationGroupType.h index fe4dc3231..7b6a81376 100644 --- a/td/telegram/NotificationGroupType.h +++ b/td/telegram/NotificationGroupType.h @@ -15,83 +15,14 @@ namespace td { enum class NotificationGroupType : int8 { Messages, Mentions, SecretChat, Calls }; -inline bool is_database_notification_group_type(NotificationGroupType type) { - switch (type) { - case NotificationGroupType::Messages: - case NotificationGroupType::Mentions: - case NotificationGroupType::SecretChat: - return true; - case NotificationGroupType::Calls: - return false; - default: - UNREACHABLE(); - return false; - } -} +bool is_database_notification_group_type(NotificationGroupType type); -inline bool is_partial_notification_group_type(NotificationGroupType type) { - switch (type) { - case NotificationGroupType::Messages: - case NotificationGroupType::Mentions: - return true; - case NotificationGroupType::SecretChat: - case NotificationGroupType::Calls: - return false; - default: - UNREACHABLE(); - return false; - } -} +bool is_partial_notification_group_type(NotificationGroupType type); -inline td_api::object_ptr get_notification_group_type_object( - NotificationGroupType type) { - switch (type) { - case NotificationGroupType::Messages: - return td_api::make_object(); - case NotificationGroupType::Mentions: - return td_api::make_object(); - case NotificationGroupType::SecretChat: - return td_api::make_object(); - case NotificationGroupType::Calls: - return td_api::make_object(); - default: - UNREACHABLE(); - return nullptr; - } -} +td_api::object_ptr get_notification_group_type_object(NotificationGroupType type); -inline NotificationGroupType get_notification_group_type( - const td_api::object_ptr &type) { - CHECK(type != nullptr); - switch (type->get_id()) { - case td_api::notificationGroupTypeMessages::ID: - return NotificationGroupType::Messages; - case td_api::notificationGroupTypeMentions::ID: - return NotificationGroupType::Mentions; - case td_api::notificationGroupTypeSecretChat::ID: - return NotificationGroupType::SecretChat; - case td_api::notificationGroupTypeCalls::ID: - return NotificationGroupType::Calls; - default: - UNREACHABLE(); - return NotificationGroupType::Calls; - } -} +NotificationGroupType get_notification_group_type(const td_api::object_ptr &type); -inline StringBuilder &operator<<(StringBuilder &sb, const NotificationGroupType &type) { - switch (type) { - case NotificationGroupType::Messages: - return sb << "Messages"; - case NotificationGroupType::Mentions: - return sb << "Mentions"; - case NotificationGroupType::SecretChat: - return sb << "SecretChat"; - case NotificationGroupType::Calls: - return sb << "Calls"; - default: - UNREACHABLE(); - return sb; - } -} +StringBuilder &operator<<(StringBuilder &string_builder, const NotificationGroupType &type); } // namespace td