Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit cbe4378

Browse files
committed
Revert "formatting"
This reverts commit 8308a7d.
1 parent b6837a0 commit cbe4378

15 files changed

+774
-575
lines changed

src/API/FetchChannels.php

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,48 +28,50 @@ public function __invoke(Request $request)
2828
}
2929
}
3030

31-
return $this->channelManager->getGlobalChannels($request->appId)->then(function ($channels) use ($request, $attributes) {
32-
$channels = collect($channels)->keyBy(function ($channel) {
33-
return $channel instanceof Channel
34-
? $channel->getName()
35-
: $channel;
36-
});
37-
38-
if ($request->has('filter_by_prefix')) {
39-
$channels = $channels->filter(function ($channel, $channelName) use ($request) {
40-
return Str::startsWith($channelName, $request->filter_by_prefix);
31+
return $this->channelManager
32+
->getGlobalChannels($request->appId)
33+
->then(function ($channels) use ($request, $attributes) {
34+
$channels = collect($channels)->keyBy(function ($channel) {
35+
return $channel instanceof Channel
36+
? $channel->getName()
37+
: $channel;
4138
});
42-
}
4339

44-
$channelNames = $channels->map(function ($channel) {
45-
return $channel instanceof Channel
46-
? $channel->getName()
47-
: $channel;
48-
})->toArray();
40+
if ($request->has('filter_by_prefix')) {
41+
$channels = $channels->filter(function ($channel, $channelName) use ($request) {
42+
return Str::startsWith($channelName, $request->filter_by_prefix);
43+
});
44+
}
4945

50-
return $this->channelManager
51-
->getChannelsMembersCount($request->appId, $channelNames)
52-
->then(function ($counts) use ($channels, $attributes) {
53-
$channels = $channels->map(function ($channel) use ($counts, $attributes) {
54-
$info = new stdClass;
46+
$channelNames = $channels->map(function ($channel) {
47+
return $channel instanceof Channel
48+
? $channel->getName()
49+
: $channel;
50+
})->toArray();
5551

56-
$channelName = $channel instanceof Channel
57-
? $channel->getName()
58-
: $channel;
52+
return $this->channelManager
53+
->getChannelsMembersCount($request->appId, $channelNames)
54+
->then(function ($counts) use ($channels, $attributes) {
55+
$channels = $channels->map(function ($channel) use ($counts, $attributes) {
56+
$info = new stdClass;
5957

60-
if (in_array('user_count', $attributes)) {
61-
$info->user_count = $counts[$channelName];
62-
}
58+
$channelName = $channel instanceof Channel
59+
? $channel->getName()
60+
: $channel;
6361

64-
return $info;
65-
})->sortBy(function ($content, $name) {
66-
return $name;
67-
})->all();
62+
if (in_array('user_count', $attributes)) {
63+
$info->user_count = $counts[$channelName];
64+
}
6865

69-
return [
70-
'channels' => $channels ?: new stdClass,
71-
];
72-
});
73-
});
66+
return $info;
67+
})->sortBy(function ($content, $name) {
68+
return $name;
69+
})->all();
70+
71+
return [
72+
'channels' => $channels ?: new stdClass,
73+
];
74+
});
75+
});
7476
}
7577
}

src/ChannelManagers/LocalChannelManager.php

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,23 @@ public function unsubscribeFromAllChannels(ConnectionInterface $connection): Pro
163163
return Helpers::createFulfilledPromise(false);
164164
}
165165

166-
$this->getLocalChannels($connection->app->id)->then(function ($channels) use ($connection) {
167-
collect($channels)->each->unsubscribe($connection);
168-
169-
collect($channels)
170-
->reject->hasConnections()
171-
->each(function (Channel $channel, string $channelName) use ($connection) {
172-
unset($this->channels[$connection->app->id][$channelName]);
173-
});
174-
});
175-
176-
$this->getLocalChannels($connection->app->id)->then(function ($channels) use ($connection) {
177-
if (count($channels) === 0) {
178-
unset($this->channels[$connection->app->id]);
179-
}
180-
});
166+
$this->getLocalChannels($connection->app->id)
167+
->then(function ($channels) use ($connection) {
168+
collect($channels)->each->unsubscribe($connection);
169+
170+
collect($channels)
171+
->reject->hasConnections()
172+
->each(function (Channel $channel, string $channelName) use ($connection) {
173+
unset($this->channels[$connection->app->id][$channelName]);
174+
});
175+
});
176+
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+
});
181183

