Gestito notificationData nelle notifiche push
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using salesbook.Shared.Core.Dto;
|
||||
using salesbook.Shared.Core.Entity;
|
||||
using salesbook.Shared.Core.Helpers;
|
||||
using salesbook.Shared.Core.Interface.IntegryApi;
|
||||
using salesbook.Shared.Core.Messages.Notification.NewPush;
|
||||
using Shiny.Push;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace salesbook.Maui.Core.System.Notification.Push;
|
||||
|
||||
@@ -20,10 +23,25 @@ public class PushNotificationDelegate(
|
||||
public Task OnReceived(PushNotification notification)
|
||||
{
|
||||
if (notification.Notification is null) return Task.CompletedTask;
|
||||
var data = notification.Data;
|
||||
|
||||
NotificationDataDTO? notificationDataDto = null;
|
||||
|
||||
if (!data.IsNullOrEmpty())
|
||||
{
|
||||
var json = JsonSerializer.Serialize(data);
|
||||
notificationDataDto = JsonSerializer.Deserialize<NotificationDataDTO>(json);
|
||||
}
|
||||
|
||||
if (notificationDataDto?.NotificationId == null) return Task.CompletedTask;
|
||||
var notificationId = long.Parse(notificationDataDto.NotificationId);
|
||||
|
||||
var pushNotification = new WtbNotification
|
||||
{
|
||||
Id = notificationId,
|
||||
Title = notification.Notification.Title,
|
||||
Body = notification.Notification.Message
|
||||
Body = notification.Notification.Message,
|
||||
NotificationData = notificationDataDto
|
||||
};
|
||||
|
||||
messenger.Send(new NewPushNotificationMessage(pushNotification));
|
||||
|
||||
@@ -77,11 +77,11 @@
|
||||
[JSInvokable]
|
||||
public async Task Delete(string id)
|
||||
{
|
||||
Loading = true;
|
||||
_ = InvokeAsync(StateHasChanged);
|
||||
|
||||
if (!long.TryParse(id, out var notificationId)) return;
|
||||
|
||||
Loading = true;
|
||||
StateHasChanged();
|
||||
|
||||
var removed = false;
|
||||
|
||||
if (Notification.ReceivedNotifications.RemoveAll(x => x.Id == notificationId) > 0)
|
||||
@@ -91,16 +91,18 @@
|
||||
else if (Notification.NotificationsRead.RemoveAll(x => x.Id == notificationId) > 0)
|
||||
removed = true;
|
||||
|
||||
if (!removed) return;
|
||||
if (!removed)
|
||||
{
|
||||
Loading = false;
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
await IntegryNotificationRestClient.Delete(notificationId);
|
||||
|
||||
NotificationService.OrderNotificationList();
|
||||
Loading = false;
|
||||
_ = InvokeAsync(StateHasChanged);
|
||||
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
_ = IntegryNotificationRestClient.Delete(notificationId);
|
||||
});
|
||||
StateHasChanged();
|
||||
|
||||
Messenger.Send(new NotificationsLoadedMessage());
|
||||
}
|
||||
@@ -109,7 +111,7 @@
|
||||
public async Task MarkAsRead(string id)
|
||||
{
|
||||
Loading = true;
|
||||
_ = InvokeAsync(StateHasChanged);
|
||||
StateHasChanged();
|
||||
|
||||
var notificationId = long.Parse(id);
|
||||
|
||||
|
||||
@@ -47,11 +47,11 @@
|
||||
Notification.StartDate < DateTime.Today && Notification.Body != null && Notification.Body.Contains("Oggi")
|
||||
)
|
||||
{
|
||||
<MudText Typo="Typo.caption" Class="subtitle">@Notification.Body.Replace("Oggi", $"{Notification.StartDate:d}")</MudText>
|
||||
<div class="subtitle">@Notification.Body.Replace("Oggi", $"{Notification.StartDate:d}")</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.caption" Class="subtitle">@Notification.Body</MudText>
|
||||
<div class="subtitle">@Notification.Body</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -105,4 +105,6 @@
|
||||
.notification-body ::deep > .subtitle {
|
||||
font-size: 12px;
|
||||
color: var(--mud-palette-drawer-text);
|
||||
line-height: inherit;
|
||||
margin-top: .5rem;
|
||||
}
|
||||
@@ -4,6 +4,9 @@ namespace salesbook.Shared.Core.Dto;
|
||||
|
||||
public class NotificationDataDTO
|
||||
{
|
||||
[JsonPropertyName("notificationId")]
|
||||
public string? NotificationId { get; set; }
|
||||
|
||||
[JsonPropertyName("activityId")]
|
||||
public string? ActivityId { get; set; }
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace salesbook.Shared.Core.Interface.IntegryApi;
|
||||
|
||||
public interface IIntegryNotificationRestClient
|
||||
{
|
||||
Task<List<WtbNotification>> Get();
|
||||
Task<List<WtbNotification>?> Get();
|
||||
Task<WtbNotification> MarkAsRead(long id);
|
||||
Task Delete(long id);
|
||||
Task DeleteAll();
|
||||
|
||||
@@ -10,7 +10,7 @@ public class IntegryNotificationRestClient(
|
||||
IUserSession userSession,
|
||||
IIntegryApiRestClient integryApiRestClient) : IIntegryNotificationRestClient
|
||||
{
|
||||
public Task<List<WtbNotification>> Get()
|
||||
public Task<List<WtbNotification>?> Get()
|
||||
{
|
||||
var queryParams = new Dictionary<string, object>
|
||||
{
|
||||
@@ -18,7 +18,7 @@ public class IntegryNotificationRestClient(
|
||||
{ "forUser", userSession.User.Username }
|
||||
};
|
||||
|
||||
return integryApiRestClient.Get<List<WtbNotification>>("notification", queryParams)!;
|
||||
return integryApiRestClient.Get<List<WtbNotification>>("notification", queryParams);
|
||||
}
|
||||
|
||||
public Task<WtbNotification> MarkAsRead(long id) =>
|
||||
|
||||
@@ -12,6 +12,8 @@ public class NotificationService(
|
||||
public async Task LoadNotification()
|
||||
{
|
||||
var allNotifications = await integryNotificationRestClient.Get();
|
||||
if (allNotifications == null) return;
|
||||
|
||||
var allIds = allNotifications.Select(n => n.Id).ToHashSet();
|
||||
|
||||
Notification.ReceivedNotifications = Notification.ReceivedNotifications
|
||||
|
||||
@@ -145,13 +145,17 @@ function initRow(row) {
|
||||
}
|
||||
|
||||
function removeRow(row) {
|
||||
//collapseAndRemove(row);
|
||||
dotnetHelper.invokeMethodAsync('Delete', row.id);
|
||||
const id = row.id;
|
||||
|
||||
collapseAndRemove(row);
|
||||
dotnetHelper.invokeMethodAsync('Delete', id);
|
||||
}
|
||||
|
||||
function markAsRead(row) {
|
||||
//collapseAndRemove(row);
|
||||
dotnetHelper.invokeMethodAsync('MarkAsRead', row.id);
|
||||
const id = row.id;
|
||||
|
||||
collapseAndRemove(row);
|
||||
dotnetHelper.invokeMethodAsync('MarkAsRead', id);
|
||||
}
|
||||
|
||||
function collapseAndRemove(row) {
|
||||
|
||||
@@ -14,12 +14,12 @@ public class ManageDataService : IManageDataService
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<List<AnagClie>> GetClienti(WhereCondContact? whereCond)
|
||||
public Task<List<AnagClie>> GetClienti(WhereCondContact? whereCond = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<List<PtbPros>> GetProspect(WhereCondContact? whereCond)
|
||||
public Task<List<PtbPros>> GetProspect(WhereCondContact? whereCond = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -34,6 +34,11 @@ public class ManageDataService : IManageDataService
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<List<ActivityDTO>> GetActivityTryLocalDb(WhereCondActivity whereCond)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<List<ActivityDTO>> GetActivity(WhereCondActivity whereCond, bool useLocalDb = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
Reference in New Issue
Block a user