Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't send user ids for announcement channels #11510

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Controllers/Chat/ChannelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
Expand Down
8 changes: 2 additions & 6 deletions app/Models/Chat/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions app/Transformers/Chat/ChannelTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/Models/Chat/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down