mondora / asteroid

An alternative client for a Meteor backend
MIT License
734 stars 101 forks source link

Query not working on data change for boolean? #38

Closed willoughby closed 9 years ago

willoughby commented 9 years ago

I have a query like notifications.reactiveQuery({"read":false}), which returns records fine, when a record read attr changes to true (via a meteor.call 'clearNotification'), the query doesn't seem to catch the change. my current workaround is to rerun the query in the updated promise from my meteor.call method

I can tweak the read attr in the db and it works as you expect. not sure if its something i'm missing ?

var unreadNotificationQuery = notifications.reactiveQuery({"read":false});
  unreadNotificationQuery.on('change',function (change) {   
    console.log("change")
    $scope.notifications =  unreadNotificationQuery.result
    $scope.$apply()
  }) 

$scope.clearNotification = function(notification) {
    call = meteor.call('clearNotification',notification._id);    
    call.updated.then(function(){
      var q = notifications.reactiveQuery({"read":false});      
      $scope.notifications =  q.result 
      $scope.$apply() 
    })
  }
pscanf commented 9 years ago

Mmh, that is strange indeed. I see no reason why the code shouldn't work without the re-run of the query.

I can tweak the read attr in the db and it works as you expect

Again, strange. :-) Maybe the call to the clearNotificationmethod is not working. Try passing console.log.bind(console) as third argument to the Asteroid constructor and see if the server is actually sending you the change notification.

willoughby commented 9 years ago

It looks like the data change isn't being picked up

Object {type: "socket_message_sent", message: "{"msg":"method","id":"33","method":"clearNotification","params":["QXrYGN6giczesiKvY"]}", timestamp: 1418647754694}
ddp.js:302 Object {type: "socket_message_received", message: "{"msg":"result","id":"33","result":1}", timestamp: 1418647754779}
ddp.js:302 Object {type: "socket_message_received", message: "{"msg":"changed","collection":"Notifications","id"…","fields":{"updatedAt":{"$date":1418647746944}}}", timestamp: 1418647754783}

The server method being called is:

'clearNotifications': ()->
    Notifications.update({"userId":Meteor.userId(),"read":false},{ $set: { read: true }},{multi:true})
pscanf commented 9 years ago

Mmh, that is strange, but it seems to be a server problem. I'm wondering, are you publishing the read property of Notifications?

pscanf commented 9 years ago

Was it solved? Closing for cleanup, reopen if necessary.