Skip to content

Commit fc13f5c

Browse files
javierdfmrafaelmf3
andauthored
feat: add channel batch updates support (#224)
* feat: add channel batch updates support * fix: make format * fix: serialization options * fix: fix tests * fix: attempt to fix tests * fix: lint * fix: fixing tests * fix: lint --------- Co-authored-by: Rafael Marinho <rafael_mf3@hotmail.com>
1 parent 2b6bbd0 commit fc13f5c

File tree

5 files changed

+802
-0
lines changed

5 files changed

+802
-0
lines changed

src/main/java/io/getstream/chat/java/models/Channel.java

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,4 +1875,167 @@ public static ChannelMemberPartialUpdateRequest unarchive(
18751875
public static MarkDeliveredRequest markDelivered() {
18761876
return new MarkDeliveredRequest();
18771877
}
1878+
1879+
/** Channel batch operation types */
1880+
public enum ChannelBatchOperation {
1881+
@JsonProperty("addMembers")
1882+
ADD_MEMBERS,
1883+
@JsonProperty("removeMembers")
1884+
REMOVE_MEMBERS,
1885+
@JsonProperty("inviteMembers")
1886+
INVITE_MEMBERS,
1887+
@JsonProperty("assignRoles")
1888+
ASSIGN_ROLES,
1889+
@JsonProperty("addModerators")
1890+
ADD_MODERATORS,
1891+
@JsonProperty("demoteModerators")
1892+
DEMOTE_MODERATORS,
1893+
@JsonProperty("hide")
1894+
HIDE,
1895+
@JsonProperty("show")
1896+
SHOW,
1897+
@JsonProperty("archive")
1898+
ARCHIVE,
1899+
@JsonProperty("unarchive")
1900+
UNARCHIVE,
1901+
@JsonProperty("updateData")
1902+
UPDATE_DATA,
1903+
@JsonProperty("addFilterTags")
1904+
ADD_FILTER_TAGS,
1905+
@JsonProperty("removeFilterTags")
1906+
REMOVE_FILTER_TAGS
1907+
}
1908+
1909+
/** Represents a member in batch operations */
1910+
@Data
1911+
@NoArgsConstructor
1912+
@AllArgsConstructor
1913+
public static class ChannelBatchMemberRequest {
1914+
@NotNull
1915+
@JsonProperty("user_id")
1916+
private String userId;
1917+
1918+
@Nullable
1919+
@JsonProperty("channel_role")
1920+
private String channelRole;
1921+
}
1922+
1923+
/** Represents data that can be updated on channels in batch */
1924+
@Data
1925+
@NoArgsConstructor
1926+
public static class ChannelDataUpdate {
1927+
@Nullable
1928+
@JsonProperty("frozen")
1929+
private Boolean frozen;
1930+
1931+
@Nullable
1932+
@JsonProperty("disabled")
1933+
private Boolean disabled;
1934+
1935+
@Nullable
1936+
@JsonProperty("custom")
1937+
private Map<String, Object> custom;
1938+
1939+
@Nullable
1940+
@JsonProperty("team")
1941+
private String team;
1942+
1943+
@Nullable
1944+
@JsonProperty("config_overrides")
1945+
private Map<String, Object> configOverrides;
1946+
1947+
@Nullable
1948+
@JsonProperty("auto_translation_enabled")
1949+
private Boolean autoTranslationEnabled;
1950+
1951+
@Nullable
1952+
@JsonProperty("auto_translation_language")
1953+
private String autoTranslationLanguage;
1954+
}
1955+
1956+
/** Represents filters for batch channel updates */
1957+
@Data
1958+
@NoArgsConstructor
1959+
@JsonInclude(JsonInclude.Include.NON_NULL)
1960+
public static class ChannelsBatchFilters {
1961+
@Nullable
1962+
@JsonProperty("cids")
1963+
private Object cids;
1964+
1965+
@Nullable
1966+
@JsonProperty("types")
1967+
private Object types;
1968+
1969+
@Nullable
1970+
@JsonProperty("filter_tags")
1971+
private Object filterTags;
1972+
}
1973+
1974+
/** Represents options for batch channel updates */
1975+
@Data
1976+
@NoArgsConstructor
1977+
public static class ChannelsBatchOptions {
1978+
@NotNull
1979+
@JsonProperty("operation")
1980+
private ChannelBatchOperation operation;
1981+
1982+
@NotNull
1983+
@JsonProperty("filter")
1984+
private ChannelsBatchFilters filter;
1985+
1986+
@Nullable
1987+
@JsonProperty("members")
1988+
private List<ChannelBatchMemberRequest> members;
1989+
1990+
@Nullable
1991+
@JsonProperty("data")
1992+
private ChannelDataUpdate data;
1993+
1994+
@Nullable
1995+
@JsonProperty("filter_tags_update")
1996+
private List<String> filterTagsUpdate;
1997+
}
1998+
1999+
@Getter
2000+
@EqualsAndHashCode
2001+
@RequiredArgsConstructor
2002+
public static class ChannelsBatchUpdateRequest
2003+
extends StreamRequest<ChannelsBatchUpdateResponse> {
2004+
@NotNull private ChannelsBatchOptions options;
2005+
2006+
@Override
2007+
protected Call<ChannelsBatchUpdateResponse> generateCall(Client client) throws StreamException {
2008+
return client.create(ChannelService.class).updateBatch(this.options);
2009+
}
2010+
}
2011+
2012+
@Data
2013+
@NoArgsConstructor
2014+
@EqualsAndHashCode(callSuper = true)
2015+
public static class ChannelsBatchUpdateResponse extends StreamResponseObject {
2016+
@NotNull
2017+
@JsonProperty("task_id")
2018+
private String taskId;
2019+
}
2020+
2021+
/**
2022+
* Creates a batch update request
2023+
*
2024+
* @param options the batch update options
2025+
* @return the created request
2026+
*/
2027+
@NotNull
2028+
public static ChannelsBatchUpdateRequest updateBatch(@NotNull ChannelsBatchOptions options) {
2029+
return new ChannelsBatchUpdateRequest(options);
2030+
}
2031+
2032+
/**
2033+
* Returns a ChannelBatchUpdater instance for batch channel operations.
2034+
*
2035+
* @return ChannelBatchUpdater instance
2036+
*/
2037+
@NotNull
2038+
public static ChannelBatchUpdater channelBatchUpdater() {
2039+
return new ChannelBatchUpdater();
2040+
}
18782041
}
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
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

Comments
 (0)