From ff53c2757d85b08126a857cd47ae0fbf7988b4ed Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Sun, 21 Nov 2021 21:28:16 +0530 Subject: [PATCH] Convert HomeServerRequest.js to ts --- src/matrix/net/HomeServerApi.js | 2 +- ...{HomeServerRequest.js => HomeServerRequest.ts} | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) rename src/matrix/net/{HomeServerRequest.js => HomeServerRequest.ts} (92%) diff --git a/src/matrix/net/HomeServerApi.js b/src/matrix/net/HomeServerApi.js index 01f5cb45..fe5e470b 100644 --- a/src/matrix/net/HomeServerApi.js +++ b/src/matrix/net/HomeServerApi.js @@ -16,7 +16,7 @@ limitations under the License. */ import {encodeQueryParams, encodeBody} from "./common"; -import {HomeServerRequest} from "./HomeServerRequest.js"; +import {HomeServerRequest} from "./HomeServerRequest"; const CS_R0_PREFIX = "/_matrix/client/r0"; const DEHYDRATION_PREFIX = "/_matrix/client/unstable/org.matrix.msc2697.v2"; diff --git a/src/matrix/net/HomeServerRequest.js b/src/matrix/net/HomeServerRequest.ts similarity index 92% rename from src/matrix/net/HomeServerRequest.js rename to src/matrix/net/HomeServerRequest.ts index 97728c28..f57fac2a 100644 --- a/src/matrix/net/HomeServerRequest.js +++ b/src/matrix/net/HomeServerRequest.ts @@ -16,9 +16,16 @@ limitations under the License. */ import {HomeServerError, ConnectionError} from "../error.js"; +import type {RequestResult} from "../../platform/web/dom/request/fetch.js"; +import type {LogItem} from "../../logging/LogItem"; export class HomeServerRequest { - constructor(method, url, sourceRequest, log) { + // todo: Shouldn't log be of type ILogItem; but ILogItem does not have finish method + private readonly _log?: LogItem; + private _sourceRequest?: RequestResult; + private readonly _promise: Promise; + + constructor(method:string, url:string, sourceRequest:RequestResult, log?: LogItem) { this._log = log; this._sourceRequest = sourceRequest; this._promise = sourceRequest.response().then(response => { @@ -80,16 +87,16 @@ export class HomeServerRequest { }); } - abort() { + abort(): void { if (this._sourceRequest) { this._log?.set("aborted", true); this._sourceRequest.abort(); // to mark that it was on purpose in above rejection handler - this._sourceRequest = null; + this._sourceRequest = undefined; } } - response() { + response(): Promise { return this._promise; } }