Browse Source

fix: global notifications should include the host

pull/682/head
cKey 3 years ago
parent
commit
47a2268a90
  1. 2
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.Common/LINGYUN/Abp/Notifications/NotificationsCommonNotificationDefinitionProvider.cs
  2. 1
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/Resources/en.json
  3. 1
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/Resources/zh-Hans.json
  4. 4
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/NotificationSendDto.cs
  5. 53
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs
  6. 10
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpMessageServiceNotificationDefinitionProvider.cs
  7. 4
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs

2
aspnet-core/modules/common/LINGYUN.Abp.Notifications.Common/LINGYUN/Abp/Notifications/NotificationsCommonNotificationDefinitionProvider.cs

@ -60,7 +60,7 @@ public class NotificationsCommonNotificationDefinitionProvider : NotificationDef
UserNotificationNames.WelcomeToApplication, UserNotificationNames.WelcomeToApplication,
L("Notifications:WelcomeToApplication"), L("Notifications:WelcomeToApplication"),
L("Notifications:WelcomeToApplication"), L("Notifications:WelcomeToApplication"),
notificationType: NotificationType.System, notificationType: NotificationType.Application,
lifetime: NotificationLifetime.OnlyOne, lifetime: NotificationLifetime.OnlyOne,
allowSubscriptionToClients: true) allowSubscriptionToClients: true)
.WithProviders( .WithProviders(

1
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/Resources/en.json

@ -7,6 +7,7 @@
"Notifications:Type": "Type", "Notifications:Type": "Type",
"Notifications:SendTime": "SendTime", "Notifications:SendTime": "SendTime",
"Notifications:Name": "Name", "Notifications:Name": "Name",
"Notifications:TemplateName": "Template Name",
"Notifications:Description": "Description", "Notifications:Description": "Description",
"Notifications:Culture": "Culture", "Notifications:Culture": "Culture",
"Notifications:Data": "Data", "Notifications:Data": "Data",

1
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/Resources/zh-Hans.json

@ -7,6 +7,7 @@
"Notifications:Type": "类型", "Notifications:Type": "类型",
"Notifications:SendTime": "发送时间", "Notifications:SendTime": "发送时间",
"Notifications:Name": "名称", "Notifications:Name": "名称",
"Notifications:TemplateName": "模板名称",
"Notifications:Description": "描述", "Notifications:Description": "描述",
"Notifications:Culture": "区域", "Notifications:Culture": "区域",
"Notifications:Data": "数据", "Notifications:Data": "数据",

4
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")] [DisplayName("Notifications:Name")]
public string Name { get; set; } public string Name { get; set; }
[StringLength(NotificationConsts.MaxNameLength)]
[DisplayName("Notifications:TemplateName")]
public string TemplateName { get; set; }
[DisplayName("Notifications:Data")] [DisplayName("Notifications:Data")]
public Dictionary<string, object> Data { get; set; } = new Dictionary<string, object>(); public Dictionary<string, object> Data { get; set; } = new Dictionary<string, object>();

53
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs

@ -1,5 +1,6 @@
using LINGYUN.Abp.Notifications; using LINGYUN.Abp.Notifications;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
@ -103,31 +104,49 @@ namespace LINGYUN.Abp.MessageService.Notifications
user = new UserIdentifier(input.ToUserId.Value, input.ToUserName); user = new UserIdentifier(input.ToUserId.Value, input.ToUserName);
} }
await NotificationSender if (!input.TemplateName.IsNullOrWhiteSpace())
.SendNofiterAsync( {
name: input.Name, if (notification.Template == null)
template: new NotificationTemplate( {
throw new BusinessException(
MessageServiceErrorCodes.NotificationTemplateNotFound,
$"The notification template {input.TemplateName} does not exist!")
.WithData("Name", input.TemplateName);
}
var notificationTemplate = new NotificationTemplate(
notification.Name, notification.Name,
culture: input.Culture ?? CultureInfo.CurrentCulture.Name, culture: input.Culture ?? CultureInfo.CurrentCulture.Name,
formUser: CurrentUser.Name ?? CurrentUser.UserName, formUser: CurrentUser.Name ?? CurrentUser.UserName,
data: input.Data), data: input.Data);
await NotificationSender
.SendNofiterAsync(
name: input.Name,
template: notificationTemplate,
user: user, user: user,
CurrentTenant.Id, tenantId: CurrentTenant.Id,
input.Severity); severity: input.Severity);
} }
else
protected async virtual Task<NotificationDefinition> GetNotificationDefinition(string name)
{
var notification = await NotificationDefinitionManager.GetOrNullAsync(name);
if (notification == null || notification.Template == null)
{ {
throw new BusinessException( var notificationData = new NotificationData();
MessageServiceErrorCodes.NotificationTemplateNotFound, notificationData.ExtraProperties.AddIfNotContains(input.Data);
$"The notification template {name} does not exist!")
.WithData("Name", name); notificationData = NotificationData.ToStandardData(notificationData);
await NotificationSender
.SendNofiterAsync(
name: input.Name,
data: notificationData,
user: user,
tenantId: CurrentTenant.Id,
severity: input.Severity);
}
} }
return notification; protected async virtual Task<NotificationDefinition> GetNotificationDefinition(string name)
{
return await NotificationDefinitionManager.GetAsync(name);
} }
} }
} }

