Ejemplo n.º 1
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                App.Discord.MessageCreated += Notification_MessageCreated;

                UpdateTitleBar();
                CheckSettingsPane();

                _loaded = true;

                this.FindParent <MainPage>().HideConnectingOverlay();

                var service = DiscordNavigationService.GetForCurrentView();

                if (_args != null && _args.ChannelId != 0)
                {
                    var channel = await App.Discord.GetChannelAsync(_args.ChannelId);

                    await service.NavigateAsync(channel);
                }
                else
                {
                    Model.IsFriendsSelected = true;
                    SidebarFrame.Navigate(typeof(DMChannelsPage));
                    MainFrame.Navigate(typeof(FriendsPage));
                }

                if (_args?.ThemeLoadException != null)
                {
                    var message = App.Discord.CreateMockMessage(
                        $"We had some trouble loading your selected themes, so we disabled them for this launch. For more information, see settings.",
                        App.Discord.CreateMockUser("Unicord", "CORD"));
                    ShowNotification(message);
                }

                var possibleConnection = await VoiceConnectionModel.FindExistingConnectionAsync();

                if (possibleConnection != null)
                {
                    (DataContext as DiscordPageModel).VoiceModel = possibleConnection;
                }

                await ContactListManager.UpdateContactsListAsync();
            }
            catch (Exception ex)
            {
                await UIUtilities.ShowErrorDialogAsync("An error has occured.", ex.Message);
            }
        }
        internal async Task NavigateAsync(DiscordChannel channel, bool skipPreviousDm = false)
        {
            var page = _page.MainFrame.Content as ChannelPage;

            if (channel == null)
            {
                _pageModel.SelectedGuild     = null;
                _pageModel.IsFriendsSelected = true;

                if (_pageModel.PreviousDM != null && (page?.ViewModel.Channel != _pageModel.PreviousDM) && !skipPreviousDm)
                {
                    _pageModel.SelectedDM = _pageModel.PreviousDM;
                    _page.MainFrame.Navigate(typeof(ChannelPage), _pageModel.PreviousDM);
                    _page.SidebarFrame.Navigate(typeof(DMChannelsPage), _pageModel.PreviousDM, new DrillInNavigationTransitionInfo());
                }
                else if (page != null || !(_page.SidebarFrame.Content is DMChannelsPage))
                {
                    _pageModel.PreviousDM = null;
                    _page.MainFrame.Navigate(typeof(FriendsPage));
                    _page.SidebarFrame.Navigate(typeof(DMChannelsPage), null, new DrillInNavigationTransitionInfo());
                }

                return;
            }

            if (_pageModel.CurrentChannel != channel && channel.Type != ChannelType.Voice)
            {
                _pageModel.Navigating = true;
                _page.CloseSplitPane(); // pane service?

                _pageModel.SelectedGuild     = null;
                _pageModel.SelectedDM        = null;
                _pageModel.IsFriendsSelected = false;

                if (await WindowManager.ActivateOtherWindow(channel))
                {
                    return;
                }

                if (channel is DiscordDmChannel dm)
                {
                    _pageModel.SelectedDM        = dm;
                    _pageModel.PreviousDM        = dm;
                    _pageModel.IsFriendsSelected = true;
                    _page.SidebarFrame.Navigate(typeof(DMChannelsPage), channel, new DrillInNavigationTransitionInfo());
                }
                else if (channel.Guild != null)
                {
                    _pageModel.SelectedGuild = channel.Guild;

                    if (!(_page.SidebarFrame.Content is GuildChannelListPage p) || p.Guild != channel.Guild)
                    {
                        _page.SidebarFrame.Navigate(typeof(GuildChannelListPage), channel.Guild, new DrillInNavigationTransitionInfo());
                    }
                }

                if (channel.IsNSFW)
                {
                    var loader = ResourceLoader.GetForViewIndependentUse();
                    if (await WindowsHelloManager.VerifyAsync(Constants.VERIFY_NSFW, loader.GetString("VerifyNSFWDisplayReason")))
                    {
                        if (App.RoamingSettings.Read($"NSFW_{channel.Id}", false) == false || !App.RoamingSettings.Read($"NSFW_All", false))
                        {
                            _page.MainFrame.Navigate(typeof(ChannelWarningPage), channel /*, info ?? new SlideNavigationTransitionInfo()*/);
                        }
                        else
                        {
                            _page.MainFrame.Navigate(typeof(ChannelPage), channel /*, info ?? new SlideNavigationTransitionInfo()*/);
                        }
                    }
                }
                else
                {
                    _page.MainFrame.Navigate(typeof(ChannelPage), channel /*, info ?? new SlideNavigationTransitionInfo()*/);
                }

                _pageModel.Navigating = false;
            }
            else if (channel?.Type == ChannelType.Voice)
            {
                try
                {
                    var voice = new VoiceConnectionModel(channel);
                    _pageModel.VoiceModel = voice;
                    await voice.ConnectAsync();
                }
                catch (Exception ex)
                {
                    await UIUtilities.ShowErrorDialogAsync("Failed to connect to voice!", ex.Message);
                }
            }
        }
Ejemplo n.º 3
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            if (App.Discord == null)
            {
                return; // im not 100% sure why this gets called on logout but it does so
            }
            Analytics.TrackEvent("DiscordPage_Loaded");

            try
            {
                App.Discord.MessageCreated += Notification_MessageCreated;

                UpdateTitleBar();
                CheckSettingsPane();

                _loaded = true;

                this.FindParent <MainPage>().HideConnectingOverlay();

                var service = DiscordNavigationService.GetForCurrentView();

                if (_args != null && _args.ChannelId != 0 && App.Discord.TryGetCachedChannel(_args.ChannelId, out var channel))
                {
                    Analytics.TrackEvent("DiscordPage_NavigateToSpecifiedChannel");
                    await service.NavigateAsync(channel);
                }
                else
                {
                    Analytics.TrackEvent("DiscordPage_NavigateToFriendsPage");
                    Model.IsFriendsSelected = true;
                    SidebarFrame.Navigate(typeof(DMChannelsPage));
                    MainFrame.Navigate(typeof(FriendsPage));
                }

                if (_args?.ThemeLoadException != null)
                {
                    Analytics.TrackEvent("DiscordPage_ThemeErrorMessageShown");

                    var message = App.Discord.CreateMockMessage(
                        $"We had some trouble loading your selected themes, so we disabled them for this launch. For more information, see settings.",
                        App.Discord.CreateMockUser("Unicord", "CORD"));
                    ShowNotification(message);
                }

                //var helper = SwipeOpenService.GetForCurrentView();
                //helper.AddAdditionalElement(SwipeHelper);

                var notificationService = BackgroundNotificationService.GetForCurrentView();
                await notificationService.StartupAsync();

                var possibleConnection = await VoiceConnectionModel.FindExistingConnectionAsync();

                if (possibleConnection != null)
                {
                    (DataContext as DiscordPageModel).VoiceModel = possibleConnection;
                }

                await ContactListManager.UpdateContactsListAsync();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                await UIUtilities.ShowErrorDialogAsync("An error has occured.", ex.Message);
            }
        }