feat: poll voting, location sharing, image captions, message forwarding

- Poll voting: PollContent sends m.poll.response on answer click
- Location: MLocation shows OSM map embed + share-location button in toolbar
- Image captions: caption field on media uploads sets message body
- Message forwarding: ForwardMessageDialog with searchable room picker
- Also includes ring timeout fix and earlier session patches
This commit is contained in:
root
2026-05-15 13:37:03 -04:00
parent e89ba95c08
commit 5bba52e315
17 changed files with 1047 additions and 51 deletions
+109
View File
@@ -30,6 +30,8 @@ import {
} from 'folds';
import { useMatrixClient } from '../../hooks/useMatrixClient';
import { GifPicker } from '../../components/GifPicker';
import { useClientConfig } from '../../hooks/useClientConfig';
import {
CustomEditor,
Toolbar,
@@ -171,6 +173,26 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
const imagePackRooms: Room[] = useImagePackRooms(roomId, roomToParents);
const [toolbar, setToolbar] = useSetting(settingsAtom, 'editorToolbar');
const [locating, setLocating] = React.useState(false);
const handleShareLocation = () => {
if (!navigator.geolocation) return;
setLocating(true);
navigator.geolocation.getCurrentPosition(
(pos) => {
setLocating(false);
const { latitude, longitude } = pos.coords;
const geoUri = `geo:${latitude.toFixed(6)},${longitude.toFixed(6)}`;
mx.sendMessage(roomId, {
msgtype: 'm.location',
body: `Location: ${geoUri}`,
geo_uri: geoUri,
} as any);
},
() => setLocating(false),
{ timeout: 10000 }
);
};
const [autocompleteQuery, setAutocompleteQuery] =
useState<AutocompleteQuery<AutocompletePrefix>>();
@@ -216,6 +238,8 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
const pickFile = useFilePicker(handleFiles, true);
const handlePaste = useFilePasteHandler(handleFiles);
const dropZoneVisible = useFileDropZone(fileDropContainerRef, handleFiles);
const { gifApiKey } = useClientConfig();
const gifBtnRef = useRef<HTMLButtonElement>(null);
const [hideStickerBtn, setHideStickerBtn] = useState(document.body.clientWidth < 500);
const isComposing = useComposingCheck();
@@ -430,6 +454,30 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
moveCursor(editor);
};
const handleGifSelect = useCallback(
async (gifUrl: string, w: number, h: number) => {
try {
const res = await fetch(gifUrl);
const blob = await res.blob();
const uploadRes = await mx.uploadContent(
new File([blob], 'image.gif', { type: 'image/gif' }),
{ type: 'image/gif', name: 'image.gif', includeFilename: false }
);
const mxcUrl = (uploadRes as any).content_uri;
if (!mxcUrl) return;
mx.sendMessage(roomId, {
msgtype: MsgType.Image,
body: 'image.gif',
url: mxcUrl,
info: { mimetype: 'image/gif', w, h, size: blob.size },
});
} catch (e) {
console.error('GIF send failed', e);
}
},
[mx, roomId]
);
const handleStickerSelect = async (mxc: string, shortcode: string, label: string) => {
const stickerUrl = mxcUrlToHttp(mx, mxc, useAuthentication);
if (!stickerUrl) return;
@@ -669,6 +717,67 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
</PopOut>
)}
</UseStateProvider>
{!!gifApiKey && (
<UseStateProvider initial={false}>
{(gifOpen: boolean, setGifOpen) => (
<PopOut
offset={16}
alignOffset={-44}
position="Top"
align="End"
anchor={
gifOpen
? gifBtnRef.current?.getBoundingClientRect() ?? undefined
: undefined
}
content={
<GifPicker
apiKey={gifApiKey}
onSelect={handleGifSelect}
requestClose={() => setGifOpen(false)}
/>
}
>
<IconButton
ref={gifBtnRef}
aria-pressed={gifOpen}
onClick={() => setGifOpen(!gifOpen)}
variant="SurfaceVariant"
size="300"
radii="300"
>
<Text
size="T200"
style={{
fontWeight: 800,
fontSize: '11px',
letterSpacing: '0.04em',
lineHeight: 1,
}}
>
GIF
</Text>
</IconButton>
</PopOut>
)}
</UseStateProvider>
)}
<IconButton
onClick={handleShareLocation}
variant="SurfaceVariant"
size="300"
radii="300"
aria-label="Share location"
title="Share location"
>
{locating ? (
<Text size="T200" style={{ fontWeight: 800, fontSize: '10px', letterSpacing: '0.04em', lineHeight: 1 }}>
...
</Text>
) : (
<Icon src={Icons.Pin} size="100" />
)}
</IconButton>
<IconButton onClick={submit} variant="SurfaceVariant" size="300" radii="300">
<Icon src={Icons.Send} />
</IconButton>