public async Task SendMessage(string roomId, string msg) { if (roomId.IsNullOrEmpty() || roomId.IsNullOrWhiteSpace() || roomId.Length > 5120) { return; } if (msg.IsNullOrEmpty() || msg.IsNullOrWhiteSpace() || msg.Length > 5120) { return; } await ExtractAffectedUser(roomId); var currentUser = UserConnecteds.FirstOrDefault(x => x.Id == CurrentUser.Id.Value); var msgDTO = new UserMessageDTO { Message = msg, IsReceived = true, IsReaded = false, MessGroupId = CurrentRoomId }; // Lưu tin nhắn vào CSDL msgDTO = await _UserMessageService.CreateAsync(msgDTO); msgDTO.Photo = currentUser.Picture; msgDTO.DisplayName = currentUser.DisplayName; if (msgDTO.Id != Guid.Empty) { // Gửi tin nhắn đến tất cả người dùng trong danh sách await _NotificationHub.Clients .Users(AffectedUser.Where(x => x != CurrentUser.Id.Value).Select(x => x.ToString())) .SendAsync("NotyHaveNewMsgReciver", msgDTO); await Clients.Users(AffectedUser.Select(x => x.ToString())).SendAsync("ReceiveMessage", msgDTO); } }