Bladeren bron

:recycle: integrating chat channel subscription with group creation

tags/0.0.1^2
J 3 jaren geleden
bovenliggende
commit
1f8b0e8160

+ 1
- 1
backend/lib/routes/membership/active.js Bestand weergeven

53
                 profileId,
53
                 profileId,
54
                 membershipType,
54
                 membershipType,
55
             )
55
             )
56
-
56
+            console.log('groupings :>> ', groupings)
57
             /**
57
             /**
58
              * Heavily process the result by storing just a profile_id
58
              * Heavily process the result by storing just a profile_id
59
              * and attach complete profiles
59
              * and attach complete profiles

+ 1
- 0
backend/lib/services/membership.js Bestand weergeven

67
             profileId,
67
             profileId,
68
             type,
68
             type,
69
         )
69
         )
70
+        console.log('dedupedGroupings :>> ', dedupedGroupings)
70
         /** Grab just the Groupings this id has a Membership for */
71
         /** Grab just the Groupings this id has a Membership for */
71
         return await Grouping.query()
72
         return await Grouping.query()
72
             .whereIn('grouping_id', dedupedGroupings)
73
             .whereIn('grouping_id', dedupedGroupings)

+ 16
- 11
frontend/src/components/ProfileCardList.vue Bestand weergeven

19
                     h4 {{ profile.name }}
19
                     h4 {{ profile.name }}
20
                     nav.swipe_icons
20
                     nav.swipe_icons
21
                         //- Accept
21
                         //- Accept
22
-                        button(@click="chat(profile.pid)") chat
23
                         button(@click="accept(profile.pid)") Accept
22
                         button(@click="accept(profile.pid)") Accept
24
                         button(@click="view(profile.pid)") view
23
                         button(@click="view(profile.pid)") view
25
                         //- Pass
24
                         //- Pass
39
                     h4 {{ profile.name }}
38
                     h4 {{ profile.name }}
40
                     nav.swipe_icons
39
                     nav.swipe_icons
41
                         button(@click="view(profile.pid)") view
40
                         button(@click="view(profile.pid)") view
42
-                        button(@click="chat(profile.pid)") chat
43
 </template>
41
 </template>
44
 
42
 
45
 <script setup>
43
 <script setup>
95
     // const charmander = await db.get(`/profile/{profile_id}/queue/{target_id}/delete?include_profile=true&reinsert=false`)
93
     // const charmander = await db.get(`/profile/{profile_id}/queue/{target_id}/delete?include_profile=true&reinsert=false`)
96
     // http://localhost:3001/api/profile/38/queue/9/delete?include_profile=true&reinsert=true
94
     // http://localhost:3001/api/profile/38/queue/9/delete?include_profile=true&reinsert=true
97
     const profileId = props.pid
95
     const profileId = props.pid
98
-    updateQueueByProfileId(profileId, targetId, false)
99
-
100
-    postMembershipByProfileId({ profileId, targetId })
101
-
96
+    await updateQueueByProfileId(profileId, targetId, false)
97
+    const { membershipMatch, groupingName } = await postMembershipByProfileId({
98
+        profileId,
99
+        targetId,
100
+    })
101
+    console.log('membershipMatch :>> ', membershipMatch)
102
+    if (membershipMatch?.hasMatch) {
103
+        await subscribeToChat(groupingName)
104
+    }
102
     emit('reload')
105
     emit('reload')
103
 }
106
 }
104
 
107
 
106
     router.push({ path: `/matches/${pid}` })
109
     router.push({ path: `/matches/${pid}` })
107
 }
110
 }
108
 
111
 
109
-const chat = async targetId => {
112
+const subscribeToChat = async groupingName => {
110
     // create a chatter reference from the current profile
113
     // create a chatter reference from the current profile
111
     const chatter = currentProfile.chatter
114
     const chatter = currentProfile.chatter
112
     // console.log('mock sender:', pid)
115
     // console.log('mock sender:', pid)
113
 
116
 
114
-    /**  publish a new message to the chatter with the channel and the message & title is optional
117
+    /**
118
+     * publish a new message to the chatter with the channel and the message & title is optional
115
      */
119
      */
116
-    const res = await chatter.publish(chatter.subscriptions[1], {
120
+    // You MUST send chatter channels as an array
121
+    chatter.subscribe([groupingName])
122
+    const res = await chatter.publish(groupingName, {
117
         title: 'New Message',
123
         title: 'New Message',
118
-        description:
119
-            'This is the checking to see if we are subscribed to a channel!',
124
+        description: `This is the checking to see if we are subscribed to the ${groupingName} channel!`,
120
     })
125
     })
121
     // PubNub response will be a timecode of when the message was published
126
     // PubNub response will be a timecode of when the message was published
122
     console.log('res:', res)
127
     console.log('res:', res)

+ 15
- 23
frontend/src/services/chat.service.js Bestand weergeven

49
     title: 'testing',
49
     title: 'testing',
50
     description: 'hello world!',
50
     description: 'hello world!',
51
 })
51
 })
52
-const MAIN_CHANNEL = 'Channel-Barcelona'
52
+const MAIN_CHANNEL = 'Channel-Siimee'
53
 
