(function () { "use strict"; var streamApp = angular.module('streamApp'); streamApp.directive('viewersDirective', ['groupsService', 'userService', 'timeService', ViewersDirective]); function ViewersDirective(groupsService, userService, timeService) { return { restrict: 'E', scope: { tags: '=' }, templateUrl: '/App/Directives/viewersDirective/viewersDirective.html?v=6.0.0c', link: function (scope, element, attrs, tabsCtrl) { scope.$watch('tags.length', function () { updateViewers(); }); scope.message = ['To share a memory with a person, you need share that memory with a Group.', 'You can add connections to a Group at anytime and they will be able to see all the memories' + ' you have shared with a Group.']; scope.now = new Date(); userService.getUser().then(function (user) { scope.user = user; scope.user.canShareDate = timeService.getDateFromString(scope.user.canShareDate); }); function updateViewers() { // debounce this - only current request gets processed const now = scope.now = new Date(); if (scope.tags && scope.tags.length) { groupsService.getViewers(scope.tags.map(x => x.tagId)).then(function (data) { if (now === scope.now) { scope.viewers = data; } }); } else { scope.viewers = []; } } } }; } }());