diff options
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/chatinput.cpp | 20 | ||||
-rw-r--r-- | src/components/chatinput.hpp | 9 | ||||
-rw-r--r-- | src/components/chatwindow.cpp | 9 | ||||
-rw-r--r-- | src/components/chatwindow.hpp | 5 |
4 files changed, 28 insertions, 15 deletions
diff --git a/src/components/chatinput.cpp b/src/components/chatinput.cpp index f9bbce4..2b8b5a5 100644 --- a/src/components/chatinput.cpp +++ b/src/components/chatinput.cpp @@ -152,10 +152,10 @@ bool ChatInputAttachmentContainer::AddImage(const Glib::RefPtr<Gdk::Pixbuf> &pb) return true; } -std::vector<std::string> ChatInputAttachmentContainer::GetFilePaths() const { - std::vector<std::string> ret; +std::vector<ChatSubmitParams::Attachment> ChatInputAttachmentContainer::GetAttachments() const { + std::vector<ChatSubmitParams::Attachment> ret; for (auto *x : m_attachments) - ret.push_back(x->GetPath()); + ret.push_back({ x->GetPath(), x->GetType() }); return ret; } @@ -165,7 +165,8 @@ ChatInputAttachmentContainer::type_signal_emptied ChatInputAttachmentContainer:: ChatInputAttachmentItem::ChatInputAttachmentItem(std::string path, const Glib::RefPtr<Gdk::Pixbuf> &pb) : m_path(std::move(path)) - , m_img(Gtk::make_managed<Gtk::Image>()) { + , m_img(Gtk::make_managed<Gtk::Image>()) + , m_type(ChatSubmitParams::PastedImage) { get_style_context()->add_class("attachment-item"); int outw, outh; @@ -184,6 +185,10 @@ std::string ChatInputAttachmentItem::GetPath() const { return m_path; } +ChatSubmitParams::AttachmentType ChatInputAttachmentItem::GetType() const { + return m_type; +} + void ChatInputAttachmentItem::SetupMenu() { m_menu_remove.set_label("Remove"); m_menu_remove.signal_activate().connect([this] { @@ -215,8 +220,11 @@ ChatInput::ChatInput() m_signal_escape.emit(); }); m_input.signal_submit().connect([this](const Glib::ustring &input) -> bool { - const auto attachments = m_attachments.GetFilePaths(); - bool b = m_signal_submit.emit(input, attachments); + ChatSubmitParams data; + data.Message = input; + data.Attachments = m_attachments.GetAttachments(); + + bool b = m_signal_submit.emit(data); if (b) { m_attachments_revealer.set_reveal_child(false); m_attachments.ClearNoPurge(); diff --git a/src/components/chatinput.hpp b/src/components/chatinput.hpp index bdbac5c..ba3ab36 100644 --- a/src/components/chatinput.hpp +++ b/src/components/chatinput.hpp @@ -1,5 +1,6 @@ #pragma once #include <gtkmm.h> +#include "discord/chatsubmitparams.hpp" #include "discord/permissions.hpp" class ChatInputAttachmentItem : public Gtk::EventBox { @@ -7,6 +8,7 @@ public: ChatInputAttachmentItem(std::string path, const Glib::RefPtr<Gdk::Pixbuf> &pb); [[nodiscard]] std::string GetPath() const; + [[nodiscard]] ChatSubmitParams::AttachmentType GetType() const; private: void SetupMenu(); @@ -18,6 +20,7 @@ private: Gtk::Image *m_img = nullptr; std::string m_path; + ChatSubmitParams::AttachmentType m_type; private: using type_signal_remove = sigc::signal<void>; @@ -35,7 +38,7 @@ public: void Clear(); void ClearNoPurge(); bool AddImage(const Glib::RefPtr<Gdk::Pixbuf> &pb); - [[nodiscard]] std::vector<std::string> GetFilePaths() const; + [[nodiscard]] std::vector<ChatSubmitParams::Attachment> GetAttachments() const; private: std::set<ChatInputAttachmentItem *> m_attachments; @@ -96,9 +99,7 @@ private: ChatInputText m_input; public: - // text, attachments -> request sent - // maybe this should be reduced to a single struct, its bound to get more complicated (application commands?) - using type_signal_submit = sigc::signal<bool, Glib::ustring, std::vector<std::string>>; + using type_signal_submit = sigc::signal<bool, ChatSubmitParams>; using type_signal_escape = sigc::signal<void>; using type_signal_check_permission = sigc::signal<bool, Permission>; diff --git a/src/components/chatwindow.cpp b/src/components/chatwindow.cpp index 52c2a60..3e1885b 100644 --- a/src/components/chatwindow.cpp +++ b/src/components/chatwindow.cpp @@ -212,15 +212,18 @@ Snowflake ChatWindow::GetActiveChannel() const { return m_active_channel; } -bool ChatWindow::OnInputSubmit(const Glib::ustring &text, const std::vector<std::string> &attachment_paths) { +bool ChatWindow::OnInputSubmit(ChatSubmitParams data) { if (!m_rate_limit_indicator->CanSpeak()) return false; - if (text.empty() && attachment_paths.empty()) + if (data.Message.empty() && data.Attachments.empty()) return false; + data.ChannelID = m_active_channel; + data.InReplyToID = m_replying_to; + if (m_active_channel.IsValid()) - m_signal_action_chat_submit.emit(text, attachment_paths, m_active_channel, m_replying_to); // m_replying_to is checked for invalid in the handler + m_signal_action_chat_submit.emit(data); // m_replying_to is checked for invalid in the handler if (m_is_replying) StopReplying(); diff --git a/src/components/chatwindow.hpp b/src/components/chatwindow.hpp index ab0bee1..ecbf666 100644 --- a/src/components/chatwindow.hpp +++ b/src/components/chatwindow.hpp @@ -3,6 +3,7 @@ #include <string> #include <set> #include "discord/discord.hpp" +#include "discord/chatsubmitparams.hpp" #include "completer.hpp" #include "state.hpp" @@ -55,7 +56,7 @@ protected: Snowflake m_active_channel; - bool OnInputSubmit(const Glib::ustring &text, const std::vector<std::string> &attachment_paths); + bool OnInputSubmit(ChatSubmitParams data); bool OnKeyPressEvent(GdkEventKey *e); void OnScrollEdgeOvershot(Gtk::PositionType pos); @@ -84,7 +85,7 @@ protected: public: using type_signal_action_message_edit = sigc::signal<void, Snowflake, Snowflake>; - using type_signal_action_chat_submit = sigc::signal<void, std::string, std::vector<std::string>, Snowflake, Snowflake>; + using type_signal_action_chat_submit = sigc::signal<void, ChatSubmitParams>; using type_signal_action_chat_load_history = sigc::signal<void, Snowflake>; using type_signal_action_channel_click = sigc::signal<void, Snowflake, bool>; using type_signal_action_insert_mention = sigc::signal<void, Snowflake>; |