|
|
@@ -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 }
|