diff --git a/app/Http/Controllers/Chat/ChannelsController.php b/app/Http/Controllers/Chat/ChannelsController.php index 40d9f07c08d..372acccd2f9 100644 --- a/app/Http/Controllers/Chat/ChannelsController.php +++ b/app/Http/Controllers/Chat/ChannelsController.php @@ -205,7 +205,7 @@ public function show($channelId) 'channel' => json_item($channel, ChannelTransformer::forUser($user), ChannelTransformer::LISTING_INCLUDES), // TODO: probably going to need a better way to list/fetch/update users on larger channels without sending user on every message. 'users' => json_collection( - $channel->visibleUsers($user)->loadMissing(UserCompactTransformer::CARD_INCLUDES_PRELOAD), + $channel->visibleUsers()->loadMissing(UserCompactTransformer::CARD_INCLUDES_PRELOAD), new UserCompactTransformer(), UserCompactTransformer::CARD_INCLUDES ), diff --git a/app/Models/Chat/Channel.php b/app/Models/Chat/Channel.php index c59ee595d9a..44866f439d9 100644 --- a/app/Models/Chat/Channel.php +++ b/app/Models/Chat/Channel.php @@ -291,13 +291,9 @@ public function users(): Collection }); } - public function visibleUsers(?User $user) + public function visibleUsers(): Collection { - if ($this->isPM() || $this->isAnnouncement() && priv_check_user($user, 'ChatAnnounce', $this)->can()) { - return $this->users(); - } - - return new Collection(); + return $this->isPM() ? $this->users() : new Collection(); } public function scopePublic($query) diff --git a/app/Transformers/Chat/ChannelTransformer.php b/app/Transformers/Chat/ChannelTransformer.php index e7126739534..c0e636ab7c2 100644 --- a/app/Transformers/Chat/ChannelTransformer.php +++ b/app/Transformers/Chat/ChannelTransformer.php @@ -99,14 +99,7 @@ public function includeRecentMessages(Channel $channel) public function includeUsers(Channel $channel) { - if ( - $channel->isPM() - || $channel->isAnnouncement() && priv_check_user($this->user, 'ChatAnnounce', $channel)->can() - ) { - return $this->primitive($channel->userIds()); - } - - return $this->primitive([]); + return $this->primitive($channel->isPM() ? $channel->userIds() : []); } public function includeUuid(Channel $channel) diff --git a/tests/Models/Chat/ChannelTest.php b/tests/Models/Chat/ChannelTest.php index 372bf003d54..5ea8eb29786 100644 --- a/tests/Models/Chat/ChannelTest.php +++ b/tests/Models/Chat/ChannelTest.php @@ -279,7 +279,7 @@ public function testPublicChannelDoesNotShowUsers() $channel = Channel::factory()->type('public', [$user])->create(); $this->assertSame(1, $channel->users()->count()); - $this->assertEmpty($channel->visibleUsers($user)); + $this->assertEmpty($channel->visibleUsers()); } // test add/removeUser resets any memoized values