Skip to content

Commit

Permalink
add m.beacon_info.live from msc3672
Browse files Browse the repository at this point in the history
Signed-off-by: Kerry Archibald <kerrya@element.io>
  • Loading branch information
Kerry Archibald committed Mar 11, 2022
1 parent ec2c472 commit 9367c6f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/unit/content-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ describe('Beacon content helpers', () => {
it('create fully defined event content', () => {
expect(makeBeaconInfoContent(
1234,
true,
'nice beacon_info',
LocationAssetType.Pin,
)).toEqual({
[M_BEACON_INFO.name]: {
description: 'nice beacon_info',
timeout: 1234,
live: true,
},
[M_TIMESTAMP.name]: mockDateNow,
[M_ASSET.name]: {
Expand All @@ -49,6 +51,7 @@ describe('Beacon content helpers', () => {
it('defaults timestamp to current time', () => {
expect(makeBeaconInfoContent(
1234,
true,
'nice beacon_info',
LocationAssetType.Pin,
)).toEqual(expect.objectContaining({
Expand All @@ -59,6 +62,7 @@ describe('Beacon content helpers', () => {
it('defaults asset type to self when not set', () => {
expect(makeBeaconInfoContent(
1234,
true,
'nice beacon_info',
// no assetType passed
)).toEqual(expect.objectContaining({
Expand Down
3 changes: 3 additions & 0 deletions src/@types/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export type MBeaconInfoContent = {
description?: string;
// how long from the last event until we consider the beacon inactive in milliseconds
timeout: number;
// true when this is a live location beacon
// https://github.com/matrix-org/matrix-spec-proposals/pull/3672
live?: boolean;
};

export type MBeaconInfoEvent = EitherAnd<
Expand Down
2 changes: 2 additions & 0 deletions src/content-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,14 @@ export const parseLocationEvent = (wireEventContent: LocationEventWireContent):

export const makeBeaconInfoContent = (
timeout: number,
isLive?: boolean,
description?: string,
assetType?: LocationAssetType,
): MBeaconInfoEventContent => ({
[M_BEACON_INFO.name]: {
description,
timeout,
live: isLive,
},
[M_TIMESTAMP.name]: Date.now(),
[M_ASSET.name]: {
Expand Down

0 comments on commit 9367c6f

Please sign in to comment.