Преглед изворни кода

🚧 added getGroupingsByProfileId, createChannelNamesByGroupings to chat service. TODO test before code review

tags/0.0.1^2
K Rob пре 3 година
родитељ
комит
3ab1e105d6
2 измењених фајлова са 35 додато и 2 уклоњено
  1. 27
    1
      frontend/src/services/chat.service.js
  2. 8
    1
      frontend/src/services/login.service.js

+ 27
- 1
frontend/src/services/chat.service.js Прегледај датотеку

@@ -1,5 +1,8 @@
1 1
 import PubNub from 'pubnub'
2 2
 
3
+// custom services 
4
+import {fetchMembershipsByProfileId} from '../services/grouping.service'
5
+
3 6
 /**
4 7
  * Provider method holder
5 8
  * We always reference this object so
@@ -57,6 +60,7 @@ class Chatter {
57 60
      */
58 61
     constructor() {
59 62
         // Map of each active chat
63
+        // * this is where we will store all of our groupings on from the backend on user login...
60 64
         this.groupings = {}
61 65
 
62 66
         // Our pubnub instance
@@ -66,6 +70,7 @@ class Chatter {
66 70
         this.uuid = null
67 71
 
68 72
         // Setup the main channel
73
+        //  subscriptions array will be built dynamically from the this.groupings object
69 74
         this.subscriptions = [MAIN_CHANNEL, 'Channel-LosAngeles']
70 75
         this.listeners = {
71 76
             status: async e => {
@@ -94,7 +99,12 @@ class Chatter {
94 99
     async setup(uuid) {
95 100
         this.uuid = `${uuid}`
96 101
         this.provider = await setupPubnub(this.uuid)
97
-
102
+            
103
+        //  step 1: build the this.groupings object from the backend
104
+        this.getGroupingsByProfileId(this.uuid)
105
+        //  step 2: build the this.subscriptions array from the this.groupings object
106
+        console.log('this.subscriptions: ', this.subscriptions)
107
+        //  step 3: subscribe to the this.subscriptions array
98 108
         this._listenFor({ listeners: this.listeners })
99 109
         this._subscribe(this.subscriptions)
100 110
     }
@@ -124,6 +134,22 @@ class Chatter {
124 134
     _listenFor({ listeners }) {
125 135
         providerMethods['listen'](listeners)
126 136
     }
137
+
138
+    // fetch all groupings for this profile and then store them in the chatter groupings object for reference
139
+    async getGroupingsByProfileId(profileId) {
140
+        console.log('fetching groupings for profileId:', profileId)
141
+        const groupings = await fetchMembershipsByProfileId(profileId)
142
+        this.groupings = groupings
143
+        this.createChannelNamesByGroupings(this.groupings)
144
+    }
145
+    // building a list of channel names from the groupings object.grouping_name
146
+    createChannelNamesByGroupings(groupings) {
147
+        groupings.forEach(item => {
148
+            this.subscriptions.push(item.grouping_name)
149
+        });
150
+        
151
+        
152
+    }
127 153
 }
128 154
 
129 155
 export { Chatter }

+ 8
- 1
frontend/src/services/login.service.js Прегледај датотеку

@@ -2,6 +2,7 @@ import { ref } from 'vue'
2 2
 import { fetchResponsesByProfileId, Chatter, StonkAlert } from '../services'
3 3
 import { surveyFactory } from '../utils'
4 4
 
5
+
5 6
 /**
6 7
  * Logged in profile state manager
7 8
  * Sort of a util and service hybrid
@@ -104,8 +105,14 @@ class Login {
104 105
         this.chatter = new Chatter()
105 106
         // Use the reactive id object
106 107
         const testAccountUUID = this.id.value
107
-        this.chatter.setup(testAccountUUID)
108
+        this.chatter.setup(testAccountUUID).then(() => {
109
+            console.log('chatter setup complete')
110
+           
111
+        })
112
+        
108 113
     }
114
+
115
+    
109 116
 }
110 117
 
111 118
 const currentProfile = new Login()

Loading…
Откажи
Сачувај