Add private live notifications

master
Jesús Espino 2017-03-31 12:12:53 +02:00 committed by Álex Hermida
parent 1d38a0270a
commit b033906e2b
2 changed files with 10 additions and 1 deletions

View File

@ -32,7 +32,11 @@ class Client
else if msg.cmd == 'auth' and msg.data
@.authUser(msg.data)
else if msg.cmd == 'subscribe' and msg.routing_key
@.addSubscription(msg.routing_key)
if msg.routing_key.indexOf("live_notifications") == 0
userId = signing.getUserId(@.auth.token)
@.addSubscription("live_notifications.#{userId}")
else
@.addSubscription(msg.routing_key)
else if msg.cmd == 'unsubscribe' and msg.routing_key
@.removeSubscription(msg.routing_key)

View File

@ -12,6 +12,11 @@ rsplit = (token, sep, maxsplit) ->
return split
exports.getUserId = (token) ->
value = token.split(':')[0]
value = JSON.parse(base64url.decode(value))
return value.user_authentication_id
exports.verify = (token) ->
[value, sig] = rsplit(token, ':', 1)