Пример #1
0
        public async Task NotifyNewCommentAsync(CommentDetailedItem model, Func<string, string> funcCommentContentFormat)
        {
            if (!IsEnabled)
            {
                _logger.LogWarning($"Skipped {nameof(NotifyNewCommentAsync)} because Email sending is disabled.");
                return;
            }

            try
            {
                var req = new NewCommentPayload(
                    model.Username,
                    model.Email,
                    model.IpAddress,
                    model.PostTitle,
                    funcCommentContentFormat(model.CommentContent),
                    model.CreateOnUtc
                );

                await SendNotificationRequest(
                    new NotificationRequest<NewCommentPayload>(MailMesageTypes.NewCommentNotification, req));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
            }
        }
Пример #2
0
        public async Task<CommentDetailedItem> CreateAsync(NewCommentRequest request)
        {
            if (_blogConfig.ContentSettings.EnableWordFilter)
            {
                var dw = _blogConfig.ContentSettings.DisharmonyWords;
                var maskWordFilter = new MaskWordFilter(new StringWordSource(dw));
                request.Username = maskWordFilter.FilterContent(request.Username);
                request.Content = maskWordFilter.FilterContent(request.Content);
            }

            var model = new CommentEntity
            {
                Id = Guid.NewGuid(),
                Username = request.Username,
                CommentContent = request.Content,
                PostId = request.PostId,
                CreateOnUtc = DateTime.UtcNow,
                Email = request.Email,
                IPAddress = request.IpAddress,
                IsApproved = !_blogConfig.ContentSettings.RequireCommentReview
            };

            await _commentRepository.AddAsync(model);

            var spec = new PostSpec(request.PostId, false);
            var postTitle = _postRepository.SelectFirstOrDefault(spec, p => p.Title);

            var item = new CommentDetailedItem
            {
                Id = model.Id,
                CommentContent = model.CommentContent,
                CreateOnUtc = model.CreateOnUtc,
                Email = model.Email,
                IpAddress = model.IPAddress,
                IsApproved = model.IsApproved,
                PostTitle = postTitle,
                Username = model.Username
            };

            return item;
        }