Skip to content

Commit

Permalink
Merge pull request #279 from uowuo/stages
Browse files Browse the repository at this point in the history
Support for stages
  • Loading branch information
ouwou authored Jul 5, 2024
2 parents e6191d9 + b19782c commit 68db143
Show file tree
Hide file tree
Showing 25 changed files with 707 additions and 135 deletions.
2 changes: 1 addition & 1 deletion src/abaddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "windows/profilewindow.hpp"
#include "windows/pinnedwindow.hpp"
#include "windows/threadswindow.hpp"
#include "windows/voicewindow.hpp"
#include "windows/voice/voicewindow.hpp"
#include "startup.hpp"
#include "notifications/notifications.hpp"
#include "remoteauth/remoteauthdialog.hpp"
Expand Down
12 changes: 9 additions & 3 deletions src/components/channellist/cellrendererchannels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ void CellRendererChannels::get_preferred_width_vfunc(Gtk::Widget &widget, int &m
case RenderType::Thread:
return get_preferred_width_vfunc_thread(widget, minimum_width, natural_width);
case RenderType::VoiceChannel:
case RenderType::VoiceStage:
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);
Expand All @@ -146,6 +147,7 @@ void CellRendererChannels::get_preferred_width_for_height_vfunc(Gtk::Widget &wid
case RenderType::Thread:
return get_preferred_width_for_height_vfunc_thread(widget, height, minimum_width, natural_width);
case RenderType::VoiceChannel:
case RenderType::VoiceStage:
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);
Expand All @@ -169,6 +171,7 @@ void CellRendererChannels::get_preferred_height_vfunc(Gtk::Widget &widget, int &
case RenderType::Thread:
return get_preferred_height_vfunc_thread(widget, minimum_height, natural_height);
case RenderType::VoiceChannel:
case RenderType::VoiceStage:
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);
Expand All @@ -192,6 +195,7 @@ void CellRendererChannels::get_preferred_height_for_width_vfunc(Gtk::Widget &wid
case RenderType::Thread:
return get_preferred_height_for_width_vfunc_thread(widget, width, minimum_height, natural_height);
case RenderType::VoiceChannel:
case RenderType::VoiceStage:
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);
Expand All @@ -215,7 +219,9 @@ void CellRendererChannels::render_vfunc(const Cairo::RefPtr<Cairo::Context> &cr,
case RenderType::Thread:
return render_vfunc_thread(cr, widget, background_area, cell_area, flags);
case RenderType::VoiceChannel:
return render_vfunc_voice_channel(cr, widget, background_area, cell_area, flags);
return render_vfunc_voice_channel(cr, widget, background_area, cell_area, flags, "\U0001F50A");
case RenderType::VoiceStage:
return render_vfunc_voice_channel(cr, widget, background_area, cell_area, flags, "\U0001F4E1");
case RenderType::VoiceParticipant:
return render_vfunc_voice_participant(cr, widget, background_area, cell_area, flags);
case RenderType::DMHeader:
Expand Down Expand Up @@ -571,7 +577,7 @@ void CellRendererChannels::get_preferred_height_for_width_vfunc_voice_channel(Gt
m_renderer_text.get_preferred_height_for_width(widget, width, minimum_height, natural_height);
}

void CellRendererChannels::render_vfunc_voice_channel(const Cairo::RefPtr<Cairo::Context> &cr, Gtk::Widget &widget, const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area, Gtk::CellRendererState flags) {
void CellRendererChannels::render_vfunc_voice_channel(const Cairo::RefPtr<Cairo::Context> &cr, Gtk::Widget &widget, const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area, Gtk::CellRendererState flags, const char *emoji) {
// channel name text
Gtk::Requisition minimum_size, natural_size;
m_renderer_text.get_preferred_size(widget, minimum_size, natural_size);
Expand All @@ -588,7 +594,7 @@ void CellRendererChannels::render_vfunc_voice_channel(const Cairo::RefPtr<Cairo:
Pango::FontDescription font;
font.set_family("sans 14");

auto layout = widget.create_pango_layout("\U0001F50A");
auto layout = widget.create_pango_layout(emoji);
layout->set_font_description(font);
layout->set_alignment(Pango::ALIGN_LEFT);
cr->set_source_rgba(1.0, 1.0, 1.0, 1.0);
Expand Down
6 changes: 4 additions & 2 deletions src/components/channellist/cellrendererchannels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <gtkmm/cellrendererpixbuf.h>
#include <gtkmm/cellrenderertext.h>
#include "discord/snowflake.hpp"
#include "discord/voicestateflags.hpp"
#include "discord/voicestate.hpp"
#include "misc/bitwise.hpp"

enum class RenderType : uint8_t {
Expand All @@ -16,6 +16,7 @@ enum class RenderType : uint8_t {
TextChannel,
Thread,
VoiceChannel,
VoiceStage, // identical to non-stage except for icon
VoiceParticipant,

DMHeader,
Expand Down Expand Up @@ -112,7 +113,8 @@ class CellRendererChannels : public Gtk::CellRenderer {
Gtk::Widget &widget,
const Gdk::Rectangle &background_area,
const Gdk::Rectangle &cell_area,
Gtk::CellRendererState flags);
Gtk::CellRendererState flags,
const char *emoji);

// voice participant
void get_preferred_width_vfunc_voice_participant(Gtk::Widget &widget, int &minimum_width, int &natural_width) const;
Expand Down
57 changes: 53 additions & 4 deletions src/components/channellist/channellisttree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ ChannelListTree::ChannelListTree()
#endif
, m_menu_voice_channel_join("_Join", true)
, m_menu_voice_channel_disconnect("_Disconnect", true)
, m_menu_voice_stage_join("_Join", true)
, m_menu_voice_stage_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)
Expand Down Expand Up @@ -225,6 +227,21 @@ ChannelListTree::ChannelListTree()
m_menu_voice_channel.append(m_menu_voice_open_chat);
m_menu_voice_channel.show_all();

#ifdef WITH_VOICE
m_menu_voice_stage_join.signal_activate().connect([this]() {
const auto id = static_cast<Snowflake>((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]);
m_signal_action_join_voice_channel.emit(id);
});

m_menu_voice_stage_disconnect.signal_activate().connect([this]() {
m_signal_action_disconnect_voice.emit();
});
#endif

m_menu_voice_stage.append(m_menu_voice_stage_join);
m_menu_voice_stage.append(m_menu_voice_stage_disconnect);
m_menu_voice_stage.show_all();

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]));
});
Expand Down Expand Up @@ -366,8 +383,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;
if (a_type == RenderType::TextChannel && b_type == RenderType::VoiceChannel) return -1;
if (b_type == RenderType::TextChannel && a_type == RenderType::VoiceChannel) return 1;
if (a_type == RenderType::TextChannel && (b_type == RenderType::VoiceChannel || b_type == RenderType::VoiceStage)) return -1;
if (b_type == RenderType::TextChannel && (a_type == RenderType::VoiceChannel || a_type == RenderType::VoiceStage)) return 1;
return static_cast<int>(std::clamp(a_sort - b_sort, int64_t(-1), int64_t(1)));
}

