From 5c63fe94874b7629da28813d6c7363a002ed5fee Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 21 Aug 2021 03:48:24 -0400 Subject: [PATCH] hide pin/unpin if no perms, allow viewing pins in dm --- components/chatlist.cpp | 10 +++++++--- windows/mainwindow.cpp | 2 +- windows/pinnedwindow.cpp | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/components/chatlist.cpp b/components/chatlist.cpp index 86460b9..ba10de9 100644 --- a/components/chatlist.cpp +++ b/components/chatlist.cpp @@ -168,18 +168,22 @@ void ChatList::ProcessNewMessage(const Message &data, bool prepend) { const auto &client = Abaddon::Get().GetDiscordClient(); const auto data = client.GetMessage(id); if (!data.has_value()) return false; + const auto channel = client.GetChannel(m_active_channel); + + bool is_dm = channel.has_value() && (channel->Type == ChannelType::DM || channel->Type == ChannelType::GROUP_DM); + const bool has_manage = client.HasChannelPermission(client.GetUserData().ID, m_active_channel, Permission::MANAGE_MESSAGES); m_menu_edit_message->set_visible(!m_use_pinned_menu); m_menu_reply_to->set_visible(!m_use_pinned_menu); - m_menu_unpin->set_visible(data->IsPinned); - m_menu_pin->set_visible(!data->IsPinned); + m_menu_unpin->set_visible((is_dm || has_manage) && data->IsPinned); + m_menu_pin->set_visible((is_dm || has_manage) && !data->IsPinned); if (data->IsDeleted()) { m_menu_delete_message->set_sensitive(false); m_menu_edit_message->set_sensitive(false); } else { const bool can_edit = client.GetUserData().ID == data->Author.ID; - const bool can_delete = can_edit || client.HasChannelPermission(client.GetUserData().ID, m_active_channel, Permission::MANAGE_MESSAGES); + const bool can_delete = can_edit || has_manage; m_menu_delete_message->set_sensitive(can_delete); m_menu_edit_message->set_sensitive(can_edit); } diff --git a/windows/mainwindow.cpp b/windows/mainwindow.cpp index 0d77e96..8750afd 100644 --- a/windows/mainwindow.cpp +++ b/windows/mainwindow.cpp @@ -244,7 +244,7 @@ void MainWindow::OnViewSubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gd auto channel = Abaddon::Get().GetDiscordClient().GetChannel(channel_id); m_menu_view_pins.set_sensitive(false); if (channel.has_value()) - m_menu_view_pins.set_sensitive(channel->Type == ChannelType::GUILD_TEXT); + m_menu_view_pins.set_sensitive(channel->Type == ChannelType::GUILD_TEXT || channel->Type == ChannelType::DM || channel->Type == ChannelType::GROUP_DM); } ChannelList *MainWindow::GetChannelList() { diff --git a/windows/pinnedwindow.cpp b/windows/pinnedwindow.cpp index fc6230c..2e9b6fd 100644 --- a/windows/pinnedwindow.cpp +++ b/windows/pinnedwindow.cpp @@ -8,7 +8,10 @@ PinnedWindow::PinnedWindow(const ChannelData &data) set_name("pinned-messages"); set_default_size(450, 375); - set_title("#" + *data.Name + " - Pinned Messages"); + if (data.Name.has_value()) + set_title("#" + *data.Name + " - Pinned Messages"); + else + set_title("Pinned Messages"); set_position(Gtk::WIN_POS_CENTER); get_style_context()->add_class("app-window"); get_style_context()->add_class("app-popup");