|
|
@@ -1,5 +1,5 @@
|
|
1
|
1
|
<template lang="pug">
|
|
2
|
|
-main.view--chat.f-col.start.w-full
|
|
|
2
|
+main.view--chat
|
|
3
|
3
|
header
|
|
4
|
4
|
h2 Chat Page
|
|
5
|
5
|
|
|
|
@@ -7,8 +7,21 @@ main.view--chat.f-col.start.w-full
|
|
7
|
7
|
h3 {{ profile.id }}
|
|
8
|
8
|
span chatting with: {{ target.profile_id }}
|
|
9
|
9
|
p subscriptions: {{ profile.chatter.subscriptions }}
|
|
10
|
|
- p target: {{ target }}
|
|
11
|
|
-
|
|
|
10
|
+
|
|
|
11
|
+ ul(id="messages").w-flex.column
|
|
|
12
|
+ li(v-for="message, i in messages" class="pa1")
|
|
|
13
|
+ w-card.w-flex.row
|
|
|
14
|
+ article
|
|
|
15
|
+ p {{ message.message }}
|
|
|
16
|
+ footer
|
|
|
17
|
+ p {{ message.publisher }} | {{ message.timetoken }}
|
|
|
18
|
+ w-button(class="my12" @click="openDrawer = i" text) setting
|
|
|
19
|
+ w-drawer(v-model="openDrawer" absolute width="160px")
|
|
|
20
|
+ p some settings things
|
|
|
21
|
+
|
|
|
22
|
+ input(v-model="toSend" @keyup.enter="sendMessage")
|
|
|
23
|
+ button(@click="sendMessage") send
|
|
|
24
|
+
|
|
12
|
25
|
p(v-else-if="profile.isLoggedIn && !target") No match found between profile {{ $route.params.tid }} and {{profile.id}}...
|
|
13
|
26
|
p(v-else) Loading...
|
|
14
|
27
|
|
|
|
@@ -22,27 +35,51 @@ export default {
|
|
22
|
35
|
name: 'ProfileView',
|
|
23
|
36
|
data: () => ({
|
|
24
|
37
|
target: null,
|
|
|
38
|
+ toSend: '',
|
|
|
39
|
+ messages: [],
|
|
|
40
|
+ openDrawer: null,
|
|
25
|
41
|
}),
|
|
26
|
42
|
computed: {
|
|
27
|
43
|
profile: () => currentProfile,
|
|
28
|
44
|
},
|
|
29
|
45
|
watch: {
|
|
30
|
|
- async profile() {
|
|
31
|
|
- await this.loadTargetProfile(this.$route.params.tid)
|
|
32
|
|
- console.log('target :>> ', this.$route.params.tid)
|
|
|
46
|
+ profile() {
|
|
|
47
|
+ this.loadTargetProfile()
|
|
|
48
|
+ currentProfile.chatter.setOnMessage(this._onMessage)
|
|
33
|
49
|
},
|
|
34
|
50
|
},
|
|
35
|
|
- async created() {
|
|
36
|
|
- await this.loadTargetProfile()
|
|
|
51
|
+ created() {
|
|
|
52
|
+ this.loadTargetProfile()
|
|
|
53
|
+ currentProfile.chatter.setOnMessage(this._onMessage)
|
|
37
|
54
|
},
|
|
38
|
55
|
methods: {
|
|
39
|
|
- async loadTargetProfile() {
|
|
|
56
|
+ /**
|
|
|
57
|
+ * Pubnub message callback fires when message event
|
|
|
58
|
+ * is detected. We define is HERE because we need the
|
|
|
59
|
+ * component state and `this` context
|
|
|
60
|
+ */
|
|
|
61
|
+ _onMessage(e) {
|
|
|
62
|
+ if (!e.message) return
|
|
|
63
|
+ this.messages.push(e)
|
|
|
64
|
+ },
|
|
|
65
|
+ getGrouping() {
|
|
|
66
|
+ return currentProfile.groupings.find(
|
|
|
67
|
+ g => g.profile.profile_id == this.$route.params.tid,
|
|
|
68
|
+ )
|
|
|
69
|
+ },
|
|
|
70
|
+ sendMessage() {
|
|
|
71
|
+ const grouping = this.getGrouping()
|
|
|
72
|
+ currentProfile.chatter.publish(grouping.grouping_name, this.toSend)
|
|
|
73
|
+ this.toSend = ''
|
|
|
74
|
+ },
|
|
|
75
|
+ loadTargetProfile() {
|
|
40
|
76
|
try {
|
|
41
|
|
- const match = this.profile.groupings.find(
|
|
42
|
|
- grouping =>
|
|
43
|
|
- grouping.profile.profile_id == this.$route.params.tid,
|
|
44
|
|
- )
|
|
45
|
|
- this.target = match.profile
|
|
|
77
|
+ const grouping = this.getGrouping()
|
|
|
78
|
+ if (!grouping) {
|
|
|
79
|
+ throw `no match found for ${currentProfile.id.value}`
|
|
|
80
|
+ }
|
|
|
81
|
+
|
|
|
82
|
+ this.target = grouping.profile
|
|
46
|
83
|
} catch (err) {
|
|
47
|
84
|
console.error(err)
|
|
48
|
85
|
}
|