Move early parts of matrix.to bits into its own class
This commit is contained in:
parent
64aa6695f5
commit
f9d5e89017
4 changed files with 44 additions and 11 deletions
|
@ -17,9 +17,7 @@ limitations under the License.
|
|||
import MatrixClientPeg from "../../MatrixClientPeg";
|
||||
import isIp from "is-ip";
|
||||
import utils from 'matrix-js-sdk/lib/utils';
|
||||
|
||||
export const host = "matrix.to";
|
||||
export const baseUrl = `https://${host}`;
|
||||
import {host as matrixtoHost, baseUrl as matrixtoBaseUrl} from "SpecPermalinks";
|
||||
|
||||
// The maximum number of servers to pick when working out which servers
|
||||
// to add to permalinks. The servers are appended as ?via=example.org
|
||||
|
@ -123,15 +121,19 @@ export class RoomPermalinkCreator {
|
|||
return this._started;
|
||||
}
|
||||
|
||||
isPermalinkHost(host: string): boolean {
|
||||
return host === matrixtoHost;
|
||||
}
|
||||
|
||||
forEvent(eventId) {
|
||||
const roomId = this._roomId;
|
||||
const permalinkBase = `${baseUrl}/#/${roomId}/${eventId}`;
|
||||
const permalinkBase = `${matrixtoBaseUrl}/#/${roomId}/${eventId}`;
|
||||
return `${permalinkBase}${encodeServerCandidates(this._serverCandidates)}`;
|
||||
}
|
||||
|
||||
forRoom() {
|
||||
const roomId = this._roomId;
|
||||
const permalinkBase = `${baseUrl}/#/${roomId}`;
|
||||
const permalinkBase = `${matrixtoBaseUrl}/#/${roomId}`;
|
||||
return `${permalinkBase}${encodeServerCandidates(this._serverCandidates)}`;
|
||||
}
|
||||
|
||||
|
@ -255,11 +257,11 @@ export class RoomPermalinkCreator {
|
|||
}
|
||||
|
||||
export function makeUserPermalink(userId) {
|
||||
return `${baseUrl}/#/${userId}`;
|
||||
return `${matrixtoBaseUrl}/#/${userId}`;
|
||||
}
|
||||
|
||||
export function makeRoomPermalink(roomId) {
|
||||
const permalinkBase = `${baseUrl}/#/${roomId}`;
|
||||
const permalinkBase = `${matrixtoBaseUrl}/#/${roomId}`;
|
||||
|
||||
if (!roomId) {
|
||||
throw new Error("can't permalink a falsey roomId");
|
||||
|
@ -280,7 +282,7 @@ export function makeRoomPermalink(roomId) {
|
|||
}
|
||||
|
||||
export function makeGroupPermalink(groupId) {
|
||||
return `${baseUrl}/#/${groupId}`;
|
||||
return `${matrixtoBaseUrl}/#/${groupId}`;
|
||||
}
|
||||
|
||||
export function encodeServerCandidates(candidates) {
|
||||
|
|
28
src/utils/permalinks/SpecPermalinks.js
Normal file
28
src/utils/permalinks/SpecPermalinks.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
export const host = "matrix.to";
|
||||
export const baseUrl = `https://${host}`;
|
||||
|
||||
/**
|
||||
* Generates matrix.to permalinks
|
||||
*/
|
||||
export default class SpecPermalinks {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
// TODO: The class
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue