1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00

add LocationAssetType enum (#2214)

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry
2022-03-03 10:49:16 +01:00
committed by GitHub
parent ac4e504b8d
commit 6bc584ba8b
3 changed files with 12 additions and 9 deletions

View File

@ -17,7 +17,7 @@ limitations under the License.
import { makeLocationContent } from "../../src/content-helpers"; import { makeLocationContent } from "../../src/content-helpers";
import { import {
ASSET_NODE_TYPE, ASSET_NODE_TYPE,
ASSET_TYPE_SELF, LocationAssetType,
LOCATION_EVENT_TYPE, LOCATION_EVENT_TYPE,
TIMESTAMP_NODE_TYPE, TIMESTAMP_NODE_TYPE,
} from "../../src/@types/location"; } from "../../src/@types/location";
@ -33,14 +33,14 @@ describe("Location", function() {
uri: "geo:foo", uri: "geo:foo",
description: undefined, description: undefined,
}); });
expect(ASSET_NODE_TYPE.findIn(loc)).toEqual({ type: ASSET_TYPE_SELF }); expect(ASSET_NODE_TYPE.findIn(loc)).toEqual({ type: LocationAssetType.Self });
expect(TEXT_NODE_TYPE.findIn(loc)).toEqual("txt"); expect(TEXT_NODE_TYPE.findIn(loc)).toEqual("txt");
expect(TIMESTAMP_NODE_TYPE.findIn(loc)).toEqual(134235435); expect(TIMESTAMP_NODE_TYPE.findIn(loc)).toEqual(134235435);
}); });
it("should create a valid location with explicit properties", function() { it("should create a valid location with explicit properties", function() {
const loc = makeLocationContent( const loc = makeLocationContent(
"txxt", "geo:bar", 134235436, "desc", "m.something"); "txxt", "geo:bar", 134235436, "desc", LocationAssetType.Pin);
expect(loc.body).toEqual("txxt"); expect(loc.body).toEqual("txxt");
expect(loc.msgtype).toEqual("m.location"); expect(loc.msgtype).toEqual("m.location");
@ -49,7 +49,7 @@ describe("Location", function() {
uri: "geo:bar", uri: "geo:bar",
description: "desc", description: "desc",
}); });
expect(ASSET_NODE_TYPE.findIn(loc)).toEqual({ type: "m.something" }); expect(ASSET_NODE_TYPE.findIn(loc)).toEqual({ type: LocationAssetType.Pin });
expect(TEXT_NODE_TYPE.findIn(loc)).toEqual("txxt"); expect(TEXT_NODE_TYPE.findIn(loc)).toEqual("txxt");
expect(TIMESTAMP_NODE_TYPE.findIn(loc)).toEqual(134235436); expect(TIMESTAMP_NODE_TYPE.findIn(loc)).toEqual(134235436);
}); });

View File

@ -27,7 +27,10 @@ export const ASSET_NODE_TYPE = new UnstableValue("m.asset", "org.matrix.msc3488.
export const TIMESTAMP_NODE_TYPE = new UnstableValue("m.ts", "org.matrix.msc3488.ts"); export const TIMESTAMP_NODE_TYPE = new UnstableValue("m.ts", "org.matrix.msc3488.ts");
export const ASSET_TYPE_SELF = "m.self"; export enum LocationAssetType {
Self = "m.self",
Pin = "m.pin",
}
/* From the spec at: /* From the spec at:
* https://github.com/matrix-org/matrix-doc/blob/matthew/location/proposals/3488-location.md * https://github.com/matrix-org/matrix-doc/blob/matthew/location/proposals/3488-location.md
@ -60,7 +63,7 @@ export interface ILocationContent extends IContent {
description?: string; description?: string;
}; };
[ASSET_NODE_TYPE.name]: { [ASSET_NODE_TYPE.name]: {
type: string; type: LocationAssetType;
}; };
[TEXT_NODE_TYPE.name]: string; [TEXT_NODE_TYPE.name]: string;
[TIMESTAMP_NODE_TYPE.name]: number; [TIMESTAMP_NODE_TYPE.name]: number;

View File

@ -20,8 +20,8 @@ import { MsgType } from "./@types/event";
import { TEXT_NODE_TYPE } from "./@types/extensible_events"; import { TEXT_NODE_TYPE } from "./@types/extensible_events";
import { import {
ASSET_NODE_TYPE, ASSET_NODE_TYPE,
ASSET_TYPE_SELF,
ILocationContent, ILocationContent,
LocationAssetType,
LOCATION_EVENT_TYPE, LOCATION_EVENT_TYPE,
TIMESTAMP_NODE_TYPE, TIMESTAMP_NODE_TYPE,
} from "./@types/location"; } from "./@types/location";
@ -121,7 +121,7 @@ export function makeLocationContent(
uri: string, uri: string,
ts: number, ts: number,
description?: string, description?: string,
assetType?: string, assetType?: LocationAssetType,
): ILocationContent { ): ILocationContent {
return { return {
"body": text, "body": text,
@ -132,7 +132,7 @@ export function makeLocationContent(
description, description,
}, },
[ASSET_NODE_TYPE.name]: { [ASSET_NODE_TYPE.name]: {
type: assetType ?? ASSET_TYPE_SELF, type: assetType ?? LocationAssetType.Self,
}, },
[TEXT_NODE_TYPE.name]: text, [TEXT_NODE_TYPE.name]: text,
[TIMESTAMP_NODE_TYPE.name]: ts, [TIMESTAMP_NODE_TYPE.name]: ts,