182184
return Helpers::createFulfilledPromise(true);
183185
}
@@ -250,17 +252,18 @@ public function unsubscribeFromApp($appId): PromiseInterface
250252
*/
251253
public function getLocalConnectionsCount($appId, string $channelName = null): PromiseInterface
252254
{
253-
return $this->getLocalChannels($appId)->then(function ($channels) use ($channelName) {
254-
return collect($channels)->when(! is_null($channelName), function ($collection) use ($channelName) {
255-
return $collection->filter(function (Channel $channel) use ($channelName) {
256-
return $channel->getName() === $channelName;
257-
});
258-
})
259-
->flatMap(function (Channel $channel) {
260-
return collect($channel->getConnections())->pluck('socketId');
261-
})
262-
->unique()->count();
263-
});
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+
});
264267
}
265268

266269
/**
@@ -452,15 +455,16 @@ public function removeObsoleteConnections(): PromiseInterface
452455
*/
453456
public function updateConnectionInChannels($connection): PromiseInterface
454457
{
455-
return $this->getLocalChannels($connection->app->id)->then(function ($channels) use ($connection) {
456-
foreach ($channels as $channel) {
457-
if ($channel->hasConnection($connection)) {
458-
$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+
}
459464
}
460-
}
461465

462-
return true;
463-
});
466+
return true;
467+
});
464468
}
465469

466470
/**

src/ChannelManagers/RedisChannelManager.php

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,15 @@ public function getGlobalChannels($appId): PromiseInterface
137137
*/
138138
public function unsubscribeFromAllChannels(ConnectionInterface $connection): PromiseInterface
139139
{
140-
return $this->getGlobalChannels($connection->app->id)->then(function ($channels) use ($connection) {
141-
foreach ($channels as $channel) {
142-
$this->unsubscribeFromChannel($connection, $channel, new stdClass);
143-
}
144-
})->then(function () use ($connection) {
145-
return parent::unsubscribeFromAllChannels($connection);
146-
});
140+
return $this->getGlobalChannels($connection->app->id)
141+
->then(function ($channels) use ($connection) {
142+
foreach ($channels as $channel) {
143+
$this->unsubscribeFromChannel($connection, $channel, new stdClass);
144+
}
145+
})
146+
->then(function () use ($connection) {
147+
return parent::unsubscribeFromAllChannels($connection);
148+
});
147149
}
148150

149151
/**
@@ -156,15 +158,19 @@ public function unsubscribeFromAllChannels(ConnectionInterface $connection): Pro
156158
*/
157159
public function subscribeToChannel(ConnectionInterface $connection, string $channelName, stdClass $payload): PromiseInterface
158160
{
159-
return $this->subscribeToTopic($connection->app->id, $channelName)->then(function () use ($connection) {
160-
return $this->addConnectionToSet($connection, Carbon::now());
161-
})->then(function () use ($connection, $channelName) {
162-
return $this->addChannelToSet($connection->app->id, $channelName);
163-
})->then(function () use ($connection, $channelName) {
164-
return $this->incrementSubscriptionsCount($connection->app->id, $channelName, 1);
165-
})->then(function () use ($connection, $channelName, $payload) {
166-
return parent::subscribeToChannel($connection, $channelName, $payload);
167-
});
161+
return $this->subscribeToTopic($connection->app->id, $channelName)
162+
->then(function () use ($connection) {
163+
return $this->addConnectionToSet($connection, Carbon::now());
164+
})
165+
->then(function () use ($connection, $channelName) {
166+
return $this->addChannelToSet($connection->app->id, $channelName);
167+
})
168+
->then(function () use ($connection, $channelName) {
169+
return $this->incrementSubscriptionsCount($connection->app->id, $channelName, 1);
170+
})
171+
->then(function () use ($connection, $channelName, $payload) {
172+
return parent::subscribeToChannel($connection, $channelName, $payload);
173+
});
168174
}
169175

