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
54 changes: 54 additions & 0 deletions src/Clients/ChannelClient.FilterTags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using StreamChat.Models;
using StreamChat.Rest;

namespace StreamChat.Clients
{
/// <summary>
/// Convenience methods for updating a channel's filter tags.
/// </summary>
public partial class ChannelClient
{
/// <summary>
/// Adds one or more filter tags to the channel.
/// </summary>
public Task<UpdateChannelResponse> AddFilterTagsAsync(string channelType, string channelId,
params string[] filterTags) => AddFilterTagsAsync(channelType, channelId, (IEnumerable<string>)filterTags);

/// <summary>
/// Adds filter tags to the channel.
/// </summary>
public async Task<UpdateChannelResponse> AddFilterTagsAsync(string channelType, string channelId,
IEnumerable<string> filterTags, MessageRequest msg = null) => await ExecuteRequestAsync<UpdateChannelResponse>(
$"channels/{channelType}/{channelId}",
HttpMethod.POST,
HttpStatusCode.Created,
new ChannelUpdateRequest
{
AddFilterTags = filterTags,
Message = msg,
});

/// <summary>
/// Removes one or more filter tags from the channel.
/// </summary>
public Task<ApiResponse> RemoveFilterTagsAsync(string channelType, string channelId,
params string[] filterTags) => RemoveFilterTagsAsync(channelType, channelId, (IEnumerable<string>)filterTags);

/// <summary>
/// Removes filter tags from the channel.
/// </summary>
public async Task<ApiResponse> RemoveFilterTagsAsync(string channelType, string channelId,
IEnumerable<string> filterTags, MessageRequest msg = null) => await ExecuteRequestAsync<ApiResponse>(
$"channels/{channelType}/{channelId}",
HttpMethod.POST,
HttpStatusCode.Created,
new ChannelUpdateRequest
{
RemoveFilterTags = filterTags,
Message = msg,
});
}
}
14 changes: 14 additions & 0 deletions src/Clients/IChannelClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ Task<PartialUpdateChannelResponse> PartialUpdateAsync(string channelType, string
Task<ApiResponse> RemoveMembersAsync(string channelType, string channelId, IEnumerable<string> userIds,
MessageRequest msg = null);

/// <summary>
/// Adds filter tags to a channel.
/// </summary>
Task<UpdateChannelResponse> AddFilterTagsAsync(string channelType, string channelId, IEnumerable<string> filterTags, MessageRequest msg = null);

Task<UpdateChannelResponse> AddFilterTagsAsync(string channelType, string channelId, params string[] filterTags);

/// <summary>
/// Removes filter tags from a channel.
/// </summary>
Task<ApiResponse> RemoveFilterTagsAsync(string channelType, string channelId, IEnumerable<string> filterTags, MessageRequest msg = null);

Task<ApiResponse> RemoveFilterTagsAsync(string channelType, string channelId, params string[] filterTags);

/// <summary>
/// Update channel member partially.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Models/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public class ChannelRequest : CustomDataBase
public Language? AutoTranslationLanguage { get; set; }
public bool? Frozen { get; set; }
public IEnumerable<ChannelMember> Members { get; set; }
public IEnumerable<string> FilterTags { get; set; }
public ConfigOverridesRequest ConfigOverrides { get; set; }
}

Expand All @@ -117,6 +118,8 @@ public class ChannelUpdateRequest
public IEnumerable<string> RemoveMembers { get; set; }
public IEnumerable<string> AddModerators { get; set; }
public IEnumerable<string> DemoteModerators { get; set; }
public IEnumerable<string> AddFilterTags { get; set; }
public IEnumerable<string> RemoveFilterTags { get; set; }
public IEnumerable<string> Invites { get; set; }
public int? Cooldown { get; set; }
public bool? AcceptInvite { get; set; }
Expand Down
30 changes: 30 additions & 0 deletions tests/ChannelClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,36 @@ public async Task TestRemoveMembersAsync()
channel.Members.Should().NotContain(x => x.UserId == _user3.Id);
}

[Test]
public async Task TestAddFilterTagsAsync()
{
var channel = await CreateChannelAsync(createdByUserId: _user1.Id);

await _channelClient.AddFilterTagsAsync(channel.Type, channel.Id, "alpha", "beta");

var channelState = await _channelClient.GetOrCreateAsync(channel.Type, channel.Id,
ChannelGetRequest.WithoutWatching());

channelState.Channel.GetData<string[]>("filter_tags").Should().Contain(new[] { "alpha", "beta" });
}

[Test]
public async Task TestRemoveFilterTagsAsync()
{
var channel = await CreateChannelAsync(createdByUserId: _user1.Id);

await _channelClient.AddFilterTagsAsync(channel.Type, channel.Id, "gamma", "delta");

await _channelClient.RemoveFilterTagsAsync(channel.Type, channel.Id, new[] { "gamma" });

var channelState = await _channelClient.GetOrCreateAsync(channel.Type, channel.Id,
ChannelGetRequest.WithoutWatching());

var tags = channelState.Channel.GetData<string[]>("filter_tags");
tags.Should().NotContain("gamma");
tags.Should().Contain("delta");
}

[Test]
public async Task TestAddModeratorsAsync()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/MessageCountTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class MessageCountTests : TestBase
public async Task SetUp()
{
_user = await UpsertNewUserAsync();
_channel = await CreateChannelAsync(_user.Id, autoDelete: false);
_channel = await CreateChannelAsync(_user.Id, autoDelete: false, channelType: "team");
}

[TearDown]
Expand Down
4 changes: 2 additions & 2 deletions tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ protected async Task<UserRequest> UpsertNewUserAsync()
return user;
}

protected async Task<ChannelWithConfig> CreateChannelAsync(string createdByUserId, IEnumerable<string> members = null, bool autoDelete = true)
protected async Task<ChannelWithConfig> CreateChannelAsync(string createdByUserId, IEnumerable<string> members = null, bool autoDelete = true, string channelType = "messaging")
{
var channelResp = await _channelClient.GetOrCreateAsync("messaging", Guid.NewGuid().ToString(), new ChannelGetRequest
var channelResp = await _channelClient.GetOrCreateAsync(channelType, Guid.NewGuid().ToString(), new ChannelGetRequest
{
Data = new ChannelRequest
{
Expand Down
Loading