|
13 | 13 |
|
14 | 14 | class Channel |
15 | 15 | { |
16 | | - public function list(int $userId, int $perPage = null) |
| 16 | + public function list(int $userId = null, array $channelIds = [], int $perPage = null) |
17 | 17 | { |
18 | 18 | $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'); |
22 | 30 | $channels = $perPage ? $channels->paginate($perPage) : $channels->get(); |
23 | 31 | return $channels; |
24 | 32 | } |
@@ -52,8 +60,9 @@ public function create(int $userId, int $receiverId, string $channelName) |
52 | 60 |
|
53 | 61 | broadcast(new CreateChannel($channel))->toOthers(); |
54 | 62 |
|
55 | | - $data['message'] = "Channel created successfully."; |
56 | | - return $data; |
| 63 | + $response['message'] = "Channel created successfully."; |
| 64 | + $response['data'] = $channel; |
| 65 | + return $response; |
57 | 66 | } |
58 | 67 |
|
59 | 68 | public function update(int $userId, int $channelId, $channelName) |
|
0 commit comments