Make more functions private

This commit is contained in:
RMidhunSuresh 2021-11-23 19:31:13 +05:30
parent 2dd050bd90
commit 69e67ad5ac
4 changed files with 13 additions and 14 deletions

View file

@ -42,11 +42,11 @@ export class HomeServerApi {
this._reconnector = reconnector;
}
_url(csPath: string, prefix: string = CS_R0_PREFIX): string {
private _url(csPath: string, prefix: string = CS_R0_PREFIX): string {
return this._homeserver + prefix + csPath;
}
_baseRequest(method: RequestMethod, url: string, queryParams?: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions, accessToken?: string): HomeServerRequest {
private _baseRequest(method: RequestMethod, url: string, queryParams?: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions, accessToken?: string): HomeServerRequest {
const queryString = encodeQueryParams(queryParams);
url = `${url}?${queryString}`;
let log: LogItem | undefined;
@ -98,23 +98,23 @@ export class HomeServerApi {
return hsRequest;
}
_unauthedRequest(method: RequestMethod, url: string, queryParams?: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
private _unauthedRequest(method: RequestMethod, url: string, queryParams?: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
return this._baseRequest(method, url, queryParams, body, options);
}
_authedRequest(method: RequestMethod, url: string, queryParams?: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
private _authedRequest(method: RequestMethod, url: string, queryParams?: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
return this._baseRequest(method, url, queryParams, body, options, this._accessToken);
}
_post(csPath: string, queryParams: Record<string, any>, body: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
private _post(csPath: string, queryParams: Record<string, any>, body: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
return this._authedRequest("POST", this._url(csPath, options?.prefix || CS_R0_PREFIX), queryParams, body, options);
}
_put(csPath: string, queryParams: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
private _put(csPath: string, queryParams: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
return this._authedRequest("PUT", this._url(csPath, options?.prefix || CS_R0_PREFIX), queryParams, body, options);
}
_get(csPath: string, queryParams?: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
private _get(csPath: string, queryParams?: Record<string, any>, body?: Record<string, any>, options?: IRequestOptions): HomeServerRequest {
return this._authedRequest("GET", this._url(csPath, options?.prefix || CS_R0_PREFIX), queryParams, body, options);
}
@ -275,9 +275,8 @@ export function tests() {
request: () => new MockRequest().respond(200, 42),
homeserver: "https://hs.tld",
});
const result = await hsApi
._get("foo", undefined, undefined, undefined)
.response();
// @ts-ignore
const result = await hsApi._get("foo", undefined, undefined, undefined).response();
assert.strictEqual(result, 42);
}
}

View file

@ -49,7 +49,7 @@ export class MediaRepository {
}
}
_parseMxcUrl(url: string): string[] | null {
private _parseMxcUrl(url: string): string[] | null {
const prefix = "mxc://";
if (url.startsWith(prefix)) {
return url.substr(prefix.length).split("/", 2);

View file

@ -93,7 +93,7 @@ export class Reconnector {
}
}
_setState(state: ConnectionStatus): void {
private _setState(state: ConnectionStatus): void {
if (state !== this._state.get()) {
if (state === ConnectionStatus.Waiting) {
this._stateSince = this._createTimeMeasure();
@ -104,7 +104,7 @@ export class Reconnector {
}
}
async _reconnectLoop(hsApi: HomeServerApi): Promise<void> {
private async _reconnectLoop(hsApi: HomeServerApi): Promise<void> {
this._versionsResponse = undefined;
this._retryDelay.reset();

View file

@ -97,7 +97,7 @@ export class RequestScheduler {
this._stopped = false;
}
_hsApiRequest(name: string, args: any[]): Request {
private _hsApiRequest(name: string, args: any[]): Request {
const request = new Request(name, args);
this._doSend(request);
return request;