summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt7
-rw-r--r--src/components/channels.cpp20
-rw-r--r--src/components/channels.hpp3
-rw-r--r--src/components/channelscellrenderer.cpp27
-rw-r--r--src/discord/discord.cpp20
-rw-r--r--src/discord/discord.hpp1
6 files changed, 58 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7a782ab..7a55057 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -175,6 +175,11 @@ if (${ENABLE_NOTIFICATION_SOUNDS})
endif ()
if (USE_MINIAUDIO)
- target_include_directories(abaddon PUBLIC subprojects/miniaudio)
+ find_path(MINIAUDIO_INCLUDE_DIR
+ NAMES miniaudio.h
+ HINTS subprojects
+ PATH_SUFFIXES miniaudio
+ REQUIRED)
+ target_include_directories(abaddon PUBLIC ${MINIAUDIO_INCLUDE_DIR})
target_compile_definitions(abaddon PRIVATE WITH_MINIAUDIO)
endif ()
diff --git a/src/components/channels.cpp b/src/components/channels.cpp
index 26f3259..9fd4abd 100644
--- a/src/components/channels.cpp
+++ b/src/components/channels.cpp
@@ -1102,15 +1102,25 @@ void ChannelList::SetDMChannelIcon(Gtk::TreeIter iter, const ChannelData &dm) {
}
}
+void ChannelList::RedrawUnreadIndicatorsForChannel(const ChannelData &channel) {
+ if (channel.GuildID.has_value()) {
+ auto iter = GetIteratorForGuildFromID(*channel.GuildID);
+ if (iter) m_model->row_changed(m_model->get_path(iter), iter);
+ }
+ if (channel.ParentID.has_value()) {
+ auto iter = GetIteratorForRowFromIDOfType(*channel.ParentID, RenderType::Category);
+ if (iter) m_model->row_changed(m_model->get_path(iter), iter);
+ }
+}
+
void ChannelList::OnMessageAck(const MessageAckData &data) {
// trick renderer into redrawing
m_model->row_changed(Gtk::TreeModel::Path("0"), m_model->get_iter("0")); // 0 is always path for dm header
auto iter = GetIteratorForRowFromID(data.ChannelID);
if (iter) m_model->row_changed(m_model->get_path(iter), iter);
auto channel = Abaddon::Get().GetDiscordClient().GetChannel(data.ChannelID);
- if (channel.has_value() && channel->GuildID.has_value()) {
- iter = GetIteratorForGuildFromID(*channel->GuildID);
- if (iter) m_model->row_changed(m_model->get_path(iter), iter);
+ if (channel.has_value()) {
+ RedrawUnreadIndicatorsForChannel(*channel);
}
}
@@ -1123,9 +1133,7 @@ void ChannelList::OnMessageCreate(const Message &msg) {
if (iter)
(*iter)[m_columns.m_sort] = static_cast<int64_t>(-msg.ID);
}
- if (channel->GuildID.has_value())
- if ((iter = GetIteratorForGuildFromID(*channel->GuildID)))
- m_model->row_changed(m_model->get_path(iter), iter);
+ RedrawUnreadIndicatorsForChannel(*channel);
}
bool ChannelList::OnButtonPressEvent(GdkEventButton *ev) {
diff --git a/src/components/channels.hpp b/src/components/channels.hpp
index d561737..9d449e4 100644
--- a/src/components/channels.hpp
+++ b/src/components/channels.hpp
@@ -116,9 +116,10 @@ protected:
void UpdateCreateDMChannel(const ChannelData &channel);
void SetDMChannelIcon(Gtk::TreeIter iter, const ChannelData &dm);
+ void RedrawUnreadIndicatorsForChannel(const ChannelData& channel);
void OnMessageAck(const MessageAckData &data);
-
void OnMessageCreate(const Message &msg);
+
Gtk::TreeModel::Path m_path_for_menu;
// cant be recovered through selection
diff --git a/src/components/channelscellrenderer.cpp b/src/components/channelscellrenderer.cpp
index 6de7a00..ac98512 100644
--- a/src/components/channelscellrenderer.cpp
+++ b/src/components/channelscellrenderer.cpp
@@ -410,6 +410,17 @@ void CellRendererChannels::get_preferred_height_for_width_vfunc_category(Gtk::Wi
m_renderer_text.get_preferred_height_for_width(widget, width, minimum_height, natural_height);
}
+void AddUnreadIndicator(const Cairo::RefPtr<Cairo::Context> &cr, const Gdk::Rectangle &background_area) {
+ static const auto color = Gdk::RGBA(Abaddon::Get().GetSettings().UnreadIndicatorColor);
+ cr->set_source_rgb(color.get_red(), color.get_green(), color.get_blue());
+ const auto x = background_area.get_x();
+ const auto y = background_area.get_y();
+ const auto w = background_area.get_width();
+ const auto h = background_area.get_height();
+ cr->rectangle(x, y, 3, h);
+ cr->fill();
+}
+
void CellRendererChannels::render_vfunc_category(const Cairo::RefPtr<Cairo::Context> &cr, Gtk::Widget &widget, const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area, Gtk::CellRendererState flags) {
// todo: figure out how Gtk::Arrow is rendered because i like it better :^)
constexpr static int len = 5;
@@ -447,13 +458,18 @@ void CellRendererChannels::render_vfunc_category(const Cairo::RefPtr<Cairo::Cont
Gdk::Rectangle text_cell_area(text_x, text_y, text_w, text_h);
static const auto color = Gdk::RGBA(Abaddon::Get().GetSettings().ChannelColor);
- if (Abaddon::Get().GetDiscordClient().IsChannelMuted(m_property_id.get_value())) {
+ auto &discord = Abaddon::Get().GetDiscordClient();
+ const auto id = m_property_id.get_value();
+ if (discord.IsChannelMuted(m_property_id.get_value())) {
auto muted = color;
muted.set_red(muted.get_red() * 0.5);
muted.set_green(muted.get_green() * 0.5);
muted.set_blue(muted.get_blue() * 0.5);
m_renderer_text.property_foreground_rgba() = muted;
} else {
+ if (discord.GetUnreadChannelsCountForCategory(id) > 0) {
+ AddUnreadIndicator(cr, background_area);
+ }
m_renderer_text.property_foreground_rgba() = color;
}
m_renderer_text.render(cr, widget, background_area, text_cell_area, flags);
@@ -519,14 +535,7 @@ void CellRendererChannels::render_vfunc_channel(const Cairo::RefPtr<Cairo::Conte
if (unread_state < 0) return;
if (!is_muted) {
- static const auto color = Gdk::RGBA(Abaddon::Get().GetSettings().UnreadIndicatorColor);
- cr->set_source_rgb(color.get_red(), color.get_green(), color.get_blue());
- const auto x = background_area.get_x();
- const auto y = background_area.get_y();
- const auto w = background_area.get_width();
- const auto h = background_area.get_height();
- cr->rectangle(x, y, 3, h);
- cr->fill();
+ AddUnreadIndicator(cr, background_area);
}
if (unread_state < 1) return;
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;