@@ -111,12 +111,16 @@ public function findOrCreate($appId, string $channel)
111
111
*/
112
112
public function getLocalConnections (): PromiseInterface
113
113
{
114
- $ connections = collect ($ this ->channels )->map (function ($ channelsWithConnections , $ appId ) {
115
- return collect ($ channelsWithConnections )->values ();
116
- })->values ()->collapse ()
117
- ->map (function ($ channel ) {
118
- return collect ($ channel ->getConnections ());
119
- })->values ()->collapse ()->toArray ();
114
+ $ connections = collect ($ this ->channels )
115
+ ->map (function ($ channelsWithConnections , $ appId ) {
116
+ return collect ($ channelsWithConnections )->values ();
117
+ })
118
+ ->values ()->collapse ()
119
+ ->map (function ($ channel ) {
120
+ return collect ($ channel ->getConnections ());
121
+ })
122
+ ->values ()->collapse ()
123
+ ->toArray ();
120
124
121
125
return Helpers::createFulfilledPromise ($ connections );
122
126
}
@@ -159,19 +163,23 @@ public function unsubscribeFromAllChannels(ConnectionInterface $connection): Pro
159
163
return Helpers::createFulfilledPromise (false );
160
164
}
161
165
162
- $ this ->getLocalChannels ($ connection ->app ->id )->then (function ($ channels ) use ($ connection ) {
163
- collect ($ channels )->each ->unsubscribe ($ connection );
166
+ $ this ->getLocalChannels ($ connection ->app ->id )
167
+ ->then (function ($ channels ) use ($ connection ) {
168
+ collect ($ channels )->each ->unsubscribe ($ connection );
164
169
165
- collect ($ channels )->reject ->hasConnections ()->each (function (Channel $ channel , string $ channelName ) use ($ connection ) {
166
- unset($ this ->channels [$ connection ->app ->id ][$ channelName ]);
170
+ collect ($ channels )
171
+ ->reject ->hasConnections ()
172
+ ->each (function (Channel $ channel , string $ channelName ) use ($ connection ) {
173
+ unset($ this ->channels [$ connection ->app ->id ][$ channelName ]);
174
+ });
167
175
});
168
- });
169
176
170
- $ this ->getLocalChannels ($ connection ->app ->id )->then (function ($ channels ) use ($ connection ) {
171
- if (count ($ channels ) === 0 ) {
172
- unset($ this ->channels [$ connection ->app ->id ]);
173
- }
174
- });
177
+ $ this ->getLocalChannels ($ connection ->app ->id )
178
+ ->then (function ($ channels ) use ($ connection ) {
179
+ if (count ($ channels ) === 0 ) {
180
+ unset($ this ->channels [$ connection ->app ->id ]);
181
+ }
182
+ });
175
183
176
184
return Helpers::createFulfilledPromise (true );
177
185
}
@@ -244,15 +252,18 @@ public function unsubscribeFromApp($appId): PromiseInterface
244
252
*/
245
253
public function getLocalConnectionsCount ($ appId , string $ channelName = null ): PromiseInterface
246
254
{
247
- return $ this ->getLocalChannels ($ appId )->then (function ($ channels ) use ($ channelName ) {
248
- return collect ($ channels )->when (! is_null ($ channelName ), function ($ collection ) use ($ channelName ) {
249
- return $ collection ->filter (function (Channel $ channel ) use ($ channelName ) {
250
- return $ channel ->getName () === $ channelName ;
251
- });
252
- })->flatMap (function (Channel $ channel ) {
253
- return collect ($ channel ->getConnections ())->pluck ('socketId ' );
254
- })->unique ()->count ();
255
- });
255
+ return $ this ->getLocalChannels ($ appId )
256
+ ->then (function ($ channels ) use ($ channelName ) {
257
+ return collect ($ channels )->when (! is_null ($ channelName ), function ($ collection ) use ($ channelName ) {
258
+ return $ collection ->filter (function (Channel $ channel ) use ($ channelName ) {
259
+ return $ channel ->getName () === $ channelName ;
260
+ });
261
+ })
262
+ ->flatMap (function (Channel $ channel ) {
263
+ return collect ($ channel ->getConnections ())->pluck ('socketId ' );
264
+ })
265
+ ->unique ()->count ();
266
+ });
256
267
}
257
268
258
269
/**
@@ -370,13 +381,14 @@ public function getChannelMember(ConnectionInterface $connection, string $channe
370
381
*/
371
382
public function getChannelsMembersCount ($ appId , array $ channelNames ): PromiseInterface
372
383
{
373
- $ results = collect ($ channelNames )->reduce (function ($ results , $ channel ) use ($ appId ) {
374
- $ results [$ channel ] = isset ($ this ->users ["{$ appId }: {$ channel }" ])
375
- ? count ($ this ->users ["{$ appId }: {$ channel }" ])
376
- : 0 ;
384
+ $ results = collect ($ channelNames )
385
+ ->reduce (function ($ results , $ channel ) use ($ appId ) {
386
+ $ results [$ channel ] = isset ($ this ->users ["{$ appId }: {$ channel }" ])
387
+ ? count ($ this ->users ["{$ appId }: {$ channel }" ])
388
+ : 0 ;
377
389
378
- return $ results ;
379
- }, []);
390
+ return $ results ;
391
+ }, []);
380
392
381
393
return Helpers::createFulfilledPromise ($ results );
382
394
}
@@ -443,15 +455,16 @@ public function removeObsoleteConnections(): PromiseInterface
443
455
*/
444
456
public function updateConnectionInChannels ($ connection ): PromiseInterface
445
457
{
446
- return $ this ->getLocalChannels ($ connection ->app ->id )->then (function ($ channels ) use ($ connection ) {
447
- foreach ($ channels as $ channel ) {
448
- if ($ channel ->hasConnection ($ connection )) {
449
- $ channel ->saveConnection ($ connection );
458
+ return $ this ->getLocalChannels ($ connection ->app ->id )
459
+ ->then (function ($ channels ) use ($ connection ) {
460
+ foreach ($ channels as $ channel ) {
461
+ if ($ channel ->hasConnection ($ connection )) {
462
+ $ channel ->saveConnection ($ connection );
463
+ }
450
464
}
451
- }
452
465
453
- return true ;
454
- });
466
+ return true ;
467
+ });
455
468
}
456
469
457
470
/**
0 commit comments