Skip to content

Commit 99ae850

Browse files
authored
Merge pull request #3 from 7span/hotfix/channel-response-change
Change the response of create and listing channel
2 parents 8800d59 + 1cedb05 commit 99ae850

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/Channel.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@
1313

1414
class Channel
1515
{
16-
public function list(int $userId, int $perPage = null)
16+
public function list(int $userId = null, array $channelIds = [], int $perPage = null)
1717
{
1818
$channels = ChannelModel::select('channels.id', 'name', 'channel_id', 'unread_message_count')
19-
->join('channel_users', 'channels.id', '=', 'channel_users.channel_id')
20-
->where('channel_users.user_id', $userId)
21-
->orderBy('channel_users.unread_message_count', 'DESC');
19+
->join('channel_users', 'channels.id', '=', 'channel_users.channel_id');
20+
21+
if (!empty($userId)) {
22+
$channels->where('channel_users.user_id', $userId);
23+
}
24+
25+
if (count($channelIds) > 0) {
26+
$channels->whereIn('channels.id', $channelIds);
27+
}
28+
29+
$channels->orderBy('channel_users.unread_message_count', 'DESC');
2230
$channels = $perPage ? $channels->paginate($perPage) : $channels->get();
2331
return $channels;
2432
}
@@ -52,8 +60,9 @@ public function create(int $userId, int $receiverId, string $channelName)
5260

5361
broadcast(new CreateChannel($channel))->toOthers();
5462

55-
$data['message'] = "Channel created successfully.";
56-
return $data;
63+
$response['message'] = "Channel created successfully.";
64+
$response['data'] = $channel;
65+
return $response;
5766
}
5867

5968
public function update(int $userId, int $channelId, $channelName)

0 commit comments

Comments
 (0)