pull chat input permission check out of signal

This commit is contained in:
ouwou 2022-08-07 19:54:39 -04:00
parent 537d4163c2
commit 91527fbd0d
3 changed files with 16 additions and 15 deletions

View File

@ -457,9 +457,7 @@ ChatInput::ChatInput()
show_all_children();
m_input.Get().signal_image_paste().connect([this](const Glib::RefPtr<Gdk::Pixbuf> &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<Gio::File> &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<Gio::File> &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;
}

View File

@ -129,27 +129,29 @@ public:
void AddAttachment(const Glib::RefPtr<Gio::File> &file);
void IndicateTooLarge();
void SetActiveChannel(Snowflake id);
void StartReplying();
void StopReplying();
private:
bool AddFileAsImageAttachment(const Glib::RefPtr<Gio::File> &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<bool, ChatSubmitParams>;
using type_signal_escape = sigc::signal<void>;
using type_signal_check_permission = sigc::signal<bool, Permission>;
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;
};

View File

@ -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<Message> &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)