Exemplo n.º 1
0
 private void CreateToastNotifications(IEnumerable <ForumThreadEntity> forumThreads)
 {
     foreach (ForumThreadEntity thread in forumThreads.Where(thread => thread.RepliesSinceLastOpened > 0))
     {
         NotifyStatusTile.CreateToastNotification(thread);
     }
 }
Exemplo n.º 2
0
        private async Task CreateNotificationToast(DateTime lastRefreshTime)
        {
            var notifications = await _client.GetNotifications();

            var newNotifications = notifications.Where(node => node.CreatedAt > lastRefreshTime);

            foreach (var notification in newNotifications)
            {
                NotifyStatusTile.CreateToastNotification(notification);
            }
        }
        private async Task Update(IBackgroundTaskInstance taskInstance)
        {
            try
            {
                var  userAccountEntity = new UserAccountEntity();
                var  authManager       = new AuthenticationManager();
                bool loginTest         = await authManager.RefreshAccessToken(userAccountEntity);

                if (loginTest)
                {
                    UserAccountEntity.User user = await authManager.GetUserEntity(userAccountEntity);

                    if (user == null)
                    {
                        return;
                    }
                    userAccountEntity.SetUserEntity(user);
                    NotificationEntity notificationEntity = await GetNotifications(userAccountEntity);

                    if (notificationEntity == null)
                    {
                        return;
                    }
                    if (notificationEntity.Notifications == null)
                    {
                        return;
                    }

                    // Debug
                    //NotifyStatusTile.CreateNotificationLiveTile(notificationEntity.Notifications.First());
                    //NotifyStatusTile.CreateToastNotification(notificationEntity.Notifications.First());

                    var notificationList = notificationEntity.Notifications.Where(o => o.SeenFlag == false);
                    foreach (var notification in notificationList)
                    {
                        NotifyStatusTile.CreateNotificationLiveTile(notification);
                        NotifyStatusTile.CreateToastNotification(notification);
                        await NotificationManager.ClearNotification(notification, userAccountEntity);
                    }
                }
            }
            catch (Exception)
            {
                Debug.WriteLine("Failed to show toast/live tile notification");
            }
        }
        public static async void WebView_ScriptNotify(object sender, NotifyEventArgs e)
        {
            var webview      = sender as WebView;
            var threadEntity = Locator.ViewModels.ThreadPageVm.ForumThreadEntity;

            if (webview == null || threadEntity == null)
            {
                return;
            }

            try
            {
                string stringJson = e.Value;
                var    command    = JsonConvert.DeserializeObject <ThreadCommand>(stringJson);
                switch (command.Command)
                {
                case "openLink":
                    await Windows.System.Launcher.LaunchUriAsync(new Uri(command.Id));

                    break;

                case "userProfile":
                    var navUser = new NavigateToUserProfilePageCommand();
                    navUser.Execute(Convert.ToInt64(command.Id));
                    break;

                case "downloadImage":
                    _url = command.Id;
                    var message = string.Format("Do you want to download this image?{0}{1}", Environment.NewLine, command.Id);
                    var msgBox  =
                        new MessageDialog(message,
                                          "Download Image");
                    var okButton = new UICommand("Yes")
                    {
                        Invoked = PictureOkButtonClick
                    };
                    var cancelButton = new UICommand("No")
                    {
                        Invoked = PictureCancelButtonClick
                    };
                    msgBox.Commands.Add(okButton);
                    msgBox.Commands.Add(cancelButton);
                    await msgBox.ShowAsync();

                    break;

                case "showPosts":
                    await webview.InvokeScriptAsync("ShowHiddenPosts", new[] { string.Empty });

                    break;

                case "profile":
                    //Frame.Navigate(typeof(UserProfileView), command.Id);
                    break;

                case "openPost":
                    var addIgnoredUserPostCommand = new AddIgnoredUserPostCommand();
                    var test = new WebViewCollection()
                    {
                        PostId  = command.Id,
                        WebView = webview
                    };
                    try
                    {
                        addIgnoredUserPostCommand.Execute(test);
                    }
                    catch (Exception ex)
                    {
                        AwfulDebugger.SendMessageDialogAsync("Error getting post", ex);
                    }
                    break;

                case "post_history":
                    //Frame.Navigate(typeof(UserPostHistoryPage), command.Id);
                    break;

                case "rap_sheet":
                    //Frame.Navigate(typeof(RapSheetView), command.Id);
                    break;

                case "quote":
                    var navigateToNewReplyViaQuoteCommand = new NavigateToNewReplyViaQuoteCommand();
                    navigateToNewReplyViaQuoteCommand.Execute(command.Id);
                    break;

                case "edit":
                    var navigateToEditPostPageCommand = new NavigateToEditPostPageCommand();
                    navigateToEditPostPageCommand.Execute(command.Id);
                    break;

                case "scrollToPost":
                    try
                    {
                        if (command.Id != null)
                        {
                            await webview.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", command.Id) });
                        }
                        else if (!string.IsNullOrEmpty(threadEntity.ScrollToPostString))
                        {
                            webview.InvokeScriptAsync("ScrollToDiv", new[] { threadEntity.ScrollToPostString });
                        }
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("Could not scroll to post...");
                    }
                    break;

                case "markAsLastRead":
                    try
                    {
                        var threadManager = new ThreadManager();
                        await threadManager.MarkPostAsLastReadAs(Locator.ViewModels.ThreadPageVm.ForumThreadEntity, Convert.ToInt32(command.Id));

                        int nextPost = Convert.ToInt32(command.Id) + 1;
                        await webview.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) });

                        NotifyStatusTile.CreateToastNotification("Last Read", "Post marked as last read.");
                    }
                    catch (Exception ex)
                    {
                        AwfulDebugger.SendMessageDialogAsync("Could not mark thread as last read", ex);
                    }
                    break;

                case "setFont":
                    if (_localSettings.Values.ContainsKey("zoomSize"))
                    {
                        _zoomSize = Convert.ToInt32(_localSettings.Values["zoomSize"]);
                        webview.InvokeScriptAsync("ResizeWebviewFont", new[] { _zoomSize.ToString() });
                    }
                    else
                    {
                        // _zoomSize = 20;
                    }
                    break;

                case "openThread":
                    var query = Extensions.ParseQueryString(command.Id);
                    if (query.ContainsKey("action") && query["action"].Equals("showPost"))
                    {
                        //var postManager = new PostManager();
                        //var html = await postManager.GetPost(Convert.ToInt32(query["postid"]));
                        return;
                    }
                    Locator.ViewModels.ThreadPageVm.IsLoading = true;
                    var newThreadEntity = new ForumThreadEntity()
                    {
                        Location          = command.Id,
                        ImageIconLocation = "/Assets/ThreadTags/noicon.png"
                    };
                    Locator.ViewModels.ThreadPageVm.ForumThreadEntity = newThreadEntity;

                    await Locator.ViewModels.ThreadPageVm.GetForumPostsAsync();

                    var tabManager = new MainForumsDatabase();
                    var test2      = await tabManager.DoesTabExist(newThreadEntity);

                    if (!test2)
                    {
                        await tabManager.AddThreadToTabListAsync(newThreadEntity);
                    }
                    Locator.ViewModels.ThreadPageVm.LinkedThreads.Add(newThreadEntity);
                    break;

                default:
                    var msgDlg = new MessageDialog("Not working yet!")
                    {
                        DefaultCommandIndex = 1
                    };
                    await msgDlg.ShowAsync();

                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Exemplo n.º 5
