2019-09-30 18:37:13 +00:00
|
|
|
/*
|
2021-01-27 11:46:20 +00:00
|
|
|
Copyright 2019, 2021 The Matrix.org Foundation C.I.C.
|
2019-09-30 18:37:13 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2019-09-30 18:51:17 +00:00
|
|
|
* Interface for classes that actually produce permalinks (strings).
|
|
|
|
* TODO: Convert this to a real TypeScript interface
|
2019-09-30 18:37:13 +00:00
|
|
|
*/
|
2019-09-30 18:51:17 +00:00
|
|
|
export default class PermalinkConstructor {
|
2022-12-16 12:29:59 +00:00
|
|
|
public forEvent(roomId: string, eventId: string, serverCandidates: string[] = []): string {
|
2019-09-30 18:51:17 +00:00
|
|
|
throw new Error("Not implemented");
|
|
|
|
}
|
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public forRoom(roomIdOrAlias: string, serverCandidates: string[] = []): string {
|
2019-09-30 18:51:17 +00:00
|
|
|
throw new Error("Not implemented");
|
2019-09-30 18:37:13 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public forUser(userId: string): string {
|
2019-09-30 18:51:17 +00:00
|
|
|
throw new Error("Not implemented");
|
|
|
|
}
|
2019-09-30 18:53:45 +00:00
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public forEntity(entityId: string): string {
|
2019-10-01 02:37:24 +00:00
|
|
|
throw new Error("Not implemented");
|
|
|
|
}
|
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public isPermalinkHost(host: string): boolean {
|
2019-09-30 18:53:45 +00:00
|
|
|
throw new Error("Not implemented");
|
|
|
|
}
|
2019-09-30 22:03:24 +00:00
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public parsePermalink(fullUrl: string): PermalinkParts {
|
2019-09-30 22:03:24 +00:00
|
|
|
throw new Error("Not implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inspired by/Borrowed with permission from the matrix-bot-sdk:
|
|
|
|
// https://github.com/turt2live/matrix-js-bot-sdk/blob/7c4665c9a25c2c8e0fe4e509f2616505b5b66a1c/src/Permalinks.ts#L1-L6
|
|
|
|
export class PermalinkParts {
|
2022-12-16 12:29:59 +00:00
|
|
|
public constructor(
|
2023-03-06 11:45:37 +00:00
|
|
|
public readonly roomIdOrAlias: string | null,
|
|
|
|
public readonly eventId: string | null,
|
|
|
|
public readonly userId: string | null,
|
|
|
|
public readonly viaServers: string[] | null,
|
2022-12-16 12:29:59 +00:00
|
|
|
) {}
|
|
|
|
|
|
|
|
public static forUser(userId: string): PermalinkParts {
|
2022-10-05 17:44:46 +00:00
|
|
|
return new PermalinkParts(null, null, userId, null);
|
2019-09-30 22:03:24 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public static forRoom(roomIdOrAlias: string, viaServers: string[] = []): PermalinkParts {
|
2022-10-05 17:44:46 +00:00
|
|
|
return new PermalinkParts(roomIdOrAlias, null, null, viaServers);
|
2019-09-30 22:03:24 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public static forEvent(roomId: string, eventId: string, viaServers: string[] = []): PermalinkParts {
|
2022-10-05 17:44:46 +00:00
|
|
|
return new PermalinkParts(roomId, eventId, null, viaServers);
|
2019-09-30 22:03:24 +00:00
|
|
|
}
|
2021-01-27 11:46:20 +00:00
|
|
|
|
2023-03-06 11:45:37 +00:00
|
|
|
public get primaryEntityId(): string | null {
|
2022-03-22 23:07:37 +00:00
|
|
|
return this.roomIdOrAlias || this.userId;
|
2021-01-27 11:46:20 +00:00
|
|
|
}
|
2019-09-30 18:37:13 +00:00
|
|
|
}
|