Exemplo n.º 1
0
        private async Task LoadData()
        {
            var rawBlocks = await _viewModel.CheckBlock();

            var blocks = JsonConvert.DeserializeObject <List <UserToBlockedUser> >(rawBlocks.content);

            ButtonSend.IsEnabled  = true;
            EntrySend.IsEnabled   = true;
            EntrySend.Placeholder = AppResources.ChatMessagePlaceholder;
            if (blocks.Any())
            {
                ButtonSend.IsEnabled  = false;
                EntrySend.IsEnabled   = false;
                EntrySend.Placeholder = AppResources.ChatIsBlockedPlaceholder;
            }

            var connectTask     = _viewModel.Connect(_tripId, _conversationId);
            var getMessagesTask = _viewModel.LoadMessageListAsync(_tripId, _conversationId);

            var(baseResult, content) = (new BaseResult(), string.Empty);
            if (_conversationId == Guid.Empty)
            {
                await connectTask;
                (baseResult, content) = await _viewModel.LoadMessageListAsync(_tripId, _viewModel.ConversationId);
            }
            else
            {
                await Task.WhenAny(connectTask, getMessagesTask);

                (baseResult, content) = await getMessagesTask;
            }

            switch (baseResult.Result)
            {
            case StatusCode.Ok:
                _viewModel.IsBusy = false;
                _viewModel.FillMessageList(content);

                Device.BeginInvokeOnMainThread(() =>
                {
                    MainScreenMessagesListView.ScrollTo(_viewModel.MessageList.LastOrDefault(), ScrollToPosition.MakeVisible, false);
                });
                break;

            case StatusCode.Unauthorized when _viewModel.IsModalAuthWasOpen:
                return;

            case StatusCode.Unauthorized:
                await Navigation.PushAsync(new ModalAuthenticationPage(Chat));

                _viewModel.IsModalAuthWasOpen = true;
                break;

            default:
                await DisplayAlert(AppResources.Notification, baseResult.Message, AppResources.Ok);

                _viewModel.IsModalAuthWasOpen = true;
                break;
            }
        }
Exemplo n.º 2
0
        public void ShowChatControl()
        {
            chatControl   = new ChatControl();
            chatViewModel = new ChatViewModel();
            chatViewModel.Connect();
            chatControl.DataContext = chatViewModel;

            MasterContentControl.Content = chatControl;
        }
 protected override async void OnAppearing()
 {
     base.OnAppearing();
     await viewModel.Connect();
 }