You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
Convert some utils to typescript
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018 New Vector Ltd
|
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");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with 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
|
* @param {string} htmlBody the HTML representation of the message
|
||||||
* @returns {{msgtype: string, format: string, body: string, formatted_body: string}}
|
* @returns {{msgtype: string, format: string, body: string, formatted_body: string}}
|
||||||
*/
|
*/
|
||||||
export function makeHtmlMessage(body, htmlBody) {
|
export function makeHtmlMessage(body: string, htmlBody: string) {
|
||||||
return {
|
return {
|
||||||
msgtype: "m.text",
|
msgtype: "m.text",
|
||||||
format: "org.matrix.custom.html",
|
format: "org.matrix.custom.html",
|
||||||
@@ -38,7 +38,7 @@ export function makeHtmlMessage(body, htmlBody) {
|
|||||||
* @param {string} htmlBody the HTML representation of the notice
|
* @param {string} htmlBody the HTML representation of the notice
|
||||||
* @returns {{msgtype: string, format: string, body: string, formatted_body: string}}
|
* @returns {{msgtype: string, format: string, body: string, formatted_body: string}}
|
||||||
*/
|
*/
|
||||||
export function makeHtmlNotice(body, htmlBody) {
|
export function makeHtmlNotice(body: string, htmlBody: string) {
|
||||||
return {
|
return {
|
||||||
msgtype: "m.notice",
|
msgtype: "m.notice",
|
||||||
format: "org.matrix.custom.html",
|
format: "org.matrix.custom.html",
|
||||||
@@ -53,7 +53,7 @@ export function makeHtmlNotice(body, htmlBody) {
|
|||||||
* @param {string} htmlBody the HTML representation of the emote
|
* @param {string} htmlBody the HTML representation of the emote
|
||||||
* @returns {{msgtype: string, format: string, body: string, formatted_body: string}}
|
* @returns {{msgtype: string, format: string, body: string, formatted_body: string}}
|
||||||
*/
|
*/
|
||||||
export function makeHtmlEmote(body, htmlBody) {
|
export function makeHtmlEmote(body: string, htmlBody: string) {
|
||||||
return {
|
return {
|
||||||
msgtype: "m.emote",
|
msgtype: "m.emote",
|
||||||
format: "org.matrix.custom.html",
|
format: "org.matrix.custom.html",
|
||||||
@@ -67,7 +67,7 @@ export function makeHtmlEmote(body, htmlBody) {
|
|||||||
* @param {string} body the plaintext body of the emote
|
* @param {string} body the plaintext body of the emote
|
||||||
* @returns {{msgtype: string, body: string}}
|
* @returns {{msgtype: string, body: string}}
|
||||||
*/
|
*/
|
||||||
export function makeTextMessage(body) {
|
export function makeTextMessage(body: string) {
|
||||||
return {
|
return {
|
||||||
msgtype: "m.text",
|
msgtype: "m.text",
|
||||||
body: body,
|
body: body,
|
||||||
@@ -79,7 +79,7 @@ export function makeTextMessage(body) {
|
|||||||
* @param {string} body the plaintext body of the notice
|
* @param {string} body the plaintext body of the notice
|
||||||
* @returns {{msgtype: string, body: string}}
|
* @returns {{msgtype: string, body: string}}
|
||||||
*/
|
*/
|
||||||
export function makeNotice(body) {
|
export function makeNotice(body: string) {
|
||||||
return {
|
return {
|
||||||
msgtype: "m.notice",
|
msgtype: "m.notice",
|
||||||
body: body,
|
body: body,
|
||||||
@@ -91,7 +91,7 @@ export function makeNotice(body) {
|
|||||||
* @param {string} body the plaintext body of the emote
|
* @param {string} body the plaintext body of the emote
|
||||||
* @returns {{msgtype: string, body: string}}
|
* @returns {{msgtype: string, body: string}}
|
||||||
*/
|
*/
|
||||||
export function makeEmoteMessage(body) {
|
export function makeEmoteMessage(body: string) {
|
||||||
return {
|
return {
|
||||||
msgtype: "m.emote",
|
msgtype: "m.emote",
|
||||||
body: body,
|
body: body,
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2015, 2016 OpenMarket Ltd
|
Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
|
||||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with 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.
|
* for such URLs.
|
||||||
* @return {string} The complete URL to the content.
|
* @return {string} The complete URL to the content.
|
||||||
*/
|
*/
|
||||||
export function getHttpUriForMxc(baseUrl, mxc, width, height,
|
export function getHttpUriForMxc(
|
||||||
resizeMethod, allowDirectLinks) {
|
baseUrl: string,
|
||||||
|
mxc: string,
|
||||||
|
width: number,
|
||||||
|
height: number,
|
||||||
|
resizeMethod: string,
|
||||||
|
allowDirectLinks: boolean,
|
||||||
|
): string {
|
||||||
if (typeof mxc !== "string" || !mxc) {
|
if (typeof mxc !== "string" || !mxc) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@@ -51,13 +56,13 @@ export function getHttpUriForMxc(baseUrl, mxc, width, height,
|
|||||||
const params = {};
|
const params = {};
|
||||||
|
|
||||||
if (width) {
|
if (width) {
|
||||||
params.width = Math.round(width);
|
params["width"] = Math.round(width);
|
||||||
}
|
}
|
||||||
if (height) {
|
if (height) {
|
||||||
params.height = Math.round(height);
|
params["height"] = Math.round(height);
|
||||||
}
|
}
|
||||||
if (resizeMethod) {
|
if (resizeMethod) {
|
||||||
params.method = resizeMethod;
|
params["method"] = resizeMethod;
|
||||||
}
|
}
|
||||||
if (Object.keys(params).length > 0) {
|
if (Object.keys(params).length > 0) {
|
||||||
// these are thumbnailing params so they probably want the
|
// these are thumbnailing params so they probably want the
|
||||||
@@ -71,7 +76,7 @@ export function getHttpUriForMxc(baseUrl, mxc, width, height,
|
|||||||
fragment = serverAndMediaId.substr(fragmentOffset);
|
fragment = serverAndMediaId.substr(fragmentOffset);
|
||||||
serverAndMediaId = serverAndMediaId.substr(0, fragmentOffset);
|
serverAndMediaId = serverAndMediaId.substr(0, fragmentOffset);
|
||||||
}
|
}
|
||||||
return baseUrl + prefix + serverAndMediaId +
|
|
||||||
(Object.keys(params).length === 0 ? "" :
|
const urlParams = (Object.keys(params).length === 0 ? "" : ("?" + utils.encodeParams(params)));
|
||||||
("?" + utils.encodeParams(params))) + fragment;
|
return baseUrl + prefix + serverAndMediaId + urlParams + fragment;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user