diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2024-03-06 01:19:55 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2024-03-06 01:19:55 -0500 |
commit | bab713baf557de427a1f93cc377d2fe79561731d (patch) | |
tree | 2295cab055d8f477adc35e8f1e3c30e46d2ac39e /src | |
parent | cb6436f527f832cf74aecda2911d8e607534d8f3 (diff) | |
download | abaddon-portaudio-bab713baf557de427a1f93cc377d2fe79561731d.tar.gz abaddon-portaudio-bab713baf557de427a1f93cc377d2fe79561731d.zip |
folder unread indicators
Diffstat (limited to 'src')
-rw-r--r-- | src/components/channellist/classic/guildlistfolderitem.cpp | 36 | ||||
-rw-r--r-- | src/components/channellist/classic/guildlistfolderitem.hpp | 6 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/components/channellist/classic/guildlistfolderitem.cpp b/src/components/channellist/classic/guildlistfolderitem.cpp index 30e1adb..e062d42 100644 --- a/src/components/channellist/classic/guildlistfolderitem.cpp +++ b/src/components/channellist/classic/guildlistfolderitem.cpp @@ -36,6 +36,8 @@ void GuildListFolderButton::SetGuilds(const std::vector<Snowflake> &guild_ids) { } GuildListFolderItem::GuildListFolderItem(const UserSettingsGuildFoldersEntry &folder) { + m_guild_ids = folder.GuildIDs; + get_style_context()->add_class("classic-guild-list-folder"); if (folder.Name.has_value()) { @@ -86,8 +88,42 @@ GuildListFolderItem::GuildListFolderItem(const UserSettingsGuildFoldersEntry &fo m_box.show(); m_image.show(); show(); + + Abaddon::Get().GetDiscordClient().signal_message_create().connect(sigc::mem_fun(*this, &GuildListFolderItem::OnMessageCreate)); + Abaddon::Get().GetDiscordClient().signal_message_ack().connect(sigc::mem_fun(*this, &GuildListFolderItem::OnMessageAck)); + + CheckUnreadStatus(); } void GuildListFolderItem::AddGuildWidget(GuildListGuildItem *widget) { m_box.add(*widget); } + +void GuildListFolderItem::OnMessageCreate(const Message &msg) { + if (msg.GuildID.has_value() && std::find(m_guild_ids.begin(), m_guild_ids.end(), *msg.GuildID) != m_guild_ids.end()) CheckUnreadStatus(); +} + +void GuildListFolderItem::OnMessageAck(const MessageAckData &data) { + CheckUnreadStatus(); +} + +void GuildListFolderItem::CheckUnreadStatus() { + auto &discord = Abaddon::Get().GetDiscordClient(); + if (!Abaddon::Get().GetSettings().Unreads) return; + + bool has_any_unreads = false; + + for (auto guild_id : m_guild_ids) { + int mentions; + if (!discord.IsGuildMuted(guild_id) && discord.GetUnreadStateForGuild(guild_id, mentions)) { + has_any_unreads = true; + break; + } + } + + if (has_any_unreads) { + get_style_context()->add_class("has-unread"); + } else { + get_style_context()->remove_class("has-unread"); + } +} diff --git a/src/components/channellist/classic/guildlistfolderitem.hpp b/src/components/channellist/classic/guildlistfolderitem.hpp index 82a5a14..e5772c0 100644 --- a/src/components/channellist/classic/guildlistfolderitem.hpp +++ b/src/components/channellist/classic/guildlistfolderitem.hpp @@ -27,6 +27,12 @@ public: void AddGuildWidget(GuildListGuildItem *widget); private: + void OnMessageCreate(const Message &msg); + void OnMessageAck(const MessageAckData &data); + void CheckUnreadStatus(); + + std::vector<Snowflake> m_guild_ids; + Gtk::Stack m_stack; GuildListFolderButton m_grid; Gtk::Image m_icon; |