2020-10-12 16:23:07 +02:00
|
|
|
export class RoomIdentifier {
|
2020-10-14 10:37:00 +02:00
|
|
|
public readonly anonymous: boolean;
|
|
|
|
public readonly id:string
|
|
|
|
public readonly organizationSlug: string|undefined;
|
|
|
|
public readonly worldSlug: string|undefined;
|
|
|
|
public readonly roomSlug: string|undefined;
|
2020-10-12 16:23:07 +02:00
|
|
|
constructor(roomID: string) {
|
2020-10-13 15:55:30 +02:00
|
|
|
if (roomID.startsWith('_/')) {
|
2020-10-12 16:23:07 +02:00
|
|
|
this.anonymous = true;
|
2020-10-13 15:55:30 +02:00
|
|
|
} else if(roomID.startsWith('@/')) {
|
2020-10-12 16:23:07 +02:00
|
|
|
this.anonymous = false;
|
2020-10-14 10:37:00 +02:00
|
|
|
|
|
|
|
const match = /@\/([^/]+)\/([^/]+)\/(.+)/.exec(roomID);
|
|
|
|
if (!match) {
|
|
|
|
throw new Error('Could not extract info from "'+roomID+'"');
|
|
|
|
}
|
|
|
|
this.organizationSlug = match[1];
|
|
|
|
this.worldSlug = match[2];
|
|
|
|
this.roomSlug = match[3];
|
2020-10-12 16:23:07 +02:00
|
|
|
} else {
|
|
|
|
throw new Error('Incorrect room ID: '+roomID);
|
|
|
|
}
|
2020-10-14 10:37:00 +02:00
|
|
|
this.id = roomID;
|
2020-10-12 16:23:07 +02:00
|
|
|
}
|
2020-10-14 10:37:00 +02:00
|
|
|
}
|