CI / Build & Quality Checks (push) Successful in 1m30s
CI / Docker image build & smoke test (push) Skipped
CI / Secret scan (gitleaks) (push) Successful in 6s
CI / Trigger Desktop Build (push) Canceled after 0s
CI / Playwright smoke (e2e) (push) Canceled after 0s
Audit of every rendered time found five families of ad-hoc formatting: the shared Time component + copies of its today/yesterday branch (forwarded header, thread summary, read receipts, device tile, moderation alerts, edit history), locale-default toLocale*String calls that ignored the user's 12/24 h and date-format settings (scheduled tray, reminders, schedule preview, notification snooze, bookmarks, threads list, search cache line, room insights, media gallery), a hard-coded en-US date in the activity log, and three relative-age variants. utils/formatTimestamp.ts now holds the rules — today → time; yesterday / tomorrow → day word + time; last 6 days → weekday + time; older → date + time in dateFormatString — plus autoDate / time / date / dateTime styles, formatDayDivider (full weekday), formatShortAge (room list) and formatRelativeAge (list rows). useTimestampFormatter binds them to the settings. 11 unit tests with an injected 'now'. Visible changes are limited to consistency: 12 h times keep the existing zero-padded hh:mm A; the a11y label and Created-by line use the user's date format instead of a fixed long month. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
211 lines
7.4 KiB
TypeScript
211 lines
7.4 KiB
TypeScript
import React, { useCallback, useEffect, useState } from 'react';
|
|
import FocusTrap from 'focus-trap-react';
|
|
import {
|
|
Avatar,
|
|
Box,
|
|
Button,
|
|
Overlay,
|
|
OverlayBackdrop,
|
|
OverlayCenter,
|
|
Spinner,
|
|
Text,
|
|
as,
|
|
color,
|
|
} from 'folds';
|
|
import { JoinRule, Room } from 'matrix-js-sdk';
|
|
import { useAtomValue } from 'jotai';
|
|
import { IRoomCreateContent, Membership, StateEvent } from '../../../types/matrix/room';
|
|
import { getMemberDisplayName, getStateEvent } from '../../utils/room';
|
|
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
|
import { getMxIdLocalPart, mxcUrlToHttp } from '../../utils/matrix';
|
|
import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback';
|
|
import { useTimestampFormatter } from '../../hooks/useTimestampFormatter';
|
|
import { useRoomNavigate } from '../../hooks/useRoomNavigate';
|
|
import { RoomAvatar } from '../room-avatar';
|
|
import { nameInitials } from '../../utils/common';
|
|
import { useRoomAvatar, useLocalRoomName, useRoomTopic } from '../../hooks/useRoomMeta';
|
|
import { mDirectAtom } from '../../state/mDirectList';
|
|
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
|
|
import { InviteUserPrompt } from '../invite-user-prompt';
|
|
import { RoomTopicViewer } from '../room-topic-viewer';
|
|
import { stopPropagation } from '../../utils/keyboard';
|
|
|
|
export type RoomIntroProps = {
|
|
room: Room;
|
|
};
|
|
|
|
export const RoomIntro = as<'div', RoomIntroProps>(({ room, ...props }, ref) => {
|
|
const mx = useMatrixClient();
|
|
const useAuthentication = useMediaAuthentication();
|
|
const { navigateRoom } = useRoomNavigate();
|
|
const mDirects = useAtomValue(mDirectAtom);
|
|
const [invitePrompt, setInvitePrompt] = useState(false);
|
|
const [viewTopic, setViewTopic] = useState(false);
|
|
const [knocked, setKnocked] = useState(false);
|
|
const [knockError, setKnockError] = useState<string | undefined>();
|
|
|
|
useEffect(() => {
|
|
setKnocked(false);
|
|
setKnockError(undefined);
|
|
}, [room.roomId]);
|
|
|
|
const createEvent = getStateEvent(room, StateEvent.RoomCreate);
|
|
const avatarMxc = useRoomAvatar(room, mDirects.has(room.roomId));
|
|
const name = useLocalRoomName(room);
|
|
const topic = useRoomTopic(room);
|
|
const avatarHttpUrl = avatarMxc ? mxcUrlToHttp(mx, avatarMxc, useAuthentication) : undefined;
|
|
|
|
const createContent = createEvent?.getContent<IRoomCreateContent>();
|
|
const ts = createEvent?.getTs();
|
|
const creatorId = createEvent?.getSender();
|
|
const creatorName =
|
|
creatorId && (getMemberDisplayName(room, creatorId) ?? getMxIdLocalPart(creatorId));
|
|
const prevRoomId = createContent?.predecessor?.room_id;
|
|
|
|
const [prevRoomState, joinPrevRoom] = useAsyncCallback(
|
|
useCallback(async (roomId: string) => mx.joinRoom(roomId), [mx]),
|
|
);
|
|
|
|
const { format } = useTimestampFormatter();
|
|
|
|
return (
|
|
<Box direction="Column" grow="Yes" gap="500" {...props} ref={ref}>
|
|
<Box>
|
|
<Avatar size="500">
|
|
<RoomAvatar
|
|
roomId={room.roomId}
|
|
src={avatarHttpUrl ?? undefined}
|
|
alt={name}
|
|
renderFallback={() => <Text size="H2">{nameInitials(name)}</Text>}
|
|
/>
|
|
</Avatar>
|
|
</Box>
|
|
<Box direction="Column" gap="300">
|
|
<Box direction="Column" gap="100">
|
|
<Text size="H3" priority="500">
|
|
{name}
|
|
</Text>
|
|
{topic ? (
|
|
<>
|
|
{viewTopic && (
|
|
<Overlay open backdrop={<OverlayBackdrop />}>
|
|
<OverlayCenter>
|
|
<FocusTrap
|
|
focusTrapOptions={{
|
|
initialFocus: false,
|
|
clickOutsideDeactivates: true,
|
|
onDeactivate: () => setViewTopic(false),
|
|
escapeDeactivates: stopPropagation,
|
|
}}
|
|
>
|
|
<RoomTopicViewer
|
|
name={name}
|
|
topic={topic}
|
|
requestClose={() => setViewTopic(false)}
|
|
/>
|
|
</FocusTrap>
|
|
</OverlayCenter>
|
|
</Overlay>
|
|
)}
|
|
<Text
|
|
as="button"
|
|
type="button"
|
|
onClick={() => setViewTopic(true)}
|
|
size="T400"
|
|
priority="400"
|
|
style={{
|
|
background: 'none',
|
|
border: 'none',
|
|
padding: 0,
|
|
cursor: 'pointer',
|
|
textAlign: 'left',
|
|
}}
|
|
>
|
|
{topic.topic}
|
|
</Text>
|
|
</>
|
|
) : (
|
|
<Text size="T400" priority="400">
|
|
This is the beginning of conversation.
|
|
</Text>
|
|
)}
|
|
{creatorName && ts && (
|
|
<Text size="T200" priority="300">
|
|
{'Created by '}
|
|
<b>@{creatorName}</b>
|
|
{` on ${format(ts, 'dateTime')}`}
|
|
</Text>
|
|
)}
|
|
</Box>
|
|
<Box gap="200" wrap="Wrap">
|
|
<Button onClick={() => setInvitePrompt(true)} variant="Secondary" size="300" radii="300">
|
|
<Text size="B300">Invite Member</Text>
|
|
</Button>
|
|
|
|
{invitePrompt && (
|
|
<InviteUserPrompt room={room} requestClose={() => setInvitePrompt(false)} />
|
|
)}
|
|
{typeof prevRoomId === 'string' &&
|
|
(mx.getRoom(prevRoomId)?.getMyMembership() === Membership.Join ? (
|
|
<Button
|
|
onClick={() => navigateRoom(prevRoomId, createContent?.predecessor?.event_id)}
|
|
variant="Success"
|
|
size="300"
|
|
fill="Soft"
|
|
radii="300"
|
|
>
|
|
<Text size="B300">Open Old Room</Text>
|
|
</Button>
|
|
) : (
|
|
<Button
|
|
onClick={() => joinPrevRoom(prevRoomId)}
|
|
variant="Secondary"
|
|
size="300"
|
|
fill="Soft"
|
|
radii="300"
|
|
disabled={prevRoomState.status === AsyncStatus.Loading}
|
|
after={
|
|
prevRoomState.status === AsyncStatus.Loading ? (
|
|
<Spinner size="50" variant="Secondary" fill="Soft" />
|
|
) : undefined
|
|
}
|
|
>
|
|
<Text size="B300">Join Old Room</Text>
|
|
</Button>
|
|
))}
|
|
{room.getJoinRule() === JoinRule.Knock &&
|
|
room.getMyMembership() !== Membership.Join &&
|
|
(knocked ? (
|
|
<Text size="T300" priority="300">
|
|
Request sent — waiting for room admin approval
|
|
</Text>
|
|
) : (
|
|
<>
|
|
<Button
|
|
onClick={() => {
|
|
setKnockError(undefined);
|
|
mx.knockRoom(room.roomId)
|
|
.then(() => setKnocked(true))
|
|
.catch((err: Error) =>
|
|
setKnockError(err.message ?? 'Failed to send request'),
|
|
);
|
|
}}
|
|
variant="Primary"
|
|
size="300"
|
|
radii="300"
|
|
>
|
|
<Text size="B300">Request to Join</Text>
|
|
</Button>
|
|
{knockError && (
|
|
<Text size="T300" style={{ color: color.Critical.Main }}>
|
|
{knockError}
|
|
</Text>
|
|
)}
|
|
</>
|
|
))}
|
|
</Box>
|
|
</Box>
|
|
</Box>
|
|
);
|
|
});
|