Skip to content

Commit 8ad67f9

Browse files
authored
feat: add channel batch updates support (#154)
* feat: add channel batch updates support * fix: fixed quotes * fix: updated quotes
1 parent 2674b36 commit 8ad67f9

3 files changed

Lines changed: 444 additions & 0 deletions

File tree

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
<?php
2+
3+
declare(strict_types=0);
4+
5+
namespace GetStream\StreamChat;
6+
7+
/**
8+
* Provides convenience methods for batch channel operations.
9+
*/
10+
class ChannelBatchUpdater
11+
{
12+
/**
13+
* @var Client
14+
*/
15+
private $client;
16+
17+
public function __construct(Client $client)
18+
{
19+
$this->client = $client;
20+
}
21+
22+
/**
23+
* Adds members to channels matching the filter.
24+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
25+
* @param array $members Array of member arrays, each with user_id (required) and optional channel_role
26+
* @return StreamResponse
27+
* @throws StreamException
28+
*/
29+
public function addMembers(array $filter, array $members): StreamResponse
30+
{
31+
$options = [
32+
"operation" => "addMembers",
33+
"filter" => $filter,
34+
"members" => $members,
35+
];
36+
return $this->client->updateChannelsBatch($options);
37+
}
38+
39+
/**
40+
* Removes members from channels matching the filter.
41+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
42+
* @param array $members Array of member arrays, each with user_id (required) and optional channel_role
43+
* @return StreamResponse
44+
* @throws StreamException
45+
*/
46+
public function removeMembers(array $filter, array $members): StreamResponse
47+
{
48+
$options = [
49+
"operation" => "removeMembers",
50+
"filter" => $filter,
51+
"members" => $members,
52+
];
53+
return $this->client->updateChannelsBatch($options);
54+
}
55+
56+
/**
57+
* Invites members to channels matching the filter.
58+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
59+
* @param array $members Array of member arrays, each with user_id (required) and optional channel_role
60+
* @return StreamResponse
61+
* @throws StreamException
62+
*/
63+
public function inviteMembers(array $filter, array $members): StreamResponse
64+
{
65+
$options = [
66+
"operation" => "inviteMembers",
67+
"filter" => $filter,
68+
"members" => $members,
69+
];
70+
return $this->client->updateChannelsBatch($options);
71+
}
72+
73+
/**
74+
* Assigns roles to members in channels matching the filter.
75+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
76+
* @param array $members Array of member arrays, each with user_id (required) and optional channel_role
77+
* @return StreamResponse
78+
* @throws StreamException
79+
*/
80+
public function assignRoles(array $filter, array $members): StreamResponse
81+
{
82+
$options = [
83+
"operation" => "assignRoles",
84+
"filter" => $filter,
85+
"members" => $members,
86+
];
87+
return $this->client->updateChannelsBatch($options);
88+
}
89+
90+
/**
91+
* Adds moderators to channels matching the filter.
92+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
93+
* @param array $members Array of member arrays, each with user_id (required) and optional channel_role
94+
* @return StreamResponse
95+
* @throws StreamException
96+
*/
97+
public function addModerators(array $filter, array $members): StreamResponse
98+
{
99+
$options = [
100+
"operation" => "addModerators",
101+
"filter" => $filter,
102+
"members" => $members,
103+
];
104+
return $this->client->updateChannelsBatch($options);
105+
}
106+
107+
/**
108+
* Removes moderator role from members in channels matching the filter.
109+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
110+
* @param array $members Array of member arrays, each with user_id (required) and optional channel_role
111+
* @return StreamResponse
112+
* @throws StreamException
113+
*/
114+
public function demoteModerators(array $filter, array $members): StreamResponse
115+
{
116+
$options = [
117+
"operation" => "demoteModerators",
118+
"filter" => $filter,
119+
"members" => $members,
120+
];
121+
return $this->client->updateChannelsBatch($options);
122+
}
123+
124+
/**
125+
* Hides channels matching the filter for the specified members.
126+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
127+
* @param array $members Array of member arrays, each with user_id (required) and optional channel_role
128+
* @return StreamResponse
129+
* @throws StreamException
130+
*/
131+
public function hide(array $filter, array $members): StreamResponse
132+
{
133+
$options = [
134+
"operation" => "hide",
135+
"filter" => $filter,
136+
"members" => $members,
137+
];
138+
return $this->client->updateChannelsBatch($options);
139+
}
140+
141+
/**
142+
* Shows channels matching the filter for the specified members.
143+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
144+
* @param array $members Array of member arrays, each with user_id (required) and optional channel_role
145+
* @return StreamResponse
146+
* @throws StreamException
147+
*/
148+
public function show(array $filter, array $members): StreamResponse
149+
{
150+
$options = [
151+
"operation" => "show",
152+
"filter" => $filter,
153+
"members" => $members,
154+
];
155+
return $this->client->updateChannelsBatch($options);
156+
}
157+
158+
/**
159+
* Archives channels matching the filter for the specified members.
160+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
161+
* @param array $members Array of member arrays, each with user_id (required) and optional channel_role
162+
* @return StreamResponse
163+
* @throws StreamException
164+
*/
165+
public function archive(array $filter, array $members): StreamResponse
166+
{
167+
$options = [
168+
"operation" => "archive",
169+
"filter" => $filter,
170+
"members" => $members,
171+
];
172+
return $this->client->updateChannelsBatch($options);
173+
}
174+
175+
/**
176+
* Unarchives channels matching the filter for the specified members.
177+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
178+
* @param array $members Array of member arrays, each with user_id (required) and optional channel_role
179+
* @return StreamResponse
180+
* @throws StreamException
181+
*/
182+
public function unarchive(array $filter, array $members): StreamResponse
183+
{
184+
$options = [
185+
"operation" => "unarchive",
186+
"filter" => $filter,
187+
"members" => $members,
188+
];
189+
return $this->client->updateChannelsBatch($options);
190+
}
191+
192+
/**
193+
* Updates data on channels matching the filter.
194+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
195+
* @param array $data Data to update (keys: frozen, disabled, custom, team, config_overrides, auto_translation_enabled, auto_translation_language)
196+
* @return StreamResponse
197+
* @throws StreamException
198+
*/
199+
public function updateData(array $filter, array $data): StreamResponse
200+
{
201+
$options = [
202+
"operation" => "updateData",
203+
"filter" => $filter,
204+
"data" => $data,
205+
];
206+
return $this->client->updateChannelsBatch($options);
207+
}
208+
209+
/**
210+
* Adds filter tags to channels matching the filter.
211+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
212+
* @param array $tags Array of filter tag strings
213+
* @return StreamResponse
214+
* @throws StreamException
215+
*/
216+
public function addFilterTags(array $filter, array $tags): StreamResponse
217+
{
218+
$options = [
219+
"operation" => "addFilterTags",
220+
"filter" => $filter,
221+
"filter_tags_update" => $tags,
222+
];
223+
return $this->client->updateChannelsBatch($options);
224+
}
225+
226+
/**
227+
* Removes filter tags from channels matching the filter.
228+
* @param array $filter Filter to match channels (keys: cids, types, filter_tags)
229+
* @param array $tags Array of filter tag strings
230+
* @return StreamResponse
231+
* @throws StreamException
232+
*/
233+
public function removeFilterTags(array $filter, array $tags): StreamResponse
234+
{
235+
$options = [
236+
"operation" => "removeFilterTags",
237+
"filter" => $filter,
238+
"filter_tags_update" => $tags,
239+
];
240+
return $this->client->updateChannelsBatch($options);
241+
}
242+
}

lib/GetStream/StreamChat/Client.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,25 @@ public function deleteChannels(array $cids, ?array $options = null): StreamRespo
432432
return $this->post("channels/delete", $options);
433433
}
434434

435+
/** Updates channels in batch based on the provided options.
436+
* This is an asynchronous operation and the returned value is a task Id.
437+
* You can use `getTask` to check the status of the task.
438+
* @link https://getstream.io/chat/docs/php/channel_update/?language=php
439+
* @throws StreamException
440+
*/
441+
public function updateChannelsBatch(array $options): StreamResponse
442+
{
443+
return $this->put("channels/batch", $options);
444+
}
445+
446+
/** Returns a ChannelBatchUpdater instance for batch channel operations.
447+
* @return ChannelBatchUpdater
448+
*/
449+
public function channelBatchUpdater(): ChannelBatchUpdater
450+
{
451+
return new ChannelBatchUpdater($this);
452+
}
453+
435454
/** Creates a guest user.
436455
* @link https://getstream.io/chat/docs/php/authless_users/?language=php
437456
* @throws StreamException

0 commit comments

Comments
 (0)