private static async Task <NotificationModel> ProcessNotification(this Octokit.Notification notification)
        {
            NotificationModel result = null;
            var isIssue = notification.Subject.Type.ToLower() == "issue";
            var isPR    = notification.Subject.Type.ToLower() == "pullrequest";

            if (int.TryParse(notification.Subject.Url.Split('/').Last().Split('#').First(), out int number))
            {
                var subtitle = "";
                var repo     = notification.Repository;
                var repoName = repo.FullName ?? repo.Name;
                if (isIssue)
                {
                    var issue = await IssueUtility.GetIssue(repo.Id, number);

                    subtitle = $"Issue {number}";
                    result   = new NotificationModel(repo.Id, issue, subtitle);
                }
                else if (isPR)
                {
                    var pr = await PullRequestUtility.GetPullRequest(repo.Id, number);

                    subtitle = $"PR {number}";
                    result   = new NotificationModel(repo.Id, pr, subtitle);
                }
                subtitle = !StringHelper.IsNullOrEmptyOrWhiteSpace(subtitle)
                          ? $"{subtitle} in {repoName}"
                          : repoName;
                result.SetSubtitle(subtitle);
            }

            return(result ?? throw new NullReferenceException(nameof(result)));
        }
Ejemplo n.º 2
0
        public async Task Load(Tuple <Repository, PullRequest> tuple)
        {
            PullRequest = tuple.Item2;
            Repository  = tuple.Item1;

            if (GlobalHelper.IsInternet())
            {
                isLoading   = true;
                PullRequest = await PullRequestUtility.GetPullRequest(Repository.Id, PullRequest.Number);

                Comments = await IssueUtility.GetAllCommentsForIssue(Repository.Id, PullRequest.Number);

                isLoading = false;
            }
        }
        public async Task Load(Tuple <Repository, PullRequest> tuple)
        {
            PullRequest = tuple.Item2;
            Repository  = tuple.Item1;

            if (!GlobalHelper.IsInternet())
            {
                //Sending NoInternet message to all viewModels
                Messenger.Default.Send(new GlobalHelper.LocalNotificationMessageType {
                    Message = "No Internet", Glyph = "\uE704"
                });
            }
            else
            {
                isLoading   = true;
                PullRequest = await PullRequestUtility.GetPullRequest(Repository.Id, PullRequest.Number);

                Comments = await IssueUtility.GetAllCommentsForIssue(Repository.Id, PullRequest.Number);

                isLoading = false;
            }
        }
Ejemplo n.º 4
0
        public async void NotificationsListView_ItemClick(object sender, ItemClickEventArgs e)
        {
            Notification notif = e.ClickedItem as Notification;

            if (int.TryParse(notif.Subject.Url.Split('/').Last().Split('?')[0], out int id))
            {
                if (notif.Subject.Type.ToLower().Equals("issue"))
                {
                    await SimpleIoc.Default.GetInstance <IAsyncNavigationService>().NavigateAsync(typeof(IssueDetailView), new Tuple <Repository, Issue>(notif.Repository, await IssueUtility.GetIssue(notif.Repository.Id, id)));
                }
                else if (notif.Subject.Type.ToLower().Equals("pullrequest"))
                {
                    await SimpleIoc.Default.GetInstance <IAsyncNavigationService>().NavigateAsync(typeof(PullRequestDetailView), new Tuple <Repository, PullRequest>(notif.Repository, await PullRequestUtility.GetPullRequest(notif.Repository.Id, id)));
                }
            }
            if (notif.Unread)
            {
                await NotificationsService.MarkNotificationAsRead(notif.Id);
            }
        }
Ejemplo n.º 5
0
        private async void OnLaunchedOrActivated(IActivatedEventArgs args)
        {
            // Set the right theme-depending color for the alternating rows
            if (SettingsService.Get <bool>(SettingsKeys.AppLightThemeEnabled))
            {
                XAMLHelper.AssignValueToXAMLResource("OddAlternatingRowsBrush", new SolidColorBrush {
                    Color = Color.FromArgb(0x08, 0, 0, 0)
                });
            }
            if (args is LaunchActivatedEventArgs launchArgs)
            {
                if (!launchArgs.PrelaunchActivated)
                {
                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(null);
                        (Window.Current.Content as Page).OpenFromSplashScreen(launchArgs.SplashScreen.ImageLocation);
                    }
                }
                Activate();
                Window.Current.Activate();
                BackgroundTaskService.RegisterAppTriggerBackgroundTasks();
            }
            else if (args is ToastNotificationActivatedEventArgs toastActivatedEventArgs)
            {
                if (args.Kind == ActivationKind.Protocol)
                {
                    if (args.PreviousExecutionState == ApplicationExecutionState.Running)
                    {
                        await HandleProtocolActivationArguments(args);
                    }
                    else
                    {
                        if (Window.Current.Content == null)
                        {
                            Window.Current.Content = new MainPage(args);
                        }
                        Activate();
                    }
                }
                else if (args.Kind == ActivationKind.ToastNotification)
                {
                    var mainPageType = typeof(FeedView);
                    var backPageType = typeof(NotificationsView);
                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(args);
                    }
                    else
                    {
                        var svc = SimpleIoc
                                  .Default
                                  .GetInstance <IAsyncNavigationService>();
                        try
                        {
                            var toastArgs      = QueryString.Parse(toastActivatedEventArgs.Argument);
                            var notificationId = toastArgs["notificationId"] as string;
                            var repoId         = long.Parse(toastArgs["repoId"]);

                            string group = null,
                                   tag   = $"N{notificationId}+R{repoId}";

                            var repo = await RepositoryUtility.GetRepository(repoId);

                            switch (toastArgs["action"])
                            {
                            case "showIssue":
                                var issueNumber = int.Parse(toastArgs["issueNumber"]);

                                var issue = await IssueUtility.GetIssue(repo.Id, issueNumber);

                                tag  += $"+I{issueNumber}";
                                group = "Issues";
                                await svc.NavigateAsync(typeof(IssueDetailView), new Tuple <Repository, Issue>(repo, issue), backPageType : backPageType);

                                break;

                            case "showPr":
                                var prNumber = int.Parse(toastArgs["prNumber"]);
                                var pr       = await PullRequestUtility.GetPullRequest(repoId, prNumber);

                                tag  += $"+P{pr.Number}";
                                group = "PullRequests";
                                await svc.NavigateAsync(typeof(PullRequestDetailView), new Tuple <Repository, PullRequest>(repo, pr), backPageType : backPageType);

                                break;
                            }
                            if (!StringHelper.IsNullOrEmptyOrWhiteSpace(tag) && !StringHelper.IsNullOrEmptyOrWhiteSpace(group))
                            {
                                ToastNotificationManager.History.Remove(tag, group);
                            }
                            if (!StringHelper.IsNullOrEmptyOrWhiteSpace(notificationId))
                            {
                                await NotificationsService.MarkNotificationAsRead(notificationId);
                            }
                        }
                        catch
                        {
                            await svc.NavigateAsync(mainPageType);
                        }
                    }

                    Activate();
                    Window.Current.Activate();
                }
            }
            else if (args is StartupTaskActivatedEventArgs startupTaskActivatedEventArgs)
            {
                if (args.Kind == ActivationKind.StartupTask)
                {
                    var payload = ActivationKind.StartupTask.ToString();
                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(args);
                    }
                    (Window.Current.Content as Frame).Navigate(typeof(NotificationsView));
                }
            }
        }