mirror of
https://github.com/uowuo/abaddon.git
synced 2024-11-10 14:10:10 +00:00
show non-lottie stickers statically
This commit is contained in:
parent
8efa202458
commit
b97722e937
@ -67,6 +67,16 @@ ChatMessageItemContainer *ChatMessageItemContainer::FromMessage(Snowflake id) {
|
||||
}
|
||||
}
|
||||
|
||||
// only 1?
|
||||
if (data->Stickers.has_value()) {
|
||||
const auto &sticker = data->Stickers.value()[0];
|
||||
// todo: lottie
|
||||
if (sticker.FormatType == StickerFormatType::PNG || sticker.FormatType == StickerFormatType::APNG) {
|
||||
auto *widget = container->CreateStickerComponent(sticker);
|
||||
container->m_main->add(*widget);
|
||||
}
|
||||
}
|
||||
|
||||
container->UpdateAttributes();
|
||||
|
||||
return container;
|
||||
@ -363,6 +373,23 @@ Gtk::Box *ChatMessageItemContainer::CreateAttachmentComponent(const AttachmentDa
|
||||
return box;
|
||||
}
|
||||
|
||||
Gtk::Box *ChatMessageItemContainer::CreateStickerComponent(const Sticker &data) {
|
||||
auto *box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
|
||||
auto *imgw = Gtk::manage(new Gtk::Image);
|
||||
auto &img = Abaddon::Get().GetImageManager();
|
||||
|
||||
if (data.FormatType == StickerFormatType::PNG || data.FormatType == StickerFormatType::APNG) {
|
||||
// clang-format off
|
||||
img.LoadFromURL(data.GetURL(), sigc::track_obj([this, imgw](const Glib::RefPtr<Gdk::Pixbuf> &pixbuf) {
|
||||
imgw->property_pixbuf() = pixbuf;
|
||||
}, imgw));
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
box->add(*imgw);
|
||||
return box;
|
||||
}
|
||||
|
||||
void ChatMessageItemContainer::HandleImage(const AttachmentData &data, Gtk::Image *img, std::string url) {
|
||||
m_img_loadmap[url] = std::make_pair(img, data);
|
||||
// ask the chatwindow to call UpdateImage because dealing with lifetimes sucks
|
||||
|
@ -24,6 +24,7 @@ protected:
|
||||
Gtk::EventBox *CreateEmbedComponent(const Message *data); // Message.Embeds[0]
|
||||
Gtk::Image *CreateImageComponent(const AttachmentData &data);
|
||||
Gtk::Box *CreateAttachmentComponent(const AttachmentData &data); // non-image attachments
|
||||
Gtk::Box *CreateStickerComponent(const Sticker &data);
|
||||
void HandleImage(const AttachmentData &data, Gtk::Image *img, std::string url);
|
||||
|
||||
static Glib::ustring GetText(const Glib::RefPtr<Gtk::TextBuffer> &buf);
|
||||
|
@ -109,6 +109,7 @@ void from_json(const nlohmann::json &j, Message &m) {
|
||||
// JS_O("application", m.Application);
|
||||
// JS_O("message_reference", m.MessageReference);
|
||||
JS_O("flags", m.Flags);
|
||||
JS_O("stickers", m.Stickers);
|
||||
}
|
||||
|
||||
void Message::from_json_edited(const nlohmann::json &j) {
|
||||
@ -130,6 +131,7 @@ void Message::from_json_edited(const nlohmann::json &j) {
|
||||
JS_O("webhook_id", WebhookID);
|
||||
JS_O("type", Type);
|
||||
JS_O("flags", Flags);
|
||||
JS_O("stickers", Stickers);
|
||||
}
|
||||
|
||||
void Message::SetDeleted() {
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "snowflake.hpp"
|
||||
#include "json.hpp"
|
||||
#include "user.hpp"
|
||||
#include "sticker.hpp"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -154,6 +155,7 @@ struct Message {
|
||||
// std::optional<MessageApplicationData> Application;
|
||||
std::optional<MessageReferenceData> MessageReference;
|
||||
std::optional<MessageFlags> Flags = MessageFlags::NONE;
|
||||
std::optional<std::vector<Sticker>> Stickers;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Message &m);
|
||||
void from_json_edited(const nlohmann::json &j); // for MESSAGE_UPDATE
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "permissions.hpp"
|
||||
#include "emoji.hpp"
|
||||
#include "activity.hpp"
|
||||
#include "sticker.hpp"
|
||||
|
||||
// most stuff below should just be objects that get processed and thrown away immediately
|
||||
|
||||
|
21
discord/sticker.cpp
Normal file
21
discord/sticker.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "sticker.hpp"
|
||||
|
||||
void from_json(const nlohmann::json &j, Sticker &m) {
|
||||
JS_D("id", m.ID);
|
||||
JS_D("pack_id", m.PackID);
|
||||
JS_D("name", m.Name);
|
||||
JS_D("description", m.Description);
|
||||
JS_O("tags", m.Tags);
|
||||
JS_D("asset", m.AssetHash);
|
||||
JS_N("preview_asset", m.PreviewAssetHash);
|
||||
JS_D("format_type", m.FormatType);
|
||||
}
|
||||
|
||||
std::string Sticker::GetURL() const {
|
||||
if (!AssetHash.has_value()) return "";
|
||||
if (FormatType == StickerFormatType::PNG || FormatType == StickerFormatType::APNG)
|
||||
return "https://media.discordapp.net/stickers/" + std::to_string(ID) + "/" + *AssetHash + ".png?size=256";
|
||||
else if (FormatType == StickerFormatType::LOTTIE)
|
||||
return "https://media.discordapp.net/stickers/" + std::to_string(ID) + "/" + *AssetHash + ".json";
|
||||
return "";
|
||||
}
|
28
discord/sticker.hpp
Normal file
28
discord/sticker.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include "snowflake.hpp"
|
||||
#include "json.hpp"
|
||||
|
||||
// unstable
|
||||
|
||||
enum class StickerFormatType {
|
||||
PNG = 1,
|
||||
APNG = 2,
|
||||
LOTTIE = 3,
|
||||
};
|
||||
|
||||
struct Sticker {
|
||||
Snowflake ID;
|
||||
Snowflake PackID;
|
||||
std::string Name;
|
||||
std::string Description;
|
||||
std::optional<std::string> Tags;
|
||||
std::optional<std::string> AssetHash;
|
||||
std::optional<std::string> PreviewAssetHash;
|
||||
StickerFormatType FormatType;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Sticker &m);
|
||||
|
||||
std::string GetURL() const;
|
||||
};
|
Loading…
Reference in New Issue
Block a user