From 5ff34cf9bc502ce1635d9ee4e3d0b58520415b2b Mon Sep 17 00:00:00 2001 From: Evan Paterakis Date: Thu, 9 Oct 2025 18:07:52 +0300 Subject: [PATCH] feat(notifications): dont handle unknown types --- src/API/GroupedNotificationsResults.vala | 20 ++++++++++++++- src/API/Notification.vala | 29 +++++++++++++++++++--- src/Services/Accounts/InstanceAccount.vala | 3 ++- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/API/GroupedNotificationsResults.vala b/src/API/GroupedNotificationsResults.vala index cb24e3ed9..4a8e09002 100644 --- a/src/API/GroupedNotificationsResults.vala +++ b/src/API/GroupedNotificationsResults.vala @@ -28,8 +28,26 @@ public class Tuba.API.GroupedNotificationsResults : Entity { case InstanceAccount.KIND_FOLLOW: case InstanceAccount.KIND_ADMIN_SIGNUP: return create_basic_card (); - default: + case InstanceAccount.KIND_MENTION: + case InstanceAccount.KIND_REBLOG: + case InstanceAccount.KIND_FAVOURITE: + case InstanceAccount.KIND_POLL: + case InstanceAccount.KIND_FOLLOW_REQUEST: + case InstanceAccount.KIND_REMOTE_REBLOG: + case InstanceAccount.KIND_EDITED: + case InstanceAccount.KIND_REPLY: + case InstanceAccount.KIND_SEVERED_RELATIONSHIPS: + case InstanceAccount.KIND_ADMIN_REPORT: + case InstanceAccount.KIND_STATUS: + case InstanceAccount.KIND_PLEROMA_REACTION: + case InstanceAccount.KIND_REACTION: + case InstanceAccount.KIND_ANNUAL_REPORT: + case InstanceAccount.KIND_MODERATION_WARNING: + case InstanceAccount.KIND_QUOTE: + case InstanceAccount.KIND_QUOTE_UPDATE: return new Widgets.GroupedNotification (this); + default: + return base.to_widget (); } } diff --git a/src/API/Notification.vala b/src/API/Notification.vala index 2cd0a72f2..5cf6bac22 100644 --- a/src/API/Notification.vala +++ b/src/API/Notification.vala @@ -138,12 +138,30 @@ public class Tuba.API.Notification : Entity, Widgetizable { _("Review your year's highlights and memorable moments on the Fediverse!") ) ); - default: + case InstanceAccount.KIND_MENTION: + case InstanceAccount.KIND_REBLOG: + case InstanceAccount.KIND_FAVOURITE: + case InstanceAccount.KIND_POLL: + case InstanceAccount.KIND_REMOTE_REBLOG: + case InstanceAccount.KIND_EDITED: + case InstanceAccount.KIND_REPLY: + case InstanceAccount.KIND_STATUS: + case InstanceAccount.KIND_PLEROMA_REACTION: + case InstanceAccount.KIND_REACTION: + case InstanceAccount.KIND_QUOTE: + case InstanceAccount.KIND_QUOTE_UPDATE: return new Widgets.Notification (this); + default: + return create_basic_card ( + "tuba-background-app-ghost-symbolic", + // translators: the variable is a string notification type + _("Unknown notification: %s").printf (kind), + false + ); } } - private Gtk.Widget create_basic_card (string icon_name, string label) { + private Gtk.Widget create_basic_card (string icon_name, string label, bool can_open = true) { var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 16) { margin_top = 8, margin_bottom = 8, @@ -165,12 +183,13 @@ public class Tuba.API.Notification : Entity, Widgetizable { var row = new Widgets.ListBoxRowWrapper () { child = box, + activatable = can_open }; - row.open.connect (open); + if (can_open) row.open.connect (open); return row; } - public virtual async GLib.Notification to_toast (InstanceAccount issuer, int others = 0) { + public virtual async GLib.Notification? to_toast (InstanceAccount issuer, int others = 0) { Tuba.InstanceAccount.Kind res_kind; bool should_show_buttons = issuer == accounts.active; @@ -188,6 +207,8 @@ public class Tuba.API.Notification : Entity, Widgetizable { } issuer.describe_kind (kind, out res_kind, kind_actor_name, null, other_data); + if (res_kind.description == null) return null; + var toast = new GLib.Notification (res_kind.description); if (status != null) { var body = ""; diff --git a/src/Services/Accounts/InstanceAccount.vala b/src/Services/Accounts/InstanceAccount.vala index 40794983a..4da19b7be 100644 --- a/src/Services/Accounts/InstanceAccount.vala +++ b/src/Services/Accounts/InstanceAccount.vala @@ -945,7 +945,8 @@ public class Tuba.InstanceAccount : API.Account, Streamable { sent_notifications.set (id, others); obj.to_toast.begin (this, others, (_obj, res) => { - app.send_notification (id, obj.to_toast.end (res)); + GLib.Notification? notification = obj.to_toast.end (res); + if (notification != null) app.send_notification (id, notification); }); }