SafetyNumberChangeDialog: Introduce awareness of stories

This commit is contained in:
Scott Nonnenberg 2022-11-10 20:10:30 -08:00 committed by GitHub
parent 709588a874
commit 5100d17ed2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 2531 additions and 522 deletions

View file

@ -2,7 +2,6 @@
// SPDX-License-Identifier: AGPL-3.0-only
import { differenceWith, omit, partition } from 'lodash';
import PQueue from 'p-queue';
import {
ErrorCode,
@ -60,7 +59,7 @@ import { SignalService as Proto } from '../protobuf';
import { strictAssert } from './assert';
import * as log from '../logging/log';
import { GLOBAL_ZONE } from '../SignalProtocolStore';
import { MINUTE } from './durations';
import { waitForAll } from './waitForAll';
const ERROR_EXPIRED_OR_MISSING_DEVICES = 409;
const ERROR_STALE_DEVICES = 410;
@ -68,8 +67,6 @@ const ERROR_STALE_DEVICES = 410;
const HOUR = 60 * 60 * 1000;
const DAY = 24 * HOUR;
const MAX_CONCURRENCY = 5;
// sendWithSenderKey is recursive, but we don't want to loop back too many times.
const MAX_RECURSION = 10;
@ -530,7 +527,7 @@ export async function sendToGroupViaSenderKey(options: {
if (parsed.success) {
const { uuids404 } = parsed.data;
if (uuids404 && uuids404.length > 0) {
await _waitForAll({
await waitForAll({
tasks: uuids404.map(
uuid => async () => markIdentifierUnregistered(uuid)
),
@ -831,21 +828,6 @@ export function _shouldFailSend(error: unknown, logId: string): boolean {
return false;
}
export async function _waitForAll<T>({
tasks,
maxConcurrency = MAX_CONCURRENCY,
}: {
tasks: Array<() => Promise<T>>;
maxConcurrency?: number;
}): Promise<Array<T>> {
const queue = new PQueue({
concurrency: maxConcurrency,
timeout: MINUTE * 30,
throwOnTimeout: true,
});
return queue.addAll(tasks);
}
function getRecipients(options: GroupSendOptionsType): Array<string> {
if (options.groupV2) {
return options.groupV2.members;
@ -888,7 +870,7 @@ function isIdentifierRegistered(identifier: string) {
async function handle409Response(logId: string, error: HTTPError) {
const parsed = multiRecipient409ResponseSchema.safeParse(error.response);
if (parsed.success) {
await _waitForAll({
await waitForAll({
tasks: parsed.data.map(item => async () => {
const { uuid, devices } = item;
// Start new sessions with devices we didn't know about before
@ -900,7 +882,7 @@ async function handle409Response(logId: string, error: HTTPError) {
if (devices.extraDevices && devices.extraDevices.length > 0) {
const ourUuid = window.textsecure.storage.user.getCheckedUuid();
await _waitForAll({
await waitForAll({
tasks: devices.extraDevices.map(deviceId => async () => {
await window.textsecure.storage.protocol.archiveSession(
new QualifiedAddress(ourUuid, Address.create(uuid, deviceId))
@ -929,14 +911,14 @@ async function handle410Response(
const parsed = multiRecipient410ResponseSchema.safeParse(error.response);
if (parsed.success) {
await _waitForAll({
await waitForAll({
tasks: parsed.data.map(item => async () => {
const { uuid, devices } = item;
if (devices.staleDevices && devices.staleDevices.length > 0) {
const ourUuid = window.textsecure.storage.user.getCheckedUuid();
// First, archive our existing sessions with these devices
await _waitForAll({
await waitForAll({
tasks: devices.staleDevices.map(deviceId => async () => {
await window.textsecure.storage.protocol.archiveSession(
new QualifiedAddress(ourUuid, Address.create(uuid, deviceId))
@ -1281,7 +1263,7 @@ async function fetchKeysForIdentifiers(
);
try {
await _waitForAll({
await waitForAll({
tasks: identifiers.map(
identifier => async () => fetchKeysForIdentifier(identifier)
),