From ab07cbd4b486da849adfb22b4e25d66e3f6d8289 Mon Sep 17 00:00:00 2001 From: Wen Yu Ge Date: Mon, 30 May 2022 17:03:43 -0400 Subject: [PATCH 1/5] update getting started for flutter and web --- app/views/docs/getting-started-for-flutter.phtml | 4 ++-- app/views/docs/getting-started-for-web.phtml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/docs/getting-started-for-flutter.phtml b/app/views/docs/getting-started-for-flutter.phtml index 0a36aef7f..fd48b0f6f 100644 --- a/app/views/docs/getting-started-for-flutter.phtml +++ b/app/views/docs/getting-started-for-flutter.phtml @@ -173,7 +173,7 @@ final realtime = Realtime(client); final subscription = realtime.subscribe(['files']); subscription.stream.listen((response) { - if(response.event == 'storage.files.create') { + if(response.events.contains('buckets.*.files.*.create') { // Log when a new file is uploaded print(response.payload); } @@ -209,7 +209,7 @@ final realtime = Realtime(client); final subscription = realtime.subscribe(['files']); subscription.stream.listen((response) { - if(response.event == 'storage.files.create') { + if(response.events.contains('buckets.*.files.*.create')) { // Log when a new file is uploaded print(response.payload); } diff --git a/app/views/docs/getting-started-for-web.phtml b/app/views/docs/getting-started-for-web.phtml index 6fd6ccacb..abc774884 100644 --- a/app/views/docs/getting-started-for-web.phtml +++ b/app/views/docs/getting-started-for-web.phtml @@ -102,7 +102,7 @@ appwrite
// Subscribe to files channel
 appwrite.subscribe('files', response => {
-    if(response.event === 'storage.files.create') {
+    if(response.events.includes('buckets.*.files.*.create')) {
         // Log when a new file is uploaded
         console.log(response.payload);
     }
@@ -130,7 +130,7 @@ appwrite
 
 // Subscribe to files channel
 appwrite.subscribe('files', response => {
-    if(response.event === 'storage.files.create') {
+    if(response.events.includes('buckets.*.files.*.create')) {
         // Log when a new file is uploaded
         console.log(response.payload);
     }

From 8a3bec9c2a93ba3e7717d8a7c2131719435b020b Mon Sep 17 00:00:00 2001
From: Wen Yu Ge 
Date: Mon, 30 May 2022 19:09:24 -0400
Subject: [PATCH 2/5] Android example and Apple example updated

---
 app/views/docs/getting-started-for-apple.phtml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/views/docs/getting-started-for-apple.phtml b/app/views/docs/getting-started-for-apple.phtml
index 83feea7cd..e815bc411 100644
--- a/app/views/docs/getting-started-for-apple.phtml
+++ b/app/views/docs/getting-started-for-apple.phtml
@@ -135,7 +135,7 @@ print(user.toMap())
 let realtime = Realtime(client: client)
 
 let subscription = realtime.subscribe(channels: ["files"]) { message in
-    if(message.event == "storage.files.create") {
+    if(message.events.contains("buckets.*.files.*.create")) {
         // Log when a new file is uploaded
         print(String(describing: message.payload))
     }
@@ -163,7 +163,7 @@ print(user.toMap())
 let realtime = Realtime(client: client)
 
 let subscription = realtime.subscribe(channels: ["files"]) { message in
-    if(message.event == "storage.files.create") {
+    if(message.events.contains("buckets.*.files.*.create")) {
         // Log when a new file is uploaded
         print(String(describing: message.payload))
     }

From c494724427662053c54da4b0d7feb0ebbfafce3e Mon Sep 17 00:00:00 2001
From: Wen Yu Ge 
Date: Mon, 30 May 2022 20:58:00 -0400
Subject: [PATCH 3/5] update realtime guide

---
 .../docs/getting-started-for-android.phtml    |  4 +-
 app/views/docs/realtime.phtml                 | 50 ++++++++++++-------
 2 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/app/views/docs/getting-started-for-android.phtml b/app/views/docs/getting-started-for-android.phtml
index 3ad772ac9..8eb239fbb 100644
--- a/app/views/docs/getting-started-for-android.phtml
+++ b/app/views/docs/getting-started-for-android.phtml
@@ -103,7 +103,7 @@ val json = response.body?.string()
val realtime = Realtime(client) realtime.subscribe("files", callback = { response -> - if(response.event == "storage.files.create") { + if(response.events.contains("buckets.*.files.*.create")) { // Log when a new file is uploaded print(response.payload.toString()); } @@ -130,7 +130,7 @@ val json = response.body?.string() val realtime = Realtime(client) realtime.subscribe("files", callback = { response -> - if(response.event == "storage.files.create") { + if(response.events.contains("buckets.*.files.*.create")) { // Log when a new file is uploaded print(response.payload.toString()); } diff --git a/app/views/docs/realtime.phtml b/app/views/docs/realtime.phtml index ba958ef2f..8a7f1feb4 100644 --- a/app/views/docs/realtime.phtml +++ b/app/views/docs/realtime.phtml @@ -36,7 +36,7 @@ sdk // Subscribe to files channel sdk.subscribe('files', response => { - if(response.event === 'storage.files.create') { + if(response.events.includes('buckets.*.files.*.create')) { // Log when a new file is uploaded console.log(response.payload); } @@ -60,7 +60,7 @@ final realtime = Realtime(client); final subscription = realtime.subscribe(['files']); subscription.stream.listen((response) { - if(response.event == 'storage.files.create') { + if(response.events.contains('buckets.*.files.*.create')) { // Log when a new file is uploaded print(response.payload); } @@ -80,7 +80,7 @@ val realtime = Realtime(client) // Subscribe to files channel realtime.subscribe("files", callback = { response -> - if(response.event === "storage.files.create") { + if(response.events.contains("buckets.*.files.*.create")) { // Log when a new file is uploaded print(response.payload.toString()); } @@ -100,7 +100,7 @@ let realtime = Realtime(client: client) // Subscribe to files channel let subscription = realtime.subscribe(channels: ["files"]) { message in - if(message.event == "storage.files.create") { + if(message.events.contains("buckets.*.files.*.create")) { // Log when a new file is uploaded print(String(describing: message.payload)) } @@ -111,7 +111,7 @@ let subscription = realtime.subscribe(channels: ["files"]) { message in

To subscribe to updates from different resources, you need to specify one or more channels. The channels offer a wide and powerful selection that will allow you to listen to all possible resources. This allows you to receive updates not only from the database, but from all the services that Appwrite offers.

-

If you listen to all documents from a collection by subscribing to the collections.[ID].documents channel, you can use the event attribute in the callback to distinguish whether a new document was created or an existing one was updated.

+

If you subscribe to the a channel, you will receive callbacks for a variety of events related to the channel. The events attribute in the callback can be used to filter and respond to specific events in a channel.

All possible events can be found here.

@@ -320,13 +320,13 @@ subscription.close() - event + events - string + string[] - The system event that triggered this update. + The system events that triggered this update. @@ -371,19 +371,35 @@ subscription.close()
{
-    "event": "database.documents.update",
+    "events": [
+        "collections.user.documents.627a95c0785cc5c7fff2.delete",
+        "collections.*.documents.*.delete",
+        "collections.user.documents.*.delete",
+        "collections.*.documents.627a95c0785cc5c7fff2.delete",
+        "collections.user.documents.627a95c0785cc5c7fff2",
+        "collections.*.documents.*",
+        "collections.user.documents.*",
+        "collections.*.documents.627a95c0785cc5c7fff2",
+        "collections.user",
+        "collections.*"
+    ],
     "channels": [
         "documents",
-        "documents.[DOCUMENT_ID]",
-        "collections.[COLLECTION_ID].documents"
+        "collections.user.documents",
+        "collections.user.documents.627a95c0785cc5c7fff2"
     ],
-    "timestamp": 1629719169,
+    "timestamp": 1653957271,
     "payload": {
-        "$id": "[DOCUMENT_ID]",
-        "$collection": "[COLLECTION_ID]",
-        "$permissions": [],
-        "attribute1": "lorem",
-        "attribute2": 2030
+        "field1": "lorem ipsum",
+        "field2": [],
+        "$read": [
+            "user:627a958ded6424a98a9f"
+        ],
+        "$write": [
+            "user:627a958ded6424a98a9f"
+        ],
+        "$id": "627a95c0785cc5c7fff2",
+        "$collection": "example-collection"
     }
 }
From 3ea5ab780efb2fecb380ec3f5268cfe2a410b0c0 Mon Sep 17 00:00:00 2001 From: Wen Yu Ge Date: Tue, 31 May 2022 13:19:38 -0400 Subject: [PATCH 4/5] correct apple examples --- app/views/docs/getting-started-for-apple.phtml | 4 ++-- app/views/docs/realtime.phtml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/docs/getting-started-for-apple.phtml b/app/views/docs/getting-started-for-apple.phtml index e815bc411..5fcf0e9b5 100644 --- a/app/views/docs/getting-started-for-apple.phtml +++ b/app/views/docs/getting-started-for-apple.phtml @@ -135,7 +135,7 @@ print(user.toMap()) let realtime = Realtime(client: client) let subscription = realtime.subscribe(channels: ["files"]) { message in - if(message.events.contains("buckets.*.files.*.create")) { + if(message.events!.contains("buckets.*.files.*.create")) { // Log when a new file is uploaded print(String(describing: message.payload)) } @@ -163,7 +163,7 @@ print(user.toMap()) let realtime = Realtime(client: client) let subscription = realtime.subscribe(channels: ["files"]) { message in - if(message.events.contains("buckets.*.files.*.create")) { + if(message.events!.contains("buckets.*.files.*.create")) { // Log when a new file is uploaded print(String(describing: message.payload)) } diff --git a/app/views/docs/realtime.phtml b/app/views/docs/realtime.phtml index 8a7f1feb4..af1fffd2f 100644 --- a/app/views/docs/realtime.phtml +++ b/app/views/docs/realtime.phtml @@ -111,7 +111,7 @@ let subscription = realtime.subscribe(channels: ["files"]) { message in

To subscribe to updates from different resources, you need to specify one or more channels. The channels offer a wide and powerful selection that will allow you to listen to all possible resources. This allows you to receive updates not only from the database, but from all the services that Appwrite offers.

-

If you subscribe to the a channel, you will receive callbacks for a variety of events related to the channel. The events attribute in the callback can be used to filter and respond to specific events in a channel.

+

If you subscribe to a channel, you will receive callbacks for a variety of events related to the channel. The events attribute in the callback can be used to filter and respond to specific events in a channel.

All possible events can be found here.

From 7e6c7a4a67cebf0c004853f16c3bcf8177afaf73 Mon Sep 17 00:00:00 2001 From: Wen Yu Ge Date: Tue, 31 May 2022 14:23:19 -0400 Subject: [PATCH 5/5] update realtime examples for apple --- app/views/docs/realtime.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/docs/realtime.phtml b/app/views/docs/realtime.phtml index af1fffd2f..7917badc7 100644 --- a/app/views/docs/realtime.phtml +++ b/app/views/docs/realtime.phtml @@ -100,7 +100,7 @@ let realtime = Realtime(client: client) // Subscribe to files channel let subscription = realtime.subscribe(channels: ["files"]) { message in - if(message.events.contains("buckets.*.files.*.create")) { + if(message.events!.contains("buckets.*.files.*.create")) { // Log when a new file is uploaded print(String(describing: message.payload)) }