diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index 3277f215bf..d3c53c8a33 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -32,7 +32,7 @@ import SettingsStore from "../../../settings/SettingsStore"; import ReplyThread from "../elements/ReplyThread"; import {pillifyLinks} from '../../../utils/pillify'; import {IntegrationManagers} from "../../../integrations/IntegrationManagers"; -import {RoomPermalinkCreator} from "../../../utils/permalinks/RoomPermalinkCreator"; +import {isPermalinkHost} from "../../../utils/permalinks/RoomPermalinkCreator"; module.exports = createReactClass({ displayName: 'TextualBody', @@ -251,10 +251,7 @@ 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 (this.props.mxEvent && this.props.mxEvent.getRoom()) { - const permalinks = new RoomPermalinkCreator(this.props.mxEvent.getRoom()); - if (permalinks.isPermalinkHost(host)) return false; - } + if (isPermalinkHost(host)) return false; if (node.textContent.toLowerCase().trim().startsWith(host.toLowerCase())) { // it's a "foo.pl" style link diff --git a/src/utils/permalinks/PermalinkConstructor.js b/src/utils/permalinks/PermalinkConstructor.js index 014bf3e225..47d813390f 100644 --- a/src/utils/permalinks/PermalinkConstructor.js +++ b/src/utils/permalinks/PermalinkConstructor.js @@ -34,4 +34,8 @@ export default class PermalinkConstructor { forUser(userId: string): string { throw new Error("Not implemented"); } + + isPermalinkHost(host: string): boolean { + throw new Error("Not implemented"); + } } diff --git a/src/utils/permalinks/RoomPermalinkCreator.js b/src/utils/permalinks/RoomPermalinkCreator.js index 984b4233ba..7394854c18 100644 --- a/src/utils/permalinks/RoomPermalinkCreator.js +++ b/src/utils/permalinks/RoomPermalinkCreator.js @@ -17,10 +17,7 @@ limitations under the License. import MatrixClientPeg from "../../MatrixClientPeg"; import isIp from "is-ip"; import utils from 'matrix-js-sdk/lib/utils'; -import SpecPermalinkConstructor, { - baseUrl as matrixtoBaseUrl, - host as matrixtoHost -} from "./SpecPermalinkConstructor"; +import SpecPermalinkConstructor from "./SpecPermalinkConstructor"; import PermalinkConstructor from "./PermalinkConstructor"; const SdkConfig = require("../../SdkConfig"); @@ -127,10 +124,6 @@ export class RoomPermalinkCreator { return this._started; } - isPermalinkHost(host: string): boolean { - return host === matrixtoHost; - } - forEvent(eventId) { return getPermalinkConstructor().forEvent(this._roomId, eventId, this._serverCandidates); } @@ -285,6 +278,10 @@ export function makeGroupPermalink(groupId) { return getPermalinkConstructor().forGroup(groupId); } +export function isPermalinkHost(host: string): boolean { + return getPermalinkConstructor().isPermalinkHost(host); +} + function getPermalinkConstructor(): PermalinkConstructor { if (SdkConfig.get()['useRiotToCreatePermalinks']) { // TODO: Return a RiotPermalinkConstructor diff --git a/src/utils/permalinks/SpecPermalinkConstructor.js b/src/utils/permalinks/SpecPermalinkConstructor.js index 6c53bfc5f2..5dd4a5a24e 100644 --- a/src/utils/permalinks/SpecPermalinkConstructor.js +++ b/src/utils/permalinks/SpecPermalinkConstructor.js @@ -43,6 +43,10 @@ export default class SpecPermalinkConstructor extends PermalinkConstructor { return `${baseUrl}/#/${groupId}`; } + isPermalinkHost(testHost: string): boolean { + return testHost === host; + } + encodeServerCandidates(candidates: string[]) { if (!candidates || candidates.length === 0) return ''; return `?via=${candidates.map(c => encodeURIComponent(c)).join("&via=")}`;