private ChatMessageDto BuildChatMessage(ChatAttachmentMessage chatMessage) { var url = _blobProvider.GetBlobUrl($"{chatMessage.ChatRoom.Id}/{chatMessage.Id}/{chatMessage.Blob}"); var properties = new ImageProperties(url); var hash = _binarySerializer.Serialize(properties); var srcUrl = _linkGenerator.GetPathByRouteValues(_httpContextAccessor.HttpContext, "imageUrl", new { hash = Base64UrlTextEncoder.Encode(hash) }); var hrefUrl = _linkGenerator.GetPathByRouteValues(_httpContextAccessor.HttpContext, "ChatDownload", new { chatRoomId = chatMessage.ChatRoom.Id, chatId = chatMessage.Id }); //return helper.RouteUrl("imageUrl", new //{ // hash = Base64UrlTextEncoder.Encode(hash) //}); //yield return _linkGenerator.GetUriByAction(_httpContextAccessor.HttpContext, "Index", "Home"); return(new ChatAttachmentDto { UserId = chatMessage.User.Id, Src = srcUrl, Href = hrefUrl, DateTime = DateTime.UtcNow }); }
public async Task ExecuteAsync(SendChatFileMessageCommand message, CancellationToken token) { var users = message.ToUsersId.ToList(); users.Add(message.UserSendingId); var chatRoom = await _chatRoomRepository.GetChatRoomAsync(users, token); if (chatRoom == null) { chatRoom = new ChatRoom(users.Select(s => _userRepository.Load(s)).ToList()); await _chatRoomRepository.AddAsync(chatRoom, token); } var user = _userRepository.Load(message.UserSendingId); var chatMessage = new ChatAttachmentMessage(user, message.Blob, chatRoom); chatRoom.AddMessage(chatMessage); await _chatRoomRepository.UpdateAsync(chatRoom, token); await _chatMessageRepository.AddAsync(chatMessage, token); var id = chatMessage.Id; await _blobProvider.MoveAsync(message.Blob, $"{chatRoom.Id}/{id}", token); }
private List <string> BuildUserList(ChatAttachmentMessage chatMessage) { return(chatMessage.ChatRoom.Users.Select(s => s.User.Id.ToString()).ToList()); }