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

Another SonarQube happiness pass (#2347)

This commit is contained in:
Michael Telatynski
2022-05-05 04:34:21 +01:00
committed by GitHub
parent a388fde3e2
commit dea3f52fe9
9 changed files with 26 additions and 30 deletions

View File

@@ -1296,9 +1296,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* Get the current dehydrated device, if any * Get the current dehydrated device, if any
* @return {Promise} A promise of an object containing the dehydrated device * @return {Promise} A promise of an object containing the dehydrated device
*/ */
public getDehydratedDevice(): Promise<IDehydratedDevice> { public async getDehydratedDevice(): Promise<IDehydratedDevice> {
try { try {
return this.http.authedRequest<IDehydratedDevice>( return await this.http.authedRequest<IDehydratedDevice>(
undefined, undefined,
Method.Get, Method.Get,
"/dehydrated_device", "/dehydrated_device",
@@ -3365,7 +3365,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* data event. * data event.
* @return {module:http-api.MatrixError} Rejects: with an error response. * @return {module:http-api.MatrixError} Rejects: with an error response.
*/ */
public getAccountDataFromServer<T extends {[k: string]: any}>(eventType: string): Promise<T> { public async getAccountDataFromServer<T extends {[k: string]: any}>(eventType: string): Promise<T> {
if (this.isInitialSyncComplete()) { if (this.isInitialSyncComplete()) {
const event = this.store.getAccountData(eventType); const event = this.store.getAccountData(eventType);
if (!event) { if (!event) {
@@ -3380,11 +3380,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
$type: eventType, $type: eventType,
}); });
try { try {
return this.http.authedRequest( return await this.http.authedRequest(undefined, Method.Get, path);
undefined, Method.Get, path, undefined,
);
} catch (e) { } catch (e) {
if (e.data && e.data.errcode === 'M_NOT_FOUND') { if (e.data?.errcode === 'M_NOT_FOUND') {
return null; return null;
} }
throw e; throw e;
@@ -4851,7 +4849,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
} }
} }
const populationResults: Record<string, Error> = {}; // {roomId: Error} const populationResults: { [roomId: string]: Error } = {};
const promises = []; const promises = [];
const doLeave = (roomId: string) => { const doLeave = (roomId: string) => {
@@ -5875,7 +5873,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
*/ */
public setRoomMutePushRule(scope: string, roomId: string, mute: boolean): Promise<void> | void { public setRoomMutePushRule(scope: string, roomId: string, mute: boolean): Promise<void> | void {
let promise: Promise<void>; let promise: Promise<void>;
let hasDontNotifyRule; let hasDontNotifyRule = false;
// Get the existing room-kind push rule if any // Get the existing room-kind push rule if any
const roomPushRule = this.getRoomPushRule(scope, roomId); const roomPushRule = this.getRoomPushRule(scope, roomId);
@@ -5928,7 +5926,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
}); });
}).catch((err: Error) => { }).catch((err: Error) => {
// Update it even if the previous operation fails. This can help the // Update it even if the previous operation fails. This can help the
// app to recover when push settings has been modifed from another client // app to recover when push settings has been modified from another client
this.getPushRules().then((result) => { this.getPushRules().then((result) => {
this.pushRules = result; this.pushRules = result;
reject(err); reject(err);

View File

@@ -122,7 +122,7 @@ export class DeviceList extends TypedEventEmitter<EmittedEvents, CryptoEventHand
'readonly', [IndexedDBCryptoStore.STORE_DEVICE_DATA], (txn) => { 'readonly', [IndexedDBCryptoStore.STORE_DEVICE_DATA], (txn) => {
this.cryptoStore.getEndToEndDeviceData(txn, (deviceData) => { this.cryptoStore.getEndToEndDeviceData(txn, (deviceData) => {
this.hasFetched = Boolean(deviceData && deviceData.devices); this.hasFetched = Boolean(deviceData && deviceData.devices);
this.devices = deviceData ? deviceData.devices : {}, this.devices = deviceData ? deviceData.devices : {};
this.crossSigningInfo = deviceData ? this.crossSigningInfo = deviceData ?
deviceData.crossSigningInfo || {} : {}; deviceData.crossSigningInfo || {} : {};
this.deviceTrackingStatus = deviceData ? this.deviceTrackingStatus = deviceData ?
@@ -190,7 +190,7 @@ export class DeviceList extends TypedEventEmitter<EmittedEvents, CryptoEventHand
let savePromise = this.savePromise; let savePromise = this.savePromise;
if (savePromise === null) { if (savePromise === null) {
savePromise = new Promise((resolve, reject) => { savePromise = new Promise((resolve) => {
this.resolveSavePromise = resolve; this.resolveSavePromise = resolve;
}); });
this.savePromise = savePromise; this.savePromise = savePromise;

View File

@@ -271,9 +271,9 @@ export class SAS extends Base<SasEvent, EventHandlerMap> {
do { do {
try { try {
if (this.initiatedByMe) { if (this.initiatedByMe) {
return this.doSendVerification(); return await this.doSendVerification();
} else { } else {
return this.doRespondVerification(); return await this.doRespondVerification();
} }
} catch (err) { } catch (err) {
if (err instanceof SwitchStartEventError) { if (err instanceof SwitchStartEventError) {

View File

@@ -152,7 +152,7 @@ export interface ICryptoCallbacks {
export function createClient(opts: ICreateClientOpts | string) { export function createClient(opts: ICreateClientOpts | string) {
if (typeof opts === "string") { if (typeof opts === "string") {
opts = { opts = {
"baseUrl": opts as string, "baseUrl": opts,
}; };
} }
opts.request = opts.request || requestInstance; opts.request = opts.request || requestInstance;

View File

@@ -28,7 +28,6 @@ import { EventType, RelationType } from "../@types/event";
import { RoomState } from "./room-state"; import { RoomState } from "./room-state";
import { TypedEventEmitter } from "./typed-event-emitter"; import { TypedEventEmitter } from "./typed-event-emitter";
// var DEBUG = false;
const DEBUG = true; const DEBUG = true;
let debuglog: (...args: any[]) => void; let debuglog: (...args: any[]) => void;

View File

@@ -26,10 +26,9 @@ import { MatrixEvent, MatrixEventEvent } from "./event";
import { MatrixClient } from "../client"; import { MatrixClient } from "../client";
import { GuestAccess, HistoryVisibility, IJoinRuleEventContent, JoinRule } from "../@types/partials"; import { GuestAccess, HistoryVisibility, IJoinRuleEventContent, JoinRule } from "../@types/partials";
import { TypedEventEmitter } from "./typed-event-emitter"; import { TypedEventEmitter } from "./typed-event-emitter";
import { Beacon, BeaconEvent, BeaconEventHandlerMap } from "./beacon"; import { Beacon, BeaconEvent, BeaconEventHandlerMap, getBeaconInfoIdentifier, BeaconIdentifier } from "./beacon";
import { TypedReEmitter } from "../ReEmitter"; import { TypedReEmitter } from "../ReEmitter";
import { M_BEACON, M_BEACON_INFO } from "../@types/beacon"; import { M_BEACON, M_BEACON_INFO } from "../@types/beacon";
import { getBeaconInfoIdentifier, BeaconIdentifier } from "./beacon";
// possible statuses for out-of-band member loading // possible statuses for out-of-band member loading
enum OobStatus { enum OobStatus {

View File

@@ -1124,14 +1124,14 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
* The aliases returned by this function may not necessarily * The aliases returned by this function may not necessarily
* still point to this room. * still point to this room.
* @return {array} The room's alias as an array of strings * @return {array} The room's alias as an array of strings
* @deprecated this uses m.room.aliases events, replaced by Room::getAltAliases()
*/ */
public getAliases(): string[] { public getAliases(): string[] {
const aliasStrings: string[] = []; const aliasStrings: string[] = [];
const aliasEvents = this.currentState.getStateEvents(EventType.RoomAliases); const aliasEvents = this.currentState.getStateEvents(EventType.RoomAliases);
if (aliasEvents) { if (aliasEvents) {
for (let i = 0; i < aliasEvents.length; ++i) { for (const aliasEvent of aliasEvents) {
const aliasEvent = aliasEvents[i];
if (Array.isArray(aliasEvent.getContent().aliases)) { if (Array.isArray(aliasEvent.getContent().aliases)) {
const filteredAliases = aliasEvent.getContent<{ aliases: string[] }>().aliases.filter(a => { const filteredAliases = aliasEvent.getContent<{ aliases: string[] }>().aliases.filter(a => {
if (typeof(a) !== "string") return false; if (typeof(a) !== "string") return false;
@@ -1141,7 +1141,7 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
// It's probably valid by here. // It's probably valid by here.
return true; return true;
}); });
Array.prototype.push.apply(aliasStrings, filteredAliases); aliasStrings.push(...filteredAliases);
} }
} }
} }
@@ -1644,8 +1644,8 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
eventsByThread[threadId]?.push(event); eventsByThread[threadId]?.push(event);
} }
Object.entries(eventsByThread).map(([threadId, events]) => ( Object.entries(eventsByThread).map(([threadId, threadEvents]) => (
this.addThreadedEvents(threadId, events, toStartOfTimeline) this.addThreadedEvents(threadId, threadEvents, toStartOfTimeline)
)); ));
} }
@@ -2143,23 +2143,23 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
const threadRoots = this.findThreadRoots(events); const threadRoots = this.findThreadRoots(events);
const eventsByThread: { [threadId: string]: MatrixEvent[] } = {}; const eventsByThread: { [threadId: string]: MatrixEvent[] } = {};
for (let i = 0; i < events.length; i++) { for (const event of events) {
// TODO: We should have a filter to say "only add state event types X Y Z to the timeline". // TODO: We should have a filter to say "only add state event types X Y Z to the timeline".
this.processLiveEvent(events[i]); this.processLiveEvent(event);
const { const {
shouldLiveInRoom, shouldLiveInRoom,
shouldLiveInThread, shouldLiveInThread,
threadId, threadId,
} = this.eventShouldLiveIn(events[i], events, threadRoots); } = this.eventShouldLiveIn(event, events, threadRoots);
if (shouldLiveInThread && !eventsByThread[threadId]) { if (shouldLiveInThread && !eventsByThread[threadId]) {
eventsByThread[threadId] = []; eventsByThread[threadId] = [];
} }
eventsByThread[threadId]?.push(events[i]); eventsByThread[threadId]?.push(event);
if (shouldLiveInRoom) { if (shouldLiveInRoom) {
this.addLiveEvent(events[i], duplicateStrategy, fromCache); this.addLiveEvent(event, duplicateStrategy, fromCache);
} }
} }

View File

@@ -37,7 +37,7 @@ export interface ISavedSync {
export interface IStore { export interface IStore {
readonly accountData: Record<string, MatrixEvent>; // type : content readonly accountData: Record<string, MatrixEvent>; // type : content
/** @return {Promise<bool>} whether or not the database was newly created in this session. */ /** @return {Promise<boolean>} whether or not the database was newly created in this session. */
isNewlyCreated(): Promise<boolean>; isNewlyCreated(): Promise<boolean>;
/** /**

View File

@@ -123,7 +123,7 @@ export class StubStore implements IStore {
/** /**
* No-op. * No-op.
* @param {Room} room * @param {Room} room
* @param {integer} limit * @param {number} limit
* @return {Array} * @return {Array}
*/ */
public scrollback(room: Room, limit: number): MatrixEvent[] { public scrollback(room: Room, limit: number): MatrixEvent[] {