Beispiel #1
0
        protected override async Task OnParametersSetAsync()
        {
            var state = await AuthenticationState;

            LoggedInUser = state.User;

            if (!LoggedInUser.Identity.IsAuthenticated)
            {
                return;
            }

            Dispatcher.Dispatch(new GetMessagesAction(ContactId));
            Dispatcher.Dispatch(new GetSingleUserAction(ContactId));

            UserState.StateChanged += (sender, state) =>
            {
                if (SelectedUser != null)
                {
                    return;
                }

                if (state.ClientUsers.Where(x => x.ContactId == ContactId).SingleOrDefault() == null)
                {
                    return;
                }

                SelectedUser = state.ClientUsers.Where(x => x.ContactId == ContactId).SingleOrDefault();
                PageTitle    = $"Messages with {SelectedUser.FullName}";
            };

            NewMessage = new ClientMessageCreate();

            await base.OnParametersSetAsync();
        }
Beispiel #2
0
        private void HandleCompleteCreate()
        {
            NewMessage.AuthorID           = LoggedInUser.Claims.First(x => x.Type == "sub").Value;
            NewMessage.RecipientContactId = ContactId;

            Dispatcher.Dispatch(new SendMessageAction(NewMessage));

            NewMessage = new ClientMessageCreate();
        }
Beispiel #3
0
        public async Task <IActionResult> CreateMessage([FromBody] ClientMessageCreate newMessage)
        {
            newMessage.SentAt = DateTimeOffset.UtcNow;
            var message = _mapper.Map <Message>(newMessage);

            await _uow.MessageRepository.Insert(message);

            var recipientUserId = await _uow.UserRepository.SelectData(x => x.UserName, x => x.ContactId == message.RecipientContactId);

            _logger.LogInformation($"Message with id {message.Id} was created.");
            await _hubContext.Clients.All.SendAsync("message", _mapper.Map <ClientMessage>(message));

            return(Ok());
        }
 public SendMessageAction(ClientMessageCreate newMessage)
 {
     NewMessage = newMessage;
 }