|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Linq; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using StreamChat.Models; |
| 5 | + |
| 6 | +namespace StreamChat.Clients |
| 7 | +{ |
| 8 | + /// <summary> |
| 9 | + /// Provides convenience methods for batch channel operations. |
| 10 | + /// </summary> |
| 11 | + public class ChannelBatchUpdater |
| 12 | + { |
| 13 | + private readonly IChannelClient _client; |
| 14 | + |
| 15 | + public ChannelBatchUpdater(IChannelClient client) |
| 16 | + { |
| 17 | + _client = client; |
| 18 | + } |
| 19 | + |
| 20 | + /// <summary> |
| 21 | + /// Adds members to channels matching the filter. |
| 22 | + /// </summary> |
| 23 | + public async Task<AsyncOperationResponse> AddMembersAsync(ChannelsBatchFilters filter, IEnumerable<ChannelBatchMemberRequest> members) |
| 24 | + { |
| 25 | + var options = new ChannelsBatchOptions |
| 26 | + { |
| 27 | + Operation = ChannelBatchOperation.AddMembers, |
| 28 | + Filter = filter, |
| 29 | + Members = members?.ToList(), |
| 30 | + }; |
| 31 | + return await _client.UpdateChannelsBatchAsync(options); |
| 32 | + } |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Removes members from channels matching the filter. |
| 36 | + /// </summary> |
| 37 | + public async Task<AsyncOperationResponse> RemoveMembersAsync(ChannelsBatchFilters filter, IEnumerable<ChannelBatchMemberRequest> members) |
| 38 | + { |
| 39 | + var options = new ChannelsBatchOptions |
| 40 | + { |
| 41 | + Operation = ChannelBatchOperation.RemoveMembers, |
| 42 | + Filter = filter, |
| 43 | + Members = members?.ToList(), |
| 44 | + }; |
| 45 | + return await _client.UpdateChannelsBatchAsync(options); |
| 46 | + } |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Invites members to channels matching the filter. |
| 50 | + /// </summary> |
| 51 | + public async Task<AsyncOperationResponse> InviteMembersAsync(ChannelsBatchFilters filter, IEnumerable<ChannelBatchMemberRequest> members) |
| 52 | + { |
| 53 | + var options = new ChannelsBatchOptions |
| 54 | + { |
| 55 | + Operation = ChannelBatchOperation.InviteMembers, |
| 56 | + Filter = filter, |
| 57 | + Members = members?.ToList(), |
| 58 | + }; |
| 59 | + return await _client.UpdateChannelsBatchAsync(options); |
| 60 | + } |
| 61 | + |
| 62 | + /// <summary> |
| 63 | + /// Assigns roles to members in channels matching the filter. |
| 64 | + /// </summary> |
| 65 | + public async Task<AsyncOperationResponse> AssignRolesAsync(ChannelsBatchFilters filter, IEnumerable<ChannelBatchMemberRequest> members) |
| 66 | + { |
| 67 | + var options = new ChannelsBatchOptions |
| 68 | + { |
| 69 | + Operation = ChannelBatchOperation.AssignRoles, |
| 70 | + Filter = filter, |
| 71 | + Members = members?.ToList(), |
| 72 | + }; |
| 73 | + return await _client.UpdateChannelsBatchAsync(options); |
| 74 | + } |
| 75 | + |
| 76 | + /// <summary> |
| 77 | + /// Adds moderators to channels matching the filter. |
| 78 | + /// </summary> |
| 79 | + public async Task<AsyncOperationResponse> AddModeratorsAsync(ChannelsBatchFilters filter, IEnumerable<ChannelBatchMemberRequest> members) |
| 80 | + { |
| 81 | + var options = new ChannelsBatchOptions |
| 82 | + { |
| 83 | + Operation = ChannelBatchOperation.AddModerators, |
| 84 | + Filter = filter, |
| 85 | + Members = members?.ToList(), |
| 86 | + }; |
| 87 | + return await _client.UpdateChannelsBatchAsync(options); |
| 88 | + } |
| 89 | + |
| 90 | + /// <summary> |
| 91 | + /// Removes moderator role from members in channels matching the filter. |
| 92 | + /// </summary> |
| 93 | + public async Task<AsyncOperationResponse> DemoteModeratorsAsync(ChannelsBatchFilters filter, IEnumerable<ChannelBatchMemberRequest> members) |
| 94 | + { |
| 95 | + var options = new ChannelsBatchOptions |
| 96 | + { |
| 97 | + Operation = ChannelBatchOperation.DemoteModerators, |
| 98 | + Filter = filter, |
| 99 | + Members = members?.ToList(), |
| 100 | + }; |
| 101 | + return await _client.UpdateChannelsBatchAsync(options); |
| 102 | + } |
| 103 | + |
| 104 | + /// <summary> |
| 105 | + /// Hides channels matching the filter for the specified members. |
| 106 | + /// </summary> |
| 107 | + public async Task<AsyncOperationResponse> HideAsync(ChannelsBatchFilters filter, IEnumerable<ChannelBatchMemberRequest> members) |
| 108 | + { |
| 109 | + var options = new ChannelsBatchOptions |
| 110 | + { |
| 111 | + Operation = ChannelBatchOperation.Hide, |
| 112 | + Filter = filter, |
| 113 | + Members = members?.ToList(), |
| 114 | + }; |
| 115 | + return await _client.UpdateChannelsBatchAsync(options); |
| 116 | + } |
| 117 | + |
| 118 | + /// <summary> |
| 119 | + /// Shows channels matching the filter for the specified members. |
| 120 | + /// </summary> |
| 121 | + public async Task<AsyncOperationResponse> ShowAsync(ChannelsBatchFilters filter, IEnumerable<ChannelBatchMemberRequest> members) |
| 122 | + { |
| 123 | + var options = new ChannelsBatchOptions |
| 124 | + { |
| 125 | + Operation = ChannelBatchOperation.Show, |
| 126 | + Filter = filter, |
| 127 | + Members = members?.ToList(), |
| 128 | + }; |
| 129 | + return await _client.UpdateChannelsBatchAsync(options); |
| 130 | + } |
| 131 | + |
| 132 | + /// <summary> |
| 133 | + /// Archives channels matching the filter for the specified members. |
| 134 | + /// </summary> |
| 135 | + public async Task<AsyncOperationResponse> ArchiveAsync(ChannelsBatchFilters filter, IEnumerable<ChannelBatchMemberRequest> members) |
| 136 | + { |
| 137 | + var options = new ChannelsBatchOptions |
| 138 | + { |
| 139 | + Operation = ChannelBatchOperation.Archive, |
| 140 | + Filter = filter, |
| 141 | + Members = members?.ToList(), |
| 142 | + }; |
| 143 | + return await _client.UpdateChannelsBatchAsync(options); |
| 144 | + } |
| 145 | + |
| 146 | + /// <summary> |
| 147 | + /// Unarchives channels matching the filter for the specified members. |
| 148 | + /// </summary> |
| 149 | + public async Task<AsyncOperationResponse> UnarchiveAsync(ChannelsBatchFilters filter, IEnumerable<ChannelBatchMemberRequest> members) |
| 150 | + { |
| 151 | + var options = new ChannelsBatchOptions |
| 152 | + { |
| 153 | + Operation = ChannelBatchOperation.Unarchive, |
| 154 | + Filter = filter, |
| 155 | + Members = members?.ToList(), |
| 156 | + }; |
| 157 | + return await _client.UpdateChannelsBatchAsync(options); |
| 158 | + } |
| 159 | + |
| 160 | + /// <summary> |
| 161 | + /// Updates data on channels matching the filter. |
| 162 | + /// </summary> |
| 163 | + public async Task<AsyncOperationResponse> UpdateDataAsync(ChannelsBatchFilters filter, ChannelDataUpdate data) |
| 164 | + { |
| 165 | + var options = new ChannelsBatchOptions |
| 166 | + { |
| 167 | + Operation = ChannelBatchOperation.UpdateData, |
| 168 | + Filter = filter, |
| 169 | + Data = data, |
| 170 | + }; |
| 171 | + return await _client.UpdateChannelsBatchAsync(options); |
| 172 | + } |
| 173 | + |
| 174 | + /// <summary> |
| 175 | + /// Adds filter tags to channels matching the filter. |
| 176 | + /// </summary> |
| 177 | + public async Task<AsyncOperationResponse> AddFilterTagsAsync(ChannelsBatchFilters filter, IEnumerable<string> tags) |
| 178 | + { |
| 179 | + var options = new ChannelsBatchOptions |
| 180 | + { |
| 181 | + Operation = ChannelBatchOperation.AddFilterTags, |
| 182 | + Filter = filter, |
| 183 | + FilterTagsUpdate = tags?.ToList(), |
| 184 | + }; |
| 185 | + return await _client.UpdateChannelsBatchAsync(options); |
| 186 | + } |
| 187 | + |
| 188 | + /// <summary> |
| 189 | + /// Removes filter tags from channels matching the filter. |
| 190 | + /// </summary> |
| 191 | + public async Task<AsyncOperationResponse> RemoveFilterTagsAsync(ChannelsBatchFilters filter, IEnumerable<string> tags) |
| 192 | + { |
| 193 | + var options = new ChannelsBatchOptions |
| 194 | + { |
| 195 | + Operation = ChannelBatchOperation.RemoveFilterTags, |
| 196 | + Filter = filter, |
| 197 | + FilterTagsUpdate = tags?.ToList(), |
| 198 | + }; |
| 199 | + return await _client.UpdateChannelsBatchAsync(options); |
| 200 | + } |
| 201 | + } |
| 202 | +} |
0 commit comments