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); }
protected UserAndOrganizationHubDto GetUserAndTenant() { var userHub = new UserAndOrganizationHubDto { UserId = Context.User.Identity.GetUserId(), OrganizationName = Context.User.Identity.GetOrganizationName(), OrganizationId = Context.User.Identity.GetOrganizationId() }; return(userHub); }
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); }
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); }
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); }
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); } }
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); }
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); } }
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); } }
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 _); } }
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); } } }
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); }
/// <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); }
public async Task Notify(CreateEventDto eventDto, UserAndOrganizationHubDto userAndOrganizationHubDto) { var notification = await _notificationService.CreateForEventAsync(userAndOrganizationHubDto, eventDto); await NotificationHub.SendNotificationToAllUsersAsync(_mapper.Map <NotificationViewModel>(notification), userAndOrganizationHubDto); }
public static void SendNotificationToParticularUsers(NotificationViewModel notification, UserAndOrganizationHubDto userOrg, string memberId) { SendNotificationToParticularUsers(notification, userOrg, new List <string> { memberId }); }
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); }
private void SendNotification(CommentCreatedDTO commentDto, UserAndOrganizationHubDto userHubDto, NotificationType notificationType, string commentDtoPostCreator) { SendNotification(commentDto, userHubDto, notificationType, new List <string> { commentDtoPostCreator }); }