Skip to content
4 changes: 2 additions & 2 deletions KNOWLEDGE_BASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,11 @@ Sources: [group creation](app/Http/Requests/CreateOrgRequest.php), [invitation e

### Muting and blocking

**Mute** someone to remove their commits and replies from your logs, threads, search, and suggestions and stop their notifications. Muting is silent, leaves follows intact, and still lets you visit their profile, which shows a **Muted** badge. Commits you starred stay in Starred.
**Mute** someone to remove their commits and replies from your logs, threads, search, and suggestions and stop their notifications. Muting is silent, leaves follows intact, and still lets you visit their profile, which shows a **Muted** badge. Commits you starred stay in Starred. Hover cards show the same badge, and logging out or deleting your account forgets them, so whoever uses that tab next doesn't see who you muted or blocked.

**Block** someone to stop messaging and interactions such as following, replies, stars, pastéis, and Tom's replies between the two accounts, and hide each other's commits while signed in. Their profile and follower lists become unavailable to you. Blocking removes follows in both directions. Unblocking does not restore those follows. Manage and reverse either choice in Settings → Safety. Blocking is an account-level interaction control, not a way to make public posts inaccessible to signed-out visitors.

Sources: [safety settings](resources/js/pages/safety/edit.tsx), [mute action](app/Actions/CreateUserMute.php), [block action](app/Actions/CreateUserBlock.php), [public routes](routes/web.php).
Sources: [safety settings](resources/js/pages/safety/edit.tsx), [mute action](app/Actions/CreateUserMute.php), [block action](app/Actions/CreateUserBlock.php), [public routes](routes/web.php), [hover cards](resources/js/components/user-preview.tsx).

### Reporting commits

Expand Down
9 changes: 8 additions & 1 deletion resources/js/components/delete-user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { clearUserPreviews } from '@/components/user-preview';
import { WordmarkText } from '@/components/wordmark-text';
import { clearRecentSearches } from '@/hooks/use-recent-searches';

Expand Down Expand Up @@ -55,7 +56,13 @@ export default function DeleteUser() {

<Form
{...UserController.destroy.form()}
onSuccess={() => user && clearRecentSearches(user.id)}
onSuccess={() => {
clearUserPreviews();

if (user) {
clearRecentSearches(user.id);
}
}}
>
{({ processing }) => (
<DialogFooter className="gap-2">
Expand Down
3 changes: 3 additions & 0 deletions resources/js/components/user-menu-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
DropdownMenuSeparator,
} from '@/components/ui/dropdown-menu';
import { UserInfo } from '@/components/user-info';
import { clearUserPreviews } from '@/components/user-preview';
import { useMobileNavigation } from '@/hooks/use-mobile-navigation';
import { clearRecentSearches } from '@/hooks/use-recent-searches';
import { clearStashes } from '@/hooks/use-stash';
Expand All @@ -46,6 +47,7 @@ export function UserMenuContent({ user }: Props) {
cleanup();
clearStashes(user.id);
clearRecentSearches(user.id);
clearUserPreviews();
router.flushAll();
};

Expand Down Expand Up @@ -181,6 +183,7 @@ export function UserMenuContent({ user }: Props) {
className="block w-full cursor-pointer"
href={logout()}
as="button"
preserveState={false}
onClick={handleLogout}
data-test="logout-button"
>
Expand Down
23 changes: 17 additions & 6 deletions resources/js/components/user-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ const viewportMargin = 8;
// Where the centre of the preview's avatar sits: border, padding and half of the size-14 avatar.
const avatarCentre = 45;
const cache = new Map<string, PreviewData>();
let cacheGeneration = 0;

async function fetchPreview(url: string): Promise<PreviewData> {
const generation = cacheGeneration;
const response = await fetch(url, {
headers: {
Accept: 'application/json',
Expand All @@ -77,11 +79,21 @@ async function fetchPreview(url: string): Promise<PreviewData> {
}

const data = (await response.json()) as PreviewData;

if (generation !== cacheGeneration) {
throw new Error(`Dropped ${url} from before the previews were cleared`);
}

cache.set(url, data);

return data;
}

export function clearUserPreviews(): void {
cacheGeneration++;
cache.clear();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

export type Relationship = Pick<
PreviewData,
'isFollowing' | 'isMuting' | 'isBlocking'
Expand Down Expand Up @@ -393,11 +405,10 @@ function UserPreviewContent({
const stream = useLiveStream(user);

const { isJustToggled, markToggled, onMouseLeave } = useFollowHover();
const { isFollowing, callbacks } = useFollow(
user,
data?.isFollowing ?? false,
);
const [isMuting] = useIsMuting(user, data?.isMuting ?? false);
const follow = useFollow(user, data?.isFollowing ?? false);
const isFollowing = auth.user !== null && follow.isFollowing;
const [isMutingNow] = useIsMuting(user, data?.isMuting ?? false);
const isMuting = auth.user !== null && isMutingNow;
const followsDelta =
Number(isFollowing) - Number(data?.isFollowing ?? false);

Expand All @@ -421,7 +432,7 @@ function UserPreviewContent({
preserveState: true,
async: true,
...followVisitOptions(component, log, commits),
...callbacks,
...follow.callbacks,
onSuccess: () => router.flushAll(),
},
);
Expand Down
81 changes: 80 additions & 1 deletion tests/Unit/AuthorHover.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const { AuthorAvatar } =
await import('../../resources/js/components/author-avatar');
const { ActorAvatar } =
await import('../../resources/js/pages/notification/index');
const { UserPreview } =
const { UserPreview, clearUserPreviews } =
await import('../../resources/js/components/user-preview');
const { SuggestedUserRow } =
await import('../../resources/js/components/who-to-follow');
Expand Down Expand Up @@ -179,6 +179,85 @@ test('profile preview stays open when its menu is dismissed under the mouse', ()
assert.ok(!stateChanges.includes(false));
});

function previewContent(user: User) {
showPreview = true;
const preview = UserPreview({ user, children: user.handle });
showPreview = false;

return (
React.Children.toArray(preview.props.children)[1] as ReactElement<{
children: ReactElement<{
data: { followsYou: boolean; isMuting: boolean } | null;
}>;
}>
).props.children.props;
}

const mutedPreview = (user: User) => ({
isFollowing: false,
followsYou: true,
isMuting: true,
isBlocking: false,
isUnavailable: false,
user,
});

async function hoverUntilLoaded(user: User, beforeResponse = () => {}) {
let respond = (_response: Response) => {};
vi.useFakeTimers();
vi.stubGlobal('window', {
matchMedia: () => ({ matches: true }),
innerWidth: 1440,
innerHeight: 900,
});
vi.stubGlobal(
'fetch',
() => new Promise<Response>((resolve) => (respond = resolve)),
);
const trigger = React.Children.toArray(
UserPreview({ user, children: user.handle }).props.children,
)[0] as ReactElement<
HTMLAttributes<HTMLElement> & { ref: { current: unknown } }
>;
trigger.props.ref.current = {
getBoundingClientRect: () => ({ left: 0, top: 0, bottom: 20 }),
};

trigger.props.onPointerEnter?.({
pointerType: 'mouse',
} as PointerEvent<HTMLElement>);
vi.runAllTimers();
beforeResponse();
respond(Response.json(mutedPreview(user)));
vi.useRealTimers();
await new Promise((resolve) => setTimeout(resolve));
vi.stubGlobal('window', { matchMedia: () => ({ matches: false }) });
}

test('profile preview opens without the cached relationship once previews are cleared', async () => {
const user = { id: 'muted', handle: 'muted' } as User;

await hoverUntilLoaded(user);
assert.equal(previewContent(user).data?.isMuting, true);

clearUserPreviews();

assert.equal(previewContent(user).data, null);
});

test('profile preview drops a response that arrives after previews are cleared', async () => {
const user = { id: 'raced', handle: 'raced' } as User;

await hoverUntilLoaded(user, clearUserPreviews);

assert.equal(previewContent(user).data, null);
assert.ok(
!stateChanges.some(
(change) => (change as { isMuting?: boolean } | null)?.isMuting,
),
);
});

test('suggested user row wraps the author in a user preview anchored to their avatar', () => {
const user = {
id: 'author',
Expand Down
30 changes: 29 additions & 1 deletion tests/Unit/FollowState.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let component = 'user/show';
let log: string | undefined;
let loadedCommits: { data: { id: string }[] } | undefined;
let suggestedUsers: SuggestedUser[] | undefined;
let viewer: { id: string } | null = { id: 'viewer' };
type VisitOptions = {
only?: string[];
headers?: Record<string, string>;
Expand Down Expand Up @@ -59,7 +60,7 @@ vi.doMock('@inertiajs/react', async () => ({
usePage: () => ({
component,
props: {
auth: { user: { id: 'viewer' } },
auth: { user: viewer },
log,
commits: loadedCommits,
showsWhoToFollow: true,
Expand Down Expand Up @@ -127,6 +128,7 @@ afterEach(() => {
log = undefined;
loadedCommits = undefined;
suggestedUsers = undefined;
viewer = { id: 'viewer' };
refreshSharedState(
new Map<string, boolean | number | string>([
['who-to-follow-dismissing', 0],
Expand Down Expand Up @@ -778,6 +780,32 @@ test('a cached preview counts a follow made elsewhere, and stops counting it onc
assert.equal(previewFollowersCount(user, false), '0');
});

test('after logging out a preview offers to follow someone the last account followed, without counting that follow', () => {
const user = suggestion('previous');
followFromProfile(user);
viewer = null;

assert.equal(
previewFollowButton(user, false).props['aria-label'],
'Follow @previous',
);
assert.equal(previewFollowersCount(user, false), '0');
});

test('after logging out a preview stops showing that the last account muted them', () => {
const user = suggestion('hushed');
const showsMuted = () =>
find(previewContent(user), (props) => props.children === 'Muted') !==
null;
refreshSharedState(new Map([[`is_muting:${user.id}`, true]]));

assert.ok(showsMuted());

viewer = null;

assert.ok(!showsMuted());
});

test('a preview unfollow that fails after a block keeps who to follow unfollowed', () => {
const user = suggestion('raced');
followFromProfile(user);
Expand Down
36 changes: 36 additions & 0 deletions tests/Unit/UserMenuLogout.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// <reference types="node" />
import assert from 'node:assert/strict';
import * as React from 'react';
import type { ReactElement } from 'react';
import { test, vi } from 'vite-plus/test';
import type { User } from '../../resources/js/types';

vi.doMock('react', () => ({
...React,
useCallback: (callback: unknown) => callback,
}));
vi.doMock('@inertiajs/react', async () => ({
...(await vi.importActual('@inertiajs/react')),
usePage: () => ({ props: { auth: { isAdmin: false }, repository: '' } }),
}));

const { UserMenuContent } =
await import('../../resources/js/components/user-menu-content');

test('logging out remounts the page instead of keeping what the signed in account had open', () => {
const items = React.Children.toArray(
UserMenuContent({ user: { id: 'author', handle: 'author' } as User })
.props.children,
);
const logout = (
items.at(-1) as ReactElement<{
children: ReactElement<{
preserveState?: boolean;
'data-test': string;
}>;
}>
).props.children;

assert.equal(logout.props['data-test'], 'logout-button');
assert.equal(logout.props.preserveState, false);
});