mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-17 23:34:14 +01:00
Enable tsconfig noUncheckedIndexedAccess
This commit is contained in:
@@ -46,7 +46,7 @@ export class OutgoingIdentityKeyError extends ReplayableError {
|
||||
|
||||
// Note: Data to resend message is no longer captured
|
||||
constructor(incomingIdentifier: string, cause?: LibSignalErrorBase) {
|
||||
const identifier = incomingIdentifier.split('.')[0];
|
||||
const [identifier] = incomingIdentifier.split('.');
|
||||
|
||||
super({
|
||||
name: 'OutgoingIdentityKeyError',
|
||||
@@ -70,7 +70,7 @@ export class OutgoingMessageError extends ReplayableError {
|
||||
_t: unknown,
|
||||
httpError?: HTTPError
|
||||
) {
|
||||
const identifier = incomingIdentifier.split('.')[0];
|
||||
const [identifier] = incomingIdentifier.split('.', 1);
|
||||
|
||||
super({
|
||||
name: 'OutgoingMessageError',
|
||||
@@ -101,7 +101,8 @@ export class SendMessageNetworkError extends ReplayableError {
|
||||
message: httpError.message,
|
||||
});
|
||||
|
||||
[this.identifier] = identifier.split('.');
|
||||
const [id] = identifier.split('.', 1);
|
||||
this.identifier = id;
|
||||
this.httpError = httpError;
|
||||
|
||||
appendStack(this, httpError);
|
||||
@@ -137,7 +138,8 @@ export class SendMessageChallengeError extends ReplayableError {
|
||||
cause: httpError,
|
||||
});
|
||||
|
||||
[this.identifier] = identifier.split('.');
|
||||
const [id] = identifier.split('.', 1);
|
||||
this.identifier = id;
|
||||
this.httpError = httpError;
|
||||
|
||||
this.data = httpError.response as SendMessageChallengeData;
|
||||
|
||||
@@ -73,8 +73,8 @@ export default class EventTarget {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.listeners[eventName] = listeners;
|
||||
}
|
||||
this.listeners[eventName] = listeners;
|
||||
}
|
||||
|
||||
extend(source: any): any {
|
||||
|
||||
@@ -69,7 +69,8 @@ const utils = {
|
||||
number[0] === '+' && /^[0-9]+$/.test(number.substring(1)),
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
jsonThing: (thing: unknown) => JSON.stringify(ensureStringed(thing)),
|
||||
unencodeNumber: (number: string): Array<string> => number.split('.'),
|
||||
unencodeNumber: (number: string): [string, ...Array<string>] =>
|
||||
number.split('.'),
|
||||
};
|
||||
|
||||
export default utils;
|
||||
|
||||
@@ -848,10 +848,9 @@ export default class MessageReceiver
|
||||
}
|
||||
|
||||
for await (const batch of this.#getAllFromCache()) {
|
||||
const max = batch.length;
|
||||
for (let i = 0; i < max; i += 1) {
|
||||
for (const item of batch) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await this.#queueCached(batch[i]);
|
||||
await this.#queueCached(item);
|
||||
}
|
||||
}
|
||||
log.info('queueAllCached - finished');
|
||||
|
||||
@@ -99,7 +99,12 @@ const MAX_ROTATIONS = 6;
|
||||
|
||||
const TIMEOUT_ERROR = new PTimeoutError();
|
||||
|
||||
const QR_CODE_TIMEOUTS = [10 * SECOND, 20 * SECOND, 30 * SECOND, 60 * SECOND];
|
||||
const QR_CODE_TIMEOUTS = [
|
||||
10 * SECOND,
|
||||
20 * SECOND,
|
||||
30 * SECOND,
|
||||
60 * SECOND,
|
||||
] as const;
|
||||
|
||||
export class Provisioner {
|
||||
readonly #subscribers = new Set<SubscriberType>();
|
||||
@@ -242,7 +247,8 @@ export class Provisioner {
|
||||
let delay: number;
|
||||
|
||||
try {
|
||||
const sleepMs = QR_CODE_TIMEOUTS[this.#attemptCount];
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const sleepMs = QR_CODE_TIMEOUTS[this.#attemptCount]!;
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await this.#connect(signal, sleepMs);
|
||||
|
||||
@@ -778,7 +778,8 @@ export class MessageSender {
|
||||
static getRandomPadding(): Uint8Array {
|
||||
// Generate a random int from 1 and 512
|
||||
const buffer = getRandomBytes(2);
|
||||
const paddingLength = (new Uint16Array(buffer)[0] & 0x1ff) + 1;
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const paddingLength = (new Uint16Array(buffer)[0]! & 0x1ff) + 1;
|
||||
|
||||
// Generate a random padding buffer of the chosen size
|
||||
return getRandomBytes(paddingLength);
|
||||
@@ -2174,7 +2175,8 @@ export class MessageSender {
|
||||
`syncViewOnceOpen: ${viewOnceOpens.length} opens provided. Can only handle one.`
|
||||
);
|
||||
}
|
||||
const { senderAci, timestamp } = viewOnceOpens[0];
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const { senderAci, timestamp } = viewOnceOpens[0]!;
|
||||
|
||||
if (!senderAci) {
|
||||
throw new Error('syncViewOnceOpen: Missing senderAci');
|
||||
|
||||
@@ -379,7 +379,7 @@ async function getFetchOptions<Type extends ResponseType, OutputShape>(
|
||||
};
|
||||
}
|
||||
const agentEntry = agents[cacheKey];
|
||||
const agent = agentEntry?.agent ?? null;
|
||||
const agent = agentEntry?.agent ?? undefined;
|
||||
|
||||
const fetchOptions: FetchOptionsType = {
|
||||
method: options.type,
|
||||
@@ -729,12 +729,11 @@ function makeHTTPError(
|
||||
export function makeKeysLowercase<V>(
|
||||
headers: Record<string, V>
|
||||
): Record<string, V> {
|
||||
const keys = Object.keys(headers);
|
||||
const lowerCase: Record<string, V> = Object.create(null);
|
||||
|
||||
keys.forEach(key => {
|
||||
lowerCase[key.toLowerCase()] = headers[key];
|
||||
});
|
||||
for (const [key, value] of Object.entries(headers)) {
|
||||
lowerCase[key.toLowerCase()] = value;
|
||||
}
|
||||
|
||||
return lowerCase;
|
||||
}
|
||||
@@ -3877,7 +3876,9 @@ export async function putStickers(
|
||||
});
|
||||
await Promise.all(
|
||||
stickers.map(async (sticker: ServerV2AttachmentType, index: number) => {
|
||||
const stickerParams = makePutParams(sticker, encryptedStickers[index]);
|
||||
const encryptedSticker = encryptedStickers[index];
|
||||
strictAssert(encryptedSticker, 'Missing encryptedSticker');
|
||||
const stickerParams = makePutParams(sticker, encryptedSticker);
|
||||
await queue.add(async () =>
|
||||
_outerAjax(`${cdnUrlObject['0']}/`, {
|
||||
...stickerParams,
|
||||
@@ -4044,7 +4045,8 @@ async function _getAttachment({
|
||||
|
||||
const match = PARSE_RANGE_HEADER.exec(range);
|
||||
strictAssert(match != null, 'Attachment Content-Range is invalid');
|
||||
const maybeSize = safeParseNumber(match[1]);
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const maybeSize = safeParseNumber(match[1]!);
|
||||
strictAssert(
|
||||
maybeSize != null,
|
||||
'Attachment Content-Range[1] is not a number'
|
||||
@@ -4193,7 +4195,8 @@ export async function putEncryptedAttachment(
|
||||
if (range != null) {
|
||||
const match = range.match(/^bytes=0-(\d+)$/);
|
||||
strictAssert(match != null, `Invalid range header: ${range}`);
|
||||
start = parseInt(match[1], 10);
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
start = parseInt(match[1]!, 10);
|
||||
} else {
|
||||
log.warn(`${logId}: No range header`);
|
||||
}
|
||||
@@ -4753,9 +4756,12 @@ export async function getGroupLog(
|
||||
const range = response.headers.get('Content-Range');
|
||||
const match = PARSE_GROUP_LOG_RANGE_HEADER.exec(range || '');
|
||||
|
||||
const start = match ? parseInt(match[1], 10) : undefined;
|
||||
const end = match ? parseInt(match[2], 10) : undefined;
|
||||
const currentRevision = match ? parseInt(match[3], 10) : undefined;
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const start = match ? parseInt(match[1]!, 10) : undefined;
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const end = match ? parseInt(match[2]!, 10) : undefined;
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const currentRevision = match ? parseInt(match[3]!, 10) : undefined;
|
||||
|
||||
if (
|
||||
match &&
|
||||
|
||||
Reference in New Issue
Block a user