show non-lottie stickers statically

This commit is contained in:
ouwou
2020-11-02 17:36:10 -05:00
parent 8efa202458
commit b97722e937
7 changed files with 82 additions and 0 deletions

View File

@@ -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