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: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3429>
This commit is contained in:
Julian Sparber 2024-07-29 17:18:22 +02:00
parent 64aadeece3
commit 6fa76cd8f4

View File

@ -967,20 +967,18 @@ class NotificationSection extends MessageListSection {
} }
_sourceAdded(tray, source) { _sourceAdded(tray, source) {
source.connectObject('notification-added', source.connectObject(
this._onNotificationAdded.bind(this), this); 'notification-added', this._onNotificationAdded.bind(this),
'notification-removed', this._onNotificationRemoved.bind(this),
this);
} }
_onNotificationAdded(source, notification) { _onNotificationAdded(source, notification) {
let message = new NotificationMessage(notification); let message = new NotificationMessage(notification);
let isUrgent = notification.urgency === MessageTray.Urgency.CRITICAL; const isUrgent = notification.urgency === MessageTray.Urgency.CRITICAL;
notification.connectObject( notification.connectObject(
'destroy', () => {
if (isUrgent)
this._nUrgent--;
},
'notify::datetime', () => { 'notify::datetime', () => {
// The datetime property changes whenever the notification is updated // The datetime property changes whenever the notification is updated
this.moveMessage(message, isUrgent ? 0 : this._nUrgent, this.mapped); this.moveMessage(message, isUrgent ? 0 : this._nUrgent, this.mapped);
@ -996,10 +994,15 @@ class NotificationSection extends MessageListSection {
notification.acknowledged = true; notification.acknowledged = true;
} }
let index = isUrgent ? 0 : this._nUrgent; const index = isUrgent ? 0 : this._nUrgent;
this.addMessageAtIndex(message, index, this.mapped); this.addMessageAtIndex(message, index, this.mapped);
} }
_onNotificationRemoved(source_, notification) {
if (notification.urgency === MessageTray.Urgency.CRITICAL)
this._nUrgent--;
}
vfunc_map() { vfunc_map() {
this._messages.forEach(message => { this._messages.forEach(message => {
if (message.notification.urgency !== MessageTray.Urgency.CRITICAL) if (message.notification.urgency !== MessageTray.Urgency.CRITICAL)