async Task NotifyAsync(ISpamOperatorContext <Comment> context) { // Get users to notify var users = await GetUsersAsync(context.Operation); // No users to notify if (users == null) { return; } // Get bot var bot = await _platoUserStore.GetPlatoBotAsync(); // Send notifications foreach (var user in users) { // Web notification if (user.NotificationEnabled(_userNotificationTypeDefaults, WebNotifications.CommentSpam)) { await _notificationManager.SendAsync(new Notification(WebNotifications.CommentSpam) { To = user, From = bot }, context.Model); } // Email notification if (user.NotificationEnabled(_userNotificationTypeDefaults, EmailNotifications.CommentSpam)) { await _notificationManager.SendAsync(new Notification(EmailNotifications.CommentSpam) { To = user }, context.Model); } } }
public async Task <ISpamOperatorResult <Question> > ValidateModelAsync(ISpamOperatorContext <Question> context) { // Ensure correct operation provider if (!context.Operation.Name.Equals(SpamOperations.Question.Name, StringComparison.Ordinal)) { return(null); } // Get user for entity var user = await BuildUserAsync(context.Model); if (user == null) { return(null); } // Create result var result = new SpamOperatorResult <Question>(); // Check if user is already flagged as SPAM within Plato if (user.IsSpam) { return(result.Failed(context.Model, context.Operation)); } // Check StopForumSpam service var spamResult = await _spamChecker.CheckAsync(user); if (spamResult.Succeeded) { return(result.Success(context.Model)); } // Return failed with our updated model and operation // This provides the calling code with the operation error message return(result.Failed(context.Model, context.Operation)); }