53
 
54
 /** Singleton that holds all our chat information */
54
 /** Singleton that holds all our chat information */
55
 class Chatter {
55
 class Chatter {
70
 
70
 
71
         // Setup the main channel
71
         // Setup the main channel
72
         //  subscriptions array will be built dynamically from the "this.groupings" object
72
         //  subscriptions array will be built dynamically from the "this.groupings" object
73
-        this.subscriptions = [MAIN_CHANNEL, 'Channel-LosAngeles']
73
+        this.subscriptions = [MAIN_CHANNEL]
74
         this.listeners = {
74
         this.listeners = {
75
             status: async e => {
75
             status: async e => {
76
-                await this.publish(this.subscriptions[0], testMessage)
76
+                // await this.publish(this.subscriptions[0], testMessage)
77
                 if (e.category !== 'PNConnectedCategory') return
77
                 if (e.category !== 'PNConnectedCategory') return
78
             },
78
             },
79
             message: this._onMessage,
79
             message: this._onMessage,
100
         this.provider = await setupPubnub(this.uuid)
100
         this.provider = await setupPubnub(this.uuid)
101
 
101
 
102
         //  step 1: build the this.groupings object from the backend
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)
103
+        // ? .await for the groupings to be fetched before subscribing to channels
104
+        await this._setupAllChannels(this.uuid)
105
+        this._listenFor({ listeners: this.listeners })
106
+        this.subscribe(this.subscriptions)
110
     }
107
     }
111
     /**
108
     /**
112
      * Send a message to a channel
109
      * Send a message to a channel
118
      */
115
      */
119
     async publish(channel, message) {
116
     async publish(channel, message) {
120
         console.log('publishing message to channel:', channel)
117
         console.log('publishing message to channel:', channel)
121
-        return await providerMethods['publish']({ channel, message })
118
+        return providerMethods.publish({ channel, message })
122
     }
119
     }
123
     /**
120
     /**
124
      * Subscribe to a channels
121
      * Subscribe to a channels
125
      * Facade so we can hide provider specific methods
122
      * Facade so we can hide provider specific methods
126
      * @param {array} channels
123
      * @param {array} channels
127
      */
124
      */
128
-    _subscribe(channels) {
129
-        providerMethods['subscribe']({ channels })
125
+    subscribe(channels) {
126
+        providerMethods.subscribe({ channels })
130
     }
127
     }
131
     /**
128
     /**
132
      * Listen to events and set callbacks
129
      * Listen to events and set callbacks
133
      * Facade so we can hide provider specific methods
130
      * Facade so we can hide provider specific methods
134
      */
131
      */
135
     _listenFor({ listeners }) {
132
     _listenFor({ listeners }) {
136
-        providerMethods['listen'](listeners)
133
+        providerMethods.listen(listeners)
137
     }
134
     }
138
     //  step 2: build the this.subscriptions array from the this.groupings object
135
     //  step 2: build the this.subscriptions array from the this.groupings object
139
     // fetch all groupings for this profile and then store them in the chatter groupings object for reference
136
     // fetch all groupings for this profile and then store them in the chatter groupings object for reference
140
-    async getGroupingsByProfileId(profileId) {
141
-        console.log('fetching groupings for profileId:', profileId)
137
+    async _setupAllChannels(profileId) {
142
         const groupings = await fetchMembershipsByProfileId(profileId)
138
         const groupings = await fetchMembershipsByProfileId(profileId)
143
-        this.groupings = groupings
144
-        this.createChannelNamesByGroupings(this.groupings)
145
-    }
146
-    // building a list of channel names from the groupings object.grouping_name
147
-    createChannelNamesByGroupings(groupings) {
148
-        groupings.forEach(item => {
149
-            this.subscriptions.push(item.grouping_name)
139
+        console.log(`fetched groupings for profileId: ${profileId}`, groupings)
140
+        groupings.forEach(grouping => {
141
+            this.subscriptions.push(grouping.grouping_name)
150
         })
142
         })
151
     }
143
     }
152
     stop() {
144
     stop() {

+ 2
- 3
frontend/src/services/grouping.service.js Bestand weergeven

40
         grouping_type: groupingType,
40
         grouping_type: groupingType,
41
         grouping_name: `${utcDateInSeconds}_${profileId}_${targetId}`,
41
         grouping_name: `${utcDateInSeconds}_${profileId}_${targetId}`,
42
     }
42
     }
43
-    const createdMembershipRecord = await db.post(
43
+    const membershipMatch = await db.post(
44
         `/membership/${profileId}/join`,
44
         `/membership/${profileId}/join`,
45
         membership,
45
         membership,
46
     )
46
     )
47
-    console.warn(`${groupingType} created between ${profileId} and ${targetId}`)
48
-    return createdMembershipRecord
47
+    return { membershipMatch, groupingName: membership.grouping_name }
49
 }
48
 }
50
 export { fetchMembershipsByProfileId, postMembershipByProfileId }
49
 export { fetchMembershipsByProfileId, postMembershipByProfileId }

Laden…
Annuleren
Opslaan