10
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, MessageServiceNotificationNames.IM.FriendValidation,
L("Notifications:FriendValidation"), L("Notifications:FriendValidation"),
L("Notifications:FriendValidation"), L("Notifications:FriendValidation"),
notificationType: NotificationType.System, notificationType: NotificationType.Application,
lifetime: NotificationLifetime.Persistent, lifetime: NotificationLifetime.Persistent,
allowSubscriptionToClients: true) allowSubscriptionToClients: true)
.WithProviders( .WithProviders(
@ -24,7 +24,7 @@ namespace LINGYUN.Abp.MessageService.Notifications
MessageServiceNotificationNames.IM.NewFriend, MessageServiceNotificationNames.IM.NewFriend,
L("Notifications:NewFriend"), L("Notifications:NewFriend"),
L("Notifications:NewFriend"), L("Notifications:NewFriend"),
notificationType: NotificationType.System, notificationType: NotificationType.Application,
lifetime: NotificationLifetime.Persistent, lifetime: NotificationLifetime.Persistent,
allowSubscriptionToClients: true) allowSubscriptionToClients: true)
.WithProviders( .WithProviders(
@ -33,7 +33,7 @@ namespace LINGYUN.Abp.MessageService.Notifications
MessageServiceNotificationNames.IM.JoinGroup, MessageServiceNotificationNames.IM.JoinGroup,
L("Notifications:JoinGroup"), L("Notifications:JoinGroup"),
L("Notifications:JoinGroup"), L("Notifications:JoinGroup"),
notificationType: NotificationType.System, notificationType: NotificationType.Application,
lifetime: NotificationLifetime.Persistent, lifetime: NotificationLifetime.Persistent,
allowSubscriptionToClients: true) allowSubscriptionToClients: true)
.WithProviders( .WithProviders(
@ -42,7 +42,7 @@ namespace LINGYUN.Abp.MessageService.Notifications
MessageServiceNotificationNames.IM.ExitGroup, MessageServiceNotificationNames.IM.ExitGroup,
L("Notifications:ExitGroup"), L("Notifications:ExitGroup"),
L("Notifications:ExitGroup"), L("Notifications:ExitGroup"),
notificationType: NotificationType.System, notificationType: NotificationType.Application,
lifetime: NotificationLifetime.Persistent, lifetime: NotificationLifetime.Persistent,
allowSubscriptionToClients: true) allowSubscriptionToClients: true)
.WithProviders( .WithProviders(
@ -51,7 +51,7 @@ namespace LINGYUN.Abp.MessageService.Notifications
MessageServiceNotificationNames.IM.DissolveGroup, MessageServiceNotificationNames.IM.DissolveGroup,
L("Notifications:DissolveGroup"), L("Notifications:DissolveGroup"),
L("Notifications:DissolveGroup"), L("Notifications:DissolveGroup"),
notificationType: NotificationType.System, notificationType: NotificationType.Application,
lifetime: NotificationLifetime.Persistent, lifetime: NotificationLifetime.Persistent,
allowSubscriptionToClients: true) allowSubscriptionToClients: true)
.WithProviders( .WithProviders(

4
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) if (notification.NotificationType == NotificationType.System)
{ {
await SendToTenantAsync(null, notification, eventData);
var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync(); var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync();
foreach (var activeTenant in allActiveTenants) foreach (var activeTenant in allActiveTenants)
@ -210,6 +212,8 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed
if (notification.NotificationType == NotificationType.System) if (notification.NotificationType == NotificationType.System)
{ {
await SendToTenantAsync(null, notification, eventData);
var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync(); var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync();
foreach (var activeTenant in allActiveTenants) foreach (var activeTenant in allActiveTenants)

Loading…
Cancel
Save