diff --git a/src/Clients/IUserClient.cs b/src/Clients/IUserClient.cs
index d99b999..8adba3e 100644
--- a/src/Clients/IUserClient.cs
+++ b/src/Clients/IUserClient.cs
@@ -238,5 +238,23 @@ public interface IUserClient
///
/// https://getstream.io/chat/docs/dotnet-csharp/query_users/?language=csharp/
Task QueryAsync(QueryUserOptions opts);
+
+ ///
+ /// Block user from sending 1x1 messages
+ ///
+ /// https://getstream.io/chat/docs/javascript/block_user/
+ Task BlockUserAsync(string targetId, string userID);
+
+ ///
+ /// Get list of blocked users by this user
+ ///
+ /// https://getstream.io/chat/docs/javascript/block_user/
+ Task GetBlockedUsersAsync(string userID);
+
+ ///
+ /// Unblock user
+ ///
+ /// https://getstream.io/chat/docs/javascript/block_user/
+ Task UnblockUserAsync(string targetId, string userID);
}
}
diff --git a/src/Clients/UserClient.cs b/src/Clients/UserClient.cs
index 27ccb0f..0c6fac8 100644
--- a/src/Clients/UserClient.cs
+++ b/src/Clients/UserClient.cs
@@ -147,6 +147,33 @@ public async Task MuteAsync(string targetId, string id)
user_id = id,
});
+ public async Task BlockUserAsync(string targetId, string userID)
+ => await ExecuteRequestAsync("users/block",
+ HttpMethod.POST,
+ HttpStatusCode.OK,
+ body: new
+ {
+ blocked_user_id = targetId,
+ user_id = userID,
+ });
+ public async Task UnblockUserAsync(string targetId, string userID)
+ => await ExecuteRequestAsync("users/unblock",
+ HttpMethod.POST,
+ HttpStatusCode.OK,
+ body: new
+ {
+ blocked_user_id = targetId,
+ user_id = userID,
+ });//$$
+ public async Task GetBlockedUsersAsync(string userID)
+ => await ExecuteRequestAsync("users/block",
+ HttpMethod.GET,
+ HttpStatusCode.OK,
+ queryParams: new List>
+ {
+ new KeyValuePair("user_id", userID),
+ });
+
public async Task UnmuteAsync(string targetId, string id)
=> await ExecuteRequestAsync("moderation/unmute",
HttpMethod.POST,
diff --git a/src/Models/BlockUser.cs b/src/Models/BlockUser.cs
new file mode 100644
index 0000000..65ac573
--- /dev/null
+++ b/src/Models/BlockUser.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using Newtonsoft.Json;
+
+namespace StreamChat.Models
+{
+ public class BlockUserResponse : ApiResponse
+ {
+ public string BlockedByUserID { get; set; }
+ public string BlockedUserID { get; set; }
+ public string CreatedAt { get; set; }
+ }
+
+ public class GetBlockedUsersResponse : ApiResponse
+ {
+ [JsonProperty("blocks")]
+ public Blocks[] Blocks { get; set; }
+ }
+
+ public class Blocks
+ {
+ [JsonProperty("user")]
+ public User BlockedByUser { get; set; }
+
+ [JsonProperty("user_id")]
+ public string BlockedByUserID { get; set; }
+
+ [JsonProperty("blocked_user")]
+ public User BlockedUser { get; set; }
+
+ [JsonProperty("blocked_user_id")]
+ public string BlockedUserID { get; set; }
+
+ [JsonProperty("created_at")]
+ public DateTime CreatedAt { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/Models/User.cs b/src/Models/User.cs
index c43e757..b84b674 100644
--- a/src/Models/User.cs
+++ b/src/Models/User.cs
@@ -37,6 +37,7 @@ public class User : CustomDataBase
public DateTimeOffset? DeletedAt { get; set; }
public DateTimeOffset? DeactivatedAt { get; set; }
public bool? Online { get; set; }
+ public string[] BlockedUserIDs { get; set; }
}
public class OwnUser
diff --git a/tests/UserClientTests.cs b/tests/UserClientTests.cs
index 7bb860c..1b46896 100644
--- a/tests/UserClientTests.cs
+++ b/tests/UserClientTests.cs
@@ -271,6 +271,40 @@ public async Task TestMuteUserAsync()
muteResp.Mute.User.Id.Should().BeEquivalentTo(_user1.Id);
}
+ [Test]
+ public async Task TestBlockUserAsync()
+ {
+ var blockResp = await _userClient.BlockUserAsync(_user2.Id, _user1.Id);
+
+ blockResp.BlockedByUserID.Should().BeEquivalentTo(_user1.Id);
+ blockResp.BlockedUserID.Should().BeEquivalentTo(_user2.Id);
+
+ var getBlockResp = await _userClient.GetBlockedUsersAsync(_user1.Id);
+ getBlockResp.Blocks[0].BlockedUserID.Should().BeEquivalentTo(_user2.Id);
+ getBlockResp.Blocks[0].BlockedByUserID.Should().BeEquivalentTo(_user1.Id);
+ getBlockResp.Blocks[0].BlockedUser.Id.Should().BeEquivalentTo(_user2.Id);
+ getBlockResp.Blocks[0].BlockedByUser.Id.Should().BeEquivalentTo(_user1.Id);
+
+ var queryUsersResp = await _userClient.QueryAsync(QueryUserOptions.Default.WithFilter(new Dictionary
+ {
+ { "id", _user1.Id },
+ }));
+ queryUsersResp.Users.Should().NotBeEmpty();
+ queryUsersResp.Users[0].BlockedUserIDs[0].Should().BeEquivalentTo(_user2.Id);
+
+ await _userClient.UnblockUserAsync(_user2.Id, _user1.Id);
+
+ getBlockResp = await _userClient.GetBlockedUsersAsync(_user1.Id);
+ getBlockResp.Blocks.Length.Should().Be(0);
+
+ queryUsersResp = await _userClient.QueryAsync(QueryUserOptions.Default.WithFilter(new Dictionary
+ {
+ { "id", _user1.Id },
+ }));
+ queryUsersResp.Users.Should().NotBeEmpty();
+ queryUsersResp.Users[0].BlockedUserIDs.Length.Should().Be(0);
+ }
+
[Test]
public async Task TestUnmuteUserAsync()
{