using System;
using System.Threading.Tasks;
using Abp;
using Abp.Dependency;
using Abp.Notifications;
using Abp.Runtime.Session;
using WeOnlineApp.Configuration;
using IwbZero.Runtime.Session;
namespace WeOnlineApp.CommonManager.Notifications
{
public class NotificationManager : INotificationManager, ISingletonDependency
{
private readonly INotificationPublisher _notificationPublisher;
private readonly IwbSession _abpSession;
public NotificationManager(INotificationPublisher notificationPublisher, IwbSession abpSession)
{
_notificationPublisher = notificationPublisher;
_abpSession = abpSession;
}
public async Task WelcomeToSystemAsync()
{
await _notificationPublisher.PublishAsync(
IwbNotificationName.WelcomeMsg, new MessageNotificationData("欢迎登陆"), severity: NotificationSeverity.Success,
userIds: new[] { _abpSession.ToUserIdentifier() });
}
///
/// 发送给指定用户消息(info)
///
///
///
///
public async Task SendMsgAsync(UserIdentifier user, string message)
{
await SendMsgAsync(user, message, NotificationSeverity.Info);
}
///
/// 发送给指定用户消息
///
///
///
///
///
public async Task SendMsgAsync(UserIdentifier user, string message, NotificationSeverity severity)
{
await _notificationPublisher.PublishAsync(
IwbNotificationName.SendMsg,
new MessageNotificationData(message), severity: severity, userIds: new[] { user });
}
///
/// 发送某种消息给订阅用户(Info)
///
/// 消息唯一名称
///
///
public async Task SendMsgAsync(string msgName, string message)
{
await SendMsgAsync(msgName, message, NotificationSeverity.Info);
}
///
/// 发送某种消息给订阅用户
///
/// 消息唯一名称
///
///
///
public async Task SendMsgAsync(string msgName, string message, NotificationSeverity severity)
{
await _notificationPublisher.PublishAsync(msgName, new MessageNotificationData(message), severity: severity);
}
///
/// 发送某种消息给指定用户(带发送人)
///
///
///
///
///
///
public async Task SendMessageAsync(UserIdentifier user, string msgName, SendMsgNotificationData data, NotificationSeverity severity)
{
await _notificationPublisher.PublishAsync(msgName, data, severity: severity, userIds: new[] { user });
}
///
/// 发送某种消息给订阅用户(带发送人)
///
///
///
///
///
public async Task SendMessageAsync(string msgName, SendMsgNotificationData data, NotificationSeverity severity)
{
await _notificationPublisher.PublishAsync(msgName, data, severity: severity);
}
}
[Serializable]
public class SendMsgNotificationData : NotificationData
{
public string SenderUserName { get; set; }
public string Message { get; set; }
public SendMsgNotificationData(string senderUserName, string message)
{
SenderUserName = senderUserName;
Message = message;
}
}
}