Merge pull request #27 from taigaio/live-notifications

Add private live notifications
master
Alex Hermida 2018-04-24 13:40:37 +02:00 committed by GitHub
commit 2efba0baf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)