Explorar el Código

:recycle: integrating chat channel subscription with group creation

tags/0.0.1^2
J hace 3 años
padre
commit
1f8b0e8160

+ 1
- 1
backend/lib/routes/membership/active.js Ver fichero

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

+ 1
- 0
backend/lib/services/membership.js Ver fichero

@@ -67,6 +67,7 @@ module.exports = class MembershipService extends Schmervice.Service {
67 67
             profileId,
68 68
             type,
69 69
         )
70
+        console.log('dedupedGroupings :>> ', dedupedGroupings)
70 71
         /** Grab just the Groupings this id has a Membership for */
71 72
         return await Grouping.query()
72 73
             .whereIn('grouping_id', dedupedGroupings)

+ 16
- 11
frontend/src/components/ProfileCardList.vue Ver fichero

@@ -19,7 +19,6 @@ section.profile-card-list(:style="{'display': 'flex', 'overflow':'auto',}")
19 19
                     h4 {{ profile.name }}
20 20
                     nav.swipe_icons
21 21
                         //- Accept
22
-                        button(@click="chat(profile.pid)") chat
23 22
                         button(@click="accept(profile.pid)") Accept
24 23
                         button(@click="view(profile.pid)") view
25 24
                         //- Pass
@@ -39,7 +38,6 @@ section.profile-card-list(:style="{'display': 'flex', 'overflow':'auto',}")
39 38
                     h4 {{ profile.name }}
40 39
                     nav.swipe_icons
41 40
                         button(@click="view(profile.pid)") view
42
-                        button(@click="chat(profile.pid)") chat
43 41
 </template>
44 42
 
45 43
 <script setup>
@@ -95,10 +93,15 @@ const accept = async targetId => {
95 93
     // const charmander = await db.get(`/profile/{profile_id}/queue/{target_id}/delete?include_profile=true&reinsert=false`)
96 94
     // http://localhost:3001/api/profile/38/queue/9/delete?include_profile=true&reinsert=true
97 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 105
     emit('reload')
103 106
 }
104 107
 
@@ -106,17 +109,19 @@ const view = pid => {
106 109
     router.push({ path: `/matches/${pid}` })
107 110
 }
108 111
 
109
-const chat = async targetId => {
112
+const subscribeToChat = async groupingName => {
110 113
     // create a chatter reference from the current profile
111 114
     const chatter = currentProfile.chatter
112 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 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 126
     // PubNub response will be a timecode of when the message was published
122 127
     console.log('res:', res)

+ 15
- 23
frontend/src/services/chat.service.js Ver fichero

@@ -49,7 +49,7 @@ const testMessage = new ChatMessage({
49 49
     title: 'testing',
50 50
     description: 'hello world!',
51 51
 })
52
-const MAIN_CHANNEL = 'Channel-Barcelona'
52
+const MAIN_CHANNEL = 'Channel-Siimee'
53 53
 
54 54
 /** Singleton that holds all our chat information */
55 55
 class Chatter {
@@ -70,10 +70,10 @@ class Chatter {
70 70
 
71 71
         // Setup the main channel
72 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 74
         this.listeners = {
75 75
             status: async e => {
76
-                await this.publish(this.subscriptions[0], testMessage)
76
+                // await this.publish(this.subscriptions[0], testMessage)
77 77
                 if (e.category !== 'PNConnectedCategory') return
78 78
             },
79 79
             message: this._onMessage,
@@ -100,13 +100,10 @@ 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
-        // ? .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 109
      * Send a message to a channel
@@ -118,35 +115,30 @@ class Chatter {
118 115
      */
119 116
     async publish(channel, message) {
120 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 121
      * Subscribe to a channels
125 122
      * Facade so we can hide provider specific methods
126 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 129
      * Listen to events and set callbacks
133 130
      * Facade so we can hide provider specific methods
134 131
      */
135 132
     _listenFor({ listeners }) {
136
-        providerMethods['listen'](listeners)
133
+        providerMethods.listen(listeners)
137 134
     }
138 135
     //  step 2: build the this.subscriptions array from the this.groupings object
139 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 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 144
     stop() {

+ 2
- 3
frontend/src/services/grouping.service.js Ver fichero

@@ -40,11 +40,10 @@ const postMembershipByProfileId = async ({
40 40
         grouping_type: groupingType,
41 41
         grouping_name: `${utcDateInSeconds}_${profileId}_${targetId}`,
42 42
     }
43
-    const createdMembershipRecord = await db.post(
43
+    const membershipMatch = await db.post(
44 44
         `/membership/${profileId}/join`,
45 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 49
 export { fetchMembershipsByProfileId, postMembershipByProfileId }

Loading…
Cancelar
Guardar