Skip to content

Commit

Permalink
fix(Announcements): ListView changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr committed Aug 31, 2023
1 parent aebc82b commit 940fab1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
17 changes: 17 additions & 0 deletions src/API/Announcement.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}
}
22 changes: 2 additions & 20 deletions src/Widgets/Announcement.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 ();
}
}

0 comments on commit 940fab1

Please sign in to comment.