Skip to content

Commit adce931

Browse files
Pin archive fix (#125)
* feat: pin / unpin channels * feat: test php v8.4 as well * fix: linting * fix: disable 8.4 for now * fix: debugging * fix: CI * fix: ci * fix: channelId * fix: null channelId * fix: tests --------- Co-authored-by: Lennart Kuijs <[email protected]>
1 parent 1098037 commit adce931

File tree

3 files changed

+119
-45
lines changed

3 files changed

+119
-45
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
return $config->setRules([
1010
'@PSR2' => true,
1111
'array_syntax' => ['syntax' => 'short'],
12+
'nullable_type_declaration_for_default_null_value' => true,
1213
])
1314
->setFinder($finder)
1415
;

lib/GetStream/StreamChat/Channel.php

Lines changed: 91 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Channel
3030
private $client;
3131

3232
/** @internal */
33-
public function __construct(Client $client, string $channelTypeName, string $channelId = null, array $data = null)
33+
public function __construct(Client $client, string $channelTypeName, ?string $channelId = null, ?array $data = null)
3434
{
3535
if ($data === null) {
3636
$data = [];
@@ -72,7 +72,7 @@ private static function addUser(array $payload, string $userId)
7272
* @link https://getstream.io/chat/docs/php/send_message/?language=php
7373
* @throws StreamException
7474
*/
75-
public function sendMessage(array $message, string $userId, string $parentId = null, array $options = null): StreamResponse
75+
public function sendMessage(array $message, string $userId, ?string $parentId = null, ?array $options = null): StreamResponse
7676
{
7777
if ($options === null) {
7878
$options = [];
@@ -139,7 +139,7 @@ public function deleteReaction(string $messageId, string $reactionType, string $
139139
* @link https://getstream.io/chat/docs/php/creating_channels/?language=php
140140
* @throws StreamException
141141
*/
142-
public function create(string $userId, array $members = null): StreamResponse
142+
public function create(string $userId, ?array $members = null): StreamResponse
143143
{
144144
$this->customData['created_by'] = ["id" => $userId];
145145
$response = $this->query([
@@ -185,7 +185,7 @@ public function query(array $options): StreamResponse
185185
* @link https://getstream.io/chat/docs/php/query_members/?language=php
186186
* @throws StreamException
187187
*/
188-
public function queryMembers(array $filterConditions = null, array $sort = null, array $options = null): StreamResponse
188+
public function queryMembers(?array $filterConditions = null, ?array $sort = null, ?array $options = null): StreamResponse
189189
{
190190
if ($options === null) {
191191
$options = [];
@@ -216,7 +216,7 @@ public function queryMembers(array $filterConditions = null, array $sort = null,
216216
* @link https://getstream.io/chat/docs/php/channel_update/?language=php
217217
* @throws StreamException
218218
*/
219-
public function update(array $channelData = null, array $updateMessage = null, array $options = null): StreamResponse
219+
public function update(?array $channelData = null, ?array $updateMessage = null, ?array $options = null): StreamResponse
220220
{
221221
$payload = [
222222
"data" => $channelData,
@@ -234,7 +234,7 @@ public function update(array $channelData = null, array $updateMessage = null, a
234234
* @link https://getstream.io/chat/docs/php/channel_update/?language=php
235235
* @throws StreamException
236236
*/
237-
public function updatePartial(array $set = null, array $unset = null): StreamResponse
237+
public function updatePartial(?array $set = null, ?array $unset = null): StreamResponse
238238
{
239239
if ($set === null && $unset === null) {
240240
throw new StreamException("set or unset is required");
@@ -260,7 +260,7 @@ public function delete(): StreamResponse
260260
* @link https://getstream.io/chat/docs/php/truncate_channel/?language=php
261261
* @throws StreamException
262262
*/
263-
public function truncate(array $options = null): StreamResponse
263+
public function truncate(?array $options = null): StreamResponse
264264
{
265265
if ($options === null) {
266266
$options = (object)[];
@@ -276,7 +276,7 @@ public function truncate(array $options = null): StreamResponse
276276
* @param array|null $options
277277
* @return StreamResponse
278278
*/
279-
public function assignRoles(array $roles, array $message = null, array $options = null): StreamResponse
279+
public function assignRoles(array $roles, ?array $message = null, ?array $options = null): StreamResponse
280280
{
281281
$opts = [
282282
"assign_roles" => $roles
@@ -293,7 +293,7 @@ public function assignRoles(array $roles, array $message = null, array $options
293293
* @link https://getstream.io/chat/docs/php/channel_members/?language=php
294294
* @throws StreamException
295295
*/
296-
public function addMembers(array $userIds, array $options = null): StreamResponse
296+
public function addMembers(array $userIds, ?array $options = null): StreamResponse
297297
{
298298
$payload = [
299299
"add_members" => $userIds
@@ -345,7 +345,7 @@ public function demoteModerators(array $userIds): StreamResponse
345345
* @link https://getstream.io/chat/docs/php/send_message/?language=php
346346
* @throws StreamException
347347
*/
348-
public function markRead(string $userId, array $data = null): StreamResponse
348+
public function markRead(string $userId, ?array $data = null): StreamResponse
349349
{
350350
if ($data === null) {
351351
$data = [];
@@ -376,7 +376,7 @@ public function getReactions(string $messageId, array $options = []): StreamResp
376376
* @link https://getstream.io/chat/docs/php/moderation/?language=php
377377
* @throws StreamException
378378
*/
379-
public function banUser(string $targetId, array $options = null): StreamResponse
379+
public function banUser(string $targetId, ?array $options = null): StreamResponse
380380
{
381381
if ($options === null) {
382382
$options = [];
@@ -390,7 +390,7 @@ public function banUser(string $targetId, array $options = null): StreamResponse
390390
* @link https://getstream.io/chat/docs/php/moderation/?language=php
391391
* @throws StreamException
392392
*/
393-
public function unbanUser(string $targetId, array $options = null): StreamResponse
393+
public function unbanUser(string $targetId, ?array $options = null): StreamResponse
394394
{
395395
if ($options === null) {
396396
$options = [];
@@ -404,7 +404,7 @@ public function unbanUser(string $targetId, array $options = null): StreamRespon
404404
* @link https://getstream.io/chat/docs/php/channel_invites/?language=php
405405
* @throws StreamException
406406
*/
407-
public function inviteMembers(array $userIds, array $message = null): StreamResponse
407+
public function inviteMembers(array $userIds, ?array $message = null): StreamResponse
408408
{
409409
$payload = [
410410
"invites" => $userIds,
@@ -418,7 +418,7 @@ public function inviteMembers(array $userIds, array $message = null): StreamResp
418418
* @link https://getstream.io/chat/docs/php/channel_invites/?language=php
419419
* @throws StreamException
420420
*/
421-
public function acceptInvite(string $userId, array $options = null): StreamResponse
421+
public function acceptInvite(string $userId, ?array $options = null): StreamResponse
422422
{
423423
if ($options === null) {
424424
$options = [];
@@ -434,7 +434,7 @@ public function acceptInvite(string $userId, array $options = null): StreamRespo
434434
* @link https://getstream.io/chat/docs/php/channel_invites/?language=php
435435
* @throws StreamException
436436
*/
437-
public function rejectInvite(string $userId, array $options = null): StreamResponse
437+
public function rejectInvite(string $userId, ?array $options = null): StreamResponse
438438
{
439439
if ($options === null) {
440440
$options = [];
@@ -452,7 +452,7 @@ public function rejectInvite(string $userId, array $options = null): StreamRespo
452452
* @link https://getstream.io/chat/docs/php/file_uploads/?language=php
453453
* @throws StreamException
454454
*/
455-
public function sendFile(string $url, string $name, array $user, string $contentType = null): StreamResponse
455+
public function sendFile(string $url, string $name, array $user, ?string $contentType = null): StreamResponse
456456
{
457457
return $this->client->sendFile($this->getUrl() . '/file', $url, $name, $user, $contentType);
458458
}
@@ -465,7 +465,7 @@ public function sendFile(string $url, string $name, array $user, string $content
465465
* @link https://getstream.io/chat/docs/php/file_uploads/?language=php
466466
* @throws StreamException
467467
*/
468-
public function sendImage(string $url, string $name, array $user, string $contentType = null): StreamResponse
468+
public function sendImage(string $url, string $name, array $user, ?string $contentType = null): StreamResponse
469469
{
470470
return $this->client->sendFile($this->getUrl() . '/image', $url, $name, $user, $contentType);
471471
}
@@ -520,7 +520,7 @@ public function show(string $userId): StreamResponse
520520
* @link https://getstream.io/chat/docs/php/muting_channels/?language=php
521521
* @throws StreamException
522522
*/
523-
public function mute(string $userId, int $expirationInMilliSeconds = null): StreamResponse
523+
public function mute(string $userId, ?int $expirationInMilliSeconds = null): StreamResponse
524524
{
525525
$postData = [
526526
"user_id" => $userId,
@@ -544,4 +544,77 @@ public function unmute(string $userId): StreamResponse
544544
];
545545
return $this->client->post("moderation/unmute/channel", $postData);
546546
}
547+
548+
/** Pins the channel for the user.
549+
* @throws StreamException
550+
*/
551+
public function pin(string $userId): StreamResponse
552+
{
553+
if (empty($userId)) {
554+
throw new StreamException("user ID must be not empty");
555+
}
556+
557+
$payload = [
558+
"set" => [
559+
"pinned" => true
560+
]
561+
];
562+
563+
return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload);
564+
}
565+
566+
567+
/** Unpins the channel for the user.
568+
* @throws StreamException
569+
*/
570+
public function unpin(string $userId): StreamResponse
571+
{
572+
if (empty($userId)) {
573+
throw new StreamException("user ID must be not empty");
574+
}
575+
576+
$payload = [
577+
"set" => [
578+
"pinned" => false
579+
]
580+
];
581+
582+
return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload);
583+
}
584+
585+
/** Archives the channel for the user.
586+
* @throws StreamException
587+
*/
588+
public function archive(string $userId): StreamResponse
589+
{
590+
if (empty($userId)) {
591+
throw new StreamException("user ID must be not empty");
592+
}
593+
594+
$payload = [
595+
"set" => [
596+
"archived" => true
597+
]
598+
];
599+
600+
return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload);
601+
}
602+
603+
/** Unarchives the channel for the user.
604+
* @throws StreamException
605+
*/
606+
public function unarchive(string $userId): StreamResponse
607+
{
608+
if (empty($userId)) {
609+
throw new StreamException("user ID must be not empty");
610+
}
611+
612+
$payload = [
613+
"set" => [
614+
"archived" => false
615+
]
616+
];
617+
618+
return $this->client->patch($this->getUrl() . "/member/" . urlencode($userId), $payload);
619+
}
547620
}

0 commit comments

Comments
 (0)