Esempio n. 1
0
        private async Task MarkRepoAsRead(string repo)
        {
            try
            {
                IsMarking = true;
                var repoId = new CodeFramework.Core.Utils.RepositoryIdentifier(repo);
                await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Notifications.MarkRepoAsRead(repoId.Owner, repoId.Name));

                Notifications.Items.RemoveRange(Notifications.Items.Where(x => string.Equals(x.Repository.FullName, repo, StringComparison.OrdinalIgnoreCase)).ToList());
                UpdateAccountNotificationsCount();
            }
            catch (Exception e)
            {
                DisplayAlert("Unable to mark repositories' notifications as read. Please try again.");
            }
            finally
            {
                IsMarking = false;
            }
        }
Esempio n. 2
0
        public NotificationsViewModel(IApplicationService applicationService)
        {
            _applicationService = applicationService;
            Notifications = new ReactiveCollection<NotificationModel> {GroupFunc = x => x.Repository.FullName};

            LoadCommand.RegisterAsyncTask(t =>
            {
                var req = applicationService.Client.Notifications.GetAll(all: Filter.All, participating: Filter.Participating);
                return this.RequestModel(req, t as bool?, response => Notifications.Reset(response.Data));
            });

            GoToNotificationCommand = new ReactiveCommand();
            GoToNotificationCommand.OfType<NotificationModel>().Subscribe(GoToNotification);

            ReadAllCommand = new ReactiveCommand(this.WhenAnyValue(x => x.ShownIndex, x => x != 2));
            ReadAllCommand.RegisterAsyncTask(async t =>
            {
                try
                {
                    if (!Notifications.Any()) return;
                    await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkAsRead());
                    Notifications.Clear();
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to mark all notifications as read. Please try again.", e);
                }
            });

            ReadRepositoriesCommand = new ReactiveCommand();
            ReadRepositoriesCommand.RegisterAsyncTask(async t =>
            {
                try
                {
                    var repo = t as string;
                    if (repo == null) return;
                    var repoId = new CodeFramework.Core.Utils.RepositoryIdentifier(repo);
                    await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkRepoAsRead(repoId.Owner, repoId.Name));
                    Notifications.RemoveAll(Notifications.Where(x => string.Equals(x.Repository.FullName, repo, StringComparison.OrdinalIgnoreCase)).ToList());
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to mark repositories' notifications as read. Please try again.", e);
                }
            });

            this.WhenAnyValue(x => x.ShownIndex).Subscribe(x =>
            {
                switch (x)
                {
                    case 0:
                        Filter = NotificationsFilterModel.CreateUnreadFilter();
                        break;
                    case 1:
                        Filter = NotificationsFilterModel.CreateParticipatingFilter();
                        break;
                    default:
                        Filter = NotificationsFilterModel.CreateAllFilter();
                        break;
                }
            });

            this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(x => LoadCommand.ExecuteIfCan());
        }
Esempio n. 3
0
        private async Task MarkRepoAsRead(string repo)
		{
            try
            {
                IsMarking = true;
                var repoId = new CodeFramework.Core.Utils.RepositoryIdentifier(repo);
                await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Notifications.MarkRepoAsRead(repoId.Owner, repoId.Name));
                Notifications.Items.RemoveRange(Notifications.Items.Where(x => string.Equals(x.Repository.FullName, repo, StringComparison.OrdinalIgnoreCase)).ToList());
                UpdateAccountNotificationsCount();
            }
            catch (Exception e)
            {
                ReportError(e);
            }
            finally
            {
                IsMarking = false;
            }
		}