From 9fcc6a46f339d10ca5e4c019a6c72f6ac061d2fb Mon Sep 17 00:00:00 2001 From: Thomas May Date: Sun, 29 Sep 2024 22:29:44 +0100 Subject: [PATCH] Incomplete fixes for contact activation --- Unicord.Universal/App.xaml.cs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/Unicord.Universal/App.xaml.cs b/Unicord.Universal/App.xaml.cs index 971a94b..841220e 100644 --- a/Unicord.Universal/App.xaml.cs +++ b/Unicord.Universal/App.xaml.cs @@ -5,6 +5,7 @@ using System.Runtime.InteropServices.WindowsRuntime; using System.Threading; using System.Threading.Tasks; +using System.Web; using DSharpPlus; using DSharpPlus.AsyncEvents; using DSharpPlus.Entities; @@ -143,6 +144,25 @@ private void OnProtocolActivatedAsync(ProtocolActivatedEventArgs protocol) if (protocol.Uri.IsAbsoluteUri) Analytics.TrackEvent("Unicord_LaunchForProtocol", new Dictionary() { ["protocol"] = protocol.Uri.GetLeftPart(UriPartial.Authority) }); + if (protocol.Uri.Scheme == "ms-ipmessaging") + { + var queryString = HttpUtility.ParseQueryString(protocol.Uri.Query); + var ids = queryString.GetValues("ContactRemoteIds").FirstOrDefault(); + if (ids != null) + { + var id = ulong.Parse(ids.Split(',')[0].Split('_')[1]); + if (!(Window.Current.Content is Frame rootFrame)) + { + rootFrame = new Frame(); + Window.Current.Content = rootFrame; + } + + rootFrame.Navigate(typeof(MainPage), new MainPageArgs() { UserId = id, IsUriActivation = true }); + Window.Current.Activate(); + return; + } + } + if (protocol.Uri.AbsolutePath.Trim('/').StartsWith("channels")) { var path = protocol.Uri.AbsolutePath.Split('/').Skip(1).ToArray(); @@ -154,15 +174,13 @@ private void OnProtocolActivatedAsync(ProtocolActivatedEventArgs protocol) Window.Current.Content = rootFrame; } - rootFrame.Navigate(typeof(MainPage), new MainPageArgs() { ChannelId = channel, FullFrame = false, IsUriActivation = true }); + rootFrame.Navigate(typeof(MainPage), new MainPageArgs() { ChannelId = channel, IsUriActivation = true }); Window.Current.Activate(); return; } } - else - { - OnLaunched(false, ""); - } + + OnLaunched(false, ""); } private static async Task OnContactPanelActivated(ContactPanelActivatedEventArgs task)