@@ -34,10 +34,24 @@ public function subscribe(ConnectionInterface $connection, stdClass $payload)
34
34
$ this ->channelManager
35
35
->getChannelMembers ($ connection ->app ->id , $ this ->getName ())
36
36
->then (function ($ users ) use ($ connection ) {
37
+ $ hash = [];
38
+
39
+ foreach ($ users as $ socketId => $ user ) {
40
+ $ hash [$ user ->user_id ] = $ user ->user_info ?? [];
41
+ }
42
+
37
43
$ connection ->send (json_encode ([
38
44
'event ' => 'pusher_internal:subscription_succeeded ' ,
39
45
'channel ' => $ this ->getName (),
40
- 'data ' => json_encode ($ this ->getChannelData ($ users )),
46
+ 'data ' => json_encode ([
47
+ 'presence ' => [
48
+ 'ids ' => collect ($ users )->map (function ($ user ) {
49
+ return (string ) $ user ->user_id ;
50
+ })->values (),
51
+ 'hash ' => $ hash ,
52
+ 'count ' => count ($ users ),
53
+ ],
54
+ ]),
41
55
]));
42
56
});
43
57
@@ -95,53 +109,4 @@ public function unsubscribe(ConnectionInterface $connection)
95
109
);
96
110
});
97
111
}
98
-
99
- /**
100
- * Get the Presence channel data.
101
- *
102
- * @param array $users
103
- * @return array
104
- */
105
- protected function getChannelData (array $ users ): array
106
- {
107
- return [
108
- 'presence ' => [
109
- 'ids ' => $ this ->getUserIds ($ users ),
110
- 'hash ' => $ this ->getHash ($ users ),
111
- 'count ' => count ($ users ),
112
- ],
113
- ];
114
- }
115
-
116
- /**
117
- * Get the Presence Channel's users.
118
- *
119
- * @param array $users
120
- * @return array
121
- */
122
- protected function getUserIds (array $ users ): array
123
- {
124
- return collect ($ users )
125
- ->map (function ($ user ) {
126
- return (string ) $ user ->user_id ;
127
- })
128
- ->values ();
129
- }
130
-
131
- /**
132
- * Compute the hash for the presence channel integrity.
133
- *
134
- * @param array $users
135
- * @return array
136
- */
137
- protected function getHash (array $ users ): array
138
- {
139
- $ hash = [];
140
-
141
- foreach ($ users as $ socketId => $ user ) {
142
- $ hash [$ user ->user_id ] = $ user ->user_info ?? [];
143
- }
144
-
145
- return $ hash ;
146
- }
147
112
}
0 commit comments