about summary refs log tree commit diff
path: root/MiniUtils/Services/IgnoreListManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MiniUtils/Services/IgnoreListManager.cs')
-rw-r--r--MiniUtils/Services/IgnoreListManager.cs20
1 files changed, 20 insertions, 0 deletions
diff --git a/MiniUtils/Services/IgnoreListManager.cs b/MiniUtils/Services/IgnoreListManager.cs

index c42dd02..3b6dc96 100644 --- a/MiniUtils/Services/IgnoreListManager.cs +++ b/MiniUtils/Services/IgnoreListManager.cs
@@ -64,4 +64,24 @@ public class IgnoreListManager(AuthenticatedHomeserverGeneric homeserver) { Lock.Release(); return moved; } + + public async Task<int> AddList(string[] itemsToAdd) { + int added = 0; + await Lock.WaitAsync(); + var ignoreList = await homeserver.GetAccountDataOrNullAsync<IgnoredUserListEventContentWithDisabled>(IgnoredUserListEventContent.EventId) ?? new(); + foreach (var item in itemsToAdd) { + if (ignoreList.IgnoredUsers.ContainsKey(item)) continue; + if (ignoreList.DisabledIgnoredUsers.Remove(item, out var value)) { + ignoreList.IgnoredUsers.Add(item, value); + added++; + continue; + } + ignoreList.IgnoredUsers.Add(item, new()); + added++; + } + if (added > 0) + await homeserver.SetAccountDataAsync(IgnoredUserListEventContent.EventId, ignoreList); + Lock.Release(); + return added; + } } \ No newline at end of file