Example #1
0
        public LoginViewModel(IDialogService dialogService, INavigationService navigationService)
        {
            ctx         = TalkBackAppContext.Get();
            CurrentUser = new UserModel();

            // _loginService = loginService;
            _dialogService     = dialogService;
            _navigationService = navigationService;

            ctx.Dispatcher.EstablishConnectionAsync();
            ctx.LoginWindow = this;

            LoginCommand = new RelayCommand(() =>
            {
                // The service sends the user input to the server that checks them in the DB
                // _loginService.LogIn(CurrentUser);
                //
                TryLogin();

                // When the server finish to check user input, it sends back contcts list and the page navigate
                // or sends error message that triggers a popup window with appropriate message.

                //contactList = something from the service
                //if (contactsList == null)
                //    _dialogService.ShowMessageBox("Password incorrect", "Error");
                //else
                //    _navigationService.NavigateTo("ContactsPage", contactsList);
                //_navigationService.NavigateTo("ContactsPage", contactsList);
            });
        }
Example #2
0
        public ChatViewModel(INavigationService navigationService)
        {
            _navigationService = navigationService;
            ctx            = TalkBackAppContext.Get();
            ctx.ChatWinodw = this;
            PeerUserName   = ctx.PeerUserName;

            HistoryContent = new ObservableCollection <string>();
            SendCommand    = new RelayCommand(() =>
            {
                MessageModel msg = new MessageModel()
                {
                    From    = ctx.CurrentUser.Name,
                    Content = MyMessage,
                    To      = PeerUserName
                };
                SendMessage(msg);

                MyMessage = string.Empty;
                RaisePropertyChanged(nameof(MyMessage));
            });

            BackCommand = new RelayCommand(() =>
            {
                _navigationService.NavigateTo(ViewModelLocator.ContactsPageKey);
                Window.Current.Activate();
            });
        }
Example #3
0
        public ContactsViewModel(IDialogService dialogService, INavigationService navigationService)
        {
            _navigationService = navigationService;
            _dialogService     = dialogService;
            _chatRequestActive = false;

            OnlineContacts     = new ObservableCollection <string>();
            OfflineContacts    = new ObservableCollection <string>();
            ctx                = TalkBackAppContext.Get();
            ctx.ContactsWindow = this;
            CurrentUserName    = ctx.CurrentUser.Name;

            ReloadContacts();

            StartChat = new RelayCommand(() =>
            {
                if (SelectedItem == null)
                {
                    _dialogService.ShowMessageBox("You must select a contact to chat with.", "Error");
                }
                else
                {
                    ctx.PeerUserName   = SelectedItem;
                    _chatRequestActive = true;
                    ChatRequest req    = new ChatRequest {
                        From = CurrentUserName, To = SelectedItem
                    };
                    ctx.Dispatcher.SendObjectAsync(req);
                    timer = ThreadPoolTimer.CreateTimer(OnNoResponse, new TimeSpan(0, 0, 59));
                }
            });

            LogOutCommand = new RelayCommand(() =>
            {
                ctx.MyWebSocket.Close(1000, "User signedoff");
                ctx.Dispatcher.EstablishConnectionAsync();
                _navigationService.NavigateTo(ViewModelLocator.LoginPageKey);
                Window.Current.Activate();
            });
        }