Przeglądaj źródła

🧹 moved _listenFor and _subscribe into .then to ensure all groupings are added before adding listeners

tags/0.0.1^2
K Rob 3 lat temu
rodzic
commit
1ea9fc9c40

+ 3
- 5
frontend/src/components/ProfileCardList.vue Wyświetl plik

@@ -112,13 +112,11 @@ const chat = async pid => {
112 112
     const chatter = currentProfile.chatter
113 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[0], {
120 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 121
     // PubNub response will be a timecode of when the message was published
124 122
     console.log('res:', res)

+ 9
- 5
frontend/src/services/chat.service.js Wyświetl plik

@@ -73,7 +73,7 @@ class Chatter {
73 73
         this.subscriptions = [MAIN_CHANNEL, 'Channel-LosAngeles']
74 74
         this.listeners = {
75 75
             status: async e => {
76
-                await this.publish(this.subscriptions[0], testMessage)
76
+                await this.publish(this.subscriptions[2], testMessage)
77 77
                 if (e.category !== 'PNConnectedCategory') return
78 78
             },
79 79
             message: this._onMessage,
@@ -100,11 +100,14 @@ class Chatter {
100 100
         this.provider = await setupPubnub(this.uuid)
101 101
             
102 102
         //  step 1: build the this.groupings object from the backend
103
-        this.getGroupingsByProfileId(this.uuid)
103
+        // added .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
+        })
104 108
         
105
-        
106
-        this._listenFor({ listeners: this.listeners })
107
-        this._subscribe(this.subscriptions)
109
+        console.log('this.subscriptions', this.subscriptions)
110
+       
108 111
     }
109 112
     /**
110 113
      * Send a message to a channel
@@ -115,6 +118,7 @@ class Chatter {
115 118
      * @return {object} timestamp
116 119
      */
117 120
     async publish(channel, message) {
121
+        console.log('publishing message to channel:', channel)
118 122
         return await providerMethods['publish']({ channel, message })
119 123
     }
120 124
     /**

Ładowanie…
Anuluj
Zapisz