From 44d446be890222c8897cb7b06ed5292d297451b6 Mon Sep 17 00:00:00 2001 From: Kerry Date: Mon, 11 Apr 2022 10:28:43 +0200 Subject: [PATCH] Live location sharing - set replaces relation when stopping beacon (#8266) * set replaces relation on stopping beacon Signed-off-by: Kerry Archibald * update tests for stopBeacon Signed-off-by: Kerry Archibald --- src/stores/OwnBeaconStore.ts | 14 ++++++++++++-- test/stores/OwnBeaconStore-test.ts | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/stores/OwnBeaconStore.ts b/src/stores/OwnBeaconStore.ts index cca428f83e..0bb76afdd4 100644 --- a/src/stores/OwnBeaconStore.ts +++ b/src/stores/OwnBeaconStore.ts @@ -20,6 +20,7 @@ import { BeaconIdentifier, BeaconEvent, MatrixEvent, + RelationType, Room, RoomMember, RoomState, @@ -447,11 +448,20 @@ export class OwnBeaconStore extends AsyncStoreWithClient { ...update, }; - const updateContent = makeBeaconInfoContent(timeout, + const newContent = makeBeaconInfoContent(timeout, live, description, 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); }; diff --git a/test/stores/OwnBeaconStore-test.ts b/test/stores/OwnBeaconStore-test.ts index 6a95c82ad0..b5713f6348 100644 --- a/test/stores/OwnBeaconStore-test.ts +++ b/test/stores/OwnBeaconStore-test.ts @@ -20,6 +20,7 @@ import { BeaconEvent, getBeaconInfoIdentifier, MatrixEvent, + RelationType, RoomStateEvent, RoomMember, } from "matrix-js-sdk/src/matrix"; @@ -472,6 +473,14 @@ describe('OwnBeaconStore', () => { const expectedUpdateContent = { ...prevEventContent, live: false, + ["m.new_content"]: { + ...prevEventContent, + live: false, + }, + ["m.relates_to"]: { + event_id: alicesRoom1BeaconInfo.getId(), + rel_type: RelationType.Replace, + }, }; expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalledWith( room1Id, @@ -641,6 +650,14 @@ describe('OwnBeaconStore', () => { const expectedUpdateContent = { ...prevEventContent, live: false, + ["m.new_content"]: { + ...prevEventContent, + live: false, + }, + ["m.relates_to"]: { + event_id: alicesRoom1BeaconInfo.getId(), + rel_type: RelationType.Replace, + }, }; expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalledWith( room1Id, @@ -666,6 +683,14 @@ describe('OwnBeaconStore', () => { const expectedUpdateContent = { ...prevEventContent, live: false, + ["m.new_content"]: { + ...prevEventContent, + live: false, + }, + ["m.relates_to"]: { + event_id: alicesRoom1BeaconInfo.getId(), + rel_type: RelationType.Replace, + }, }; expect(mockClient.unstable_setLiveBeacon).toHaveBeenCalledWith( room1Id,