Пример #1
0
 public IActionResult AddMessage(int writer, int requestId, string message)
 {
     _messageService.AddMessage(new ChatMessage
     {
         Message   = message,
         RequestId = requestId,
         Writer    = writer
     });
     return(Ok());
 }
Пример #2
0
        public Task SendRoomMessage(string roomId, string message)
        {
            var userId = Context.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (_roomService.HasUserAccess(roomId, userId))
            {
                var msg = new ChatMessage {
                    Content = message, RoomID = roomId, UserID = userId, Username = Context.User.Identity.Name
                };
                _chatMessageService.AddMessage(msg);
                return(Clients.Groups(roomId).SendAsync("ReceiveMessage", Context.User.Identity.Name, message, roomId));
            }
            else
            {
                return(Clients.Caller.SendAsync("ReceiveServerMessage", message));
            }
        }