summaryrefslogtreecommitdiff
path: root/demo/components/private-messaging.js
diff options
context:
space:
mode:
authortheia2023-02-03 17:07:17 -0500
committertheia2023-02-03 17:07:17 -0500
commitc11da4dd7e082fd54562c3676dc27f4a0e8e3048 (patch)
tree669190c4035926b8e5d6d3349a0b74414eb87989 /demo/components/private-messaging.js
parent486de89b002b996e2fc8e0538eb7e25df2d18541 (diff)
Private messaging working
Diffstat (limited to 'demo/components/private-messaging.js')
-rw-r--r--demo/components/private-messaging.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/demo/components/private-messaging.js b/demo/components/private-messaging.js
new file mode 100644
index 0000000..61f783b
--- /dev/null
+++ b/demo/components/private-messaging.js
@@ -0,0 +1,66 @@
+import Chat from './chat.js'
+import {Name} from './name.js'
+
+export default {
+
+ data: ()=> ({
+ recipient: null,
+ message: ''
+ }),
+
+ methods: {
+ messageObjects: Chat.methods.messageObjects,
+ chatObjects(objects) {
+ return this.messageObjects(objects).filter(o=>
+ '_to' in o && o._to.length == 1)
+ },
+
+ sendMessage() {
+ if (!this.message) return
+ this.$graffitiUpdate({
+ message: this.message,
+ timestamp: Date.now(),
+ _to: [this.recipient],
+ _tags: [this.$graffitiMyID, this.recipient]
+ })
+ this.message = ''
+ }
+ },
+
+ template: `
+ Send private message to:
+ <graffiti-objects :tags="['demo']" v-slot="{objects}">
+ <select v-model="recipient">
+ <option v-for="id in objects.notMine.authors" :value="id">
+ <Name :of="id">
+ </option>
+ </select>
+ </graffiti-objects>
+
+ <form @submit.prevent="sendMessage">
+ <input v-model="message">
+ <input type="submit" value="Submit"/>
+ </form>
+
+ <graffiti-objects :tags="[$graffitiMyID]" v-slot="{objects}">
+
+ <h3>My Outbox</h3>
+
+ <ul v-for="object in chatObjects(objects).mine">
+ <li>
+ To <em><Name :of="object._to[0]"/></em>:
+ {{ object.message }}
+ </li>
+ </ul>
+
+ <h3>My Inbox</h3>
+
+ <ul v-for="object in chatObjects(objects).notMine">
+ <li>
+ From <em><Name :of="object._by"/></em>:
+ {{ object.message }}
+ </li>
+ </ul>
+
+ </graffiti-objects>`
+}