From 6fa76cd8f47d5f83436d14950a0e737603f25fcc Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Mon, 29 Jul 2024 17:18:22 +0200 Subject: [PATCH] messageList: Use `notification-removed` signal in `MessageListSection` Since we have now the `notification-removed` signal on `MessageTray.Source` we can use it instead of connecting to the `destroy()` signal for each single notification in the `MessageListSection`. Part-of: --- js/ui/messageList.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/js/ui/messageList.js b/js/ui/messageList.js index ac3ab542f..71f42a090 100644 --- a/js/ui/messageList.js +++ b/js/ui/messageList.js @@ -967,20 +967,18 @@ class NotificationSection extends MessageListSection { } _sourceAdded(tray, source) { - source.connectObject('notification-added', - this._onNotificationAdded.bind(this), this); + source.connectObject( + 'notification-added', this._onNotificationAdded.bind(this), + 'notification-removed', this._onNotificationRemoved.bind(this), + this); } _onNotificationAdded(source, notification) { let message = new NotificationMessage(notification); - let isUrgent = notification.urgency === MessageTray.Urgency.CRITICAL; + const isUrgent = notification.urgency === MessageTray.Urgency.CRITICAL; notification.connectObject( - 'destroy', () => { - if (isUrgent) - this._nUrgent--; - }, 'notify::datetime', () => { // The datetime property changes whenever the notification is updated this.moveMessage(message, isUrgent ? 0 : this._nUrgent, this.mapped); @@ -996,10 +994,15 @@ class NotificationSection extends MessageListSection { notification.acknowledged = true; } - let index = isUrgent ? 0 : this._nUrgent; + const index = isUrgent ? 0 : this._nUrgent; this.addMessageAtIndex(message, index, this.mapped); } + _onNotificationRemoved(source_, notification) { + if (notification.urgency === MessageTray.Urgency.CRITICAL) + this._nUrgent--; + } + vfunc_map() { this._messages.forEach(message => { if (message.notification.urgency !== MessageTray.Urgency.CRITICAL)