diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index e5ad549a6..0f47f9f37 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -660,7 +660,7 @@ Sources: [issue command UI](resources/js/components/issue-command.tsx), [issue v Guilds are public groups around hashtags and are not generally available yet. In the preview, matching hashtags become small clickable guild labels; ordinary hashtags still open search. Create a guild from the Guilds overview or a hashtag's search page. From the overview, its display name determines the hashtag: “Laravel 4ever” becomes `#laravel4ever`. Display names and handles each allow up to 60 characters. When claiming a hashtag, the display name must match its letters, numbers and underscores, ignoring case; spaces, punctuation and decorative symbols are ignored, so `/dev/null` is valid for `#devnull`. Accents and underscores remain significant. Its creator joins automatically and maintains its icon and description. Each person can create up to 100 guilds. A guild's name, description and icon pass the same automated moderation as commits before the guild is published or edited; a guild that the moderation flags is not saved. -The Guilds page lists groups by member count. Joining adds matching commits to Following without following every author and clears any existing mute. When a commit appears only because of a joined guild, it says “because you joined” beside the guild label. Leave a guild to reveal its Mute control. Muting hides matching commits from logs and search, including commits by followed authors. You can still open the guild or a commit directly. +The Guilds page lists groups by member count. Click a guild's member count to browse its members: the moderator appears first, labeled “(moderator)”, followed by newest joins, with 50 people per page and Load more for the next page. Joining adds matching commits to Following without following every author and clears any existing mute. When a commit appears only because of a joined guild, it says “because you joined” beside the guild label. Leave a guild to reveal its Mute control. Muting hides matching commits from logs and search, including commits by followed authors. You can still open the guild or a commit directly. Each guild's bulletin board shows commits posted directly to it and regular commits containing its exact hashtag—not semantic search. Matching replies bring their thread onto the board, even when the root has no hashtag. Threads show reply previews and expand like a regular commit log, ordered by root date, newest first. Each page contains 30 distinct root commits; replies do not use up that limit, and Load more adds the next page. Posts from the board's composer stay attached to that guild without an automatic hashtag, including scheduled posts. They count toward the author's commit count but do not appear in their profile log or general feeds. They appear in Following when you join the guild, and in semantic search suggestions and results under a divider with the guild's name and icon. Regular hashtag commits keep appearing on profiles and in feeds as usual. Typing a hashtag offers matching guilds in the autocomplete menu; select one with the keyboard or pointer to insert its handle. diff --git a/app/Http/Controllers/GuildMembershipController.php b/app/Http/Controllers/GuildMembershipController.php index 7205c7b29..e2b9b8dcc 100644 --- a/app/Http/Controllers/GuildMembershipController.php +++ b/app/Http/Controllers/GuildMembershipController.php @@ -5,14 +5,36 @@ namespace App\Http\Controllers; use App\Actions\UpdateGuildMembership; +use App\Http\Requests\ListGuildMembersRequest; use App\Http\Requests\UpdateGuildMembershipRequest; use App\Models\Guild; use App\Models\User; use Illuminate\Container\Attributes\CurrentUser; use Illuminate\Http\RedirectResponse; +use Inertia\Inertia; +use Inertia\Response; final readonly class GuildMembershipController { + public function index(ListGuildMembersRequest $request, Guild $guild): Response + { + return Inertia::render('guild/members', [ + 'guild' => $guild, + 'users' => Inertia::scroll(fn () => $guild->members() + ->orderByRaw('(users.id = ?) desc nulls last', [$guild->user_id]) + ->orderByPivot('joined_at', 'desc')->latest('users.id') + ->paginate(50)->through(fn (User $member): array => [ + 'id' => $member->id, + 'handle' => $member->handle, + 'name' => $member->name, + 'avatar_url' => $member->avatar_url, + 'bio' => $member->bio, + 'lane' => $member->lane(), + 'is_moderator' => $member->id === $guild->user_id, + ])), + ])->withViewData(['robots' => 'noindex, follow']); + } + public function update(UpdateGuildMembershipRequest $request, Guild $guild, #[CurrentUser] User $user, UpdateGuildMembership $action): RedirectResponse { $action->handle($user, $guild, $request->boolean('joined')); diff --git a/app/Http/Requests/ListGuildMembersRequest.php b/app/Http/Requests/ListGuildMembersRequest.php new file mode 100644 index 000000000..0b839c78e --- /dev/null +++ b/app/Http/Requests/ListGuildMembersRequest.php @@ -0,0 +1,24 @@ +available(Feature::Guilds, $this->user()) ? Response::allow() : Response::denyAsNotFound(); + } + + /** @return array> */ + public function rules(): array + { + return ['page' => ['sometimes', 'integer', 'min:1']]; + } +} diff --git a/resources/js/components/guild-preferences.tsx b/resources/js/components/guild-preferences.tsx index 740f27a3e..59b39494b 100644 --- a/resources/js/components/guild-preferences.tsx +++ b/resources/js/components/guild-preferences.tsx @@ -1,7 +1,10 @@ -import { router } from '@inertiajs/react'; +import { Link, router } from '@inertiajs/react'; import { UserPlus, Volume2, VolumeX } from 'lucide-react'; import { useState } from 'react'; -import { update as membership } from '@/actions/App/Http/Controllers/GuildMembershipController'; +import { + index as members, + update as membership, +} from '@/actions/App/Http/Controllers/GuildMembershipController'; import { update as mute } from '@/actions/App/Http/Controllers/GuildMuteController'; import { useFollowHover } from '@/components/follow-button'; import { Button } from '@/components/ui/button'; @@ -10,8 +13,10 @@ import type { Guild } from '@/types/guild'; export function GuildMemberCount({ guild }: { guild: Guild }) { return ( - {guild.member_count === 1 ? 'member' : 'members'} - + ); } diff --git a/resources/js/pages/guild/members.tsx b/resources/js/pages/guild/members.tsx new file mode 100644 index 000000000..444b7b0ed --- /dev/null +++ b/resources/js/pages/guild/members.tsx @@ -0,0 +1,133 @@ +import { Head, InfiniteScroll, Link } from '@inertiajs/react'; +import { ArrowLeft } from 'lucide-react'; +import type { CSSProperties } from 'react'; +import { show } from '@/actions/App/Http/Controllers/GuildController'; +import { EmptyFeed } from '@/components/commit-feed'; +import { Button } from '@/components/ui/button'; +import { Spinner } from '@/components/ui/spinner'; +import { UserAvatar } from '@/components/user-avatar'; +import AppLayout from '@/layouts/app-layout'; +import { laneColor } from '@/lib/utils'; +import { show as profile } from '@/routes/user'; +import type { User } from '@/types'; +import type { Guild } from '@/types/guild'; + +export default function Members({ + guild, + users, +}: { + guild: Pick; + users: { + data: (Pick< + User, + 'id' | 'handle' | 'name' | 'avatar_url' | 'bio' | 'lane' + > & { is_moderator: boolean })[]; + }; +}) { + return ( + <> + +
+ + + +

+ {guild.name} +

+

+ Members +

+
+ {users.data.length === 0 ? ( +
+ + Nobody has joined this guild yet. + +
+ ) : ( + + hasMore && ( +
+ +
+ ) + } + > +
    + {users.data.map((person) => ( +
  • + + +
    +
    +

    + {person.name} +

    + {person.is_moderator && ( + + (moderator) + + )} +
    +

    + @{person.handle} +

    + {person.bio && ( +

    + {person.bio} +

    + )} +
    + +
  • + ))} +
+
+ )} + + ); +} + +Members.layout = AppLayout; diff --git a/routes/web.php b/routes/web.php index 2da68649e..f7065f281 100644 --- a/routes/web.php +++ b/routes/web.php @@ -362,6 +362,7 @@ Route::middleware('auth')->group(function (): void { Route::get('guilds', [GuildController::class, 'index'])->name('guild.index'); Route::get('guilds/{guild:handle}', [GuildController::class, 'show'])->name('guild.show'); + Route::get('guilds/{guild:handle}/members', [GuildMembershipController::class, 'index'])->name('guild-membership.index'); Route::get('guilds/{guild:handle}/icon', [GuildIconController::class, 'show'])->name('guild-icon.show'); Route::post('guilds', [GuildController::class, 'store'])->middleware([PreventPostingInTimeout::class, 'throttle:10,1'])->name('guild.store'); Route::put('guilds/{guild:handle}', [GuildController::class, 'update'])->middleware([PreventPostingInTimeout::class, 'throttle:10,1'])->name('guild.update'); diff --git a/tests/Feature/Controllers/GuildMembershipControllerTest.php b/tests/Feature/Controllers/GuildMembershipControllerTest.php new file mode 100644 index 000000000..c9769adb1 --- /dev/null +++ b/tests/Feature/Controllers/GuildMembershipControllerTest.php @@ -0,0 +1,73 @@ + ['admin']]); +}); + +it('lists the moderator first then joined members newest first in pages of fifty without private preferences', function (): void { + $viewer = User::factory()->create(['handle' => 'admin']); + $moderator = User::factory()->create(); + $guild = Guild::factory()->create(['user_id' => $moderator->id]); + $older = User::factory()->create(); + $members = User::factory()->count(50)->create(); + $guild->members()->attach($moderator, ['joined_at' => now()->subDays(2)]); + $guild->members()->attach($older, ['joined_at' => now()->subDay()]); + $guild->members()->attach($members->modelKeys(), ['joined_at' => now()]); + $guild->muters()->attach(User::factory()->create(), ['muted_at' => now()]); + Guild::factory()->create()->members()->attach(User::factory()->create(), ['joined_at' => now()]); + + $this->actingAs($viewer)->get(route('guild-membership.index', $guild->handle)) + ->assertOk()->assertInertia(fn ($page) => $page + ->component('guild/members') + ->where('guild.handle', $guild->handle) + ->has('users.data', 50) + ->where('users.data.0.id', $moderator->id) + ->where('users.data.0.is_moderator', true) + ->where('users.data.1.is_moderator', false) + ->where('users.data', fn ($users): bool => collect($users)->pluck('id')->all() === [$moderator->id, ...$members->sortByDesc('id')->take(49)->values()->modelKeys()]) + ->where('users.current_page', 1) + ->where('users.per_page', 50) + ->where('users.next_page_url', route('guild-membership.index', ['guild' => $guild->handle, 'page' => 2])) + ->missing('users.data.0.email') + ->missing('users.data.0.pivot')); + + $this->get(route('guild-membership.index', ['guild' => $guild->handle, 'page' => 2])) + ->assertOk()->assertInertia(fn ($page) => $page + ->has('users.data', 2) + ->where('users.data.0.id', $members->sortBy('id')->first()->id) + ->where('users.data.1.id', $older->id) + ->where('users.next_page_url', null)); +}); + +it('keeps paused guild members accessible and supports an empty list', function (): void { + $viewer = User::factory()->create(['handle' => 'admin']); + $guild = Guild::factory()->create(['user_id' => null]); + + $this->actingAs($viewer)->get(route('guild-membership.index', $guild->handle)) + ->assertOk()->assertInertia(fn ($page) => $page->has('users.data', 0)->where('users.next_page_url', null)); + + $guild->members()->attach($viewer, ['joined_at' => now()]); + + $this->get(route('guild-membership.index', $guild->handle)) + ->assertOk()->assertInertia(fn ($page) => $page->has('users.data', 1)->where('users.data.0.id', $viewer->id)->where('users.data.0.is_moderator', false)); +}); + +it('requires sign in and the guild preview feature to list members', function (): void { + $guild = Guild::factory()->create(); + + $this->get(route('guild-membership.index', $guild->handle))->assertRedirectToRoute('home'); + $this->actingAs(User::factory()->create())->get(route('guild-membership.index', $guild->handle))->assertNotFound(); +}); + +it('rejects invalid member pages', function (mixed $page): void { + $guild = Guild::factory()->create(); + + $this->actingAs(User::factory()->create(['handle' => 'admin'])) + ->getJson(route('guild-membership.index', ['guild' => $guild->handle, 'page' => $page])) + ->assertUnprocessable()->assertJsonValidationErrors('page'); +})->with([0, 'not-a-page']);