Skip to content

Commit 7cd1432

Browse files
authored
Merge branch 'master' into add-include-deactivated-users
2 parents aa90750 + 4f73c9e commit 7cd1432

File tree

6 files changed

+104
-3
lines changed

6 files changed

+104
-3
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Collections.Generic;
2+
using System.Net;
3+
using System.Threading.Tasks;
4+
using StreamChat.Models;
5+
using StreamChat.Rest;
6+
7+
namespace StreamChat.Clients
8+
{
9+
/// <summary>
10+
/// Convenience methods for updating a channel's filter tags.
11+
/// </summary>
12+
public partial class ChannelClient
13+
{
14+
/// <summary>
15+
/// Adds one or more filter tags to the channel.
16+
/// </summary>
17+
public Task<UpdateChannelResponse> AddFilterTagsAsync(string channelType, string channelId,
18+
params string[] filterTags) => AddFilterTagsAsync(channelType, channelId, (IEnumerable<string>)filterTags);
19+
20+
/// <summary>
21+
/// Adds filter tags to the channel.
22+
/// </summary>
23+
public async Task<UpdateChannelResponse> AddFilterTagsAsync(string channelType, string channelId,
24+
IEnumerable<string> filterTags, MessageRequest msg = null) => await ExecuteRequestAsync<UpdateChannelResponse>(
25+
$"channels/{channelType}/{channelId}",
26+
HttpMethod.POST,
27+
HttpStatusCode.Created,
28+
new ChannelUpdateRequest
29+
{
30+
AddFilterTags = filterTags,
31+
Message = msg,
32+
});
33+
34+
/// <summary>
35+
/// Removes one or more filter tags from the channel.
36+
/// </summary>
37+
public Task<ApiResponse> RemoveFilterTagsAsync(string channelType, string channelId,
38+
params string[] filterTags) => RemoveFilterTagsAsync(channelType, channelId, (IEnumerable<string>)filterTags);
39+
40+
/// <summary>
41+
/// Removes filter tags from the channel.
42+
/// </summary>
43+
public async Task<ApiResponse> RemoveFilterTagsAsync(string channelType, string channelId,
44+
IEnumerable<string> filterTags, MessageRequest msg = null) => await ExecuteRequestAsync<ApiResponse>(
45+
$"channels/{channelType}/{channelId}",
46+
HttpMethod.POST,
47+
HttpStatusCode.Created,
48+
new ChannelUpdateRequest
49+
{
50+
RemoveFilterTags = filterTags,
51+
Message = msg,
52+
});
53+
}
54+
}

src/Clients/IChannelClient.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ Task<PartialUpdateChannelResponse> PartialUpdateAsync(string channelType, string
170170
Task<ApiResponse> RemoveMembersAsync(string channelType, string channelId, IEnumerable<string> userIds,
171171
MessageRequest msg = null);
172172

173+
/// <summary>
174+
/// Adds filter tags to a channel.
175+
/// </summary>
176+
Task<UpdateChannelResponse> AddFilterTagsAsync(string channelType, string channelId, IEnumerable<string> filterTags, MessageRequest msg = null);
177+
178+
Task<UpdateChannelResponse> AddFilterTagsAsync(string channelType, string channelId, params string[] filterTags);
179+
180+
/// <summary>
181+
/// Removes filter tags from a channel.
182+
/// </summary>
183+
Task<ApiResponse> RemoveFilterTagsAsync(string channelType, string channelId, IEnumerable<string> filterTags, MessageRequest msg = null);
184+
185+
Task<ApiResponse> RemoveFilterTagsAsync(string channelType, string channelId, params string[] filterTags);
186+
173187
/// <summary>
174188
/// Update channel member partially.
175189
/// </summary>

src/Models/Channel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public class ChannelRequest : CustomDataBase
9393
public Language? AutoTranslationLanguage { get; set; }
9494
public bool? Frozen { get; set; }
9595
public IEnumerable<ChannelMember> Members { get; set; }
96+
public IEnumerable<string> FilterTags { get; set; }
9697
public ConfigOverridesRequest ConfigOverrides { get; set; }
9798
}
9899

@@ -117,6 +118,8 @@ public class ChannelUpdateRequest
117118
public IEnumerable<string> RemoveMembers { get; set; }
118119
public IEnumerable<string> AddModerators { get; set; }
119120
public IEnumerable<string> DemoteModerators { get; set; }
121+
public IEnumerable<string> AddFilterTags { get; set; }
122+
public IEnumerable<string> RemoveFilterTags { get; set; }
120123
public IEnumerable<string> Invites { get; set; }
121124
public int? Cooldown { get; set; }
122125
public bool? AcceptInvite { get; set; }

tests/ChannelClientTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,36 @@ public async Task TestRemoveMembersAsync()
590590
channel.Members.Should().NotContain(x => x.UserId == _user3.Id);
591591
}
592592

593+
[Test]
594+
public async Task TestAddFilterTagsAsync()
595+
{
596+
var channel = await CreateChannelAsync(createdByUserId: _user1.Id);
597+
598+
await _channelClient.AddFilterTagsAsync(channel.Type, channel.Id, "alpha", "beta");
599+
600+
var channelState = await _channelClient.GetOrCreateAsync(channel.Type, channel.Id,
601+
ChannelGetRequest.WithoutWatching());
602+
603+
channelState.Channel.GetData<string[]>("filter_tags").Should().Contain(new[] { "alpha", "beta" });
604+
}
605+
606+
[Test]
607+
public async Task TestRemoveFilterTagsAsync()
608+
{
609+
var channel = await CreateChannelAsync(createdByUserId: _user1.Id);
610+
611+
await _channelClient.AddFilterTagsAsync(channel.Type, channel.Id, "gamma", "delta");
612+
613+
await _channelClient.RemoveFilterTagsAsync(channel.Type, channel.Id, new[] { "gamma" });
614+
615+
var channelState = await _channelClient.GetOrCreateAsync(channel.Type, channel.Id,
616+
ChannelGetRequest.WithoutWatching());
617+
618+
var tags = channelState.Channel.GetData<string[]>("filter_tags");
619+
tags.Should().NotContain("gamma");
620+
tags.Should().Contain("delta");
621+
}
622+
593623
[Test]
594624
public async Task TestAddModeratorsAsync()
595625
{

tests/MessageCountTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class MessageCountTests : TestBase
1717
public async Task SetUp()
1818
{
1919
_user = await UpsertNewUserAsync();
20-
_channel = await CreateChannelAsync(_user.Id, autoDelete: false);
20+
_channel = await CreateChannelAsync(_user.Id, autoDelete: false, channelType: "team");
2121
}
2222

2323
[TearDown]

tests/TestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ protected async Task<UserRequest> UpsertNewUserAsync()
106106
return user;
107107
}
108108

109-
protected async Task<ChannelWithConfig> CreateChannelAsync(string createdByUserId, IEnumerable<string> members = null, bool autoDelete = true)
109+
protected async Task<ChannelWithConfig> CreateChannelAsync(string createdByUserId, IEnumerable<string> members = null, bool autoDelete = true, string channelType = "messaging")
110110
{
111-
var channelResp = await _channelClient.GetOrCreateAsync("messaging", Guid.NewGuid().ToString(), new ChannelGetRequest
111+
var channelResp = await _channelClient.GetOrCreateAsync(channelType, Guid.NewGuid().ToString(), new ChannelGetRequest
112112
{
113113
Data = new ChannelRequest
114114
{

0 commit comments

Comments
 (0)