瀏覽代碼

Continued work on storing reveal info in client state

tags/0.0.3^2
tomit4 3 年之前
父節點
當前提交
9cd108b384

+ 5
- 1
backend/lib/routes/membership/reveal.js 查看文件

@@ -55,20 +55,24 @@ module.exports = {
55 55
                 // notification based off of tag_id
56 56
                 const completeProfile = await profileService.getProfilesFor([profile_id], 'participant')
57 57
                 let revealInfo
58
+                let tag_description
58 59
                 if (tag_id == 7) {
59 60
                     revealInfo = completeProfile[0].user_name
61
+                    tag_description = 'name'
60 62
                 } else if (tag_id == 8) {
61 63
                     revealInfo = completeProfile[0].user_email
64
+                    tag_description = 'email'
62 65
                 }
63 66
 
64 67
                 idsInGroup.forEach(profile_id => {
65 68
                     request.server.methods.notify(
66 69
                         `${profile_id}.stonk`,
67 70
                         {
68
-                            name: 'REVEALED INFO',
71
+                            name: 'REVEALED_INFO',
69 72
                             revealed_info: revealInfo,
70 73
                             grouping_id: grouping_id,
71 74
                             tag: tag_id,
75
+                            description: tag_description,
72 76
                             type: 'info',
73 77
                         },
74 78
                         h,

+ 1
- 1
frontend/src/services/chat.service.js 查看文件

@@ -116,7 +116,7 @@ class Chatter {
116 116
         } catch (error) {
117 117
             console.error('[chatter]', error)
118 118
         }
119
-        const channelHistory = pastMessages.channels[channel]
119
+        const channelHistory = pastMessages && pastMessages.channels ? pastMessages.channels[channel] : null
120 120
         console.log('channelHistory :>> ', channelHistory)
121 121
         return channelHistory
122 122
             ? channelHistory.map(msg => ({

+ 42
- 1
frontend/src/services/notification.service.js 查看文件

@@ -1,5 +1,5 @@
1 1
 import { remote } from '../utils/db.js'
2
-
2
+import { currentProfile } from '../services'
3 3
 /**
4 4
  * Base notifier class
5 5
  * @param {number} profileId needed to listen for events for this profile
@@ -29,6 +29,9 @@ class StonkAlert extends Toaster {
29 29
         this.stonks = {}
30 30
         this.listenFor(`${profileId}.${this.event}`, message => {
31 31
             const parsed = JSON.parse(message.data)
32
+            if (parsed.name === 'REVEALED_INFO') {
33
+                this._appendTagsToGrouping(parsed)
34
+            }
32 35
             this.stonks[parsed.name] = parsed
33 36
             waveCb(this._formatToast(parsed), parsed.type)
34 37
         })
@@ -40,6 +43,44 @@ class StonkAlert extends Toaster {
40 43
             return `${parsed.name}: ${parsed.profile_id} ${parsed.order} at ${parsed.price}`
41 44
         }
42 45
     }
46
+    _appendTagsToGrouping(parsed) {
47
+        console.log('_appendTagsToGrouping fired')
48
+        // look inside the current profile for the groupings
49
+        // get the grouping with the correct grouping id
50
+        const foundGrouping = currentProfile.groupings.find(grouping =>
51
+            grouping.grouping_id === parsed.grouping_id
52
+        )
53
+
54
+        if (foundGrouping) {
55
+            // create a tag from the notification called tagFromNotification
56
+            const tagFromNotification = {
57
+                grouping_id: parsed.grouping_id,
58
+                is_deleted: 0,
59
+                profile_id: currentProfile._profile.profile_id,
60
+                target_id: foundGrouping.profile.profile_id,
61
+                tag: {
62
+                    is_active: 1,
63
+                    tag_category: "reveal",
64
+                    tag_description: parsed.description,
65
+                    tag_id: parsed.tag
66
+                    // tag_association:
67
+                }
68
+            }
69
+            const target_desc = `target_${parsed.description}`
70
+            tagFromNotification.tag[target_desc] = parsed.revealed_info
71
+
72
+            // grouping.tags.push(tagFromNotification)
73
+            foundGrouping.tags.push(tagFromNotification)
74
+            console.log(currentProfile)
75
+            // TODO: finish this function, while it is viewable in the console
76
+            // afterwards, I am confused as to how to "find the target"
77
+
78
+            // find the target (other person in the grouping) and store the
79
+            // information that came from the notification (target.profile.email
80
+            // = email target.profile.name = name)
81
+            // find a grouping_id from the notification
82
+        }
83
+    }
43 84
 }
44 85
 
45 86
 export { Toaster, StonkAlert }

+ 1
- 15
frontend/src/views/ChatView.vue 查看文件

@@ -89,21 +89,7 @@ export default {
89 89
         async reveal(tagId) {
90 90
             const grouping = this.getGrouping()
91 91
             await grouping.reveal(currentProfile.id.value, tagId)
92
-
93
-            const revealedData = currentProfile.toaster.stonks['REVEALED INFO']
94
-            currentProfile.groupings.forEach((g) => {
95
-                if (g.grouping_id === revealedData.grouping_id) {
96
-                    g.tags.forEach((t) => {
97
-                        if (currentProfile.id.value === t.profile_id &&
98
-                            t.tag_id === revealedData.tag) {
99
-                            // data does not persist after refresh
100
-                            t.tag.tag_data = revealedData.revealed_info
101
-                        }
102
-                    })
103
-                }
104
-            })
105
-            /* console.log(currentProfile) */
106
-        },
92
+         },
107 93
         // TODO: remove, only for testing reveal()
108 94
         async checkData() {
109 95
             console.log(currentProfile)

Loading…
取消
儲存