From a98f16f1aaa72aa68278420a61d8ce897639416f Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Wed, 11 Oct 2023 15:52:28 +0200 Subject: Added options to skip inviting already invited/joined/left users, added option to join room if it already exists when trying to create --- LibMatrix/RoomTypes/GenericRoom.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'LibMatrix/RoomTypes/GenericRoom.cs') diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs index 37006af..1c0633c 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs @@ -232,7 +232,9 @@ public class GenericRoom { $"/_matrix/client/v3/rooms/{RoomId}/redact/{eventToRedact}/{Guid.NewGuid()}", data)).Content.ReadFromJsonAsync())!; } - public async Task InviteUserAsync(string userId, string? reason = null) { + public async Task InviteUserAsync(string userId, string? reason = null, bool skipExisting = true) { + if (skipExisting && await GetStateAsync("m.room.member", userId) is not null) + return; await _httpClient.PostAsJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/invite", new UserIdAndReason(userId, reason)); } @@ -265,8 +267,8 @@ public class GenericRoom { #endregion - public async Task InviteUsersAsync(IEnumerable users) { - var tasks = users.Select(x=>InviteUserAsync(x)).ToList(); + public async Task InviteUsersAsync(IEnumerable users, string? reason = null, bool skipExisting = true) { + var tasks = users.Select(x => InviteUserAsync(x, reason, skipExisting)).ToList(); await Task.WhenAll(tasks); } } -- cgit 1.4.1