Merge remote-tracking branch 'origin/void/commons-files-row' into void/rc-a5
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 3m31s
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 3m31s
This commit is contained in:
commit
b36173005b
6 changed files with 133 additions and 11 deletions
|
|
@ -118,9 +118,9 @@ Under A the paused service is not built, and most of its list disappears:
|
|||
|
||||
## Cuts under A
|
||||
|
||||
Status 2026-11-14 (dev da822e9e plus the size-refusal cut): built: folders by album title path with navigation and breadcrumb (#147), pagination (#148), version folding (#149), add-to-album with named refusals (#150), Stop for a send in flight, replaces loops shown, freshest last event on add (#151), and the pre-send size refusal: a file larger than the server's `m.upload.size` is named and left unsent before any upload or album root, and a server stating no cap refuses nothing. **Not built: the Commons entry row** (item 1 below, found by `#commons:gamecult.org` or the carried `media.commons` id through `lookupMediaRoom`, behind a dark `filesDesk.enabled` flag; neither the row nor the flag exists in the code). It waits on Eureka's Commons room.
|
||||
Status 2026-11-14 (dev da822e9e plus the size-refusal cut): built: folders by album title path with navigation and breadcrumb (#147), pagination (#148), version folding (#149), add-to-album with named refusals (#150), Stop for a send in flight, replaces loops shown, freshest last event on add (#151), and the pre-send size refusal: a file larger than the server's `m.upload.size` is named and left unsent before any upload or album root, and a server stating no cap refuses nothing. The Commons entry row is built (item 1): `useCommons` in `MediaRow.tsx` finds the room by the alias `#commons:<server>` (provisioning records no id for it), through `lookupZoneRoom` (the one lookup `lookupMediaRoom` also uses); `EstateNavigator` shows it above the tiers as a Commons link when joined, a join row when invited or not joined, and nothing when the room is absent, the lookup failed or is out. It is gated on the existing `fileZoneShare.enabled`, not a new `filesDesk.enabled` flag. The album view and ShareSet work there because provisioning creates the Commons with the `org.gamecult.file_zone` create type. Members can share only once the room's power levels let them post: provisioning gives the poster level to the Minds alone.
|
||||
|
||||
1. **Commons entry**: a Commons row in the navigator (like `MediaRow`, found by alias or carried id), opening the room's album view. Flagged, no new data layer.
|
||||
1. **Commons entry**: a Commons row in the navigator (like `MediaRow`, found by alias), opening the room's album view. Flagged, no new data layer.
|
||||
2. **Pagination** of albums and files in `useAlbums` (done, PR #148).
|
||||
3. **Folders by title path** and the album list grouped by it.
|
||||
4. **Versions**: read `org.gamecult.publish.replaces`, show the latest of a chain with the earlier versions folded under it (done, PR #149).
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import { searchModalAtom } from '../../state/searchModal';
|
|||
import { getCanonicalAliasOrRoomId } from '../../utils/matrix';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
import { MINDS } from '../../components/message/pose/poses';
|
||||
import { MediaLink, MediaNote, useMindMedia } from './MediaRow';
|
||||
import { MediaLink, MediaNote, useCommons, useMindMedia } from './MediaRow';
|
||||
import { MediaRow as MediaRowState } from './mediaRoom';
|
||||
import { useSelectedRoom } from '../../hooks/router/useSelectedRoom';
|
||||
import { useCallEmbed } from '../../hooks/useCallEmbed';
|
||||
|
|
@ -194,6 +194,15 @@ function MindMedia({ media }: { media: MediaRowState }) {
|
|||
return <JoinRow room={media.room} icon={Icons.Photo} />;
|
||||
}
|
||||
|
||||
/** The shared Commons room above the tiers: a link when joined, a join row otherwise, nothing when there is none. */
|
||||
function CommonsEntry() {
|
||||
const mx = useMatrixClient();
|
||||
const room = useCommons();
|
||||
if (!room) return null;
|
||||
if (room.state === 'joined') return <MediaLink to={estateRoomPath(mx, room)} label="Commons" />;
|
||||
return <JoinRow room={room} icon={Icons.Photo} />;
|
||||
}
|
||||
|
||||
function GroupSection({ tierId, group }: { tierId: string; group: EstateGroup }) {
|
||||
const media = useMindMedia(group.mind, group.rooms);
|
||||
const hasMedia = MINDS.includes(group.mind);
|
||||
|
|
@ -345,6 +354,7 @@ function EstateTiers({ rootId }: { rootId: string }) {
|
|||
|
||||
return (
|
||||
<>
|
||||
<CommonsEntry />
|
||||
{tiers.map((tier) => (
|
||||
<Tier key={tier.id} tier={tier} />
|
||||
))}
|
||||
|
|
|
|||
|
|
@ -26,4 +26,14 @@ describe('Media row', () => {
|
|||
expect(text(html)).toBe('Media');
|
||||
expect(html).toContain('href="/home/%23void-files%3Agamecult.org/"');
|
||||
});
|
||||
|
||||
it('the Commons link reads "Commons" and opens the room', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<MemoryRouter>
|
||||
<MediaLink to="/home/%23commons%3Agamecult.org/" label="Commons" />
|
||||
</MemoryRouter>
|
||||
);
|
||||
expect(text(html)).toBe('Commons');
|
||||
expect(html).toContain('href="/home/%23commons%3Agamecult.org/"');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -15,7 +15,10 @@ import { useEstateRootId } from './useEstate';
|
|||
import {
|
||||
STEWARDSHIPS_KEY,
|
||||
MediaRow as MediaRowState,
|
||||
commonsAlias,
|
||||
commonsRow,
|
||||
lookupMediaRoom,
|
||||
lookupZoneRoom,
|
||||
mediaRoomIdFromStewardships,
|
||||
mediaRow,
|
||||
typedMediaRoom,
|
||||
|
|
@ -44,7 +47,7 @@ export function MediaNote({ note, title }: { note: string; title?: string }) {
|
|||
}
|
||||
|
||||
/** The joined Media row: opens the room, which shows its album view. */
|
||||
export function MediaLink({ to }: { to: string }) {
|
||||
export function MediaLink({ to, label = 'Media' }: { to: string; label?: string }) {
|
||||
return (
|
||||
<NavItem variant="Background" radii="400">
|
||||
<NavLink to={to}>
|
||||
|
|
@ -52,7 +55,7 @@ export function MediaLink({ to }: { to: string }) {
|
|||
<Box as="span" grow="Yes" alignItems="Center" gap="200">
|
||||
<NavGutter>{mediaIcon}</NavGutter>
|
||||
<Text className={NavLabel} as="span" size="Inherit" truncate>
|
||||
Media
|
||||
{label}
|
||||
</Text>
|
||||
</Box>
|
||||
</NavItemContent>
|
||||
|
|
@ -105,3 +108,23 @@ export const useMindMedia = (mind: string, rooms: readonly EstateRoom[]): MediaR
|
|||
if (typed) return { kind: 'room', room: { ...typed, name: 'Media' } };
|
||||
return mediaRow(lookup.data, membership);
|
||||
};
|
||||
|
||||
/** The shared Commons room as the navigator sees it right now: undefined means no row. Dark unless fileZoneShare.enabled. */
|
||||
export const useCommons = (): EstateRoom | undefined => {
|
||||
const mx = useMatrixClient();
|
||||
const joined = useAtomValue(allRoomsAtom);
|
||||
const invited = useAtomValue(allInvitesAtom);
|
||||
const enabled = !!useClientConfig().fileZoneShare?.enabled;
|
||||
const server = mx.getDomain() ?? '';
|
||||
// Provisioning records no id for the Commons (only per-Mind zones under @rooms.file_zones): the alias is the one way in.
|
||||
const lookup = useQuery({
|
||||
queryKey: ['commons-room', server],
|
||||
queryFn: () => lookupZoneRoom(mx, commonsAlias(server), server),
|
||||
staleTime: 60_000,
|
||||
enabled,
|
||||
});
|
||||
const membership = new Map<string, 'join' | 'invite'>();
|
||||
invited.forEach((id) => membership.set(id, 'invite'));
|
||||
joined.forEach((id) => membership.set(id, 'join'));
|
||||
return commonsRow(enabled, lookup.data, membership);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
commonsAlias,
|
||||
commonsRow,
|
||||
lookupMediaRoom,
|
||||
lookupZoneRoom,
|
||||
mediaAlias,
|
||||
mediaRoomIdFromStewardships,
|
||||
mediaRow,
|
||||
MediaLookup,
|
||||
typedMediaRoom,
|
||||
} from './mediaRoom';
|
||||
|
||||
|
|
@ -132,3 +136,51 @@ describe('the Media row of a Mind', () => {
|
|||
expect(typedMediaRoom(rooms, () => false)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('the Commons row', () => {
|
||||
const none = new Map<string, 'join' | 'invite'>();
|
||||
|
||||
it('is found by the alias #commons:<server>', async () => {
|
||||
const { mx, asked } = clientFor(async () => ({ room_id: '!c:gamecult.org' }));
|
||||
const lookup = await lookupZoneRoom(mx, commonsAlias('gamecult.org'), 'gamecult.org');
|
||||
expect(asked).toEqual(['#commons:gamecult.org']);
|
||||
expect(commonsRow(true, lookup, new Map([['!c:gamecult.org', 'join']]))).toMatchObject({
|
||||
roomId: '!c:gamecult.org',
|
||||
name: 'Commons',
|
||||
state: 'joined',
|
||||
});
|
||||
});
|
||||
|
||||
it('shows no row when the room is absent, the lookup failed or is still out', async () => {
|
||||
const missing = await lookupZoneRoom(
|
||||
clientFor(async () => {
|
||||
throw notFound;
|
||||
}).mx,
|
||||
commonsAlias('gamecult.org'),
|
||||
'gamecult.org'
|
||||
);
|
||||
const failed = await lookupZoneRoom(
|
||||
clientFor(async () => {
|
||||
throw new Error('down');
|
||||
}).mx,
|
||||
commonsAlias('gamecult.org'),
|
||||
'gamecult.org'
|
||||
);
|
||||
expect(commonsRow(true, missing, none)).toBeUndefined();
|
||||
expect(commonsRow(true, failed, none)).toBeUndefined();
|
||||
expect(commonsRow(true, undefined, none)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('shows no row with the flag off, even for a found room', () => {
|
||||
const found: MediaLookup = { found: true, roomId: '!c:gamecult.org', via: ['gamecult.org'] };
|
||||
expect(commonsRow(false, found, new Map([['!c:gamecult.org', 'join']]))).toBeUndefined();
|
||||
});
|
||||
|
||||
it('offers a join to a viewer who has not joined, and an accept to an invited one', () => {
|
||||
const found: MediaLookup = { found: true, roomId: '!c:gamecult.org', via: ['gamecult.org'] };
|
||||
expect(commonsRow(true, found, none)?.state).toBe('joinable');
|
||||
expect(commonsRow(true, found, new Map([['!c:gamecult.org', 'invite']]))?.state).toBe(
|
||||
'invited'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ export const ROOMS_KEY = '@rooms';
|
|||
|
||||
export const mediaAlias = (mind: string, server: string): string => `#${mind}-files:${server}`;
|
||||
|
||||
/** The shared Commons room's alias (gamecult-ops synapse-accounts-hand-managed.py COMMONS_ALIAS). */
|
||||
export const commonsAlias = (server: string): string => `#commons:${server}`;
|
||||
|
||||
/**
|
||||
* The room id the stewardships state names for a Mind's media room, under `@rooms.file_zones[<mind>]`.
|
||||
* The state's mind-to-repos lists are not read here.
|
||||
|
|
@ -46,16 +49,16 @@ export type MediaLookup =
|
|||
| { found: true; roomId: string; via: string[] }
|
||||
| { found: false; reason: 'unset' | 'error'; message?: string };
|
||||
|
||||
/** Resolve a Mind's media room: a carried id if there is one, else the alias. A 404 means it is not set up. */
|
||||
export const lookupMediaRoom = async (
|
||||
/** Resolve a file-zone room (a Mind's media room, or Commons): a carried id if there is one, else the alias. A 404 means it is not set up. */
|
||||
export const lookupZoneRoom = async (
|
||||
mx: MediaClient,
|
||||
mind: string,
|
||||
alias: string,
|
||||
server: string,
|
||||
carriedId?: string
|
||||
): Promise<MediaLookup> => {
|
||||
if (carriedId) return { found: true, roomId: carriedId, via: [server] };
|
||||
try {
|
||||
const r = await mx.getRoomIdForAlias(mediaAlias(mind, server));
|
||||
const r = await mx.getRoomIdForAlias(alias);
|
||||
return { found: true, roomId: r.room_id, via: r.servers?.length ? r.servers : [server] };
|
||||
} catch (e) {
|
||||
const err = e as {
|
||||
|
|
@ -75,6 +78,14 @@ export const lookupMediaRoom = async (
|
|||
}
|
||||
};
|
||||
|
||||
/** Resolve a Mind's media room. */
|
||||
export const lookupMediaRoom = (
|
||||
mx: MediaClient,
|
||||
mind: string,
|
||||
server: string,
|
||||
carriedId?: string
|
||||
): Promise<MediaLookup> => lookupZoneRoom(mx, mediaAlias(mind, server), server, carriedId);
|
||||
|
||||
export type MediaRow =
|
||||
| { kind: 'checking' }
|
||||
| { kind: 'unset' }
|
||||
|
|
@ -86,7 +97,8 @@ const MEMBERSHIP_STATE = { join: 'joined', invite: 'invited', none: 'joinable' }
|
|||
/** What the Media row shows: the lookup result joined to the user's own membership. */
|
||||
export const mediaRow = (
|
||||
lookup: MediaLookup | undefined,
|
||||
membership: ReadonlyMap<string, 'join' | 'invite'>
|
||||
membership: ReadonlyMap<string, 'join' | 'invite'>,
|
||||
name = 'Media'
|
||||
): MediaRow => {
|
||||
if (!lookup) return { kind: 'checking' };
|
||||
if (!lookup.found) {
|
||||
|
|
@ -99,7 +111,7 @@ export const mediaRow = (
|
|||
kind: 'room',
|
||||
room: {
|
||||
roomId: lookup.roomId,
|
||||
name: 'Media',
|
||||
name,
|
||||
state: MEMBERSHIP_STATE[m ?? 'none'],
|
||||
via: lookup.via,
|
||||
parentId: null,
|
||||
|
|
@ -107,3 +119,18 @@ export const mediaRow = (
|
|||
},
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* The Commons row: the shared room, or nothing. Off with the share flag; not set up, still looking and a failed lookup
|
||||
* show no row (the room is shared furniture, not a per-Mind promise like Media). A found room is joined, invited or
|
||||
* joinable, as for Media.
|
||||
*/
|
||||
export const commonsRow = (
|
||||
enabled: boolean,
|
||||
lookup: MediaLookup | undefined,
|
||||
membership: ReadonlyMap<string, 'join' | 'invite'>
|
||||
): EstateRoom | undefined => {
|
||||
if (!enabled) return undefined;
|
||||
const row = mediaRow(lookup, membership, 'Commons');
|
||||
return row.kind === 'room' ? row.room : undefined;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue