using System; using System.Threading.Tasks; using Kurs.Notifications.Enums; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Identity; namespace Kurs.Notifications.Domain; public interface INotificationIdentifierProvider : ITransientDependency { Task GetIdentifier(Guid UserId, string NotificationChannel); } public class NotificationIdentifierProvider : INotificationIdentifierProvider { private readonly IIdentityUserRepository userRepository; public NotificationIdentifierProvider(IIdentityUserRepository userRepository) { this.userRepository = userRepository; } public async Task 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("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; } }