Fix notification fallback, fix fdo markup escaping

This commit is contained in:
fiaxh 2020-12-01 21:53:56 +01:00
parent 552591640f
commit cd7c4c8221
2 changed files with 34 additions and 28 deletions

View file

@ -29,7 +29,7 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
startup.connect(() => { startup.connect(() => {
stream_interactor.get_module(NotificationEvents.IDENTITY).register_notification_provider(new GNotificationsNotifier(stream_interactor)); stream_interactor.get_module(NotificationEvents.IDENTITY).register_notification_provider(new GNotificationsNotifier(stream_interactor));
FreeDesktopNotifier free_desktop_notifier = FreeDesktopNotifier.try_create(stream_interactor); FreeDesktopNotifier? free_desktop_notifier = FreeDesktopNotifier.try_create(stream_interactor);
if (free_desktop_notifier != null) { if (free_desktop_notifier != null) {
stream_interactor.get_module(NotificationEvents.IDENTITY).register_notification_provider(free_desktop_notifier); stream_interactor.get_module(NotificationEvents.IDENTITY).register_notification_provider(free_desktop_notifier);
} }

View file

@ -15,11 +15,14 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
private HashMap<Conversation, Gee.List<uint32>> conversation_notifications = new HashMap<Conversation, Gee.List<uint32>>(Conversation.hash_func, Conversation.equals_func); private HashMap<Conversation, Gee.List<uint32>> conversation_notifications = new HashMap<Conversation, Gee.List<uint32>>(Conversation.hash_func, Conversation.equals_func);
private HashMap<uint32, HashMap<string, ListenerFuncWrapper>> action_listeners = new HashMap<uint32, HashMap<string, ListenerFuncWrapper>>(); private HashMap<uint32, HashMap<string, ListenerFuncWrapper>> action_listeners = new HashMap<uint32, HashMap<string, ListenerFuncWrapper>>();
private FreeDesktopNotifier(StreamInteractor stream_interactor, DBusNotifications dbus_notifications) { private FreeDesktopNotifier(StreamInteractor stream_interactor) {
this.stream_interactor = stream_interactor; this.stream_interactor = stream_interactor;
}
private void set_dbus_notifications(DBusNotifications dbus_notifications) throws Error {
this.dbus_notifications = dbus_notifications; this.dbus_notifications = dbus_notifications;
try {
string[] caps; string[] caps;
dbus_notifications.get_capabilities(out caps); dbus_notifications.get_capabilities(out caps);
foreach (string cap in caps) { foreach (string cap in caps) {
@ -39,19 +42,21 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
dbus_notifications.notification_closed.connect((id) => { dbus_notifications.notification_closed.connect((id) => {
action_listeners.unset(id); action_listeners.unset(id);
}); });
} catch (Error e) {
warning("Failed accessing fdo notification server: %s", e.message);
}
} }
public static FreeDesktopNotifier? try_create(StreamInteractor stream_interactor) { public static FreeDesktopNotifier? try_create(StreamInteractor stream_interactor) {
DBusNotifications? dbus_notifications = get_notifications_dbus(); DBusNotifications? dbus_notifications = get_notifications_dbus();
if (dbus_notifications == null) return null; if (dbus_notifications == null) return null;
FreeDesktopNotifier notifier = new FreeDesktopNotifier(stream_interactor, dbus_notifications); try {
notifier.dbus_notifications = dbus_notifications; FreeDesktopNotifier notifier = new FreeDesktopNotifier(stream_interactor);
notifier.set_dbus_notifications(dbus_notifications);
return notifier; return notifier;
} catch (Error e) {
debug("Failed accessing fdo notification server: %s", e.message);
}
return null;
} }
public double get_priority() { public double get_priority() {
@ -59,7 +64,8 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
} }
public async void notify_message(Message message, Conversation conversation, string conversation_display_name, string? participant_display_name) { public async void notify_message(Message message, Conversation conversation, string conversation_display_name, string? participant_display_name) {
yield notify_content_item(conversation, conversation_display_name, participant_display_name, message.body); string body = supports_body_markup ? Markup.escape_text(message.body) : message.body;
yield notify_content_item(conversation, conversation_display_name, participant_display_name, body);
} }
public async void notify_file(FileTransfer file_transfer, Conversation conversation, bool is_image, string conversation_display_name, string? participant_display_name) { public async void notify_file(FileTransfer file_transfer, Conversation conversation, bool is_image, string conversation_display_name, string? participant_display_name) {
@ -81,7 +87,7 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
string body = body_; string body = body_;
if (participant_display_name != null) { if (participant_display_name != null) {
if (supports_body_markup) { if (supports_body_markup) {
body = @"<b>$(Markup.escape_text(participant_display_name)):</b> $(Markup.escape_text(body))"; body = @"<b>$(Markup.escape_text(participant_display_name)):</b> $body";
} else { } else {
body = @"$participant_display_name: $body"; body = @"$participant_display_name: $body";
} }