Quellcode durchsuchen

:sparkles: grabbing chat history | SIIMEE-T-82

tags/0.0.3^2
j vor 3 Jahren
Ursprung
Commit
c2c85f5235

+ 0
- 10
frontend/src/components/ProfileCardList.vue Datei anzeigen

12
 
12
 
13
 <script setup>
13
 <script setup>
14
 import { ref } from 'vue'
14
 import { ref } from 'vue'
15
-import { currentProfile } from '../services'
16
 import { cardAspects } from '../entities'
15
 import { cardAspects } from '../entities'
17
 import ProfileCard from './ProfileCard.vue'
16
 import ProfileCard from './ProfileCard.vue'
18
 
17
 
33
         ],
32
         ],
34
     },
33
     },
35
 })
34
 })
36
-
37
-/**
38
- * publish a new message to the chatter with the channel and the message & title is optional
39
- */
40
-const subscribeToChannel = async channelName => {
41
-    // You MUST send chatter channels as an array in an object
42
-    const channels = [channelName]
43
-    currentProfile.chatter.subscribe({ channels })
44
-}
45
 </script>
35
 </script>
46
 
36
 
47
 <style lang="sass">
37
 <style lang="sass">

+ 30
- 3
frontend/src/services/chat.service.js Datei anzeigen

101
         this.subscribe({ channels: this._subscriptions })
101
         this.subscribe({ channels: this._subscriptions })
102
         return this.subscriptions
102
         return this.subscriptions
103
     }
103
     }
104
+    async getHistory(channel, count = 10) {
105
+        console.warn('[chatter] grabbing history for channel:', channel)
106
+        let pastMessages = null
107
+        try {
108
+            pastMessages = await this.provider.fetchMessages({
109
+                channels: [channel],
110
+                count: count,
111
+                includeMessageType: true,
112
+                includeUUID: true,
113
+                includeMeta: true,
114
+                includeMessageActions: false,
115
+            })
116
+        } catch (error) {
117
+            console.error('[chatter]', error)
118
+        }
119
+        const channelHistory = pastMessages.channels[channel]
120
+        console.log('channelHistory :>> ', channelHistory)
121
+        return channelHistory
122
+            ? channelHistory.map(msg => ({
123
+                  publisher: msg.uuid,
124
+                  message: new ChatMessage(msg.message.description),
125
+                  timetoken: msg.timetoken,
126
+              }))
127
+            : []
128
+    }
104
     /**
129
     /**
105
      * Send a message to a channel
130
      * Send a message to a channel
106
      * example = new ChatMessage({ title: 'example', description: 'ni' })
131
      * example = new ChatMessage({ title: 'example', description: 'ni' })
118
     /**
143
     /**
119
      * Subscribe to a channels
144
      * Subscribe to a channels
120
      * Facade so we can hide provider specific methods
145
      * Facade so we can hide provider specific methods
121
-     * @param {array} channels
146
+     * @param {array} channels grouping name
122
      */
147
      */
