Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit 750151d

Browse files
authored
Merge pull request #192 from appwrite/update-realtime-examples
Update realtime examples
2 parents e66dee3 + 7e6c7a4 commit 750151d

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

app/views/docs/getting-started-for-android.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ val json = response.body?.string()</code></pre>
103103
val realtime = Realtime(client)
104104

105105
realtime.subscribe("files", callback = { response ->
106-
if(response.event == "storage.files.create") {
106+
if(response.events.contains("buckets.*.files.*.create")) {
107107
// Log when a new file is uploaded
108108
print(response.payload.toString());
109109
}
@@ -130,7 +130,7 @@ val json = response.body?.string()
130130
val realtime = Realtime(client)
131131

132132
realtime.subscribe("files", callback = { response ->
133-
if(response.event == "storage.files.create") {
133+
if(response.events.contains("buckets.*.files.*.create")) {
134134
// Log when a new file is uploaded
135135
print(response.payload.toString());
136136
}

app/views/docs/getting-started-for-apple.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ print(user.toMap())
135135
let realtime = Realtime(client: client)
136136

137137
let subscription = realtime.subscribe(channels: ["files"]) { message in
138-
if(message.event == "storage.files.create") {
138+
if(message.events!.contains("buckets.*.files.*.create")) {
139139
// Log when a new file is uploaded
140140
print(String(describing: message.payload))
141141
}
@@ -163,7 +163,7 @@ print(user.toMap())
163163
let realtime = Realtime(client: client)
164164

165165
let subscription = realtime.subscribe(channels: ["files"]) { message in
166-
if(message.event == "storage.files.create") {
166+
if(message.events!.contains("buckets.*.files.*.create")) {
167167
// Log when a new file is uploaded
168168
print(String(describing: message.payload))
169169
}

app/views/docs/getting-started-for-flutter.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ final realtime = Realtime(client);
173173
final subscription = realtime.subscribe(['files']);
174174

175175
subscription.stream.listen((response) {
176-
if(response.event == 'storage.files.create') {
176+
if(response.events.contains('buckets.*.files.*.create') {
177177
// Log when a new file is uploaded
178178
print(response.payload);
179179
}
@@ -209,7 +209,7 @@ final realtime = Realtime(client);
209209
final subscription = realtime.subscribe(['files']);
210210

211211
subscription.stream.listen((response) {
212-
if(response.event == 'storage.files.create') {
212+
if(response.events.contains('buckets.*.files.*.create')) {
213213
// Log when a new file is uploaded
214214
print(response.payload);
215215
}

app/views/docs/getting-started-for-web.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ appwrite
102102
<div class="ide" data-lang="javascript" data-lang-label="Web SDK">
103103
<pre class="line-numbers"><code class="prism language-javascript" data-prism>// Subscribe to files channel
104104
appwrite.subscribe('files', response => {
105-
if(response.event === 'storage.files.create') {
105+
if(response.events.includes('buckets.*.files.*.create')) {
106106
// Log when a new file is uploaded
107107
console.log(response.payload);
108108
}
@@ -130,7 +130,7 @@ appwrite
130130

131131
// Subscribe to files channel
132132
appwrite.subscribe('files', response => {
133-
if(response.event === 'storage.files.create') {
133+
if(response.events.includes('buckets.*.files.*.create')) {
134134
// Log when a new file is uploaded
135135
console.log(response.payload);
136136
}

app/views/docs/realtime.phtml

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ sdk
3636

3737
// Subscribe to files channel
3838
sdk.subscribe('files', response => {
39-
if(response.event === 'storage.files.create') {
39+
if(response.events.includes('buckets.*.files.*.create')) {
4040
// Log when a new file is uploaded
4141
console.log(response.payload);
4242
}
@@ -60,7 +60,7 @@ final realtime = Realtime(client);
6060
final subscription = realtime.subscribe(['files']);
6161

6262
subscription.stream.listen((response) {
63-
if(response.event == 'storage.files.create') {
63+
if(response.events.contains('buckets.*.files.*.create')) {
6464
// Log when a new file is uploaded
6565
print(response.payload);
6666
}
@@ -80,7 +80,7 @@ val realtime = Realtime(client)
8080

8181
// Subscribe to files channel
8282
realtime.subscribe("files", callback = { response ->
83-
if(response.event === "storage.files.create") {
83+
if(response.events.contains("buckets.*.files.*.create")) {
8484
// Log when a new file is uploaded
8585
print(response.payload.toString());
8686
}
@@ -100,7 +100,7 @@ let realtime = Realtime(client: client)
100100

101101
// Subscribe to files channel
102102
let subscription = realtime.subscribe(channels: ["files"]) { message in
103-
if(message.event == "storage.files.create") {
103+
if(message.events!.contains("buckets.*.files.*.create")) {
104104
// Log when a new file is uploaded
105105
print(String(describing: message.payload))
106106
}
@@ -111,7 +111,7 @@ let subscription = realtime.subscribe(channels: ["files"]) { message in
111111

112112
<p>To subscribe to updates from different resources, you need to specify one or more channels. The <a href="/docs/realtime#channels">channels</a> 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.</p>
113113

114-
<p>If you listen to all documents from a collection by subscribing to the <span class="tag">collections.[ID].documents</span> channel, you can use the <b>event</b> attribute in the callback to distinguish whether a new document was created or an existing one was updated.</p>
114+
<p>If you subscribe to a channel, you will receive callbacks for a variety of events related to the channel. The <b>events</b> attribute in the callback can be used to filter and respond to specific events in a channel.</p>
115115

116116
<p>All possible events can be found <a href="/docs/webhooks#events">here</a>.</p>
117117

@@ -320,13 +320,13 @@ subscription.close()</code></pre>
320320
<tbody>
321321
<tr>
322322
<td data-title="Name: ">
323-
event
323+
events
324324
</td>
325325
<td data-title="Type: ">
326-
string
326+
string[]
327327
</td>
328328
<td data-title="Description: ">
329-
The <a href="/docs/webhooks#events">system event</a> that triggered this update.
329+
The <a href="/docs/webhooks#events">system events</a> that triggered this update.
330330
</td>
331331
</tr>
332332
<tr>
@@ -371,19 +371,35 @@ subscription.close()</code></pre>
371371

372372
<div class="ide margin-bottom" data-lang="json" data-lang-label="JSON">
373373
<pre class="line-numbers"><code class="prism language-json" data-prism>{
374-
"event": "database.documents.update",
374+
"events": [
375+
"collections.user.documents.627a95c0785cc5c7fff2.delete",
376+
"collections.*.documents.*.delete",
377+
"collections.user.documents.*.delete",
378+
"collections.*.documents.627a95c0785cc5c7fff2.delete",
379+
"collections.user.documents.627a95c0785cc5c7fff2",
380+
"collections.*.documents.*",
381+
"collections.user.documents.*",
382+
"collections.*.documents.627a95c0785cc5c7fff2",
383+
"collections.user",
384+
"collections.*"
385+
],
375386
"channels": [
376387
"documents",
377-
"documents.[DOCUMENT_ID]",
378-
"collections.[COLLECTION_ID].documents"
388+
"collections.user.documents",
389+
"collections.user.documents.627a95c0785cc5c7fff2"
379390
],
380-
"timestamp": 1629719169,
391+
"timestamp": 1653957271,
381392
"payload": {
382-
"$id": "[DOCUMENT_ID]",
383-
"$collection": "[COLLECTION_ID]",
384-
"$permissions": [],
385-
"attribute1": "lorem",
386-
"attribute2": 2030
393+
"field1": "lorem ipsum",
394+
"field2": [],
395+
"$read": [
396+
"user:627a958ded6424a98a9f"
397+
],
398+
"$write": [
399+
"user:627a958ded6424a98a9f"
400+
],
401+
"$id": "627a95c0785cc5c7fff2",
402+
"$collection": "example-collection"
387403
}
388404
}</code></pre>
389405
</div>

0 commit comments

Comments
 (0)