public async Task <int> DeleteByUserId(string userId) { try { var userConnections = await _userConnectionRepository.GetAllUserConnections(userId); if (userConnections != null && userConnections.Any()) { await _notificationHubContext.Clients.Clients(userConnections.Select(x => x.ConnectionId).ToList()) .SendAsync("LoggedOut"); } return(await _userConnectionRepository.Delete(userId)); } catch (Exception e) { return(1); } }
public async Task Handle(NotificationEvent @event) { var notification = new Notification { TenantId = @event.TenantId, Id = @event.Id.ToString(), Title = @event.Title, Content = @event.Content, Image = @event.Image, ReceiverId = @event.ReceiverId, SenderId = @event.SenderId, SenderFullName = @event.SenderFullName, SenderAvatar = @event.SenderAvatar, Type = @event.Type, Url = @event.Url }; var result = await _notificationService.Insert(notification); if (result.Code > 0) { var userConnections = Task.Run(() => _userConnectionRepository.GetAllUserConnections(notification.ReceiverId)).Result; if (userConnections.Any()) { // Refactor: Need to support multi languages. var cultureInfo = new CultureInfo("vi-VN"); Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; // Parse notification title to current language. notification.Title = ExtractMessageContent(notification.Title); notification.Content = ExtractMessageContent(notification.Content); foreach (var userConnection in userConnections) { await _notificationHub .Clients .Client(userConnection.ConnectionId) .SendAsync("NotificationReceived", notification); } } } }
private async Task SendNotification(NotificationEvent @event) { var notification = new Notification { TenantId = @event.TenantId, Id = @event.Id.ToString(), Title = @event.Title, Content = @event.Content, Image = @event.Image, ReceiverId = @event.ReceiverId, SenderId = @event.SenderId, SenderFullName = @event.SenderFullName, SenderAvatar = @event.SenderAvatar, Type = @event.Type, Url = @event.Url }; var result = await _notificationService.Insert(notification); if (result.Code > 0) { var userConnections = await _userConnectionRepository.GetAllUserConnections(notification.ReceiverId); if (userConnections.Any()) { // Parse notification title to current language. notification.Title = ExtractMessageContent(notification.Title); notification.Content = ExtractMessageContent(notification.Content); foreach (var userConnection in userConnections) { await _notificationHub .Clients .Client(userConnection.ConnectionId) .SendAsync("NotificationReceived", notification); } } } }