Tooth/src/Views/Notifications.vala

59 lines
1.8 KiB
Vala
Raw Normal View History

2018-04-17 12:01:55 +00:00
using Gtk;
using Gdk;
2022-11-13 20:57:43 +00:00
public class Tooth.Views.Notifications : Views.Timeline, AccountHolder, Streamable {
2021-07-23 11:41:03 +00:00
protected InstanceAccount? last_account = null;
public Notifications () {
Object (
url: "/api/v1/notifications",
label: _("Notifications"),
icon: "tooth-bell-symbolic",
2022-11-18 01:59:31 +00:00
badge_number: 0,
needs_attention: false
2021-07-23 11:41:03 +00:00
);
accepts = typeof (API.Notification);
}
public override void on_account_changed (InstanceAccount? acc) {
base.on_account_changed (acc);
if (last_account != null) {
last_account.notification_inhibitors.remove (this);
acc.stream_event[InstanceAccount.EVENT_NOTIFICATION].disconnect (on_new_post);
2022-11-18 01:59:31 +00:00
// acc.stream_event[InstanceAccount.EVENT_NOTIFICATION].disconnect (on_new_post_badge);
2020-05-29 12:19:35 +00:00
}
2020-05-30 10:31:02 +00:00
2021-07-23 11:41:03 +00:00
last_account = acc;
acc.stream_event[InstanceAccount.EVENT_NOTIFICATION].connect (on_new_post);
2022-11-18 01:59:31 +00:00
// acc.stream_event[InstanceAccount.EVENT_NOTIFICATION].connect (on_new_post_badge);
acc.bind_property ("unread_count", this, "badge_number", BindingFlags.SYNC_CREATE);
acc.bind_property ("has_unread", this, "needs_attention", BindingFlags.SYNC_CREATE);
// acc.check_notifications ();
// acc.init_notifications();
2021-07-23 11:41:03 +00:00
}
2019-03-11 14:14:37 +00:00
2022-11-18 01:59:31 +00:00
// public virtual void on_new_post_badge (Streamable.Event ev) {
// needs_attention = true;
// }
2021-07-23 11:41:03 +00:00
public override void on_shown () {
base.on_shown ();
if (account != null) {
if (!account.notification_inhibitors.contains (this))
account.notification_inhibitors.add (this);
2020-05-31 10:28:35 +00:00
account.read_notifications (account.last_received_id > account.last_read_id ? account.last_received_id : account.last_read_id);
2021-07-23 11:41:03 +00:00
}
}
public override void on_hidden () {
base.on_hidden ();
if (account != null) {
if (account.notification_inhibitors.contains (this))
account.notification_inhibitors.remove (this);
}
}
2018-04-17 12:01:55 +00:00
}