You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.6 KiB
84 lines
2.6 KiB
using JetBrains.Annotations; |
|
using System.Collections.Generic; |
|
using System.Collections.Immutable; |
|
using Volo.Abp; |
|
using Volo.Abp.Localization; |
|
|
|
namespace Sanhe.Abp.Notifications; |
|
|
|
/// <summary> |
|
/// 通知组定义 |
|
/// </summary> |
|
public class NotificationGroupDefinition |
|
{ |
|
/// <summary> |
|
/// 通知组名称 |
|
/// </summary> |
|
[NotNull] |
|
public string Name { get; set; } |
|
/// <summary> |
|
/// 通知组显示名称 |
|
/// </summary> |
|
[NotNull] |
|
public ILocalizableString DisplayName { |
|
get => _displayName; |
|
set => _displayName = Check.NotNull(value, nameof(value)); |
|
} |
|
private ILocalizableString _displayName; |
|
/// <summary> |
|
/// 通知组说明 |
|
/// </summary> |
|
[CanBeNull] |
|
public ILocalizableString Description { get; set; } |
|
/// <summary> |
|
/// 允许客户端显示订阅 |
|
/// </summary> |
|
public bool AllowSubscriptionToClients { get; set; } |
|
|
|
public IReadOnlyList<NotificationDefinition> Notifications => _notifications.ToImmutableList(); |
|
private readonly List<NotificationDefinition> _notifications; |
|
|
|
protected internal NotificationGroupDefinition( |
|
string name, |
|
ILocalizableString displayName = null, |
|
bool allowSubscriptionToClients = false) |
|
{ |
|
Name = name; |
|
DisplayName = displayName ?? new FixedLocalizableString(Name); |
|
AllowSubscriptionToClients = allowSubscriptionToClients; |
|
|
|
_notifications = new List<NotificationDefinition>(); |
|
} |
|
|
|
/// <summary> |
|
/// 添加通知 |
|
/// </summary> |
|
/// <param name="name">通知组名称</param> |
|
/// <param name="displayName">通知组显示名称</param> |
|
/// <param name="description">通知组说明</param> |
|
/// <param name="notificationType">通知类型</param> |
|
/// <param name="lifetime">通知存活时间</param> |
|
/// <param name="allowSubscriptionToClients">允许客户端显示订阅</param> |
|
/// <returns></returns> |
|
public virtual NotificationDefinition AddNotification( |
|
string name, |
|
ILocalizableString displayName = null, |
|
ILocalizableString description = null, |
|
NotificationType notificationType = NotificationType.Application, |
|
NotificationLifetime lifetime = NotificationLifetime.Persistent, |
|
bool allowSubscriptionToClients = false) |
|
{ |
|
var notification = new NotificationDefinition( |
|
name, |
|
displayName, |
|
description, |
|
notificationType, |
|
lifetime, |
|
allowSubscriptionToClients |
|
); |
|
|
|
_notifications.Add(notification); |
|
|
|
return notification; |
|
} |
|
}
|
|
|