messageTray: Add optional datetime parameter to notifications

Since the last notification redesign, we've been showing the time a
notification was received in the calendar drop-down. However as the
time is in fact added by the NotificationSection, it is actually the
time a notification was added to the list. Usually that difference is
not significant, except when previously received notifications are
restored on startup.
In order to be able to address those cases, we need a time that is
associated with the notification itself, so add a datetime property
that defaults to the current time, but may be set from an optional
parameter as well.

https://bugzilla.gnome.org/show_bug.cgi?id=775799
This commit is contained in:
Florian Müllner 2017-02-27 00:14:09 +01:00
parent 0353ebde5d
commit 0569bb18f5
2 changed files with 10 additions and 4 deletions

View File

@ -946,8 +946,8 @@ const NotificationSection = new Lang.Class({
!Main.sessionMode.isGreeter;
},
_createTimeLabel: function() {
let label = Util.createTimeLabel(new Date());
_createTimeLabel: function(datetime) {
let label = Util.createTimeLabel(datetime);
label.style_class = 'event-time',
label.x_align = Clutter.ActorAlign.END;
return label;
@ -970,13 +970,13 @@ const NotificationSection = new Lang.Class({
_onNotificationAdded: function(source, notification) {
let message = new NotificationMessage(notification);
message.setSecondaryActor(this._createTimeLabel());
message.setSecondaryActor(this._createTimeLabel(notification.datetime));
let isUrgent = notification.urgency == MessageTray.Urgency.CRITICAL;
let updatedId = notification.connect('updated', Lang.bind(this,
function() {
message.setSecondaryActor(this._createTimeLabel());
message.setSecondaryActor(this._createTimeLabel(notification.datetime));
this.moveMessage(message, isUrgent ? 0 : this._nUrgent, this.actor.mapped);
}));
let destroyId = notification.connect('destroy', Lang.bind(this,

View File

@ -368,6 +368,7 @@ const Notification = new Lang.Class({
secondaryGIcon: null,
bannerMarkup: false,
clear: false,
datetime: null,
soundName: null,
soundFile: null });
@ -375,6 +376,11 @@ const Notification = new Lang.Class({
this.bannerBodyText = banner;
this.bannerBodyMarkup = params.bannerMarkup;
if (params.datetime)
this.datetime = params.datetime;
else
this.datetime = GLib.DateTime.new_now_local();
if (params.gicon || params.clear)
this.gicon = params.gicon;