diff options
Diffstat (limited to '')
-rw-r--r-- | LibMatrix/Interfaces/IHomeServer.cs | 29 | ||||
-rw-r--r-- | LibMatrix/Interfaces/IStateEventType.cs | 5 | ||||
-rw-r--r-- | LibMatrix/Interfaces/Services/IStorageProvider.cs | 58 |
3 files changed, 92 insertions, 0 deletions
diff --git a/LibMatrix/Interfaces/IHomeServer.cs b/LibMatrix/Interfaces/IHomeServer.cs new file mode 100644 index 0000000..5e7e374 --- /dev/null +++ b/LibMatrix/Interfaces/IHomeServer.cs @@ -0,0 +1,29 @@ +using System.Net.Http.Json; +using LibMatrix.Extensions; +using LibMatrix.StateEventTypes.Spec; + +namespace LibMatrix.Interfaces; + +public class IHomeServer { + private readonly Dictionary<string, object> _profileCache = new(); + public string HomeServerDomain { get; set; } + public string FullHomeServerDomain { get; set; } + + public MatrixHttpClient _httpClient { get; set; } = new(); + + public async Task<ProfileResponseEventData> GetProfile(string mxid) { + if(mxid is null) throw new ArgumentNullException(nameof(mxid)); + if (_profileCache.ContainsKey(mxid)) { + if (_profileCache[mxid] is SemaphoreSlim s) await s.WaitAsync(); + if (_profileCache[mxid] is ProfileResponseEventData p) return p; + } + _profileCache[mxid] = new SemaphoreSlim(1); + + var resp = await _httpClient.GetAsync($"/_matrix/client/v3/profile/{mxid}"); + var data = await resp.Content.ReadFromJsonAsync<ProfileResponseEventData>(); + if (!resp.IsSuccessStatusCode) Console.WriteLine("Profile: " + data); + _profileCache[mxid] = data; + + return data; + } +} diff --git a/LibMatrix/Interfaces/IStateEventType.cs b/LibMatrix/Interfaces/IStateEventType.cs new file mode 100644 index 0000000..d80f22d --- /dev/null +++ b/LibMatrix/Interfaces/IStateEventType.cs @@ -0,0 +1,5 @@ +namespace LibMatrix.Interfaces; + +public interface IStateEventType { + +} diff --git a/LibMatrix/Interfaces/Services/IStorageProvider.cs b/LibMatrix/Interfaces/Services/IStorageProvider.cs new file mode 100644 index 0000000..519d8ed --- /dev/null +++ b/LibMatrix/Interfaces/Services/IStorageProvider.cs @@ -0,0 +1,58 @@ +namespace LibMatrix.Interfaces.Services; + +public interface IStorageProvider { + // save all children of a type with reflection + public Task SaveAllChildrenAsync<T>(string key, T value) { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement SaveAllChildren<T>(key, value)!"); + throw new NotImplementedException(); + } + + // load all children of a type with reflection + public Task<T?> LoadAllChildrenAsync<T>(string key) { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement LoadAllChildren<T>(key)!"); + throw new NotImplementedException(); + } + + + public Task SaveObjectAsync<T>(string key, T value) { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement SaveObject<T>(key, value)!"); + throw new NotImplementedException(); + } + + // load + public Task<T?> LoadObjectAsync<T>(string key) { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement LoadObject<T>(key)!"); + throw new NotImplementedException(); + } + + // check if exists + public Task<bool> ObjectExistsAsync(string key) { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement ObjectExists(key)!"); + throw new NotImplementedException(); + } + + // get all keys + public Task<List<string>> GetAllKeysAsync() { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement GetAllKeys()!"); + throw new NotImplementedException(); + } + + + // delete + public Task DeleteObjectAsync(string key) { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement DeleteObject(key)!"); + throw new NotImplementedException(); + } + + // save stream + public Task SaveStreamAsync(string key, Stream stream) { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement SaveStream(key, stream)!"); + throw new NotImplementedException(); + } + + // load stream + public Task<Stream?> LoadStreamAsync(string key) { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement LoadStream(key)!"); + throw new NotImplementedException(); + } +} |