From b6ae292e176a746710df5ba731bc3761d628c608 Mon Sep 17 00:00:00 2001 From: Thomas May Date: Sun, 24 Nov 2024 21:47:28 +0000 Subject: [PATCH 1/5] Make login more sticky --- UniSky/ViewModels/HomeViewModel.cs | 22 +++++++++++++++++++--- UniSky/ViewModels/LoginViewModel.cs | 9 +++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/UniSky/ViewModels/HomeViewModel.cs b/UniSky/ViewModels/HomeViewModel.cs index 5a55227..0d61124 100644 --- a/UniSky/ViewModels/HomeViewModel.cs +++ b/UniSky/ViewModels/HomeViewModel.cs @@ -6,6 +6,7 @@ using FishyFlip.Events; using FishyFlip.Lexicon.App.Bsky.Actor; using FishyFlip.Lexicon.App.Bsky.Notification; +using FishyFlip.Lexicon.Com.Atproto.Server; using FishyFlip.Models; using FishyFlip.Tools; using Microsoft.Extensions.Logging; @@ -132,10 +133,25 @@ private async Task LoadAsync() try { - var session = await protocol.AuthenticateWithPasswordSessionAsync(sessionModel.Session); - var refreshSession = await protocol.RefreshAuthSessionAsync(); + // to ensure the session gets refreshed properly: + // - initially authenticate the client with the refresh token + // - refresh the sesssion + // - reauthenticate with the new session - await protocol.AuthenticateWithPasswordSessionAsync(refreshSession); + var sessionRefresh = sessionModel.Session.Session; + var authSessionRefresh = new AuthSession( + new Session(sessionRefresh.Did, sessionRefresh.DidDoc, sessionRefresh.Handle, null, sessionRefresh.RefreshJwt, sessionRefresh.RefreshJwt)); + + var session = await protocol.AuthenticateWithPasswordSessionAsync(authSessionRefresh); + var refreshSession = (await protocol.RefreshSessionAsync()) + .HandleResult(); + + var session2 = await protocol.AuthenticateWithPasswordSessionAsync( + new AuthSession( + new Session(refreshSession.Did, refreshSession.DidDoc, refreshSession.Handle, null, refreshSession.AccessJwt, refreshSession.RefreshJwt))); + + if (session2 == null) + throw new InvalidOperationException("Authentication failed!"); protocolService.SetProtocol(protocol); } diff --git a/UniSky/ViewModels/LoginViewModel.cs b/UniSky/ViewModels/LoginViewModel.cs index 67c7b74..cd4f29f 100644 --- a/UniSky/ViewModels/LoginViewModel.cs +++ b/UniSky/ViewModels/LoginViewModel.cs @@ -5,7 +5,9 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using FishyFlip; +using FishyFlip.Lexicon.Com.Atproto.Server; using FishyFlip.Models; +using FishyFlip.Tools; using UniSky.Extensions; using UniSky.Helpers; using UniSky.Models; @@ -58,9 +60,12 @@ private async Task Login() .WithInstanceUrl(new Uri(Host)); using var protocol = builder.Build(); - var session = await protocol.AuthenticateWithPasswordAsync(Username, Password, CancellationToken.None) - .ConfigureAwait(false); + var createSession = (await protocol.CreateSessionAsync(Username, Password, cancellationToken: CancellationToken.None) + .ConfigureAwait(false)) + .HandleResult(); + + var session = new Session(createSession.Did, createSession.DidDoc, createSession.Handle, createSession.Email, createSession.AccessJwt, createSession.RefreshJwt); var loginModel = this.loginService.SaveLogin(normalisedHost, Username, Password); var sessionModel = new SessionModel(true, normalisedHost, session); From 3fb3bb6272a075122a42fa024378d59b71d2fcfc Mon Sep 17 00:00:00 2001 From: Thomas May Date: Sun, 24 Nov 2024 21:50:13 +0000 Subject: [PATCH 2/5] Update Package.appxmanifest --- UniSky/Package.appxmanifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UniSky/Package.appxmanifest b/UniSky/Package.appxmanifest index b443f75..d7b999f 100644 --- a/UniSky/Package.appxmanifest +++ b/UniSky/Package.appxmanifest @@ -10,7 +10,7 @@ + Version="1.0.116.0" /> From 369038d9469daffe011643a559c7f67542a2c54c Mon Sep 17 00:00:00 2001 From: Thomas May Date: Sun, 24 Nov 2024 21:56:27 +0000 Subject: [PATCH 3/5] Make sure we're saving logins correctly --- UniSky/ViewModels/HomeViewModel.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/UniSky/ViewModels/HomeViewModel.cs b/UniSky/ViewModels/HomeViewModel.cs index 0d61124..7abceea 100644 --- a/UniSky/ViewModels/HomeViewModel.cs +++ b/UniSky/ViewModels/HomeViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.DependencyInjection; using CommunityToolkit.Mvvm.Input; using FishyFlip; using FishyFlip.Events; @@ -142,17 +143,21 @@ private async Task LoadAsync() var authSessionRefresh = new AuthSession( new Session(sessionRefresh.Did, sessionRefresh.DidDoc, sessionRefresh.Handle, null, sessionRefresh.RefreshJwt, sessionRefresh.RefreshJwt)); - var session = await protocol.AuthenticateWithPasswordSessionAsync(authSessionRefresh); - var refreshSession = (await protocol.RefreshSessionAsync()) + await protocol.AuthenticateWithPasswordSessionAsync(authSessionRefresh); + var refreshSession = (await protocol.RefreshSessionAsync().ConfigureAwait(false)) .HandleResult(); - var session2 = await protocol.AuthenticateWithPasswordSessionAsync( - new AuthSession( - new Session(refreshSession.Did, refreshSession.DidDoc, refreshSession.Handle, null, refreshSession.AccessJwt, refreshSession.RefreshJwt))); + var authSession2 = new AuthSession( + new Session(refreshSession.Did, refreshSession.DidDoc, refreshSession.Handle, null, refreshSession.AccessJwt, refreshSession.RefreshJwt)); + var session2 = await protocol.AuthenticateWithPasswordSessionAsync(authSession2).ConfigureAwait(false); if (session2 == null) throw new InvalidOperationException("Authentication failed!"); + var sessionModel2 = new SessionModel(true, sessionModel.Service, authSession2.Session, authSession2); + var sessionService = Ioc.Default.GetRequiredService(); + sessionService.SaveSession(sessionModel2); + protocolService.SetProtocol(protocol); } catch (Exception ex) From 4e27977bc18efc14a0f77dab989e638449a9d707 Mon Sep 17 00:00:00 2001 From: Thomas May Date: Sun, 24 Nov 2024 23:36:06 +0000 Subject: [PATCH 4/5] Add F5 to refresh --- UniSky/Pages/FeedsPage.xaml | 12 ++++++++++-- UniSky/Pages/FeedsPage.xaml.cs | 8 ++++++++ UniSky/ViewModels/Feeds/FeedItemCollection.cs | 5 +++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/UniSky/Pages/FeedsPage.xaml b/UniSky/Pages/FeedsPage.xaml index f8c1ecb..abe0a57 100644 --- a/UniSky/Pages/FeedsPage.xaml +++ b/UniSky/Pages/FeedsPage.xaml @@ -5,14 +5,22 @@ xmlns:local="using:UniSky.Pages" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:w1709="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 5)" + xmlns:w1803="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 6)" xmlns:viewmodels="using:UniSky.ViewModels" xmlns:mux="using:Microsoft.UI.Xaml.Controls" xmlns:feeds="using:UniSky.ViewModels.Feeds" - xmlns:extensions="using:UniSky.Extensions" + xmlns:extensions="using:UniSky.Extensions" mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=viewmodels:FeedsViewModel}" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" - NavigationCacheMode="Enabled"> + NavigationCacheMode="Enabled" + w1803:KeyboardAcceleratorPlacementMode="Hidden"> + + + this.Add(new PostViewModel(item)); }); - if (posts.Count == 0) + if (posts.Count == 0 || string.IsNullOrWhiteSpace(this.cursor)) HasMoreItems = false; return new LoadMoreItemsResult() { Count = (uint)posts.Count }; From 3bec07e7cb65a2ae23b9d761c1990c315371e0b2 Mon Sep 17 00:00:00 2001 From: Thomas May Date: Mon, 25 Nov 2024 00:00:10 +0000 Subject: [PATCH 5/5] Fix AccentButton styles --- UniSky/Pages/LoginPage.xaml | 3 +- UniSky/Pages/ProfilePage.xaml | 1 - UniSky/Templates/ButtonStyles.xaml | 87 ++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) diff --git a/UniSky/Pages/LoginPage.xaml b/UniSky/Pages/LoginPage.xaml index d5a7762..057cc33 100644 --- a/UniSky/Pages/LoginPage.xaml +++ b/UniSky/Pages/LoginPage.xaml @@ -139,8 +139,7 @@