示例#1
0
        public void Notify(NewlyCreatedPostDTO createdPost, UserAndOrganizationHubDto userAndOrganizationHubDto)
        {
            _postNotificationService.NotifyAboutNewPost(createdPost);

            var membersToNotify = _userService.GetWallUserAppNotificationEnabledIds(createdPost.User.UserId, createdPost.WallId);

            var notificationDto = _notificationService.CreateForPost(userAndOrganizationHubDto, createdPost, createdPost.WallId, membersToNotify).GetAwaiter().GetResult();

            NotificationHub.SendNotificationToParticularUsers(_mapper.Map <NotificationViewModel>(notificationDto), userAndOrganizationHubDto, membersToNotify);
            NotificationHub.SendWallNotification(createdPost.WallId, membersToNotify, createdPost.WallType, userAndOrganizationHubDto);
        }
示例#2
0
        protected UserAndOrganizationHubDto GetUserAndTenant()
        {
            var userHub = new UserAndOrganizationHubDto
            {
                UserId           = Context.User.Identity.GetUserId(),
                OrganizationName = Context.User.Identity.GetOrganizationName(),
                OrganizationId   = Context.User.Identity.GetOrganizationId()
            };

            return(userHub);
        }
示例#3
0
        private async Task SendNotificationAsync(CommentCreatedDto commentDto, UserAndOrganizationHubDto userHubDto, NotificationType notificationType, IList <string> watchers)
        {
            var notificationAuthorDto = await _notificationService.CreateForCommentAsync(userHubDto, commentDto, notificationType, watchers);

            if (notificationAuthorDto == null)
            {
                return;
            }

            var notification = _mapper.Map <NotificationViewModel>(notificationAuthorDto);
            await NotificationHub.SendNotificationToParticularUsersAsync(notification, userHubDto, watchers);
        }
示例#4
0
        public async Task NotifyAsync(NewlyCreatedPostDto createdPost, UserAndOrganizationHubDto userAndOrganizationHubDto)
        {
            await _postNotificationService.NotifyAboutNewPostAsync(createdPost);

            var membersToNotify = (await _userService.GetWallUserAppNotificationEnabledIdsAsync(createdPost.User.UserId, createdPost.WallId)).ToList();

            var notificationDto = await _notificationService.CreateForPostAsync(userAndOrganizationHubDto, createdPost, createdPost.WallId, membersToNotify);

            var notificationViewModel = _mapper.Map <NotificationViewModel>(notificationDto);
            await NotificationHub.SendNotificationToParticularUsersAsync(notificationViewModel, userAndOrganizationHubDto, membersToNotify);

            await NotificationHub.SendWallNotificationAsync(createdPost.WallId, membersToNotify, createdPost.WallType, userAndOrganizationHubDto);
        }
示例#5
0
        private void SendNotification(CommentCreatedDTO commentDto, UserAndOrganizationHubDto userHubDto, NotificationType notificationType, IList <string> watchers)
        {
            var notificationAuthorDto = _notificationService.CreateForComment(userHubDto, commentDto, notificationType, watchers).GetAwaiter().GetResult();

            if (notificationAuthorDto == null)
            {
                return;
            }

            var notification = _mapper.Map <NotificationViewModel>(notificationAuthorDto);

            NotificationHub.SendNotificationToParticularUsers(notification, userHubDto, watchers);
        }
示例#6
0
        private void MapUserWithConnection(UserAndOrganizationHubDto userOrg)
        {
            var user = NotificationHubUsers.GetOrAdd(userOrg, _ => new HubUser
            {
                Id               = userOrg.UserId,
                OrganizationId   = userOrg.OrganizationId,
                OrganizationName = userOrg.OrganizationName,
                ConnectionIds    = new HashSet <string>()
            });

            lock (user.ConnectionIds)
            {
                user.ConnectionIds.Add(Context.ConnectionId);
            }
        }
示例#7
0
        public static void SendNotificationToParticularUsers(
            NotificationViewModel notification,
            UserAndOrganizationHubDto userOrg,
            IEnumerable <string> membersIds)
        {
            var notificationHub = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>();

            var connectionIds = NotificationHubUsers
                                .Where(u => membersIds.Contains(u.Key.UserId) &&
                                       u.Key.OrganizationId == userOrg.OrganizationId &&
                                       u.Key.OrganizationName == userOrg.OrganizationName)
                                .SelectMany(u => u.Value.ConnectionIds)
                                .ToList();

            notificationHub.Clients.Clients(connectionIds).newNotification(notification);
        }
示例#8
0
        public void Notify(CommentCreatedDTO commentDto, UserAndOrganizationHubDto userHubDto)
        {
            _commentEmailNotificationService.SendEmailNotification(commentDto);

            var membersToNotify = _wallService.GetWallMembersIds(commentDto.WallId, userHubDto);

            NotificationHub.SendWallNotification(commentDto.WallId, membersToNotify, commentDto.WallType, userHubDto);

            var postWatchers = _postService.GetPostWatchersForAppNotifications(commentDto.PostId).ToList();

            // Comment author doesn't need to receive notification about his own comment
            postWatchers.Remove(commentDto.CommentCreator);

            // Send notification to other users
            if (postWatchers.Count > 0)
            {
                SendNotification(commentDto, userHubDto, NotificationType.FollowingComment, postWatchers);
            }
        }
