* center icon better Signed-off-by: Kerry Archibald <kerrya@element.io> * remove debug Signed-off-by: Kerry Archibald <kerrya@element.io> * retrigger all builds Signed-off-by: Kerry Archibald <kerrya@element.io> * set assetType on share event Signed-off-by: Kerry Archibald <kerrya@element.io> * use pin marker on map for pin drop share Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * test events Signed-off-by: Kerry Archibald <kerrya@element.io> * pin drop helper text Signed-off-by: Kerry Archibald <kerrya@element.io> * use generic location type Signed-off-by: Kerry Archibald <kerrya@element.io> * add navigationcontrol when in pin mode Signed-off-by: Kerry Archibald <kerrya@element.io> * allow pin drop without location permissions Signed-off-by: Kerry Archibald <kerrya@element.io> * remove geolocate control when pin dropping without geo perms Signed-off-by: Kerry Archibald <kerrya@element.io> * test locationpicker Signed-off-by: Kerry Archibald <kerrya@element.io> * test marker type, tidy Signed-off-by: Kerry Archibald <kerrya@element.io> * tweak style Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io>
81 lines
2.8 KiB
TypeScript
81 lines
2.8 KiB
TypeScript
/*
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
import { RelationType } from "matrix-js-sdk/src/@types/event";
|
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
|
import { makeLocationContent } from "matrix-js-sdk/src/content-helpers";
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
|
import { IEventRelation } from "matrix-js-sdk/src/models/event";
|
|
import { LocationAssetType } from "matrix-js-sdk/src/@types/location";
|
|
|
|
import { _t } from "../../../languageHandler";
|
|
import Modal from "../../../Modal";
|
|
import QuestionDialog from "../dialogs/QuestionDialog";
|
|
import SdkConfig from "../../../SdkConfig";
|
|
|
|
export enum LocationShareType {
|
|
Own = 'Own',
|
|
Pin = 'Pin',
|
|
Live = 'Live'
|
|
}
|
|
|
|
export const shareLocation = (
|
|
client: MatrixClient,
|
|
roomId: string,
|
|
shareType: LocationShareType,
|
|
relation: IEventRelation | undefined,
|
|
openMenu: () => void,
|
|
) => async (uri: string, ts: number) => {
|
|
if (!uri) return false;
|
|
try {
|
|
const text = textForLocation(uri, ts, null);
|
|
const threadId = relation?.rel_type === RelationType.Thread ? relation.event_id : null;
|
|
const assetType = shareType === LocationShareType.Pin ? LocationAssetType.Pin : LocationAssetType.Self;
|
|
await client.sendMessage(roomId, threadId, makeLocationContent(text, uri, ts, null, assetType));
|
|
} catch (e) {
|
|
logger.error("We couldn't send your location", e);
|
|
|
|
const analyticsAction = "We couldn't send your location";
|
|
const params = {
|
|
title: _t("We couldn't send your location"),
|
|
description: _t("%(brand)s could not send your location. Please try again later.", {
|
|
brand: SdkConfig.get().brand,
|
|
}),
|
|
button: _t('Try again'),
|
|
cancelButton: _t('Cancel'),
|
|
onFinished: (tryAgain: boolean) => {
|
|
if (tryAgain) {
|
|
openMenu();
|
|
}
|
|
},
|
|
};
|
|
Modal.createTrackedDialog(analyticsAction, '', QuestionDialog, params);
|
|
}
|
|
return true;
|
|
};
|
|
|
|
export function textForLocation(
|
|
uri: string,
|
|
ts: number,
|
|
description: string | null,
|
|
): string {
|
|
const date = new Date(ts).toISOString();
|
|
if (description) {
|
|
return `Location "${description}" ${uri} at ${date}`;
|
|
} else {
|
|
return `Location ${uri} at ${date}`;
|
|
}
|
|
}
|