Skip to content

Commit

Permalink
Merge pull request #37 from granstel/disable-units-notifications
Browse files Browse the repository at this point in the history
Disable units notifications
  • Loading branch information
granstel authored Dec 14, 2023
2 parents a7605bd + 8ec38c4 commit 458c3e2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
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

0 comments on commit 458c3e2

Please sign in to comment.