Преглед изворни кода

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

tags/0.0.1^2
J пре 3 година
родитељ
комит
2a4bf1e0d2

+ 9
- 6
backend/lib/routes/membership/join.js Прегледај датотеку

@@ -27,6 +27,7 @@ const responseSchemas = {
27 27
     response: Joi.object({
28 28
         memberships: Joi.array().items(),
29 29
         hasMatch: Joi.boolean(),
30
+        groupings: Joi.array().items(),
30 31
     }).label('grouping_membership_list'),
31 32
     error: errorSchema.single,
32 33
 }
@@ -68,12 +69,13 @@ module.exports = {
68 69
                 // !: You should only be associated with a single company too
69 70
 
70 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 79
                 const hasMatch = memberships.every(
78 80
                     membership => membership && membership.is_active == true,
79 81
                 )
@@ -103,6 +105,7 @@ module.exports = {
103 105
                         data: {
104 106
                             memberships,
105 107
                             hasMatch,
108
+                            groupings,
106 109
                         },
107 110
                     })
108 111
                     .code(200)

+ 12
- 4
backend/lib/services/membership.js Прегледај датотеку

@@ -25,7 +25,10 @@ module.exports = class MembershipService extends Schmervice.Service {
25 25
         /** Uncomment to dedupe the list just in case */
26 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 33
      * Internal method to create a new grouping
31 34
      * @param {object} groupingToTry from payload data
@@ -116,7 +119,7 @@ module.exports = class MembershipService extends Schmervice.Service {
116 119
 
117 120
         if (matchingGroupingIds.length) {
118 121
             /** Grab all memberships associated with groupingIds */
119
-            const memberships = await Membership.query().whereIn(
122
+            let memberships = await Membership.query().whereIn(
120 123
                 'grouping_id',
121 124
                 matchingGroupingIds,
122 125
             )
@@ -127,10 +130,12 @@ module.exports = class MembershipService extends Schmervice.Service {
127 130
             })
128 131
 
129 132
             /** Make a new query to get updated information */
130
-            return await Membership.query().whereIn(
133
+            memberships = await Membership.query().whereIn(
131 134
                 'grouping_id',
132 135
                 matchingGroupingIds,
133 136
             )
137
+            const groupings = await this._getGroupings(matchingGroupingIds, txn)
138
+            return { memberships, groupings }
134 139
         } else {
135 140
             /**
136 141
              * If both have NO grouping in common, create a membership
@@ -160,7 +165,10 @@ module.exports = class MembershipService extends Schmervice.Service {
160 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 Прегледај датотеку

@@ -98,10 +98,16 @@ const accept = async targetId => {
98 98
         profileId,
99 99
         targetId,
100 100
     })
101
+
102
+    // Reuse old grouping name if theres a match
103
+    let channel = groupingName
101 104
     console.log('membershipMatch :>> ', membershipMatch)
102 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 111
     emit('reload')
106 112
 }
107 113
 
@@ -109,7 +115,7 @@ const view = pid => {
109 115
     router.push({ path: `/matches/${pid}` })
110 116
 }
111 117
 
112
-const subscribeToChat = async groupingName => {
118
+const subscribeToChannel = async channelName => {
113 119
     // create a chatter reference from the current profile
114 120
     const chatter = currentProfile.chatter
115 121
     // console.log('mock sender:', pid)
@@ -117,11 +123,11 @@ const subscribeToChat = async groupingName => {
117 123
     /**
118 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 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 132
     // PubNub response will be a timecode of when the message was published
127 133
     console.log('res:', res)

+ 2
- 2
frontend/src/services/chat.service.js Прегледај датотеку

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

Loading…
Откажи
Сачувај