calendar: Create SourceSection class

Reorder sources list according to received messages
parent 08ed59bf
......@@ -1009,42 +1009,50 @@ class NotificationTimeLabel extends St.Label {
var NotificationSection = GObject.registerClass(
class NotificationSection extends MessageList.MessageListSection {
_init() {
super._init();
this._sources = new Map();
this._nUrgent = 0;
super._init({
style_class: 'message-list-section',
vertical: true,
x_expand: true,
y_expand: true,
y_align: Clutter.ActorAlign.START,
});
Main.messageTray.connect('source-added', this._sourceAdded.bind(this));
Main.messageTray.getSources().forEach(source => {
this._sourceAdded(Main.messageTray, source);
});
this._sources = Main.messageTray.getSources();
this._sources.forEach(source => this._sourceAdded(null, source));
}
get allowed() {
return Main.sessionMode.hasNotifications &&
!Main.sessionMode.isGreeter;
_sourceAdded(tray, source) {
const group = new SourceSection(source);
this.addMessageAtIndex(group, 0, true);
group.connect('group-updated', this.moveMessage.bind(this));
}
});
_sourceAdded(tray, source) {
let obj = {
destroyId: 0,
notificationAddedId: 0,
};
var SourceSection = GObject.registerClass({
Signals: {
'group-updated': {},
'close': {},
},
}, class SourceSection extends MessageList.MessageListSection {
_init(source) {
super._init();
obj.destroyId = source.connect('destroy', () => {
this._onSourceDestroy(source, obj);
});
obj.notificationAddedId = source.connect('notification-added',
this._onNotificationAdded.bind(this));
this._source = source;
this._nUrgent = 0;
this._sources.set(source, obj);
this._sourceDestroyId = this._source.connect('destroy', () => {
this._onSourceDestroy();
});
this._notificationAddedId = this._source.connect('notification-added',
this._onNotificationAdded.bind(this));
}
_onNotificationAdded(source, notification) {
let message = new NotificationMessage(notification);
message.setSecondaryActor(new TimeLabel(notification.datetime));
let isUrgent = notification.urgency == MessageTray.Urgency.CRITICAL;
let isUrgent = notification.urgency === MessageTray.Urgency.CRITICAL;
let updatedId = notification.connect('updated', () => {
message.setSecondaryActor(new TimeLabel(notification.datetime));
......@@ -1069,22 +1077,31 @@ class NotificationSection extends MessageList.MessageListSection {
let index = isUrgent ? 0 : this._nUrgent;
this.addMessageAtIndex(message, index, this.mapped);
}
_onSourceDestroy(source, obj) {
source.disconnect(obj.destroyId);
source.disconnect(obj.notificationAddedId);
this.emit('group-updated');
}
this._sources.delete(source);
_onSourceDestroy() {
this._source.disconnect(this._sourceDestroyId);
this._source.disconnect(this._notificationAddedId);
this.emit('close');
}
vfunc_map() {
this._messages.forEach(message => {
if (message.notification.urgency != MessageTray.Urgency.CRITICAL)
if (message.notification.urgency !== MessageTray.Urgency.CRITICAL)
message.notification.acknowledged = true;
});
super.vfunc_map();
}
canClose() {
return true;
}
close() {
this.clear();
}
});
var Placeholder = GObject.registerClass(
......@@ -1189,7 +1206,7 @@ class CalendarMessageList extends St.Widget {
vertical: true,
x_expand: true,
y_expand: true,
y_align: Clutter.ActorAlign.START });
y_align: Clutter.ActorAlign.START });
this._sectionList.connect('actor-added', this._sync.bind(this));
this._sectionList.connect('actor-removed', this._sync.bind(this));
this._scrollView.add_actor(this._sectionList);
......@@ -1214,11 +1231,6 @@ class CalendarMessageList extends St.Widget {
Util.ensureActorVisibleInScrollView(this._scrollView, messageActor);
}));
connectionsIds.push(section.connect('destroy', () => {
connectionsIds.forEach(id => section.disconnect(id));
this._sectionList.remove_actor(section);
}));
this._sectionList.add_actor(section);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment