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(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); } }
public async Task SendEmailNotificationAsync(CommentCreatedDto commentDto) { var commentCreator = await _userService.GetApplicationUserAsync(commentDto.CommentCreator); var organization = await _organizationService.GetOrganizationByIdAsync(commentCreator.OrganizationId); var mentionedUsers = (await GetMentionedUsersAsync(commentDto.MentionedUsersIds)).ToList(); var destinationEmails = (await GetPostWatchersEmailsAsync(commentCreator.Email, commentDto.PostId, commentCreator.Id)) .Except(mentionedUsers.Select(x => x.Email)) .ToList(); if (destinationEmails.Count > 0) { await SendPostWatcherEmailsAsync(commentDto, destinationEmails, commentCreator, organization); } if (mentionedUsers.Count > 0) { await SendMentionEmailsAsync(commentDto, mentionedUsers, commentCreator, organization); } }
private async Task SendMentionEmailsAsync(CommentCreatedDto commentDto, IList <ApplicationUser> mentionedUsers, ApplicationUser commentCreator, Organization organization) { var comment = await _commentService.GetCommentBodyAsync(commentDto.CommentId); var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName); var postUrl = _appSettings.WallPostUrl(organization.ShortName, commentDto.PostId); const string subject = "You have been mentioned in the post"; var messageBody = _markdownConverter.ConvertToHtml(comment); foreach (var mentionedUser in mentionedUsers) { try { if (mentionedUser.NotificationsSettings?.MentionEmailNotifications == false) { continue; } var newMentionTemplateViewModel = new NewMentionTemplateViewModel( mentionedUser.FullName, commentCreator.FullName, postUrl, userNotificationSettingsUrl, messageBody); var content = _mailTemplate.Generate(newMentionTemplateViewModel, EmailTemplateCacheKeys.NewMention); var emailData = new EmailDto(mentionedUser.Email, subject, content); await _mailingService.SendEmailAsync(emailData); } catch (Exception e) { _logger.Debug(e.Message, e); } } }
private async Task SendPostWatcherEmailsAsync(CommentCreatedDto commentDto, IList <string> emails, ApplicationUser commentCreator, Organization organization) { var comment = await LoadCommentAsync(commentDto.CommentId); var postLink = await GetPostLinkAsync(commentDto.WallType, commentDto.WallId, organization.ShortName, commentDto.PostId); var authorPictureUrl = _appSettings.PictureUrl(organization.ShortName, commentCreator.PictureId); var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName); var subject = string.Format(Templates.NewPostCommentEmailSubject, CutMessage(comment.Post.MessageBody), commentCreator.FullName); var body = _markdownConverter.ConvertToHtml(comment.MessageBody); var emailTemplateViewModel = new NewCommentEmailTemplateViewModel(string.Format(EmailTemplates.PostCommentTitle, CutMessage(comment.Post.MessageBody)), authorPictureUrl, commentCreator.FullName, postLink, body, userNotificationSettingsUrl, EmailTemplates.DefaultActionButtonTitle); var content = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.NewPostComment); var emailData = new EmailDto(emails, subject, content); await _mailingService.SendEmailAsync(emailData); }
public async Task <NotificationDto> CreateForCommentAsync(UserAndOrganizationDto userOrg, CommentCreatedDto comment, NotificationType type, IEnumerable <string> membersToNotify) { var sources = new Sources { PostId = comment.PostId }; var wallName = await _wallDbSet .Where(x => x.Id == comment.WallId && x.OrganizationId == userOrg.OrganizationId) .Select(s => s.Name) .SingleAsync(); var commentCreator = await _userDbSet .Where(x => x.Id == comment.CommentCreator) .Select(c => new { c.FirstName, c.LastName, c.PictureId }) .SingleAsync(); var commentCreatorApplicationUser = new ApplicationUser { FirstName = commentCreator.FirstName, LastName = commentCreator.LastName, PictureId = commentCreator.PictureId }; var newNotification = Notification.Create(commentCreatorApplicationUser.FullName, wallName, commentCreatorApplicationUser.PictureId, sources, type, userOrg.OrganizationId, membersToNotify); _notificationDbSet.Add(newNotification); await _uow.SaveChangesAsync(); return(_mapper.Map <NotificationDto>(newNotification)); }