Quellcode durchsuchen

Merge branch 'pub-sub' of fyindr/siimee into dev

tags/0.0.1^2
maeda vor 3 Jahren
Ursprung
Commit
be4873c5fb

+ 3
- 0
frontend/src/App.vue Datei anzeigen

72
                 currentProfile.setupToaster(this.$waveui.notify)
72
                 currentProfile.setupToaster(this.$waveui.notify)
73
             }
73
             }
74
             console.log('---')
74
             console.log('---')
75
+            //  step 3: subscribe to the this.subscriptions array
76
+            // view current subscriptions on the currentProfile.chatter.subscriptions
77
+            console.log('subscriptions', currentProfile.chatter.subscriptions)
75
         },
78
         },
76
     },
79
     },
77
 }
80
 }

+ 2
- 4
frontend/src/components/ProfileCardList.vue Datei anzeigen

112
     const chatter = currentProfile.chatter
112
     const chatter = currentProfile.chatter
113
     // console.log('mock sender:', pid)
113
     // console.log('mock sender:', pid)
114
     
114
     
115
-    /**  publish a new message to the chatter with the channel and the message
116
-     *  
117
-     *  title is optional
115
+    /**  publish a new message to the chatter with the channel and the message & title is optional
118
      */
116
      */
119
     const res = await chatter.publish(chatter.subscriptions[1], {
117
     const res = await chatter.publish(chatter.subscriptions[1], {
120
         title: 'New Message',
118
         title: 'New Message',
121
-        description: 'This is the start of a chat conversation!',
119
+        description: 'This is the checking to see if we are subscribed to a channel!',
122
     })
120
     })
123
     // PubNub response will be a timecode of when the message was published
121
     // PubNub response will be a timecode of when the message was published
124
     console.log('res:', res)
122
     console.log('res:', res)

+ 34
- 5
frontend/src/services/chat.service.js Datei anzeigen

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
20
 const setupPubnub = async uuid => {
23
 const setupPubnub = async uuid => {
21
     const publishKey = 'pub-c-73f35484-396f-47ff-b4b6-45bed079fd3b'
24
     const publishKey = 'pub-c-73f35484-396f-47ff-b4b6-45bed079fd3b'
22
     const subscribeKey = 'sub-c-6cb7f5d0-94e2-11ec-b249-a68c05a281ab'
25
     const subscribeKey = 'sub-c-6cb7f5d0-94e2-11ec-b249-a68c05a281ab'
23
-    // console.log('publishKey: ' , publishKey)
24
     if (!uuid) return console.error('no pubnub uuid set')
26
     if (!uuid) return console.error('no pubnub uuid set')
25
 
27
 
26
     const pubnubClient = await new PubNub({
28
     const pubnubClient = await new PubNub({
57
      */
59
      */
58
     constructor() {
60
     constructor() {
59
         // Map of each active chat
61
         // Map of each active chat
62
+        // * this is where we will store all of our groupings on from the backend on user login...
60
         this.groupings = {}
63
         this.groupings = {}
61
 
64
 
62
         // Our pubnub instance
65
         // Our pubnub instance
66
         this.uuid = null
69
         this.uuid = null
67
 
70
 
68
         // Setup the main channel
71
         // Setup the main channel
72
+        //  subscriptions array will be built dynamically from the "this.groupings" object
69
         this.subscriptions = [MAIN_CHANNEL, 'Channel-LosAngeles']
73
         this.subscriptions = [MAIN_CHANNEL, 'Channel-LosAngeles']
70
         this.listeners = {
74
         this.listeners = {
71
             status: async e => {
75
             status: async e => {
72
-                await this.publish(this.subscriptions[0], testMessage)
76
+                await this.publish(this.subscriptions[2], testMessage)
73
                 if (e.category !== 'PNConnectedCategory') return
77
                 if (e.category !== 'PNConnectedCategory') return
74
             },
78
             },
75
             message: this._onMessage,
79
             message: this._onMessage,
94
     async setup(uuid) {
98
     async setup(uuid) {
95
         this.uuid = `${uuid}`
99
         this.uuid = `${uuid}`
96
         this.provider = await setupPubnub(this.uuid)
100
         this.provider = await setupPubnub(this.uuid)
97
-
98
-        this._listenFor({ listeners: this.listeners })
99
-        this._subscribe(this.subscriptions)
101
+            
102
+        //  step 1: build the this.groupings object from the backend
103
+        // ? .then() to wait for the groupings to be fetched before subscribing to channels
104
+        this.getGroupingsByProfileId(this.uuid).then(() => {
105
+            this._listenFor({ listeners: this.listeners })
106
+            this._subscribe(this.subscriptions)
107
+        })
108
+        
109
+        console.log('this.subscriptions', this.subscriptions)
110
+       
100
     }
111
     }
101
     /**
112
     /**
102
      * Send a message to a channel
113
      * Send a message to a channel
107
      * @return {object} timestamp
118
      * @return {object} timestamp
108
      */
119
      */
109
     async publish(channel, message) {
120
     async publish(channel, message) {
121
+        console.log('publishing message to channel:', channel)
110
         return await providerMethods['publish']({ channel, message })
122
         return await providerMethods['publish']({ channel, message })
111
     }
123
     }
112
     /**
124
     /**
124
     _listenFor({ listeners }) {
136
     _listenFor({ listeners }) {
125
         providerMethods['listen'](listeners)
137
         providerMethods['listen'](listeners)
126
     }
138
     }
139
+    
140
+    //  step 2: build the this.subscriptions array from the this.groupings object
141
+    // fetch all groupings for this profile and then store them in the chatter groupings object for reference
142
+    async getGroupingsByProfileId(profileId) {
143
+        console.log('fetching groupings for profileId:', profileId)
144
+        const groupings = await fetchMembershipsByProfileId(profileId)
145
+        this.groupings = groupings
146
+        this.createChannelNamesByGroupings(this.groupings)
147
+    }
148
+    // building a list of channel names from the groupings object.grouping_name
149
+    createChannelNamesByGroupings(groupings) {
150
+        groupings.forEach(item => {
151
+            this.subscriptions.push(item.grouping_name)
152
+        });
153
+        
154
+        
155
+    }
127
 }
156
 }
128
 
157
 
129
 export { Chatter }
158
 export { Chatter }

+ 3
- 0
frontend/src/services/login.service.js Datei anzeigen

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
106
         const testAccountUUID = this.id.value
107
         const testAccountUUID = this.id.value
107
         this.chatter.setup(testAccountUUID)
108
         this.chatter.setup(testAccountUUID)
108
     }
109
     }
110
+
111
+    
109
 }
112
 }
110
 
113
 
111
 const currentProfile = new Login()
114
 const currentProfile = new Login()

Laden…
Abbrechen
Speichern