Migliorata gestione e visualizzazione notifiche

This commit is contained in:
2025-09-12 15:42:56 +02:00
parent b798b01da0
commit 223e74c490
20 changed files with 229 additions and 60 deletions

View File

@@ -15,6 +15,7 @@ public interface IManageDataService
Task<List<ContactDTO>> GetContact(WhereCondContact whereCond);
Task<ContactDTO?> GetSpecificContact(string codAnag, bool IsContact);
Task<List<ActivityDTO>> GetActivityTryLocalDb(WhereCondActivity whereCond);
Task<List<ActivityDTO>> GetActivity(WhereCondActivity whereCond, bool useLocalDb = false);
Task InsertOrUpdate<T>(T objectToSave);

View File

@@ -0,0 +1,7 @@
namespace salesbook.Shared.Core.Interface;
public interface INotificationService
{
Task LoadNotification();
void OrderNotificationList();
}

View File

@@ -0,0 +1,5 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
namespace salesbook.Shared.Core.Messages.Notification.Loaded;
public class NotificationsLoadedMessage(object? value = null) : ValueChangedMessage<object?>(value);

View File

@@ -0,0 +1,13 @@
using CommunityToolkit.Mvvm.Messaging;
namespace salesbook.Shared.Core.Messages.Notification.Loaded;
public class NotificationsLoadedService
{
public event Action? OnNotificationsLoaded;
public NotificationsLoadedService(IMessenger messenger)
{
messenger.Register<NotificationsLoadedMessage>(this, (_, _) => { OnNotificationsLoaded?.Invoke(); });
}
}

View File

@@ -1,6 +1,6 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
using salesbook.Shared.Core.Entity;
namespace salesbook.Shared.Core.Messages.Notification;
namespace salesbook.Shared.Core.Messages.Notification.NewPush;
public class NewPushNotificationMessage(WtbNotification value) : ValueChangedMessage<WtbNotification>(value);

View File

@@ -1,7 +1,7 @@
using CommunityToolkit.Mvvm.Messaging;
using salesbook.Shared.Core.Entity;
namespace salesbook.Shared.Core.Messages.Notification;
namespace salesbook.Shared.Core.Messages.Notification.NewPush;
public class NewPushNotificationService
{

View File

@@ -0,0 +1,45 @@
using salesbook.Shared.Core.Dto.PageState;
using salesbook.Shared.Core.Interface;
using salesbook.Shared.Core.Interface.IntegryApi;
namespace salesbook.Shared.Core.Services;
public class NotificationService(
IIntegryNotificationRestClient integryNotificationRestClient,
NotificationState Notification
) : INotificationService
{
public async Task LoadNotification()
{
var allNotifications = await integryNotificationRestClient.Get();
var allIds = allNotifications.Select(n => n.Id).ToHashSet();
Notification.ReceivedNotifications = Notification.ReceivedNotifications
.Where(r => !allIds.Contains(r.Id))
.ToList();
Notification.UnreadNotifications = allNotifications
.Where(x =>
x.WtbDeviceNotifications == null ||
x.WtbDeviceNotifications.Any(y => y.ReadDate == null))
.ToList();
Notification.NotificationsRead = allNotifications
.Where(x =>
x.WtbDeviceNotifications != null &&
x.WtbDeviceNotifications.All(y => y.ReadDate != null))
.ToList();
}
public void OrderNotificationList()
{
Notification.ReceivedNotifications = Notification.ReceivedNotifications
.OrderByDescending(x => x.StartDate).ToList();
Notification.UnreadNotifications = Notification.UnreadNotifications
.OrderByDescending(x => x.StartDate).ToList();
Notification.NotificationsRead = Notification.NotificationsRead
.OrderByDescending(x => x.StartDate).ToList();
}
}