123
     subscribe({ channels }) {
148
     subscribe({ channels }) {
124
         _providerMethods.subscribe({ channels })
149
         _providerMethods.subscribe({ channels })
130
     _listenFor({ listeners }) {
155
     _listenFor({ listeners }) {
131
         _providerMethods.listen(listeners)
156
         _providerMethods.listen(listeners)
132
     }
157
     }
133
-    //  step 2: build the this.subscriptions array from the this.groupings object
134
-    // fetch all groupings for this profile and then store them in the chatter groupings object for reference
158
+    /**
159
+     * Get all groupings for this profile and
160
+     * then store them as subscriptions
161
+     */
135
     async _setupAllChannels(groupings) {
162
     async _setupAllChannels(groupings) {
136
         groupings.forEach(grouping => {
163
         groupings.forEach(grouping => {
137
             this._subscriptions.push(grouping.grouping_name)
164
             this._subscriptions.push(grouping.grouping_name)

+ 28
- 30
frontend/src/utils/db.js Datei anzeigen

21
 class Connector {
21
 class Connector {
22
     constructor() {
22
     constructor() {
23
         this.apiPrefix = prefix
23
         this.apiPrefix = prefix
24
+        this._verbs = {
25
+            get: 'GET',
26
+            post: 'POST',
27
+            patch: 'PATCH',
28
+        }
24
     }
29
     }
25
-    async get(endpoint) {
30
+    _makeHeader({ method, payload }) {
26
         const header = { ...headerTemplate }
31
         const header = { ...headerTemplate }
27
-        header.method = 'GET'
32
+        header.method = method
33
+        if (payload) {
34
+            header.body = JSON.stringify(payload)
35
+        }
36
+        return header
37
+    }
38
+    async _tryFetch({ endpoint, header }) {
28
         try {
39
         try {
29
-            // console.log(`${remote}${endpoint}`)
30
-            let res = await fetch(`${remote}${endpoint}`, header)
40
+            const res = await fetch(`${remote}${endpoint}`, header)
31
             if (!res.ok) {
41
             if (!res.ok) {
32
                 throw Error(res.statusText)
42
                 throw Error(res.statusText)
33
             }
43
             }
37
             console.error(`[API Util]: ${error}\nroute:`, endpoint)
47
             console.error(`[API Util]: ${error}\nroute:`, endpoint)
38
         }
48
         }
39
     }
49
     }
50
+    async get(endpoint) {
51
+        return await this._tryFetch({
52
+            endpoint,
53
+            header: this._makeHeader(this._verbs.get),
54
+        })
55
+    }
40
     async post(endpoint, payload = {}) {
56
     async post(endpoint, payload = {}) {
41
-        const header = { ...headerTemplate }
42
-        header.method = 'POST'
43
-        header.body = JSON.stringify(payload)
44
-        try {
45
-            let res = await fetch(`${remote}${endpoint}`, header)
46
-            if (!res.ok) {
47
-                throw Error(res.statusText)
48
-            }
49
-            const jsonRes = await res.json()
50
-            return jsonRes.data
51
-        } catch (error) {
52
-            console.error(error)
53
-        }
57
+        return await this._tryFetch({
58
+            endpoint,
59
+            header: this._makeHeader(this._verbs.post, payload),
60
+        })
54
     }
61
     }
55
     async patch(endpoint, payload = {}) {
62
     async patch(endpoint, payload = {}) {
56
-        const header = { ...headerTemplate }
57
-        header.method = 'PATCH'
58
-        header.body = JSON.stringify(payload)
59
-        try {
60
-            let res = await fetch(`${remote}${endpoint}`, header)
61
-            if (!res.ok) {
62
-                throw Error(res.statusText)
63
-            }
64
-            const jsonRes = await res.json()
65
-            return jsonRes.data
66
-        } catch (error) {
67
-            console.error(error)
68
-        }
63
+        return await this._tryFetch({
64
+            endpoint,
65
+            header: this._makeHeader(this._verbs.patch, payload),
66
+        })
69
     }
67
     }
70
 
68
 
71
     /** !: DEV ONLY */
69
     /** !: DEV ONLY */

+ 0
- 4
frontend/src/utils/index.js Datei anzeigen

1
 import Joi from 'joi'
1
 import Joi from 'joi'
2
-import { Connector } from './db.js'
3
 import { SurveyFactory } from './survey.js'
2
 import { SurveyFactory } from './survey.js'
4
 import { possible } from './lang.js'
3
 import { possible } from './lang.js'
5
 import { pidMixin, profileMixin } from './mixins.js'
4
 import { pidMixin, profileMixin } from './mixins.js'
31
     '97075',
30
     '97075',
32
 ]
31
 ]
33
 
32
 
34
-const api = new Connector('kittens')
35
-
36
 const validatorMapping = {
33
 const validatorMapping = {
37
     'input-string': Joi.string(),
34
     'input-string': Joi.string(),
38
     'tag-cloud': Joi.string(),
35
     'tag-cloud': Joi.string(),
133
 }
130
 }
134
 
131
 
135
 export {
132
 export {
136
-    api,
137
     validatorMapping,
133
     validatorMapping,
138
     surveyFactory,
134
     surveyFactory,
139
     makeKebob,
135
     makeKebob,

+ 9
- 34
frontend/src/utils/lang.js Datei anzeigen

17
         distance: 'distance',
17
         distance: 'distance',
18
         blurb: 'blurb',
18
         blurb: 'blurb',
19
         image: 'image',
19
         image: 'image',
20
-    }
20
+    },
21
 }
21
 }
22
 
22
 
23
 const aspectResponses = {
23
 const aspectResponses = {
29
         mostly: 'mostly',
29
         mostly: 'mostly',
30
         often: 'often',
30
         often: 'often',
31
         everytime: 'everytime',
31
         everytime: 'everytime',
32
-    }
32
+    },
33
 }
33
 }
34
 
34
 
35
 const possible = {}
35
 const possible = {}
55
         'casually_browsing',
55
         'casually_browsing',
56
     ],
56
     ],
57
     // key 11
57
     // key 11
58
-    presence: [
59
-        'remote',
60
-        'in_person',
61
-        'hybrid',
62
-        'flexible'
63
-    ],
58
+    presence: ['remote', 'in_person', 'hybrid', 'flexible'],
64
     // key 10
59
     // key 10
65
-    duration: [
66
-        'full-time',
67
-        'part-time',
68
-        'contract',
69
-        'flexible',
70
-    ],
60
+    duration: ['full-time', 'part-time', 'contract', 'flexible'],
71
     // Experience and roles concat, key: 14
61
     // Experience and roles concat, key: 14
72
-    experience: [
73
-        'associate',
74
-        'junior',
75
-        'mid-level',
76
-        'senior',
77
-        'staff',
78
-    ],
62
+    experience: ['associate', 'junior', 'mid-level', 'senior', 'staff'],
79
     roles: {
63
     roles: {
80
         type: [
64
         type: [
81
             'back-end',
65
             'back-end',
96
             'manager',
80
             'manager',
97
             'technician',
81
             'technician',
98
         ],
82
         ],
99
-        candidate: [
100
-            'hiring_manager',
101
-            'recruiter',
102
-        ]
83
+        candidate: ['hiring_manager', 'recruiter'],
103
     },
84
     },
104
-    pronouns: [
105
-        'she/her',
106
-        'she/they',
107
-        'he/him',
108
-        'he/they',
109
-        'they/them',
110
-    ],
85
+    pronouns: ['she/her', 'she/they', 'he/him', 'he/they', 'they/them'],
111
     image: [],
86
     image: [],
112
     zipcode: [],
87
     zipcode: [],
113
-    blurb: []
88
+    blurb: [],
114
 }
89
 }
