1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Apply corrections identified by SonarQube (#2336)

* Apply corrections identified by SonarQube

* Apply corrections identified by SonarQube

* Make type more flexible
This commit is contained in:
Michael Telatynski
2022-05-02 03:23:17 +01:00
committed by GitHub
parent 6137afeb28
commit b896111269
9 changed files with 28 additions and 32 deletions

View File

@@ -249,8 +249,7 @@ export class AutoDiscovery {
// Step 7: Copy any other keys directly into the clientConfig. This is for // Step 7: Copy any other keys directly into the clientConfig. This is for
// things like custom configuration of services. // things like custom configuration of services.
Object.keys(wellknown) Object.keys(wellknown).forEach((k) => {
.map((k) => {
if (k === "m.homeserver" || k === "m.identity_server") { if (k === "m.homeserver" || k === "m.identity_server") {
// Only copy selected parts of the config to avoid overwriting // Only copy selected parts of the config to avoid overwriting
// properties computed by the validation logic above. // properties computed by the validation logic above.

View File

@@ -3415,7 +3415,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
*/ */
public setIgnoredUsers(userIds: string[], callback?: Callback): Promise<{}> { public setIgnoredUsers(userIds: string[], callback?: Callback): Promise<{}> {
const content = { ignored_users: {} }; const content = { ignored_users: {} };
userIds.map((u) => content.ignored_users[u] = {}); userIds.forEach((u) => {
content.ignored_users[u] = {};
});
return this.setAccountData("m.ignored_user_list", content, callback); return this.setAccountData("m.ignored_user_list", content, callback);
} }

View File

@@ -309,10 +309,10 @@ export class DeviceList extends TypedEventEmitter<EmittedEvents, CryptoEventHand
*/ */
private getDevicesFromStore(userIds: string[]): DeviceInfoMap { private getDevicesFromStore(userIds: string[]): DeviceInfoMap {
const stored: DeviceInfoMap = {}; const stored: DeviceInfoMap = {};
userIds.map((u) => { userIds.forEach((u) => {
stored[u] = {}; stored[u] = {};
const devices = this.getStoredDevicesForUser(u) || []; const devices = this.getStoredDevicesForUser(u) || [];
devices.map(function(dev) { devices.forEach(function(dev) {
stored[u][dev.deviceId] = dev; stored[u][dev.deviceId] = dev;
}); });
}); });

View File

@@ -375,9 +375,7 @@ export class BackupManager {
); );
if (device) { if (device) {
sigInfo.device = device; sigInfo.device = device;
sigInfo.deviceTrust = await this.baseApis.checkDeviceTrust( sigInfo.deviceTrust = this.baseApis.checkDeviceTrust(this.baseApis.getUserId(), sigInfo.deviceId);
this.baseApis.getUserId(), sigInfo.deviceId,
);
try { try {
await verifySignature( await verifySignature(
this.baseApis.crypto.olmDevice, this.baseApis.crypto.olmDevice,
@@ -495,7 +493,7 @@ export class BackupManager {
rooms[roomId] = { sessions: {} }; rooms[roomId] = { sessions: {} };
} }
const sessionData = await this.baseApis.crypto.olmDevice.exportInboundGroupSession( const sessionData = this.baseApis.crypto.olmDevice.exportInboundGroupSession(
session.senderKey, session.sessionId, session.sessionData, session.senderKey, session.sessionId, session.sessionData,
); );
sessionData.algorithm = MEGOLM_ALGORITHM; sessionData.algorithm = MEGOLM_ALGORITHM;

View File

@@ -1026,7 +1026,7 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
const decodedBackupKey = new Uint8Array(olmlib.decodeBase64( const decodedBackupKey = new Uint8Array(olmlib.decodeBase64(
fixedBackupKey || sessionBackupKey, fixedBackupKey || sessionBackupKey,
)); ));
await builder.addSessionBackupPrivateKeyToCache(decodedBackupKey); builder.addSessionBackupPrivateKeyToCache(decodedBackupKey);
} else if (this.backupManager.getKeyBackupEnabled()) { } else if (this.backupManager.getKeyBackupEnabled()) {
// key backup is enabled but we don't have a session backup key in SSSS: see if we have one in // key backup is enabled but we don't have a session backup key in SSSS: see if we have one in
// the cache or the user can provide one, and if so, write it to SSSS // the cache or the user can provide one, and if so, write it to SSSS

View File

@@ -796,8 +796,7 @@ export class VerificationRequest<
} }
private setupTimeout(phase: Phase): void { private setupTimeout(phase: Phase): void {
const shouldTimeout = !this.timeoutTimer && !this.observeOnly && const shouldTimeout = !this.timeoutTimer && !this.observeOnly && phase === PHASE_REQUESTED;
phase === PHASE_REQUESTED;
if (shouldTimeout) { if (shouldTimeout) {
this.timeoutTimer = setTimeout(this.cancelOnTimeout, this.timeout); this.timeoutTimer = setTimeout(this.cancelOnTimeout, this.timeout);
@@ -814,15 +813,15 @@ export class VerificationRequest<
} }
} }
private cancelOnTimeout = () => { private cancelOnTimeout = async () => {
try { try {
if (this.initiatedByMe) { if (this.initiatedByMe) {
this.cancel({ await this.cancel({
reason: "Other party didn't accept in time", reason: "Other party didn't accept in time",
code: "m.timeout", code: "m.timeout",
}); });
} else { } else {
this.cancel({ await this.cancel({
reason: "User didn't accept in time", reason: "User didn't accept in time",
code: "m.timeout", code: "m.timeout",
}); });

View File

@@ -1105,7 +1105,7 @@ export class AbortError extends Error {
* @return {any} the result of the network operation * @return {any} the result of the network operation
* @throws {ConnectionError} If after maxAttempts the callback still throws ConnectionError * @throws {ConnectionError} If after maxAttempts the callback still throws ConnectionError
*/ */
export async function retryNetworkOperation<T>(maxAttempts: number, callback: () => T): Promise<T> { export async function retryNetworkOperation<T>(maxAttempts: number, callback: () => Promise<T>): Promise<T> {
let attempts = 0; let attempts = 0;
let lastConnectionError = null; let lastConnectionError = null;
while (attempts < maxAttempts) { while (attempts < maxAttempts) {

View File

@@ -530,9 +530,7 @@ export class LocalIndexedDBStoreBackend implements IIndexedDBBackend {
const txn = this.db.transaction(["client_options"], "readonly"); const txn = this.db.transaction(["client_options"], "readonly");
const store = txn.objectStore("client_options"); const store = txn.objectStore("client_options");
return selectQuery(store, undefined, (cursor) => { return selectQuery(store, undefined, (cursor) => {
if (cursor.value && cursor.value && cursor.value.options) { return cursor.value?.options;
return cursor.value.options;
}
}).then((results) => results[0]); }).then((results) => results[0]);
}); });
} }

View File

@@ -464,7 +464,7 @@ export function defer<T = void>(): IDeferred<T> {
} }
export async function promiseMapSeries<T>( export async function promiseMapSeries<T>(
promises: T[], promises: Array<T | Promise<T>>,
fn: (t: T) => void, fn: (t: T) => void,
): Promise<void> { ): Promise<void> {
for (const o of promises) { for (const o of promises) {