a9505ca5b2
Soundboard v2 — a near-parallel of the custom-emoji image-pack system for in-call audio clips. - Data model: 3-tier packs mirroring MSC2545 — room/space pack (state event io.lotus.soundboard, inherited by child rooms via parent-space aggregation), global refs (io.lotus.soundboard_rooms), and the personal pack (io.lotus.soundboard account data; the v1 flat-list content is migrated to the pack shape on read). New plugins/soundboard/ (readers, SoundboardPack, utils) + hooks/useSoundboardPacks (useRelevantSoundboardPacks = user U global U room, deduped). Unit-tested (migration + slug). - Management: reusable SoundboardPackEditor (name + emoji + per-clip volume + delete + upload + batched save), power-level-gated for room packs like emoji packs; a Soundboard page wired into Room + Space settings. - In-call: CallSoundboard rewritten as a Discord-style grid grouped by pack (emoji + name tiles), sourcing room+parent-space U personal clips; a Manage toggle embeds the editors; per-clip volume x master volume on playback. - Spam guard: host gates on a playing key (fork enforces one clip at a time). - Control bar: Mute-Screenshare moved next to the Screenshare button. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
50 lines
1.9 KiB
TypeScript
50 lines
1.9 KiB
TypeScript
import React, { useCallback, useMemo } from 'react';
|
|
import { Room } from 'matrix-js-sdk';
|
|
import { usePowerLevels } from '../../hooks/usePowerLevels';
|
|
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
|
import { SoundboardPackEditor } from './SoundboardPackEditor';
|
|
import { SoundboardContent, SoundboardPack } from '../../plugins/soundboard';
|
|
import { StateEvent } from '../../../types/matrix/room';
|
|
import { useRoomSoundboardPack } from '../../hooks/useSoundboardPacks';
|
|
import { PackAddress } from '../../plugins/custom-emoji/PackAddress';
|
|
import { randomStr } from '../../utils/common';
|
|
import { useRoomPermissions } from '../../hooks/useRoomPermissions';
|
|
import { useRoomCreators } from '../../hooks/useRoomCreators';
|
|
|
|
type RoomSoundboardPackProps = {
|
|
room: Room;
|
|
stateKey: string;
|
|
};
|
|
|
|
export function RoomSoundboardPack({ room, stateKey }: RoomSoundboardPackProps) {
|
|
const mx = useMatrixClient();
|
|
const userId = mx.getUserId()!;
|
|
const powerLevels = usePowerLevels(room);
|
|
const creators = useRoomCreators(room);
|
|
const permissions = useRoomPermissions(creators, powerLevels);
|
|
const canEdit = permissions.stateEvent(
|
|
StateEvent.LotusSoundboardRoom as unknown as keyof import('matrix-js-sdk').StateEvents,
|
|
userId,
|
|
);
|
|
|
|
const fallbackPack = useMemo(
|
|
() => new SoundboardPack(randomStr(4), {}, new PackAddress(room.roomId, stateKey)),
|
|
[room.roomId, stateKey],
|
|
);
|
|
const pack = useRoomSoundboardPack(room, stateKey) ?? fallbackPack;
|
|
|
|
const handleUpdate = useCallback(
|
|
async (content: SoundboardContent) => {
|
|
await mx.sendStateEvent(
|
|
room.roomId,
|
|
StateEvent.LotusSoundboardRoom as unknown as keyof import('matrix-js-sdk').StateEvents,
|
|
content as never,
|
|
stateKey,
|
|
);
|
|
},
|
|
[mx, room.roomId, stateKey],
|
|
);
|
|
|
|
return <SoundboardPackEditor pack={pack} canEdit={canEdit} onUpdate={handleUpdate} />;
|
|
}
|