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

Iterate type definitions (#2029)

This commit is contained in:
Michael Telatynski
2021-11-19 17:35:09 +00:00
committed by GitHub
parent 1b91cd7037
commit b2d83c1f80
5 changed files with 43 additions and 56 deletions

View File

@@ -75,11 +75,13 @@ import {
IKeyBackupPrepareOpts,
IKeyBackupRestoreOpts,
IKeyBackupRestoreResult,
IKeyBackupRoomSessions,
IKeyBackupSession,
} from "./crypto/keybackup";
import { IIdentityServerProvider } from "./@types/IIdentityServerProvider";
import type Request from "request";
import { MatrixScheduler } from "./scheduler";
import { ICryptoCallbacks, IMinimalEvent, IRoomEvent, IStateEvent, NotificationCountType } from "./matrix";
import { IAuthData, ICryptoCallbacks, IMinimalEvent, IRoomEvent, IStateEvent, NotificationCountType } from "./matrix";
import {
CrossSigningKey,
IAddSecretStorageKeyOpts,
@@ -677,6 +679,14 @@ interface IRoomSummary extends Omit<IPublicRoomsChunkRoom, "canonical_alias" | "
membership?: string;
is_encrypted: boolean;
}
interface IRoomKeysResponse {
sessions: IKeyBackupRoomSessions;
}
interface IRoomsKeysResponse {
rooms: Record<string, IRoomKeysResponse>;
}
/* eslint-enable camelcase */
/**
@@ -724,7 +734,7 @@ export class MatrixClient extends EventEmitter {
protected fallbackICEServerAllowed = false;
protected roomList: RoomList;
protected syncApi: SyncApi;
public pushRules: any; // TODO: Types
public pushRules: IPushRules;
protected syncLeftRoomsPromise: Promise<Room[]>;
protected syncedLeftRooms = false;
protected clientOpts: IStoredClientOpts;
@@ -2719,7 +2729,6 @@ export class MatrixClient extends EventEmitter {
* @return {Promise<object>} Status of restoration with `total` and `imported`
* key counts.
*/
// TODO: Types
public async restoreKeyBackupWithPassword(
password: string,
targetRoomId: string,
@@ -2746,7 +2755,6 @@ export class MatrixClient extends EventEmitter {
* @return {Promise<object>} Status of restoration with `total` and `imported`
* key counts.
*/
// TODO: Types
public async restoreKeyBackupWithSecretStorage(
backupInfo: IKeyBackupInfo,
targetRoomId?: string,
@@ -2783,7 +2791,6 @@ export class MatrixClient extends EventEmitter {
* @return {Promise<object>} Status of restoration with `total` and `imported`
* key counts.
*/
// TODO: Types
public restoreKeyBackupWithRecoveryKey(
recoveryKey: string,
targetRoomId: string,
@@ -2795,7 +2802,6 @@ export class MatrixClient extends EventEmitter {
return this.restoreKeyBackup(privKey, targetRoomId, targetSessionId, backupInfo, opts);
}
// TODO: Types
public async restoreKeyBackupWithCache(
targetRoomId: string,
targetSessionId: string,
@@ -2856,11 +2862,11 @@ export class MatrixClient extends EventEmitter {
const res = await this.http.authedRequest(
undefined, "GET", path.path, path.queryData, undefined,
{ prefix: PREFIX_UNSTABLE },
);
) as IRoomsKeysResponse | IRoomKeysResponse | IKeyBackupSession;
if (res.rooms) {
// TODO: Types
for (const [roomId, roomData] of Object.entries<any>(res.rooms)) {
if ((res as IRoomsKeysResponse).rooms) {
const rooms = (res as IRoomsKeysResponse).rooms;
for (const [roomId, roomData] of Object.entries(rooms)) {
if (!roomData.sessions) continue;
totalKeyCount += Object.keys(roomData.sessions).length;
@@ -2870,9 +2876,10 @@ export class MatrixClient extends EventEmitter {
keys.push(k);
}
}
} else if (res.sessions) {
totalKeyCount = Object.keys(res.sessions).length;
keys = await algorithm.decryptSessions(res.sessions);
} else if ((res as IRoomKeysResponse).sessions) {
const sessions = (res as IRoomKeysResponse).sessions;
totalKeyCount = Object.keys(sessions).length;
keys = await algorithm.decryptSessions(sessions);
for (const k of keys) {
k.room_id = targetRoomId;
}
@@ -2880,7 +2887,7 @@ export class MatrixClient extends EventEmitter {
totalKeyCount = 1;
try {
const [key] = await algorithm.decryptSessions({
[targetSessionId]: res,
[targetSessionId]: res as IKeyBackupSession,
});
key.room_id = targetRoomId;
key.session_id = targetSessionId;
@@ -7510,7 +7517,7 @@ export class MatrixClient extends EventEmitter {
return this.http.authedRequest(undefined, "GET", path, qps, undefined);
}
public uploadDeviceSigningKeys(auth: any, keys?: CrossSigningKeys): Promise<{}> { // TODO: types
public uploadDeviceSigningKeys(auth?: IAuthData, keys?: CrossSigningKeys): Promise<{}> {
const data = Object.assign({}, keys);
if (auth) Object.assign(data, { auth });
return this.http.authedRequest(