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

Disable units notifications #37

Merged
merged 2 commits into from
Dec 14, 2023
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 Dodo1000Bot.Api/Dodo1000Bot.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.22.0</Version>
<Version>1.23.0</Version>
<UserSecretsId>f449de95-800a-40ef-8716-6e80b7f0977d</UserSecretsId>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Dodo1000Bot.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"KeyPrefix": ""
},
"PushNotifications": {
"EveryTime": "0:05:00"
"EveryTime": "0:01:00"
},
"UnitsJob": {
"RefreshEveryTime": "0:55:00"
Expand Down
3 changes: 3 additions & 0 deletions Dodo1000Bot.Services/NotificationsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Dodo1000Bot.Models;
using Dodo1000Bot.Models.Domain;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -42,6 +43,8 @@ public async Task PushNotifications(CancellationToken cancellationToken)
return;
}

notifications = notifications.Where(n => n.Type != NotificationType.NewUnit).ToList();

IEnumerable<Task<IEnumerable<PushedNotification>>> tasks = _notifyServices.Select(s => s.NotifyAbout(notifications, cancellationToken));

IEnumerable<PushedNotification>[] tasksResults = await Task.WhenAll(tasks);
Expand Down
14 changes: 10 additions & 4 deletions Dodo1000Bot.Services/Repositories/NotificationsRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Data;
using System.Linq;
Expand Down Expand Up @@ -43,10 +44,15 @@ LEFT JOIN pushed_notifications pn
ON n.Id = pn.notificationId
WHERE pn.id IS NULL", cancellationToken: cancellationToken));

var notifications = records.Select(r => new Notification(r.Type is NotificationType ? (NotificationType)r.Type : NotificationType.Custom)

var notifications = records.Select(r =>
{
Id = r.Id,
Payload = JsonSerializer.Deserialize<NotificationPayload>(r.Payload)
var type = Enum.Parse<NotificationType>(r.Type.ToString());
return new Notification(type)
{
Id = r.Id,
Payload = JsonSerializer.Deserialize<NotificationPayload>(r.Payload)
};
}).ToImmutableArray();

return notifications;
Expand Down