diff --git a/src/components/chatinput.cpp b/src/components/chatinput.cpp index 65b3c30..63bd48b 100644 --- a/src/components/chatinput.cpp +++ b/src/components/chatinput.cpp @@ -457,9 +457,7 @@ ChatInput::ChatInput() show_all_children(); m_input.Get().signal_image_paste().connect([this](const Glib::RefPtr &pb) { - const bool can_attach_files = m_signal_check_permission.emit(Permission::ATTACH_FILES); - - if (can_attach_files && m_attachments.AddImage(pb)) + if (CanAttachFiles() && m_attachments.AddImage(pb)) m_attachments_revealer.set_reveal_child(true); }); @@ -487,8 +485,7 @@ bool ChatInput::ProcessKeyPress(GdkEventKey *event) { } void ChatInput::AddAttachment(const Glib::RefPtr &file) { - const bool can_attach_files = m_signal_check_permission.emit(Permission::ATTACH_FILES); - if (!can_attach_files) return; + if (!CanAttachFiles()) return; std::string content_type; @@ -527,6 +524,10 @@ void ChatInput::IndicateTooLarge() { Glib::signal_timeout().connect_seconds_once(sigc::track_obj(cb, *this), 2); } +void ChatInput::SetActiveChannel(Snowflake id) { + m_active_channel = id; +} + void ChatInput::StartReplying() { m_input.Get().grab_focus(); m_input.Get().get_style_context()->add_class("replying"); @@ -547,6 +548,10 @@ bool ChatInput::AddFileAsImageAttachment(const Glib::RefPtr &file) { } } +bool ChatInput::CanAttachFiles() { + return Abaddon::Get().GetDiscordClient().HasSelfChannelPermission(m_active_channel, Permission::ATTACH_FILES); +} + ChatInput::type_signal_submit ChatInput::signal_submit() { return m_signal_submit; } @@ -554,7 +559,3 @@ ChatInput::type_signal_submit ChatInput::signal_submit() { ChatInput::type_signal_escape ChatInput::signal_escape() { return m_signal_escape; } - -ChatInput::type_signal_check_permission ChatInput::signal_check_permission() { - return m_signal_check_permission; -} diff --git a/src/components/chatinput.hpp b/src/components/chatinput.hpp index 82ea2fd..f6c4358 100644 --- a/src/components/chatinput.hpp +++ b/src/components/chatinput.hpp @@ -129,27 +129,29 @@ public: void AddAttachment(const Glib::RefPtr &file); void IndicateTooLarge(); + void SetActiveChannel(Snowflake id); + void StartReplying(); void StopReplying(); private: bool AddFileAsImageAttachment(const Glib::RefPtr &file); + bool CanAttachFiles(); Gtk::Revealer m_attachments_revealer; ChatInputAttachmentContainer m_attachments; ChatInputTextContainer m_input; + Snowflake m_active_channel; + public: using type_signal_submit = sigc::signal; using type_signal_escape = sigc::signal; - using type_signal_check_permission = sigc::signal; type_signal_submit signal_submit(); type_signal_escape signal_escape(); - type_signal_check_permission signal_check_permission(); private: type_signal_submit m_signal_submit; type_signal_escape m_signal_escape; - type_signal_check_permission m_signal_check_permission; }; diff --git a/src/components/chatwindow.cpp b/src/components/chatwindow.cpp index b68ceba..f7c3459 100644 --- a/src/components/chatwindow.cpp +++ b/src/components/chatwindow.cpp @@ -49,9 +49,6 @@ ChatWindow::ChatWindow() { m_input->set_valign(Gtk::ALIGN_END); - m_input->signal_check_permission().connect([this](Permission perm) { - return Abaddon::Get().GetDiscordClient().HasSelfChannelPermission(m_active_channel, perm); - }); m_input->signal_submit().connect(sigc::mem_fun(*this, &ChatWindow::OnInputSubmit)); m_input->signal_escape().connect([this]() { if (m_is_replying) @@ -133,6 +130,7 @@ void ChatWindow::SetMessages(const std::vector &msgs) { void ChatWindow::SetActiveChannel(Snowflake id) { m_active_channel = id; m_chat->SetActiveChannel(id); + m_input->SetActiveChannel(id); m_input_indicator->SetActiveChannel(id); m_rate_limit_indicator->SetActiveChannel(id); if (m_is_replying)