implement rendering maps in sharing location

Signed-off-by: Shea <[email protected]>
This commit is contained in:
Shea committed 2026-06-06 22:03:35 +03:00
1 parent 107f31482a
commit 9b6f2fbd79
10 files changed
+200 -47

No files matched your search

+3
View File
@@ -71,6 +71,7 @@
"is-hotkey": "^0.2.0",
"jotai": "^2.18.0",
"katex": "^0.16.45",
"leaflet": "1.9.4",
"linkify-react": "^4.3.2",
"linkifyjs": "^4.3.2",
"marked": "^18.0.2",
@@ -84,6 +85,7 @@
"react-dom": "^18.3.1",
"react-google-recaptcha": "^2.1.0",
"react-i18next": "^16.5.4",
"react-leaflet": "^4.2.1",
"react-range": "^1.10.0",
"react-router-dom": "^6.30.3",
"slate": "^0.123.0",
@@ -107,6 +109,7 @@
"@types/chroma-js": "^3.1.2",
"@types/file-saver": "^2.0.7",
"@types/is-hotkey": "^0.1.10",
"@types/leaflet": "^1.9.21",
"@types/node": "24.10.13",
"@types/react": "^18.3.28",
"@types/react-dom": "^18.3.7",
+53
View File
@@ -138,6 +138,9 @@ importers:
katex:
specifier: ^0.16.45
version: 0.16.45
leaflet:
specifier: 1.9.4
version: 1.9.4
linkify-react:
specifier: ^4.3.2
version: 4.3.2([email protected])([email protected])
@@ -177,6 +180,9 @@ importers:
react-i18next:
specifier: ^16.5.4
version: 16.5.7([email protected]([email protected]))([email protected]([email protected]))([email protected])([email protected])
react-leaflet:
specifier: ^4.2.1
version: 4.2.1([email protected])([email protected]([email protected]))([email protected])
react-range:
specifier: ^1.10.0
version: 1.10.0([email protected]([email protected]))([email protected])
@@ -241,6 +247,9 @@ importers:
'@types/is-hotkey':
specifier: ^0.1.10
version: 0.1.10
'@types/leaflet':
specifier: ^1.9.21
version: 1.9.21
'@types/node':
specifier: 24.10.13
version: 24.10.13
@@ -2137,6 +2146,13 @@ packages:
react: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1
react-dom: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1
'@react-leaflet/[email protected]':
resolution: {integrity: sha512-Qk7Pfu8BSarKGqILj4x7bCSZ1pjuAPZ+qmRwH5S7mDS91VSbVVsJSrW4qA+GPrro8t69gFYVMWb1Zc4yFmPiVg==}
peerDependencies:
leaflet: ^1.9.0
react: ^18.0.0
react-dom: ^18.0.0
'@react-stately/[email protected]':
resolution: {integrity: sha512-uw7fCZXoypSBBUsVkbNvJMQWTihZReRbyLIGG3o/ZM630N3OCZhb/h4Uxke4pNu7n527H0V1bAnZgAldIzOYqg==}
peerDependencies:
@@ -2984,9 +3000,15 @@ packages:
'@types/[email protected]':
resolution: {integrity: sha512-dNKVfHd/jk0SkR/exKGj2ggkB45MAkzvWCaqLUUgkyjITkGNzH8H+yUwr+BLJUBjZOe9w8X3wgmXhZDRg1ED6A==}
'@types/[email protected]':
resolution: {integrity: sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==}
'@types/[email protected]':
resolution: {integrity: sha512-RvC8KMw5BCac1NvRRyaHgMMEtBaZ6wh0pyPTBu7izn4Sj/AX9Y4aXU5c7rX8PnM/knsuUpC1IeoBkANtxBypsQ==}
'@types/[email protected]':
resolution: {integrity: sha512-TbAd9DaPGSnzp6QvtYngntMZgcRk+igFELwR2N99XZn7RXUdKgsXMR+28bUO0rPsWp8MIu/f47luLIQuSLYv/w==}
'@types/[email protected]':
resolution: {integrity: sha512-oH72nZRfDv9lADUBSo104Aq7gPHpQZc4BTx38r9xf9pg5LfP6EzSyH2n7qFmmxRQXh7YlUXODcYsg6PuTDSxGg==}
@@ -4092,6 +4114,9 @@ packages:
'@types/node': '>=18'
typescript: '>=5.0.4 <7'
[email protected]:
resolution: {integrity: sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA==}
[email protected]:
resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==}
engines: {node: '>=6'}
@@ -4493,6 +4518,13 @@ packages:
[email protected]:
resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==}
[email protected]:
resolution: {integrity: sha512-p9chkvhcKrWn/H/1FFeVSqLdReGwn2qmiobOQGO3BifX+/vV/39qhY8dGqbdcPh1e6jxh/QHriLXr7a4eLFK4Q==}
peerDependencies:
leaflet: ^1.9.0
react: ^18.0.0
react-dom: ^18.0.0
[email protected]:
resolution: {integrity: sha512-+PbtI3VuDV0l6CleQMsx2gtK0JZbZKbpdu5ynr+lbsuvtmgbNcS3VM0tuY2QjFNOcWxvXeHjDpy42RO+4U2rug==}
@@ -7212,6 +7244,12 @@ snapshots:
react: 18.3.1
react-dom: 18.3.1([email protected])
'@react-leaflet/[email protected]([email protected])([email protected]([email protected]))([email protected])':
dependencies:
leaflet: 1.9.4
react: 18.3.1
react-dom: 18.3.1([email protected])
'@react-stately/[email protected]([email protected])':
dependencies:
'@internationalized/date': 3.12.0
@@ -8083,8 +8121,14 @@ snapshots:
'@types/[email protected]': {}
'@types/[email protected]': {}
'@types/[email protected]': {}
'@types/[email protected]':
dependencies:
'@types/geojson': 7946.0.16
'@types/[email protected]':
dependencies:
undici-types: 7.16.0
@@ -9332,6 +9376,8 @@ snapshots:
typescript: 5.9.3
zod: 4.3.6
[email protected]: {}
[email protected]: {}
[email protected]: {}
@@ -9798,6 +9844,13 @@ snapshots:
[email protected]: {}
[email protected]([email protected])([email protected]([email protected]))([email protected]):
dependencies:
'@react-leaflet/core': 2.1.0([email protected])([email protected]([email protected]))([email protected])
leaflet: 1.9.4
react: 18.3.1
react-dom: 18.3.1([email protected])
[email protected]: {}
[email protected]([email protected]([email protected]))([email protected]):
+3 -1
View File
@@ -59,6 +59,7 @@ type RenderMessageContentProps = {
bundledPreview?: boolean;
urlPreview?: boolean;
clientUrlPreview?: boolean;
showMaps?: boolean;
highlightRegex?: RegExp;
htmlReactParserOptions: HTMLReactParserOptions;
linkifyOpts: Opts;
@@ -94,6 +95,7 @@ function RenderMessageContentInternal({
bundledPreview,
urlPreview,
clientUrlPreview,
showMaps,
highlightRegex,
htmlReactParserOptions,
linkifyOpts,
@@ -429,7 +431,7 @@ function RenderMessageContentInternal({
}
if (msgType === (MsgType.File as string)) return renderFile();
if (msgType === (MsgType.Location as string)) return <MLocation content={content} />;
if (msgType === (MsgType.Location as string)) return <MLocation showMaps={showMaps} content={content} />;
if (msgType === 'm.bad.encrypted') return <MBadEncrypted />;
// cute events
+61 -16
View File
@@ -1,6 +1,6 @@
import type { CSSProperties, ReactNode } from 'react';
import { useMemo } from 'react';
import { Box, Chip, Icon, Icons, Text, toRem } from 'folds';
import { Box, Chip, color, Icon, Icons, Text, toRem, config } from 'folds';
import type { IContent, IPreviewUrlResponse } from '$types/matrix-sdk';
import { JUMBO_EMOJI_REG } from '$utils/regex';
import { trimReplyFromBody } from '$utils/room';
@@ -35,6 +35,10 @@ import { MessageTextBody } from './layout';
import { unwrapForwardedContent } from './modals/MessageForward';
import { LINKINPUTREGEX } from '$components/editor';
import { MATRIX_TO_BASE } from '$plugins/matrix-to';
import { MapContainer, Marker, TileLayer } from 'react-leaflet';
import type { LatLngExpression } from 'leaflet';
import 'leaflet/dist/leaflet.css';
import { copyToClipboard } from '$utils/dom';
export interface BundleContent extends IPreviewUrlResponse {
matched_url: string;
@@ -636,30 +640,71 @@ export function MFile({ content, renderFileContent, outlined }: MFileProps) {
type MLocationProps = {
content: IContent;
showMaps?: boolean;
};
export function MLocation({ content }: MLocationProps) {
export function MLocation({ content, showMaps }: MLocationProps) {
const geoUri = content.geo_uri;
if (typeof geoUri !== 'string') {
return <BrokenContent body={typeof content.body === 'string' ? content.body : undefined} />;
}
const location = parseGeoUri(geoUri);
if (!location) return <BrokenContent />;
const coords: LatLngExpression = [Number(location.latitude), Number(location.longitude)];
return (
<Box direction="Column" alignItems="Start" gap="100">
<Text size="T400">{geoUri}</Text>
<Chip
as="a"
size="400"
href={`https://www.openstreetmap.org/?mlat=${location.latitude}&mlon=${location.longitude}#map=16/${location.latitude}/${location.longitude}`}
target="_blank"
rel="noreferrer noopener"
variant="Primary"
radii="Pill"
before={<Icon src={Icons.External} size="50" />}
<Box
direction="Column"
style={{
maxWidth: toRem(500),
backgroundColor: color.SurfaceVariant.Container,
borderRadius: config.radii.R500,
overflow: 'hidden',
}}
onPointerMove={(evt) => evt.stopPropagation()}
>
<Box
direction="Row"
alignItems="Center"
gap="100"
justifyContent="SpaceBetween"
style={{ padding: config.space.S200 }}
>
<Text size="B300">Open Location</Text>
</Chip>
<Chip
size="400"
variant="SurfaceVariant"
onClick={() => copyToClipboard(`${location.latitude}, ${location.longitude}`)}
before={<Icon size="50" src={Icons.Link} />}
>
<Text size="T400">{`${location.latitude}, ${location.longitude}`}</Text>
</Chip>
<Chip
as="a"
size="400"
href={`https://www.openstreetmap.org/?mlat=${location.latitude}&mlon=${location.longitude}#map=16/${location.latitude}/${location.longitude}`}
target="_blank"
rel="noreferrer noopener"
variant="Primary"
radii="Pill"
before={<Icon src={Icons.External} size="50" />}
>
<Text size="B300">Open Location</Text>
</Chip>
</Box>
{showMaps && (
<MapContainer
center={coords}
zoom={16}
scrollWheelZoom={true}
style={{ height: toRem(400) }}
attributionControl
>
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap Contributors</a>'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<Marker position={coords} draggable></Marker>
</MapContainer>)}
</Box>
);
}
+5
View File
@@ -162,6 +162,10 @@ export function RoomTimeline({
const [incomingInlineImagesMaxHeight] = useSetting(settingsAtom, 'incomingInlineImagesMaxHeight');
const [hideMemberInReadOnly] = useSetting(settingsAtom, 'hideMembershipInReadOnly');
const [showInteractiveMap] = useSetting(settingsAtom, 'showInteractiveMap');
const [showEncInteractiveMap] = useSetting(settingsAtom, 'showEncInteractiveMap');
const showMaps = room.hasEncryptionStateEvent() ? showEncInteractiveMap : showInteractiveMap;
const showUrlPreview = room.hasEncryptionStateEvent() ? encUrlPreview : urlPreview;
const showClientUrlPreview = room.hasEncryptionStateEvent()
? clientUrlPreview && encClientUrlPreview
@@ -609,6 +613,7 @@ export function RoomTimeline({
showBundledPreview,
showUrlPreview,
showClientUrlPreview,
showMaps,
autoplayStickers,
hideMemberInReadOnly,
isReadOnly,
+4
View File
@@ -153,6 +153,9 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
const showClientUrlPreview = room.hasEncryptionStateEvent()
? clientUrlPreview && encClientUrlPreview
: clientUrlPreview;
const [showInteractiveMap] = useSetting(settingsAtom, 'showInteractiveMap');
const [showEncInteractiveMap] = useSetting(settingsAtom, 'showEncInteractiveMap');
const showMaps = room.hasEncryptionStateEvent() ? showEncInteractiveMap : showInteractiveMap;
// Memoized parsing options
const linkifyOpts = useMemo<LinkifyOpts>(
@@ -703,6 +706,7 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
showUrlPreview,
showClientUrlPreview,
showBundledPreview,
showMaps,
autoplayStickers,
hideMemberInReadOnly,
isReadOnly,
+62 -30
View File
@@ -1052,6 +1052,14 @@ function Embeds() {
const [urlPreview, setUrlPreview] = useSetting(settingsAtom, 'urlPreview');
const [encUrlPreview, setEncUrlPreview] = useSetting(settingsAtom, 'encUrlPreview');
const [clientUrlPreview, setClientUrlPreview] = useSetting(settingsAtom, 'clientUrlPreview');
const [showInteractiveMap, setShowInteractiveMap] = useSetting(
settingsAtom,
'showInteractiveMap'
);
const [showEncInteractiveMap, setEncShowInteractiveMap] = useSetting(
settingsAtom,
'showEncInteractiveMap'
);
const [encClientUrlPreview, setEncClientUrlPreview] = useSetting(
settingsAtom,
'encClientUrlPreview'
@@ -1112,48 +1120,72 @@ function Embeds() {
}
/>
</SequenceCard>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
style={clientUrlPreview ? {} : { display: 'none' }}
>
{clientUrlPreview && (
<>
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Client-side Embeds in Encrypted Rooms"
focusId="encrypted-room-embeds"
after={
<Switch
variant="Primary"
value={encClientUrlPreview}
onChange={setEncClientUrlPreview}
title={
encClientUrlPreview
? 'Disable client-side embeds in encrypted rooms'
: 'Enable client-side embeds in encrypted rooms'
}
/>
}
/>
</SequenceCard>
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Embed YouTube Links"
focusId="embed-youtube-links"
after={
<Switch
variant="Primary"
value={clientPreviewYoutube}
onChange={setClientPreviewYoutube}
title={
clientPreviewYoutube
? 'Disable client-side Youtube video embeds'
: 'Enable client-side Youtube video embeds'
}
/>
}
/>
</SequenceCard>
</>
)}
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Client-side Embeds in Encrypted Rooms"
focusId="encrypted-room-embeds"
title="Show Interactive maps"
focusId="show-interactive-map"
description="Show an interactive map in messages. This reduces Privacy because it requests map data from OpenStreetMap.org"
after={
<Switch
variant="Primary"
value={encClientUrlPreview}
onChange={setEncClientUrlPreview}
title={
encClientUrlPreview
? 'Disable client-side embeds in encrypted rooms'
: 'Enable client-side embeds in encrypted rooms'
}
value={showInteractiveMap}
onChange={setShowInteractiveMap}
title={showInteractiveMap ? 'Disable Interactive Map' : 'Enable Interactive Map'}
/>
}
/>
</SequenceCard>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
style={clientUrlPreview ? {} : { display: 'none' }}
>
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Embed YouTube Links"
focusId="embed-youtube-links"
title="Show Interactive maps in Encrypted Rooms"
focusId="show-interactive-map-enc"
description="Show an interactive map in Encrtyped rooms. This reduces Privacy because it requests map data from OpenStreetMap.org"
after={
<Switch
variant="Primary"
value={clientPreviewYoutube}
onChange={setClientPreviewYoutube}
title={
clientPreviewYoutube
? 'Disable client-side Youtube video embeds'
: 'Enable client-side Youtube video embeds'
}
value={showEncInteractiveMap}
onChange={setEncShowInteractiveMap}
title={showEncInteractiveMap ? 'Disable Interactive Map' : 'Enable Interactive Map'}
/>
}
/>
@@ -17,6 +17,8 @@ const settingsSectionLabel = Object.fromEntries(
const settingsLinkFocusIdsBySection: Record<SettingsSectionId, readonly string[]> = {
general: [
'show-interactive-map',
'show-interactive-map-enc',
'client-side-embeds',
'composer-formatting-toolbar',
'hide-add-menu',
@@ -273,6 +273,7 @@ export interface TimelineEventRendererOptions {
showUrlPreview: boolean;
showBundledPreview: boolean;
showClientUrlPreview: boolean;
showMaps?: boolean;
autoplayStickers: boolean;
hideMemberInReadOnly: boolean;
isReadOnly: boolean;
@@ -329,6 +330,7 @@ export function useTimelineEventRenderer({
showBundledPreview,
showUrlPreview,
showClientUrlPreview,
showMaps,
autoplayStickers,
hideMemberInReadOnly,
isReadOnly,
@@ -511,6 +513,7 @@ export function useTimelineEventRenderer({
urlPreview={showUrlPreview}
bundledPreview={showBundledPreview}
clientUrlPreview={showClientUrlPreview}
showMaps={showMaps}
htmlReactParserOptions={htmlReactParserOptions}
linkifyOpts={linkifyOpts}
outlineAttachment={messageLayout === MessageLayout.Bubble}
+4
View File
@@ -115,6 +115,8 @@ export interface Settings {
clientUrlPreview: boolean;
encClientUrlPreview: boolean;
clientPreviewYoutube: boolean;
showInteractiveMap: boolean;
showEncInteractiveMap: boolean;
usePushNotifications: boolean;
useInAppNotifications: boolean;
@@ -248,6 +250,8 @@ export const defaultSettings: Settings = {
clientUrlPreview: false,
encClientUrlPreview: false,
clientPreviewYoutube: false,
showInteractiveMap: true,
showEncInteractiveMap: false,
showHiddenEvents: false,
showTombstoneEvents: false,
legacyUsernameColor: false,