about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-23 08:51:02 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-23 08:51:02 +0200
commit3ef3e5caa65458e595e2303358322626c7da1dda (patch)
tree6a60d401da8b5f906a423601ac4c135d44e896d1 /MatrixRoomUtils.Core/Interfaces/IHomeServer.cs
parentLocal changes (diff)
downloadMatrixUtils-3ef3e5caa65458e595e2303358322626c7da1dda.tar.xz
Add numerous new things
Diffstat (limited to 'MatrixRoomUtils.Core/Interfaces/IHomeServer.cs')
-rw-r--r--MatrixRoomUtils.Core/Interfaces/IHomeServer.cs17
1 files changed, 17 insertions, 0 deletions
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<string> 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<string> _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<string> ResolveMediaUri(string mxc)
+    {
+        return mxc.Replace("mxc://", $"{FullHomeServerDomain}/_matrix/media/r0/download/");
+    }
 }
\ No newline at end of file