From 00ba74458ed7707e676c2b2a3345c270b97db80b Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Wed, 22 Nov 2023 14:40:35 +0900 Subject: [PATCH] Fix --- src/FishyFlip/ATProtocol.cs | 26 ++++++++++++++++++++++++++ src/FishyFlip/SessionManager.cs | 23 +---------------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/FishyFlip/ATProtocol.cs b/src/FishyFlip/ATProtocol.cs index 6db417db..a8a4d30d 100644 --- a/src/FishyFlip/ATProtocol.cs +++ b/src/FishyFlip/ATProtocol.cs @@ -230,6 +230,32 @@ internal void OnSubscribedRepoMessageInternal(SubscribedRepoEventArgs e) /// . internal void OnUserLoggedIn(Session session) { + if (this.options.UseServiceEndpointUponLogin) + { + var logger = this.options?.Logger; + var serviceUrl = session.DidDoc?.Service?.FirstOrDefault()?.ServiceEndpoint; + if (string.IsNullOrEmpty(serviceUrl)) + { + logger?.LogWarning($"UseServiceEndpointUponLogin enabled, but session missing Service Endpoint."); + } + else + { + var result = Uri.TryCreate(serviceUrl, UriKind.Absolute, out Uri? uriResult); + if (!result || uriResult is null) + { + logger?.LogWarning($"UseServiceEndpointUponLogin enabled, but session missing Service Endpoint."); + } + else + { + this.Options.Url = uriResult; + logger?.LogInformation($"UseServiceEndpointUponLogin enabled, switching to {uriResult}."); + this.Options.Session = session; + this.UpdateOptions(this.Options); + return; + } + } + } + if (this.sessionManager is null) { this.sessionManager = new SessionManager(this); diff --git a/src/FishyFlip/SessionManager.cs b/src/FishyFlip/SessionManager.cs index cc6753fb..4def28d4 100644 --- a/src/FishyFlip/SessionManager.cs +++ b/src/FishyFlip/SessionManager.cs @@ -93,34 +93,13 @@ internal void SetSession(Session session) this.UpdateBearerToken(session); this.logger?.LogDebug($"Session set, {session.Did}"); + if (!this.protocol.Options.AutoRenewSession) { this.logger?.LogDebug("AutoRenewSession is disabled."); return; } - if (this.protocol.Options.UseServiceEndpointUponLogin) - { - var serviceUrl = session.DidDoc?.Service?.FirstOrDefault()?.ServiceEndpoint; - if (!string.IsNullOrEmpty(serviceUrl)) - { - this.logger?.LogWarning($"UseServiceEndpointUponLogin enabled, but session missing Service Endpoint."); - } - else - { - var result = Uri.TryCreate(serviceUrl, UriKind.Absolute, out Uri? uriResult); - if (!result || uriResult is null) - { - this.logger?.LogWarning($"UseServiceEndpointUponLogin enabled, but session missing Service Endpoint."); - } - else - { - this.protocol.Options.Url = uriResult; - this.logger?.LogInformation($"UseServiceEndpointUponLogin enabled, switching to {uriResult}."); - } - } - } - this.logger?.LogDebug("AutoRenewSession is enabled."); this.timer ??= new System.Timers.Timer();