Gestita pagina notifiche

This commit is contained in:
2025-09-11 16:06:19 +02:00
parent 7319378e75
commit 7bfe67a97c
30 changed files with 611 additions and 105 deletions

View File

@@ -6,11 +6,11 @@ using salesbook.Shared.Core.Interface.IntegryApi;
namespace salesbook.Maui.Core.RestClient.IntegryApi;
public class IntegryNotificationRestClient(
ILogger<IntegryNotificationRestClient> logger,
public class IntegryRegisterNotificationRestClient(
ILogger<IntegryRegisterNotificationRestClient> logger,
IUserSession userSession,
IIntegryApiRestClient integryApiRestClient
) : IIntegryNotificationRestClient
) : IIntegryRegisterNotificationRestClient
{
public async Task Register(string fcmToken, ILogger? logger1 = null)
{

View File

@@ -1,14 +1,15 @@
using AutoMapper;
using MudBlazor.Extensions;
using salesbook.Shared.Core.Dto;
using salesbook.Shared.Core.Dto.Activity;
using salesbook.Shared.Core.Dto.Contact;
using salesbook.Shared.Core.Entity;
using salesbook.Shared.Core.Helpers.Enum;
using salesbook.Shared.Core.Interface;
using Sentry.Protocol;
using System.Linq.Expressions;
using salesbook.Shared.Core.Interface.IntegryApi;
using salesbook.Shared.Core.Interface.System.Network;
using Sentry.Protocol;
using System.Linq.Expressions;
namespace salesbook.Maui.Core.Services;
@@ -211,6 +212,15 @@ public class ManageDataService(
{
var dto = mapper.Map<ActivityDTO>(activity);
if (activity is { AlarmTime: not null, EstimatedTime: not null })
{
var minuteBefore = activity.EstimatedTime.Value - activity.AlarmTime.Value;
dto.MinuteBefore = (int)Math.Abs(minuteBefore.TotalMinutes);
dto.NotificationDate = dto.MinuteBefore == 0 ?
activity.EstimatedTime : activity.AlarmTime;
}
if (activity.CodJcom != null)
{
dto.Category = ActivityCategoryEnum.Commessa;

View File

@@ -8,7 +8,7 @@ namespace salesbook.Maui.Core.System.Notification;
public class FirebaseNotificationService(
IPushManager pushManager,
IIntegryNotificationRestClient integryNotificationRestClient,
IIntegryRegisterNotificationRestClient integryRegisterNotificationRestClient,
INotificationManager notificationManager
) : IFirebaseNotificationService
{
@@ -19,7 +19,7 @@ public class FirebaseNotificationService(
var (accessState, token) = await pushManager.RequestAccess();
if (accessState == AccessState.Denied || token is null) return;
await integryNotificationRestClient.Register(token);
await integryRegisterNotificationRestClient.Register(token);
}
private void CreateNotificationChannel()

View File

@@ -1,5 +1,5 @@
using CommunityToolkit.Mvvm.Messaging;
using salesbook.Shared.Core.Dto.Notification;
using salesbook.Shared.Core.Entity;
using salesbook.Shared.Core.Interface.IntegryApi;
using salesbook.Shared.Core.Messages.Notification;
using Shiny.Push;
@@ -7,7 +7,7 @@ using Shiny.Push;
namespace salesbook.Maui.Core.System.Notification.Push;
public class PushNotificationDelegate(
IIntegryNotificationRestClient integryNotificationRestClient,
IIntegryRegisterNotificationRestClient integryRegisterNotificationRestClient,
IMessenger messenger
) : IPushDelegate
{
@@ -20,10 +20,10 @@ public class PushNotificationDelegate(
public Task OnReceived(PushNotification notification)
{
if (notification.Notification is null) return Task.CompletedTask;
var pushNotification = new PushNotificationDTO
var pushNotification = new WtbNotification
{
Title = notification.Notification.Title,
Message = notification.Notification.Message
Body = notification.Notification.Message
};
messenger.Send(new NewPushNotificationMessage(pushNotification));
@@ -33,7 +33,7 @@ public class PushNotificationDelegate(
public Task OnNewToken(string token)
{
integryNotificationRestClient.Register(token);
integryRegisterNotificationRestClient.Register(token);
return Task.CompletedTask;
}

View File

@@ -86,6 +86,7 @@ namespace salesbook.Maui
//Notification
builder.Services.AddNotifications();
builder.Services.AddPush<PushNotificationDelegate>();
builder.Services.AddSingleton<IIntegryRegisterNotificationRestClient, IntegryRegisterNotificationRestClient>();
builder.Services.AddSingleton<IIntegryNotificationRestClient, IntegryNotificationRestClient>();
builder.Services.AddSingleton<IFirebaseNotificationService, FirebaseNotificationService>();
builder.Services.AddSingleton<IShinyNotificationManager, ShinyNotificationManager>();

View File

@@ -133,7 +133,7 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="12.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="IntegryApiClient.MAUI" Version="1.1.6" />
<PackageReference Include="IntegryApiClient.MAUI" Version="1.2.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.6" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.81" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.81" />