Move early parts of matrix.to bits into its own class

pull/21833/head
Travis Ralston 2019-09-30 12:37:13 -06:00
parent 64aa6695f5
commit f9d5e89017
4 changed files with 44 additions and 11 deletions

View File

@ -30,9 +30,9 @@ import { _t } from '../../../languageHandler';
import * as ContextualMenu from '../../structures/ContextualMenu';
import SettingsStore from "../../../settings/SettingsStore";
import ReplyThread from "../elements/ReplyThread";
import {host as matrixtoHost} from '../../../utils/permalinks/RoomPermalinkCreator';
import {pillifyLinks} from '../../../utils/pillify';
import {IntegrationManagers} from "../../../integrations/IntegrationManagers";
import {RoomPermalinkCreator} from "../../../utils/permalinks/RoomPermalinkCreator";
module.exports = createReactClass({
displayName: 'TextualBody',
@ -251,7 +251,10 @@ module.exports = createReactClass({
// never preview matrix.to links (if anything we should give a smart
// preview of the room/user they point to: nobody needs to be reminded
// what the matrix.to site looks like).
if (host === matrixtoHost) return false;
if (this.props.mxEvent && this.props.mxEvent.getRoom()) {
const permalinks = new RoomPermalinkCreator(this.props.mxEvent.getRoom());
if (permalinks.isPermalinkHost(host)) return false;
}
if (node.textContent.toLowerCase().trim().startsWith(host.toLowerCase())) {
// it's a "foo.pl" style link

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {baseUrl} from "./utils/permalinks/RoomPermalinkCreator";
import {baseUrl} from "./utils/permalinks/SpecPermalinks";
function matrixLinkify(linkify) {
// Text tokens

View File

@ -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) {

View 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
}