/// <summary> /// 初始发送的数据对象 /// </summary> /// <param name="notificationName"></param> /// <param name="message"></param> /// <param name="detailed"></param> /// <returns></returns> private FrameNotificationData InitNotificationData(string notificationName, string message, string detailed) { var notification = _cacheManagerExtens.GetNotificationCache(notificationName); //设置通知内容以及详细信息 FrameNotificationData frameNotificationData = new FrameNotificationData(message); frameNotificationData.NotificationType = notification.NotificationType; frameNotificationData.Title = notification.NotificationDisplayName; frameNotificationData.NotificationDetailed = detailed; frameNotificationData.SendId = AbpSessionExtens.UserId.Value; return(frameNotificationData); }
/// <summary> /// 发送点对点消息 /// </summary> /// <param name="recipientId"></param> /// <param name="chatDetailed"></param> /// <param name="severity"></param> /// <returns></returns> public virtual async Task SendChatAsync(long recipientId, string chatDetailed, NotificationSeverity severity = NotificationSeverity.Info) { UserIdentifier userIdentifier = new UserIdentifier(AbpSessionExtens.TenantId, recipientId); //用户不在线直接返回 var onlineClients = _onlineClientManager.GetAllByUserId(userIdentifier); if (onlineClients == null || onlineClients.Count == 0) { return; } UserInfo userModel = _cacheManagerExtens.GetUserInfoCache(recipientId); string promptContent = "您有一条来自[" + userModel.UserNameCn + "]的消息"; string promptTitle = "您有一条新消息"; FrameNotificationData frameNotificationData = new FrameNotificationData(promptContent); frameNotificationData.NotificationType = "chat"; //推送的类型用于前端JS判断 frameNotificationData.Title = promptTitle; frameNotificationData.NotificationDetailed = chatDetailed; frameNotificationData.SendId = AbpSessionExtens.UserId.Value; TenantNotification tenantNotification = new TenantNotification() { Id = Guid.NewGuid(), Data = frameNotificationData, Severity = severity, NotificationName = "站内短信", TenantId = userIdentifier.TenantId, CreationTime = DateTime.Now }; List <UserNotification> userNotification = new List <UserNotification>(); userNotification.Add( new UserNotification { Id = Guid.NewGuid(), Notification = tenantNotification, UserId = userIdentifier.UserId, State = UserNotificationState.Unread, TenantId = userIdentifier.TenantId }); await _realTimeNotifier.SendNotificationsAsync(userNotification.ToArray()); }
/// <summary> /// 发送通知到用户 /// </summary> /// <param name="notificationName">订阅名称</param> /// <param name="message">消息内容</param> /// <param name="userIdentifier">用户对象集合</param> /// <param name="severity">通知类型枚举</param> /// <param name="detailed">消息详细信息</param> /// <returns></returns> public virtual async Task PublishAsync(string notificationName, string message, UserIdentifier[] userIdentifier, NotificationSeverity severity = NotificationSeverity.Info, string detailed = null) { FrameNotificationData frameNotificationData = InitNotificationData(notificationName, message, detailed); await PublishAsync(notificationName, frameNotificationData, severity : severity, userIds : userIdentifier); }