|
| 1 | +package io.getstream.chat.java.models; |
| 2 | + |
| 3 | +import io.getstream.chat.java.models.Channel.*; |
| 4 | +import java.util.ArrayList; |
| 5 | +import java.util.List; |
| 6 | +import org.jetbrains.annotations.NotNull; |
| 7 | + |
| 8 | +/** Provides convenience methods for batch channel operations. */ |
| 9 | +public class ChannelBatchUpdater { |
| 10 | + |
| 11 | + /** |
| 12 | + * Adds members to channels matching the filter. |
| 13 | + * |
| 14 | + * @param filter the filter to match channels |
| 15 | + * @param members list of members to add |
| 16 | + * @return the batch update request |
| 17 | + */ |
| 18 | + @NotNull |
| 19 | + public ChannelsBatchUpdateRequest addMembers( |
| 20 | + @NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) { |
| 21 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 22 | + options.setOperation(ChannelBatchOperation.ADD_MEMBERS); |
| 23 | + options.setFilter(filter); |
| 24 | + options.setMembers(members != null ? new ArrayList<>(members) : null); |
| 25 | + return Channel.updateBatch(options); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Removes members from channels matching the filter. |
| 30 | + * |
| 31 | + * @param filter the filter to match channels |
| 32 | + * @param members list of members to remove |
| 33 | + * @return the batch update request |
| 34 | + */ |
| 35 | + @NotNull |
| 36 | + public ChannelsBatchUpdateRequest removeMembers( |
| 37 | + @NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) { |
| 38 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 39 | + options.setOperation(ChannelBatchOperation.REMOVE_MEMBERS); |
| 40 | + options.setFilter(filter); |
| 41 | + options.setMembers(members != null ? new ArrayList<>(members) : null); |
| 42 | + return Channel.updateBatch(options); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Invites members to channels matching the filter. |
| 47 | + * |
| 48 | + * @param filter the filter to match channels |
| 49 | + * @param members list of members to invite |
| 50 | + * @return the batch update request |
| 51 | + */ |
| 52 | + @NotNull |
| 53 | + public ChannelsBatchUpdateRequest inviteMembers( |
| 54 | + @NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) { |
| 55 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 56 | + options.setOperation(ChannelBatchOperation.INVITE_MEMBERS); |
| 57 | + options.setFilter(filter); |
| 58 | + options.setMembers(members != null ? new ArrayList<>(members) : null); |
| 59 | + return Channel.updateBatch(options); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Adds moderators to channels matching the filter. |
| 64 | + * |
| 65 | + * @param filter the filter to match channels |
| 66 | + * @param members list of members to add as moderators |
| 67 | + * @return the batch update request |
| 68 | + */ |
| 69 | + @NotNull |
| 70 | + public ChannelsBatchUpdateRequest addModerators( |
| 71 | + @NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) { |
| 72 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 73 | + options.setOperation(ChannelBatchOperation.ADD_MODERATORS); |
| 74 | + options.setFilter(filter); |
| 75 | + options.setMembers(members != null ? new ArrayList<>(members) : null); |
| 76 | + return Channel.updateBatch(options); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Removes moderator role from members in channels matching the filter. |
| 81 | + * |
| 82 | + * @param filter the filter to match channels |
| 83 | + * @param members list of members to demote from moderators |
| 84 | + * @return the batch update request |
| 85 | + */ |
| 86 | + @NotNull |
| 87 | + public ChannelsBatchUpdateRequest demoteModerators( |
| 88 | + @NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) { |
| 89 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 90 | + options.setOperation(ChannelBatchOperation.DEMOTE_MODERATORS); |
| 91 | + options.setFilter(filter); |
| 92 | + options.setMembers(members != null ? new ArrayList<>(members) : null); |
| 93 | + return Channel.updateBatch(options); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Assigns roles to members in channels matching the filter. |
| 98 | + * |
| 99 | + * @param filter the filter to match channels |
| 100 | + * @param members list of members with roles to assign |
| 101 | + * @return the batch update request |
| 102 | + */ |
| 103 | + @NotNull |
| 104 | + public ChannelsBatchUpdateRequest assignRoles( |
| 105 | + @NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) { |
| 106 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 107 | + options.setOperation(ChannelBatchOperation.ASSIGN_ROLES); |
| 108 | + options.setFilter(filter); |
| 109 | + options.setMembers(members != null ? new ArrayList<>(members) : null); |
| 110 | + return Channel.updateBatch(options); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Hides channels matching the filter for the specified members. |
| 115 | + * |
| 116 | + * @param filter the filter to match channels |
| 117 | + * @param members list of members for whom to hide channels |
| 118 | + * @return the batch update request |
| 119 | + */ |
| 120 | + @NotNull |
| 121 | + public ChannelsBatchUpdateRequest hide( |
| 122 | + @NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) { |
| 123 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 124 | + options.setOperation(ChannelBatchOperation.HIDE); |
| 125 | + options.setFilter(filter); |
| 126 | + options.setMembers(members != null ? new ArrayList<>(members) : null); |
| 127 | + return Channel.updateBatch(options); |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Shows channels matching the filter for the specified members. |
| 132 | + * |
| 133 | + * @param filter the filter to match channels |
| 134 | + * @param members list of members for whom to show channels |
| 135 | + * @return the batch update request |
| 136 | + */ |
| 137 | + @NotNull |
| 138 | + public ChannelsBatchUpdateRequest show( |
| 139 | + @NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) { |
| 140 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 141 | + options.setOperation(ChannelBatchOperation.SHOW); |
| 142 | + options.setFilter(filter); |
| 143 | + options.setMembers(members != null ? new ArrayList<>(members) : null); |
| 144 | + return Channel.updateBatch(options); |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Archives channels matching the filter for the specified members. |
| 149 | + * |
| 150 | + * @param filter the filter to match channels |
| 151 | + * @param members list of members for whom to archive channels |
| 152 | + * @return the batch update request |
| 153 | + */ |
| 154 | + @NotNull |
| 155 | + public ChannelsBatchUpdateRequest archive( |
| 156 | + @NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) { |
| 157 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 158 | + options.setOperation(ChannelBatchOperation.ARCHIVE); |
| 159 | + options.setFilter(filter); |
| 160 | + options.setMembers(members != null ? new ArrayList<>(members) : null); |
| 161 | + return Channel.updateBatch(options); |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * Unarchives channels matching the filter for the specified members. |
| 166 | + * |
| 167 | + * @param filter the filter to match channels |
| 168 | + * @param members list of members for whom to unarchive channels |
| 169 | + * @return the batch update request |
| 170 | + */ |
| 171 | + @NotNull |
| 172 | + public ChannelsBatchUpdateRequest unarchive( |
| 173 | + @NotNull ChannelsBatchFilters filter, @NotNull List<ChannelBatchMemberRequest> members) { |
| 174 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 175 | + options.setOperation(ChannelBatchOperation.UNARCHIVE); |
| 176 | + options.setFilter(filter); |
| 177 | + options.setMembers(members != null ? new ArrayList<>(members) : null); |
| 178 | + return Channel.updateBatch(options); |
| 179 | + } |
| 180 | + |
| 181 | + /** |
| 182 | + * Updates data on channels matching the filter. |
| 183 | + * |
| 184 | + * @param filter the filter to match channels |
| 185 | + * @param data channel data to update |
| 186 | + * @return the batch update request |
| 187 | + */ |
| 188 | + @NotNull |
| 189 | + public ChannelsBatchUpdateRequest updateData( |
| 190 | + @NotNull ChannelsBatchFilters filter, @NotNull ChannelDataUpdate data) { |
| 191 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 192 | + options.setOperation(ChannelBatchOperation.UPDATE_DATA); |
| 193 | + options.setFilter(filter); |
| 194 | + options.setData(data); |
| 195 | + return Channel.updateBatch(options); |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * Adds filter tags to channels matching the filter. |
| 200 | + * |
| 201 | + * @param filter the filter to match channels |
| 202 | + * @param tags list of filter tags to add |
| 203 | + * @return the batch update request |
| 204 | + */ |
| 205 | + @NotNull |
| 206 | + public ChannelsBatchUpdateRequest addFilterTags( |
| 207 | + @NotNull ChannelsBatchFilters filter, @NotNull List<String> tags) { |
| 208 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 209 | + options.setOperation(ChannelBatchOperation.ADD_FILTER_TAGS); |
| 210 | + options.setFilter(filter); |
| 211 | + options.setFilterTagsUpdate(tags != null ? new ArrayList<>(tags) : null); |
| 212 | + return Channel.updateBatch(options); |
| 213 | + } |
| 214 | + |
| 215 | + /** |
| 216 | + * Removes filter tags from channels matching the filter. |
| 217 | + * |
| 218 | + * @param filter the filter to match channels |
| 219 | + * @param tags list of filter tags to remove |
| 220 | + * @return the batch update request |
| 221 | + */ |
| 222 | + @NotNull |
| 223 | + public ChannelsBatchUpdateRequest removeFilterTags( |
| 224 | + @NotNull ChannelsBatchFilters filter, @NotNull List<String> tags) { |
| 225 | + ChannelsBatchOptions options = new ChannelsBatchOptions(); |
| 226 | + options.setOperation(ChannelBatchOperation.REMOVE_FILTER_TAGS); |
| 227 | + options.setFilter(filter); |
| 228 | + options.setFilterTagsUpdate(tags != null ? new ArrayList<>(tags) : null); |
| 229 | + return Channel.updateBatch(options); |
| 230 | + } |
| 231 | +} |
0 commit comments