Skip to content

Commit

Permalink
view image alt text on hover
Browse files Browse the repository at this point in the history
  • Loading branch information
ouwou committed Dec 14, 2023
1 parent 260fc2a commit 23bf237
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/components/chatmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/discord/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions src/discord/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/discord/store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -1509,6 +1511,7 @@ bool Store::CreateTables() {
proxy TEXT NOT NULL,
height INTEGER,
width INTEGER,
description TEXT,
PRIMARY KEY(message, id)
)
)";
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 23bf237

Please sign in to comment.