Live location share - open latest location in map site (#8981)
* move getForwardableBeacon to beacon utils * move event transform type up * add helper to get shareable-as-locaion events * use getShareableLocationEvent in MessageContextMenu * test opening in maplink * fix bad copy pasted tests
This commit is contained in:
parent
0026e0462b
commit
ed92071046
10 changed files with 310 additions and 17 deletions
|
@ -36,7 +36,7 @@ import { IRoomState } from "../../../../src/components/structures/RoomView";
|
|||
import { canEditContent } from "../../../../src/utils/EventUtils";
|
||||
import { copyPlaintext, getSelectedText } from "../../../../src/utils/strings";
|
||||
import MessageContextMenu from "../../../../src/components/views/context_menus/MessageContextMenu";
|
||||
import { makeBeaconEvent, makeBeaconInfoEvent, stubClient } from '../../../test-utils';
|
||||
import { makeBeaconEvent, makeBeaconInfoEvent, makeLocationEvent, stubClient } from '../../../test-utils';
|
||||
import dispatcher from '../../../../src/dispatcher/dispatcher';
|
||||
import SettingsStore from '../../../../src/settings/SettingsStore';
|
||||
import { ReadPinsEventId } from '../../../../src/components/views/right_panel/types';
|
||||
|
@ -308,6 +308,49 @@ describe('MessageContextMenu', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('open as map link', () => {
|
||||
it('does not allow opening a plain message in open street maps', () => {
|
||||
const eventContent = MessageEvent.from("hello");
|
||||
const menu = createMenuWithContent(eventContent);
|
||||
expect(menu.find('a[aria-label="Open in OpenStreetMap"]')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('does not allow opening a beacon that does not have a shareable location event', () => {
|
||||
const deadBeaconEvent = makeBeaconInfoEvent('@alice', roomId, { isLive: false });
|
||||
const beacon = new Beacon(deadBeaconEvent);
|
||||
const beacons = new Map<BeaconIdentifier, Beacon>();
|
||||
beacons.set(getBeaconInfoIdentifier(deadBeaconEvent), beacon);
|
||||
const menu = createMenu(deadBeaconEvent, {}, {}, beacons);
|
||||
expect(menu.find('a[aria-label="Open in OpenStreetMap"]')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('allows opening a location event in open street map', () => {
|
||||
const locationEvent = makeLocationEvent('geo:50,50');
|
||||
const menu = createMenu(locationEvent);
|
||||
// exists with a href with the lat/lon from the location event
|
||||
expect(
|
||||
menu.find('a[aria-label="Open in OpenStreetMap"]').at(0).props().href,
|
||||
).toEqual('https://www.openstreetmap.org/?mlat=50&mlon=50#map=16/50/50');
|
||||
});
|
||||
|
||||
it('allows opening a beacon that has a shareable location event', () => {
|
||||
const liveBeaconEvent = makeBeaconInfoEvent('@alice', roomId, { isLive: true });
|
||||
const beaconLocation = makeBeaconEvent(
|
||||
'@alice', { beaconInfoId: liveBeaconEvent.getId(), geoUri: 'geo:51,41' },
|
||||
);
|
||||
const beacon = new Beacon(liveBeaconEvent);
|
||||
// @ts-ignore illegally set private prop
|
||||
beacon._latestLocationEvent = beaconLocation;
|
||||
const beacons = new Map<BeaconIdentifier, Beacon>();
|
||||
beacons.set(getBeaconInfoIdentifier(liveBeaconEvent), beacon);
|
||||
const menu = createMenu(liveBeaconEvent, {}, {}, beacons);
|
||||
// exists with a href with the lat/lon from the location event
|
||||
expect(
|
||||
menu.find('a[aria-label="Open in OpenStreetMap"]').at(0).props().href,
|
||||
).toEqual('https://www.openstreetmap.org/?mlat=51&mlon=41#map=16/51/41');
|
||||
});
|
||||
});
|
||||
|
||||
describe("right click", () => {
|
||||
it('copy button does work as expected', () => {
|
||||
const text = "hello";
|
||||
|
|
87
test/events/forward/getForwardableEvent-test.ts
Normal file
87
test/events/forward/getForwardableEvent-test.ts
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
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 {
|
||||
EventType,
|
||||
MatrixEvent,
|
||||
MsgType,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { getForwardableEvent } from "../../../src/events";
|
||||
import {
|
||||
getMockClientWithEventEmitter,
|
||||
makeBeaconEvent,
|
||||
makeBeaconInfoEvent,
|
||||
makePollStartEvent,
|
||||
makeRoomWithBeacons,
|
||||
} from "../../test-utils";
|
||||
|
||||
describe('getForwardableEvent()', () => {
|
||||
const userId = '@alice:server.org';
|
||||
const roomId = '!room:server.org';
|
||||
const client = getMockClientWithEventEmitter({
|
||||
getRoom: jest.fn(),
|
||||
});
|
||||
|
||||
it('returns the event for a room message', () => {
|
||||
const alicesMessageEvent = new MatrixEvent({
|
||||
type: EventType.RoomMessage,
|
||||
sender: userId,
|
||||
room_id: roomId,
|
||||
content: {
|
||||
msgtype: MsgType.Text,
|
||||
body: 'Hello',
|
||||
},
|
||||
});
|
||||
|
||||
expect(getForwardableEvent(alicesMessageEvent, client)).toBe(alicesMessageEvent);
|
||||
});
|
||||
|
||||
it('returns null for a poll start event', () => {
|
||||
const pollStartEvent = makePollStartEvent('test?', userId);
|
||||
|
||||
expect(getForwardableEvent(pollStartEvent, client)).toBe(null);
|
||||
});
|
||||
|
||||
describe('beacons', () => {
|
||||
it('returns null for a beacon that is not live', () => {
|
||||
const notLiveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: false });
|
||||
makeRoomWithBeacons(roomId, client, [notLiveBeacon]);
|
||||
|
||||
expect(getForwardableEvent(notLiveBeacon, client)).toBe(null);
|
||||
});
|
||||
|
||||
it('returns null for a live beacon that does not have a location', () => {
|
||||
const liveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: true });
|
||||
makeRoomWithBeacons(roomId, client, [liveBeacon]);
|
||||
|
||||
expect(getForwardableEvent(liveBeacon, client)).toBe(null);
|
||||
});
|
||||
|
||||
it('returns the latest location event for a live beacon with location', () => {
|
||||
const liveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: true }, 'id');
|
||||
const locationEvent = makeBeaconEvent(userId, {
|
||||
beaconInfoId: liveBeacon.getId(),
|
||||
geoUri: 'geo:52,42',
|
||||
// make sure its in live period
|
||||
timestamp: Date.now() + 1,
|
||||
});
|
||||
makeRoomWithBeacons(roomId, client, [liveBeacon], [locationEvent]);
|
||||
|
||||
expect(getForwardableEvent(liveBeacon, client)).toBe(locationEvent);
|
||||
});
|
||||
});
|
||||
});
|
87
test/events/location/getShareableLocationEvent-test.ts
Normal file
87
test/events/location/getShareableLocationEvent-test.ts
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
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 {
|
||||
EventType,
|
||||
MatrixEvent,
|
||||
MsgType,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { getShareableLocationEvent } from "../../../src/events";
|
||||
import {
|
||||
getMockClientWithEventEmitter,
|
||||
makeBeaconEvent,
|
||||
makeBeaconInfoEvent,
|
||||
makeLocationEvent,
|
||||
makeRoomWithBeacons,
|
||||
} from "../../test-utils";
|
||||
|
||||
describe('getShareableLocationEvent()', () => {
|
||||
const userId = '@alice:server.org';
|
||||
const roomId = '!room:server.org';
|
||||
const client = getMockClientWithEventEmitter({
|
||||
getRoom: jest.fn(),
|
||||
});
|
||||
|
||||
it('returns null for a non-location event', () => {
|
||||
const alicesMessageEvent = new MatrixEvent({
|
||||
type: EventType.RoomMessage,
|
||||
sender: userId,
|
||||
room_id: roomId,
|
||||
content: {
|
||||
msgtype: MsgType.Text,
|
||||
body: 'Hello',
|
||||
},
|
||||
});
|
||||
|
||||
expect(getShareableLocationEvent(alicesMessageEvent, client)).toBe(null);
|
||||
});
|
||||
|
||||
it('returns the event for a location event', () => {
|
||||
const locationEvent = makeLocationEvent('geo:52,42');
|
||||
|
||||
expect(getShareableLocationEvent(locationEvent, client)).toBe(locationEvent);
|
||||
});
|
||||
|
||||
describe('beacons', () => {
|
||||
it('returns null for a beacon that is not live', () => {
|
||||
const notLiveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: false });
|
||||
makeRoomWithBeacons(roomId, client, [notLiveBeacon]);
|
||||
|
||||
expect(getShareableLocationEvent(notLiveBeacon, client)).toBe(null);
|
||||
});
|
||||
|
||||
it('returns null for a live beacon that does not have a location', () => {
|
||||
const liveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: true });
|
||||
makeRoomWithBeacons(roomId, client, [liveBeacon]);
|
||||
|
||||
expect(getShareableLocationEvent(liveBeacon, client)).toBe(null);
|
||||
});
|
||||
|
||||
it('returns the latest location event for a live beacon with location', () => {
|
||||
const liveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: true }, 'id');
|
||||
const locationEvent = makeBeaconEvent(userId, {
|
||||
beaconInfoId: liveBeacon.getId(),
|
||||
geoUri: 'geo:52,42',
|
||||
// make sure its in live period
|
||||
timestamp: Date.now() + 1,
|
||||
});
|
||||
makeRoomWithBeacons(roomId, client, [liveBeacon], [locationEvent]);
|
||||
|
||||
expect(getShareableLocationEvent(liveBeacon, client)).toBe(locationEvent);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue