take muted channels into account for unread guild indicator

This commit is contained in:
ouwou 2021-12-25 03:07:11 -05:00
parent 36f73a6106
commit 207c004228
3 changed files with 19 additions and 13 deletions

View File

@ -250,20 +250,11 @@ void CellRendererChannels::render_vfunc_guild(const Cairo::RefPtr<Cairo::Context
const auto id = m_property_id.get_value();
int total_mentions = 0;
auto &discord = Abaddon::Get().GetDiscordClient();
const auto channels = discord.GetChannelsInGuild(id);
bool has_unread = false;
for (const auto &id : channels) {
const int state = Abaddon::Get().GetDiscordClient().GetUnreadStateForChannel(id);
if (state >= 0) {
has_unread = true;
total_mentions += state;
}
}
if (!has_unread) return;
int total_mentions;
const auto has_unread = discord.GetUnreadStateForGuild(id, total_mentions);
if (!discord.IsGuildMuted(id)) {
if (has_unread && !discord.IsGuildMuted(id)) {
cr->set_source_rgb(1.0, 1.0, 1.0);
const auto x = background_area.get_x();
const auto y = background_area.get_y();

View File

@ -1156,10 +1156,24 @@ bool DiscordClient::IsGuildMuted(Snowflake id) const noexcept {
int DiscordClient::GetUnreadStateForChannel(Snowflake id) const noexcept {
const auto iter = m_unread.find(id);
if (iter == m_unread.end()) return -1; // todo: no magic number
if (iter == m_unread.end()) return -1; // todo: no magic number (who am i kidding ill never change this)
return iter->second;
}
bool DiscordClient::GetUnreadStateForGuild(Snowflake id, int &total_mentions) const noexcept {
total_mentions = 0;
bool has_any_unread = false;
const auto channels = GetChannelsInGuild(id);
for (const auto channel_id : channels) {
const auto channel_unread = GetUnreadStateForChannel(channel_id);
if (!has_any_unread && channel_unread > -1 && !IsChannelMuted(channel_id))
has_any_unread = true;
if (channel_unread > -1)
total_mentions += channel_unread;
}
return has_any_unread;
}
PresenceStatus DiscordClient::GetUserStatus(Snowflake id) const {
auto it = m_user_to_status.find(id);
if (it != m_user_to_status.end())

View File

@ -190,6 +190,7 @@ public:
bool IsChannelMuted(Snowflake id) const noexcept;
bool IsGuildMuted(Snowflake id) const noexcept;
int GetUnreadStateForChannel(Snowflake id) const noexcept;
bool GetUnreadStateForGuild(Snowflake id, int &total_mentions) const noexcept;
PresenceStatus GetUserStatus(Snowflake id) const;