public async Task <ChatMessageReceivedByChatRoomEvent> Run(ChatMessageSentEvent message)
        {
            var chatMessage = _messages.Find(message.Contents.Id);
            var chatRoomId  = CalculateChatRoomId(chatMessage.Destination);
            var chatRoom    = _chatRooms.Find(chatRoomId);

            if (!_chatRooms.ListMembers(chatRoom.Id).Any(m => chatMessage.Sender.Id == m.Id))
            {
                throw new PermissionException("User is not a member of this chat room.");
            }

            var messageReceivedEvent = new ChatMessageReceivedByChatRoomEvent
            {
                ChatMessage  = chatMessage,
                ChatRoom     = chatRoom,
                DateReceived = DateTime.Now
            };

            _chatMessageReceivedEvents.Add(messageReceivedEvent);

            return(await Task.FromResult(messageReceivedEvent));
        }
Esempio n. 2
0
 public IEnumerable <ChatUser> Members(int chatRoomId)
 => _chatRoomsRepository.ListMembers(chatRoomId);