mirror of
https://github.com/element-hq/element-web.git
synced 2024-11-30 07:53:31 +03:00
LLS: Remove beacon info illegal replace relation (#8390)
* dont apply illegal replace relation to beacon_info event Signed-off-by: Kerry Archibald <kerrya@element.io> * only display tiles for beacon infos with live prop Signed-off-by: Kerry Archibald <kerrya@element.io> * copyrights Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
763edb7ab9
commit
a3a7c60dd7
5 changed files with 72 additions and 37 deletions
|
@ -19,7 +19,6 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||||
import { EventType, MsgType, RelationType } from "matrix-js-sdk/src/@types/event";
|
import { EventType, MsgType, RelationType } from "matrix-js-sdk/src/@types/event";
|
||||||
import { M_POLL_START, Optional } from "matrix-events-sdk";
|
import { M_POLL_START, Optional } from "matrix-events-sdk";
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
|
|
||||||
|
|
||||||
import EditorStateTransfer from "../utils/EditorStateTransfer";
|
import EditorStateTransfer from "../utils/EditorStateTransfer";
|
||||||
import { RoomPermalinkCreator } from "../utils/permalinks/Permalinks";
|
import { RoomPermalinkCreator } from "../utils/permalinks/Permalinks";
|
||||||
|
@ -44,6 +43,7 @@ import { getMessageModerationState, MessageModerationState } from "../utils/Even
|
||||||
import HiddenBody from "../components/views/messages/HiddenBody";
|
import HiddenBody from "../components/views/messages/HiddenBody";
|
||||||
import SettingsStore from "../settings/SettingsStore";
|
import SettingsStore from "../settings/SettingsStore";
|
||||||
import ViewSourceEvent from "../components/views/messages/ViewSourceEvent";
|
import ViewSourceEvent from "../components/views/messages/ViewSourceEvent";
|
||||||
|
import { shouldDisplayAsBeaconTile } from "../utils/beacon/timeline";
|
||||||
|
|
||||||
// Subset of EventTile's IProps plus some mixins
|
// Subset of EventTile's IProps plus some mixins
|
||||||
export interface EventTileTypeProps {
|
export interface EventTileTypeProps {
|
||||||
|
@ -219,7 +219,9 @@ export function pickFactory(
|
||||||
// Try and pick a state event factory, if we can.
|
// Try and pick a state event factory, if we can.
|
||||||
if (mxEvent.isState()) {
|
if (mxEvent.isState()) {
|
||||||
if (
|
if (
|
||||||
M_BEACON_INFO.matches(evType) &&
|
shouldDisplayAsBeaconTile(mxEvent) &&
|
||||||
|
// settings store access here temporarily during labs
|
||||||
|
// only hit when a beacon_info event is hit
|
||||||
SettingsStore.getValue("feature_location_share_live")
|
SettingsStore.getValue("feature_location_share_live")
|
||||||
) {
|
) {
|
||||||
return MessageEventFactory;
|
return MessageEventFactory;
|
||||||
|
|
|
@ -20,7 +20,6 @@ import {
|
||||||
BeaconIdentifier,
|
BeaconIdentifier,
|
||||||
BeaconEvent,
|
BeaconEvent,
|
||||||
MatrixEvent,
|
MatrixEvent,
|
||||||
RelationType,
|
|
||||||
Room,
|
Room,
|
||||||
RoomMember,
|
RoomMember,
|
||||||
RoomState,
|
RoomState,
|
||||||
|
@ -449,20 +448,12 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
||||||
...update,
|
...update,
|
||||||
};
|
};
|
||||||
|
|
||||||
const newContent = makeBeaconInfoContent(timeout,
|
const updateContent = makeBeaconInfoContent(timeout,
|
||||||
live,
|
live,
|
||||||
description,
|
description,
|
||||||
assetType,
|
assetType,
|
||||||
timestamp,
|
timestamp,
|
||||||
);
|
);
|
||||||
const updateContent = {
|
|
||||||
...newContent,
|
|
||||||
"m.new_content": newContent,
|
|
||||||
"m.relates_to": {
|
|
||||||
"rel_type": RelationType.Replace,
|
|
||||||
"event_id": beacon.beaconInfoId,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
await this.matrixClient.unstable_setLiveBeacon(beacon.roomId, updateContent);
|
await this.matrixClient.unstable_setLiveBeacon(beacon.roomId, updateContent);
|
||||||
};
|
};
|
||||||
|
|
27
src/utils/beacon/timeline.ts
Normal file
27
src/utils/beacon/timeline.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020 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 { MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||||
|
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* beacon_info events without live property set to true
|
||||||
|
* should be displayed in the timeline
|
||||||
|
*/
|
||||||
|
export const shouldDisplayAsBeaconTile = (event: MatrixEvent): boolean => (
|
||||||
|
M_BEACON_INFO.matches(event.getType()) &&
|
||||||
|
!!event.getContent()?.live
|
||||||
|
);
|
|
@ -20,7 +20,6 @@ import {
|
||||||
BeaconEvent,
|
BeaconEvent,
|
||||||
getBeaconInfoIdentifier,
|
getBeaconInfoIdentifier,
|
||||||
MatrixEvent,
|
MatrixEvent,
|
||||||
RelationType,
|
|
||||||
RoomStateEvent,
|
RoomStateEvent,
|
||||||
RoomMember,
|
RoomMember,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
|
@ -473,14 +472,6 @@ describe('OwnBeaconStore', () => {
|
||||||
const expectedUpdateContent = {
|
const expectedUpdateContent = {
|
||||||
...prevEventContent,
|
...prevEventContent,
|
||||||
live: false,
|
live: false,
|
||||||
["m.new_content"]: {
|
|
||||||
...prevEventContent,
|
|
||||||
live: false,
|
|
||||||
},
|
|
||||||
["m.relates_to"]: {
|
|
||||||
event_id: alicesRoom1BeaconInfo.getId(),
|
|
||||||
rel_type: RelationType.Replace,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalledWith(
|
expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalledWith(
|
||||||
room1Id,
|
room1Id,
|
||||||
|
@ -650,14 +641,6 @@ describe('OwnBeaconStore', () => {
|
||||||
const expectedUpdateContent = {
|
const expectedUpdateContent = {
|
||||||
...prevEventContent,
|
...prevEventContent,
|
||||||
live: false,
|
live: false,
|
||||||
["m.new_content"]: {
|
|
||||||
...prevEventContent,
|
|
||||||
live: false,
|
|
||||||
},
|
|
||||||
["m.relates_to"]: {
|
|
||||||
event_id: alicesRoom1BeaconInfo.getId(),
|
|
||||||
rel_type: RelationType.Replace,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalledWith(
|
expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalledWith(
|
||||||
room1Id,
|
room1Id,
|
||||||
|
@ -683,14 +666,6 @@ describe('OwnBeaconStore', () => {
|
||||||
const expectedUpdateContent = {
|
const expectedUpdateContent = {
|
||||||
...prevEventContent,
|
...prevEventContent,
|
||||||
live: false,
|
live: false,
|
||||||
["m.new_content"]: {
|
|
||||||
...prevEventContent,
|
|
||||||
live: false,
|
|
||||||
},
|
|
||||||
["m.relates_to"]: {
|
|
||||||
event_id: alicesRoom1BeaconInfo.getId(),
|
|
||||||
rel_type: RelationType.Replace,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalledWith(
|
expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalledWith(
|
||||||
room1Id,
|
room1Id,
|
||||||
|
|
40
test/utils/beacon/timeline-test.ts
Normal file
40
test/utils/beacon/timeline-test.ts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020 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 } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
|
import { shouldDisplayAsBeaconTile } from "../../../src/utils/beacon/timeline";
|
||||||
|
import { makeBeaconInfoEvent } from "../../test-utils";
|
||||||
|
|
||||||
|
describe('shouldDisplayAsBeaconTile', () => {
|
||||||
|
const userId = '@user:server';
|
||||||
|
const roomId = '!room:server';
|
||||||
|
const liveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: true });
|
||||||
|
const notLiveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: false });
|
||||||
|
const memberEvent = new MatrixEvent({ type: EventType.RoomMember });
|
||||||
|
|
||||||
|
it('returns true for a beacon with live property set to true', () => {
|
||||||
|
expect(shouldDisplayAsBeaconTile(liveBeacon)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false for a beacon with live property set to false', () => {
|
||||||
|
expect(shouldDisplayAsBeaconTile(notLiveBeacon)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false for a non beacon event', () => {
|
||||||
|
expect(shouldDisplayAsBeaconTile(memberEvent)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue