public async Task Post([FromBody] dynamic data) { if (data == null || data.Acknowledgment == null || data.broadcastMode == null || data.Message == null || data.UserId == null || data.NotificationType == null) { _logger.Log(LogLevel.Warn, "InAppNotificationAdminController", "Notification is not valid", new { data }); return; } var notif = new InAppNotification { Acknowledgment = data.Acknowledgment, NotificationType = data.NotificationType, Message = data.Message, UserId = data.UserId, CreatedOn = DateTime.UtcNow, Type = "notification.admin" }; var broadcastMode = (BroadcastMode)(data.BroadcastMode ?? BroadcastMode.None); if (broadcastMode == BroadcastMode.AllConnectedUsers) { // TODO await _notificationChannel.SendNotification("AdminNotificationBroadcastAllConnectedUsers", notif); } else if (broadcastMode == BroadcastMode.AllUsers) { // TODO //await _notificationChannel.SendNotification("AdminNotificationBroadcastAllUsers", notif); } else //if (broadcastMode == BroadcastMode.None) { var record = new InAppNotificationRecord(notif); await _repository.IndexNotification(record); // TODO await _notificationChannel.SendNotification("AdminNotification.ByUserId", notif); } }
public async Task IndexNotification(InAppNotificationRecord notif) { var client = await _client; if (string.IsNullOrEmpty(notif.Id)) { notif.Id = Guid.NewGuid().ToString("N"); } await client.IndexDocumentAsync(notif); }
public async Task <bool> SendNotification(string type, dynamic data) { var notif = data as InAppNotification; if (notif == null) { return(false); } PeerFilter filter; bool sent = false; if (string.IsNullOrWhiteSpace(notif.UserId)) { _logger.Log(Stormancer.Diagnostics.LogLevel.Warn, "InAppNotificationProvider", "UserId is null", data); return(false); } if (notif.UserId == "*") { filter = new MatchArrayFilter(_scene.RemotePeers); // TODO fix matchAll //filter = new MatchAllFilter(); } else { var list = new List <string>(); foreach (var userId in notif.UserId.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { var session = await _userSessions.GetSessionByUserId(userId); if (session != null) { list.Add(session.SessionId); sent = true; } } filter = new MatchArrayFilter(list); } notif.Id = Guid.NewGuid().ToString("N"); notif.UserId = ""; notif.CreatedOn = DateTime.UtcNow; await _scene.Send(filter, "inappnotification.push", s => serializer.Serialize(notif, s), PacketPriority.MEDIUM_PRIORITY, PacketReliability.RELIABLE_ORDERED); if (notif.Acknowledgment == InAppNotificationAcknowledgment.OnReceive || notif.Acknowledgment == InAppNotificationAcknowledgment.ByUser || (!sent && notif.Acknowledgment == InAppNotificationAcknowledgment.OnSend)) { var record = new InAppNotificationRecord(notif); await _repository.IndexNotification(record); } return(true); }
public InAppNotification(InAppNotificationRecord record) { Id = record.Id; Type = record.Type; UserId = record.UserId; Message = record.Message; Data = record.Data; CreatedOn = record.CreatedOn; ShouldExpire = record.ShouldExpire; ExpirationDate = record.ExpirationDate; Acknowledgment = record.Acknowledgment; NotificationType = record.NotificationType; }