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

Simple static location sharing #7135

Merged
merged 32 commits into from
Dec 6, 2021
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c66d54b
first ugly cut at a location picker via maplibre
ara4n Nov 14, 2021
7970b90
fix css
ara4n Nov 14, 2021
12bb69b
fix dropdown height
ara4n Nov 14, 2021
1b75489
fix form
ara4n Nov 14, 2021
cd9ea95
use right icon
ara4n Nov 14, 2021
3a779b7
hook up locationpicker
ara4n Nov 15, 2021
3b0a3a2
actually send m.location events
ara4n Nov 15, 2021
6ce1e86
view m.location
ara4n Nov 15, 2021
e7cd207
border radius on picker
ara4n Nov 15, 2021
fc41580
fix lint
ara4n Nov 21, 2021
bec7af4
Merge branch 'develop' into matthew/location-share
ara4n Nov 21, 2021
d6b5153
Merge branch 'develop' into matthew/location-share
ara4n Nov 21, 2021
ccd416d
fix css var
ara4n Nov 21, 2021
eebf29d
fix types
ara4n Nov 21, 2021
426f7b3
only send loc if you have one
ara4n Nov 21, 2021
94f1ff9
disable the streaming options until they're hooked up
ara4n Nov 21, 2021
6488168
lint
ara4n Nov 21, 2021
644fe03
more lint
ara4n Nov 21, 2021
f774e71
fix i18n
ara4n Nov 21, 2021
80a15a1
show descriptions
ara4n Nov 21, 2021
92ba926
incorporate review
ara4n Nov 22, 2021
5531d09
use fancy optional chaining
ara4n Nov 22, 2021
8fd4310
add createObjectURL mock
ara4n Nov 22, 2021
097c8f7
fix i18n
ara4n Nov 22, 2021
3dc7b21
Merge branch 'develop' into matthew/location-share
ara4n Nov 28, 2021
982d5b7
warn if API key not set when showing maps
ara4n Nov 28, 2021
6ea351e
Merge branch 'develop' into matthew/location-share
ara4n Dec 4, 2021
49c590c
export LocationShareType enum correctly
ara4n Dec 5, 2021
f088094
hook up map failure error correctly
ara4n Dec 5, 2021
58ebf2a
fix lint
ara4n Dec 5, 2021
e6842ba
fix type
ara4n Dec 5, 2021
d6b805a
fix types
ara4n Dec 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix types
ara4n committed Nov 21, 2021
commit eebf29dbc7418e54bf2e294ec95d65989d8b7eae
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@
"@babel/runtime": "^7.12.5",
"@sentry/browser": "^6.11.0",
"@sentry/tracing": "^6.11.0",
"@types/geojson": "^7946.0.8",
"await-lock": "^2.1.0",
"blurhash": "^1.1.3",
"browser-encrypt-attachment": "^0.3.0",
35 changes: 14 additions & 21 deletions src/components/views/location/LocationPicker.tsx
Original file line number Diff line number Diff line change
@@ -21,25 +21,13 @@ import SdkConfig from '../../../SdkConfig';
import Field from "../elements/Field";
import DialogButtons from "../elements/DialogButtons";
import Dropdown from "../elements/Dropdown";
import { LocationShareType } from "./LocationShareType";

import { _t } from '../../../languageHandler';
import { replaceableComponent } from "../../../utils/replaceableComponent";

enum LocationShareType {
CUSTOM = -1,
ONE_OFF = 0,
ONE_MIN = 60,
FIVE_MINS = 5 * 60,
THIRTY_MINS = 30 * 60,
ONE_HOUR = 60 * 60,
THREE_HOURS = 3 * 60 * 60,
SIX_HOURS = 6 * 60 * 60,
ONE_DAY = 24 * 60 * 60,
FOREVER = Number.MAX_SAFE_INTEGER,
}

