Iniziata implementazione notifiche firebase

This commit is contained in:
2025-08-25 10:00:41 +02:00
parent 9957229e70
commit 833a1e456f
16 changed files with 244 additions and 2 deletions

View File

@@ -0,0 +1,10 @@
using System.Text.Json.Serialization;
namespace salesbook.Maui.Core.RestClient.IntegryApi.Dto;
public class RegisterDeviceDTO
{
[JsonPropertyName("userDeviceToken")]
public WtbUserDeviceTokenDTO UserDeviceToken { get; set; }
}

View File

@@ -0,0 +1,22 @@
using System.Text.Json.Serialization;
namespace salesbook.Maui.Core.RestClient.IntegryApi.Dto;
public class WtbUserDeviceTokenDTO
{
[JsonPropertyName("type")]
public string Type => "wtb_user_device_tokens";
[JsonPropertyName("deviceToken")]
public string DeviceToken { get; set; }
[JsonPropertyName("userName")]
public string Username { get; set; }
[JsonPropertyName("appName")]
public int AppName => 7; //salesbook
[JsonPropertyName("platform")]
public string Platform { get; set; }
}

View File

@@ -0,0 +1,38 @@
using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account;
using IntegryApiClient.Core.Domain.RestClient.Contacts;
using Microsoft.Extensions.Logging;
using salesbook.Maui.Core.RestClient.IntegryApi.Dto;
using salesbook.Shared.Core.Interface;
namespace salesbook.Maui.Core.RestClient.IntegryApi;
public class IntegryNotificationRestClient(
ILogger<IntegryNotificationRestClient> logger,
IUserSession userSession,
IIntegryApiRestClient integryApiRestClient
) : IIntegryNotificationRestClient
{
public async Task Register(string fcmToken, ILogger? logger1 = null)
{
logger1 ??= logger;
var userDeviceToken = new RegisterDeviceDTO()
{
UserDeviceToken = new WtbUserDeviceTokenDTO()
{
DeviceToken = fcmToken,
Platform = OperatingSystem.IsAndroid() ? "Android" : "iOS",
Username = userSession.User.Username
}
};
try
{
await integryApiRestClient.AuthorizedPost<object>($"device_tokens/insert", userDeviceToken,
logger: logger1);
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
}
}
}

View File

@@ -1,6 +1,6 @@
using salesbook.Shared.Core.Interface;
namespace salesbook.Maui.Core.Services;
namespace salesbook.Maui.Core.System.Network;
public class NetworkService : INetworkService
{

View File

@@ -0,0 +1,16 @@
using salesbook.Shared.Core.Interface;
using Shiny;
using Shiny.Push;
namespace salesbook.Maui.Core.System.Notification;
public class FirebaseNotificationService(IPushManager pushManager, IIntegryNotificationRestClient integryNotificationRestClient) : IFirebaseNotificationService
{
public async Task InitFirebase()
{
var (accessState, token) = await pushManager.RequestAccess();
if (accessState == AccessState.Denied || token is null) return;
await integryNotificationRestClient.Register(token);
}
}

View File

@@ -0,0 +1,31 @@
using Shiny.Push;
namespace salesbook.Maui.Core.System.Notification.Push;
public class PushNotificationDelegate : IPushDelegate
{
public Task OnEntry(PushNotification notification)
{
// fires when the user taps on a push notification
return Task.CompletedTask;
}
public Task OnReceived(PushNotification notification)
{
// fires when a push notification is received (silient or notification)
//notification.Data["content-available"] = "1";
return Task.CompletedTask;
}
public Task OnNewToken(string token)
{
// fires when a push notification change is set by the operating system or provider
return Task.CompletedTask;
}
public Task OnUnRegistered(string token)
{
// fires when a push notification change is set by the operating system or provider
return Task.CompletedTask;
}
}