public async Task ProcessMentionsInPost(Guid postId) { var post = await _mediator.Send(new GetPostById(postId)); if (post == null || !int.TryParse(post.AuthorId, out int authorId)) { return; } var mentions = MentionsHelper.FindMentions(post.Body); var users = await GetMentionedUsers(mentions, post.MentionedUsers, authorId); if (users == null || !users.Any()) { return; } var user = await _mediator.Send(new GetUserInfoById(authorId)); var notification = new PostCommentMentionNotification(post.Title, user.DisplayName, post.Slug, users.Select(x => new Tuple <string, string>(x.Email, x.DisplayName))); await _mediator.Publish(notification); //update mentioned users var updateMentionedQuery = new Domain.Posts.Commands.UpdateMentionedUsers(post.Id, mentions); await _mediator.Send(updateMentionedQuery); }
public async Task ProcessMentionsInPostComment(Guid commentId) { var query = new GetCommentById(commentId); var comment = await _mediator.Send(query); if (comment == null) { return; } var mentions = MentionsHelper.FindMentions(comment.Body); var users = await GetMentionedUsers(mentions, comment.MentionedUsers, comment.AuthorId); if (users == null || !users.Any()) { return; } //we are getting the post here to be sure the slug not changed var postQuery = new GetPostById(comment.PostId); var post = await _mediator.Send(postQuery); var user = await _mediator.Send(new GetUserInfoById(comment.AuthorId)); var notification = new PostCommentMentionNotification(post.Title, user.DisplayName, post.Slug, users.Select(x => new Tuple <string, string>(x.Email, x.DisplayName))); await _mediator.Publish(notification); //update mentioned users var updateMentionedQuery = new Domain.PostComments.Commands.UpdateMentionedUsers(comment.Id, mentions); await _mediator.Send(updateMentionedQuery); }