public BaseViewModel(IDataStore <User> userDataStore, IConversationsDataStore convDataStore, IMessageDataStore messageDataStore) { _conversationDataStore = convDataStore; _messageDataStore = messageDataStore; _userDataStore = userDataStore; _notBusyObservable = this.WhenAnyValue(vm => vm.IsBusy, isBusy => !isBusy); }
public ConversationsViewModel(IDataStore <User> userDataStore, IConversationsDataStore convDataStore, IMessageDataStore messageDataStore, INavigationService navigationService) : base(userDataStore, convDataStore, messageDataStore) { _navigationService = navigationService; ConversationSelectedCommand = ReactiveCommand.CreateFromTask <Conversation>(ConversationSelected); FilterOptionChangedCommand = ReactiveCommand.CreateFromTask <bool>(FilterOptionChanged, _notBusyObservable); }
public ConversationsPageViewModel(INavigationService navigationService, IConversationsDataStore conversationsDataStore, IDialogService dialogService ) : base(navigationService, dialogService) { Title = "帮助中心"; _conversationsDataStore = conversationsDataStore; //搜索 this.WhenAnyValue(x => x.Filter.SerchKey) .Select(s => s) .Throttle(TimeSpan.FromSeconds(2), RxApp.MainThreadScheduler) .Subscribe(s => { ((ICommand)SerchCommand)?.Execute(s); }).DisposeWith(DeactivateWith); this.SerchCommand = ReactiveCommand.Create <string>(e => { if (!IsBusy) { ((ICommand)Load)?.Execute(null); } }); //初始化 this.Load = ReactiveCommand.CreateFromTask(() => Task.Run(async() => { await FilterOptionChanged(); })); this.FilterOptionChangedCommand = ReactiveCommand.CreateFromTask <bool>(OnTabChange, this.WhenAnyValue(vm => vm.IsBusy, isBusy => !isBusy)); //选择客服 this.ConversationSelectedCommand = ReactiveCommand.Create <Conversation>(async item => { await this.NavigateAsync("MessagerPage", ("ConversationId", item.Id)); //this.Selecter = null; }); this.BindBusyCommand(Load); }
public MessagerPageViewModel(INavigationService navigationService, IConversationsDataStore conversationsDataStore, IMessagesDataStore messagesDataStore, IDialogService dialogService ) : base(navigationService, dialogService) { Title = "帮助中心"; _conversationsDataStore = conversationsDataStore; _messagesDataStore = messagesDataStore; _messages = new List <Message>(); //回复 this.ReplyMessageSelectedCommand = ReactiveCommand.Create <Message>((message) => { ScrollToMessage(message); }); this.MessageSwippedCommand = ReactiveCommand.Create <Message>((message) => { ReplyMessage = message; MessagingCenter.Send(this, Constants.ShowKeyboard, new MyFocusEventArgs { IsFocused = true }); }); //发送消息 this.SendMessageCommand = ReactiveCommand.CreateFromTask(async() => { var message = new Message { Content = CurrentMessage, ReplyTo = ReplyMessage, CreationDate = DateTime.Now, Sender = new User(), ISentPreviousMessage = (bool)Messages?.Last()?.Last()?.ISent, ISent = true, ConversationId = CurrentConversation.Id, SenderId = new User().Id }; CurrentConversation.LastMessage = message; await _conversationsDataStore.UpdateItemAsync(CurrentConversation); CurrentMessage = string.Empty; Messages.Last().Add(message); ReplyMessage = null; await _messagesDataStore.AddItemAsync(message); CurrentConversation.LastMessage = message; ScrollToMessage(message); await FakeMessaging(); }, this.WhenAnyValue(vm => vm.CurrentMessage, curm => !String.IsNullOrEmpty(curm))); //取消回复 this.CancelReplyCommand = ReactiveCommand.Create(() => { ReplyMessage = null; MessagingCenter.Send(this, Constants.ShowKeyboard, new MyFocusEventArgs { IsFocused = false }); }); //初始化 this.Load = ReactiveCommand.CreateFromTask(() => Task.Run(async() => { //获取对话 this.CurrentConversation = await _conversationsDataStore.GetItemAsync(this.ConversationId); //获取消息 var messages = await _messagesDataStore.GetMessagesForConversation(this.ConversationId); _messages.AddRange(messages); var messagesGroups = _messages.GroupBy(m => m.CreationDate.Day) .Select(grp => { var messagesGrp = grp.ToList().OrderBy(m => m.CreationDate); var msg = messagesGrp.First(); var date = msg.CreationDate.Date; var dayDiff = DateTime.Now.Day - date.Day; string groupHeader = string.Empty; if (dayDiff == 0) { groupHeader = TextResources.Today; } else if (dayDiff == 1) { groupHeader = TextResources.Yesterday; } else { groupHeader = date.ToString("MM-dd-yyyy"); } return(new MessagesGroup ( dateTime: date, groupHeader: groupHeader, messages: new ObservableCollection <Message>(messagesGrp) )); }) .OrderBy(m => m.DateTime.Day) .ToList(); this.Messages = new ObservableCollection <MessagesGroup>(messagesGroups); await Task.Delay(TimeSpan.FromSeconds(0.5)); if (Messages.Any()) { ScrollToMessage(Messages?.Last()?.Last()); } })); this.BindBusyCommand(Load); }
public SettingsViewModel(IDataStore <User> userDataStore, IConversationsDataStore convDataStore, IMessageDataStore messageDataStore) : base(userDataStore, convDataStore, messageDataStore) { }