From 940fab16e41d664f94237a47d2a8317eb39ab974 Mon Sep 17 00:00:00 2001 From: Evangelos Paterakis Date: Thu, 31 Aug 2023 06:45:57 +0300 Subject: [PATCH] fix(Announcements): ListView changes --- src/API/Announcement.vala | 17 +++++++++++++++++ src/Widgets/Announcement.vala | 22 ++-------------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/API/Announcement.vala b/src/API/Announcement.vala index a60e7f9d6..ff8e5b589 100644 --- a/src/API/Announcement.vala +++ b/src/API/Announcement.vala @@ -29,4 +29,21 @@ public class Tuba.API.Announcement : Entity, Widgetizable { public override Gtk.Widget to_widget () { return new Widgets.Announcement (this); } + + public override void open () { + if (this.read) return; + + new Request.POST (@"/api/v1/announcements/$(this.id)/dismiss") + .with_account (accounts.active) + .then (() => { + this.read = true; + }) + .on_error ((code, message) => { + warning (@"Error while dismissing announcement: $code $message"); + + var dlg = app.inform (_("Error"), message); + dlg.present (); + }) + .exec (); + } } diff --git a/src/Widgets/Announcement.vala b/src/Widgets/Announcement.vala index a5e57146a..ec3a16c06 100644 --- a/src/Widgets/Announcement.vala +++ b/src/Widgets/Announcement.vala @@ -125,8 +125,6 @@ public class Tuba.Widgets.Announcement : Gtk.ListBoxRow { settings.notify["larger-font-size"].connect (settings_updated); settings.notify["larger-line-height"].connect (settings_updated); settings.notify["scale-emoji-hover"].connect (settings_updated); - - open.connect (on_open); } public Announcement (API.Announcement t_announcement) { @@ -156,6 +154,8 @@ public class Tuba.Widgets.Announcement : Gtk.ListBoxRow { if (instance_thumbnail != "") image_cache.request_paintable (instance_thumbnail, on_cache_response); reactions = t_announcement.reactions; + + announcement.bind_property ("read", attention_indicator, "visible", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.INVERT_BOOLEAN); } void on_cache_response (bool is_loaded, owned Gdk.Paintable? data) { @@ -183,22 +183,4 @@ public class Tuba.Widgets.Announcement : Gtk.ListBoxRow { }) .exec (); } - - private void on_open () { - if (announcement.read) return; - - new Request.POST (@"/api/v1/announcements/$(announcement.id)/dismiss") - .with_account (accounts.active) - .then (() => { - announcement.read = true; - attention_indicator.visible = false; - }) - .on_error ((code, message) => { - warning (@"Error while dismissing announcement: $code $message"); - - var dlg = app.inform (_("Error"), message); - dlg.present (); - }) - .exec (); - } }