From dcb810c0d6e996bc39d46497d5f545e141607c6a Mon Sep 17 00:00:00 2001
From: cKey <35512826+colinin@users.noreply.github.com>
Date: Sat, 28 May 2022 11:26:56 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=9A=E7=9F=A5=E6=A8=A1?=
=?UTF-8?q?=E5=9D=97.=E5=A2=9E=E5=8A=A0=E5=86=85=E7=BD=AE=E9=80=9A?=
=?UTF-8?q?=E7=9F=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../LINGYUN.Abp.Notifications.csproj | 8 ++
.../Notifications/AbpNotificationModule.cs | 20 ++++-
.../Abp/Notifications/DefaultNotifications.cs | 18 +++++
.../DefaultNotificationDefinitionProvider.cs | 44 +++++++++++
.../Localization/NotificationsResource.cs | 8 ++
.../Localization/Resources/en.json | 12 +++
.../Localization/Resources/zh-Hans.json | 12 +++
.../Distributed/NotificationEventHandler.cs | 15 +---
.../Distributed/TenantSynchronizer.cs | 73 ++++++++++---------
.../UserCreateSendWelcomeEventHandler.cs | 38 +++++++---
10 files changed, 192 insertions(+), 56 deletions(-)
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/DefaultNotifications.cs
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDefinitionProvider.cs
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/NotificationsResource.cs
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/Resources/en.json
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Localization/Resources/zh-Hans.json
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