* copyright Signed-off-by: Kerry Archibald <kerrya@element.io> * empty line Signed-off-by: Kerry Archibald <kerrya@element.io> * functional picker Signed-off-by: Kerry Archibald <kerrya@element.io> * most style Signed-off-by: Kerry Archibald <kerrya@element.io> * nice style for options Signed-off-by: Kerry Archibald <kerrya@element.io> * get ShareType test passing Signed-off-by: Kerry Archibald <kerrya@element.io> * add maplibre mock Signed-off-by: Kerry Archibald <kerrya@element.io> * lint and test Signed-off-by: Kerry Archibald <kerrya@element.io> * add section to themes for location sharing cols Signed-off-by: Kerry Archibald <kerrya@element.io> * add svg mock Signed-off-by: Kerry Archibald <kerrya@element.io> * use same mock string as imageMock Signed-off-by: Kerry Archibald <kerrya@element.io> * newline Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * add live location icon Signed-off-by: Kerry Archibald <kerrya@element.io> * rename useEnabledShareTypes Signed-off-by: Kerry Archibald <kerrya@element.io> * use solid color for live border * use ternary Signed-off-by: Kerry Archibald <kerrya@element.io> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
66 lines
2.3 KiB
TypeScript
66 lines
2.3 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 { 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 { _t } from "../../../languageHandler";
|
||
import Modal from "../../../Modal";
|
||
import QuestionDialog from "../dialogs/QuestionDialog";
|
||
|
||
export const shareLocation = (client: MatrixClient, roomId: string, openMenu: () => void) =>
|
||
(uri: string, ts: number) => {
|
||
if (!uri) return false;
|
||
try {
|
||
const text = textForLocation(uri, ts, null);
|
||
client.sendMessage(
|
||
roomId,
|
||
makeLocationContent(text, uri, ts, null),
|
||
);
|
||
} 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(
|
||
"Element could not send your location. Please try again later."),
|
||
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}`;
|
||
}
|
||
}
|