Skip to content

Commit

Permalink
Dynamically update unread count in notifications controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ianngiaw committed Nov 14, 2015
1 parent 349272d commit 2b04678
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions www/js/controllers/notificationsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ angular.module('letterbox.controllers')
if ($scope.chats[i].id === message.RoomHash) {
$scope.chats[i].last_message = (message.sender === window.localStorage.getItem('hashedId') ? 'You: ' : $scope.chats[i].from + ': ') + message.content;
$scope.chats[i].last_activity = new Date(message.timeSent);
if (message.sender !== window.localStorage.getItem('hashedId')) {
$scope.chats[i].unread_count++;
}
break;
}
}
Expand All @@ -82,6 +85,16 @@ angular.module('letterbox.controllers')

eventbus.registerListener('letterReceived', refreshNotifications);

eventbus.registerListener('roomRead', function(roomRead) {
for (var i = 0; i < $scope.chats.length; i++) {
var chat = $scope.chats[i];
if (chat.id === roomRead.roomHash) {
chat.unread_count = 0;
break;
}
}
});

$scope.$on("$ionicView.enter", function(scopes, states) {
refreshNotifications();
RoomsService.updateRooms();
Expand Down

0 comments on commit 2b04678

Please sign in to comment.