diff options
Diffstat (limited to 'src/discord')
-rw-r--r-- | src/discord/discord.cpp | 20 | ||||
-rw-r--r-- | src/discord/discord.hpp | 1 |
2 files changed, 18 insertions, 3 deletions
diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 75d066b..084e19f 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1338,6 +1338,17 @@ int DiscordClient::GetUnreadStateForChannel(Snowflake id) const noexcept { return iter->second; } +int DiscordClient::GetUnreadChannelsCountForCategory(Snowflake id) const noexcept { + int result = 0; + for (Snowflake channel_id : m_store.GetChannelIDsWithParentID(id)) { + if (IsChannelMuted(channel_id)) continue; + const auto iter = m_unread.find(channel_id); + if (iter == m_unread.end()) continue; + result += 1; + } + return result; +} + bool DiscordClient::GetUnreadStateForGuild(Snowflake id, int &total_mentions) const noexcept { total_mentions = 0; bool has_any_unread = false; @@ -1836,9 +1847,12 @@ void DiscordClient::HandleGatewayPresenceUpdate(const GatewayMessage &msg) { void DiscordClient::HandleGatewayChannelDelete(const GatewayMessage &msg) { const auto id = msg.Data.at("id").get<Snowflake>(); const auto channel = GetChannel(id); - auto it = m_guild_to_channels.find(*channel->GuildID); - if (it != m_guild_to_channels.end()) - it->second.erase(id); + if (channel.has_value() && channel->GuildID.has_value()) { + auto it = m_guild_to_channels.find(*channel->GuildID); + if (it != m_guild_to_channels.end()) { + it->second.erase(id); + } + } m_store.ClearChannel(id); m_signal_channel_delete.emit(id); m_signal_channel_accessibility_changed.emit(id, false); diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index 438e4e6..eba190a 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -216,6 +216,7 @@ public: bool IsChannelMuted(Snowflake id) const noexcept; bool IsGuildMuted(Snowflake id) const noexcept; int GetUnreadStateForChannel(Snowflake id) const noexcept; + int GetUnreadChannelsCountForCategory(Snowflake id) const noexcept; bool GetUnreadStateForGuild(Snowflake id, int &total_mentions) const noexcept; int GetUnreadDMsCount() const; |