diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index 888e7ce8f0..4cf327f296 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -596,7 +596,7 @@ A signed request sees what the web shows you, such as your own pending commits a - read who to follow, also as it is suggested beside a profile or a commit, and mark a suggestion not interested; - read the hot topics, and each one's commits from the past week with its recap; - list guilds as the Guilds page does, 24 a page, searched by name, handle or description, with whether you joined or muted each one and whether it is paused, while guilds are available to you; -- read a guild's board as its page does, 30 threads a page with reply previews, with the guild, its pinned commit and whether you moderate it, while guilds are available to you. The pinned commit also keeps its place in the list, so an app that shows it apart skips it there by its id; +- read a guild's board as its page does, 30 matching commits a page with reply previews, with the guild, its pinned commit and whether you moderate it, while guilds are available to you. When the pinned commit also appears in the list, an app that shows it apart skips it there by its id; - list a guild's members as its members page does, the moderator first and then the newest joins, 50 a page, with whether you follow each one and whether each one follows you, and the moderator's id, while guilds are available to you; - create a guild, or claim a paused one, as the Guilds page does, with the same rules and limit of 100, where a guild the moderation flags waits for an admin's review instead, while guilds are available to you; - edit the display name, description, emoji and icon of a guild you moderate, as Edit guild does, where an edit the moderation flags waits for an admin's review and the guild stays as it was, while guilds are available to you; @@ -668,9 +668,9 @@ The guilds you joined are listed in the left navigation, with the guilds that ha While guilds are available to you, profiles show a guild count beside following and followers. Click it to see the guilds that person has joined, listed by hashtag, with links to their boards. You can join or leave those guilds directly from the list. Muting a guild does not remove it from this membership list; leaving does. -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. Outside the board, such as when one is opened by its link, a board post names the guild it was posted in and notes that it is not shown in general logs. 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. +Each guild's bulletin board shows commits posted directly to it and regular commits containing its exact hashtag—not semantic search. Matching replies appear directly on the board, even when nested in a thread whose root has no hashtag. Replies show who they are replying to when that parent is visible, and “View full thread” opens the conversation with the matching reply in focus. Commits show reply previews and expand like a regular commit log, ordered by their own date, newest first. Each page contains 30 matching commits, replies included, 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. Outside the board, such as when one is opened by its link, a board post names the guild it was posted in and notes that it is not shown in general logs. 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. -The guild's moderator can pin one commit from its board, including a thread brought in by a matching reply. It appears first with a “Pinned to board” label, without appearing twice or changing profile pins or other guilds. The pin is separate from the 30 chronological threads per page, so pinning never changes what Load more brings in. Pinning another replaces it; unpinning restores its natural position if already loaded, or removes its promotion until you load that older page. A pin never overrides visibility, blocks or author mutes, and disappears from the board if the thread no longer matches the guild. Permanently deleting the pinned commit clears the pin. +The guild's moderator can pin one top-level commit from its board. Existing pins of threads brought in by a matching reply remain visible. The pin appears first with a “Pinned to board” label, without appearing twice or changing profile pins or other guilds. The pin is separate from the 30 chronological matching commits per page, so pinning never changes what Load more brings in. Pinning another replaces it; unpinning restores its natural position if already loaded, or removes its promotion. A pin never overrides visibility, blocks or author mutes, and disappears from the board if the thread no longer matches the guild. Permanently deleting the pinned commit clears the pin. Guild descriptions can be reported privately. When a guild has no moderator, including after its moderator deletes their account, it is paused, not deleted. Its page, posts, icon, description, memberships and mute preferences stay connected. New board posts wait until it has a moderator; scheduled board posts stay pending and keep their guild, and committing one now says the guild is paused. Ordinary hashtag commits still appear. A different person can claim the hashtag to resume the same guild, but a removed moderator cannot reclaim it. diff --git a/app/Http/Controllers/Api/GuildController.php b/app/Http/Controllers/Api/GuildController.php index eb63c2e766..945229e951 100644 --- a/app/Http/Controllers/Api/GuildController.php +++ b/app/Http/Controllers/Api/GuildController.php @@ -62,9 +62,9 @@ public function store(CreateApiGuildRequest $request, #[CurrentUser] User $user, } /** - * The guild's board as its page on the web shows it: 30 threads per page, newest first. Everyone gets the pin the - * moderator set beside them, and it keeps its place on the board, which the web's page skips. One snapshot reads the - * board, the pin and the guild, so they agree. + * The guild's board as its page on the web shows it: 30 matching commits per page, newest first. Everyone gets the + * moderator's pin beside them; when it also matches directly, the web skips its duplicate in the list. One snapshot + * reads the board, the pin and the guild, so they agree. */ public function show(ShowApiGuildRequest $request, Guild $guild, #[CurrentUser] User $user, GuildsQuery $guilds, GuildCommitsQuery $commits, ReplyPreviewsQuery $replyPreviews): AnonymousResourceCollection { diff --git a/app/Queries/GuildCommitsQuery.php b/app/Queries/GuildCommitsQuery.php index 09249f63e7..4dc8dbf362 100644 --- a/app/Queries/GuildCommitsQuery.php +++ b/app/Queries/GuildCommitsQuery.php @@ -12,6 +12,7 @@ use App\Services\Hashtags; use Closure; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Query\Builder; use Illuminate\Database\Query\JoinClause; use Illuminate\Pagination\Paginator; @@ -118,6 +119,14 @@ public function joinedFor(iterable $commits, User $user): array /** @return LazyCollection */ public function rootIds(Guild $guild, User $viewer, ?string $forRoot = null): LazyCollection + { + return $this->matches($guild, $viewer, $forRoot) + ->map(fn (Fluent $commit): string => $commit->string('root_id')->value()) + ->unique()->values(); + } + + /** @return LazyCollection> */ + private function matches(Guild $guild, User $viewer, ?string $forRoot = null): LazyCollection { $roots = Commit::query()->topLevel()->visibleTo($viewer)->withoutMutedAuthorsFor($viewer) ->when($forRoot !== null, fn (CommitBuilder $query): CommitBuilder => $query->whereKey($forRoot)) @@ -127,22 +136,23 @@ public function rootIds(Guild $guild, User $viewer, ?string $forRoot = null): La ->where(fn (CommitBuilder $query): CommitBuilder => $query->where('guild_id', $guild->id) ->orWhere(fn (CommitBuilder $query): CommitBuilder => $query->whereNull('guild_id')->whereLike('body', '%#%'))) ->joinSub($roots, 'roots', fn (JoinClause $join): JoinClause => $join->on('roots.id', '=', DB::raw('coalesce(commits.root_id, commits.id)'))) - ->orderByDesc('roots.created_at')->orderByDesc('roots.id')->orderBy('commits.id') - ->select(['roots.id', 'commits.body', 'commits.guild_id'])->toBase()->cursor() + ->newestFirst() + ->select(['commits.id', 'roots.id as root_id', 'commits.body', 'commits.guild_id'])->toBase()->cursor() ->map(fn (stdClass $commit): Fluent => new Fluent(get_object_vars($commit))) ->filter(fn (Fluent $commit): bool => $commit->get('guild_id') !== null - || (str_contains(str_replace('ς', 'σ', mb_strtolower($commit->string('body')->value())), '#'.str_replace('ς', 'σ', $guild->handle)) && in_array($guild->handle, $this->hashtags->handles($commit->string('body')->value()), true))) - ->map(fn (Fluent $commit): string => $commit->string('id')->value()) - ->unique()->values(); + || (str_contains(str_replace('ς', 'σ', mb_strtolower($commit->string('body')->value())), '#'.str_replace('ς', 'σ', $guild->handle)) && in_array($guild->handle, $this->hashtags->handles($commit->string('body')->value()), true))); } /** @return Paginator */ private function page(Guild $guild, User $viewer, int $page): Paginator { - $ids = $this->rootIds($guild, $viewer)->skip(($page - 1) * 30)->take(31)->all(); + $ids = $this->matches($guild, $viewer)->skip(($page - 1) * 30)->take(31) + ->map(fn (Fluent $commit): string => $commit->string('id')->value())->all(); $commits = Commit::query()->whereKey($ids) ->withVisibleReplyCount($viewer)->withReplyPreviews($viewer)->withCardDataFor($viewer) + ->with(['parent' => fn (BelongsTo $parent): BelongsTo => $parent + ->withTrashed()->visibleTo($viewer)->withoutMutedAuthorsFor($viewer)->with('author')]) ->newestFirst()->get(); return new Paginator($commits, 30, $page, ['path' => Paginator::resolveCurrentPath()]); diff --git a/resources/js/pages/guild/show.tsx b/resources/js/pages/guild/show.tsx index 5804b9aa00..a8279e4821 100644 --- a/resources/js/pages/guild/show.tsx +++ b/resources/js/pages/guild/show.tsx @@ -1,7 +1,8 @@ -import { Head, router, usePage } from '@inertiajs/react'; +import { Head, Link, router, usePage } from '@inertiajs/react'; import { Pencil, Pin } from 'lucide-react'; import { useEffect, useLayoutEffect, useRef, useState } from 'react'; import { toast } from 'sonner'; +import { show as showCommit } from '@/actions/App/Http/Controllers/CommitController'; import { update as updatePin } from '@/actions/App/Http/Controllers/GuildCommitPinController'; import { show } from '@/actions/App/Http/Controllers/GuildController'; import { update as updateRead } from '@/actions/App/Http/Controllers/GuildReadController'; @@ -313,29 +314,52 @@ export default function Show({ commit={commit} endsWithDot threadActions={ - canModerate && ( + commit.parent_id ? ( + ) : ( + canModerate && ( + + ) ) } /> diff --git a/tests/Feature/Controllers/Api/GuildControllerTest.php b/tests/Feature/Controllers/Api/GuildControllerTest.php index 52c2bada99..9b4293fde3 100644 --- a/tests/Feature/Controllers/Api/GuildControllerTest.php +++ b/tests/Feature/Controllers/Api/GuildControllerTest.php @@ -137,7 +137,38 @@ ->assertJsonPath('can_moderate', false); }); -it('pages the board 30 roots at a time', function (): void { +it('shows a nested guild mention instead of its untagged root', function (): void { + Guild::factory()->create(['handle' => 'rust']); + $root = Commit::factory()->create(['body' => 'An older conversation', 'created_at' => now()->subYear()]); + $parent = Commit::factory()->for($root, 'parent')->create(['body' => 'An untagged reply']); + $match = Commit::factory()->for($parent, 'parent')->create(['body' => 'Learning #rust']); + + signedApiRequest($this->keyPair, 'GET', route('api-guild.show', 'rust')) + ->assertOk() + ->assertJsonPath('data.*.id', [$match->id]) + ->assertJsonPath('data.0.body', 'Learning #rust') + ->assertJsonPath('data.0.parent.id', $parent->id); +}); + +it('keeps a matching guild reply visible with only a tombstone for its deleted parent', function (): void { + Guild::factory()->create(['handle' => 'rust']); + $root = Commit::factory()->create(); + $parent = Commit::factory()->for($root, 'parent')->create(['body' => 'Deleted parent context']); + $match = Commit::factory()->for($parent, 'parent')->create(['body' => 'A public #rust reply']); + $parent->delete(); + + signedApiRequest($this->keyPair, 'GET', route('api-guild.show', 'rust')) + ->assertOk() + ->assertJsonPath('data.*.id', [$match->id]) + ->assertJsonPath('data.0.body', 'A public #rust reply') + ->assertJsonPath('data.0.parent', [ + 'id' => $parent->id, + 'parent_id' => $root->id, + 'deleted_at' => now()->toIso8601ZuluString(), + ]); +}); + +it('pages the board 30 matching commits at a time', function (): void { $rust = Guild::factory()->create(['handle' => 'rust']); $oldest = Commit::factory()->for($rust)->create(['created_at' => now()->subYear()]); Commit::factory()->for($rust)->count(30)->create(); diff --git a/tests/Feature/Controllers/GuildCommitPinControllerTest.php b/tests/Feature/Controllers/GuildCommitPinControllerTest.php index cf95e26e61..b9d1379b8c 100644 --- a/tests/Feature/Controllers/GuildCommitPinControllerTest.php +++ b/tests/Feature/Controllers/GuildCommitPinControllerTest.php @@ -28,9 +28,9 @@ 'guild_id' => $kind === 'board' ? $guild->id : null, 'created_at' => now()->subYear(), ]); - if ($kind === 'reply') { - Commit::factory()->for($commit, 'parent')->create(['body' => 'Discuss #rust here']); - } + $listed = $kind === 'reply' + ? Commit::factory()->for($commit, 'parent')->create(['body' => 'Discuss #rust here']) + : $commit; $newer = Commit::factory()->for($guild)->create(); Event::fake([UsersUpdated::class]); @@ -43,7 +43,7 @@ && collect($event->userIds)->sort()->values()->all() === collect([$moderator->id, $member->id])->sort()->values()->all()); $this->actingAs(User::factory()->create(['handle' => 'viewer']))->get(route('guild.show', $guild->handle)) ->assertInertia(fn ($page) => $page->where('pinnedCommit.id', $commit->id)->where('canModerate', false) - ->where('commits.0.id', $newer->id)->where('commits.1.id', $commit->id)->has('commits', 2)); + ->where('commits.0.id', $newer->id)->where('commits.1.id', $listed->id)->has('commits', 2)); })->with(['board', 'hashtag', 'reply']); it('replaces pins and ignores stale unpins without changing profile pins', function (): void { diff --git a/tests/Feature/Controllers/GuildControllerTest.php b/tests/Feature/Controllers/GuildControllerTest.php index b7bc58ce74..e9881b13f1 100644 --- a/tests/Feature/Controllers/GuildControllerTest.php +++ b/tests/Feature/Controllers/GuildControllerTest.php @@ -308,7 +308,7 @@ ->has('commits', 1)->where('commits.0.id', $tagged->id)); }); -it('merges board posts and exact hashtags newest first with thirty roots per page', function (): void { +it('merges board posts and exact hashtags newest first with thirty matching commits per page', function (): void { $admin = User::factory()->create(['handle' => 'admin']); $guild = Guild::factory()->create(['handle' => 'café_dev']); $old = Commit::factory()->create(['body' => 'An old regular commit', 'created_at' => now()->subYear()]); @@ -316,18 +316,18 @@ $board = Commit::factory()->for($guild)->count(15)->create(['body' => 'Direct to the board']); Commit::factory()->count(122)->create(['body' => '`#café_dev` #café_developers']); Commit::factory()->for(Guild::factory())->create(['body' => 'Another board #café_dev']); - $reply = Commit::factory()->for($old, 'parent')->create(['body' => '#café_dev']); - Commit::factory()->for($reply, 'parent')->create(['body' => 'A nested #café_dev reply']); + $reply = Commit::factory()->for($old, 'parent')->create(['body' => '#café_dev', 'created_at' => now()->subMinute()]); + $nested = Commit::factory()->for($reply, 'parent')->create(['body' => 'A nested #café_dev reply']); $boardReply = Commit::factory()->for($board->last(), 'parent')->create(['body' => 'An ordinary reply']); - Commit::factory()->count(101)->for($board->last(), 'parent')->create(['body' => 'An older #café_dev match', 'created_at' => now()->subHour()]); - Commit::factory()->for($board->last(), 'parent')->create(['body' => 'Another #café_dev match']); $this->actingAs($admin)->get(route('guild.show', 'café_dev'))->assertOk()->assertInertia(fn ($page) => $page ->has('commits', 30)->where('hasMore', true)->where('page', 1) - ->where('commits.0.id', $board->last()->id)->where('commits.15.id', $tagged->last()->id) - ->has('commits.0.reply_preview.data', 3)->where('commits.0.reply_preview.data.1.id', $boardReply->id)); + ->where('commits.0.id', $nested->id)->where('commits.0.parent.id', $reply->id) + ->where('commits.1.id', $board->last()->id)->where('commits.16.id', $reply->id) + ->where('commits.17.id', $tagged->last()->id) + ->has('commits.1.reply_preview.data', 1)->where('commits.1.reply_preview.data.0.id', $boardReply->id)); $this->get(route('guild.show', ['guild' => 'café_dev', 'page' => 2]))->assertOk()->assertInertia(fn ($page) => $page - ->has('commits', 1)->where('commits.0.id', $old->id)->where('hasMore', false)->where('page', 2) - ->where('commits.0.reply_preview.data.0.id', $reply->id)); + ->has('commits', 2)->where('commits.0.id', $tagged[1]->id)->where('commits.1.id', $tagged[0]->id) + ->where('hasMore', false)->where('page', 2)); $this->getJson(route('guild.show', ['guild' => 'café_dev', 'page' => 0]))->assertUnprocessable()->assertJsonValidationErrors('page'); }); @@ -364,7 +364,7 @@ DB::disableQueryLog(); }); -it('includes roots matched only by nested replies without exposing hidden roots or replies', function (): void { +it('shows nested guild mentions directly without exposing hidden roots or replies', function (): void { $admin = User::factory()->create(['handle' => 'admin']); Guild::factory()->create(['handle' => 'rust']); $root = Commit::factory()->create(['body' => 'A regular thread']); @@ -381,11 +381,45 @@ Commit::factory()->for($muted)->for($unmatched, 'parent')->create(['body' => '#rust']); $this->actingAs($admin)->get(route('guild.show', 'rust'))->assertOk()->assertInertia(fn ($page) => $page - ->has('commits', 1)->where('commits.0.id', $root->id)->where('hasMore', false) - ->where('commits.0.reply_preview.data.0.id', $parent->id)); + ->has('commits', 1)->where('commits.0.id', $match->id)->where('hasMore', false) + ->where('commits.0.parent.id', $parent->id)->where('commits.0.body', 'A nested #rust reply')); $this->getJson(route('commit-reply.index', $parent))->assertOk()->assertJsonPath('data.0.id', $match->id); }); +it('keeps a matching guild reply visible with only a tombstone for its deleted parent', function (): void { + $viewer = User::factory()->create(['handle' => 'admin']); + Guild::factory()->create(['handle' => 'rust']); + $root = Commit::factory()->create(); + $parent = Commit::factory()->for($root, 'parent')->create(['body' => 'Deleted parent context']); + $match = Commit::factory()->for($parent, 'parent')->create(['body' => 'A public #rust reply']); + $parent->delete(); + + $this->actingAs($viewer)->get(route('guild.show', 'rust'))->assertOk()->assertInertia(fn ($page) => $page + ->has('commits', 1)->where('commits.0.id', $match->id)->where('commits.0.body', 'A public #rust reply') + ->where('commits.0.parent', [ + 'id' => $parent->id, + 'parent_id' => $root->id, + 'deleted_at' => now()->startOfSecond()->toJSON(), + ])); +}); + +it('keeps an unavailable parent out of a matching guild reply', function (string $hidden): void { + $viewer = User::factory()->create(['handle' => 'admin']); + Guild::factory()->create(['handle' => 'rust']); + $root = Commit::factory()->create(); + $parent = Commit::factory()->for($root, 'parent')->create(['body' => 'Private parent context']); + $match = Commit::factory()->for($parent, 'parent')->create(['body' => 'A public #rust reply']); + + if ($hidden === 'pending') { + $parent->update(['status' => CommitStatus::Pending]); + } else { + $viewer->muting()->attach($parent->user_id); + } + + $this->actingAs($viewer)->get(route('guild.show', 'rust'))->assertOk()->assertInertia(fn ($page) => $page + ->has('commits', 1)->where('commits.0.id', $match->id)->where('commits.0.parent', null)); +})->with(['pending', 'muted']); + it('matches decorated names to their hashtag while preserving their display spelling', function (string $handle, string $name): void { $this->actingAs(User::factory()->create(['handle' => 'admin']))->post(route('guild.store'), [ 'handle' => $handle, 'name' => $name, 'description' => 'A developer community.', 'emoji' => '☕', @@ -541,7 +575,7 @@ ->assertJsonPath('props.refreshedCommits.0.id', $parent->id) ->assertJsonCount(0, 'props.refreshedCommits.0.reply_preview.data'); $this->get(route('guild.show', 'rust'))->assertInertia(fn ($page) => $page - ->has('commits', 1)->where('commits.0.id', $parent->id)->where('commits.0.reply_preview.data.0.id', $reply->id)); + ->has('commits', 1)->where('commits.0.id', $reply->id)->where('commits.0.parent.id', $parent->id)); $this->getJson(route('commit-reply.index', [$parent, 'in_log' => true]))->assertOk()->assertJsonCount(0, 'data'); $this->getJson(route('commit-reply.index', [$parent, 'in_log' => true, 'ids' => [$reply->id]]))->assertOk()->assertJsonCount(0, 'data'); $this->getJson(route('commit-reply.index', $parent))->assertOk()->assertJsonPath('data.0.id', $reply->id);