diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj index d98083ef8..206ed4be1 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj @@ -8,6 +8,14 @@ + + + + + + + + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs index fafc1e65b..dee8f62ef 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs @@ -1,4 +1,5 @@ using LINGYUN.Abp.IdGenerator; +using LINGYUN.Abp.Notifications.Localization; using LINGYUN.Abp.RealTime; using Microsoft.Extensions.DependencyInjection; using System; @@ -6,7 +7,9 @@ using System.Collections.Generic; using Volo.Abp.BackgroundJobs; using Volo.Abp.BackgroundWorkers; using Volo.Abp.Json; +using Volo.Abp.Localization; using Volo.Abp.Modularity; +using Volo.Abp.VirtualFileSystem; namespace LINGYUN.Abp.Notifications { @@ -16,15 +19,30 @@ namespace LINGYUN.Abp.Notifications typeof(AbpBackgroundJobsAbstractionsModule), typeof(AbpIdGeneratorModule), typeof(AbpJsonModule), + typeof(AbpLocalizationModule), typeof(AbpRealTimeModule))] public class AbpNotificationModule : AbpModule { - public override void PreConfigureServices(ServiceConfigurationContext context) { AutoAddDefinitionProviders(context.Services); } + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.FileSets.AddEmbedded(); + }); + + Configure(options => + { + options.Resources + .Add("en") + .AddVirtualJson("/LINGYUN/Abp/Notifications/Localization/Resources"); + }); + } + private void AutoAddDefinitionProviders(IServiceCollection services) { var definitionProviders = new List(); diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/DefaultNotifications.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/DefaultNotifications.cs new file mode 100644 index 000000000..e0bb1b810 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/DefaultNotifications.cs @@ -0,0 +1,18 @@ +namespace LINGYUN.Abp.Notifications; + +public static class DefaultNotifications +{ + public const string GroupName = "Abp.Notifications"; + /// + /// 站内通知 + /// + public const string OnsideNotice = GroupName + ".OnsideNotice"; + /// + /// 活动通知 + /// + public const string ActivityNotice = GroupName + ".ActivityNotice"; + /// + /// 系统通知 + /// + public const string SystemNotice = GroupName + ".SystemNotice"; +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDefinitionProvider.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDefinitionProvider.cs new file mode 100644 index 000000000..f2e35fe14 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDefinitionProvider.cs @@ -0,0 +1,44 @@ +using LINGYUN.Abp.Notifications.Localization; +using Volo.Abp.Localization; + +namespace LINGYUN.Abp.Notifications.Internal; + +internal class DefaultNotificationDefinitionProvider : NotificationDefinitionProvider +{ + public override void Define(INotificationDefinitionContext context) + { + var internalGroup = context.AddGroup( + DefaultNotifications.GroupName, + L("Notifications:Internal")); + + internalGroup.AddNotification( + DefaultNotifications.OnsideNotice, + L("Notifications:OnsideNotice"), + L("Notifications:OnsideNoticeDesc"), + notificationType: NotificationType.Application, + lifetime: NotificationLifetime.Persistent, + allowSubscriptionToClients: true) + .WithProviders(NotificationProviderNames.SignalR); + internalGroup.AddNotification( + DefaultNotifications.ActivityNotice, + L("Notifications:ActivityNotice"), + L("Notifications:ActivityNoticeDesc"), + notificationType: NotificationType.Application, + lifetime: NotificationLifetime.Persistent, + allowSubscriptionToClients: true) + .WithProviders(NotificationProviderNames.SignalR); + internalGroup.AddNotification( + DefaultNotifications.SystemNotice, + L("Notifications:SystemNotice"), + L("Notifications:SystemNoticeDesc"), + notificationType: NotificationType.System, + lifetime: NotificationLifetime.Persistent, + allowSubscriptionToClients: true) + .WithProviders(NotificationProviderNames.SignalR); + } + + protected LocalizableString L(string name) + { + return LocalizableString.Create(name); + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/NotificationsResource.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/NotificationsResource.cs new file mode 100644 index 000000000..690187edf --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/NotificationsResource.cs @@ -0,0 +1,8 @@ +using Volo.Abp.Localization; + +namespace LINGYUN.Abp.Notifications.Localization; + +[LocalizationResourceName("Notifications")] +public class NotificationsResource +{ +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/Resources/en.json b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/Resources/en.json new file mode 100644 index 000000000..974a19e4f --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/Resources/en.json @@ -0,0 +1,12 @@ +{ + "culture": "en", + "texts": { + "Notifications:Internal": "Internal", + "Notifications:OnsideNotice": "Onside", + "Notifications:OnsideNoticeDesc": "In-app notification push", + "Notifications:ActivityNotice": "Activity", + "Notifications:ActivityNoticeDesc": "The administrator delivers an event notification push", + "Notifications:SystemNotice": "System", + "Notifications:SystemNoticeDesc": "System global notification push" + } +} \ No newline at end of file diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/Resources/zh-Hans.json b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/Resources/zh-Hans.json new file mode 100644 index 000000000..c5ea0dec4 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/Resources/zh-Hans.json @@ -0,0 +1,12 @@ +{ + "culture": "zh-Hans", + "texts": { + "Notifications:Internal": "内置通知", + "Notifications:OnsideNotice": "站内通知", + "Notifications:OnsideNoticeDesc": "应用内部通知推送", + "Notifications:ActivityNotice": "活动通知", + "Notifications:ActivityNoticeDesc": "管理员下发活动通知推送", + "Notifications:SystemNotice": "系统通知", + "Notifications:SystemNoticeDesc": "系统全局消息推送" + } +} \ No newline at end of file diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs index 32c029759..079e857db 100644 --- a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs +++ b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs @@ -145,19 +145,10 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed { // 检查是够已订阅消息 Logger.LogDebug($"Gets a list of user subscriptions {notificationInfo.Name}"); - List userSubscriptions; - if (users == null) - { - // 获取用户订阅列表 - userSubscriptions = await NotificationSubscriptionManager - .GetUserSubscriptionsAsync(notificationInfo.TenantId, notificationInfo.Name); - } - else - { - // 过滤未订阅的用户 - userSubscriptions = await NotificationSubscriptionManager + + // 获取用户订阅列表 + var userSubscriptions = await NotificationSubscriptionManager .GetUsersSubscriptionsAsync(notificationInfo.TenantId, notificationInfo.Name, users); - } users = userSubscriptions.Select(us => new UserIdentifier(us.UserId, us.UserName)); diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/TenantSynchronizer.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/TenantSynchronizer.cs index 8fdb1f6fc..276b618fa 100644 --- a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/TenantSynchronizer.cs +++ b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/TenantSynchronizer.cs @@ -70,44 +70,51 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed private async Task SendNotificationAsync(CreateEventData eventData) { - var tenantAdminUserIdentifier = new UserIdentifier(eventData.AdminUserId, eventData.AdminEmailAddress); + try + { + var tenantAdminUserIdentifier = new UserIdentifier(eventData.AdminUserId, eventData.AdminEmailAddress); - // 租户管理员订阅事件 - await NotificationSubscriptionManager - .SubscribeAsync( - eventData.Id, - tenantAdminUserIdentifier, - TenantNotificationNames.NewTenantRegistered); + // 租户管理员订阅事件 + await NotificationSubscriptionManager + .SubscribeAsync( + eventData.Id, + tenantAdminUserIdentifier, + TenantNotificationNames.NewTenantRegistered); - var notificationData = new NotificationData(); - notificationData.TrySetData("name", eventData.Name); - notificationData.WriteLocalizedData( - new LocalizableStringInfo( - LocalizationResourceNameAttribute.GetName(typeof(MessageServiceResource)), - "NewTenantRegisteredNotificationTitle", - new Dictionary - { + var notificationData = new NotificationData(); + notificationData.TrySetData("name", eventData.Name); + notificationData.WriteLocalizedData( + new LocalizableStringInfo( + LocalizationResourceNameAttribute.GetName(typeof(MessageServiceResource)), + "NewTenantRegisteredNotificationTitle", + new Dictionary + { { "Name", eventData.Name }, - }), - new LocalizableStringInfo( - LocalizationResourceNameAttribute.GetName(typeof(MessageServiceResource)), - "NewTenantRegisteredNotificationMessage", - new Dictionary - { + }), + new LocalizableStringInfo( + LocalizationResourceNameAttribute.GetName(typeof(MessageServiceResource)), + "NewTenantRegisteredNotificationMessage", + new Dictionary + { { "Name", eventData.Name} - }), - DateTime.Now, eventData.AdminEmailAddress); + }), + DateTime.Now, eventData.AdminEmailAddress); - Logger.LogInformation("publish new tenant notification.."); - // 发布租户创建通知 - await NotificationSender - .SendNofiterAsync( - TenantNotificationNames.NewTenantRegistered, - notificationData, - tenantAdminUserIdentifier, - eventData.Id, - NotificationSeverity.Success); - Logger.LogInformation("tenant administrator subscribes to new tenant events.."); + Logger.LogInformation("publish new tenant notification.."); + // 发布租户创建通知 + await NotificationSender + .SendNofiterAsync( + TenantNotificationNames.NewTenantRegistered, + notificationData, + tenantAdminUserIdentifier, + eventData.Id, + NotificationSeverity.Success); + Logger.LogInformation("tenant administrator subscribes to new tenant events.."); + } + catch(Exception ex) + { + Logger.LogWarning(ex, "Failed to send the tenant initialization notification."); + } } } } diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Local/UserCreateSendWelcomeEventHandler.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Local/UserCreateSendWelcomeEventHandler.cs index 0c9e57940..1075b7daa 100644 --- a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Local/UserCreateSendWelcomeEventHandler.cs +++ b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Local/UserCreateSendWelcomeEventHandler.cs @@ -29,19 +29,10 @@ namespace LY.MicroService.RealtimeMessage.EventBus { var userIdentifer = new UserIdentifier(eventData.Entity.Id, eventData.Entity.UserName); // 订阅用户欢迎消息 - await _notificationSubscriptionManager - .SubscribeAsync( - eventData.Entity.TenantId, - userIdentifer, - UserNotificationNames.WelcomeToApplication); + await SubscribeInternalNotifers(userIdentifer, eventData.Entity.TenantId); var userWelcomeNotifictionData = new NotificationData(); - //userWelcomeNotifictionData.WriteStandardData( - // L("WelcomeToApplicationFormUser", eventData.Entity.Name ?? eventData.Entity.UserName), - // L("WelcomeToApplicationFormUser", eventData.Entity.Name ?? eventData.Entity.UserName), - // DateTime.Now, eventData.Entity.UserName); - userWelcomeNotifictionData.TrySetData("user", eventData.Entity.UserName); userWelcomeNotifictionData .WriteLocalizedData( @@ -70,5 +61,32 @@ namespace LY.MicroService.RealtimeMessage.EventBus NotificationSeverity.Info ); } + + private async Task SubscribeInternalNotifers(UserIdentifier userIdentifer, Guid? tenantId = null) + { + // 订阅内置通知 + await _notificationSubscriptionManager + .SubscribeAsync( + tenantId, + userIdentifer, + DefaultNotifications.SystemNotice); + await _notificationSubscriptionManager + .SubscribeAsync( + tenantId, + userIdentifer, + DefaultNotifications.OnsideNotice); + await _notificationSubscriptionManager + .SubscribeAsync( + tenantId, + userIdentifer, + DefaultNotifications.ActivityNotice); + + // 订阅用户欢迎消息 + await _notificationSubscriptionManager + .SubscribeAsync( + tenantId, + userIdentifer, + UserNotificationNames.WelcomeToApplication); + } } }