115
 
90
 
116
-export { allSteps, aspectResponses, possible }
91
+export { allSteps, aspectResponses, possible, DELIMITER }

+ 23
- 14
frontend/src/views/ChatView.vue Datei anzeigen

1
 <template lang="pug">
1
 <template lang="pug">
2
 main.view--chat
2
 main.view--chat
3
     header.mb6(v-if='profile && grouping')
3
     header.mb6(v-if='profile && grouping')
4
-        h3 chatting with: {{ target.profile_id }}
5
-        p {{ grouping.profile.user_name }}
6
-        p {{ grouping.profile.user_email }}
7
-        p(v-if='!grouping._loading') {{ grouping.revealed }}
4
+        h3 chatting with:
5
+        p {{ target.profile_id }} | {{ grouping.profile.user_name }} | {{ grouping.profile.user_email }}
6
+
7
+        h3 logged in as:
8
+        p {{ profile.id }} | {{ profile._profile.user_name }} | {{ profile._profile.user_email }}
8
         //- p subscriptions: {{ profile.chatter.subscriptions }}
9
         //- p subscriptions: {{ profile.chatter.subscriptions }}
10
+        hr
9
 
11
 
10
-        .w-flex.column
11
-            p reveal: {{ grouping.revealed }}
12
+        .w-flex.column(v-if='!grouping._loading')
13
+            p you revealed: {{ grouping.revealed[profile.id.value].map(tag => tag.description) }}
12
             .w-flex.row
14
             .w-flex.row
13
-                button(@click='reveal(7)') my name
14
-                button(@click='reveal(8)') my email
15
+                button(@click='reveal(7)') reveal my name
16
+                button(@click='reveal(8)') reveal my email
17
+            p they revealed: {{ grouping.revealed[target.profile_id].map(tag => tag.description) }}
15
 
18
 
16
     article
19
     article
17
         template(v-if='isLoading')
20
         template(v-if='isLoading')
22
                 template(v-for='chatmessage in messages')
25
                 template(v-for='chatmessage in messages')
23
                     li(
26
                     li(
24
                         :class='[{ me: chatmessage.publisher == profile.id.value }, chatmessage.publisher]'
27
                         :class='[{ me: chatmessage.publisher == profile.id.value }, chatmessage.publisher]'
25
-                        v-if='chatmessage.message.description'
28
+                        v-if='chatmessage.message && chatmessage.message.description'
26
                     )
29
                     )
27
                         ChatBubble(
30
                         ChatBubble(
28
                             :message='chatmessage.message.description'
31
                             :message='chatmessage.message.description'
41
     MainNav
44
     MainNav
42
 </template>
45
 </template>
43
 
46
 
44
-<script>
47
+<script lang="js">
45
 import ChatBubble from '../components/ChatBubble.vue'
48
 import ChatBubble from '../components/ChatBubble.vue'
46
 import { currentProfile } from '../services'
49
 import { currentProfile } from '../services'
47
 import { mixins } from '../utils'
50
 import { mixins } from '../utils'
54
         target: null,
57
         target: null,
55
         toSend: '',
58
         toSend: '',
56
         messages: [],
59
         messages: [],
57
-        openDrawer: null,
58
         grouping: null,
60
         grouping: null,
59
     }),
61
     }),
60
     watch: {
62
     watch: {
61
-        profile() {
63
+        async profile() {
62
             this.loadTargetProfile()
64
             this.loadTargetProfile()
65
+            currentProfile._loading.value = true
66
+            this.messages = await currentProfile.chatter.getHistory(this.grouping.grouping_name)
63
             currentProfile.chatter.setOnMessage(this._onMessage)
67
             currentProfile.chatter.setOnMessage(this._onMessage)
68
+            currentProfile._loading.value = false
64
         },
69
         },
65
     },
70
     },
66
-    created() {
71
+    async created() {
67
         this.loadTargetProfile()
72
         this.loadTargetProfile()
68
-        currentProfile.chatter.setOnMessage(this._onMessage)
73
+        currentProfile._loading.value = true
69
         this.grouping = this.getGrouping()
74
         this.grouping = this.getGrouping()
75
+        this.messages = await currentProfile.chatter.getHistory(this.grouping.grouping_name)
76
+        console.log('this.messages :>> ', this.messages)
77
+        currentProfile.chatter.setOnMessage(this._onMessage)
78
+        currentProfile._loading.value = false
70
     },
79
     },
71
     methods: {
80
     methods: {
72
         async reveal(tagId) {
81
         async reveal(tagId) {

Laden…
Abbrechen
Speichern