diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 385d6b7..f955f45 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -351,7 +351,9 @@ void DiscordClient::GetArchivedPrivateThreads(Snowflake channel_id, const sigc:: } std::vector DiscordClient::GetChildChannelIDs(Snowflake parent_id) const { - return m_store.GetChannelIDsWithParentID(parent_id); + std::vector ids; + for (auto [id, type] : m_store.GetChannelIDsWithParentID(parent_id)) ids.push_back(id); + return ids; } std::optional DiscordClient::GetWebhookMessageData(Snowflake message_id) const { @@ -1371,7 +1373,8 @@ int DiscordClient::GetUnreadStateForChannel(Snowflake id) const noexcept { int DiscordClient::GetUnreadChannelsCountForCategory(Snowflake id) const noexcept { int result = 0; - for (Snowflake channel_id : m_store.GetChannelIDsWithParentID(id)) { + for (auto [channel_id, channel_type] : m_store.GetChannelIDsWithParentID(id)) { + if (!ShouldChannelTypeCountInUnread(channel_type)) continue; if (IsChannelMuted(channel_id)) continue; const auto iter = m_unread.find(channel_id); if (iter == m_unread.end()) continue; @@ -1393,6 +1396,9 @@ bool DiscordClient::GetUnreadStateForGuild(Snowflake id, int &total_mentions) co if (const auto iter = m_channel_muted_parent.find(channel_id); iter != m_channel_muted_parent.end()) continue; + const auto channel = GetChannel(channel_id); + if (channel.has_value() && !ShouldChannelTypeCountInUnread(channel->Type)) continue; + if (!has_any_unread && channel_unread > -1 && !IsChannelMuted(channel_id)) has_any_unread = true; } @@ -2753,6 +2759,14 @@ bool DiscordClient::CheckCode(const http::response_type &r, int expected) { return true; } +bool DiscordClient::ShouldChannelTypeCountInUnread(ChannelType type) { + return type != ChannelType::GUILD_VOICE && + type != ChannelType::GUILD_FORUM && + type != ChannelType::GUILD_MEDIA && + type != ChannelType::GUILD_STORE && + type != ChannelType::GUILD_DIRECTORY; +} + void DiscordClient::StoreMessageData(Message &msg) { const auto chan = m_store.GetChannel(msg.ChannelID); if (chan.has_value() && chan->GuildID.has_value()) diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index 9c2c080..6b2853b 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -321,6 +321,8 @@ private: void StoreMessageData(Message &msg); + static bool ShouldChannelTypeCountInUnread(ChannelType type); + void HandleReadyReadState(const ReadyEventData &data); void HandleReadyGuildSettings(const ReadyEventData &data); diff --git a/src/discord/store.cpp b/src/discord/store.cpp index bf630aa..4de5d63 100644 --- a/src/discord/store.cpp +++ b/src/discord/store.cpp @@ -638,16 +638,16 @@ std::vector Store::GetActiveThreads(Snowflake channel_id) const { return ret; } -std::vector Store::GetChannelIDsWithParentID(Snowflake channel_id) const { +std::vector> Store::GetChannelIDsWithParentID(Snowflake channel_id) const { auto &s = m_stmt_get_chan_ids_parent; s->Bind(1, channel_id); - std::vector ret; + std::vector> ret; while (s->FetchOne()) { - Snowflake x; - s->Get(0, x); - ret.push_back(x); + auto &p = ret.emplace_back(); + s->Get(0, p.first); + s->Get(1, p.second); } s->Reset(); @@ -2315,7 +2315,7 @@ bool Store::CreateStatements() { } m_stmt_get_chan_ids_parent = std::make_unique(m_db, R"( - SELECT id FROM channels WHERE parent_id = ? + SELECT id, type FROM channels WHERE parent_id = ? )"); if (!m_stmt_get_chan_ids_parent->OK()) { fprintf(stderr, "failed to prepare get channel ids for parent statement: %s\n", m_db.ErrStr()); diff --git a/src/discord/store.hpp b/src/discord/store.hpp index 6157f09..e53d5c7 100644 --- a/src/discord/store.hpp +++ b/src/discord/store.hpp @@ -50,7 +50,7 @@ public: std::vector GetMessagesBefore(Snowflake channel_id, Snowflake message_id, size_t limit) const; std::vector GetPinnedMessages(Snowflake channel_id) const; std::vector GetActiveThreads(Snowflake channel_id) const; // public - std::vector GetChannelIDsWithParentID(Snowflake channel_id) const; + std::vector> GetChannelIDsWithParentID(Snowflake channel_id) const; std::unordered_set GetMembersInGuild(Snowflake guild_id) const; // ^ not the same as GetUsersInGuild since users in a guild may include users who do not have retrieved member data