Skip to content

add LocationAssetType enum #2214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions spec/unit/location.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
import { makeLocationContent } from "../../src/content-helpers";
import {
ASSET_NODE_TYPE,
ASSET_TYPE_SELF,
LocationAssetType,
LOCATION_EVENT_TYPE,
TIMESTAMP_NODE_TYPE,
} from "../../src/@types/location";
Expand All @@ -33,14 +33,14 @@ describe("Location", function() {
uri: "geo:foo",
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(TIMESTAMP_NODE_TYPE.findIn(loc)).toEqual(134235435);
});

it("should create a valid location with explicit properties", function() {
const loc = makeLocationContent(
"txxt", "geo:bar", 134235436, "desc", "m.something");
"txxt", "geo:bar", 134235436, "desc", LocationAssetType.Pin);

expect(loc.body).toEqual("txxt");
expect(loc.msgtype).toEqual("m.location");
Expand All @@ -49,7 +49,7 @@ describe("Location", function() {
uri: "geo:bar",
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(TIMESTAMP_NODE_TYPE.findIn(loc)).toEqual(134235436);
});
Expand Down
7 changes: 5 additions & 2 deletions src/@types/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ASSET_TYPE_SELF = "m.self";
export enum LocationAssetType {
Self = "m.self",
Pin = "m.pin",
}

/* From the spec at:
* https://github.com/matrix-org/matrix-doc/blob/matthew/location/proposals/3488-location.md
Expand Down Expand Up @@ -60,7 +63,7 @@ export interface ILocationContent extends IContent {
description?: string;
};
[ASSET_NODE_TYPE.name]: {
type: string;
type: LocationAssetType;
};
[TEXT_NODE_TYPE.name]: string;
[TIMESTAMP_NODE_TYPE.name]: number;
Expand Down
6 changes: 3 additions & 3 deletions src/content-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { MsgType } from "./@types/event";
import { TEXT_NODE_TYPE } from "./@types/extensible_events";
import {
ASSET_NODE_TYPE,
ASSET_TYPE_SELF,
ILocationContent,
LocationAssetType,
LOCATION_EVENT_TYPE,
TIMESTAMP_NODE_TYPE,
} from "./@types/location";
Expand Down Expand Up @@ -121,7 +121,7 @@ export function makeLocationContent(
uri: string,
ts: number,
description?: string,
assetType?: string,
assetType?: LocationAssetType,
): ILocationContent {
return {
"body": text,
Expand All @@ -132,7 +132,7 @@ export function makeLocationContent(
description,
},
[ASSET_NODE_TYPE.name]: {
type: assetType ?? ASSET_TYPE_SELF,
type: assetType ?? LocationAssetType.Self,
},
[TEXT_NODE_TYPE.name]: text,
[TIMESTAMP_NODE_TYPE.name]: ts,
Expand Down