Expand Down Expand Up @@ -634,6 +651,7 @@ void ChannelListTree::OnThreadListSync(const ThreadListSyncData &data) {

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::VoiceStage);
if (!parent_iter) parent_iter = GetIteratorForRowFromIDOfType(channel_id, RenderType::DM);
if (!parent_iter) return;
const auto user = Abaddon::Get().GetDiscordClient().GetUser(user_id);
Expand Down Expand Up @@ -914,7 +932,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;
if (channel->Type == ChannelType::GUILD_TEXT || channel->Type == ChannelType::GUILD_NEWS || channel->Type == ChannelType::GUILD_VOICE) {
if (channel->Type == ChannelType::GUILD_TEXT || channel->Type == ChannelType::GUILD_NEWS || channel->Type == ChannelType::GUILD_VOICE || channel->Type == ChannelType::GUILD_STAGE_VOICE) {
if (channel->ParentID.has_value())
categories[*channel->ParentID].push_back(*channel);
else
Expand Down Expand Up @@ -954,6 +972,10 @@ 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);
} else if (channel.Type == ChannelType::GUILD_STAGE_VOICE) {
channel_row[m_columns.m_type] = RenderType::VoiceStage;
channel_row[m_columns.m_name] = Glib::Markup::escape_text(*channel.Name);
add_voice_participants(channel, channel_row->children());
} else {
channel_row[m_columns.m_type] = RenderType::VoiceChannel;
channel_row[m_columns.m_name] = Glib::Markup::escape_text(*channel.Name);
Expand Down Expand Up @@ -983,6 +1005,10 @@ 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);
} else if (channel.Type == ChannelType::GUILD_STAGE_VOICE) {
channel_row[m_columns.m_type] = RenderType::VoiceStage;
channel_row[m_columns.m_name] = Glib::Markup::escape_text(*channel.Name);
add_voice_participants(channel, channel_row->children());
} else {
channel_row[m_columns.m_type] = RenderType::VoiceChannel;
channel_row[m_columns.m_name] = Glib::Markup::escape_text(*channel.Name);
Expand Down Expand Up @@ -1033,7 +1059,7 @@ Gtk::TreeModel::iterator ChannelListTree::CreateVoiceParticipantRow(const UserDa

const auto voice_state = Abaddon::Get().GetDiscordClient().GetVoiceState(user.ID);
if (voice_state.has_value()) {
row[m_columns.m_voice_flags] = voice_state->second;
row[m_columns.m_voice_flags] = voice_state->second.Flags;
}

auto &img = Abaddon::Get().GetImageManager();
Expand Down Expand Up @@ -1331,6 +1357,10 @@ bool ChannelListTree::OnButtonPressEvent(GdkEventButton *ev) {
OnVoiceChannelSubmenuPopup();
m_menu_voice_channel.popup_at_pointer(reinterpret_cast<GdkEvent *>(ev));
break;
case RenderType::VoiceStage:
OnVoiceStageSubmenuPopup();
m_menu_voice_stage.popup_at_pointer(reinterpret_cast<GdkEvent *>(ev));
break;
case RenderType::DM: {
OnDMSubmenuPopup();
const auto channel = Abaddon::Get().GetDiscordClient().GetChannel(static_cast<Snowflake>(row[m_columns.m_id]));
Expand Down Expand Up @@ -1442,6 +1472,25 @@ void ChannelListTree::OnVoiceChannelSubmenuPopup() {
#endif
}

void ChannelListTree::OnVoiceStageSubmenuPopup() {
#ifdef WITH_VOICE
const auto iter = m_model->get_iter(m_path_for_menu);
if (!iter) return;
const auto id = static_cast<Snowflake>((*iter)[m_columns.m_id]);
auto &discord = Abaddon::Get().GetDiscordClient();
if (discord.IsVoiceConnected() || discord.IsVoiceConnecting()) {
m_menu_voice_stage_join.set_sensitive(false);
m_menu_voice_stage_disconnect.set_sensitive(discord.GetVoiceChannelID() == id);
} else {
m_menu_voice_stage_join.set_sensitive(true);
m_menu_voice_stage_disconnect.set_sensitive(false);
}
#else
m_menu_voice_stage_join.set_sensitive(false);
m_menu_voice_stage_disconnect.set_sensitive(false);
#endif
}

void ChannelListTree::OnDMSubmenuPopup() {
auto iter = m_model->get_iter(m_path_for_menu);
if (!iter) return;
Expand Down
5 changes: 5 additions & 0 deletions src/components/channellist/channellisttree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ class ChannelListTree : public Gtk::ScrolledWindow {
Gtk::Menu m_menu_voice_channel;
Gtk::MenuItem m_menu_voice_channel_join;
Gtk::MenuItem m_menu_voice_channel_disconnect;

Gtk::Menu m_menu_voice_stage;
Gtk::MenuItem m_menu_voice_stage_join;
Gtk::MenuItem m_menu_voice_stage_disconnect;
Gtk::MenuItem m_menu_voice_channel_mark_as_read;
Gtk::MenuItem m_menu_voice_open_chat;

Expand Down Expand Up @@ -192,6 +196,7 @@ class ChannelListTree : public Gtk::ScrolledWindow {
void OnDMSubmenuPopup();
void OnThreadSubmenuPopup();
void OnVoiceChannelSubmenuPopup();
void OnVoiceStageSubmenuPopup();

bool m_updating_listing = false;

Expand Down
16 changes: 0 additions & 16 deletions src/discord/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ enum class ChannelType : int {
GUILD_MEDIA = 16,
};

enum class StagePrivacy {
PUBLIC = 1,
GUILD_ONLY = 2,
};

constexpr const char *GetStagePrivacyDisplayString(StagePrivacy e) {
switch (e) {
case StagePrivacy::PUBLIC:
return "Public";
case StagePrivacy::GUILD_ONLY:
return "Guild Only";
default:
return "Unknown";
}
}

// should be moved somewhere?

struct ThreadMetadataData {
Expand Down
Loading

0 comments on commit 68db143

Please sign in to comment.