From 72975d8517c7d3230faffe4a3ee030da5d594f8e Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Tue, 21 May 2024 01:51:16 -0400 Subject: handle new and updated voice channels i hope --- src/components/channellist/channellisttree.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/components/channellist') diff --git a/src/components/channellist/channellisttree.cpp b/src/components/channellist/channellisttree.cpp index 4816b42..3b11485 100644 --- a/src/components/channellist/channellisttree.cpp +++ b/src/components/channellist/channellisttree.cpp @@ -490,7 +490,13 @@ void ChannelListTree::UpdateChannel(Snowflake id) { auto channel = Abaddon::Get().GetDiscordClient().GetChannel(id); if (!iter || !channel.has_value()) return; if (channel->Type == ChannelType::GUILD_CATEGORY) return UpdateChannelCategory(*channel); + // TODO: theres like 4 different fucking ways of checking if somethin g is text or voice can i fix that How stupid . + // fun fact clang-format is indenting me right now i wonder why ,,,,,,,,,,, +#ifdef WITH_VOICE + if (!channel->IsText() && channel->Type != ChannelType::GUILD_VOICE) return; +#else if (!channel->IsText()) return; +#endif // refresh stuff that might have changed const bool is_orphan_TMP = !channel->ParentID.has_value(); @@ -512,7 +518,11 @@ void ChannelListTree::UpdateChannel(Snowflake id) { void ChannelListTree::UpdateCreateChannel(const ChannelData &channel) { if (channel.Type == ChannelType::GUILD_CATEGORY) return (void)UpdateCreateChannelCategory(channel); if (channel.Type == ChannelType::DM || channel.Type == ChannelType::GROUP_DM) return UpdateCreateDMChannel(channel); +#ifdef WITH_VOICE + if (channel.Type != ChannelType::GUILD_TEXT && channel.Type != ChannelType::GUILD_NEWS && channel.Type != ChannelType::GUILD_VOICE) return; +#else if (channel.Type != ChannelType::GUILD_TEXT && channel.Type != ChannelType::GUILD_NEWS) return; +#endif Gtk::TreeRow channel_row; bool orphan; @@ -525,7 +535,7 @@ void ChannelListTree::UpdateCreateChannel(const ChannelData &channel) { auto iter = GetIteratorForGuildFromID(*channel.GuildID); channel_row = *m_model->append(iter->children()); } - channel_row[m_columns.m_type] = RenderType::TextChannel; + channel_row[m_columns.m_type] = IsTextChannel(channel.Type) ? RenderType::TextChannel : RenderType::VoiceChannel; channel_row[m_columns.m_id] = channel.ID; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel.Name); channel_row[m_columns.m_nsfw] = channel.NSFW(); -- cgit v1.2.3 From 057dd2a1f8de65e4885f48211e324e1b966f4e2f Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Tue, 21 May 2024 02:06:20 -0400 Subject: add ugly little mention indicator to classic guild listing --- .../channellist/cellrendererchannels.cpp | 19 ++----- .../channellist/cellrendererchannels.hpp | 1 - src/components/channellist/classic/guildlist.cpp | 14 ++++- .../channellist/classic/guildlistfolderitem.cpp | 2 +- .../channellist/classic/guildlistfolderitem.hpp | 2 +- .../channellist/classic/mentionoverlay.cpp | 62 ++++++++++++++++++++++ .../channellist/classic/mentionoverlay.hpp | 19 +++++++ src/misc/cairo.cpp | 17 ++++++ src/misc/cairo.hpp | 5 ++ 9 files changed, 122 insertions(+), 19 deletions(-) create mode 100644 src/components/channellist/classic/mentionoverlay.cpp create mode 100644 src/components/channellist/classic/mentionoverlay.hpp create mode 100644 src/misc/cairo.cpp create mode 100644 src/misc/cairo.hpp (limited to 'src/components/channellist') diff --git a/src/components/channellist/cellrendererchannels.cpp b/src/components/channellist/cellrendererchannels.cpp index b049252..bb2b9ba 100644 --- a/src/components/channellist/cellrendererchannels.cpp +++ b/src/components/channellist/cellrendererchannels.cpp @@ -1,13 +1,15 @@ #include "cellrendererchannels.hpp" + #include + +#include "misc/cairo.hpp" + #include "abaddon.hpp" constexpr static int MentionsRightPad = 7; #ifndef M_PI constexpr static double M_PI = 3.14159265358979; #endif -constexpr static double M_PI_H = M_PI / 2.0; -constexpr static double M_PI_3_2 = M_PI * 3.0 / 2.0; void AddUnreadIndicator(const Cairo::RefPtr &cr, Gtk::Widget &widget, const Gdk::Rectangle &background_area) { static const auto color_setting = Gdk::RGBA(Abaddon::Get().GetSettings().UnreadIndicatorColor); @@ -832,17 +834,6 @@ void CellRendererChannels::render_vfunc_dm(const Cairo::RefPtr & } } -void CellRendererChannels::cairo_path_rounded_rect(const Cairo::RefPtr &cr, double x, double y, double w, double h, double r) { - const double degrees = M_PI / 180.0; - - cr->begin_new_sub_path(); - cr->arc(x + w - r, y + r, r, -M_PI_H, 0); - cr->arc(x + w - r, y + h - r, r, 0, M_PI_H); - cr->arc(x + r, y + h - r, r, M_PI_H, M_PI); - cr->arc(x + r, y + r, r, M_PI, M_PI_3_2); - cr->close_path(); -} - void CellRendererChannels::unread_render_mentions(const Cairo::RefPtr &cr, Gtk::Widget &widget, int mentions, int edge, const Gdk::Rectangle &cell_area) { Pango::FontDescription font; font.set_family("sans 14"); @@ -863,7 +854,7 @@ void CellRendererChannels::unread_render_mentions(const Cairo::RefPtrset_source_rgb(bg.get_red(), bg.get_green(), bg.get_blue()); cr->fill(); cr->set_source_rgb(text.get_red(), text.get_green(), text.get_blue()); diff --git a/src/components/channellist/cellrendererchannels.hpp b/src/components/channellist/cellrendererchannels.hpp index e142b2a..a313dc7 100644 --- a/src/components/channellist/cellrendererchannels.hpp +++ b/src/components/channellist/cellrendererchannels.hpp @@ -153,7 +153,6 @@ protected: const Gdk::Rectangle &cell_area, Gtk::CellRendererState flags); - static void cairo_path_rounded_rect(const Cairo::RefPtr &cr, double x, double y, double w, double h, double r); static void unread_render_mentions(const Cairo::RefPtr &cr, Gtk::Widget &widget, int mentions, int edge, const Gdk::Rectangle &cell_area); private: diff --git a/src/components/channellist/classic/guildlist.cpp b/src/components/channellist/classic/guildlist.cpp index 6a6e3d4..17cd79a 100644 --- a/src/components/channellist/classic/guildlist.cpp +++ b/src/components/channellist/classic/guildlist.cpp @@ -3,6 +3,7 @@ #include "abaddon.hpp" #include "util.hpp" #include "guildlistfolderitem.hpp" +#include "mentionoverlay.hpp" class GuildListDMsButton : public Gtk::EventBox { public: @@ -93,10 +94,19 @@ void GuildList::UpdateListing() { } } +static Gtk::Widget *AddMentionOverlay(Gtk::Widget *widget, Snowflake guild_id) { + auto *overlay = Gtk::make_managed(); + overlay->add(*widget); + auto *mention_overlay = Gtk::make_managed(guild_id); + overlay->add_overlay(*mention_overlay); + overlay->show_all(); + return overlay; +} + void GuildList::AddGuild(Snowflake id) { if (auto item = CreateGuildWidget(id)) { item->show(); - add(*item); + add(*AddMentionOverlay(item, id)); } } @@ -132,7 +142,7 @@ void GuildList::AddFolder(const UserSettingsGuildFoldersEntry &folder) { for (const auto guild_id : folder.GuildIDs) { if (auto *guild_widget = CreateGuildWidget(guild_id)) { guild_widget->show(); - folder_widget->AddGuildWidget(guild_widget); + folder_widget->AddGuildWidget(AddMentionOverlay(guild_widget, guild_id)); } } diff --git a/src/components/channellist/classic/guildlistfolderitem.cpp b/src/components/channellist/classic/guildlistfolderitem.cpp index e062d42..337d4b3 100644 --- a/src/components/channellist/classic/guildlistfolderitem.cpp +++ b/src/components/channellist/classic/guildlistfolderitem.cpp @@ -95,7 +95,7 @@ GuildListFolderItem::GuildListFolderItem(const UserSettingsGuildFoldersEntry &fo CheckUnreadStatus(); } -void GuildListFolderItem::AddGuildWidget(GuildListGuildItem *widget) { +void GuildListFolderItem::AddGuildWidget(Gtk::Widget *widget) { m_box.add(*widget); } diff --git a/src/components/channellist/classic/guildlistfolderitem.hpp b/src/components/channellist/classic/guildlistfolderitem.hpp index e5772c0..06d05f1 100644 --- a/src/components/channellist/classic/guildlistfolderitem.hpp +++ b/src/components/channellist/classic/guildlistfolderitem.hpp @@ -24,7 +24,7 @@ class GuildListFolderItem : public Gtk::VBox { public: GuildListFolderItem(const UserSettingsGuildFoldersEntry &folder); - void AddGuildWidget(GuildListGuildItem *widget); + void AddGuildWidget(Gtk::Widget *widget); private: void OnMessageCreate(const Message &msg); diff --git a/src/components/channellist/classic/mentionoverlay.cpp b/src/components/channellist/classic/mentionoverlay.cpp new file mode 100644 index 0000000..c734ced --- /dev/null +++ b/src/components/channellist/classic/mentionoverlay.cpp @@ -0,0 +1,62 @@ +#include "mentionoverlay.hpp" + +#include "misc/cairo.hpp" + +#include "abaddon.hpp" + +MentionOverlay::MentionOverlay(Snowflake guild_id) + : m_guild_id(guild_id) { + m_font.set_family("sans 14"); + m_layout = create_pango_layout("12"); + m_layout->set_font_description(m_font); + m_layout->set_alignment(Pango::ALIGN_RIGHT); + + get_style_context()->add_class("classic-mention-overlay"); // fuck you + + set_hexpand(false); + set_vexpand(false); + + signal_draw().connect(sigc::mem_fun(*this, &MentionOverlay::OnDraw)); + + Abaddon::Get().GetDiscordClient().signal_message_ack().connect([this](const MessageAckData &data) { + // fetching and checking guild id is probably more expensive than just forcing a redraw anyways + queue_draw(); + }); + + Abaddon::Get().GetDiscordClient().signal_message_create().connect([this](const Message &msg) { + if (msg.GuildID.has_value() && *msg.GuildID != m_guild_id) return; + if (!msg.DoesMentionEveryone && msg.Mentions.empty() && msg.MentionRoles.empty()) return; + queue_draw(); + }); +} + +bool MentionOverlay::OnDraw(const Cairo::RefPtr &cr) { + int mentions; + Abaddon::Get().GetDiscordClient().GetUnreadStateForGuild(m_guild_id, mentions); + if (mentions == 0) return true; + m_layout->set_text(std::to_string(mentions)); + + const int width = get_allocated_width(); + const int height = get_allocated_height(); + + int lw, lh; + m_layout->get_pixel_size(lw, lh); + { + static const auto badge_setting = Gdk::RGBA(Abaddon::Get().GetSettings().MentionBadgeColor); + static const auto text_setting = Gdk::RGBA(Abaddon::Get().GetSettings().MentionBadgeTextColor); + + auto bg = badge_setting.get_alpha_u() > 0 ? badge_setting : get_style_context()->get_background_color(Gtk::STATE_FLAG_SELECTED); + auto text = text_setting.get_alpha_u() > 0 ? text_setting : get_style_context()->get_color(Gtk::STATE_FLAG_SELECTED); + + const auto x = width - lw - 5; + const auto y = height - lh - 1; + CairoUtil::PathRoundedRect(cr, x - 4, y + 2, lw + 8, lh, 5); + cr->set_source_rgb(bg.get_red(), bg.get_green(), bg.get_blue()); + cr->fill(); + cr->set_source_rgb(text.get_red(), text.get_green(), text.get_blue()); + cr->move_to(x, y); + m_layout->show_in_cairo_context(cr); + } + + return true; +} diff --git a/src/components/channellist/classic/mentionoverlay.hpp b/src/components/channellist/classic/mentionoverlay.hpp new file mode 100644 index 0000000..24eb7e2 --- /dev/null +++ b/src/components/channellist/classic/mentionoverlay.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +#include "discord/snowflake.hpp" + +class MentionOverlay : public Gtk::DrawingArea { +public: + MentionOverlay(Snowflake guild_id); + +private: + bool OnDraw(const Cairo::RefPtr &cr); + + Snowflake m_guild_id; + + Pango::FontDescription m_font; + Glib::RefPtr m_layout; +}; diff --git a/src/misc/cairo.cpp b/src/misc/cairo.cpp new file mode 100644 index 0000000..1272f75 --- /dev/null +++ b/src/misc/cairo.cpp @@ -0,0 +1,17 @@ +#include "cairo.hpp" + +#include + +constexpr static double M_PI_H = M_PI / 2.0; +constexpr static double M_PI_3_2 = M_PI * 3.0 / 2.0; + +void CairoUtil::PathRoundedRect(const Cairo::RefPtr &cr, double x, double y, double w, double h, double r) { + const double degrees = M_PI / 180.0; + + cr->begin_new_sub_path(); + cr->arc(x + w - r, y + r, r, -M_PI_H, 0); + cr->arc(x + w - r, y + h - r, r, 0, M_PI_H); + cr->arc(x + r, y + h - r, r, M_PI_H, M_PI); + cr->arc(x + r, y + r, r, M_PI, M_PI_3_2); + cr->close_path(); +} \ No newline at end of file diff --git a/src/misc/cairo.hpp b/src/misc/cairo.hpp new file mode 100644 index 0000000..b66fa34 --- /dev/null +++ b/src/misc/cairo.hpp @@ -0,0 +1,5 @@ +#pragma once + +namespace CairoUtil { +void PathRoundedRect(const Cairo::RefPtr &cr, double x, double y, double w, double h, double r); +} // namespace CairoUtil -- cgit v1.2.3 From ead06ca864714e6804344da37da2f74230bfa39b Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Tue, 21 May 2024 02:12:28 -0400 Subject: fix cringe --- src/components/channellist/channellisttree.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/components/channellist') diff --git a/src/components/channellist/channellisttree.cpp b/src/components/channellist/channellisttree.cpp index 3b11485..ebbed58 100644 --- a/src/components/channellist/channellisttree.cpp +++ b/src/components/channellist/channellisttree.cpp @@ -535,7 +535,11 @@ void ChannelListTree::UpdateCreateChannel(const ChannelData &channel) { auto iter = GetIteratorForGuildFromID(*channel.GuildID); channel_row = *m_model->append(iter->children()); } +#ifdef WITH_VOICE channel_row[m_columns.m_type] = IsTextChannel(channel.Type) ? RenderType::TextChannel : RenderType::VoiceChannel; +#else + channel_row[m_columns.m_type] = RenderType::TextChannel; +#endif channel_row[m_columns.m_id] = channel.ID; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel.Name); channel_row[m_columns.m_nsfw] = channel.NSFW(); -- cgit v1.2.3 From bf29c44d9fa7bbc11fd68824c2468d4946ea29a6 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Tue, 21 May 2024 14:43:16 -0400 Subject: mention overlay passthrough --- src/components/channellist/classic/guildlist.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/components/channellist') diff --git a/src/components/channellist/classic/guildlist.cpp b/src/components/channellist/classic/guildlist.cpp index 17cd79a..6bee484 100644 --- a/src/components/channellist/classic/guildlist.cpp +++ b/src/components/channellist/classic/guildlist.cpp @@ -99,6 +99,10 @@ static Gtk::Widget *AddMentionOverlay(Gtk::Widget *widget, Snowflake guild_id) { overlay->add(*widget); auto *mention_overlay = Gtk::make_managed(guild_id); overlay->add_overlay(*mention_overlay); + overlay->set_overlay_pass_through(*mention_overlay, true); + mention_overlay->signal_realize().connect([mention_overlay]() { + mention_overlay->get_window()->set_pass_through(true); + }); overlay->show_all(); return overlay; } -- cgit v1.2.3 From 96687f019e415d830a7ebf57fe7c1372f76ba115 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 25 May 2024 00:09:08 -0400 Subject: add mention overlay to folders in classic --- src/components/channellist/classic/guildlist.cpp | 19 +++++++++++++-- .../channellist/classic/mentionoverlay.cpp | 27 ++++++++++++++++------ .../channellist/classic/mentionoverlay.hpp | 6 ++++- 3 files changed, 42 insertions(+), 10 deletions(-) (limited to 'src/components/channellist') diff --git a/src/components/channellist/classic/guildlist.cpp b/src/components/channellist/classic/guildlist.cpp index 6bee484..fdc15f9 100644 --- a/src/components/channellist/classic/guildlist.cpp +++ b/src/components/channellist/classic/guildlist.cpp @@ -103,7 +103,22 @@ static Gtk::Widget *AddMentionOverlay(Gtk::Widget *widget, Snowflake guild_id) { mention_overlay->signal_realize().connect([mention_overlay]() { mention_overlay->get_window()->set_pass_through(true); }); - overlay->show_all(); + mention_overlay->show(); + overlay->show(); + return overlay; +} + +static Gtk::Widget *AddMentionOverlay(Gtk::Widget *widget, const UserSettingsGuildFoldersEntry &folder) { + auto *overlay = Gtk::make_managed(); + overlay->add(*widget); + auto *mention_overlay = Gtk::make_managed(folder); + overlay->add_overlay(*mention_overlay); + overlay->set_overlay_pass_through(*mention_overlay, true); + mention_overlay->signal_realize().connect([mention_overlay]() { + mention_overlay->get_window()->set_pass_through(true); + }); + mention_overlay->show(); + overlay->show(); return overlay; } @@ -151,7 +166,7 @@ void GuildList::AddFolder(const UserSettingsGuildFoldersEntry &folder) { } folder_widget->show(); - add(*folder_widget); + add(*AddMentionOverlay(folder_widget, folder)); } void GuildList::Clear() { diff --git a/src/components/channellist/classic/mentionoverlay.cpp b/src/components/channellist/classic/mentionoverlay.cpp index c734ced..9fdd694 100644 --- a/src/components/channellist/classic/mentionoverlay.cpp +++ b/src/components/channellist/classic/mentionoverlay.cpp @@ -5,7 +5,16 @@ #include "abaddon.hpp" MentionOverlay::MentionOverlay(Snowflake guild_id) - : m_guild_id(guild_id) { + : m_guild_ids({ guild_id }) { + Init(); +} + +MentionOverlay::MentionOverlay(const UserSettingsGuildFoldersEntry &folder) + : m_guild_ids({ folder.GuildIDs.begin(), folder.GuildIDs.end() }) { + Init(); +} + +void MentionOverlay::Init() { m_font.set_family("sans 14"); m_layout = create_pango_layout("12"); m_layout->set_font_description(m_font); @@ -24,20 +33,24 @@ MentionOverlay::MentionOverlay(Snowflake guild_id) }); Abaddon::Get().GetDiscordClient().signal_message_create().connect([this](const Message &msg) { - if (msg.GuildID.has_value() && *msg.GuildID != m_guild_id) return; + if (msg.GuildID.has_value() && m_guild_ids.find(*msg.GuildID) == m_guild_ids.end()) return; if (!msg.DoesMentionEveryone && msg.Mentions.empty() && msg.MentionRoles.empty()) return; queue_draw(); }); } bool MentionOverlay::OnDraw(const Cairo::RefPtr &cr) { - int mentions; - Abaddon::Get().GetDiscordClient().GetUnreadStateForGuild(m_guild_id, mentions); - if (mentions == 0) return true; - m_layout->set_text(std::to_string(mentions)); + int total_mentions = 0; + for (auto guild_id : m_guild_ids) { + int mentions; + Abaddon::Get().GetDiscordClient().GetUnreadStateForGuild(guild_id, mentions); + total_mentions += mentions; + } + if (total_mentions == 0) return true; + m_layout->set_text(std::to_string(total_mentions)); const int width = get_allocated_width(); - const int height = get_allocated_height(); + const int height = std::min(get_allocated_height(), 48); // cope int lw, lh; m_layout->get_pixel_size(lw, lh); diff --git a/src/components/channellist/classic/mentionoverlay.hpp b/src/components/channellist/classic/mentionoverlay.hpp index 24eb7e2..ceb4f01 100644 --- a/src/components/channellist/classic/mentionoverlay.hpp +++ b/src/components/channellist/classic/mentionoverlay.hpp @@ -4,15 +4,19 @@ #include #include "discord/snowflake.hpp" +#include "discord/usersettings.hpp" class MentionOverlay : public Gtk::DrawingArea { public: MentionOverlay(Snowflake guild_id); + MentionOverlay(const UserSettingsGuildFoldersEntry &folder); private: + void Init(); + bool OnDraw(const Cairo::RefPtr &cr); - Snowflake m_guild_id; + std::set m_guild_ids; Pango::FontDescription m_font; Glib::RefPtr m_layout; -- cgit v1.2.3 From bc7c5f9ec3f1f19517a556a4c4f9e830ca191c32 Mon Sep 17 00:00:00 2001 From: pastalian <28638872+pastalian@users.noreply.github.com> Date: Sun, 16 Jun 2024 05:47:48 +0900 Subject: Explicitly include headers for PCH free build (#312) There are some headers that implicitly included by PCH. Include those explicitly so PCH free build succeeds. --- src/components/channellist/classic/guildlist.cpp | 2 ++ src/components/channellist/classic/mentionoverlay.hpp | 2 ++ src/misc/cairo.cpp | 2 -- src/misc/cairo.hpp | 2 ++ src/platform.cpp | 3 +++ 5 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src/components/channellist') diff --git a/src/components/channellist/classic/guildlist.cpp b/src/components/channellist/classic/guildlist.cpp index fdc15f9..11a6775 100644 --- a/src/components/channellist/classic/guildlist.cpp +++ b/src/components/channellist/classic/guildlist.cpp @@ -1,3 +1,5 @@ +#include + #include "guildlist.hpp" #include "abaddon.hpp" diff --git a/src/components/channellist/classic/mentionoverlay.hpp b/src/components/channellist/classic/mentionoverlay.hpp index ceb4f01..7c168c2 100644 --- a/src/components/channellist/classic/mentionoverlay.hpp +++ b/src/components/channellist/classic/mentionoverlay.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include diff --git a/src/misc/cairo.cpp b/src/misc/cairo.cpp index 1272f75..a1c6220 100644 --- a/src/misc/cairo.cpp +++ b/src/misc/cairo.cpp @@ -1,7 +1,5 @@ #include "cairo.hpp" -#include - constexpr static double M_PI_H = M_PI / 2.0; constexpr static double M_PI_3_2 = M_PI * 3.0 / 2.0; diff --git a/src/misc/cairo.hpp b/src/misc/cairo.hpp index b66fa34..37c71d6 100644 --- a/src/misc/cairo.hpp +++ b/src/misc/cairo.hpp @@ -1,5 +1,7 @@ #pragma once +#include + namespace CairoUtil { void PathRoundedRect(const Cairo::RefPtr &cr, double x, double y, double w, double h, double r); } // namespace CairoUtil diff --git a/src/platform.cpp b/src/platform.cpp index ce0ac74..726655b 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -7,6 +7,9 @@ #ifdef __APPLE__ #include #endif +#ifdef __linux__ + #include "util.hpp" +#endif #include -- cgit v1.2.3 From f8de54e47eadc40fad4027a34902476527f48a5c Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 17 Jun 2024 03:29:03 -0400 Subject: add open chat to voice channels --- src/components/channellist/channellisttree.cpp | 14 ++++++++++++-- src/components/channellist/channellisttree.hpp | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src/components/channellist') diff --git a/src/components/channellist/channellisttree.cpp b/src/components/channellist/channellisttree.cpp index ebbed58..e5bc06e 100644 --- a/src/components/channellist/channellisttree.cpp +++ b/src/components/channellist/channellisttree.cpp @@ -29,6 +29,7 @@ ChannelListTree::ChannelListTree() #ifdef WITH_VOICE , m_menu_voice_channel_join("_Join", true) , m_menu_voice_channel_disconnect("_Disconnect", true) + , m_menu_voice_open_chat("Open _Chat", true) #endif , m_menu_dm_copy_id("_Copy ID", true) , m_menu_dm_close("") // changes depending on if group or not @@ -209,8 +210,14 @@ ChannelListTree::ChannelListTree() m_signal_action_disconnect_voice.emit(); }); + m_menu_voice_open_chat.signal_activate().connect([this]() { + const auto id = static_cast((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]); + m_signal_action_channel_item_select.emit(id); + }); + m_menu_voice_channel.append(m_menu_voice_channel_join); m_menu_voice_channel.append(m_menu_voice_channel_disconnect); + m_menu_voice_channel.append(m_menu_voice_open_chat); m_menu_voice_channel.show_all(); #endif @@ -1172,8 +1179,11 @@ bool ChannelListTree::SelectionFunc(const Glib::RefPtr &model, c } } - auto type = (*model->get_iter(path))[m_columns.m_type]; - return type == RenderType::TextChannel || type == RenderType::DM || type == RenderType::Thread; + const auto type = (*model->get_iter(path))[m_columns.m_type]; + const auto id = static_cast((*model->get_iter(path))[m_columns.m_id]); + // todo maybe just keep this last check? + if (type == RenderType::TextChannel || type == RenderType::DM || type == RenderType::Thread || (id == m_active_channel)) return true; + return is_currently_selected; } void ChannelListTree::AddPrivateChannels() { diff --git a/src/components/channellist/channellisttree.hpp b/src/components/channellist/channellisttree.hpp index 4eebbdb..17acb46 100644 --- a/src/components/channellist/channellisttree.hpp +++ b/src/components/channellist/channellisttree.hpp @@ -166,6 +166,7 @@ protected: Gtk::Menu m_menu_voice_channel; Gtk::MenuItem m_menu_voice_channel_join; Gtk::MenuItem m_menu_voice_channel_disconnect; + Gtk::MenuItem m_menu_voice_open_chat; #endif Gtk::Menu m_menu_dm; -- cgit v1.2.3 From eb9ad703be7769958bee959ce2f83f5325ef206b Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 17 Jun 2024 03:50:50 -0400 Subject: show voice channels and participants even if compiled without audio --- .../channellist/cellrendererchannels.cpp | 14 ---- .../channellist/cellrendererchannels.hpp | 6 -- src/components/channellist/channellisttree.cpp | 53 +++------------ src/components/channellist/channellisttree.hpp | 8 --- src/discord/discord.cpp | 77 +++++++++++----------- src/discord/discord.hpp | 44 +++++++------ 6 files changed, 75 insertions(+), 127 deletions(-) (limited to 'src/components/channellist') diff --git a/src/components/channellist/cellrendererchannels.cpp b/src/components/channellist/cellrendererchannels.cpp index bb2b9ba..8758a7d 100644 --- a/src/components/channellist/cellrendererchannels.cpp +++ b/src/components/channellist/cellrendererchannels.cpp @@ -122,12 +122,10 @@ void CellRendererChannels::get_preferred_width_vfunc(Gtk::Widget &widget, int &m return get_preferred_width_vfunc_channel(widget, minimum_width, natural_width); case RenderType::Thread: return get_preferred_width_vfunc_thread(widget, minimum_width, natural_width); -#ifdef WITH_VOICE case RenderType::VoiceChannel: return get_preferred_width_vfunc_voice_channel(widget, minimum_width, natural_width); case RenderType::VoiceParticipant: return get_preferred_width_vfunc_voice_participant(widget, minimum_width, natural_width); -#endif case RenderType::DMHeader: return get_preferred_width_vfunc_dmheader(widget, minimum_width, natural_width); case RenderType::DM: @@ -147,12 +145,10 @@ void CellRendererChannels::get_preferred_width_for_height_vfunc(Gtk::Widget &wid return get_preferred_width_for_height_vfunc_channel(widget, height, minimum_width, natural_width); case RenderType::Thread: return get_preferred_width_for_height_vfunc_thread(widget, height, minimum_width, natural_width); -#ifdef WITH_VOICE case RenderType::VoiceChannel: return get_preferred_width_for_height_vfunc_voice_channel(widget, height, minimum_width, natural_width); case RenderType::VoiceParticipant: return get_preferred_width_for_height_vfunc_voice_participant(widget, height, minimum_width, natural_width); -#endif case RenderType::DMHeader: return get_preferred_width_for_height_vfunc_dmheader(widget, height, minimum_width, natural_width); case RenderType::DM: @@ -172,12 +168,10 @@ void CellRendererChannels::get_preferred_height_vfunc(Gtk::Widget &widget, int & return get_preferred_height_vfunc_channel(widget, minimum_height, natural_height); case RenderType::Thread: return get_preferred_height_vfunc_thread(widget, minimum_height, natural_height); -#ifdef WITH_VOICE case RenderType::VoiceChannel: return get_preferred_height_vfunc_voice_channel(widget, minimum_height, natural_height); case RenderType::VoiceParticipant: return get_preferred_height_vfunc_voice_participant(widget, minimum_height, natural_height); -#endif case RenderType::DMHeader: return get_preferred_height_vfunc_dmheader(widget, minimum_height, natural_height); case RenderType::DM: @@ -197,12 +191,10 @@ void CellRendererChannels::get_preferred_height_for_width_vfunc(Gtk::Widget &wid return get_preferred_height_for_width_vfunc_channel(widget, width, minimum_height, natural_height); case RenderType::Thread: return get_preferred_height_for_width_vfunc_thread(widget, width, minimum_height, natural_height); -#ifdef WITH_VOICE case RenderType::VoiceChannel: return get_preferred_height_for_width_vfunc_voice_channel(widget, width, minimum_height, natural_height); case RenderType::VoiceParticipant: return get_preferred_height_for_width_vfunc_voice_participant(widget, width, minimum_height, natural_height); -#endif case RenderType::DMHeader: return get_preferred_height_for_width_vfunc_dmheader(widget, width, minimum_height, natural_height); case RenderType::DM: @@ -222,12 +214,10 @@ void CellRendererChannels::render_vfunc(const Cairo::RefPtr &cr, return render_vfunc_channel(cr, widget, background_area, cell_area, flags); case RenderType::Thread: return render_vfunc_thread(cr, widget, background_area, cell_area, flags); -#ifdef WITH_VOICE case RenderType::VoiceChannel: return render_vfunc_voice_channel(cr, widget, background_area, cell_area, flags); case RenderType::VoiceParticipant: return render_vfunc_voice_participant(cr, widget, background_area, cell_area, flags); -#endif case RenderType::DMHeader: return render_vfunc_dmheader(cr, widget, background_area, cell_area, flags); case RenderType::DM: @@ -563,8 +553,6 @@ void CellRendererChannels::render_vfunc_thread(const Cairo::RefPtr((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]); @@ -219,7 +218,6 @@ ChannelListTree::ChannelListTree() m_menu_voice_channel.append(m_menu_voice_channel_disconnect); m_menu_voice_channel.append(m_menu_voice_open_chat); m_menu_voice_channel.show_all(); -#endif m_menu_dm_copy_id.signal_activate().connect([this] { Gtk::Clipboard::get()->set_text(std::to_string((*m_model->get_iter(m_path_for_menu))[m_columns.m_id])); @@ -362,10 +360,8 @@ int ChannelListTree::SortFunc(const Gtk::TreeModel::iterator &a, const Gtk::Tree const int64_t b_sort = (*b)[m_columns.m_sort]; if (a_type == RenderType::DMHeader) return -1; if (b_type == RenderType::DMHeader) return 1; -#ifdef WITH_VOICE if (a_type == RenderType::TextChannel && b_type == RenderType::VoiceChannel) return -1; if (b_type == RenderType::TextChannel && a_type == RenderType::VoiceChannel) return 1; -#endif return static_cast(std::clamp(a_sort - b_sort, int64_t(-1), int64_t(1))); } @@ -497,13 +493,9 @@ void ChannelListTree::UpdateChannel(Snowflake id) { auto channel = Abaddon::Get().GetDiscordClient().GetChannel(id); if (!iter || !channel.has_value()) return; if (channel->Type == ChannelType::GUILD_CATEGORY) return UpdateChannelCategory(*channel); - // TODO: theres like 4 different fucking ways of checking if somethin g is text or voice can i fix that How stupid . - // fun fact clang-format is indenting me right now i wonder why ,,,,,,,,,,, -#ifdef WITH_VOICE + // TODO: theres like 4 different fucking ways of checking if somethin g is text or voice can i fix that How stupid . + // fun fact clang-format is indenting me right now i wonder why ,,,,,,,,,,, if (!channel->IsText() && channel->Type != ChannelType::GUILD_VOICE) return; -#else - if (!channel->IsText()) return; -#endif // refresh stuff that might have changed const bool is_orphan_TMP = !channel->ParentID.has_value(); @@ -525,11 +517,7 @@ void ChannelListTree::UpdateChannel(Snowflake id) { void ChannelListTree::UpdateCreateChannel(const ChannelData &channel) { if (channel.Type == ChannelType::GUILD_CATEGORY) return (void)UpdateCreateChannelCategory(channel); if (channel.Type == ChannelType::DM || channel.Type == ChannelType::GROUP_DM) return UpdateCreateDMChannel(channel); -#ifdef WITH_VOICE if (channel.Type != ChannelType::GUILD_TEXT && channel.Type != ChannelType::GUILD_NEWS && channel.Type != ChannelType::GUILD_VOICE) return; -#else - if (channel.Type != ChannelType::GUILD_TEXT && channel.Type != ChannelType::GUILD_NEWS) return; -#endif Gtk::TreeRow channel_row; bool orphan; @@ -542,11 +530,7 @@ void ChannelListTree::UpdateCreateChannel(const ChannelData &channel) { auto iter = GetIteratorForGuildFromID(*channel.GuildID); channel_row = *m_model->append(iter->children()); } -#ifdef WITH_VOICE channel_row[m_columns.m_type] = IsTextChannel(channel.Type) ? RenderType::TextChannel : RenderType::VoiceChannel; -#else - channel_row[m_columns.m_type] = RenderType::TextChannel; -#endif channel_row[m_columns.m_id] = channel.ID; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel.Name); channel_row[m_columns.m_nsfw] = channel.NSFW(); @@ -642,7 +626,6 @@ void ChannelListTree::OnThreadListSync(const ThreadListSyncData &data) { } } -#ifdef WITH_VOICE void ChannelListTree::OnVoiceUserConnect(Snowflake user_id, Snowflake channel_id) { auto parent_iter = GetIteratorForRowFromIDOfType(channel_id, RenderType::VoiceChannel); if (!parent_iter) parent_iter = GetIteratorForRowFromIDOfType(channel_id, RenderType::DM); @@ -664,7 +647,6 @@ void ChannelListTree::OnVoiceStateSet(Snowflake user_id, Snowflake channel_id, V (*iter)[m_columns.m_voice_flags] = flags; } } -#endif void ChannelListTree::DeleteThreadRow(Snowflake id) { auto iter = GetIteratorForRowFromID(id); @@ -926,11 +908,7 @@ Gtk::TreeModel::iterator ChannelListTree::AddGuild(const GuildData &guild, const for (const auto &channel_ : *guild.Channels) { const auto channel = discord.GetChannel(channel_.ID); if (!channel.has_value()) continue; -#ifdef WITH_VOICE if (channel->Type == ChannelType::GUILD_TEXT || channel->Type == ChannelType::GUILD_NEWS || channel->Type == ChannelType::GUILD_VOICE) { -#else - if (channel->Type == ChannelType::GUILD_TEXT || channel->Type == ChannelType::GUILD_NEWS) { -#endif if (channel->ParentID.has_value()) categories[*channel->ParentID].push_back(*channel); else @@ -957,7 +935,6 @@ Gtk::TreeModel::iterator ChannelListTree::AddGuild(const GuildData &guild, const } }; -#ifdef WITH_VOICE auto add_voice_participants = [this, &discord](const ChannelData &channel, const Gtk::TreeNodeChildren &root) { for (auto user_id : discord.GetUsersInVoiceChannel(channel.ID)) { if (const auto user = discord.GetUser(user_id); user.has_value()) { @@ -965,21 +942,17 @@ Gtk::TreeModel::iterator ChannelListTree::AddGuild(const GuildData &guild, const } } }; -#endif for (const auto &channel : orphan_channels) { auto channel_row = *m_model->append(guild_row.children()); if (IsTextChannel(channel.Type)) { channel_row[m_columns.m_type] = RenderType::TextChannel; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel.Name); - } -#ifdef WITH_VOICE - else { + } else { channel_row[m_columns.m_type] = RenderType::VoiceChannel; channel_row[m_columns.m_name] = Glib::Markup::escape_text(*channel.Name); add_voice_participants(channel, channel_row->children()); } -#endif channel_row[m_columns.m_id] = channel.ID; channel_row[m_columns.m_sort] = *channel.Position + OrphanChannelSortOffset; channel_row[m_columns.m_nsfw] = channel.NSFW(); @@ -1004,14 +977,11 @@ Gtk::TreeModel::iterator ChannelListTree::AddGuild(const GuildData &guild, const if (IsTextChannel(channel.Type)) { channel_row[m_columns.m_type] = RenderType::TextChannel; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel.Name); - } -#ifdef WITH_VOICE - else { + } else { channel_row[m_columns.m_type] = RenderType::VoiceChannel; channel_row[m_columns.m_name] = Glib::Markup::escape_text(*channel.Name); add_voice_participants(channel, channel_row->children()); } -#endif channel_row[m_columns.m_id] = channel.ID; channel_row[m_columns.m_sort] = *channel.Position; channel_row[m_columns.m_nsfw] = channel.NSFW(); @@ -1049,7 +1019,6 @@ Gtk::TreeModel::iterator ChannelListTree::CreateThreadRow(const Gtk::TreeNodeChi return thread_iter; } -#ifdef WITH_VOICE Gtk::TreeModel::iterator ChannelListTree::CreateVoiceParticipantRow(const UserData &user, const Gtk::TreeNodeChildren &parent) { auto row = *m_model->append(parent); row[m_columns.m_type] = RenderType::VoiceParticipant; @@ -1071,7 +1040,6 @@ Gtk::TreeModel::iterator ChannelListTree::CreateVoiceParticipantRow(const UserDa return row; } -#endif void ChannelListTree::UpdateChannelCategory(const ChannelData &channel) { auto iter = GetIteratorForRowFromID(channel.ID); @@ -1215,13 +1183,11 @@ void ChannelListTree::AddPrivateChannels() { row[m_columns.m_icon] = img.GetPlaceholder(DMIconSize); row[m_columns.m_expanded] = true; -#ifdef WITH_VOICE for (auto user_id : discord.GetUsersInVoiceChannel(dm_id)) { if (const auto user = discord.GetUser(user_id); user.has_value()) { CreateVoiceParticipantRow(*user, row->children()); } } -#endif SetDMChannelIcon(iter, *dm); } @@ -1352,12 +1318,10 @@ bool ChannelListTree::OnButtonPressEvent(GdkEventButton *ev) { OnChannelSubmenuPopup(); m_menu_channel.popup_at_pointer(reinterpret_cast(ev)); break; -#ifdef WITH_VOICE case RenderType::VoiceChannel: OnVoiceChannelSubmenuPopup(); m_menu_voice_channel.popup_at_pointer(reinterpret_cast(ev)); break; -#endif case RenderType::DM: { OnDMSubmenuPopup(); const auto channel = Abaddon::Get().GetDiscordClient().GetChannel(static_cast(row[m_columns.m_id])); @@ -1450,8 +1414,8 @@ void ChannelListTree::OnChannelSubmenuPopup() { m_menu_channel_toggle_mute.set_label("Mute"); } -#ifdef WITH_VOICE void ChannelListTree::OnVoiceChannelSubmenuPopup() { +#ifdef WITH_VOICE const auto iter = m_model->get_iter(m_path_for_menu); if (!iter) return; const auto id = static_cast((*iter)[m_columns.m_id]); @@ -1463,8 +1427,11 @@ void ChannelListTree::OnVoiceChannelSubmenuPopup() { m_menu_voice_channel_join.set_sensitive(true); m_menu_voice_channel_disconnect.set_sensitive(false); } -} +#else + m_menu_voice_channel_join.set_sensitive(false); + m_menu_voice_channel_disconnect.set_sensitive(false); #endif +} void ChannelListTree::OnDMSubmenuPopup() { auto iter = m_model->get_iter(m_path_for_menu); diff --git a/src/components/channellist/channellisttree.hpp b/src/components/channellist/channellisttree.hpp index 17acb46..abceca9 100644 --- a/src/components/channellist/channellisttree.hpp +++ b/src/components/channellist/channellisttree.hpp @@ -104,10 +104,7 @@ protected: Gtk::TreeModel::iterator AddGuild(const GuildData &guild, const Gtk::TreeNodeChildren &root); Gtk::TreeModel::iterator UpdateCreateChannelCategory(const ChannelData &channel); Gtk::TreeModel::iterator CreateThreadRow(const Gtk::TreeNodeChildren &children, const ChannelData &channel); - -#ifdef WITH_VOICE Gtk::TreeModel::iterator CreateVoiceParticipantRow(const UserData &user, const Gtk::TreeNodeChildren &parent); -#endif void UpdateChannelCategory(const ChannelData &channel); @@ -162,12 +159,10 @@ protected: Gtk::MenuItem m_menu_channel_open_tab; #endif -#ifdef WITH_VOICE Gtk::Menu m_menu_voice_channel; Gtk::MenuItem m_menu_voice_channel_join; Gtk::MenuItem m_menu_voice_channel_disconnect; Gtk::MenuItem m_menu_voice_open_chat; -#endif Gtk::Menu m_menu_dm; Gtk::MenuItem m_menu_dm_copy_id; @@ -195,10 +190,7 @@ protected: void OnChannelSubmenuPopup(); void OnDMSubmenuPopup(); void OnThreadSubmenuPopup(); - -#ifdef WITH_VOICE void OnVoiceChannelSubmenuPopup(); -#endif bool m_updating_listing = false; diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index f955f45..062a871 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1284,21 +1284,10 @@ Snowflake DiscordClient::GetVoiceChannelID() const noexcept { return m_voice_channel_id; } -std::unordered_set DiscordClient::GetUsersInVoiceChannel(Snowflake channel_id) { - return m_voice_state_channel_users[channel_id]; -} - std::optional DiscordClient::GetSSRCOfUser(Snowflake id) const { return m_voice.GetSSRCOfUser(id); } -std::optional> DiscordClient::GetVoiceState(Snowflake user_id) const { - if (const auto it = m_voice_states.find(user_id); it != m_voice_states.end()) { - return it->second; - } - return std::nullopt; -} - DiscordVoiceClient &DiscordClient::GetVoiceClient() { return m_voice; } @@ -1314,6 +1303,17 @@ void DiscordClient::SetVoiceDeafened(bool is_deaf) { } #endif +std::optional> DiscordClient::GetVoiceState(Snowflake user_id) const { + if (const auto it = m_voice_states.find(user_id); it != m_voice_states.end()) { + return it->second; + } + return std::nullopt; +} + +std::unordered_set DiscordClient::GetUsersInVoiceChannel(Snowflake channel_id) { + return m_voice_state_channel_users[channel_id]; +} + void DiscordClient::SetReferringChannel(Snowflake id) { if (!id.IsValid()) { m_http.SetPersistentHeader("Referer", "https://discord.com/channels/@me"); @@ -1652,10 +1652,10 @@ void DiscordClient::HandleGatewayMessage(std::string str) { case GatewayEvent::GUILD_MEMBERS_CHUNK: { HandleGatewayGuildMembersChunk(m); } break; -#ifdef WITH_VOICE case GatewayEvent::VOICE_STATE_UPDATE: { HandleGatewayVoiceStateUpdate(m); } break; +#ifdef WITH_VOICE case GatewayEvent::VOICE_SERVER_UPDATE: { HandleGatewayVoiceServerUpdate(m); } break; @@ -2336,12 +2336,6 @@ void DiscordClient::HandleGatewayGuildMembersChunk(const GatewayMessage &msg) { * */ -void DiscordClient::HandleGatewayVoiceStateUpdate(const GatewayMessage &msg) { - spdlog::get("discord")->trace("VOICE_STATE_UPDATE"); - - CheckVoiceState(msg.Data); -} - void DiscordClient::HandleGatewayVoiceServerUpdate(const GatewayMessage &msg) { spdlog::get("discord")->trace("VOICE_SERVER_UPDATE"); @@ -2371,8 +2365,17 @@ void DiscordClient::HandleGatewayCallCreate(const GatewayMessage &msg) { } } +#endif + +void DiscordClient::HandleGatewayVoiceStateUpdate(const GatewayMessage &msg) { + spdlog::get("discord")->trace("VOICE_STATE_UPDATE"); + + CheckVoiceState(msg.Data); +} + void DiscordClient::CheckVoiceState(const VoiceState &data) { if (data.UserID == m_user_data.ID) { +#ifdef WITH_VOICE spdlog::get("discord")->debug("Voice session ID: {}", data.SessionID); m_voice.SetSessionID(data.SessionID); @@ -2383,6 +2386,7 @@ void DiscordClient::CheckVoiceState(const VoiceState &data) { m_voice_channel_id = *data.ChannelID; m_signal_voice_channel_changed.emit(m_voice_channel_id); } +#endif } else { if (data.GuildID.has_value() && data.Member.has_value()) { if (data.Member->User.has_value()) { @@ -2409,7 +2413,6 @@ void DiscordClient::CheckVoiceState(const VoiceState &data) { } } } -#endif void DiscordClient::HandleGatewayReadySupplemental(const GatewayMessage &msg) { ReadySupplementalData data = msg.Data; @@ -2929,6 +2932,15 @@ void DiscordClient::SendVoiceStateUpdate() { m_websocket.Send(msg); } +void DiscordClient::OnVoiceConnected() { + m_signal_voice_connected.emit(); +} + +void DiscordClient::OnVoiceDisconnected() { + m_signal_voice_disconnected.emit(); +} +#endif + void DiscordClient::SetVoiceState(Snowflake user_id, const VoiceState &state) { if (!state.ChannelID.has_value()) { spdlog::get("discord")->error("SetVoiceState called with missing channel ID"); @@ -2958,15 +2970,6 @@ void DiscordClient::ClearVoiceState(Snowflake user_id) { } } -void DiscordClient::OnVoiceConnected() { - m_signal_voice_connected.emit(); -} - -void DiscordClient::OnVoiceDisconnected() { - m_signal_voice_disconnected.emit(); -} -#endif - void DiscordClient::LoadEventMap() { m_event_map["READY"] = GatewayEvent::READY; m_event_map["MESSAGE_CREATE"] = GatewayEvent::MESSAGE_CREATE; @@ -3242,14 +3245,6 @@ DiscordClient::type_signal_voice_speaking DiscordClient::signal_voice_speaking() return m_signal_voice_speaking; } -DiscordClient::type_signal_voice_user_disconnect DiscordClient::signal_voice_user_disconnect() { - return m_signal_voice_user_disconnect; -} - -DiscordClient::type_signal_voice_user_connect DiscordClient::signal_voice_user_connect() { - return m_signal_voice_user_connect; -} - DiscordClient::type_signal_voice_requested_connect DiscordClient::signal_voice_requested_connect() { return m_signal_voice_requested_connect; } @@ -3265,8 +3260,16 @@ DiscordClient::type_signal_voice_client_state_update DiscordClient::signal_voice DiscordClient::type_signal_voice_channel_changed DiscordClient::signal_voice_channel_changed() { return m_signal_voice_channel_changed; } +#endif + +DiscordClient::type_signal_voice_user_disconnect DiscordClient::signal_voice_user_disconnect() { + return m_signal_voice_user_disconnect; +} + +DiscordClient::type_signal_voice_user_connect DiscordClient::signal_voice_user_connect() { + return m_signal_voice_user_connect; +} DiscordClient::type_signal_voice_state_set DiscordClient::signal_voice_state_set() { return m_signal_voice_state_set; } -#endif diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index 6b2853b..4e898dc 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -200,9 +200,7 @@ public: [[nodiscard]] bool IsVoiceConnected() const noexcept; [[nodiscard]] bool IsVoiceConnecting() const noexcept; [[nodiscard]] Snowflake GetVoiceChannelID() const noexcept; - [[nodiscard]] std::unordered_set GetUsersInVoiceChannel(Snowflake channel_id); [[nodiscard]] std::optional GetSSRCOfUser(Snowflake id) const; - [[nodiscard]] std::optional> GetVoiceState(Snowflake user_id) const; DiscordVoiceClient &GetVoiceClient(); @@ -210,6 +208,9 @@ public: void SetVoiceDeafened(bool is_deaf); #endif + [[nodiscard]] std::optional> GetVoiceState(Snowflake user_id) const; + [[nodiscard]] std::unordered_set GetUsersInVoiceChannel(Snowflake channel_id); + void SetReferringChannel(Snowflake id); void SetBuildNumber(uint32_t build_number); @@ -299,12 +300,13 @@ private: void HandleGatewayInvalidSession(const GatewayMessage &msg); #ifdef WITH_VOICE - void HandleGatewayVoiceStateUpdate(const GatewayMessage &msg); void HandleGatewayVoiceServerUpdate(const GatewayMessage &msg); void HandleGatewayCallCreate(const GatewayMessage &msg); +#endif + + void HandleGatewayVoiceStateUpdate(const GatewayMessage &msg); void CheckVoiceState(const VoiceState &data); -#endif void HeartbeatThread(); void SendIdentify(); @@ -375,19 +377,20 @@ private: bool m_deaf_requested = false; Snowflake m_voice_channel_id; - // todo sql i guess - std::unordered_map> m_voice_states; - std::unordered_map> m_voice_state_channel_users; void SendVoiceStateUpdate(); - void SetVoiceState(Snowflake user_id, const VoiceState &state); - void ClearVoiceState(Snowflake user_id); - void OnVoiceConnected(); void OnVoiceDisconnected(); #endif + void SetVoiceState(Snowflake user_id, const VoiceState &state); + void ClearVoiceState(Snowflake user_id); + + // todo sql i guess + std::unordered_map> m_voice_states; + std::unordered_map> m_voice_state_channel_users; + mutable std::mutex m_msg_mutex; Glib::Dispatcher m_msg_dispatch; std::queue m_msg_queue; @@ -465,15 +468,16 @@ public: using type_signal_voice_connected = sigc::signal; using type_signal_voice_disconnected = sigc::signal; using type_signal_voice_speaking = sigc::signal; - using type_signal_voice_user_disconnect = sigc::signal; - using type_signal_voice_user_connect = sigc::signal; using type_signal_voice_requested_connect = sigc::signal; using type_signal_voice_requested_disconnect = sigc::signal; using type_signal_voice_client_state_update = sigc::signal; using type_signal_voice_channel_changed = sigc::signal; - using type_signal_voice_state_set = sigc::signal; #endif + using type_signal_voice_user_disconnect = sigc::signal; + using type_signal_voice_user_connect = sigc::signal; + using type_signal_voice_state_set = sigc::signal; + type_signal_gateway_ready signal_gateway_ready(); type_signal_gateway_ready_supplemental signal_gateway_ready_supplemental(); type_signal_message_create signal_message_create(); @@ -533,15 +537,16 @@ public: type_signal_voice_connected signal_voice_connected(); type_signal_voice_disconnected signal_voice_disconnected(); type_signal_voice_speaking signal_voice_speaking(); - type_signal_voice_user_disconnect signal_voice_user_disconnect(); - type_signal_voice_user_connect signal_voice_user_connect(); type_signal_voice_requested_connect signal_voice_requested_connect(); type_signal_voice_requested_disconnect signal_voice_requested_disconnect(); type_signal_voice_client_state_update signal_voice_client_state_update(); type_signal_voice_channel_changed signal_voice_channel_changed(); - type_signal_voice_state_set signal_voice_state_set(); #endif + type_signal_voice_user_disconnect signal_voice_user_disconnect(); + type_signal_voice_user_connect signal_voice_user_connect(); + type_signal_voice_state_set signal_voice_state_set(); + protected: type_signal_gateway_ready m_signal_gateway_ready; type_signal_gateway_ready_supplemental m_signal_gateway_ready_supplemental; @@ -602,12 +607,13 @@ protected: type_signal_voice_connected m_signal_voice_connected; type_signal_voice_disconnected m_signal_voice_disconnected; type_signal_voice_speaking m_signal_voice_speaking; - type_signal_voice_user_disconnect m_signal_voice_user_disconnect; - type_signal_voice_user_connect m_signal_voice_user_connect; type_signal_voice_requested_connect m_signal_voice_requested_connect; type_signal_voice_requested_disconnect m_signal_voice_requested_disconnect; type_signal_voice_client_state_update m_signal_voice_client_state_update; type_signal_voice_channel_changed m_signal_voice_channel_changed; - type_signal_voice_state_set m_signal_voice_state_set; #endif + + type_signal_voice_user_disconnect m_signal_voice_user_disconnect; + type_signal_voice_user_connect m_signal_voice_user_connect; + type_signal_voice_state_set m_signal_voice_state_set; }; -- cgit v1.2.3 From 15955050f45a4ee0c3aff60e8cf0c0c54da6dc41 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 17 Jun 2024 03:56:14 -0400 Subject: show mentions on voice channels --- src/components/channellist/cellrendererchannels.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/components/channellist') diff --git a/src/components/channellist/cellrendererchannels.cpp b/src/components/channellist/cellrendererchannels.cpp index 8758a7d..8a6097e 100644 --- a/src/components/channellist/cellrendererchannels.cpp +++ b/src/components/channellist/cellrendererchannels.cpp @@ -600,6 +600,21 @@ void CellRendererChannels::render_vfunc_voice_channel(const Cairo::RefPtrshow_in_cairo_context(cr); RenderExpander(24, cr, widget, background_area, property_expanded()); + + // unread + if (!Abaddon::Get().GetSettings().Unreads) return; + + const auto id = m_property_id.get_value(); + const auto unread_state = Abaddon::Get().GetDiscordClient().GetUnreadStateForChannel(id); + + if (unread_state < 1) return; + + auto *paned = dynamic_cast(widget.get_ancestor(Gtk::Paned::get_type())); + if (paned != nullptr) { + const auto edge = std::min(paned->get_position(), cell_area.get_width()); + + unread_render_mentions(cr, widget, unread_state, edge, cell_area); + } } // voice participant -- cgit v1.2.3 From bd4162b18aa460782a015e4cf982119a2b7a1153 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 17 Jun 2024 04:00:29 -0400 Subject: add mark as read to voice channels --- src/components/channellist/channellisttree.cpp | 6 ++++++ src/components/channellist/channellisttree.hpp | 1 + 2 files changed, 7 insertions(+) (limited to 'src/components/channellist') diff --git a/src/components/channellist/channellisttree.cpp b/src/components/channellist/channellisttree.cpp index 611dc03..4597a1f 100644 --- a/src/components/channellist/channellisttree.cpp +++ b/src/components/channellist/channellisttree.cpp @@ -28,6 +28,7 @@ ChannelListTree::ChannelListTree() #endif , m_menu_voice_channel_join("_Join", true) , m_menu_voice_channel_disconnect("_Disconnect", true) + , m_menu_voice_channel_mark_as_read("Mark as _Read", true) , m_menu_voice_open_chat("Open _Chat", true) , m_menu_dm_copy_id("_Copy ID", true) , m_menu_dm_close("") // changes depending on if group or not @@ -209,6 +210,10 @@ ChannelListTree::ChannelListTree() }); #endif + m_menu_voice_channel_mark_as_read.signal_activate().connect([this]() { + Abaddon::Get().GetDiscordClient().MarkChannelAsRead(static_cast((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]), NOOP_CALLBACK); + }); + m_menu_voice_open_chat.signal_activate().connect([this]() { const auto id = static_cast((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]); m_signal_action_channel_item_select.emit(id); @@ -216,6 +221,7 @@ ChannelListTree::ChannelListTree() m_menu_voice_channel.append(m_menu_voice_channel_join); m_menu_voice_channel.append(m_menu_voice_channel_disconnect); + m_menu_voice_channel.append(m_menu_voice_channel_mark_as_read); m_menu_voice_channel.append(m_menu_voice_open_chat); m_menu_voice_channel.show_all(); diff --git a/src/components/channellist/channellisttree.hpp b/src/components/channellist/channellisttree.hpp index abceca9..9e2c544 100644 --- a/src/components/channellist/channellisttree.hpp +++ b/src/components/channellist/channellisttree.hpp @@ -162,6 +162,7 @@ protected: Gtk::Menu m_menu_voice_channel; Gtk::MenuItem m_menu_voice_channel_join; Gtk::MenuItem m_menu_voice_channel_disconnect; + Gtk::MenuItem m_menu_voice_channel_mark_as_read; Gtk::MenuItem m_menu_voice_open_chat; Gtk::Menu m_menu_dm; -- cgit v1.2.3