public BakerProfileViewModel( string bakerId, IScreen hostScreen = null, ICakeModelService cakeModelService = null, IAppUserModelService appUserModelService = null, IBakerModelService bakerModelService = null, IUserApiService userApiService = null, ILogger logger = null, IMapper mapper = null) : base(hostScreen) { _cakeModelService = cakeModelService; _appUserModelService = appUserModelService; _bakerModelService = bakerModelService; _userApiService = userApiService; _logger = logger; _mapper = mapper; _bakerIdSubject = new Subject <string>(); StartChatCommand = ReactiveCommand.CreateFromTask(GoToChat); PrepareCommand = ReactiveCommand.CreateFromTask(async b => await Prepare(bakerId)); Observable.Return(Unit.Default) .InvokeCommand(PrepareCommand); PrepareCommand.Subscribe(); }
public PaymentViewModel( PaymentNavigation paymentNavigation, IAppUserModelService appUserModelService = null, IBakerModelService bakerModelService = null, IPaymentApiService paymentApiService = null) { _appUserModelService = appUserModelService ?? Locator.Current.GetService <IAppUserModelService>(); _bakerModelService = bakerModelService ?? Locator.Current.GetService <IBakerModelService>(); _paymentApiService = paymentApiService ?? Locator.Current.GetService <IPaymentApiService>(); PayWithVippsCommand = ReactiveCommand.CreateFromTask(PayWithVipps); var canGoToReceiptObservable = this.WhenAnyValue(vm => vm.PaymentSuccessfull) .Select(ps => ps) .StartWith(false); canGoToReceiptObservable.ToProperty(this, vm => vm.GoNextEnabled, out _goNextEnabled); GoNextCommand = ReactiveCommand.CreateFromTask(GoToReceipt, canGoToReceiptObservable); Prepare(paymentNavigation); }
public BakerChatViewModel(string bakerId, IAppUserModelService appUserModelService = null, IBakerModelService bakerModelService = null, IChatModelService chatModelService = null) { _appUserModelService = appUserModelService ?? Locator.Current.GetService <IAppUserModelService>(); _bakerModelService = bakerModelService; _chatModelService = chatModelService; var user = _appUserModelService.User; UserAvatarUrl = user.AvatarUrl; var dynamicFilter = this.WhenValueChanged(vm => vm.BakerId) .Select(CreatePredicate); var chatMessages = _chatModelService .ChatsForUser .Connect() .SubscribeOn(RxApp.TaskpoolScheduler) .Filter(dynamicFilter) .Transform(TransformToListItem) .Publish(); chatMessages .Bind(out _chatMessages) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe() .DisposeWith(CompositeDisposable); chatMessages.Connect(); SendMessageCommand = ReactiveCommand.CreateFromTask(SendMessage); PrepareCommand = ReactiveCommand.CreateFromTask(async b => await Prepare(bakerId)); Observable.Return(Unit.Default) .InvokeCommand(PrepareCommand); PrepareCommand.Subscribe(); }
public ChatModelService(IAppUserModelService appUserModelService, IChatApiService chatApiService, IBakerModelService bakerModelService, ILogger logger) { _chatApiService = chatApiService; _logger = logger; _chatsForUser = new SourceCache <ChatMessageDto, int>(cm => cm.Id); _bakerChatsForUser = new SourceCache <BakerDto, string>(bk => bk.Id); appUserModelService .UserObservable .ObserveOn(RxApp.TaskpoolScheduler) .Where(u => u != null) .SelectMany(async u => await chatApiService.GetChatsForUser(u.Id)) .RetryWithBackoff(3) .LogException(logger) .Subscribe(async chatMessages => { _chatsForUser.Edit(l => l.AddOrUpdate(chatMessages)); var bakerIds = chatMessages.GroupBy(cm => cm.BakerId).Select(b => b.Key); foreach (var bakerId in bakerIds) { var baker = await bakerModelService.GetBaker(bakerId); _bakerChatsForUser.Edit(l => l.AddOrUpdate(baker)); //TODO: optimize } }); }