Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Look up tile server info in homeserver's .well-known area #7623

Merged
merged 9 commits into from
Jan 27, 2022
5 changes: 2 additions & 3 deletions src/components/views/location/LocationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import maplibregl from 'maplibre-gl';
import { logger } from "matrix-js-sdk/src/logger";
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';

import SdkConfig from '../../../SdkConfig';
import DialogButtons from "../elements/DialogButtons";
import { _t } from '../../../languageHandler';
import { replaceableComponent } from "../../../utils/replaceableComponent";
import MemberAvatar from '../avatars/MemberAvatar';
import MatrixClientContext from '../../../contexts/MatrixClientContext';
import Modal from '../../../Modal';
import ErrorDialog from '../dialogs/ErrorDialog';
import { findMapStyleUrl } from '../messages/MLocationBody';

interface IProps {
sender: RoomMember;
Expand Down Expand Up @@ -69,10 +69,9 @@ class LocationPicker extends React.Component<IProps, IState> {
};

componentDidMount() {
const config = SdkConfig.get();
this.map = new maplibregl.Map({
container: 'mx_LocationPicker_map',
style: config.map_style_url,
style: findMapStyleUrl(),
center: [0, 0],
zoom: 1,
});
Expand Down
16 changes: 15 additions & 1 deletion src/components/views/messages/MLocationBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import LocationViewDialog from '../location/LocationViewDialog';
import TooltipTarget from '../elements/TooltipTarget';
import { Alignment } from '../elements/Tooltip';
import AccessibleButton from '../elements/AccessibleButton';
import { getTileServerWellKnown } from '../../../utils/WellKnownUtils';

interface IState {
error: Error;
Expand Down Expand Up @@ -206,14 +207,27 @@ function ZoomButtons(props: IZoomButtonsProps): React.ReactElement<HTMLDivElemen
</div>;
}

/**
* Look up what map tile server style URL was provided in the homeserver's
* .well-known location, or, failing that, in our local config, or, failing
* that, defaults to the same tile server listed by matrix.org.
*/
export function findMapStyleUrl(): string {
return (
getTileServerWellKnown().map_style_url ??
SdkConfig.get().map_style_url ??
"https://api.maptiler.com/maps/streets/style.json?key=fU3vlMsMn4Jb6dnEIFsx"
andybalaam marked this conversation as resolved.
Show resolved Hide resolved
);
}

export function createMap(
coords: GeolocationCoordinates,
interactive: boolean,
bodyId: string,
markerId: string,
onError: (error: Error) => void,
): maplibregl.Map {
const styleUrl = SdkConfig.get().map_style_url;
const styleUrl = findMapStyleUrl();
const coordinates = new maplibregl.LngLat(coords.longitude, coords.latitude);

const map = new maplibregl.Map({
Expand Down
16 changes: 16 additions & 0 deletions src/utils/WellKnownUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { UnstableValue } from 'matrix-js-sdk/src/NamespacedValue';

import { MatrixClientPeg } from '../MatrixClientPeg';

const CALL_BEHAVIOUR_WK_KEY = "io.element.call_behaviour";
const E2EE_WK_KEY = "io.element.e2ee";
const E2EE_WK_KEY_DEPRECATED = "im.vector.riot.e2ee";
const TILE_SERVER_WK_KEY = new UnstableValue(
"m.tile_server", "org.matrix.msc3488.tile_server");

/* eslint-disable camelcase */
export interface ICallBehaviourWellKnown {
Expand All @@ -30,6 +34,10 @@ export interface IE2EEWellKnown {
secure_backup_required?: boolean;
secure_backup_setup_methods?: SecureBackupSetupMethod[];
}

export interface ITileServerWellKnown {
map_style_url?: string;
}
/* eslint-enable camelcase */

export function getCallBehaviourWellKnown(): ICallBehaviourWellKnown {
Expand All @@ -48,6 +56,14 @@ export function getE2EEWellKnown(): IE2EEWellKnown {
return null;
}

export function getTileServerWellKnown(): ITileServerWellKnown {
const clientWellKnown = MatrixClientPeg.get().getClientWellKnown();
return (
clientWellKnown?.[TILE_SERVER_WK_KEY.name] ??
clientWellKnown?.[TILE_SERVER_WK_KEY.altName]
);
}

andybalaam marked this conversation as resolved.
Show resolved Hide resolved
export function isSecureBackupRequired(): boolean {
const wellKnown = getE2EEWellKnown();
return wellKnown && wellKnown["secure_backup_required"] === true;
Expand Down