summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2022-05-06 01:14:15 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2022-05-06 01:14:15 -0400
commit2c25319fb85e077f27c3a4cd0bfdc8f503c6020d (patch)
treee92422ddcb896fb6b5bb75576138100c4f32f43d /src
parent7daa0a250c76247c883cf536a3d339016a3852b4 (diff)
downloadabaddon-portaudio-2c25319fb85e077f27c3a4cd0bfdc8f503c6020d.tar.gz
abaddon-portaudio-2c25319fb85e077f27c3a4cd0bfdc8f503c6020d.zip
clear tabs when access lost, show blanks for missing channels
Diffstat (limited to 'src')
-rw-r--r--src/abaddon.cpp6
-rw-r--r--src/components/channels.cpp5
-rw-r--r--src/components/channeltabswitcherhandy.cpp14
-rw-r--r--src/components/channeltabswitcherhandy.hpp2
-rw-r--r--src/components/memberlist.cpp5
-rw-r--r--src/discord/discord.cpp40
-rw-r--r--src/discord/discord.hpp3
7 files changed, 68 insertions, 7 deletions
diff --git a/src/abaddon.cpp b/src/abaddon.cpp
index 4ca1462..fe37251 100644
--- a/src/abaddon.cpp
+++ b/src/abaddon.cpp
@@ -610,7 +610,11 @@ void Abaddon::ActionChannelOpened(Snowflake id, bool expand_to) {
m_main_window->GetChatWindow()->SetTopic("");
const auto channel = m_discord.GetChannel(id);
- if (!channel.has_value()) return;
+ if (!channel.has_value()) {
+ m_main_window->UpdateChatActiveChannel(Snowflake::Invalid, false);
+ m_main_window->UpdateChatWindowContents();
+ return;
+ }
const bool can_access = channel->IsDM() || m_discord.HasChannelPermission(m_discord.GetUserData().ID, id, Permission::VIEW_CHANNEL);
diff --git a/src/components/channels.cpp b/src/components/channels.cpp
index 2b83eb0..4e2e4df 100644
--- a/src/components/channels.cpp
+++ b/src/components/channels.cpp
@@ -931,7 +931,10 @@ void ChannelList::OnChannelSubmenuPopup() {
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]);
- if (Abaddon::Get().GetDiscordClient().IsChannelMuted(id))
+ auto &discord = Abaddon::Get().GetDiscordClient();
+ const auto perms = discord.HasChannelPermission(discord.GetUserData().ID, id, Permission::VIEW_CHANNEL);
+ m_menu_channel_open_tab.set_sensitive(perms);
+ if (discord.IsChannelMuted(id))
m_menu_channel_toggle_mute.set_label("Unmute");
else
m_menu_channel_toggle_mute.set_label("Mute");
diff --git a/src/components/channeltabswitcherhandy.cpp b/src/components/channeltabswitcherhandy.cpp
index f7b0226..67dbff0 100644
--- a/src/components/channeltabswitcherhandy.cpp
+++ b/src/components/channeltabswitcherhandy.cpp
@@ -37,6 +37,8 @@ ChannelTabSwitcherHandy::ChannelTabSwitcherHandy() {
discord.signal_message_ack().connect([this](const MessageAckData &data) {
CheckUnread(data.ChannelID);
});
+
+ discord.signal_channel_accessibility_changed().connect(sigc::mem_fun(*this, &ChannelTabSwitcherHandy::OnChannelAccessibilityChanged));
}
void ChannelTabSwitcherHandy::AddChannelTab(Snowflake id) {
@@ -195,6 +197,18 @@ void ChannelTabSwitcherHandy::AdvanceOnCurrent(size_t by) {
history->second.CurrentVisitedIndex = real;
}
+void ChannelTabSwitcherHandy::OnChannelAccessibilityChanged(Snowflake id, bool accessibility) {
+ if (accessibility) return;
+ if (auto it = m_pages.find(id); it != m_pages.end()) {
+ if (hdy_tab_page_get_selected(it->second))
+ if (!hdy_tab_view_select_previous_page(m_tab_view))
+ hdy_tab_view_select_next_page(m_tab_view);
+
+ hdy_tab_view_close_page(m_tab_view, it->second);
+ ClearPage(it->second);
+ }
+}
+
ChannelTabSwitcherHandy::type_signal_channel_switched_to ChannelTabSwitcherHandy::signal_channel_switched_to() {
return m_signal_channel_switched_to;
}
diff --git a/src/components/channeltabswitcherhandy.hpp b/src/components/channeltabswitcherhandy.hpp
index 561d463..6da9b17 100644
--- a/src/components/channeltabswitcherhandy.hpp
+++ b/src/components/channeltabswitcherhandy.hpp
@@ -35,6 +35,8 @@ private:
void AppendPageHistory(HdyTabPage *page, Snowflake channel);
void AdvanceOnCurrent(size_t by);
+ void OnChannelAccessibilityChanged(Snowflake id, bool accessibility);
+
HdyTabBar *m_tab_bar;
Gtk::Widget *m_tab_bar_wrapped;
HdyTabView *m_tab_view;
diff --git a/src/components/memberlist.cpp b/src/components/memberlist.cpp
index 4c95b63..85ccd05 100644
--- a/src/components/memberlist.cpp
+++ b/src/components/memberlist.cpp
@@ -160,10 +160,11 @@ void MemberList::UpdateMemberList() {
}
int num_rows = 0;
- const auto guild = *discord.GetGuild(m_guild_id);
+ const auto guild = discord.GetGuild(m_guild_id);
+ if (!guild.has_value()) return;
auto add_user = [this, &num_rows, guild](const UserData &data) -> bool {
if (num_rows++ > MaxMemberListRows) return false;
- auto *row = Gtk::manage(new MemberListUserRow(guild, data));
+ auto *row = Gtk::manage(new MemberListUserRow(*guild, data));
m_id_to_row[data.ID] = row;
AttachUserMenuHandler(row, data.ID);
m_listbox->add(*row);
diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp
index dda4b81..c3961b5 100644
--- a/src/discord/discord.cpp
+++ b/src/discord/discord.cpp
@@ -1622,18 +1622,27 @@ void DiscordClient::HandleGatewayChannelDelete(const GatewayMessage &msg) {
it->second.erase(id);
m_store.ClearChannel(id);
m_signal_channel_delete.emit(id);
+ m_signal_channel_accessibility_changed.emit(id, false);
}
void DiscordClient::HandleGatewayChannelUpdate(const GatewayMessage &msg) {
const auto id = msg.Data.at("id").get<Snowflake>();
auto cur = m_store.GetChannel(id);
if (cur.has_value()) {
+ const bool old_perms = HasChannelPermission(m_user_data.ID, id, Permission::VIEW_CHANNEL);
+
cur->update_from_json(msg.Data);
m_store.SetChannel(id, *cur);
if (cur->PermissionOverwrites.has_value())
for (const auto &p : *cur->PermissionOverwrites)
m_store.SetPermissionOverwrite(id, p.ID, p);
m_signal_channel_update.emit(id);
+
+ const bool new_perms = HasChannelPermission(m_user_data.ID, id, Permission::VIEW_CHANNEL);
+ if (old_perms && !new_perms)
+ m_signal_channel_accessibility_changed.emit(id, false);
+ else if (!old_perms && new_perms)
+ m_signal_channel_accessibility_changed.emit(id, true);
}
}
@@ -1660,8 +1669,26 @@ void DiscordClient::HandleGatewayGuildUpdate(const GatewayMessage &msg) {
void DiscordClient::HandleGatewayGuildRoleUpdate(const GatewayMessage &msg) {
GuildRoleUpdateObject data = msg.Data;
+
+ const auto channels = GetChannelsInGuild(data.GuildID);
+ std::unordered_set<Snowflake> accessible;
+ for (auto channel : channels) {
+ if (HasChannelPermission(m_user_data.ID, channel, Permission::VIEW_CHANNEL))
+ accessible.insert(channel);
+ }
+
m_store.SetRole(data.GuildID, data.Role);
m_signal_role_update.emit(data.GuildID, data.Role.ID);
+
+ for (auto channel : channels) {
+ const bool old_perms = accessible.find(channel) != accessible.end();
+ const bool new_perms = HasChannelPermission(m_user_data.ID, channel, Permission::VIEW_CHANNEL);
+ if (old_perms && !new_perms) {
+ m_signal_channel_accessibility_changed.emit(channel, false);
+ } else if (!old_perms && new_perms) {
+ m_signal_channel_accessibility_changed.emit(channel, true);
+ }
+ }
}
void DiscordClient::HandleGatewayGuildRoleCreate(const GatewayMessage &msg) {
@@ -2152,7 +2179,7 @@ void DiscordClient::HandleGatewayGuildCreate(const GatewayMessage &msg) {
void DiscordClient::HandleGatewayGuildDelete(const GatewayMessage &msg) {
Snowflake id = msg.Data.at("id");
- bool unavailable = msg.Data.contains("unavilable") && msg.Data.at("unavailable").get<bool>();
+ bool unavailable = msg.Data.contains("unavailable") && msg.Data.at("unavailable").get<bool>();
if (unavailable)
printf("guild %" PRIu64 " became unavailable\n", static_cast<uint64_t>(id));
@@ -2165,9 +2192,12 @@ void DiscordClient::HandleGatewayGuildDelete(const GatewayMessage &msg) {
}
m_store.ClearGuild(id);
- if (guild->Channels.has_value())
- for (const auto &c : *guild->Channels)
+ if (guild->Channels.has_value()) {
+ for (const auto &c : *guild->Channels) {
m_store.ClearChannel(c.ID);
+ m_signal_channel_accessibility_changed.emit(c.ID, false);
+ }
+ }
m_signal_guild_delete.emit(id);
}
@@ -2657,6 +2687,10 @@ DiscordClient::type_signal_guild_unmuted DiscordClient::signal_guild_unmuted() {
return m_signal_guild_unmuted;
}
+DiscordClient::type_signal_channel_accessibility_changed DiscordClient::signal_channel_accessibility_changed() {
+ return m_signal_channel_accessibility_changed;
+}
+
DiscordClient::type_signal_message_send_fail DiscordClient::signal_message_send_fail() {
return m_signal_message_send_fail;
}
diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp
index 2af2d30..1c09fc1 100644
--- a/src/discord/discord.hpp
+++ b/src/discord/discord.hpp
@@ -396,6 +396,7 @@ public:
typedef sigc::signal<void, Snowflake> type_signal_channel_unmuted;
typedef sigc::signal<void, Snowflake> type_signal_guild_muted;
typedef sigc::signal<void, Snowflake> type_signal_guild_unmuted;
+ typedef sigc::signal<void, Snowflake, bool> type_signal_channel_accessibility_changed;
typedef sigc::signal<void, std::string /* nonce */, float /* retry_after */> type_signal_message_send_fail; // retry after param will be 0 if it failed for a reason that isnt slowmode
typedef sigc::signal<void, bool, GatewayCloseCode> type_signal_disconnected; // bool true if reconnecting
@@ -449,6 +450,7 @@ public:
type_signal_channel_unmuted signal_channel_unmuted();
type_signal_guild_muted signal_guild_muted();
type_signal_guild_unmuted signal_guild_unmuted();
+ type_signal_channel_accessibility_changed signal_channel_accessibility_changed();
type_signal_message_send_fail signal_message_send_fail();
type_signal_disconnected signal_disconnected();
type_signal_connected signal_connected();
@@ -502,6 +504,7 @@ protected:
type_signal_channel_unmuted m_signal_channel_unmuted;
type_signal_guild_muted m_signal_guild_muted;
type_signal_guild_unmuted m_signal_guild_unmuted;
+ type_signal_channel_accessibility_changed m_signal_channel_accessibility_changed;
type_signal_message_send_fail m_signal_message_send_fail;
type_signal_disconnected m_signal_disconnected;
type_signal_connected m_signal_connected;