Skip to content
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
6 changes: 3 additions & 3 deletions KNOWLEDGE_BASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/GuildController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
22 changes: 16 additions & 6 deletions app/Queries/GuildCommitsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,6 +119,14 @@ public function joinedFor(iterable $commits, User $user): array

/** @return LazyCollection<int, string> */
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<int, Fluent<array-key, mixed>> */
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))
Expand All @@ -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<int, Commit> */
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')])
Comment thread
paulinevos marked this conversation as resolved.
Resolved
->newestFirst()->get();

return new Paginator($commits, 30, $page, ['path' => Paginator::resolveCurrentPath()]);
Expand Down
62 changes: 43 additions & 19 deletions resources/js/pages/guild/show.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -313,29 +314,52 @@ export default function Show({
commit={commit}
endsWithDot
threadActions={
canModerate && (
commit.parent_id ? (
<Button
variant="ghost"
size="sm"
className="min-h-9 px-2 text-[13px] text-muted-foreground aria-pressed:text-primary"
aria-label={`${isPinned ? 'Unpin from' : 'Pin to'} board`}
aria-pressed={isPinned}
title={
isPinned
? 'Unpin from board'
: 'Pin to board'
}
disabled={
isPinning || isLoading
}
onClick={() => pin(commit)}
className="min-h-9 px-2 text-[13px] text-muted-foreground"
asChild
>
<Pin
aria-hidden
className="size-3.5"
/>
Pin
<Link
prefetch
href={showCommit({
profile:
commit.author,
commit,
})}
>
View full thread
</Link>
</Button>
) : (
canModerate && (
<Button
variant="ghost"
size="sm"
className="min-h-9 px-2 text-[13px] text-muted-foreground aria-pressed:text-primary"
aria-label={`${isPinned ? 'Unpin from' : 'Pin to'} board`}
aria-pressed={isPinned}
title={
isPinned
? 'Unpin from board'
: 'Pin to board'
}
disabled={
isPinning ||
isLoading
}
onClick={() =>
pin(commit)
}
>
<Pin
aria-hidden
className="size-3.5"
/>
Pin
</Button>
)
)
}
/>
Expand Down
33 changes: 32 additions & 1 deletion tests/Feature/Controllers/Api/GuildControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/Controllers/GuildCommitPinControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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 {
Expand Down
Loading
Loading