hopefully take care of some annoying bugs

This commit is contained in:
ouwou 2020-09-30 15:12:52 -04:00
parent 7965b788b1
commit 872b15e6af
5 changed files with 24 additions and 24 deletions

View File

@ -46,13 +46,7 @@ ChannelListRowDMChannel::ChannelListRowDMChannel(const Channel *data) {
m_icon = Gtk::manage(new Gtk::Image(buf));
else {
m_icon = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(24)));
Abaddon::Get().GetImageManager().LoadFromURL(data->Recipients[0].GetAvatarURL("png", "16"), [this](Glib::RefPtr<Gdk::Pixbuf> ldbuf) {
Glib::signal_idle().connect([this, ldbuf]() -> bool {
m_icon->property_pixbuf() = ldbuf;
return false;
});
});
Abaddon::Get().GetImageManager().LoadFromURL(data->Recipients[0].GetAvatarURL("png", "16"), sigc::mem_fun(*this, &ChannelListRowDMChannel::OnImageLoad));
}
}
@ -70,6 +64,11 @@ ChannelListRowDMChannel::ChannelListRowDMChannel(const Channel *data) {
show_all_children();
}
void ChannelListRowDMChannel::OnImageLoad(Glib::RefPtr<Gdk::Pixbuf> buf) {
if (m_icon != nullptr)
m_icon->property_pixbuf() = buf;
}
ChannelListRowGuild::ChannelListRowGuild(const Guild *data) {
ID = data->ID;
m_ev = Gtk::manage(new Gtk::EventBox);

View File

@ -40,6 +40,8 @@ public:
ChannelListRowDMChannel(const Channel *data);
protected:
void OnImageLoad(Glib::RefPtr<Gdk::Pixbuf> buf);
Gtk::EventBox *m_ev;
Gtk::Box *m_box;
Gtk::Label *m_lbl;

View File

@ -132,6 +132,11 @@ void ChatMessageItemContainer::UpdateAttributes() {
m_attrib_label->set_markup("<span color='#999999'>[edited]</span>");
}
bool ChatMessageItemContainer::EmitImageLoad(std::string url) {
m_signal_image_load.emit(url);
return false;
}
void ChatMessageItemContainer::AddClickHandler(Gtk::Widget *widget, std::string url) {
// clang-format off
widget->signal_button_press_event().connect([url](GdkEventButton *event) -> bool {
@ -258,27 +263,24 @@ Gtk::EventBox *ChatMessageItemContainer::CreateEmbedComponent(const Message *dat
}
}
bool img = embed.Image.URL.size() > 0;
bool thumb = embed.Thumbnail.URL.size() > 0;
if (img || thumb) {
bool is_img = embed.Image.URL.size() > 0;
bool is_thumb = embed.Thumbnail.URL.size() > 0;
if (is_img || is_thumb) {
auto *img = Gtk::manage(new Gtk::Image);
img->set_halign(Gtk::ALIGN_CENTER);
int w, h;
if (img)
if (is_img)
std::tie(w, h) = GetImageDimensions(embed.Image.Width, embed.Image.Height, 200, 150);
else
std::tie(w, h) = GetImageDimensions(embed.Thumbnail.Width, embed.Thumbnail.Height, 200, 150);
img->set_size_request(w, h);
main->pack_start(*img);
m_embed_img = img;
if (img)
if (is_img)
m_embed_imgurl = embed.Image.ProxyURL;
else
m_embed_imgurl = embed.Thumbnail.ProxyURL;
Glib::signal_idle().connect([this]() -> bool {
m_signal_image_load.emit(m_embed_imgurl);
return false;
});
Glib::signal_idle().connect(sigc::bind(sigc::mem_fun(*this, &ChatMessageItemContainer::EmitImageLoad), m_embed_imgurl));
}
if (embed.Footer.Text.length() > 0) {
@ -366,10 +368,8 @@ std::pair<int, int> ChatMessageItemContainer::GetImageDimensions(int width, int
void ChatMessageItemContainer::HandleImage(const AttachmentData &data, Gtk::Image *img, std::string url) {
m_img_loadmap[url] = std::make_pair(img, data);
Glib::signal_idle().connect([this, url]() -> bool {
m_signal_image_load.emit(url); // ask the chatwindow to call UpdateImage because dealing with lifetimes sucks
return false;
});
// ask the chatwindow to call UpdateImage because dealing with lifetimes sucks
Glib::signal_idle().connect(sigc::bind(sigc::mem_fun(*this, &ChatMessageItemContainer::EmitImageLoad), url));
}
void ChatMessageItemContainer::ShowMenu(GdkEvent *event) {

View File

@ -16,6 +16,8 @@ public:
void UpdateImage();
protected:
bool EmitImageLoad(std::string url);
void AddClickHandler(Gtk::Widget *widget, std::string);
Gtk::TextView *CreateTextComponent(const Message *data); // Message.Content
Gtk::EventBox *CreateEmbedComponent(const Message *data); // Message.Embeds[0]

View File

@ -232,9 +232,8 @@ void ChatWindow::ProcessNewMessage(Snowflake id, bool prepend) {
}
void ChatWindow::SetMessagesInternal() {
m_update_mutex.lock();
std::scoped_lock<std::mutex> guard(m_update_mutex);
const auto *msgs = &m_set_messages_queue.front();
m_update_mutex.unlock();
// empty the listbox
auto children = m_list->get_children();
@ -251,9 +250,7 @@ void ChatWindow::SetMessagesInternal() {
ProcessNewMessage(id, false);
}
m_update_mutex.lock();
m_set_messages_queue.pop();
m_update_mutex.unlock();
}
void ChatWindow::AddNewMessageInternal() {