diff --git a/src/content-helpers.js b/src/content-helpers.ts similarity index 86% rename from src/content-helpers.js rename to src/content-helpers.ts index c82f808c5..061073c5e 100644 --- a/src/content-helpers.js +++ b/src/content-helpers.ts @@ -1,6 +1,6 @@ /* Copyright 2018 New Vector Ltd -Copyright 2019 The Matrix.org Foundation C.I.C. +Copyright 2018 - 2021 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. @@ -23,7 +23,7 @@ limitations under the License. * @param {string} htmlBody the HTML representation of the message * @returns {{msgtype: string, format: string, body: string, formatted_body: string}} */ -export function makeHtmlMessage(body, htmlBody) { +export function makeHtmlMessage(body: string, htmlBody: string) { return { msgtype: "m.text", format: "org.matrix.custom.html", @@ -38,7 +38,7 @@ export function makeHtmlMessage(body, htmlBody) { * @param {string} htmlBody the HTML representation of the notice * @returns {{msgtype: string, format: string, body: string, formatted_body: string}} */ -export function makeHtmlNotice(body, htmlBody) { +export function makeHtmlNotice(body: string, htmlBody: string) { return { msgtype: "m.notice", format: "org.matrix.custom.html", @@ -53,7 +53,7 @@ export function makeHtmlNotice(body, htmlBody) { * @param {string} htmlBody the HTML representation of the emote * @returns {{msgtype: string, format: string, body: string, formatted_body: string}} */ -export function makeHtmlEmote(body, htmlBody) { +export function makeHtmlEmote(body: string, htmlBody: string) { return { msgtype: "m.emote", format: "org.matrix.custom.html", @@ -67,7 +67,7 @@ export function makeHtmlEmote(body, htmlBody) { * @param {string} body the plaintext body of the emote * @returns {{msgtype: string, body: string}} */ -export function makeTextMessage(body) { +export function makeTextMessage(body: string) { return { msgtype: "m.text", body: body, @@ -79,7 +79,7 @@ export function makeTextMessage(body) { * @param {string} body the plaintext body of the notice * @returns {{msgtype: string, body: string}} */ -export function makeNotice(body) { +export function makeNotice(body: string) { return { msgtype: "m.notice", body: body, @@ -91,7 +91,7 @@ export function makeNotice(body) { * @param {string} body the plaintext body of the emote * @returns {{msgtype: string, body: string}} */ -export function makeEmoteMessage(body) { +export function makeEmoteMessage(body: string) { return { msgtype: "m.emote", body: body, diff --git a/src/content-repo.js b/src/content-repo.ts similarity index 79% rename from src/content-repo.js rename to src/content-repo.ts index 1b92d59ae..baa91879b 100644 --- a/src/content-repo.js +++ b/src/content-repo.ts @@ -1,6 +1,5 @@ /* -Copyright 2015, 2016 OpenMarket Ltd -Copyright 2019 The Matrix.org Foundation C.I.C. +Copyright 2015 - 2021 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. @@ -34,8 +33,14 @@ import * as utils from "./utils"; * for such URLs. * @return {string} The complete URL to the content. */ -export function getHttpUriForMxc(baseUrl, mxc, width, height, - resizeMethod, allowDirectLinks) { +export function getHttpUriForMxc( + baseUrl: string, + mxc: string, + width: number, + height: number, + resizeMethod: string, + allowDirectLinks: boolean, +): string { if (typeof mxc !== "string" || !mxc) { return ''; } @@ -51,13 +56,13 @@ export function getHttpUriForMxc(baseUrl, mxc, width, height, const params = {}; if (width) { - params.width = Math.round(width); + params["width"] = Math.round(width); } if (height) { - params.height = Math.round(height); + params["height"] = Math.round(height); } if (resizeMethod) { - params.method = resizeMethod; + params["method"] = resizeMethod; } if (Object.keys(params).length > 0) { // these are thumbnailing params so they probably want the @@ -71,7 +76,7 @@ export function getHttpUriForMxc(baseUrl, mxc, width, height, fragment = serverAndMediaId.substr(fragmentOffset); serverAndMediaId = serverAndMediaId.substr(0, fragmentOffset); } - return baseUrl + prefix + serverAndMediaId + - (Object.keys(params).length === 0 ? "" : - ("?" + utils.encodeParams(params))) + fragment; + + const urlParams = (Object.keys(params).length === 0 ? "" : ("?" + utils.encodeParams(params))); + return baseUrl + prefix + serverAndMediaId + urlParams + fragment; }