diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Common/LINGYUN/Abp/Notifications/NotificationsCommonNotificationDefinitionProvider.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Common/LINGYUN/Abp/Notifications/NotificationsCommonNotificationDefinitionProvider.cs index 05b27cc00..91d5856ec 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Common/LINGYUN/Abp/Notifications/NotificationsCommonNotificationDefinitionProvider.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Common/LINGYUN/Abp/Notifications/NotificationsCommonNotificationDefinitionProvider.cs @@ -60,7 +60,7 @@ public class NotificationsCommonNotificationDefinitionProvider : NotificationDef UserNotificationNames.WelcomeToApplication, L("Notifications:WelcomeToApplication"), L("Notifications:WelcomeToApplication"), - notificationType: NotificationType.System, + notificationType: NotificationType.Application, lifetime: NotificationLifetime.OnlyOne, allowSubscriptionToClients: true) .WithProviders( 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 index 8e7bddce6..d03b701a8 100644 --- 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 @@ -7,6 +7,7 @@ "Notifications:Type": "Type", "Notifications:SendTime": "SendTime", "Notifications:Name": "Name", + "Notifications:TemplateName": "Template Name", "Notifications:Description": "Description", "Notifications:Culture": "Culture", "Notifications:Data": "Data", 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 index 522ebd549..373e2ac64 100644 --- 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 @@ -7,6 +7,7 @@ "Notifications:Type": "类型", "Notifications:SendTime": "发送时间", "Notifications:Name": "名称", + "Notifications:TemplateName": "模板名称", "Notifications:Description": "描述", "Notifications:Culture": "区域", "Notifications:Data": "数据", diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/NotificationSendDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/NotificationSendDto.cs index b7a3ef2d9..174acd640 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/NotificationSendDto.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/NotificationSendDto.cs @@ -13,6 +13,10 @@ namespace LINGYUN.Abp.MessageService.Notifications [DisplayName("Notifications:Name")] public string Name { get; set; } + [StringLength(NotificationConsts.MaxNameLength)] + [DisplayName("Notifications:TemplateName")] + public string TemplateName { get; set; } + [DisplayName("Notifications:Data")] public Dictionary Data { get; set; } = new Dictionary(); diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs index af286e9e3..c71380dd5 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs @@ -1,5 +1,6 @@ using LINGYUN.Abp.Notifications; using Microsoft.AspNetCore.Authorization; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -103,31 +104,49 @@ namespace LINGYUN.Abp.MessageService.Notifications user = new UserIdentifier(input.ToUserId.Value, input.ToUserName); } - await NotificationSender - .SendNofiterAsync( - name: input.Name, - template: new NotificationTemplate( - notification.Name, - culture: input.Culture ?? CultureInfo.CurrentCulture.Name, - formUser: CurrentUser.Name ?? CurrentUser.UserName, - data: input.Data), - user: user, - CurrentTenant.Id, - input.Severity); + if (!input.TemplateName.IsNullOrWhiteSpace()) + { + if (notification.Template == null) + { + throw new BusinessException( + MessageServiceErrorCodes.NotificationTemplateNotFound, + $"The notification template {input.TemplateName} does not exist!") + .WithData("Name", input.TemplateName); + } + var notificationTemplate = new NotificationTemplate( + notification.Name, + culture: input.Culture ?? CultureInfo.CurrentCulture.Name, + formUser: CurrentUser.Name ?? CurrentUser.UserName, + data: input.Data); + + await NotificationSender + .SendNofiterAsync( + name: input.Name, + template: notificationTemplate, + user: user, + tenantId: CurrentTenant.Id, + severity: input.Severity); + } + else + { + var notificationData = new NotificationData(); + notificationData.ExtraProperties.AddIfNotContains(input.Data); + + notificationData = NotificationData.ToStandardData(notificationData); + + await NotificationSender + .SendNofiterAsync( + name: input.Name, + data: notificationData, + user: user, + tenantId: CurrentTenant.Id, + severity: input.Severity); + } } protected async virtual Task GetNotificationDefinition(string name) { - var notification = await NotificationDefinitionManager.GetOrNullAsync(name); - if (notification == null || notification.Template == null) - { - throw new BusinessException( - MessageServiceErrorCodes.NotificationTemplateNotFound, - $"The notification template {name} does not exist!") - .WithData("Name", name); - } - - return notification; + return await NotificationDefinitionManager.GetAsync(name); } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpMessageServiceNotificationDefinitionProvider.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpMessageServiceNotificationDefinitionProvider.cs index 04a92ea9b..74d26f501 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpMessageServiceNotificationDefinitionProvider.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpMessageServiceNotificationDefinitionProvider.cs @@ -15,7 +15,7 @@ namespace LINGYUN.Abp.MessageService.Notifications MessageServiceNotificationNames.IM.FriendValidation, L("Notifications:FriendValidation"), L("Notifications:FriendValidation"), - notificationType: NotificationType.System, + notificationType: NotificationType.Application, lifetime: NotificationLifetime.Persistent, allowSubscriptionToClients: true) .WithProviders( @@ -24,7 +24,7 @@ namespace LINGYUN.Abp.MessageService.Notifications MessageServiceNotificationNames.IM.NewFriend, L("Notifications:NewFriend"), L("Notifications:NewFriend"), - notificationType: NotificationType.System, + notificationType: NotificationType.Application, lifetime: NotificationLifetime.Persistent, allowSubscriptionToClients: true) .WithProviders( @@ -33,7 +33,7 @@ namespace LINGYUN.Abp.MessageService.Notifications MessageServiceNotificationNames.IM.JoinGroup, L("Notifications:JoinGroup"), L("Notifications:JoinGroup"), - notificationType: NotificationType.System, + notificationType: NotificationType.Application, lifetime: NotificationLifetime.Persistent, allowSubscriptionToClients: true) .WithProviders( @@ -42,7 +42,7 @@ namespace LINGYUN.Abp.MessageService.Notifications MessageServiceNotificationNames.IM.ExitGroup, L("Notifications:ExitGroup"), L("Notifications:ExitGroup"), - notificationType: NotificationType.System, + notificationType: NotificationType.Application, lifetime: NotificationLifetime.Persistent, allowSubscriptionToClients: true) .WithProviders( @@ -51,7 +51,7 @@ namespace LINGYUN.Abp.MessageService.Notifications MessageServiceNotificationNames.IM.DissolveGroup, L("Notifications:DissolveGroup"), L("Notifications:DissolveGroup"), - notificationType: NotificationType.System, + notificationType: NotificationType.Application, lifetime: NotificationLifetime.Persistent, allowSubscriptionToClients: true) .WithProviders( 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 a891482ac..f0d6e5479 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 @@ -122,6 +122,8 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed if (notification.NotificationType == NotificationType.System) { + await SendToTenantAsync(null, notification, eventData); + var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync(); foreach (var activeTenant in allActiveTenants) @@ -210,6 +212,8 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed if (notification.NotificationType == NotificationType.System) { + await SendToTenantAsync(null, notification, eventData); + var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync(); foreach (var activeTenant in allActiveTenants)