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,
L("Notifications:WelcomeToApplication"),
L("Notifications:WelcomeToApplication"),
notificationType: NotificationType.System,
notificationType: NotificationType.Application,
lifetime: NotificationLifetime.OnlyOne,
allowSubscriptionToClients: true)
.WithProviders(

1
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",

1
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": "数据",

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")]
public string Name { get; set; }
[StringLength(NotificationConsts.MaxNameLength)]
[DisplayName("Notifications:TemplateName")]
public string TemplateName { get; set; }
[DisplayName("Notifications:Data")]
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 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(
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),
data: input.Data);
await NotificationSender
.SendNofiterAsync(
name: input.Name,
template: notificationTemplate,
user: user,
CurrentTenant.Id,
input.Severity);
tenantId: CurrentTenant.Id,
severity: input.Severity);
}
protected async virtual Task<NotificationDefinition> GetNotificationDefinition(string name)
{
var notification = await NotificationDefinitionManager.GetOrNullAsync(name);
if (notification == null || notification.Template == null)
else
{
throw new BusinessException(
MessageServiceErrorCodes.NotificationTemplateNotFound,
$"The notification template {name} does not exist!")
.WithData("Name", name);
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);
}
}
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,
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(

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)
{
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)

Loading…
Cancel
Save