示例#1
0
        internal async void Navigate(DiscordChannel channel, NavigationTransitionInfo info = null)
        {
            try
            {
                CloseSplitPane();

                unreadDms.SelectionChanged  -= UnreadDms_SelectionChanged;
                guildsList.SelectionChanged -= GuildsList_SelectionChanged;

                guildsList.SelectedIndex = -1;
                unreadDms.SelectedIndex  = -1;
                friendsItem.IsSelected   = false;

                if (channel == null)
                {
                    friendsItem.IsSelected = true;
                    sidebarFrame.Navigate(typeof(DMChannelsPage), channel, new DrillInNavigationTransitionInfo());
                    Frame.Navigate(typeof(FriendsPage));

                    return;
                }

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

                if (channel is DiscordDmChannel dm)
                {
                    unreadDms.SelectedItem = dm;
                    friendsItem.IsSelected = true;

                    if (!(sidebarFrame.Content is DMChannelsPage))
                    {
                        sidebarFrame.Navigate(typeof(DMChannelsPage), channel, new DrillInNavigationTransitionInfo());
                    }
                }
                else if (channel.Guild != null)
                {
                    guildsList.SelectedIndex = _guilds.IndexOf(channel.Guild);

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

                if (channel.Type == ChannelType.Voice)
                {
                    var voice = await VoiceViewModel.StartNewAsync(channel);

                    return;
                }

                if (!(Frame.Content is ChannelPage cPage) || cPage.ViewModel?.Channel?.Id != channel.Id)
                {
                    if (channel.IsNSFW)
                    {
                        if (await WindowsHelloManager.VerifyAsync(Constants.VERIFY_NSFW, "Verify your identity to access this channel"))
                        {
                            if (!App.RoamingSettings.Read($"NSFW_{channel.Id}", false) || !App.RoamingSettings.Read($"NSFW_All", false))
                            {
                                Frame.Navigate(typeof(ChannelWarningPage), channel, info ?? new SlideNavigationTransitionInfo());
                            }
                            else
                            {
                                Frame.Navigate(typeof(ChannelPage), channel, info ?? new SlideNavigationTransitionInfo());
                            }
                        }
                    }
                    else
                    {
                        Frame.Navigate(typeof(ChannelPage), channel, info ?? new SlideNavigationTransitionInfo());
                    }
                }
            }
            finally
            {
                unreadDms.SelectionChanged  += UnreadDms_SelectionChanged;
                guildsList.SelectionChanged += GuildsList_SelectionChanged;
            }
        }
        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);
                }
            }
        }