Add numerous new things
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
|