using LibMatrix.Filters; using LibMatrix.Utilities; namespace LibMatrix.Homeservers.Extensions.NamedCaches; public class NamedFilterCache(AuthenticatedHomeserverGeneric hs) : NamedCache(hs, "gay.rory.libmatrix.named_cache.filter") { /// /// /// Allows passing a filter directly, or using a common filter. /// Substitutes @me for the user's ID. /// /// Filter name /// Filter to upload if not cached, otherwise defaults to common filters if that exists. /// /// public async Task GetOrSetValueAsync(string key, SyncFilter? filter = null) { var existingValue = await GetValueAsync(key); if (existingValue != null) { return existingValue; } if (filter is null) { if(CommonSyncFilters.FilterMap.TryGetValue(key, out var commonFilter)) { filter = commonFilter; } else { throw new ArgumentNullException(nameof(filter)); } } var filterUpload = await hs.UploadFilterAsync(filter); return await SetValueAsync(key, filterUpload.FilterId); } }