Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent sending notifications to the user who performed the action #667

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BLAZAM/BLAZAM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<ServerGarbageCollection>false</ServerGarbageCollection>
<AssemblyVersion>1.2.0</AssemblyVersion>
<Version>2024.11.25.0412</Version>
<Version>2024.11.26.2304</Version>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<RootNamespace>BLAZAM</RootNamespace>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down
36 changes: 20 additions & 16 deletions BLAZAMServices/Background/NotificationGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,31 @@ await Task.Run(async () =>

Parallel.ForEach(users, async user =>
{
var effectiveInAppSubscriptions = CalculateEffectiveInAppSubscriptions(user, source);
var effectiveEmailSubscriptions = CalculateEffectiveEmailSubscriptions(user, source);

if (effectiveInAppSubscriptions.NotificationTypes.Any(x => x.NotificationType == notificationType))
//Avoid sending to triggering user if actor is set
if (user.Id != actor?.Id)
{
await _notificationPublisher.PublishNotification(user, notification);
}
var effectiveInAppSubscriptions = CalculateEffectiveInAppSubscriptions(user, source);
var effectiveEmailSubscriptions = CalculateEffectiveEmailSubscriptions(user, source);

if (effectiveEmailSubscriptions.NotificationTypes.Any(x => x.NotificationType == notificationType))
{
if (emailMessage != null)
if (effectiveInAppSubscriptions.NotificationTypes.Any(x => x.NotificationType == notificationType))
{
if (_emailConfigured && !user.Email.IsNullOrEmpty())
{
await _emailService.SendMessage(notificationTitle, emailMessage, user.Email);
}
await _notificationPublisher.PublishNotification(user, notification);
}
else

if (effectiveEmailSubscriptions.NotificationTypes.Any(x => x.NotificationType == notificationType))
{
var error = new ApplicationException();
Loggers.SystemLogger.Error("Email message template was not found! {@Error}", error);
if (emailMessage != null)
{
if (_emailConfigured && !user.Email.IsNullOrEmpty())
{
await _emailService.SendMessage(notificationTitle, emailMessage, user.Email);
}
}
else
{
var error = new ApplicationException();
Loggers.SystemLogger.Error("Email message template was not found! {@Error}", error);
}
}
}
});
Expand Down