From 64085fafec86b347c26bb92b758042a0bd4edc75 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 6 Mar 2023 17:31:09 -0500 Subject: add basic guild notifications --- src/discord/objects.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/discord/objects.hpp') diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp index 9db9369..97da807 100644 --- a/src/discord/objects.hpp +++ b/src/discord/objects.hpp @@ -272,10 +272,16 @@ struct ReadStateData { friend void from_json(const nlohmann::json &j, ReadStateData &m); }; +enum class NotificationLevel { + ALL_MESSAGES = 0, + ONLY_MENTIONS = 1, + NO_MESSAGES = 2, +}; + struct UserGuildSettingsChannelOverride { bool Muted; MuteConfigData MuteConfig; - int MessageNotifications; + NotificationLevel MessageNotifications; bool Collapsed; Snowflake ChannelID; @@ -290,13 +296,15 @@ struct UserGuildSettingsEntry { bool Muted; MuteConfigData MuteConfig; bool MobilePush; - int MessageNotifications; + NotificationLevel MessageNotifications; bool HideMutedChannels; Snowflake GuildID; std::vector ChannelOverrides; friend void from_json(const nlohmann::json &j, UserGuildSettingsEntry &m); friend void to_json(nlohmann::json &j, const UserGuildSettingsEntry &m); + + std::optional GetOverride(Snowflake channel_id) const; }; struct UserGuildSettingsData { -- cgit v1.2.3 From 816f1a01ecc3155ad410d1ff34510b558e2d8cbf Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 8 Mar 2023 19:21:02 -0500 Subject: handle notification level 3 --- src/discord/objects.hpp | 1 + src/notifications/notifications.cpp | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src/discord/objects.hpp') diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp index 97da807..d7db55b 100644 --- a/src/discord/objects.hpp +++ b/src/discord/objects.hpp @@ -276,6 +276,7 @@ enum class NotificationLevel { ALL_MESSAGES = 0, ONLY_MENTIONS = 1, NO_MESSAGES = 2, + USE_UPPER = 3, // actually called "NULL" }; struct UserGuildSettingsChannelOverride { diff --git a/src/notifications/notifications.cpp b/src/notifications/notifications.cpp index bda9f46..db06651 100644 --- a/src/notifications/notifications.cpp +++ b/src/notifications/notifications.cpp @@ -44,14 +44,29 @@ bool CheckGuildMessage(const Message &message) { const auto channel_settings = guild_settings->GetOverride(message.ChannelID); - // if there are guild settings but no channel settings then fallback to category or guild - + // 🥴 NotificationLevel level; if (channel_settings.has_value()) { - level = channel_settings->MessageNotifications; + if (channel_settings->MessageNotifications == NotificationLevel::USE_UPPER) { + if (category_settings.has_value()) { + if (category_settings->MessageNotifications == NotificationLevel::USE_UPPER) { + level = guild_settings->MessageNotifications; + } else { + level = category_settings->MessageNotifications; + } + } else { + level = guild_settings->MessageNotifications; + } + } else { + level = channel_settings->MessageNotifications; + } } else { if (category_settings.has_value()) { - level = category_settings->MessageNotifications; + if (category_settings->MessageNotifications == NotificationLevel::USE_UPPER) { + level = guild_settings->MessageNotifications; + } else { + level = category_settings->MessageNotifications; + } } else { level = guild_settings->MessageNotifications; } -- cgit v1.2.3 From e3f6a1dcbd75b511397f7ba64f81ba37db4a1cfc Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Fri, 10 Mar 2023 19:14:19 -0500 Subject: handle USER_GUILD_SETTINGS_UPDATE for notifications --- src/discord/discord.cpp | 8 +++++--- src/discord/objects.cpp | 10 +++++++++- src/discord/objects.hpp | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src/discord/objects.hpp') diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index f21e8a1..8e435aa 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -86,8 +86,8 @@ const UserGuildSettingsData &DiscordClient::GetUserGuildSettings() const { } std::optional DiscordClient::GetSettingsForGuild(Snowflake id) const { - for (const auto &entry : m_user_guild_settings.Entries) { - if (entry.GuildID == id) return entry; + if (const auto it = m_user_guild_settings.Entries.find(id); it != m_user_guild_settings.Entries.end()) { + return it->second; } return std::nullopt; @@ -2049,6 +2049,8 @@ void DiscordClient::HandleGatewayMessageAck(const GatewayMessage &msg) { void DiscordClient::HandleGatewayUserGuildSettingsUpdate(const GatewayMessage &msg) { UserGuildSettingsUpdateData data = msg.Data; + m_user_guild_settings.Entries[data.Settings.GuildID] = data.Settings; + const bool for_dms = !data.Settings.GuildID.IsValid(); const auto channels = for_dms ? GetPrivateChannels() : GetChannelsInGuild(data.Settings.GuildID); @@ -2543,7 +2545,7 @@ void DiscordClient::HandleReadyGuildSettings(const ReadyEventData &data) { } const auto now = Snowflake::FromNow(); - for (const auto &entry : data.GuildSettings.Entries) { + for (const auto &[guild_id, entry] : data.GuildSettings.Entries) { // even if muted is true a guild/channel can be unmuted if the current time passes mute_config.end_time if (entry.Muted) { if (entry.MuteConfig.EndTime.has_value()) { diff --git a/src/discord/objects.cpp b/src/discord/objects.cpp index 7f0d51e..0837633 100644 --- a/src/discord/objects.cpp +++ b/src/discord/objects.cpp @@ -210,7 +210,15 @@ std::optional UserGuildSettingsEntry::GetOverr void from_json(const nlohmann::json &j, UserGuildSettingsData &m) { JS_D("version", m.Version); JS_D("partial", m.IsPartial); - JS_D("entries", m.Entries); + + { + std::vector entries; + JS_D("entries", entries); + + for (const auto &entry : entries) { + m.Entries[entry.GuildID] = entry; + } + } } void from_json(const nlohmann::json &j, ReadyEventData &m) { diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp index d7db55b..1545cf4 100644 --- a/src/discord/objects.hpp +++ b/src/discord/objects.hpp @@ -311,7 +311,7 @@ struct UserGuildSettingsEntry { struct UserGuildSettingsData { int Version; bool IsPartial; - std::vector Entries; + std::map Entries; friend void from_json(const nlohmann::json &j, UserGuildSettingsData &m); }; -- cgit v1.2.3