From d2708340350cca70ec396ef4f5947f00d66ae076 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 13 Feb 2022 07:02:34 +0000 Subject: [PATCH] fix for storage event refactor --- src/Appwrite/Messaging/Adapter/Realtime.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Appwrite/Messaging/Adapter/Realtime.php b/src/Appwrite/Messaging/Adapter/Realtime.php index aec538954..9e4d8c86a 100644 --- a/src/Appwrite/Messaging/Adapter/Realtime.php +++ b/src/Appwrite/Messaging/Adapter/Realtime.php @@ -240,7 +240,7 @@ class Realtime extends Adapter * @param Document|null $project * @return array */ - public static function fromPayload(string $event, Document $payload, Document $project = null, Document $collection = null): array + public static function fromPayload(string $event, Document $payload, Document $project = null, Document $collection = null, Document $bucket = null): array { $channels = []; $roles = []; @@ -285,7 +285,7 @@ class Realtime extends Adapter break; case strpos($event, 'database.documents.') === 0: if ($collection->isEmpty()) { - throw new \Exception('Collection need to be passed to to Realtime for Document events in the Database.'); + throw new \Exception('Collection needs to be passed to Realtime for Document events in the Database.'); } $channels[] = 'documents'; @@ -294,17 +294,14 @@ class Realtime extends Adapter $roles = ($collection->getAttribute('permission') === 'collection') ? $collection->getRead() : $payload->getRead(); - break; - case strpos($event, 'storage.buckets.') === 0: - $channels[] = 'buckets'; - $channels[] = 'buckets.' . $payload->getId(); - $roles = $payload->getRead(); - break; case strpos($event, 'storage.files') === 0: + if($bucket->isEmpty()) { + throw new \Exception('Bucket needs to be pased to Realtime for File events in the Storage.'); + } $channels[] = 'files'; $channels[] = 'buckets.' . $payload->getAttribute('bucketId') . '.files'; - $channels[] = 'files.' . $payload->getId(); + $channels[] = 'buckets.' . $payload.getAttribute('bucketId') . '.files.' . $payload->getId(); $roles = $payload->getRead(); break;