title: Filter notifications within policy
body: <p>Whenever a model is created (or deleted/modified) every connected socket is notified through Sails autowatch setting. That's fine to some extent, but I'd like to filter these notifications at some point.</p>
  
  <p>My application has its own "Notifications" which should be sent to their respective receiver. So their anatomy is somewhat like: <code>id, message, receiver, sender</code>.</p>
  
  <p>Authentication is a local passport implementation.</p>
  
  <p>Listening for <code>notification</code> events result in getting notified every time a notification is created.</p>
  
  <pre><code>// client: app.js
  io.socket.on('notification', function(evt) { console.log(evt); });
  </code></pre>
  
  <p>What I try to achieve now is to filter these notifications to match the user id. I've written a policy which gets applied to the <code>/notification</code> events.</p>
  
  <pre><code>// Policy: forUser
  module.exports = function(req, res, next) {
    // ... whatever ... //
  
    return next();
  }
  </code></pre>
  
  <p>Within the policies</p>
  
  <pre><code>  'notification': {
      'create': ['passport', 'forUser']
    }
  </code></pre>
  
  <p>My problem now is: how to implement this policy? I thought of just checking for <code>notification.receiver == req.user.id</code>, but how to get the notification model within the policy (if this is the right way at all)?</p>
  
  <p>Thanks.</p>
  
  <p><strong>Edit</strong>: Tried implementing the room solution, but I don't get any notifications on the client.</p>
  
  <p>I've altered my subscribe function within my NotificationController:</p>
  
  <pre><code>subscribe: function(req, res) {
          sails.log.info('Your user id: ' + req.user.id);
          sails.sockets.join(req.socket, 'user_notifications_' + req.user.id);
          res.json({
              room: 'user_notifications_' + req.user.id
          });
      },
  </code></pre>
  
  <p>And added a <code>afterCreate</code> method to my model:</p>
  
  <pre><code>afterCreate: function(model, next) {
      sails.sockets.broadcast('user_notifications_' + model.receiver, { test: 'hello' });
      next();
    }
  </code></pre>
  
  <p>Code on client is now:</p>
  
  <pre><code>  io.socket.get("/notification/subscribe", function(data, jwr) {
      io.socket.on(data.room, function(obj) {
        console.log(obj);
      });
    });
  </code></pre>
  
  <p>The subscription method is called and returns the right room name. But I don't get any messages when calling <code>/notification/create?message=test&amp;receiver=1</code>. The <code>afterCreate</code> method is called, all user ids are right (since there's only one user), but nothing happens.</p>
  
  <p>Edit2:
  It seems like joining the rooms fails.</p>
  
  <pre><code>sails.sockets.join(req.socket, 'testroom');
  // For testing
  sails.log.debug(sails.sockets.socketRooms(req.socket));
  </code></pre>
  
  <p>The room gets created, but the socket is not subscribed to it.</p>
  
  <p>Edit3:
  <strong>Found the solution. I'll post the GitHub link as soon as the interface is done.</strong></p>