diff options
Diffstat (limited to 'src/discord')
-rw-r--r-- | src/discord/chatsubmitparams.hpp | 2 | ||||
-rw-r--r-- | src/discord/discord.cpp | 10 | ||||
-rw-r--r-- | src/discord/message.cpp | 2 | ||||
-rw-r--r-- | src/discord/message.hpp | 5 | ||||
-rw-r--r-- | src/discord/objects.cpp | 6 | ||||
-rw-r--r-- | src/discord/objects.hpp | 8 | ||||
-rw-r--r-- | src/discord/store.cpp | 7 |
7 files changed, 34 insertions, 6 deletions
diff --git a/src/discord/chatsubmitparams.hpp b/src/discord/chatsubmitparams.hpp index e195189..45fbb2a 100644 --- a/src/discord/chatsubmitparams.hpp +++ b/src/discord/chatsubmitparams.hpp @@ -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; diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 0618e72..ac7e2f2 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -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) { diff --git a/src/discord/message.cpp b/src/discord/message.cpp index bc4c6c8..8a0e271 100644 --- a/src/discord/message.cpp +++ b/src/discord/message.cpp @@ -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) { diff --git a/src/discord/message.hpp b/src/discord/message.hpp index b71c158..1e836d0 100644 --- a/src/discord/message.hpp +++ b/src/discord/message.hpp @@ -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); diff --git a/src/discord/objects.cpp b/src/discord/objects.cpp index 4ad17c3..804f10d 100644 --- a/src/discord/objects.cpp +++ b/src/discord/objects.cpp @@ -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); } diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp index 603a9c7..dfe99f0 100644 --- a/src/discord/objects.hpp +++ b/src/discord/objects.hpp @@ -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); }; diff --git a/src/discord/store.cpp b/src/discord/store.cpp index 817f71f..bf630aa 100644 --- a/src/discord/store.cpp +++ b/src/discord/store.cpp @@ -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()) { |