0
        private async void WebView_ScriptNotify(object sender, NotifyEventArgs e)
        {
            try
            {
                string stringJson = e.Value;
                var    command    = JsonConvert.DeserializeObject <ReplyView.ThreadCommand>(stringJson);
                switch (command.Command)
                {
                case "profile":
                    Frame.Navigate(typeof(UserProfileView), command.Id);
                    break;

                case "openPost":
                    break;

                case "post_history":
                    Frame.Navigate(typeof(UserPostHistoryPage), command.Id);
                    break;

                case "rap_sheet":
                    Frame.Navigate(typeof(RapSheetView), command.Id);
                    break;

                case "quote":
                    Frame.Navigate(typeof(ReplyView), command.Id);
                    break;

                case "edit":
                    Frame.Navigate(typeof(EditReplyPage), command.Id);
                    break;

                case "scrollToPost":
                    if (command.Id != null)
                    {
                        await ThreadFullView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", command.Id) });

                        await ThreadSnapView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", command.Id) });
                    }
                    else if (!string.IsNullOrEmpty(_vm.ForumThreadEntity.ScrollToPostString))
                    {
                        ThreadFullView.InvokeScriptAsync("ScrollToDiv", new[] { _vm.ForumThreadEntity.ScrollToPostString });
                        ThreadSnapView.InvokeScriptAsync("ScrollToDiv", new[] { _vm.ForumThreadEntity.ScrollToPostString });
                    }
                    break;

                case "markAsLastRead":
                    await _threadManager.MarkPostAsLastRead(_forumThread, Convert.ToInt32(command.Id));

                    int nextPost = Convert.ToInt32(command.Id) + 1;
                    await ThreadFullView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) });

                    await ThreadSnapView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) });

                    NotifyStatusTile.CreateToastNotification("Post marked as last read! Now smash this computer and live your life!");
                    break;

                case "setFont":
                    if (_localSettings.Values.ContainsKey("zoomSize"))
                    {
                        _zoomSize = Convert.ToInt32(_localSettings.Values["zoomSize"]);
                        ThreadFullView.InvokeScriptAsync("ResizeWebviewFont", new[] { _zoomSize.ToString() });
                        ThreadSnapView.InvokeScriptAsync("ResizeWebviewFont", new[] { _zoomSize.ToString() });
                    }
                    else
                    {
                        // _zoomSize = 20;
                    }
                    break;

                case "openThread":
                    var query = Extensions.ParseQueryString(command.Id);
                    if (query.ContainsKey("action") && query["action"].Equals("showPost"))
                    {
                        var postManager = new PostManager();
                        var html        = await postManager.GetPost(Convert.ToInt32(query["postid"]));

                        return;
                    }
                    var threadManager = new ThreadManager();
                    var threadEntity  = new ForumThreadEntity();
                    var thread        = await threadManager.GetThread(threadEntity, command.Id);

                    if (thread == null)
                    {
                        var error = new MessageDialog("Specified post was not found in the live forums.")
                        {
                            DefaultCommandIndex = 1
                        };
                        await error.ShowAsync();

                        break;
                    }
                    string jsonObjectString = JsonConvert.SerializeObject(threadEntity);
                    Frame.Navigate(typeof(ThreadPage), jsonObjectString);
                    break;

                default:
                    var msgDlg = new MessageDialog("Not working yet!")
                    {
                        DefaultCommandIndex = 1
                    };
                    await msgDlg.ShowAsync();

                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }