Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4486f02bc6 |
@@ -16,7 +16,7 @@ import { SettingTile } from '../setting-tile';
|
||||
import { UsageSwitcher } from './UsageSwitcher';
|
||||
import { ImagePackProfile, ImagePackProfileEdit } from './PackMeta';
|
||||
import * as css from './style.css';
|
||||
import { useFilePicker } from '../../hooks/useFilePicker';
|
||||
import { useStrippedFilePicker } from '../../hooks/useStrippedFilePicker';
|
||||
import { CompactUploadCardRenderer } from '../upload-card';
|
||||
import { UploadSuccess } from '../../state/upload';
|
||||
import { getImageInfo, TUploadContent } from '../../utils/matrix';
|
||||
@@ -60,7 +60,7 @@ export const ImagePackContent = as<'div', ImagePackContentProps>(
|
||||
[imagePack, savedImages, uploadedImages],
|
||||
);
|
||||
|
||||
const pickFiles = useFilePicker(
|
||||
const pickFiles = useStrippedFilePicker(
|
||||
useCallback(
|
||||
(pickedFiles: File[]) => {
|
||||
const uniqueFiles = pickedFiles.map((file) => {
|
||||
|
||||
@@ -19,7 +19,7 @@ import { nameInitials } from '../../utils/common';
|
||||
import { BreakWord } from '../../styles/Text.css';
|
||||
import { LINKIFY_OPTS } from '../../plugins/react-custom-html-parser';
|
||||
import { ContainerColor } from '../../styles/ContainerColor.css';
|
||||
import { useFilePicker } from '../../hooks/useFilePicker';
|
||||
import { useStrippedFilePicker } from '../../hooks/useStrippedFilePicker';
|
||||
import { useObjectURL } from '../../hooks/useObjectURL';
|
||||
import { createUploadAtom, UploadSuccess } from '../../state/upload';
|
||||
import { CompactUploadCardRenderer } from '../upload-card';
|
||||
@@ -111,7 +111,7 @@ export function ImagePackProfileEdit({ meta, onCancel, onSave }: ImagePackProfil
|
||||
return undefined;
|
||||
}, [imageFile]);
|
||||
|
||||
const pickFile = useFilePicker(setImageFile, false);
|
||||
const pickFile = useStrippedFilePicker(setImageFile, false);
|
||||
|
||||
const handleRemoveUpload = useCallback(() => {
|
||||
setImageFile(undefined);
|
||||
|
||||
@@ -50,14 +50,6 @@ type FlatClip = {
|
||||
* A management toggle reveals the pack editors (personal + this room, if
|
||||
* permitted). Space-wide packs are managed from Space settings.
|
||||
*/
|
||||
/** [EC#13, EC#47] Why the fork refused to play a clip, for the user. */
|
||||
export const soundboardRefusalText = (reason: string | undefined): string => {
|
||||
if (reason === 'muted') return 'Unmute your microphone to play a soundboard clip.';
|
||||
if (reason === 'not_permitted')
|
||||
return "The soundboard isn't available in this voice channel (only microphone audio is allowed here).";
|
||||
return 'Could not play that clip.';
|
||||
};
|
||||
|
||||
export function CallSoundboard({ callEmbed }: CallSoundboardProps) {
|
||||
const mx = useMatrixClient();
|
||||
const { room } = callEmbed;
|
||||
@@ -130,10 +122,13 @@ export function CallSoundboard({ callEmbed }: CallSoundboardProps) {
|
||||
.catch(() => undefined);
|
||||
const result = await callEmbed.control.injectAudio(url, vol, clipBytes);
|
||||
if (!result.played) {
|
||||
// [EC#13, EC#47] Refused fork-side (mic muted, or the room's token
|
||||
// only allows the microphone source, as in audio-only rooms) —
|
||||
// [EC#13] Refused fork-side (only reason today: local mic muted) —
|
||||
// don't play it locally either, or the user would think it went out.
|
||||
setError(soundboardRefusalText(result.reason));
|
||||
setError(
|
||||
result.reason === 'muted'
|
||||
? 'Unmute your microphone to play a soundboard clip.'
|
||||
: 'Could not play that clip.',
|
||||
);
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ import { useImagePackRooms } from '../../../hooks/useImagePackRooms';
|
||||
import { roomToParentsAtom } from '../../../state/room/roomToParents';
|
||||
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
import { useFilePicker } from '../../../hooks/useFilePicker';
|
||||
import { useStrippedFilePicker } from '../../../hooks/useStrippedFilePicker';
|
||||
import { CompactUploadCardRenderer } from '../../../components/upload-card';
|
||||
import { createUploadAtom, UploadSuccess } from '../../../state/upload';
|
||||
import { AsyncStatus, useAsyncCallback } from '../../../hooks/useAsyncCallback';
|
||||
@@ -68,7 +68,7 @@ function EditPower({ maxPower, power, tag, onSave, onClose }: EditPowerProps) {
|
||||
const imagePackRooms = useImagePackRooms(room.roomId, roomToParents);
|
||||
|
||||
const [iconFile, setIconFile] = useState<File>();
|
||||
const pickFile = useFilePicker(setIconFile, false);
|
||||
const pickFile = useStrippedFilePicker(setIconFile, false);
|
||||
|
||||
const [tagColor, setTagColor] = useState<string | undefined>(tag?.color);
|
||||
const [tagIcon, setTagIcon] = useState<MemberPowerTagIcon | undefined>(tag?.icon);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useFilePicker } from './useFilePicker';
|
||||
import { useSetting } from '../state/hooks/settings';
|
||||
import { settingsAtom } from '../state/settings';
|
||||
import { stripImageMetadata } from '../utils/stripImageMetadata';
|
||||
|
||||
/**
|
||||
* [Gitea #332] `useFilePicker` for images that get published (emoji / sticker
|
||||
* packs, pack avatars, power-level badges): applies "Remove Photo Metadata"
|
||||
* like message attachments and avatars, so a phone photo's GPS location and
|
||||
* timestamp don't go to every member of the room or space.
|
||||
*/
|
||||
export const useStrippedFilePicker = <M extends boolean | undefined = undefined>(
|
||||
onSelect: (file: M extends true ? File[] : File) => void,
|
||||
multiple?: M,
|
||||
) => {
|
||||
const [strip] = useSetting(settingsAtom, 'stripImageMetadata');
|
||||
const handle = useCallback(
|
||||
(picked: File | File[]) => {
|
||||
if (!strip) {
|
||||
onSelect(picked as M extends true ? File[] : File);
|
||||
return;
|
||||
}
|
||||
const clean = (f: File) => stripImageMetadata(f).then((r) => r.file);
|
||||
if (Array.isArray(picked)) {
|
||||
Promise.all(picked.map(clean)).then((files) =>
|
||||
onSelect(files as M extends true ? File[] : File),
|
||||
);
|
||||
} else {
|
||||
clean(picked).then((file) => onSelect(file as M extends true ? File[] : File));
|
||||
}
|
||||
},
|
||||
[strip, onSelect],
|
||||
);
|
||||
return useFilePicker(handle as (file: M extends true ? File[] : File) => void, multiple);
|
||||
};
|
||||
Reference in New Issue
Block a user