From 9b13bf552a7bbe37a34e1d0dfb437a652e1a4b0a Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Sat, 5 Oct 2024 17:48:48 +0200 Subject: [PATCH] messageList: Drop all subclasses of MessageListSection For message/notification grouping by source we need more control over each single message therefore in a future commit the MessageListSection will contain all messages directly instead of having a separate section for different source (notifications and media). The lost NotificationSection and MediaSection will be readded in a future commit as well. Part-of: --- js/ui/calendar.js | 7 ---- js/ui/messageList.js | 96 -------------------------------------------- 2 files changed, 103 deletions(-) diff --git a/js/ui/calendar.js b/js/ui/calendar.js index 855343165..7744c86e8 100644 --- a/js/ui/calendar.js +++ b/js/ui/calendar.js @@ -5,7 +5,6 @@ import GObject from 'gi://GObject'; import Shell from 'gi://Shell'; import St from 'gi://St'; -import * as MessageList from './messageList.js'; import * as PopupMenu from './popupMenu.js'; import {ensureActorVisibleInScrollView} from '../misc/animationUtils.js'; @@ -874,12 +873,6 @@ class CalendarMessageList extends St.Widget { 'child-removed', this._sync.bind(this), this); this._scrollView.child = this._sectionList; - - this._mediaSection = new MessageList.MediaSection(); - this._addSection(this._mediaSection); - - this._notificationSection = new MessageList.NotificationSection(); - this._addSection(this._notificationSection); } _addSection(section) { diff --git a/js/ui/messageList.js b/js/ui/messageList.js index c62b4c1f4..6ae1f12ee 100644 --- a/js/ui/messageList.js +++ b/js/ui/messageList.js @@ -10,7 +10,6 @@ import St from 'gi://St'; import * as Main from './main.js'; import * as MessageTray from './messageTray.js'; -import * as Mpris from './mpris.js'; import * as Util from '../misc/util.js'; import {formatTimeSpan} from '../misc/dateUtils.js'; @@ -999,98 +998,3 @@ export const MessageListSection = GObject.registerClass({ this.visible = !this.empty; } }); - -export const NotificationSection = GObject.registerClass( -class NotificationSection extends MessageListSection { - _init() { - super._init(); - - this._nUrgent = 0; - - Main.messageTray.connect('source-added', this._sourceAdded.bind(this)); - Main.messageTray.getSources().forEach(source => { - this._sourceAdded(Main.messageTray, source); - }); - } - - _sourceAdded(tray, source) { - source.connectObject( - 'notification-added', this._onNotificationAdded.bind(this), - 'notification-removed', this._onNotificationRemoved.bind(this), - this); - } - - _onNotificationAdded(source, notification) { - let message = new NotificationMessage(notification); - - const isUrgent = notification.urgency === MessageTray.Urgency.CRITICAL; - - notification.connectObject( - 'notify::datetime', () => { - // The datetime property changes whenever the notification is updated - this.moveMessage(message, isUrgent ? 0 : this._nUrgent, this.mapped); - }, this); - - if (isUrgent) { - // Keep track of urgent notifications to keep them on top - this._nUrgent++; - } else if (this.mapped) { - // Only acknowledge non-urgent notifications in case it - // has important actions that are inaccessible when not - // shown as banner - notification.acknowledged = true; - } - - 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) - message.notification.acknowledged = true; - }); - super.vfunc_map(); - } -}); - -export const MediaSection = GObject.registerClass( -class MediaSection extends MessageListSection { - constructor() { - super(); - this._players = new Map(); - this._mediaSource = new Mpris.MprisSource(); - - this._mediaSource.connectObject( - 'player-added', (_, player) => this._addPlayer(player), - 'player-removed', (_, player) => this._removePlayer(player), - this); - - this._mediaSource.players.forEach(player => { - this._addPlayer(player); - }); - } - - _addPlayer(player) { - if (this._players.has(player)) - throw new Error('Player was already added previously'); - - const message = new MediaMessage(player); - this._players.set(player, message); - this.addMessage(message, true); - } - - _removePlayer(player) { - const message = this._players.get(player); - - if (message) - this.removeMessage(message, true); - - this._players.delete(player); - } -});