mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-13 20:18:50 +03:00
refactor send message params into one struct
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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>;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user