You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-05 00:42:10 +03:00
Make SonarCloud happier (#2850)
* Make SonarCloud happier * Revert one change due to lack of strict mode upstream * Fix typo
This commit is contained in:
committed by
GitHub
parent
52932f59ab
commit
6c543382e6
@@ -169,8 +169,8 @@ export interface IPusher {
|
||||
lang: string;
|
||||
profile_tag?: string;
|
||||
pushkey: string;
|
||||
enabled?: boolean | null | undefined;
|
||||
"org.matrix.msc3881.enabled"?: boolean | null | undefined;
|
||||
enabled?: boolean | null;
|
||||
"org.matrix.msc3881.enabled"?: boolean | null;
|
||||
device_id?: string | null;
|
||||
"org.matrix.msc3881.device_id"?: string | null;
|
||||
}
|
||||
|
@@ -2930,7 +2930,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
throw new Error("End-to-end encryption disabled");
|
||||
}
|
||||
|
||||
const path = this.makeKeyBackupPath(roomId!, sessionId!, version!);
|
||||
const path = this.makeKeyBackupPath(roomId!, sessionId!, version);
|
||||
await this.http.authedRequest(
|
||||
Method.Put, path.path, path.queryData, data,
|
||||
{ prefix: ClientPrefix.V3 },
|
||||
@@ -3284,7 +3284,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
throw new Error("End-to-end encryption disabled");
|
||||
}
|
||||
|
||||
const path = this.makeKeyBackupPath(roomId!, sessionId!, version!);
|
||||
const path = this.makeKeyBackupPath(roomId!, sessionId!, version);
|
||||
await this.http.authedRequest(
|
||||
Method.Delete, path.path, path.queryData, undefined,
|
||||
{ prefix: ClientPrefix.V3 },
|
||||
@@ -4181,7 +4181,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
|
||||
return this.sendEvent(
|
||||
roomId,
|
||||
threadId as (string | null),
|
||||
threadId as string | null,
|
||||
eventType,
|
||||
sendContent,
|
||||
txnId,
|
||||
@@ -5225,7 +5225,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
];
|
||||
|
||||
// Here we handle non-thread timelines only, but still process any thread events to populate thread summaries.
|
||||
let timeline = timelineSet.getTimelineForEvent(events[0].getId()!);
|
||||
let timeline = timelineSet.getTimelineForEvent(events[0].getId());
|
||||
if (timeline) {
|
||||
timeline.getState(EventTimeline.BACKWARDS)!.setUnknownStateEvents(res.state.map(mapper));
|
||||
} else {
|
||||
@@ -6115,15 +6115,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
// There can be only room-kind push rule per room
|
||||
// and its id is the room id.
|
||||
if (this.pushRules) {
|
||||
if (!this.pushRules[scope] || !this.pushRules[scope].room) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < this.pushRules[scope].room.length; i++) {
|
||||
const rule = this.pushRules[scope].room[i];
|
||||
if (rule.rule_id === roomId) {
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
return this.pushRules[scope]?.room?.find(rule => rule.rule_id === roomId);
|
||||
} else {
|
||||
throw new Error(
|
||||
"SyncApi.sync() must be done before accessing to push rules.",
|
||||
@@ -6473,8 +6465,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
// create a new filter
|
||||
const createdFilter = await this.createFilter(filter.getDefinition());
|
||||
|
||||
// debuglog("Created new filter ID %s: %s", createdFilter.filterId,
|
||||
// JSON.stringify(createdFilter.getDefinition()));
|
||||
this.store.setFilterIdByName(filterName, createdFilter.filterId);
|
||||
return createdFilter.filterId!;
|
||||
}
|
||||
@@ -8434,9 +8424,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
keyAlgorithm = "signed_curve25519";
|
||||
}
|
||||
|
||||
for (let i = 0; i < devices.length; ++i) {
|
||||
const userId = devices[i][0];
|
||||
const deviceId = devices[i][1];
|
||||
for (const [userId, deviceId] of devices) {
|
||||
const query = queries[userId] || {};
|
||||
queries[userId] = query;
|
||||
query[deviceId] = keyAlgorithm;
|
||||
|
@@ -230,7 +230,7 @@ export class DeviceList extends TypedEventEmitter<EmittedEvents, CryptoEventHand
|
||||
}, delay);
|
||||
}
|
||||
|
||||
return savePromise!;
|
||||
return savePromise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -804,7 +804,7 @@ export class OlmDevice {
|
||||
log,
|
||||
);
|
||||
|
||||
return info!;
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -119,12 +119,10 @@ class OlmEncryption extends EncryptionAlgorithm {
|
||||
|
||||
const promises: Promise<void>[] = [];
|
||||
|
||||
for (let i = 0; i < users.length; ++i) {
|
||||
const userId = users[i];
|
||||
for (const userId of users) {
|
||||
const devices = this.crypto.getStoredDevicesForUser(userId) || [];
|
||||
|
||||
for (let j = 0; j < devices.length; ++j) {
|
||||
const deviceInfo = devices[j];
|
||||
for (const deviceInfo of devices) {
|
||||
const key = deviceInfo.getIdentityKey();
|
||||
if (key == this.olmDevice.deviceCurve25519Key) {
|
||||
// don't bother sending to ourself
|
||||
@@ -304,8 +302,7 @@ class OlmDecryption extends DecryptionAlgorithm {
|
||||
|
||||
// try each session in turn.
|
||||
const decryptionErrors: Record<string, string> = {};
|
||||
for (let i = 0; i < sessionIds.length; i++) {
|
||||
const sessionId = sessionIds[i];
|
||||
for (const sessionId of sessionIds) {
|
||||
try {
|
||||
const payload = await this.olmDevice.decryptMessage(
|
||||
theirDeviceIdentityKey, sessionId, message.type, message.body,
|
||||
|
@@ -680,8 +680,7 @@ export class Curve25519 implements BackupAlgorithm {
|
||||
const backupPubKey = decryption.init_with_private_key(privKey);
|
||||
|
||||
if (backupPubKey !== this.authData.public_key) {
|
||||
// eslint-disable-next-line no-throw-literal
|
||||
throw { errcode: MatrixClient.RESTORE_BACKUP_ERROR_BAD_KEY };
|
||||
throw new MatrixError({ errcode: MatrixClient.RESTORE_BACKUP_ERROR_BAD_KEY });
|
||||
}
|
||||
|
||||
const keys: IMegolmSessionData[] = [];
|
||||
|
@@ -2379,9 +2379,8 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
|
||||
*/
|
||||
public async getOlmSessionsForUser(userId: string): Promise<Record<string, IUserOlmSession>> {
|
||||
const devices = this.getStoredDevicesForUser(userId) || [];
|
||||
const result = {};
|
||||
for (let j = 0; j < devices.length; ++j) {
|
||||
const device = devices[j];
|
||||
const result: { [deviceId: string]: IUserOlmSession } = {};
|
||||
for (const device of devices) {
|
||||
const deviceKey = device.getIdentityKey();
|
||||
const sessions = await this.olmDevice.getSessionInfoForDevice(deviceKey);
|
||||
|
||||
@@ -2682,14 +2681,11 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
|
||||
): Promise<Record<string, Record<string, olmlib.IOlmSessionResult>>> {
|
||||
const devicesByUser: Record<string, DeviceInfo[]> = {};
|
||||
|
||||
for (let i = 0; i < users.length; ++i) {
|
||||
const userId = users[i];
|
||||
for (const userId of users) {
|
||||
devicesByUser[userId] = [];
|
||||
|
||||
const devices = this.getStoredDevicesForUser(userId) || [];
|
||||
for (let j = 0; j < devices.length; ++j) {
|
||||
const deviceInfo = devices[j];
|
||||
|
||||
for (const deviceInfo of devices) {
|
||||
const key = deviceInfo.getIdentityKey();
|
||||
if (key == this.olmDevice.deviceCurve25519Key) {
|
||||
// don't bother setting up session to ourself
|
||||
|
@@ -335,8 +335,7 @@ export async function ensureOlmSessionsForDevices(
|
||||
const promises: Promise<void>[] = [];
|
||||
for (const [userId, devices] of Object.entries(devicesByUser)) {
|
||||
const userRes = otkResult[userId] || {};
|
||||
for (let j = 0; j < devices.length; j++) {
|
||||
const deviceInfo = devices[j];
|
||||
for (const deviceInfo of devices) {
|
||||
const deviceId = deviceInfo.deviceId;
|
||||
const key = deviceInfo.getIdentityKey();
|
||||
|
||||
|
@@ -150,8 +150,7 @@ export class FilterComponent {
|
||||
},
|
||||
};
|
||||
|
||||
for (let n = 0; n < Object.keys(literalKeys).length; n++) {
|
||||
const name = Object.keys(literalKeys)[n];
|
||||
for (const name in literalKeys) {
|
||||
const matchFunc = literalKeys[name];
|
||||
const notName = "not_" + name;
|
||||
const disallowedValues: string[] = this.filterJson[notName];
|
||||
|
@@ -631,11 +631,6 @@ export class InteractiveAuth {
|
||||
*/
|
||||
private firstUncompletedStage(flow: IFlow): AuthType | undefined {
|
||||
const completed = this.data.completed || [];
|
||||
for (let i = 0; i < flow.stages.length; ++i) {
|
||||
const stageType = flow.stages[i];
|
||||
if (completed.indexOf(stageType) === -1) {
|
||||
return stageType;
|
||||
}
|
||||
}
|
||||
return flow.stages.find(stageType => !completed.includes(stageType));
|
||||
}
|
||||
}
|
||||
|
@@ -457,8 +457,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
|
||||
|
||||
let didUpdate = false;
|
||||
let lastEventWasNew = false;
|
||||
for (let i = 0; i < events.length; i++) {
|
||||
const event = events[i];
|
||||
for (const event of events) {
|
||||
const eventId = event.getId()!;
|
||||
|
||||
const existingTimeline = this._eventIdToTimeline.get(eventId);
|
||||
|
@@ -1008,8 +1008,8 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
|
||||
* Removing just the old live timeline whilst preserving previous ones is not supported.
|
||||
*/
|
||||
public resetLiveTimeline(backPaginationToken?: string | null, forwardPaginationToken?: string | null): void {
|
||||
for (let i = 0; i < this.timelineSets.length; i++) {
|
||||
this.timelineSets[i].resetLiveTimeline(
|
||||
for (const timelineSet of this.timelineSets) {
|
||||
timelineSet.resetLiveTimeline(
|
||||
backPaginationToken ?? undefined,
|
||||
forwardPaginationToken ?? undefined,
|
||||
);
|
||||
@@ -2128,8 +2128,8 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
|
||||
const { duplicateStrategy, timelineWasEmpty, fromCache } = addLiveEventOptions;
|
||||
|
||||
// add to our timeline sets
|
||||
for (let i = 0; i < this.timelineSets.length; i++) {
|
||||
this.timelineSets[i].addLiveEvent(event, {
|
||||
for (const timelineSet of this.timelineSets) {
|
||||
timelineSet.addLiveEvent(event, {
|
||||
duplicateStrategy,
|
||||
fromCache,
|
||||
timelineWasEmpty,
|
||||
@@ -2214,8 +2214,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < this.timelineSets.length; i++) {
|
||||
const timelineSet = this.timelineSets[i];
|
||||
for (const timelineSet of this.timelineSets) {
|
||||
if (timelineSet.getFilter()) {
|
||||
if (timelineSet.getFilter()!.filterRoomTimeline([event]).length) {
|
||||
timelineSet.addEventToTimeline(event,
|
||||
@@ -2322,9 +2321,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
|
||||
thread?.timelineSet.handleRemoteEcho(localEvent, oldEventId, newEventId);
|
||||
|
||||
if (shouldLiveInRoom) {
|
||||
for (let i = 0; i < this.timelineSets.length; i++) {
|
||||
const timelineSet = this.timelineSets[i];
|
||||
|
||||
for (const timelineSet of this.timelineSets) {
|
||||
// if it's already in the timeline, update the timeline map. If it's not, add it.
|
||||
timelineSet.handleRemoteEcho(localEvent, oldEventId, newEventId);
|
||||
}
|
||||
@@ -2407,8 +2404,8 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
|
||||
// if the event was already in the timeline (which will be the case if
|
||||
// opts.pendingEventOrdering==chronological), we need to update the
|
||||
// timeline map.
|
||||
for (let i = 0; i < this.timelineSets.length; i++) {
|
||||
this.timelineSets[i].replaceEventId(oldEventId, newEventId!);
|
||||
for (const timelineSet of this.timelineSets) {
|
||||
timelineSet.replaceEventId(oldEventId, newEventId!);
|
||||
}
|
||||
}
|
||||
} else if (newStatus == EventStatus.CANCELLED) {
|
||||
@@ -2643,8 +2640,8 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
|
||||
* @param {String[]} eventIds A list of eventIds to remove.
|
||||
*/
|
||||
public removeEvents(eventIds: string[]): void {
|
||||
for (let i = 0; i < eventIds.length; ++i) {
|
||||
this.removeEvent(eventIds[i]);
|
||||
for (const eventId of eventIds) {
|
||||
this.removeEvent(eventId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2657,8 +2654,8 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
|
||||
*/
|
||||
public removeEvent(eventId: string): boolean {
|
||||
let removedAny = false;
|
||||
for (let i = 0; i < this.timelineSets.length; i++) {
|
||||
const removed = this.timelineSets[i].removeEvent(eventId);
|
||||
for (const timelineSet of this.timelineSets) {
|
||||
const removed = timelineSet.removeEvent(eventId);
|
||||
if (removed) {
|
||||
if (removed.isRedaction()) {
|
||||
this.revertRedactionLocalEcho(removed);
|
||||
@@ -2740,8 +2737,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
|
||||
* @param {Array<MatrixEvent>} events an array of account_data events to add
|
||||
*/
|
||||
public addAccountData(events: MatrixEvent[]): void {
|
||||
for (let i = 0; i < events.length; i++) {
|
||||
const event = events[i];
|
||||
for (const event of events) {
|
||||
if (event.getType() === "m.tag") {
|
||||
this.addTags(event);
|
||||
}
|
||||
|
@@ -134,8 +134,8 @@ export class User extends TypedEventEmitter<UserEvent, UserEventHandlerMap> {
|
||||
|
||||
this.updateModifiedTime();
|
||||
|
||||
for (let i = 0; i < eventsToFire.length; i++) {
|
||||
this.emit(eventsToFire[i], event, this);
|
||||
for (const eventToFire of eventsToFire) {
|
||||
this.emit(eventToFire, event, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -135,8 +135,7 @@ export class PushProcessor {
|
||||
*/
|
||||
public static actionListToActionsObject(actionList: PushRuleAction[]): IActionsObject {
|
||||
const actionObj: IActionsObject = { notify: false, tweaks: {} };
|
||||
for (let i = 0; i < actionList.length; ++i) {
|
||||
const action = actionList[i];
|
||||
for (const action of actionList) {
|
||||
if (action === PushRuleActionName.Notify) {
|
||||
actionObj.notify = true;
|
||||
} else if (typeof action === 'object') {
|
||||
@@ -190,15 +189,13 @@ export class PushProcessor {
|
||||
private static cachedGlobToRegex: Record<string, RegExp> = {}; // $glob: RegExp
|
||||
|
||||
private matchingRuleFromKindSet(ev: MatrixEvent, kindset: PushRuleSet): IAnnotatedPushRule | null {
|
||||
for (let ruleKindIndex = 0; ruleKindIndex < RULEKINDS_IN_ORDER.length; ++ruleKindIndex) {
|
||||
const kind = RULEKINDS_IN_ORDER[ruleKindIndex];
|
||||
for (const kind of RULEKINDS_IN_ORDER) {
|
||||
const ruleset = kindset[kind];
|
||||
if (!ruleset) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (let ruleIndex = 0; ruleIndex < ruleset.length; ++ruleIndex) {
|
||||
const rule = ruleset[ruleIndex];
|
||||
for (const rule of ruleset) {
|
||||
if (!rule.enabled) {
|
||||
continue;
|
||||
}
|
||||
@@ -478,16 +475,7 @@ export class PushProcessor {
|
||||
}
|
||||
|
||||
public ruleMatchesEvent(rule: Partial<IPushRule> & Pick<IPushRule, "conditions">, ev: MatrixEvent): boolean {
|
||||
if (!rule.conditions?.length) return true;
|
||||
|
||||
let ret = true;
|
||||
for (let i = 0; i < rule.conditions.length; ++i) {
|
||||
const cond = rule.conditions[i];
|
||||
// @ts-ignore
|
||||
ret &= this.eventFulfillsCondition(cond, ev);
|
||||
}
|
||||
//console.log("Rule "+rule.rule_id+(ret ? " matches" : " doesn't match"));
|
||||
return ret;
|
||||
return !rule.conditions?.some(cond => !this.eventFulfillsCondition(cond, ev));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -101,7 +101,7 @@ export function clearTimeout(key: number): void {
|
||||
}
|
||||
|
||||
// remove the element from the list
|
||||
let i;
|
||||
let i: number;
|
||||
for (i = 0; i < callbackList.length; i++) {
|
||||
const cb = callbackList[i];
|
||||
if (cb.key == key) {
|
||||
@@ -137,7 +137,6 @@ function scheduleRealCallback(): void {
|
||||
}
|
||||
|
||||
function runCallbacks(): void {
|
||||
let cb: Callback;
|
||||
const timestamp = Date.now();
|
||||
debuglog("runCallbacks: now:", timestamp);
|
||||
|
||||
@@ -149,7 +148,7 @@ function runCallbacks(): void {
|
||||
if (!first || first.runAt > timestamp) {
|
||||
break;
|
||||
}
|
||||
cb = callbackList.shift()!;
|
||||
const cb = callbackList.shift()!;
|
||||
debuglog("runCallbacks: popping", cb.key);
|
||||
callbacksToRun.push(cb);
|
||||
}
|
||||
@@ -159,8 +158,7 @@ function runCallbacks(): void {
|
||||
// register their own setTimeouts.
|
||||
scheduleRealCallback();
|
||||
|
||||
for (let i = 0; i < callbacksToRun.length; i++) {
|
||||
cb = callbacksToRun[i];
|
||||
for (const cb of callbacksToRun) {
|
||||
try {
|
||||
cb.func.apply(global, cb.params);
|
||||
} catch (e) {
|
||||
|
@@ -16,14 +16,13 @@ limitations under the License.
|
||||
|
||||
import { UnstableValue } from "matrix-events-sdk";
|
||||
|
||||
import { RendezvousChannel } from ".";
|
||||
import { RendezvousChannel, RendezvousFailureListener, RendezvousFailureReason, RendezvousIntent } from ".";
|
||||
import { MatrixClient } from "../client";
|
||||
import { CrossSigningInfo } from "../crypto/CrossSigning";
|
||||
import { DeviceInfo } from "../crypto/deviceinfo";
|
||||
import { buildFeatureSupportMap, Feature, ServerSupport } from "../feature";
|
||||
import { logger } from "../logger";
|
||||
import { sleep } from "../utils";
|
||||
import { RendezvousFailureListener, RendezvousFailureReason, RendezvousIntent } from ".";
|
||||
|
||||
enum PayloadType {
|
||||
Start = 'm.login.start',
|
||||
|
@@ -454,8 +454,8 @@ export class LocalIndexedDBStoreBackend implements IIndexedDBBackend {
|
||||
return utils.promiseTry<void>(() => {
|
||||
const txn = this.db!.transaction(["accountData"], "readwrite");
|
||||
const store = txn.objectStore("accountData");
|
||||
for (let i = 0; i < accountData.length; i++) {
|
||||
store.put(accountData[i]); // put == UPSERT
|
||||
for (const event of accountData) {
|
||||
store.put(event); // put == UPSERT
|
||||
}
|
||||
return txnAsPromise(txn).then();
|
||||
});
|
||||
|
@@ -400,47 +400,51 @@ export class SyncAccumulator {
|
||||
acc[INVITED_COUNT_KEY] = sum[INVITED_COUNT_KEY] || acc[INVITED_COUNT_KEY];
|
||||
}
|
||||
|
||||
if (data.ephemeral && data.ephemeral.events) {
|
||||
data.ephemeral.events.forEach((e) => {
|
||||
// We purposefully do not persist m.typing events.
|
||||
// Technically you could refresh a browser before the timer on a
|
||||
// typing event is up, so it'll look like you aren't typing when
|
||||
// you really still are. However, the alternative is worse. If
|
||||
// we do persist typing events, it will look like people are
|
||||
// typing forever until someone really does start typing (which
|
||||
// will prompt Synapse to send down an actual m.typing event to
|
||||
// clobber the one we persisted).
|
||||
if (e.type !== EventType.Receipt || !e.content) {
|
||||
// This means we'll drop unknown ephemeral events but that
|
||||
// seems okay.
|
||||
return;
|
||||
}
|
||||
// Handle m.receipt events. They clobber based on:
|
||||
// (user_id, receipt_type)
|
||||
// but they are keyed in the event as:
|
||||
// content:{ $event_id: { $receipt_type: { $user_id: {json} }}}
|
||||
// so store them in the former so we can accumulate receipt deltas
|
||||
// quickly and efficiently (we expect a lot of them). Fold the
|
||||
// receipt type into the key name since we only have 1 at the
|
||||
// moment (m.read) and nested JSON objects are slower and more
|
||||
// of a hassle to work with. We'll inflate this back out when
|
||||
// getJSON() is called.
|
||||
Object.keys(e.content).forEach((eventId) => {
|
||||
Object.entries(e.content[eventId]).forEach(([key, value]) => {
|
||||
if (!isSupportedReceiptType(key)) return;
|
||||
data.ephemeral?.events?.forEach((e) => {
|
||||
// We purposefully do not persist m.typing events.
|
||||
// Technically you could refresh a browser before the timer on a
|
||||
// typing event is up, so it'll look like you aren't typing when
|
||||
// you really still are. However, the alternative is worse. If
|
||||
// we do persist typing events, it will look like people are
|
||||
// typing forever until someone really does start typing (which
|
||||
// will prompt Synapse to send down an actual m.typing event to
|
||||
// clobber the one we persisted).
|
||||
if (e.type !== EventType.Receipt || !e.content) {
|
||||
// This means we'll drop unknown ephemeral events but that
|
||||
// seems okay.
|
||||
return;
|
||||
}
|
||||
// Handle m.receipt events. They clobber based on:
|
||||
// (user_id, receipt_type)
|
||||
// but they are keyed in the event as:
|
||||
// content:{ $event_id: { $receipt_type: { $user_id: {json} }}}
|
||||
// so store them in the former so we can accumulate receipt deltas
|
||||
// quickly and efficiently (we expect a lot of them). Fold the
|
||||
// receipt type into the key name since we only have 1 at the
|
||||
// moment (m.read) and nested JSON objects are slower and more
|
||||
// of a hassle to work with. We'll inflate this back out when
|
||||
// getJSON() is called.
|
||||
Object.keys(e.content).forEach((eventId) => {
|
||||
Object.entries<{
|
||||
[eventId: string]: {
|
||||
[receiptType: string]: {
|
||||
[userId: string]: IMinimalEvent;
|
||||
};
|
||||
};
|
||||
}>(e.content[eventId]).forEach(([key, value]) => {
|
||||
if (!isSupportedReceiptType(key)) return;
|
||||
|
||||
Object.keys(value!).forEach((userId) => {
|
||||
// clobber on user ID
|
||||
currentData._readReceipts[userId] = {
|
||||
data: e.content[eventId][key][userId],
|
||||
type: key as ReceiptType,
|
||||
eventId: eventId,
|
||||
};
|
||||
});
|
||||
Object.keys(value).forEach((userId) => {
|
||||
// clobber on user ID
|
||||
currentData._readReceipts[userId] = {
|
||||
data: e.content[eventId][key][userId],
|
||||
type: key as ReceiptType,
|
||||
eventId: eventId,
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// if we got a limited sync, we need to remove all timeline entries or else
|
||||
// we will have gaps in the timeline.
|
||||
@@ -551,7 +555,7 @@ export class SyncAccumulator {
|
||||
};
|
||||
// Add account data
|
||||
Object.keys(roomData._accountData).forEach((evType) => {
|
||||
roomJson.account_data.events.push(roomData._accountData[evType] as IMinimalEvent);
|
||||
roomJson.account_data.events.push(roomData._accountData[evType]);
|
||||
});
|
||||
|
||||
// Add receipt data
|
||||
|
12
src/sync.ts
12
src/sync.ts
@@ -821,7 +821,6 @@ export class SyncApi {
|
||||
|
||||
let data: ISyncResponse;
|
||||
try {
|
||||
//debuglog('Starting sync since=' + syncToken);
|
||||
if (!this.currentSyncRequest) {
|
||||
this.currentSyncRequest = this.doSyncRequest(syncOptions, syncToken);
|
||||
}
|
||||
@@ -834,8 +833,6 @@ export class SyncApi {
|
||||
this.currentSyncRequest = undefined;
|
||||
}
|
||||
|
||||
//debuglog('Completed sync, next_batch=' + data.next_batch);
|
||||
|
||||
// set the sync token NOW *before* processing the events. We do this so
|
||||
// if something barfs on an event we can skip it rather than constantly
|
||||
// polling with the same token.
|
||||
@@ -1747,11 +1744,10 @@ export class SyncApi {
|
||||
private processEventsForNotifs(room: Room, timelineEventList: MatrixEvent[]): void {
|
||||
// gather our notifications into this.notifEvents
|
||||
if (this.client.getNotifTimelineSet()) {
|
||||
for (let i = 0; i < timelineEventList.length; i++) {
|
||||
const pushActions = this.client.getPushActionsForEvent(timelineEventList[i]);
|
||||
if (pushActions && pushActions.notify &&
|
||||
pushActions.tweaks && pushActions.tweaks.highlight) {
|
||||
this.notifEvents.push(timelineEventList[i]);
|
||||
for (const event of timelineEventList) {
|
||||
const pushActions = this.client.getPushActionsForEvent(event);
|
||||
if (pushActions?.notify && pushActions.tweaks?.highlight) {
|
||||
this.notifEvents.push(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -190,9 +190,9 @@ export function isFunction(value: any) {
|
||||
*/
|
||||
// note using 'keys' here would shadow the 'keys' function defined above
|
||||
export function checkObjectHasKeys(obj: object, keys: string[]) {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
if (!obj.hasOwnProperty(keys[i])) {
|
||||
throw new Error("Missing required key: " + keys[i]);
|
||||
for (const key of keys) {
|
||||
if (!obj.hasOwnProperty(key)) {
|
||||
throw new Error("Missing required key: " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2237,8 +2237,8 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
|
||||
}
|
||||
|
||||
function setTracksEnabled(tracks: Array<MediaStreamTrack>, enabled: boolean): void {
|
||||
for (let i = 0; i < tracks.length; i++) {
|
||||
tracks[i].enabled = enabled;
|
||||
for (const track of tracks) {
|
||||
track.enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -140,7 +140,6 @@ export class CallEventHandler {
|
||||
const type = event.getType() as EventType;
|
||||
const weSentTheEvent = event.getSender() === this.client.credentials.userId;
|
||||
let call = content.call_id ? this.calls.get(content.call_id) : undefined;
|
||||
//console.info("RECV %s content=%s", type, JSON.stringify(content));
|
||||
|
||||
if (type === EventType.CallInvite) {
|
||||
// ignore invites you send
|
||||
|
@@ -220,9 +220,9 @@ export class CallFeed extends TypedEventEmitter<CallFeedEvent, EventHandlerMap>
|
||||
this.analyser.getFloatFrequencyData(this.frequencyBinCount!);
|
||||
|
||||
let maxVolume = -Infinity;
|
||||
for (let i = 0; i < this.frequencyBinCount!.length; i++) {
|
||||
if (this.frequencyBinCount![i] > maxVolume) {
|
||||
maxVolume = this.frequencyBinCount![i];
|
||||
for (const volume of this.frequencyBinCount!) {
|
||||
if (volume > maxVolume) {
|
||||
maxVolume = volume;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,9 +233,7 @@ export class CallFeed extends TypedEventEmitter<CallFeedEvent, EventHandlerMap>
|
||||
|
||||
let newSpeaking = false;
|
||||
|
||||
for (let i = 0; i < this.speakingVolumeSamples.length; i++) {
|
||||
const volume = this.speakingVolumeSamples[i];
|
||||
|
||||
for (const volume of this.speakingVolumeSamples) {
|
||||
if (volume > this.speakingThreshold) {
|
||||
newSpeaking = true;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user