50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Erp.Notifications.Enums;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.DependencyInjection;
|
|
using Volo.Abp.Identity;
|
|
|
|
namespace Erp.Notifications.Domain;
|
|
|
|
public interface INotificationIdentifierProvider : ITransientDependency
|
|
{
|
|
Task<string?> GetIdentifier(Guid UserId, string NotificationChannel);
|
|
}
|
|
|
|
public class NotificationIdentifierProvider : INotificationIdentifierProvider
|
|
{
|
|
private readonly IIdentityUserRepository userRepository;
|
|
|
|
public NotificationIdentifierProvider(IIdentityUserRepository userRepository)
|
|
{
|
|
this.userRepository = userRepository;
|
|
|
|
}
|
|
|
|
public async Task<string?> GetIdentifier(Guid UserId, string NotificationChannel)
|
|
{
|
|
var user = await userRepository.FindAsync(UserId);
|
|
if (user == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
|
|
var identifier = NotificationChannel switch
|
|
{
|
|
NotificationChannels.Sms => user.PhoneNumber,
|
|
NotificationChannels.Mail => user.Email,
|
|
NotificationChannels.Rocket => user.GetProperty<string?>("RocketUsername"),
|
|
NotificationChannels.Desktop => user.Id.ToString(),
|
|
NotificationChannels.UiActivity => user.Id.ToString(),
|
|
NotificationChannels.UiToast => user.Id.ToString(),
|
|
NotificationChannels.WhatsApp => user.PhoneNumber,
|
|
NotificationChannels.Telegram => user.PhoneNumber,
|
|
_ => null,
|
|
};
|
|
|
|
return identifier;
|
|
}
|
|
}
|
|
|