示例#9
0
        public async Task NotifyAsync(CommentCreatedDto commentDto, UserAndOrganizationHubDto userHubDto)
        {
            await _commentEmailNotificationService.SendEmailNotificationAsync(commentDto);

            var membersToNotify = await _wallService.GetWallMembersIdsAsync(commentDto.WallId, userHubDto);

            await NotificationHub.SendWallNotificationAsync(commentDto.WallId, membersToNotify, commentDto.WallType, userHubDto);

            var postWatchers = await _postService.GetPostWatchersForAppNotificationsAsync(commentDto.PostId);

            // Comment author doesn't need to receive notification about his own comment
            postWatchers.Remove(commentDto.CommentCreator);

            // Send notification to other users
            if (postWatchers.Count > 0)
            {
                await SendNotificationAsync(commentDto, userHubDto, NotificationType.FollowingComment, postWatchers);
            }
        }
示例#10
0
        private void RemoveUserConnections(UserAndOrganizationHubDto userOrg)
        {
            NotificationHubUsers.TryGetValue(userOrg, out var user);

            if (user == null)
            {
                return;
            }

            lock (user.ConnectionIds)
            {
                user.ConnectionIds.RemoveWhere(cid => cid.Equals(Context.ConnectionId));

                if (user.ConnectionIds.Any())
                {
                    return;
                }

                NotificationHubUsers.TryRemove(userOrg, out _);
            }
        }
示例#11
0
        public void Notify(CommentCreatedDTO commentDto, UserAndOrganizationHubDto userHubDto)
        {
            _commentNotificationService.NotifyAboutNewComment(commentDto);

            var membersToNotify = _wallService.GetWallMembersIds(commentDto.WallId, userHubDto);

            NotificationHub.SendWallNotification(commentDto.WallId, membersToNotify, commentDto.WallType, userHubDto);

            var commentsAuthorsToNotify = _commentService.GetCommentsAuthorsToNotify(
                commentDto.PostId,
                new List <string>()
            {
                commentDto.CommentCreator
            });

            if (commentDto.PostCreator != commentDto.CommentCreator && _commentService.IsPostAuthorAppNotificationsEnabled(commentDto.PostCreator))
            {
                var notificationAuthorDto = _notificationService.CreateForComment(userHubDto, commentDto, NotificationType.WallComment, new List <string> {
                    commentDto.PostCreator
                }).GetAwaiter().GetResult();
                if (notificationAuthorDto != null)
                {
                    NotificationHub.SendNotificationToParticularUsers(_mapper.Map <NotificationViewModel>(notificationAuthorDto), userHubDto, new List <string>()
                    {
                        commentDto.PostCreator
                    });
                }

                commentsAuthorsToNotify.Remove(commentDto.PostCreator);
            }

            if (commentsAuthorsToNotify.Count > 0)
            {
                var notificationDto = _notificationService.CreateForComment(userHubDto, commentDto, NotificationType.FollowingComment, commentsAuthorsToNotify).GetAwaiter().GetResult();
                if (notificationDto != null)
                {
                    NotificationHub.SendNotificationToParticularUsers(_mapper.Map <NotificationViewModel>(notificationDto), userHubDto, commentsAuthorsToNotify);
                }
            }
        }
示例#12
0
        public static void SendNotificationToAllUsers(NotificationViewModel notification, UserAndOrganizationHubDto userOrg)
        {
            var notificationHub = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>();

            var connectionIds = NotificationHubUsers
                                .Where(x => x.Key.UserId != userOrg.UserId &&
                                       x.Key.OrganizationId == userOrg.OrganizationId &&
                                       x.Key.OrganizationName == userOrg.OrganizationName)
                                .SelectMany(u => u.Value.ConnectionIds)
                                .ToList();

            notificationHub.Clients.Clients(connectionIds).newNotification(notification);
        }
示例#13
0
        /// <summary>
        /// Triggers New Content Available toolbox
        /// </summary>
        /// <param name="wallId"></param>
        /// <param name="membersIds"></param>
        /// <param name="wallType"></param>
        /// <param name="userOrg"></param>
        public static void SendWallNotification(int wallId, IEnumerable <string> membersIds, WallType wallType, UserAndOrganizationHubDto userOrg)
        {
            var notificationHub = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>();

            var connectionIds = NotificationHubUsers
                                .Where(u => membersIds.Contains(u.Key.UserId) &&
                                       u.Key.OrganizationName == userOrg.OrganizationName &&
                                       u.Key.OrganizationId == userOrg.OrganizationId)
                                .SelectMany(u => u.Value.ConnectionIds)
                                .ToList();

            notificationHub.Clients.Clients(connectionIds).newContent(wallId, wallType);
        }
示例#14
0
        public async Task Notify(CreateEventDto eventDto, UserAndOrganizationHubDto userAndOrganizationHubDto)
        {
            var notification = await _notificationService.CreateForEventAsync(userAndOrganizationHubDto, eventDto);

            await NotificationHub.SendNotificationToAllUsersAsync(_mapper.Map <NotificationViewModel>(notification), userAndOrganizationHubDto);
        }
示例#15
0
 public static void SendNotificationToParticularUsers(NotificationViewModel notification, UserAndOrganizationHubDto userOrg, string memberId)
 {
     SendNotificationToParticularUsers(notification, userOrg, new List <string> {
         memberId
     });
 }
示例#16
0
        public async Task NotifyAsync(NewPostDto postModel, NewlyCreatedPostDto createdPost, UserAndOrganizationHubDto userHubDto)
        {
            await _postNotificationService.NotifyAboutNewPostAsync(createdPost);

            var membersToNotify = await _wallService.GetWallMembersIdsAsync(postModel.WallId, postModel);

            await NotificationHub.SendWallNotificationAsync(postModel.WallId, membersToNotify, createdPost.WallType, userHubDto);
        }
示例#17
0
 private void SendNotification(CommentCreatedDTO commentDto, UserAndOrganizationHubDto userHubDto, NotificationType notificationType, string commentDtoPostCreator)
 {
     SendNotification(commentDto, userHubDto, notificationType, new List <string> {
         commentDtoPostCreator
     });
 }