1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-05 17:02:07 +03:00

Make ContentRepo a class for easier importing

Exporting it the way we were was causing problems for webpack way down
the line, so we export it differently here to get around that. We also
have to fix all the import references so we import the right thing.
This commit is contained in:
Travis Ralston
2019-12-20 14:06:36 -07:00
parent 1e5e705458
commit 50791e3aa7
6 changed files with 88 additions and 86 deletions

View File

@@ -1,4 +1,4 @@
import * as ContentRepo from "../../src/content-repo"; import {ContentRepo} from "../../src/content-repo";
describe("ContentRepo", function() { describe("ContentRepo", function() {
const baseUrl = "https://my.home.server"; const baseUrl = "https://my.home.server";

View File

@@ -36,7 +36,7 @@ import {createNewMatrixCall} from "./webrtc/call";
import * as utils from './utils'; import * as utils from './utils';
import {sleep} from './utils'; import {sleep} from './utils';
import {MatrixError, PREFIX_MEDIA_R0, PREFIX_UNSTABLE} from "./http-api"; import {MatrixError, PREFIX_MEDIA_R0, PREFIX_UNSTABLE} from "./http-api";
import * as contentRepo from "./content-repo"; import {ContentRepo} from "./content-repo";
import * as ContentHelpers from "./content-helpers"; import * as ContentHelpers from "./content-helpers";
import * as olmlib from "./crypto/olmlib"; import * as olmlib from "./crypto/olmlib";
import {ReEmitter} from './ReEmitter'; import {ReEmitter} from './ReEmitter';
@@ -3132,7 +3132,7 @@ MatrixClient.prototype.setAvatarUrl = function(url, callback) {
*/ */
MatrixClient.prototype.mxcUrlToHttp = MatrixClient.prototype.mxcUrlToHttp =
function(mxcUrl, width, height, resizeMethod, allowDirectLinks) { function(mxcUrl, width, height, resizeMethod, allowDirectLinks) {
return contentRepo.getHttpUriForMxc( return ContentRepo.getHttpUriForMxc(
this.baseUrl, mxcUrl, width, height, resizeMethod, allowDirectLinks, this.baseUrl, mxcUrl, width, height, resizeMethod, allowDirectLinks,
); );
}; };

View File

@@ -20,6 +20,7 @@ limitations under the License.
import * as utils from "./utils"; import * as utils from "./utils";
export class ContentRepo {
/** /**
* Get the HTTP URL for an MXC URI. * Get the HTTP URL for an MXC URI.
* @param {string} baseUrl The base homeserver url which has a content repo. * @param {string} baseUrl The base homeserver url which has a content repo.
@@ -34,7 +35,7 @@ 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, static getHttpUriForMxc(baseUrl, mxc, width, height,
resizeMethod, allowDirectLinks) { resizeMethod, allowDirectLinks) {
if (typeof mxc !== "string" || !mxc) { if (typeof mxc !== "string" || !mxc) {
return ''; return '';
@@ -85,7 +86,7 @@ export function getHttpUriForMxc(baseUrl, mxc, width, height,
* @return {string} The complete URL to the identicon. * @return {string} The complete URL to the identicon.
* @deprecated This is no longer in the specification. * @deprecated This is no longer in the specification.
*/ */
export function getIdenticonUri(baseUrl, identiconString, width, height) { static getIdenticonUri(baseUrl, identiconString, width, height) {
if (!identiconString) { if (!identiconString) {
return null; return null;
} }
@@ -107,3 +108,4 @@ export function getIdenticonUri(baseUrl, identiconString, width, height) {
(utils.keys(params).length === 0 ? "" : (utils.keys(params).length === 0 ? "" :
("?" + utils.encodeParams(params))); ("?" + utils.encodeParams(params)));
} }
}

View File

@@ -44,8 +44,8 @@ export * from "./store/indexeddb";
export * from "./store/session/webstorage"; export * from "./store/session/webstorage";
export * from "./crypto/store/memory-crypto-store"; export * from "./crypto/store/memory-crypto-store";
export * from "./crypto/store/indexeddb-crypto-store"; export * from "./crypto/store/indexeddb-crypto-store";
export * from "./content-repo";
export const ContentHelpers = import("./content-helpers"); export const ContentHelpers = import("./content-helpers");
export const ContentRepo = import("./content-repo");
export { export {
createNewMatrixCall, createNewMatrixCall,
setAudioOutput as setMatrixCallAudioOutput, setAudioOutput as setMatrixCallAudioOutput,

View File

@@ -20,7 +20,7 @@ limitations under the License.
*/ */
import {EventEmitter} from "events"; import {EventEmitter} from "events";
import * as ContentRepo from "../content-repo"; import {ContentRepo} from "../content-repo";
import * as utils from "../utils"; import * as utils from "../utils";
/** /**

View File

@@ -23,7 +23,7 @@ limitations under the License.
import {EventEmitter} from "events"; import {EventEmitter} from "events";
import {EventTimelineSet} from "./event-timeline-set"; import {EventTimelineSet} from "./event-timeline-set";
import {EventTimeline} from "./event-timeline"; import {EventTimeline} from "./event-timeline";
import * as ContentRepo from "../content-repo"; import {ContentRepo} from "../content-repo";
import * as utils from "../utils"; import * as utils from "../utils";
import {EventStatus, MatrixEvent} from "./event"; import {EventStatus, MatrixEvent} from "./event";
import {RoomMember} from "./room-member"; import {RoomMember} from "./room-member";