Skip to content

Commit aa90750

Browse files
author
Slava Bobik
committed
Added include_deactivated_users property
1 parent 013b2f5 commit aa90750

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

src/Clients/UserClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ public async Task<QueryUsersResponse> QueryAsync(QueryUserOptions opts)
229229
offset = opts.Offset,
230230
limit = opts.Limit,
231231
presence = opts.Presence,
232+
include_deactivated_users = opts.IncludeDeactivatedUsers,
232233
filter_conditions = opts.Filter,
233234
sort = opts.Sort,
234235
};

src/Models/QueryOptions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class QueryUserOptions
2626
public int Offset { get; set; } = DefaultOffset;
2727
public int Limit { get; set; } = DefaultLimit;
2828
public bool Presence { get; set; } = false;
29+
public bool IncludeDeactivatedUsers { get; set; } = false;
2930
public List<SortParameter> Sort { get; set; } = new List<SortParameter>();
3031
public Dictionary<string, object> Filter { get; set; } = new Dictionary<string, object>();
3132

@@ -47,6 +48,12 @@ public QueryUserOptions WithPresence()
4748
return this;
4849
}
4950

51+
public QueryUserOptions WithIncludeDeactivatedUsers()
52+
{
53+
IncludeDeactivatedUsers = true;
54+
return this;
55+
}
56+
5057
public QueryUserOptions WithSortBy(SortParameter param)
5158
{
5259
Sort.Add(param);

tests/UserClientTests.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ public class UserClientTests : TestBase
2525
private ChannelWithConfig _channel;
2626
private UserRequest _user1;
2727
private UserRequest _user2;
28+
private UserRequest _user3;
2829

2930
[SetUp]
3031
public async Task SetupAsync()
3132
{
32-
(_user1, _user2) = (await UpsertNewUserAsync(), await UpsertNewUserAsync());
33+
(_user1, _user2, _user3) = (await UpsertNewUserAsync(), await UpsertNewUserAsync(), await UpsertNewUserAsync());
3334
_channel = await CreateChannelAsync(createdByUserId: _user1.Id, members: new[] { _user1.Id, _user2.Id });
3435
}
3536

3637
[TearDown]
3738
public async Task TeardownAsync()
3839
{
39-
await TryDeleteUsersAsync(_user1.Id, _user2.Id);
40+
await TryDeleteUsersAsync(_user1.Id, _user2.Id, _user3.Id);
4041
}
4142

4243
[Test]
@@ -180,6 +181,45 @@ public async Task TestQueryUsersAsync()
180181
resp.Users.Should().NotBeEmpty();
181182
}
182183

184+
[Test]
185+
public async Task TestQueryUsersWithIncludeDeactivatedUsersAsync()
186+
{
187+
// Deactivate user3
188+
await _userClient.DeactivateAsync(_user3.Id);
189+
190+
// Query without including deactivated users
191+
var respWithoutDeactivated = await _userClient.QueryAsync(QueryUserOptions.Default.WithFilter(new Dictionary<string, object>
192+
{
193+
{ "id", new Dictionary<string, object> { { "$in", new[] { _user1.Id, _user3.Id } } } },
194+
}));
195+
196+
// Should only find user1 (user3 is deactivated)
197+
respWithoutDeactivated.Users.Should().NotBeEmpty();
198+
respWithoutDeactivated.Users.Should().HaveCount(1);
199+
respWithoutDeactivated.Users[0].Id.Should().Be(_user1.Id);
200+
201+
// Query with including deactivated users
202+
var respWithDeactivated = await _userClient.QueryAsync(QueryUserOptions.Default
203+
.WithIncludeDeactivatedUsers()
204+
.WithFilter(new Dictionary<string, object>
205+
{
206+
{ "id", new Dictionary<string, object> { { "$in", new[] { _user1.Id, _user3.Id } } } },
207+
}));
208+
209+
// Should find both users
210+
respWithDeactivated.Users.Should().NotBeEmpty();
211+
respWithDeactivated.Users.Should().HaveCount(2);
212+
respWithDeactivated.Users.Should().Contain(u => u.Id == _user1.Id);
213+
respWithDeactivated.Users.Should().Contain(u => u.Id == _user3.Id);
214+
215+
// Verify user3 is deactivated
216+
var user3 = respWithDeactivated.Users.First(u => u.Id == _user3.Id);
217+
user3.DeactivatedAt.Should().NotBeNull();
218+
219+
// Reactivate user3 for cleanup
220+
await _userClient.ReactivateAsync(_user3.Id);
221+
}
222+
183223
[Test]
184224
public async Task TestDeactivateUserAsync()
185225
{

0 commit comments

Comments
 (0)