Przeglądaj źródła

:bug: fixing transposed pubnub group names by returning grouping from backend

tags/0.0.1^2
J 3 lat temu
rodzic
commit
2a4bf1e0d2

+ 9
- 6
backend/lib/routes/membership/join.js Wyświetl plik

27
     response: Joi.object({
27
     response: Joi.object({
28
         memberships: Joi.array().items(),
28
         memberships: Joi.array().items(),
29
         hasMatch: Joi.boolean(),
29
         hasMatch: Joi.boolean(),
30
+        groupings: Joi.array().items(),
30
     }).label('grouping_membership_list'),
31
     }).label('grouping_membership_list'),
31
     error: errorSchema.single,
32
     error: errorSchema.single,
32
 }
33
 }
68
                 // !: You should only be associated with a single company too
69
                 // !: You should only be associated with a single company too
69
 
70
 
70
                 /** User membership service method to create membership */
71
                 /** User membership service method to create membership */
71
-                const memberships = await membershipService.joinGrouping(
72
-                    profileId,
73
-                    res.target_id,
74
-                    groupingToWrite,
75
-                    role,
76
-                )
72
+                const { memberships, groupings } =
73
+                    await membershipService.joinGrouping(
74
+                        profileId,
75
+                        res.target_id,
76
+                        groupingToWrite,
77
+                        role,
78
+                    )
77
                 const hasMatch = memberships.every(
79
                 const hasMatch = memberships.every(
78
                     membership => membership && membership.is_active == true,
80
                     membership => membership && membership.is_active == true,
79
                 )
81
                 )
103
                         data: {
105
                         data: {
104
                             memberships,
106
                             memberships,
105
                             hasMatch,
107
                             hasMatch,
108
+                            groupings,
106
                         },
109
                         },
107
                     })
110
                     })
108
                     .code(200)
111
                     .code(200)

+ 12
- 4
backend/lib/services/membership.js Wyświetl plik

25
         /** Uncomment to dedupe the list just in case */
25
         /** Uncomment to dedupe the list just in case */
26
         return [...new Set(groupingIdsToGrab)]
26
         return [...new Set(groupingIdsToGrab)]
27
     }
27
     }
28
-
28
+    async _getGroupings(groupingIds, txn) {
29
+        const { Grouping } = this.server.models()
30
+        return await Grouping.query(txn).whereIn('grouping_id', groupingIds)
31
+    }
29
     /**
32
     /**
30
      * Internal method to create a new grouping
33
      * Internal method to create a new grouping
31
      * @param {object} groupingToTry from payload data
34
      * @param {object} groupingToTry from payload data
116
 
119
 
117
         if (matchingGroupingIds.length) {
120
         if (matchingGroupingIds.length) {
118
             /** Grab all memberships associated with groupingIds */
121
             /** Grab all memberships associated with groupingIds */
119
-            const memberships = await Membership.query().whereIn(
122
+            let memberships = await Membership.query().whereIn(
120
                 'grouping_id',
123
                 'grouping_id',
121
                 matchingGroupingIds,
124
                 matchingGroupingIds,
122
             )
125
             )
127
             })
130
             })
128
 
131
 
129
             /** Make a new query to get updated information */
132
             /** Make a new query to get updated information */
130
-            return await Membership.query().whereIn(
133
+            memberships = await Membership.query().whereIn(
131
                 'grouping_id',
134
                 'grouping_id',
132
                 matchingGroupingIds,
135
                 matchingGroupingIds,
133
             )
136
             )
137
+            const groupings = await this._getGroupings(matchingGroupingIds, txn)
138
+            return { memberships, groupings }
134
         } else {
139
         } else {
135
             /**
140
             /**
136
              * If both have NO grouping in common, create a membership
141
              * If both have NO grouping in common, create a membership
160
                 is_active: false,
165
                 is_active: false,
161
             })
166
             })
162
 
167
 
163
-            return [userMembership, targetMembership]
168
+            return {
169
+                memberships: [userMembership, targetMembership],
170
+                groupings: [],
171
+            }
164
         }
172
         }
165
     }
173
     }
166
 
174
 

+ 12
- 6
frontend/src/components/ProfileCardList.vue Wyświetl plik

98
         profileId,
98
         profileId,
99
         targetId,
99
         targetId,
100
     })
100
     })
101
+
102
+    // Reuse old grouping name if theres a match
103
+    let channel = groupingName
101
     console.log('membershipMatch :>> ', membershipMatch)
104
     console.log('membershipMatch :>> ', membershipMatch)
102
     if (membershipMatch?.hasMatch) {
105
     if (membershipMatch?.hasMatch) {
103
-        await subscribeToChat(groupingName)
106
+        const [time, intiator, target] = groupingName.split('_')
107
+        channel = membershipMatch.groupings[0].grouping_name
108
+        console.log('channel :>> ', channel)
104
     }
109
     }
110
+    await subscribeToChannel(channel)
105
     emit('reload')
111
     emit('reload')
106
 }
112
 }
107
 
113
 
109
     router.push({ path: `/matches/${pid}` })
115
     router.push({ path: `/matches/${pid}` })
110
 }
116
 }
111
 
117
 
112
-const subscribeToChat = async groupingName => {
118
+const subscribeToChannel = async channelName => {
113
     // create a chatter reference from the current profile
119
     // create a chatter reference from the current profile
114
     const chatter = currentProfile.chatter
120
     const chatter = currentProfile.chatter
115
     // console.log('mock sender:', pid)
121
     // console.log('mock sender:', pid)
117
     /**
123
     /**
118
      * publish a new message to the chatter with the channel and the message & title is optional
124
      * publish a new message to the chatter with the channel and the message & title is optional
119
      */
125
      */
120
-    // You MUST send chatter channels as an array
121
-    chatter.subscribe([groupingName])
122
-    const res = await chatter.publish(groupingName, {
126
+    // You MUST send chatter channels as an array in an object
127
+    chatter.subscribe({ channels: [channelName] })
128
+    const res = await chatter.publish(channelName, {
123
         title: 'New Message',
129
         title: 'New Message',
124
-        description: `This is the checking to see if we are subscribed to the ${groupingName} channel!`,
130
+        description: `This is the checking to see if we are subscribed to the ${channelName} channel!`,
125
     })
131
     })
126
     // PubNub response will be a timecode of when the message was published
132
     // PubNub response will be a timecode of when the message was published
127
     console.log('res:', res)
133
     console.log('res:', res)

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

103
         // ? .await for the groupings to be fetched before subscribing to channels
103
         // ? .await for the groupings to be fetched before subscribing to channels
104
         await this._setupAllChannels(this.uuid)
104
         await this._setupAllChannels(this.uuid)
105
         this._listenFor({ listeners: this.listeners })
105
         this._listenFor({ listeners: this.listeners })
106
-        this.subscribe(this.subscriptions)
106
+        this.subscribe({ channels: this.subscriptions })
107
     }
107
     }
108
     /**
108
     /**
109
      * Send a message to a channel
109
      * Send a message to a channel
122
      * Facade so we can hide provider specific methods
122
      * Facade so we can hide provider specific methods
123
      * @param {array} channels
123
      * @param {array} channels
124
      */
124
      */
125
-    subscribe(channels) {
125
+    subscribe({ channels }) {
126
         providerMethods.subscribe({ channels })
126
         providerMethods.subscribe({ channels })
127
     }
127
     }
128
     /**
128
     /**

Ładowanie…
Anuluj
Zapisz