Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Clients/UserClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public async Task<QueryUsersResponse> QueryAsync(QueryUserOptions opts)
offset = opts.Offset,
limit = opts.Limit,
presence = opts.Presence,
include_deactivated_users = opts.IncludeDeactivatedUsers,
filter_conditions = opts.Filter,
sort = opts.Sort,
};
Expand Down
7 changes: 7 additions & 0 deletions src/Models/QueryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class QueryUserOptions
public int Offset { get; set; } = DefaultOffset;
public int Limit { get; set; } = DefaultLimit;
public bool Presence { get; set; } = false;
public bool IncludeDeactivatedUsers { get; set; } = false;
public List<SortParameter> Sort { get; set; } = new List<SortParameter>();
public Dictionary<string, object> Filter { get; set; } = new Dictionary<string, object>();

Expand All @@ -47,6 +48,12 @@ public QueryUserOptions WithPresence()
return this;
}

public QueryUserOptions WithIncludeDeactivatedUsers()
{
IncludeDeactivatedUsers = true;
return this;
}

public QueryUserOptions WithSortBy(SortParameter param)
{
Sort.Add(param);
Expand Down
44 changes: 42 additions & 2 deletions tests/UserClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
private ChannelWithConfig _channel;
private UserRequest _user1;
private UserRequest _user2;
private UserRequest _user3;

[SetUp]
public async Task SetupAsync()
{
(_user1, _user2) = (await UpsertNewUserAsync(), await UpsertNewUserAsync());
(_user1, _user2, _user3) = (await UpsertNewUserAsync(), await UpsertNewUserAsync(), await UpsertNewUserAsync());
_channel = await CreateChannelAsync(createdByUserId: _user1.Id, members: new[] { _user1.Id, _user2.Id });
}

[TearDown]
public async Task TeardownAsync()
{
await TryDeleteUsersAsync(_user1.Id, _user2.Id);
await TryDeleteUsersAsync(_user1.Id, _user2.Id, _user3.Id);
}

[Test]
Expand Down Expand Up @@ -180,6 +181,45 @@
resp.Users.Should().NotBeEmpty();
}

[Test]
public async Task TestQueryUsersWithIncludeDeactivatedUsersAsync()
{
// Deactivate user3
await _userClient.DeactivateAsync(_user3.Id);

// Query without including deactivated users
var respWithoutDeactivated = await _userClient.QueryAsync(QueryUserOptions.Default.WithFilter(new Dictionary<string, object>
{
{ "id", new Dictionary<string, object> { { "$in", new[] { _user1.Id, _user3.Id } } } },
}));

// Should only find user1 (user3 is deactivated)
respWithoutDeactivated.Users.Should().NotBeEmpty();
respWithoutDeactivated.Users.Should().HaveCount(1);
respWithoutDeactivated.Users[0].Id.Should().Be(_user1.Id);

// Query with including deactivated users
var respWithDeactivated = await _userClient.QueryAsync(QueryUserOptions.Default
.WithIncludeDeactivatedUsers()
.WithFilter(new Dictionary<string, object>
{
{ "id", new Dictionary<string, object> { { "$in", new[] { _user1.Id, _user3.Id } } } },
}));

// Should find both users
respWithDeactivated.Users.Should().NotBeEmpty();
respWithDeactivated.Users.Should().HaveCount(2);
respWithDeactivated.Users.Should().Contain(u => u.Id == _user1.Id);
respWithDeactivated.Users.Should().Contain(u => u.Id == _user3.Id);

// Verify user3 is deactivated
var user3 = respWithDeactivated.Users.First(u => u.Id == _user3.Id);
user3.DeactivatedAt.Should().NotBeNull();

// Reactivate user3 for cleanup
await _userClient.ReactivateAsync(_user3.Id);
}

[Test]
public async Task TestDeactivateUserAsync()
{
Expand Down Expand Up @@ -515,7 +555,7 @@
ChannelCID = "channel1",
MessageID = "message1",
},
new DeliveredMessageConfirmation

Check warning on line 558 in tests/UserClientTests.cs

View workflow job for this annotation

GitHub Actions / 🧪 Run tests

Use trailing comma in multi-line initializers
{
ChannelCID = "channel2",
MessageID = "message2",
Expand All @@ -536,7 +576,7 @@
{
LatestDeliveredMessages = new List<DeliveredMessageConfirmation>
{
new DeliveredMessageConfirmation

Check warning on line 579 in tests/UserClientTests.cs

View workflow job for this annotation

GitHub Actions / 🧪 Run tests

Use trailing comma in multi-line initializers
{
ChannelCID = "channel1",
MessageID = "message1",
Expand Down Expand Up @@ -577,9 +617,9 @@
{
var markDeliveredOptions = new MarkDeliveredOptions
{
LatestDeliveredMessages = new List<DeliveredMessageConfirmation>

Check warning on line 620 in tests/UserClientTests.cs

View workflow job for this annotation

GitHub Actions / 🧪 Run tests

Use trailing comma in multi-line initializers
{
new DeliveredMessageConfirmation

Check warning on line 622 in tests/UserClientTests.cs

View workflow job for this annotation

GitHub Actions / 🧪 Run tests

Use trailing comma in multi-line initializers
{
ChannelCID = "channel1",
MessageID = "message1",
Expand Down
Loading