mirror of
https://github.com/uowuo/abaddon.git
synced 2024-11-10 06:00:10 +00:00
Merge branch 'master' into theming
This commit is contained in:
commit
af31402b7f
@ -262,7 +262,7 @@ std::vector<ChatSubmitParams::Attachment> ChatInputAttachmentContainer::GetAttac
|
||||
for (auto *x : m_attachments) {
|
||||
if (!x->GetFile()->query_exists())
|
||||
puts("bad!");
|
||||
ret.push_back({ x->GetFile(), x->GetType(), x->GetFilename() });
|
||||
ret.push_back({ x->GetFile(), x->GetType(), x->GetFilename(), x->GetDescription() });
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -310,6 +310,7 @@ ChatInputAttachmentItem::ChatInputAttachmentItem(const Glib::RefPtr<Gio::File> &
|
||||
, m_img(Gtk::make_managed<Gtk::Image>())
|
||||
, m_type(is_extant ? ChatSubmitParams::ExtantFile : ChatSubmitParams::PastedImage)
|
||||
, m_filename("unknown.png")
|
||||
, m_is_image(true)
|
||||
, m_label("unknown.png")
|
||||
, m_box(Gtk::ORIENTATION_VERTICAL) {
|
||||
get_style_context()->add_class("attachment-item");
|
||||
@ -356,10 +357,18 @@ std::string ChatInputAttachmentItem::GetFilename() const {
|
||||
return m_filename;
|
||||
}
|
||||
|
||||
std::optional<std::string> ChatInputAttachmentItem::GetDescription() const {
|
||||
return m_description.empty() ? std::nullopt : std::optional<std::string>(m_description);
|
||||
}
|
||||
|
||||
bool ChatInputAttachmentItem::IsTemp() const noexcept {
|
||||
return m_type == ChatSubmitParams::PastedImage;
|
||||
}
|
||||
|
||||
bool ChatInputAttachmentItem::IsImage() const noexcept {
|
||||
return m_is_image;
|
||||
}
|
||||
|
||||
void ChatInputAttachmentItem::RemoveIfTemp() {
|
||||
if (IsTemp())
|
||||
m_file->remove();
|
||||
@ -387,12 +396,22 @@ void ChatInputAttachmentItem::SetupMenu() {
|
||||
}
|
||||
});
|
||||
|
||||
m_menu_set_alt_text.set_label("Change Alt-Text");
|
||||
m_menu_set_alt_text.signal_activate().connect([this]() {
|
||||
const auto description = Abaddon::Get().ShowTextPrompt("Enter description (alt-text) for attachment", "Enter alt-text", m_description);
|
||||
if (description.has_value()) {
|
||||
m_description = *description;
|
||||
}
|
||||
});
|
||||
|
||||
m_menu.add(m_menu_set_filename);
|
||||
m_menu.add(m_menu_set_alt_text);
|
||||
m_menu.add(m_menu_remove);
|
||||
m_menu.show_all();
|
||||
|
||||
signal_button_press_event().connect([this](GdkEventButton *ev) -> bool {
|
||||
if (ev->button == GDK_BUTTON_SECONDARY) {
|
||||
m_menu_set_alt_text.set_visible(IsImage());
|
||||
m_menu.popup_at_pointer(reinterpret_cast<GdkEvent *>(ev));
|
||||
return true;
|
||||
}
|
||||
|
@ -7,10 +7,13 @@ public:
|
||||
ChatInputAttachmentItem(const Glib::RefPtr<Gio::File> &file);
|
||||
ChatInputAttachmentItem(const Glib::RefPtr<Gio::File> &file, const Glib::RefPtr<Gdk::Pixbuf> &pb, bool is_extant = false);
|
||||
|
||||
[[nodiscard]] Glib::RefPtr<Gio::File> GetFile() const;
|
||||
[[nodiscard]] ChatSubmitParams::AttachmentType GetType() const;
|
||||
[[nodiscard]] std::string GetFilename() const;
|
||||
[[nodiscard]] bool IsTemp() const noexcept;
|
||||
Glib::RefPtr<Gio::File> GetFile() const;
|
||||
ChatSubmitParams::AttachmentType GetType() const;
|
||||
std::string GetFilename() const;
|
||||
std::optional<std::string> GetDescription() const;
|
||||
bool IsTemp() const noexcept;
|
||||
bool IsImage() const noexcept;
|
||||
|
||||
void RemoveIfTemp();
|
||||
|
||||
private:
|
||||
@ -21,6 +24,7 @@ private:
|
||||
Gtk::Menu m_menu;
|
||||
Gtk::MenuItem m_menu_remove;
|
||||
Gtk::MenuItem m_menu_set_filename;
|
||||
Gtk::MenuItem m_menu_set_alt_text;
|
||||
|
||||
Gtk::Box m_box;
|
||||
Gtk::Label m_label;
|
||||
@ -29,6 +33,8 @@ private:
|
||||
Glib::RefPtr<Gio::File> m_file;
|
||||
ChatSubmitParams::AttachmentType m_type;
|
||||
std::string m_filename;
|
||||
std::string m_description;
|
||||
bool m_is_image = false;
|
||||
|
||||
private:
|
||||
using type_signal_item_removed = sigc::signal<void>;
|
||||
|
@ -46,6 +46,9 @@ ChatMessageItemContainer *ChatMessageItemContainer::FromMessage(const Message &d
|
||||
for (const auto &a : data.Attachments) {
|
||||
if (IsURLViewableImage(a.ProxyURL) && a.Width.has_value() && a.Height.has_value()) {
|
||||
auto *widget = container->CreateImageComponent(a.ProxyURL, a.URL, *a.Width, *a.Height);
|
||||
if (a.Description.has_value()) {
|
||||
widget->set_tooltip_text(*a.Description);
|
||||
}
|
||||
container->m_main.add(*widget);
|
||||
} else {
|
||||
auto *widget = container->CreateAttachmentComponent(a);
|
||||
@ -661,7 +664,12 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data)
|
||||
if (role.has_value()) {
|
||||
const auto author = discord.GetUser(author_id);
|
||||
if (author.has_value()) {
|
||||
return "<b><span color=\"#" + IntToCSSColor(role->Color) + "\">" + author->GetDisplayNameEscaped(guild_id) + "</span></b>";
|
||||
const auto is_mention = !data.Interaction.has_value() && data.DoesMention(author_id);
|
||||
if (is_mention) {
|
||||
return "<b><span color=\"#" + IntToCSSColor(role->Color) + "\">@" + author->GetDisplayNameEscaped(guild_id) + "</span></b>";
|
||||
} else {
|
||||
return "<b><span color=\"#" + IntToCSSColor(role->Color) + "\">" + author->GetDisplayNameEscaped(guild_id) + "</span></b>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -717,16 +725,12 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data)
|
||||
HandleChannelMentions(buf);
|
||||
text = Glib::Markup::escape_text(buf->get_text());
|
||||
}
|
||||
// getting markup out of a textbuffer seems like something that to me should be really simple
|
||||
// but actually is horribly annoying. replies won't have mention colors because you can't do this
|
||||
// also no emojis because idk how to make a textview act like a label
|
||||
// which of course would not be an issue if i could figure out how to get fonts to work on this god-forsaken framework
|
||||
// oh well
|
||||
// but ill manually get colors for the user who is being replied to
|
||||
if (referenced.GuildID.has_value())
|
||||
|
||||
if (referenced.GuildID.has_value()) {
|
||||
lbl->set_markup(get_author_markup(referenced.Author.ID, *referenced.GuildID) + ": " + text);
|
||||
else
|
||||
} else {
|
||||
lbl->set_markup(get_author_markup(referenced.Author.ID) + ": " + text);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lbl->set_markup("<i>reply unavailable</i>");
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <glibmm/ustring.h>
|
||||
@ -15,6 +16,7 @@ struct ChatSubmitParams {
|
||||
Glib::RefPtr<Gio::File> File;
|
||||
AttachmentType Type;
|
||||
std::string Filename;
|
||||
std::optional<std::string> Description;
|
||||
};
|
||||
|
||||
bool Silent = false;
|
||||
|
@ -518,6 +518,7 @@ void DiscordClient::SendChatMessageAttachments(const ChatSubmitParams ¶ms, c
|
||||
CreateMessageObject obj;
|
||||
obj.Content = params.Message;
|
||||
obj.Nonce = nonce;
|
||||
obj.Attachments.emplace();
|
||||
if (params.Silent) {
|
||||
obj.Flags |= MessageFlags::SUPPRESS_NOTIFICATIONS;
|
||||
}
|
||||
@ -541,11 +542,16 @@ void DiscordClient::SendChatMessageAttachments(const ChatSubmitParams ¶ms, c
|
||||
m_generic_dispatch.emit();
|
||||
});
|
||||
req.make_form();
|
||||
req.add_field("payload_json", nlohmann::json(obj).dump().c_str(), CURL_ZERO_TERMINATED);
|
||||
|
||||
for (size_t i = 0; i < params.Attachments.size(); i++) {
|
||||
auto &attachment = params.Attachments.at(i);
|
||||
const auto field_name = "files[" + std::to_string(i) + "]";
|
||||
req.add_file(field_name, params.Attachments.at(i).File, params.Attachments.at(i).Filename);
|
||||
req.add_file(field_name, attachment.File, attachment.Filename);
|
||||
obj.Attachments->push_back({ static_cast<int>(i), attachment.Description });
|
||||
}
|
||||
|
||||
req.add_field("payload_json", nlohmann::json(obj).dump().c_str(), CURL_ZERO_TERMINATED);
|
||||
|
||||
m_http.Execute(std::move(req), [this, params, nonce, callback](const http::response_type &res) {
|
||||
for (const auto &attachment : params.Attachments) {
|
||||
if (attachment.Type == ChatSubmitParams::AttachmentType::PastedImage) {
|
||||
|
@ -128,6 +128,7 @@ void to_json(nlohmann::json &j, const AttachmentData &m) {
|
||||
j["proxy_url"] = m.ProxyURL;
|
||||
JS_IF("height", m.Height);
|
||||
JS_IF("width", m.Width);
|
||||
JS_IF("description", m.Description);
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json &j, AttachmentData &m) {
|
||||
@ -138,6 +139,7 @@ void from_json(const nlohmann::json &j, AttachmentData &m) {
|
||||
JS_D("proxy_url", m.ProxyURL);
|
||||
JS_ON("height", m.Height);
|
||||
JS_ON("width", m.Width);
|
||||
JS_ON("description", m.Description);
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json &j, MessageReferenceData &m) {
|
||||
|
@ -168,8 +168,9 @@ struct AttachmentData {
|
||||
int Bytes;
|
||||
std::string URL;
|
||||
std::string ProxyURL;
|
||||
std::optional<int> Height; // null
|
||||
std::optional<int> Width; // null
|
||||
std::optional<int> Height; // null
|
||||
std::optional<int> Width; // null
|
||||
std::optional<std::string> Description; // alt text
|
||||
|
||||
friend void to_json(nlohmann::json &j, const AttachmentData &m);
|
||||
friend void from_json(const nlohmann::json &j, AttachmentData &m);
|
||||
|
@ -306,9 +306,15 @@ void to_json(nlohmann::json &j, const HeartbeatMessage &m) {
|
||||
j["d"] = m.Sequence;
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json &j, const CreateMessageAttachmentObject &m) {
|
||||
j["id"] = m.ID;
|
||||
JS_IF("description", m.Description);
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json &j, const CreateMessageObject &m) {
|
||||
j["content"] = m.Content;
|
||||
j["flags"] = m.Flags;
|
||||
JS_IF("attachments", m.Attachments);
|
||||
JS_IF("message_reference", m.MessageReference);
|
||||
JS_IF("nonce", m.Nonce);
|
||||
}
|
||||
|
@ -433,11 +433,19 @@ struct HeartbeatMessage : GatewayMessage {
|
||||
friend void to_json(nlohmann::json &j, const HeartbeatMessage &m);
|
||||
};
|
||||
|
||||
struct CreateMessageAttachmentObject {
|
||||
int ID;
|
||||
std::optional<std::string> Description;
|
||||
|
||||
friend void to_json(nlohmann::json &j, const CreateMessageAttachmentObject &m);
|
||||
};
|
||||
|
||||
struct CreateMessageObject {
|
||||
std::string Content;
|
||||
MessageFlags Flags = MessageFlags::NONE;
|
||||
std::optional<MessageReferenceData> MessageReference;
|
||||
std::optional<std::string> Nonce;
|
||||
std::optional<std::vector<CreateMessageAttachmentObject>> Attachments;
|
||||
|
||||
friend void to_json(nlohmann::json &j, const CreateMessageObject &m);
|
||||
};
|
||||
|
@ -368,6 +368,7 @@ void Store::SetMessage(Snowflake id, const Message &message) {
|
||||
s->Bind(6, a.ProxyURL);
|
||||
s->Bind(7, a.Height);
|
||||
s->Bind(8, a.Width);
|
||||
s->Bind(9, a.Description);
|
||||
if (!s->Insert())
|
||||
fprintf(stderr, "message attachment insert failed for %" PRIu64 "/%" PRIu64 ": %s\n", static_cast<uint64_t>(id), static_cast<uint64_t>(a.ID), m_db.ErrStr());
|
||||
s->Reset();
|
||||
@ -975,7 +976,7 @@ Message Store::GetMessageBound(std::unique_ptr<Statement> &s) const {
|
||||
s->Get(5, r.Timestamp);
|
||||
s->Get(6, r.EditedTimestamp);
|
||||
// s->Get(7, r.IsTTS);
|
||||
// s->Get(8, r.DoesMentionEveryone);
|
||||
s->Get(8, r.DoesMentionEveryone);
|
||||
s->GetJSON(9, r.Embeds);
|
||||
s->Get(10, r.IsPinned);
|
||||
s->Get(11, r.WebhookID);
|
||||
@ -1021,6 +1022,7 @@ Message Store::GetMessageBound(std::unique_ptr<Statement> &s) const {
|
||||
s->Get(5, q.ProxyURL);
|
||||
s->Get(6, q.Height);
|
||||
s->Get(7, q.Width);
|
||||
s->Get(8, q.Description);
|
||||
}
|
||||
s->Reset();
|
||||
}
|
||||
@ -1509,6 +1511,7 @@ bool Store::CreateTables() {
|
||||
proxy TEXT NOT NULL,
|
||||
height INTEGER,
|
||||
width INTEGER,
|
||||
description TEXT,
|
||||
PRIMARY KEY(message, id)
|
||||
)
|
||||
)";
|
||||
@ -2212,7 +2215,7 @@ bool Store::CreateStatements() {
|
||||
|
||||
m_stmt_set_attachment = std::make_unique<Statement>(m_db, R"(
|
||||
REPLACE INTO attachments VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?, ?
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
)");
|
||||
if (!m_stmt_set_attachment->OK()) {
|
||||
|
Loading…
Reference in New Issue
Block a user