Notifications = require 'app/collections/notifications'

module.allow =
  users: ['all']

date = new ReactiveVar()
setDate = ->
  date.set moment().subtract(1, 'minute').toDate()

setInterval ->
  do setDate
  # Fiber ->
  #   find = {}
  #   find.createdAt = $gte: date.get()
  #   # console.log date.get()
  #   # console.log Notifications.findOne().createdAt
  #   # console.log moment().subtract(1, 'hour').toDate()
  #   console.log Notifications.find(find).fetch()
  # .run()
, 1000


pub = Meteor.publish module, 'notifications', ->
  @autorun ->
    find = {}
    find.createdAt = $gte: date.get()
    Notifications.find find

# setInterval =>
#   Fiber =>
#     Notifications.insert
#       for: "all"
#       href: "#client/00001276"
#       message: "Это я"
#       time: 11000
#       # audio: 'fanfar3.mp3'
#   .run()
#   console.log 'go'
# , 15000