interface IDropdownProps {
value: JoinRule;
value: LocationShareType;
label: string;
width?: number;
onChange(type: LocationShareType): void;
@@ -67,17 +55,18 @@ const LocationShareTypeDropdown = ({
return <Dropdown
id="mx_LocationShareTypeDropdown"
className="mx_LocationShareTypeDropdown"
onOptionChange={onChange}
width={width}
value={value}
onOptionChange={(key: string)=>{ onChange(LocationShareType[LocationShareType[parseInt(key)]]) }}
menuWidth={width}
label={label}
value={value.toString()}
>
{ options }
</Dropdown>;
};

interface IProps {
onChoose(uri: string, ts: integer, type: LocationShareType, description: string): boolean;
onCancel();
onChoose(uri: string, ts: number, type: LocationShareType, description: string): boolean;
onFinished();
}

interface IState {
@@ -88,6 +77,9 @@ interface IState {

@replaceableComponent("views.location.LocationPicker")
class LocationPicker extends React.Component<IProps, IState> {
private map : maplibregl.Map;
private geolocate : maplibregl.GeolocateControl;

constructor(props) {
super(props);

@@ -131,7 +123,7 @@ class LocationPicker extends React.Component<IProps, IState> {
this.setState({ position });
};

private onDescriptionChange = (ev: ChangeEvent<HTMLInputElement>) => {
private onDescriptionChange = (ev: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ description: ev.target.value });
};

@@ -162,9 +154,10 @@ class LocationPicker extends React.Component<IProps, IState> {
<div className="mx_LocationPicker">
<div id="mx_LocationPicker_map" />
<div className="mx_LocationPicker_footer">
<form onSubmit={this.onOk} onKeyDown={this.onKeyDown}>
<form onSubmit={this.onOk}>
<LocationShareTypeDropdown
value={this.state.type}
label={_t("Type of location share")}
onChange={this.onTypeChange}
width={400}
/>
28 changes: 28 additions & 0 deletions src/components/views/location/LocationShareType.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2021 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.
*/

export enum LocationShareType {
CUSTOM = -1,
ONE_OFF = 0,
ONE_MIN = 60,
FIVE_MINS = 5 * 60,
THIRTY_MINS = 30 * 60,
ONE_HOUR = 60 * 60,
THREE_HOURS = 3 * 60 * 60,
SIX_HOURS = 6 * 60 * 60,
ONE_DAY = 24 * 60 * 60,
FOREVER = Number.MAX_SAFE_INTEGER,
}
24 changes: 17 additions & 7 deletions src/components/views/messages/MLocationBody.tsx
Original file line number Diff line number Diff line change
@@ -19,9 +19,16 @@ import maplibregl from 'maplibre-gl';
import SdkConfig from '../../../SdkConfig';
import { replaceableComponent } from "../../../utils/replaceableComponent";
import { IBodyProps } from "./IBodyProps";
import { LocationShareType } from "../location/LocationShareType";

interface IState {
}

@replaceableComponent("views.messages.MLocationBody")
export default class MLocationBody extends React.Component<IBodyProps, IState> {
private map : maplibregl.Map;
private coords : GeolocationCoordinates;

constructor(props: IBodyProps) {
super(props);

@@ -37,21 +44,24 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {
this.coords = this.parseGeoUri(uri);
}

private parseGeoUri = (uri) => {
private parseGeoUri = (uri: string) : GeolocationCoordinates => {
const m = uri.match(/^\s*geo:(.*?)\s*$/);
if (!m) return;
const parts = m[1].split(';');
const coords = parts[0].split(',');
let uncertainty;
let uncertainty : number;
for (const param of parts.slice(1)) {
const m = param.match(/u=(.*)/);
if (m) uncertainty = m[1];
if (m) uncertainty = parseFloat(m[1]);
}
return {
'latitude': coords[0],
'longitude': coords[1],
'altitude': coords[2],
'accuracy': uncertainty,
latitude: parseFloat(coords[0]),
longitude: parseFloat(coords[1]),
altitude: parseFloat(coords[2]),
accuracy: uncertainty,
altitudeAccuracy: undefined,
heading: undefined,
speed: undefined,
};
};

5 changes: 3 additions & 2 deletions src/components/views/rooms/MessageComposer.tsx
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ import ErrorDialog from "../dialogs/ErrorDialog";
import PollCreateDialog from "../elements/PollCreateDialog";
import { MsgType } from "matrix-js-sdk/src/@types/event";
import { logger } from "matrix-js-sdk/src/logger";
import { LocationShareType } from "../location/LocationShareType";

let instanceCount = 0;
const NARROW_MODE_BREAKPOINT = 500;
@@ -131,7 +132,7 @@ const EmojiButton: React.FC<IEmojiButtonProps> = ({ addEmoji, menuPosition, narr

interface ILocationButtonProps {
room: Room;
shareLocation: (uri: string, ts: int, type: LocationShareType, description: string) => boolean;
shareLocation: (uri: string, ts: number, type: LocationShareType, description: string) => boolean;
menuPosition: any; // TODO: Types
narrowMode: boolean;
}
@@ -462,7 +463,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
return true;
};

private shareLocation = (uri: string, ts: int, type: LocationShareType, description: string): boolean => {
private shareLocation = (uri: string, ts: number, type: LocationShareType, description: string): boolean => {
if (!uri) return false;
try {
const text = `${description ? description : 'Location'} at ${uri} as of ${new Date(ts).toISOString()}`;
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
@@ -2077,6 +2077,7 @@
"Share my current location for six hours": "Share my current location for six hours",
"Share my current location for one day": "Share my current location for one day",
"Share my current location until I disable it": "Share my current location until I disable it",
"Type of location share": "Type of location share",
"Failed to load group members": "Failed to load group members",
"Filter community members": "Filter community members",
"Are you sure you want to remove '%(roomName)s' from %(groupId)s?": "Are you sure you want to remove '%(roomName)s' from %(groupId)s?",
2 changes: 2 additions & 0 deletions src/settings/controllers/SettingController.ts
Original file line number Diff line number Diff line change
@@ -54,6 +54,8 @@ export default abstract class SettingController {
*/
public onChange(level: SettingLevel, roomId: string, newValue: any) {
// do nothing by default

// FIXME: force a fresh on the RoomView for the roomId in question
}

/**
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -1722,6 +1722,11 @@
"@types/fbemitter" "*"
"@types/react" "*"

"@types/geojson@^7946.0.8":
version "7946.0.8"
resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-7946.0.8.tgz#30744afdb385e2945e22f3b033f897f76b1f12ca"
integrity sha512-1rkryxURpr6aWP7R786/UQOkJ3PcpQiWkAXBmdWc7ryFWqN6a4xfK7BtjXvFBKO9LjQ+MWQSWxYeZX1OApnArA==

"@types/graceful-fs@^4.1.2":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15"