1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 19:42:01 +02:00

Keep forwards list up to date on client side.

This commit is contained in:
Simo Kinnunen 2014-04-15 18:02:48 +09:00
parent b0400130ff
commit fb3892ab07
2 changed files with 21 additions and 1 deletions

View file

@ -505,6 +505,7 @@ module.exports = function(options) {
}
dbapi.addUserForward(user.email, data)
.then(function() {
socket.emit('forward.create', data)
joinChannel(responseChannel)
push.send([
channel
@ -518,6 +519,7 @@ module.exports = function(options) {
.on('forward.remove', function(channel, responseChannel, data) {
dbapi.removeUserForward(user.email, data.devicePort)
.then(function() {
socket.emit('forward.remove', data)
joinChannel(responseChannel)
push.send([
channel

View file

@ -1,4 +1,4 @@
module.exports = function UserServiceFactory($http) {
module.exports = function UserServiceFactory($http, $rootScope, socket) {
var userService = {}
userService.user = (function () {
@ -8,5 +8,23 @@ module.exports = function UserServiceFactory($http) {
}
})()
socket.on('forward.create', function(data) {
userService.user().then(function(user) {
$rootScope.$apply(function() {
user.forwards.push(data)
})
})
})
socket.on('forward.remove', function(data) {
userService.user().then(function(user) {
$rootScope.$apply(function() {
user.forwards = user.forwards.filter(function(forward) {
return forward.devicePort !== data.devicePort
})
})
})
})
return userService
}