diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md
index c86097248..c6650e490 100644
--- a/KNOWLEDGE_BASE.md
+++ b/KNOWLEDGE_BASE.md
@@ -594,8 +594,8 @@ A signed request sees what the web shows you, such as your own pending commits a
- follow or unfollow people and organizations, mute or unmute, and block or unblock, and list who you muted and blocked;
- 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;
+- list guilds as the Guilds page does, 24 a page, searched by name, handle, alias or description, with each guild's aliases, 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, by its handle or one of its aliases, 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;
- star or unstar, and list who starred your own commit, newest first, 20 a page;
- create polls on commits that are neither replies nor quotes, and vote on polls;
- change Remotes settings, read and send messages with images, link cards, and voice notes in conversations and orgs, mark them pulled, react to messages and list your reactions, pin and unpin org messages as a maintainer, find people, and start orgs;
@@ -652,7 +652,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 display name, icon and description; a new display name must still match the hashtag, so `#adhd` can become “ADHD” but never another hashtag. 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. When the moderation flags a new guild or an edit, it waits for an admin to review it instead: nothing of it is public until it is approved, the guild keeps its current details meanwhile, and a rejected submission is discarded. Submitting again for the same hashtag replaces the one still waiting, and new guilds waiting for review count toward the creation limit.
-The Guilds page lists groups by member count, with 24 guilds per page. Search matches keywords in guild names, handles, and descriptions, ignoring case; a leading `#` is optional. This directory search is keyword-based, not semantic. 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.
+The Guilds page lists groups by member count, with 24 guilds per page. Search matches keywords in guild names, handles, aliases, and descriptions, ignoring case; a leading `#` is optional. This directory search is keyword-based, not semantic. 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.
The guilds you joined are listed in the left navigation, with the guilds that have the most commits you missed first. Guilds with the same number of missed commits are ordered by how much you have committed in them, counting your recent approved commits. The count of missed commits starts from your last visit to the guild's board, or from when you joined, and leaves out your own commits, commits you cannot see, and commits by people you muted. Counts above 99 show as 99+, and a muted guild is not listed. Opening a board clears its count, and a line marks where the commits that are new since your last visit end.
@@ -660,6 +660,8 @@ While guilds are available to you, profiles show a guild count beside following
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.
+A guild's moderator can add aliases from its page: other hashtags that lead to the same guild. With `#golang` as an alias of `#go`, both hashtags show the guild's label, commits containing either appear on its board and count for joining, muting and missed commits, and `/guilds/golang` opens the same guild. An alias follows the rules of a handle: it starts with a letter, contains only letters, numbers and underscores, and allows up to 60 characters. It must be a free hashtag: one that is already a guild, including a paused guild, or already an alias of any guild cannot be used, and nobody can create a guild for a hashtag that is an alias. Each guild can have up to 10 aliases, and each passes the same automated moderation as commits; one that is flagged is refused. Aliases are listed beside the hashtag on the guild's page, the hashtag autocomplete finds a guild by an alias and inserts its handle, and the directory search matches them. The moderator can remove an alias at any time, which takes commits that only carry that hashtag off the board. Aliases stay with a paused guild.
+
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.
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.
@@ -672,7 +674,7 @@ Choose **Download JSON** in Settings → Profile to export your account data. Th
- the days you used /dev/null (dates, not times), oldest first, with which of its apps you used on each (days before apps were tracked say web, whatever you used, and a phone approved before the mobile app started identifying itself says other), and the last of them;
- your commits and replies (including pending, rejected, and deleted entries still stored), their cached translations, polls, and your votes;
- stars, followers and people you follow, mutes, blocks, and dismissed **Not interested** suggestions;
-- guilds you moderate, guilds and guild edits you submitted that are waiting for review, your guild memberships and mutes, reports you submitted, and guild moderator-removal records relating to your account;
+- guilds you moderate with their aliases, guilds and guild edits you submitted that are waiting for review, your guild memberships and mutes, reports you submitted, and guild moderator-removal records relating to your account;
- messages you sent, including links to your voice notes, and notifications;
- SSH key fingerprints, approved devices, timeout history, and ban history;
- active-session metadata: IP address, browser information, and last activity.
diff --git a/app/Actions/CreateExport.php b/app/Actions/CreateExport.php
index 26ff673e4..da3d08caf 100644
--- a/app/Actions/CreateExport.php
+++ b/app/Actions/CreateExport.php
@@ -140,8 +140,9 @@ public function handle(User $user): array
'dismissed_suggestions' => $this->handles($user->dismissedSuggestions()),
'organizations' => $this->organizations($user),
'followed_organizations' => $this->followedOrganizations($user),
- 'guilds' => Guild::query()->where('user_id', $user->id)->orderBy('handle')->get()->map(fn (Guild $guild): array => [
+ 'guilds' => Guild::query()->with('aliases')->where('user_id', $user->id)->orderBy('handle')->get()->map(fn (Guild $guild): array => [
...$guild->toArray(),
+ 'aliases' => $guild->aliases->pluck('handle')->all(),
'icon' => $guild->icon_path === null ? null : route('guild-icon.show', $guild->handle),
'pinned_commit_id' => $guild->pinned_commit_id,
'created_at' => $guild->created_at->toIso8601String(),
diff --git a/app/Actions/CreateGuild.php b/app/Actions/CreateGuild.php
index c5fe66fbd..f8c8e21ba 100644
--- a/app/Actions/CreateGuild.php
+++ b/app/Actions/CreateGuild.php
@@ -4,8 +4,10 @@
namespace App\Actions;
+use App\Exceptions\GuildHandleTaken;
use App\Exceptions\GuildModeratorRemoved;
use App\Models\Guild;
+use App\Models\GuildAlias;
use App\Models\GuildSubmission;
use App\Models\User;
use Illuminate\Http\UploadedFile;
@@ -19,7 +21,8 @@ public function __construct(private CreateImageFiles $images, private UpdateGuil
}
/**
- * The icon is an upload, or the path of one already stored, such as a reviewed submission's.
+ * The icon is an upload, or the path of one already stored, such as a reviewed submission's. A hashtag that became
+ * another guild's alias meanwhile is taken.
*/
public function handle(User $user, string $handle, string $name, string $description, string $emoji, UploadedFile|string|null $icon, bool $flagged = false): Guild|GuildSubmission
{
@@ -30,6 +33,12 @@ public function handle(User $user, string $handle, string $name, string $descrip
throw new GuildModeratorRemoved;
}
+ DB::select('select pg_advisory_xact_lock(hashtextextended(?, 0))', [CreateGuildAlias::HANDLE_LOCK.mb_strtolower($handle)]);
+
+ if (GuildAlias::query()->where('handle', mb_strtolower($handle))->exists()) {
+ throw new GuildHandleTaken;
+ }
+
if ($flagged) {
assert($icon instanceof UploadedFile || $icon === null);
diff --git a/app/Actions/CreateGuildAlias.php b/app/Actions/CreateGuildAlias.php
new file mode 100644
index 000000000..96cd0b84f
--- /dev/null
+++ b/app/Actions/CreateGuildAlias.php
@@ -0,0 +1,47 @@
+whereKey($guild->id)->lockForUpdate()->firstOrFail();
+
+ if ($guild->user_id !== $user->id || Guild::query()->where('handle', $handle)->exists() || GuildAlias::query()->where('handle', $handle)->exists()) {
+ return;
+ }
+
+ if ($guild->aliases()->count() >= GuildAlias::MAX_PER_GUILD) {
+ return;
+ }
+
+ $guild->aliases()->create(['handle' => $handle]);
+
+ event(new UsersUpdated(DB::table('guild_preferences')->where('guild_id', $guild->id)->pluck('user_id')->push($guild->user_id), UserUpdate::Guilds));
+ });
+ }
+}
diff --git a/app/Actions/CreateGuildSubmissionApproval.php b/app/Actions/CreateGuildSubmissionApproval.php
index f104739bb..25c287397 100644
--- a/app/Actions/CreateGuildSubmissionApproval.php
+++ b/app/Actions/CreateGuildSubmissionApproval.php
@@ -4,6 +4,7 @@
namespace App\Actions;
+use App\Exceptions\GuildHandleTaken;
use App\Exceptions\GuildModeratorRemoved;
use App\Models\Guild;
use App\Models\GuildSubmission;
@@ -20,7 +21,7 @@ public function __construct(private CreateGuild $createGuild, private UpdateGuil
/**
* Publishes the submission as if it had passed the moderation: an edit when its author still moderates the guild,
* otherwise a new guild, which claims a paused one and leaves one someone else moderates alone. An author removed
- * from the guild meanwhile gets nothing.
+ * from the guild meanwhile gets nothing, and neither does a hashtag that became another guild's alias.
*/
public function handle(?GuildSubmission $submission): void
{
@@ -43,7 +44,7 @@ public function handle(?GuildSubmission $submission): void
} else {
$this->createGuild->handle($submission->user, $submission->handle, $submission->name, $submission->description, $submission->emoji, $submission->icon_path);
}
- } catch (GuildModeratorRemoved) {
+ } catch (GuildHandleTaken|GuildModeratorRemoved) {
//
}
diff --git a/app/Actions/DeleteGuildAlias.php b/app/Actions/DeleteGuildAlias.php
new file mode 100644
index 000000000..60b6101d0
--- /dev/null
+++ b/app/Actions/DeleteGuildAlias.php
@@ -0,0 +1,21 @@
+delete();
+
+ event(new UsersUpdated(DB::table('guild_preferences')->where('guild_id', $guild->id)->pluck('user_id')->push($guild->user_id), UserUpdate::Guilds));
+ }
+}
diff --git a/app/Exceptions/GuildHandleTaken.php b/app/Exceptions/GuildHandleTaken.php
new file mode 100644
index 000000000..7f9853d68
--- /dev/null
+++ b/app/Exceptions/GuildHandleTaken.php
@@ -0,0 +1,9 @@
+handle($guild, $user, $request->string('handle')->value());
+
+ return to_route('guild.show', $guild->handle);
+ }
+
+ public function destroy(DeleteGuildAliasRequest $request, Guild $guild, GuildAlias $alias, DeleteGuildAlias $action): RedirectResponse
+ {
+ $action->handle($guild, $alias);
+
+ return to_route('guild.show', $guild->handle);
+ }
+}
diff --git a/app/Http/Controllers/GuildController.php b/app/Http/Controllers/GuildController.php
index de80fc205..13a4e9d83 100644
--- a/app/Http/Controllers/GuildController.php
+++ b/app/Http/Controllers/GuildController.php
@@ -6,6 +6,7 @@
use App\Actions\CreateGuild;
use App\Actions\UpdateGuild;
+use App\Exceptions\GuildHandleTaken;
use App\Exceptions\GuildModeratorRemoved;
use App\Http\Requests\CreateGuildRequest;
use App\Http\Requests\ListGuildsRequest;
@@ -44,6 +45,8 @@ public function store(CreateGuildRequest $request, #[CurrentUser] User $user, Cr
$guild = $action->handle($user, $request->string('handle')->value(), $request->string('name')->value(), $request->string('description')->value(), $request->string('emoji')->value(), $icon, $request->isFlagged());
} catch (GuildModeratorRemoved) {
return back()->withErrors(['handle' => 'You cannot reclaim a guild you were removed from.']);
+ } catch (GuildHandleTaken) {
+ return back()->withErrors(['handle' => 'A guild already uses this hashtag. Choose a different display name.']);
}
if ($guild instanceof GuildSubmission) {
diff --git a/app/Http/Requests/CreateGuildAliasRequest.php b/app/Http/Requests/CreateGuildAliasRequest.php
new file mode 100644
index 000000000..e358e872c
--- /dev/null
+++ b/app/Http/Requests/CreateGuildAliasRequest.php
@@ -0,0 +1,76 @@
+route('guild');
+ assert($guild instanceof Guild);
+
+ return $features->available(Feature::Guilds, $this->user()) && $guild->user_id === $this->user()?->id
+ ? Response::allow() : Response::denyAsNotFound();
+ }
+
+ /** @return array> */
+ public function rules(): array
+ {
+ return [
+ 'handle' => ['required', 'string', 'max:60', 'regex:/^\p{L}[\p{L}\p{M}\p{N}_]*$/uD', Rule::unique('guilds', 'handle'), Rule::unique('guild_aliases', 'handle')],
+ ];
+ }
+
+ /** @return list */
+ public function after(FlaggedGuild $flagged): array
+ {
+ return [function (Validator $validator) use ($flagged): void {
+ if ($validator->errors()->isNotEmpty()) {
+ return;
+ }
+
+ $guild = $this->route('guild');
+ assert($guild instanceof Guild);
+
+ if ($guild->aliases()->count() >= GuildAlias::MAX_PER_GUILD) {
+ $validator->errors()->add('handle', 'A guild can have up to '.GuildAlias::MAX_PER_GUILD.' aliases.');
+
+ return;
+ }
+
+ if ($flagged->validate($validator, '#'.$this->string('handle')->value(), null)) {
+ $validator->errors()->add('handle', 'This hashtag cannot be used as an alias.');
+ }
+ }];
+ }
+
+ /** @return array */
+ public function messages(): array
+ {
+ return [
+ 'handle.unique' => 'A guild already uses this hashtag.',
+ 'handle.regex' => 'Use a hashtag that starts with a letter and contains only letters, numbers and underscores.',
+ ];
+ }
+
+ public function prepareForValidation(): void
+ {
+ if (is_string($this->input('handle'))) {
+ $this->merge(['handle' => $this->string('handle')->trim()->ltrim('#')->lower()->value()]);
+ }
+ }
+}
diff --git a/app/Http/Requests/CreateGuildRequest.php b/app/Http/Requests/CreateGuildRequest.php
index 30f8539b1..9169ebc79 100644
--- a/app/Http/Requests/CreateGuildRequest.php
+++ b/app/Http/Requests/CreateGuildRequest.php
@@ -35,7 +35,7 @@ public function authorize(Features $features): Response
public function rules(EmojiShortcodes $emoji): array
{
return [
- 'handle' => ['required', 'string', 'max:60', 'regex:/^\p{L}[\p{L}\p{M}\p{N}_]*$/uD', Rule::unique('guilds', 'handle')->whereNotNull('user_id')],
+ 'handle' => ['required', 'string', 'max:60', 'regex:/^\p{L}[\p{L}\p{M}\p{N}_]*$/uD', Rule::unique('guilds', 'handle')->whereNotNull('user_id'), Rule::unique('guild_aliases', 'handle')],
'name' => ['required', 'string', 'max:60'],
'description' => ['required', 'string', 'max:500'],
'emoji' => ['required', 'string', Rule::in($emoji->emoji())],
diff --git a/app/Http/Requests/DeleteGuildAliasRequest.php b/app/Http/Requests/DeleteGuildAliasRequest.php
new file mode 100644
index 000000000..261199874
--- /dev/null
+++ b/app/Http/Requests/DeleteGuildAliasRequest.php
@@ -0,0 +1,29 @@
+route('guild');
+ assert($guild instanceof Guild);
+
+ return $features->available(Feature::Guilds, $this->user()) && $guild->user_id === $this->user()?->id
+ ? Response::allow() : Response::denyAsNotFound();
+ }
+
+ /** @return array{} */
+ public function rules(): array
+ {
+ return [];
+ }
+}
diff --git a/app/Http/Resources/GuildResource.php b/app/Http/Resources/GuildResource.php
index d5d37f240..9e239de17 100644
--- a/app/Http/Resources/GuildResource.php
+++ b/app/Http/Resources/GuildResource.php
@@ -10,7 +10,7 @@
/**
* A guild as the web's Guilds page shows it, with whether the user joined or muted it. A guild without a moderator is
- * paused.
+ * paused. Its aliases are the other hashtags that lead to it.
*
* On API routes, icon_url is signed for the user, as the app has no web session, and stays the same all day so the app
* can cache it.
@@ -26,6 +26,7 @@ public function toArray(Request $request): array
{
return [
'handle' => $this->handle,
+ 'aliases' => $this->aliases->pluck('handle')->all(),
'name' => $this->name,
'description' => $this->description,
'emoji' => $this->emoji,
diff --git a/app/Models/Guild.php b/app/Models/Guild.php
index fe4d6ab8e..4b3ff1051 100644
--- a/app/Models/Guild.php
+++ b/app/Models/Guild.php
@@ -6,13 +6,17 @@
use Carbon\CarbonInterface;
use Database\Factories\GuildFactory;
+use Illuminate\Contracts\Database\Eloquent\Builder as BuilderContract;
use Illuminate\Database\Eloquent\Attributes\Visible;
+use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\URL;
+use Override;
/**
* @property-read string $id
@@ -43,6 +47,38 @@ public function commits(): HasMany
return $this->hasMany(Commit::class);
}
+ /** @return HasMany */
+ public function aliases(): HasMany
+ {
+ return $this->hasMany(GuildAlias::class)->orderBy('handle');
+ }
+
+ /**
+ * The hashtags that bring a commit to the guild: its handle, then its aliases.
+ *
+ * @return list
+ */
+ public function hashtags(): array
+ {
+ return [$this->handle, ...$this->aliases->map(fn (GuildAlias $alias): string => $alias->handle)->all()];
+ }
+
+ /**
+ * Resolves "guilds/{handle}" URLs by the guild's handle or by one of its aliases.
+ *
+ * @param Model|BuilderContract|Relation $query
+ * @param mixed $value
+ * @param string|null $field
+ */
+ #[Override]
+ public function resolveRouteBindingQuery($query, $value, $field = null): BuilderContract
+ {
+ return $field === 'handle'
+ ? parent::resolveRouteBindingQuery($query, self::query()->select('id')->where('handle', $value)
+ ->orWhereHas('aliases', fn (Builder $aliases): Builder => $aliases->where('guild_aliases.handle', $value))->limit(1), 'id')
+ : parent::resolveRouteBindingQuery($query, $value, $field);
+ }
+
/** @return BelongsToMany */
public function members(): BelongsToMany
{
diff --git a/app/Models/GuildAlias.php b/app/Models/GuildAlias.php
new file mode 100644
index 000000000..a7a8a6af8
--- /dev/null
+++ b/app/Models/GuildAlias.php
@@ -0,0 +1,43 @@
+ */
+ use HasFactory;
+
+ use HasUuids;
+
+ /**
+ * How many aliases one guild can have.
+ */
+ public const int MAX_PER_GUILD = 10;
+
+ public $timestamps = false;
+
+ /** @return BelongsTo */
+ public function guild(): BelongsTo
+ {
+ return $this->belongsTo(Guild::class);
+ }
+}
diff --git a/app/Queries/GuildCommitsQuery.php b/app/Queries/GuildCommitsQuery.php
index 09249f63e..6eec79ae8 100644
--- a/app/Queries/GuildCommitsQuery.php
+++ b/app/Queries/GuildCommitsQuery.php
@@ -15,6 +15,7 @@
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Pagination\Paginator;
+use Illuminate\Support\Collection as SupportCollection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Fluent;
use Illuminate\Support\LazyCollection;
@@ -66,13 +67,11 @@ public function pinned(Guild $guild, User $viewer): ?Commit
public function forPreference(User $user, bool $muted): Builder
{
- /** @var list $handles */
- $handles = resolve(Features::class)->available(Feature::Guilds, $user)
- ? DB::table('guild_preferences')->join('guilds', 'guilds.id', '=', 'guild_preferences.guild_id')
- ->where('guild_preferences.user_id', $user->id)->whereNotNull($muted ? 'muted_at' : 'joined_at')->pluck('handle')->all()
+ $hashtags = resolve(Features::class)->available(Feature::Guilds, $user)
+ ? $this->hashtagsOf($this->preferencesOf($user)->whereNotNull($muted ? 'muted_at' : 'joined_at')->get())
: [];
- return DB::query()->selectRaw('jsonb_array_elements_text(?)::uuid', [$this->ids($user, $handles)->values()->toJson()]);
+ return DB::query()->selectRaw('jsonb_array_elements_text(?)::uuid', [$this->ids($user, array_keys($hashtags))->values()->toJson()]);
}
/**
@@ -85,13 +84,12 @@ public function rejectMuted(Collection $commits, ?User $user): Collection
return $commits;
}
- /** @var array $muted */
- $muted = DB::table('guild_preferences')->join('guilds', 'guilds.id', '=', 'guild_preferences.guild_id')
- ->where('guild_preferences.user_id', $user->id)->whereNotNull('muted_at')->pluck('handle', 'guilds.id')->all();
+ $muted = $this->preferencesOf($user)->whereNotNull('muted_at')->get();
+ $hashtags = array_keys($this->hashtagsOf($muted));
- return $muted === [] ? $commits : $commits->reject(fn (Commit $commit): bool => $commit->guild_id !== null
- ? array_key_exists($commit->guild_id, $muted)
- : array_intersect($muted, $this->hashtags->handles($commit->body)) !== [])->values();
+ return $muted->isEmpty() ? $commits : $commits->reject(fn (Commit $commit): bool => $commit->guild_id !== null
+ ? $muted->contains('id', $commit->guild_id)
+ : array_intersect($hashtags, $this->hashtags->handles($commit->body)) !== [])->values();
}
/**
@@ -104,21 +102,22 @@ public function joinedFor(iterable $commits, User $user): array
return [];
}
- $handles = DB::table('guild_preferences')->join('guilds', 'guilds.id', '=', 'guild_preferences.guild_id')
- ->where('guild_preferences.user_id', $user->id)->whereNotNull('joined_at')->whereNull('muted_at')->orderBy('handle')->pluck('handle')->all();
+ $hashtags = $this->hashtagsOf($this->preferencesOf($user)->whereNotNull('joined_at')->whereNull('muted_at')->get());
$following = $user->following();
$organizations = $user->followedOrganizations();
$authors = $following->newPivotQuery()->pluck($following->getRelatedPivotKeyName())
->merge($organizations->newPivotQuery()->pluck($organizations->getRelatedPivotKeyName()))->push($user->id);
return collect($commits)->reject(fn (Commit $commit): bool => $commit->guild_id === null && $authors->contains($commit->author_id))
- ->mapWithKeys(fn (Commit $commit): array => [$commit->id => $commit->guild->handle ?? collect($this->hashtags->handles($commit->body))->first(fn (string $handle): bool => in_array($handle, $handles, true))])
+ ->mapWithKeys(fn (Commit $commit): array => [$commit->id => $commit->guild->handle ?? collect($this->hashtags->handles($commit->body))->map(fn (string $hashtag): ?string => $hashtags[$hashtag] ?? null)->filter()->first()])
->filter()->all();
}
/** @return LazyCollection */
public function rootIds(Guild $guild, User $viewer, ?string $forRoot = null): LazyCollection
{
+ $hashtags = $guild->hashtags();
+ $tags = array_map(fn (string $hashtag): string => '#'.str_replace('ς', 'σ', $hashtag), $hashtags);
$roots = Commit::query()->topLevel()->visibleTo($viewer)->withoutMutedAuthorsFor($viewer)
->when($forRoot !== null, fn (CommitBuilder $query): CommitBuilder => $query->whereKey($forRoot))
->select(['id', 'created_at']);
@@ -131,7 +130,7 @@ public function rootIds(Guild $guild, User $viewer, ?string $forRoot = null): La
->select(['roots.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)))
+ || ($commit->string('body')->lower()->replace('ς', 'σ')->contains($tags) && array_intersect($hashtags, $this->hashtags->handles($commit->string('body')->value())) !== []))
->map(fn (Fluent $commit): string => $commit->string('id')->value())
->unique()->values();
}
@@ -148,6 +147,33 @@ private function page(Guild $guild, User $viewer, int $page): Paginator
return new Paginator($commits, 30, $page, ['path' => Paginator::resolveCurrentPath()]);
}
+ /**
+ * The guilds the user has preferences for, with a row for each alias, so one read brings every hashtag of them.
+ */
+ private function preferencesOf(User $user): Builder
+ {
+ return DB::table('guild_preferences')->join('guilds', 'guilds.id', '=', 'guild_preferences.guild_id')
+ ->leftJoin('guild_aliases', 'guild_aliases.guild_id', '=', 'guilds.id')
+ ->where('guild_preferences.user_id', $user->id)
+ ->select(['guilds.id', 'guilds.handle', 'guild_aliases.handle as alias']);
+ }
+
+ /**
+ * The handle of the guild each hashtag leads to, by hashtag: the handles themselves, and the aliases.
+ *
+ * @param SupportCollection $guilds
+ * @return array
+ */
+ private function hashtagsOf(SupportCollection $guilds): array
+ {
+ /** @var array $handles */
+ $handles = $guilds->pluck('handle', 'handle')->all();
+ /** @var array $aliases */
+ $aliases = $guilds->whereNotNull('alias')->pluck('handle', 'alias')->all();
+
+ return [...$handles, ...$aliases];
+ }
+
/**
* @param list $handles
* @return LazyCollection
diff --git a/app/Queries/GuildsQuery.php b/app/Queries/GuildsQuery.php
index ab829625e..8f0c4bff3 100644
--- a/app/Queries/GuildsQuery.php
+++ b/app/Queries/GuildsQuery.php
@@ -39,7 +39,9 @@ public function paginate(string $term, int $page, User $user): LengthAwarePagina
->when($term !== '', fn (Builder $query): Builder => $query->where(fn (Builder $query): Builder => $query
->whereRaw('TRANSLATE(LOWER(handle COLLATE "pg_c_utf8"), \'ς\', \'σ\') LIKE TRANSLATE(LOWER(? COLLATE "pg_c_utf8"), \'ς\', \'σ\') ESCAPE \'!\'', ["%{$escaped}%"])
->orWhereRaw('TRANSLATE(LOWER(name COLLATE "pg_c_utf8"), \'ς\', \'σ\') LIKE TRANSLATE(LOWER(? COLLATE "pg_c_utf8"), \'ς\', \'σ\') ESCAPE \'!\'', ["%{$escaped}%"])
- ->orWhereRaw('TRANSLATE(LOWER(description COLLATE "pg_c_utf8"), \'ς\', \'σ\') LIKE TRANSLATE(LOWER(? COLLATE "pg_c_utf8"), \'ς\', \'σ\') ESCAPE \'!\'', ["%{$escaped}%"])))
+ ->orWhereRaw('TRANSLATE(LOWER(description COLLATE "pg_c_utf8"), \'ς\', \'σ\') LIKE TRANSLATE(LOWER(? COLLATE "pg_c_utf8"), \'ς\', \'σ\') ESCAPE \'!\'', ["%{$escaped}%"])
+ ->orWhereHas('aliases', fn (Builder $query): Builder => $query
+ ->whereRaw('TRANSLATE(LOWER(guild_aliases.handle COLLATE "pg_c_utf8"), \'ς\', \'σ\') LIKE TRANSLATE(LOWER(? COLLATE "pg_c_utf8"), \'ς\', \'σ\') ESCAPE \'!\'', ["%{$escaped}%"]))))
->orderByDesc('members_count')->orderBy('handle')
->paginate(24, page: $page);
}
@@ -51,7 +53,7 @@ public function paginate(string $term, int $page, User $user): LengthAwarePagina
*/
private function withPreferencesOf(User $user): Builder
{
- return Guild::query()->withCount('members')->withExists([
+ return Guild::query()->with('aliases')->withCount('members')->withExists([
'members as is_joined' => fn (Builder $query): Builder => $query->whereKey($user->id),
'muters as is_muted' => fn (Builder $query): Builder => $query->whereKey($user->id),
]);
diff --git a/app/Queries/JoinedGuildsQuery.php b/app/Queries/JoinedGuildsQuery.php
index fda59ae0d..bff61646d 100644
--- a/app/Queries/JoinedGuildsQuery.php
+++ b/app/Queries/JoinedGuildsQuery.php
@@ -46,7 +46,7 @@ public function get(User $user): array
$commits = $this->commitsSince($user, array_keys($readFrom), min($readFrom));
$ownCommits = $this->ownCommits($user, array_keys($readFrom));
- $guilds = Guild::query()->whereKey(array_keys($readFrom))->get();
+ $guilds = Guild::query()->with('aliases')->whereKey(array_keys($readFrom))->get();
$ownCommitCounts = $guilds->mapWithKeys(fn (Guild $guild): array => [
$guild->handle => $ownCommits->filter(fn (array $commit): bool => $this->isPostedIn($guild, $commit))->count(),
]);
@@ -133,6 +133,6 @@ private function ownCommits(User $user, array $guildIds): Collection
private function isPostedIn(Guild $guild, array $commit): bool
{
return $commit['guild_id'] === $guild->id
- || ($commit['guild_id'] === null && in_array($guild->handle, $commit['handles'], true));
+ || ($commit['guild_id'] === null && array_intersect($guild->hashtags(), $commit['handles']) !== []);
}
}
diff --git a/database/factories/GuildAliasFactory.php b/database/factories/GuildAliasFactory.php
new file mode 100644
index 000000000..b79ba3669
--- /dev/null
+++ b/database/factories/GuildAliasFactory.php
@@ -0,0 +1,26 @@
+
+ */
+final class GuildAliasFactory extends Factory
+{
+ /**
+ * @return array
+ */
+ public function definition(): array
+ {
+ return [
+ 'guild_id' => Guild::factory(),
+ 'handle' => fake()->unique()->lexify('alias????????'),
+ ];
+ }
+}
diff --git a/database/migrations/2026_11_21_101500_create_guild_aliases_table.php b/database/migrations/2026_11_21_101500_create_guild_aliases_table.php
new file mode 100644
index 000000000..a4dd8f1a4
--- /dev/null
+++ b/database/migrations/2026_11_21_101500_create_guild_aliases_table.php
@@ -0,0 +1,20 @@
+uuid('id')->primary();
+ $table->foreignUuid('guild_id')->constrained()->cascadeOnDelete();
+ $table->string('handle', 60)->unique();
+ $table->index('guild_id');
+ });
+ }
+};
diff --git a/resources/js/components/guild-aliases.tsx b/resources/js/components/guild-aliases.tsx
new file mode 100644
index 000000000..1fea0e459
--- /dev/null
+++ b/resources/js/components/guild-aliases.tsx
@@ -0,0 +1,134 @@
+import { Form, router } from '@inertiajs/react';
+import { Plus, X } from 'lucide-react';
+import {
+ destroy,
+ store,
+} from '@/actions/App/Http/Controllers/GuildAliasController';
+import InputError from '@/components/input-error';
+import { Button } from '@/components/ui/button';
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from '@/components/ui/dialog';
+import { Label } from '@/components/ui/label';
+import type { Guild } from '@/types/guild';
+
+export function GuildAliasesButton({ guild }: { guild: Guild }) {
+ function remove(alias: string) {
+ router
+ .optimistic<{ guilds: Guild[] | null }>((props) => ({
+ guilds: props.guilds?.map((item) =>
+ item.id === guild.id
+ ? {
+ ...item,
+ aliases: item.aliases.filter(
+ (other) => other !== alias,
+ ),
+ }
+ : item,
+ ),
+ }))
+ .delete(destroy.url({ guild: guild.handle, alias }), {
+ preserveScroll: true,
+ onSuccess: () => router.flushAll(),
+ });
+ }
+
+ return (
+
+ );
+}
diff --git a/resources/js/components/linkified-text.tsx b/resources/js/components/linkified-text.tsx
index 38fe900d7..24e86b4a5 100644
--- a/resources/js/components/linkified-text.tsx
+++ b/resources/js/components/linkified-text.tsx
@@ -16,6 +16,7 @@ import { UserPreview } from '@/components/user-preview';
import { typedProse, withoutCode } from '@/lib/code';
import type { Color } from '@/lib/colors';
import { colorsIn } from '@/lib/colors';
+import { guildFor } from '@/lib/guilds';
import { hashtagPattern } from '@/lib/hashtags';
import { mentionPattern } from '@/lib/mentions';
import { pasteisParts } from '@/lib/pasteis';
@@ -635,10 +636,7 @@ export function Hashtag({
}) {
const { auth, guilds } = usePage().props;
const guild =
- postedGuild ??
- guilds?.find(
- (guild) => guild.handle === hashtag.slice(1).toLowerCase(),
- );
+ postedGuild ?? guildFor(guilds, hashtag.slice(1).toLowerCase());
if (guild) {
const canOpenGuild = !!auth.user && !!guilds;
diff --git a/resources/js/components/mention-textarea.tsx b/resources/js/components/mention-textarea.tsx
index aa6a06bfe..d3a9b0932 100644
--- a/resources/js/components/mention-textarea.tsx
+++ b/resources/js/components/mention-textarea.tsx
@@ -516,6 +516,9 @@ export function MentionTextarea({
.filter(
(guild) =>
guild.handle.includes(guildQuery) ||
+ guild.aliases.some((alias) =>
+ alias.includes(guildQuery),
+ ) ||
guild.name.toLowerCase().includes(guildQuery),
)
.toSorted(
diff --git a/resources/js/lib/guilds.ts b/resources/js/lib/guilds.ts
new file mode 100644
index 000000000..180142b24
--- /dev/null
+++ b/resources/js/lib/guilds.ts
@@ -0,0 +1,13 @@
+import type { Guild } from '@/types/guild';
+
+/**
+ * The guild a hashtag leads to: the one with that handle, or with it as an alias.
+ */
+export function guildFor>(
+ guilds: T[] | null | undefined,
+ handle: string,
+): T | undefined {
+ return guilds?.find(
+ (guild) => guild.handle === handle || guild.aliases.includes(handle),
+ );
+}
diff --git a/resources/js/pages/guild/show.tsx b/resources/js/pages/guild/show.tsx
index cbadaf590..9339f6dfc 100644
--- a/resources/js/pages/guild/show.tsx
+++ b/resources/js/pages/guild/show.tsx
@@ -10,6 +10,7 @@ import { CommitComposer } from '@/components/commit-composer';
import { EmptyFeed } from '@/components/commit-feed';
import { GraphCanvas } from '@/components/graph-canvas';
import { RailSegment } from '@/components/graph-rail';
+import { GuildAliasesButton } from '@/components/guild-aliases';
import { GuildDialog } from '@/components/guild-dialog';
import { GuildIcon } from '@/components/guild-icon';
import {
@@ -175,6 +176,8 @@ export default function Show({
);
}
+ const aliases = guild.aliases.map((alias) => `#${alias}`).join(' ');
+
return (
<>
@@ -213,6 +216,15 @@ export default function Show({
#{handle}
+ {aliases && (
+
+ also {aliases}
+
+ )}
·
{guild.is_paused
@@ -227,6 +239,7 @@ export default function Show({