     console.log 'Scheduling notification', note
 
   @notificationInsert = (notification) ->
-    notification.when = new Date unless notification.when?
     notification.seen = false
     Notifications.insert notification
     xxx notificationTime notification
 
 @notificationTime = (notification) ->
-  notification.when
-  user = findUsername notification.username
-  delays = user.profile?.notifications?[notification.level]
+  user = findUsername notification.target
+  delays = user.profile?.notifications?[notification.level] ?
+           defaultNotificationDelays[notification.level]
   


@defaultNotificationDelays =
  batched:
    batch:
      amount: 4
      unit: 'hour'
  settled:
    settle:
      amount: 30
      unit: 'minute'
    maximum:
      amount: 60
      unit: 'minute'
  instant:
    settle:
      amount: 0
      unit: 'second'
    maximum:
      amount: 0
      unit: 'second'

## notification can consist of
##   - level: one of notificationLevels
##   - message: ID of relevant message
##   - updates: list of changed, title, body, ... from message

if Meteor.isServer
  Meteor.publish 'notifications', () ->

          seen: false
      else
        @ready()
  Meteor.publish 'notifications.all', () ->
    @autorun ->
      user = findUser @userId
      if user?
