Просмотр исходного кода

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

tags/0.0.1^2
K Rob 3 лет назад
Родитель
Сommit
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
 import PubNub from 'pubnub'
1
 import PubNub from 'pubnub'
2
 
2
 
3
+// custom services 
4
+import {fetchMembershipsByProfileId} from '../services/grouping.service'
5
+
3
 /**
6
 /**
4
  * Provider method holder
7
  * Provider method holder
5
  * We always reference this object so
8
  * We always reference this object so
57
      */
60
      */
58
     constructor() {
61
     constructor() {
59
         // Map of each active chat
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
         this.groupings = {}
64
         this.groupings = {}
61
 
65
 
62
         // Our pubnub instance
66
         // Our pubnub instance
66
         this.uuid = null
70
         this.uuid = null
67
 
71
 
68
         // Setup the main channel
72
         // Setup the main channel
73
+        //  subscriptions array will be built dynamically from the this.groupings object
69
         this.subscriptions = [MAIN_CHANNEL, 'Channel-LosAngeles']
74
         this.subscriptions = [MAIN_CHANNEL, 'Channel-LosAngeles']
70
         this.listeners = {
75
         this.listeners = {
71
             status: async e => {
76
             status: async e => {
94
     async setup(uuid) {
99
     async setup(uuid) {
95
         this.uuid = `${uuid}`
100
         this.uuid = `${uuid}`
96
         this.provider = await setupPubnub(this.uuid)
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
         this._listenFor({ listeners: this.listeners })
108
         this._listenFor({ listeners: this.listeners })
99
         this._subscribe(this.subscriptions)
109
         this._subscribe(this.subscriptions)
100
     }
110
     }
124
     _listenFor({ listeners }) {
134
     _listenFor({ listeners }) {
125
         providerMethods['listen'](listeners)
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
 export { Chatter }
155
 export { Chatter }

+ 8
- 1
frontend/src/services/login.service.js Просмотреть файл

2
 import { fetchResponsesByProfileId, Chatter, StonkAlert } from '../services'
2
 import { fetchResponsesByProfileId, Chatter, StonkAlert } from '../services'
3
 import { surveyFactory } from '../utils'
3
 import { surveyFactory } from '../utils'
4
 
4
 
5
+
5
 /**
6
 /**
6
  * Logged in profile state manager
7
  * Logged in profile state manager
7
  * Sort of a util and service hybrid
8
  * Sort of a util and service hybrid
104
         this.chatter = new Chatter()
105
         this.chatter = new Chatter()
105
         // Use the reactive id object
106
         // Use the reactive id object
106
         const testAccountUUID = this.id.value
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
 const currentProfile = new Login()
118
 const currentProfile = new Login()

Загрузка…
Отмена
Сохранить