   users = messageSubscribers msg, options
   _.sortBy users, userSortKey
 
-@notificationTime = (notification, user = notification.to) ->
-  ## Currently notification timing doesn't depend on the notification
-  ## itself, only on the user that it's addressed to.
+@notificationTime = (base, user) ->
+  ## base = dateMin(notification.dates...)
   user = findUsername user
   delays = user.profile?.notifications?.after ?
            defaultNotificationDelays.after
-  moment(dateMin(notification.dates...)).add(delays.after, delays.unit).toDate()
+  try
+    moment(base).add(delays.after, delays.unit).toDate()
+  catch e
+    ## Handle buggy specification of user.profile.notifications.after
+    delays = defaultNotificationDelays.after
+    moment(base).add(delays.after, delays.unit).toDate()
   ## Old settle dynamics:
   #settleTime = moment(dateMax(notification.dates...)).add(delays.settle, delays.unit).toDate()
   #maximumTime = moment(dateMin(notification.dates...)).add(delays.maximum, delays.unit).toDate()

    ## we also don't need to do anything, because at the end of running the
    ## notifier will check for any new notifications to schedule.
    if username of notifiers
      if notifiers[username].running or notifiers[username].time.getTime() <= time.getTime()
        return
      else
        Meteor.clearTimeout notifiers[username].timeout
    now = new Date()
    #console.log notification, '@', time.getTime() - now.getTime()
    notifiers[username] =
      time: time
      timeout:
        Meteor.setTimeout ->
          notificationDo username
        , Math.max(minSchedule, time.getTime() - now.getTime())

      text: text
      headers: autoHeaders

  Meteor.startup ->
    ## Reschedule any leftover notifications from last server run.
    Notifications.find
      seen: false
    .forEach (notification) ->
      try
        #console.log 'Scheduling leftover notification', notification
        notificationSchedule notification
      catch e
        console.warn 'Could not schedule', notification, ':', e

    ## Watch for change in notification frequency, and reschedule timeouts.
    Meteor.users.find {},
      fields:
        'username': true
        'profile.notifications.after': true  ## for @notificationTime
    .observe
      changed: (user) ->
        notificationReschedule user
