using JetBrains.Annotations;
using System.Collections.Generic;
using System.Collections.Immutable;
using Volo.Abp;
using Volo.Abp.Localization;
namespace Sanhe.Abp.Notifications;
///
/// 通知组定义
///
public class NotificationGroupDefinition
{
///
/// 通知组名称
///
[NotNull]
public string Name { get; set; }
///
/// 通知组显示名称
///
[NotNull]
public ILocalizableString DisplayName {
get => _displayName;
set => _displayName = Check.NotNull(value, nameof(value));
}
private ILocalizableString _displayName;
///
/// 通知组说明
///
[CanBeNull]
public ILocalizableString Description { get; set; }
///
/// 允许客户端显示订阅
///
public bool AllowSubscriptionToClients { get; set; }
public IReadOnlyList Notifications => _notifications.ToImmutableList();
private readonly List _notifications;
protected internal NotificationGroupDefinition(
string name,
ILocalizableString displayName = null,
bool allowSubscriptionToClients = false)
{
Name = name;
DisplayName = displayName ?? new FixedLocalizableString(Name);
AllowSubscriptionToClients = allowSubscriptionToClients;
_notifications = new List();
}
///
/// 添加通知
///
/// 通知组名称
/// 通知组显示名称
/// 通知组说明
/// 通知类型
/// 通知存活时间
/// 允许客户端显示订阅
///
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;
}
}