Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asxelot committed Oct 30, 2015
1 parent 753c93c commit db427d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 8 additions & 6 deletions app/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ angular.module('FlameSlackApp')

.controller('MainCtrl', function($scope, $rootScope, $location,
Auth, Users, Usernames) {
$scope.lightbox = function(src) {
$scope.lightboxSrc = src
}

Auth.$onAuth(function(authData) {
if (authData) {
Expand All @@ -16,6 +13,10 @@ angular.module('FlameSlackApp')
$location.path('/login')
}
})

$scope.lightbox = function(src) {
$scope.lightboxSrc = src
}

$scope.logout = function() {
Users.setOffline($scope.user.$id)
Expand Down Expand Up @@ -110,7 +111,8 @@ angular.module('FlameSlackApp')

if (!$scope.users) $rootScope.users = Users.all
if (!$scope.channels) $rootScope.channels = Channels
if (!$scope.directNotify) $rootScope.directNotify = Direct.getNotify($scope.user.$id)
if (!$scope.directNotify)
$rootScope.directNotify = Direct.notifications($scope.user.$id)

$scope.msg = {}
$scope.directWith = {
Expand All @@ -119,7 +121,7 @@ angular.module('FlameSlackApp')
}
$scope.messages = Direct.messages($scope.user.$id, $scope.directWith.$id)

Direct.removeNotify($scope.user.$id, $scope.directWith.$id)
Direct.removeNotifications($scope.user.$id, $scope.directWith.$id)

$scope.addMessage = function() {
if (!$scope.msg.text) return
Expand All @@ -132,7 +134,7 @@ angular.module('FlameSlackApp')
}

$scope.messages.$add($scope.msg)
Direct.addNotify($scope.user.$id, $scope.directWith.$id)
Direct.notify($scope.user.$id, $scope.directWith.$id)
$scope.msg = {}
}
})
Expand Down
10 changes: 5 additions & 5 deletions app/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('FlameSlackApp')
return $firebaseAuth(new Firebase(FB))
})

.factory('Users', function($q, $firebaseArray, $firebaseObject, FB) {
.factory('Users', function($firebaseArray, $firebaseObject, FB) {
var usersRef = new Firebase(FB + 'users'),
connectedRef = new Firebase(FB + '.info/connected'),
users = $firebaseArray(usersRef)
Expand Down Expand Up @@ -61,17 +61,17 @@ angular.module('FlameSlackApp')
var path = uid1 < uid2 ? uid1 + '/' + uid2 : uid2 + '/' + uid1
return $firebaseArray(new Firebase(FB).child('direct').child(path))
},
addNotify: function(from, to) {
notify: function(from, to) {
var ref = new Firebase(FB + 'directNotification').child(to).child(from)
ref.transaction(function(val) {
return val ? val + 1 : 1
})
},
getNotify: function(uid) {
notifications: function(uid) {
return $firebaseObject(new Firebase(FB + 'directNotification').child(uid))
},
removeNotify: function(from, to) {
new Firebase(FB + 'directNotification').child(from).child(to).remove()
removeNotifications: function(to, from) {
new Firebase(FB + 'directNotification').child(to).child(from).remove()
}
}
})
Expand Down

0 comments on commit db427d4

Please sign in to comment.