From 3ef3e5caa65458e595e2303358322626c7da1dda Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Tue, 23 May 2023 08:51:02 +0200 Subject: Add numerous new things --- MatrixRoomUtils.Core/Interfaces/IHomeServer.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'MatrixRoomUtils.Core/Interfaces') diff --git a/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs b/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs index c6d788c..8fb8b2c 100644 --- a/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs +++ b/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs @@ -15,6 +15,18 @@ public class IHomeServer public async Task ResolveHomeserverFromWellKnown(string homeserver) { + var res = await _resolveHomeserverFromWellKnown(homeserver); + if(!res.StartsWith("http")) res = "https://" + res; + if(res.EndsWith(":443")) res = res.Substring(0, res.Length - 4); + return res; + } + private async Task _resolveHomeserverFromWellKnown(string homeserver) + { + if (RuntimeCache.HomeserverResolutionCache.Count == 0) + { + Console.WriteLine("No cached homeservers, resolving..."); + await Task.Delay(Random.Shared.Next(1000, 5000)); + } if (RuntimeCache.HomeserverResolutionCache.ContainsKey(homeserver)) { if (RuntimeCache.HomeserverResolutionCache[homeserver].ResolutionTime < DateTime.Now.AddHours(1)) @@ -22,6 +34,7 @@ public class IHomeServer Console.WriteLine($"Found cached homeserver: {RuntimeCache.HomeserverResolutionCache[homeserver].Result}"); return RuntimeCache.HomeserverResolutionCache[homeserver].Result; } + Console.WriteLine($"Cached homeserver expired, removing: {RuntimeCache.HomeserverResolutionCache[homeserver].Result}"); RuntimeCache.HomeserverResolutionCache.Remove(homeserver); } //throw new NotImplementedException(); @@ -95,4 +108,8 @@ public class IHomeServer _profileCache[mxid] = profile; return profile; } + public async Task ResolveMediaUri(string mxc) + { + return mxc.Replace("mxc://", $"{FullHomeServerDomain}/_matrix/media/r0/download/"); + } } \ No newline at end of file -- cgit 1.5.1