170176
/**
@@ -193,11 +199,14 @@ public function unsubscribeFromChannel(ConnectionInterface $connection, string $
193199
$this->unsubscribeFromTopic($connection->app->id, $channelName);
194200
}
195201
});
196-
})->then(function () use ($connection, $channelName) {
202+
})
203+
->then(function () use ($connection, $channelName) {
197204
return $this->removeChannelFromSet($connection->app->id, $channelName);
198-
})->then(function () use ($connection) {
205+
})
206+
->then(function () use ($connection) {
199207
return $this->removeConnectionFromSet($connection);
200-
})->then(function () use ($connection, $channelName, $payload) {
208+
})
209+
->then(function () use ($connection, $channelName, $payload) {
201210
return parent::unsubscribeFromChannel($connection, $channelName, $payload);
202211
});
203212
}
@@ -211,9 +220,10 @@ public function unsubscribeFromChannel(ConnectionInterface $connection, string $
211220
*/
212221
public function subscribeToApp($appId): PromiseInterface
213222
{
214-
return $this->subscribeToTopic($appId)->then(function () use ($appId) {
215-
return $this->incrementSubscriptionsCount($appId);
216-
});
223+
return $this->subscribeToTopic($appId)
224+
->then(function () use ($appId) {
225+
return $this->incrementSubscriptionsCount($appId);
226+
});
217227
}
218228

219229
/**
@@ -225,9 +235,10 @@ public function subscribeToApp($appId): PromiseInterface
225235
*/
226236
public function unsubscribeFromApp($appId): PromiseInterface
227237
{
228-
return $this->unsubscribeFromTopic($appId)->then(function () use ($appId) {
229-
return $this->decrementSubscriptionsCount($appId);
230-
});
238+
return $this->unsubscribeFromTopic($appId)
239+
->then(function () use ($appId) {
240+
return $this->decrementSubscriptionsCount($appId);
241+
});
231242
}
232243

233244
/**
@@ -297,7 +308,8 @@ public function userJoinedPresenceChannel(ConnectionInterface $connection, stdCl
297308
return $this->storeUserData($connection->app->id, $channel, $connection->socketId, json_encode($user))
298309
->then(function () use ($connection, $channel, $user) {
299310
return $this->addUserSocket($connection->app->id, $channel, $user, $connection->socketId);
300-
})->then(function () use ($connection, $user, $channel, $payload) {
311+
})
312+
->then(function () use ($connection, $user, $channel, $payload) {
301313
return parent::userJoinedPresenceChannel($connection, $user, $channel, $payload);
302314
});
303315
}
@@ -316,7 +328,8 @@ public function userLeftPresenceChannel(ConnectionInterface $connection, stdClas
316328
return $this->removeUserData($connection->app->id, $channel, $connection->socketId)
317329
->then(function () use ($connection, $channel, $user) {
318330
return $this->removeUserSocket($connection->app->id, $channel, $user, $connection->socketId);
319-
})->then(function () use ($connection, $user, $channel) {
331+
})
332+
->then(function () use ($connection, $user, $channel) {
320333
return parent::userLeftPresenceChannel($connection, $user, $channel);
321334
});
322335
}
@@ -370,9 +383,10 @@ public function getChannelsMembersCount($appId, array $channelNames): PromiseInt
370383
);
371384
}
372385

373-
return $this->publishClient->exec()->then(function ($data) use ($channelNames) {
374-
return array_combine($channelNames, $data);
375-
});
386+
return $this->publishClient->exec()
387+
->then(function ($data) use ($channelNames) {
388+
return array_combine($channelNames, $data);
389+
});
376390
}
377391

378392
/**
@@ -399,9 +413,10 @@ public function getMemberSockets($userId, $appId, $channelName): PromiseInterfac
399413
public function connectionPonged(ConnectionInterface $connection): PromiseInterface
400414
{
401415
// This will update the score with the current timestamp.
402-
return $this->addConnectionToSet($connection, Carbon::now())->then(function () use ($connection) {
403-
return parent::connectionPonged($connection);
404-
});
416+
return $this->addConnectionToSet($connection, Carbon::now())
417+
->then(function () use ($connection) {
418+
return parent::connectionPonged($connection);
419+
});
405420
}
406421

407422
/**

0 commit comments

Comments
 (0)