ignore unread state from undisplayed channel types

This commit is contained in:
ouwou 2024-06-04 21:36:55 -04:00
parent 01865075a4
commit 25ecbce043
4 changed files with 25 additions and 9 deletions

View File

@ -351,7 +351,9 @@ void DiscordClient::GetArchivedPrivateThreads(Snowflake channel_id, const sigc::
} }
std::vector<Snowflake> DiscordClient::GetChildChannelIDs(Snowflake parent_id) const { std::vector<Snowflake> DiscordClient::GetChildChannelIDs(Snowflake parent_id) const {
return m_store.GetChannelIDsWithParentID(parent_id); std::vector<Snowflake> ids;
for (auto [id, type] : m_store.GetChannelIDsWithParentID(parent_id)) ids.push_back(id);
return ids;
} }
std::optional<WebhookMessageData> DiscordClient::GetWebhookMessageData(Snowflake message_id) const { std::optional<WebhookMessageData> 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 DiscordClient::GetUnreadChannelsCountForCategory(Snowflake id) const noexcept {
int result = 0; 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; if (IsChannelMuted(channel_id)) continue;
const auto iter = m_unread.find(channel_id); const auto iter = m_unread.find(channel_id);
if (iter == m_unread.end()) continue; 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()) if (const auto iter = m_channel_muted_parent.find(channel_id); iter != m_channel_muted_parent.end())
continue; 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)) if (!has_any_unread && channel_unread > -1 && !IsChannelMuted(channel_id))
has_any_unread = true; has_any_unread = true;
} }
@ -2753,6 +2759,14 @@ bool DiscordClient::CheckCode(const http::response_type &r, int expected) {
return true; 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) { void DiscordClient::StoreMessageData(Message &msg) {
const auto chan = m_store.GetChannel(msg.ChannelID); const auto chan = m_store.GetChannel(msg.ChannelID);
if (chan.has_value() && chan->GuildID.has_value()) if (chan.has_value() && chan->GuildID.has_value())

View File

@ -321,6 +321,8 @@ private:
void StoreMessageData(Message &msg); void StoreMessageData(Message &msg);
static bool ShouldChannelTypeCountInUnread(ChannelType type);
void HandleReadyReadState(const ReadyEventData &data); void HandleReadyReadState(const ReadyEventData &data);
void HandleReadyGuildSettings(const ReadyEventData &data); void HandleReadyGuildSettings(const ReadyEventData &data);

View File

@ -638,16 +638,16 @@ std::vector<ChannelData> Store::GetActiveThreads(Snowflake channel_id) const {
return ret; return ret;
} }
std::vector<Snowflake> Store::GetChannelIDsWithParentID(Snowflake channel_id) const { std::vector<std::pair<Snowflake, ChannelType>> Store::GetChannelIDsWithParentID(Snowflake channel_id) const {
auto &s = m_stmt_get_chan_ids_parent; auto &s = m_stmt_get_chan_ids_parent;
s->Bind(1, channel_id); s->Bind(1, channel_id);
std::vector<Snowflake> ret; std::vector<std::pair<Snowflake, ChannelType>> ret;
while (s->FetchOne()) { while (s->FetchOne()) {
Snowflake x; auto &p = ret.emplace_back();
s->Get(0, x); s->Get(0, p.first);
ret.push_back(x); s->Get(1, p.second);
} }
s->Reset(); s->Reset();
@ -2315,7 +2315,7 @@ bool Store::CreateStatements() {
} }
m_stmt_get_chan_ids_parent = std::make_unique<Statement>(m_db, R"( m_stmt_get_chan_ids_parent = std::make_unique<Statement>(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()) { if (!m_stmt_get_chan_ids_parent->OK()) {
fprintf(stderr, "failed to prepare get channel ids for parent statement: %s\n", m_db.ErrStr()); fprintf(stderr, "failed to prepare get channel ids for parent statement: %s\n", m_db.ErrStr());

View File

@ -50,7 +50,7 @@ public:
std::vector<Message> GetMessagesBefore(Snowflake channel_id, Snowflake message_id, size_t limit) const; std::vector<Message> GetMessagesBefore(Snowflake channel_id, Snowflake message_id, size_t limit) const;
std::vector<Message> GetPinnedMessages(Snowflake channel_id) const; std::vector<Message> GetPinnedMessages(Snowflake channel_id) const;
std::vector<ChannelData> GetActiveThreads(Snowflake channel_id) const; // public std::vector<ChannelData> GetActiveThreads(Snowflake channel_id) const; // public
std::vector<Snowflake> GetChannelIDsWithParentID(Snowflake channel_id) const; std::vector<std::pair<Snowflake, ChannelType>> GetChannelIDsWithParentID(Snowflake channel_id) const;
std::unordered_set<Snowflake> GetMembersInGuild(Snowflake guild_id) const; std::unordered_set<Snowflake> 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 // ^ not the same as GetUsersInGuild since users in a guild may include users who do not have retrieved member data