Fix part of storybook stories
This commit is contained in:
parent
eaae3ff88b
commit
a2b05333f7
8 changed files with 65 additions and 38 deletions
|
@ -63,3 +63,7 @@ export function areEqual(
|
||||||
): boolean {
|
): boolean {
|
||||||
return bytes.areEqual(a, b);
|
return bytes.areEqual(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function readBigUint64BE(value: Uint8Array): bigint {
|
||||||
|
return bytes.readBigUint64BE(value);
|
||||||
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ import * as log from './logging/log';
|
||||||
import type { UUIDStringType } from './types/UUID';
|
import type { UUIDStringType } from './types/UUID';
|
||||||
import { parseIntOrThrow } from './util/parseIntOrThrow';
|
import { parseIntOrThrow } from './util/parseIntOrThrow';
|
||||||
import { SECOND, HOUR } from './util/durations';
|
import { SECOND, HOUR } from './util/durations';
|
||||||
|
import { uuidToBytes } from './util/uuidToBytes';
|
||||||
import * as Bytes from './Bytes';
|
import * as Bytes from './Bytes';
|
||||||
import { hash, uuidToBytes } from './Crypto';
|
|
||||||
import { HashType } from './types/Crypto';
|
import { HashType } from './types/Crypto';
|
||||||
import { getCountryCode } from './types/PhoneNumber';
|
import { getCountryCode } from './types/PhoneNumber';
|
||||||
|
|
||||||
|
@ -234,8 +234,10 @@ export function getBucketValue(uuid: UUIDStringType, flagName: string): number {
|
||||||
Bytes.fromString(`${flagName}.`),
|
Bytes.fromString(`${flagName}.`),
|
||||||
uuidToBytes(uuid),
|
uuidToBytes(uuid),
|
||||||
]);
|
]);
|
||||||
const hashResult = hash(HashType.size256, hashInput);
|
const hashResult = window.SignalContext.crypto.hash(
|
||||||
const buffer = Buffer.from(hashResult.slice(0, 8));
|
HashType.size256,
|
||||||
|
hashInput
|
||||||
|
);
|
||||||
|
|
||||||
return Number(buffer.readBigUint64BE() % 1_000_000n);
|
return Number(Bytes.readBigUint64BE(hashResult.slice(0, 8)) % 1_000_000n);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,4 +67,9 @@ export class Bytes {
|
||||||
|
|
||||||
return Buffer.compare(a, b) === 0;
|
return Buffer.compare(a, b) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public readBigUint64BE(value: Uint8Array): bigint {
|
||||||
|
const buffer = Buffer.from(value);
|
||||||
|
return buffer.readBigUint64BE();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ import { singleProtoJobQueue } from '../../jobs/singleProtoJobQueue';
|
||||||
import MessageSender from '../../textsecure/SendMessage';
|
import MessageSender from '../../textsecure/SendMessage';
|
||||||
import type { BoundActionCreatorsMapObject } from '../../hooks/useBoundActions';
|
import type { BoundActionCreatorsMapObject } from '../../hooks/useBoundActions';
|
||||||
import { useBoundActions } from '../../hooks/useBoundActions';
|
import { useBoundActions } from '../../hooks/useBoundActions';
|
||||||
|
import { isAnybodyElseInGroupCall } from './callingHelpers';
|
||||||
|
|
||||||
// State
|
// State
|
||||||
|
|
||||||
|
@ -297,33 +298,6 @@ export const getActiveCall = ({
|
||||||
activeCallState &&
|
activeCallState &&
|
||||||
getOwn(callsByConversation, activeCallState.conversationId);
|
getOwn(callsByConversation, activeCallState.conversationId);
|
||||||
|
|
||||||
// In theory, there could be multiple incoming calls, or an incoming call while there's
|
|
||||||
// an active call. In practice, the UI is not ready for this, and RingRTC doesn't
|
|
||||||
// support it for direct calls.
|
|
||||||
export const getIncomingCall = (
|
|
||||||
callsByConversation: Readonly<CallsByConversationType>,
|
|
||||||
ourUuid: UUIDStringType
|
|
||||||
): undefined | DirectCallStateType | GroupCallStateType =>
|
|
||||||
Object.values(callsByConversation).find(call => {
|
|
||||||
switch (call.callMode) {
|
|
||||||
case CallMode.Direct:
|
|
||||||
return call.isIncoming && call.callState === CallState.Ringing;
|
|
||||||
case CallMode.Group:
|
|
||||||
return (
|
|
||||||
call.ringerUuid &&
|
|
||||||
call.connectionState === GroupCallConnectionState.NotConnected &&
|
|
||||||
isAnybodyElseInGroupCall(call.peekInfo, ourUuid)
|
|
||||||
);
|
|
||||||
default:
|
|
||||||
throw missingCaseError(call);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const isAnybodyElseInGroupCall = (
|
|
||||||
peekInfo: undefined | Readonly<Pick<GroupCallPeekInfoType, 'uuids'>>,
|
|
||||||
ourUuid: UUIDStringType
|
|
||||||
): boolean => Boolean(peekInfo?.uuids.some(id => id !== ourUuid));
|
|
||||||
|
|
||||||
const getGroupCallRingState = (
|
const getGroupCallRingState = (
|
||||||
call: Readonly<undefined | GroupCallStateType>
|
call: Readonly<undefined | GroupCallStateType>
|
||||||
): GroupCallRingStateType =>
|
): GroupCallRingStateType =>
|
||||||
|
|
45
ts/state/ducks/callingHelpers.ts
Normal file
45
ts/state/ducks/callingHelpers.ts
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
// Copyright 2023 Signal Messenger, LLC
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
// Note that this file should not important any binary addons or Node.js modules
|
||||||
|
// because it can be imported by storybook
|
||||||
|
import {
|
||||||
|
CallMode,
|
||||||
|
CallState,
|
||||||
|
GroupCallConnectionState,
|
||||||
|
} from '../../types/Calling';
|
||||||
|
import type { UUIDStringType } from '../../types/UUID';
|
||||||
|
import { missingCaseError } from '../../util/missingCaseError';
|
||||||
|
import type {
|
||||||
|
DirectCallStateType,
|
||||||
|
CallsByConversationType,
|
||||||
|
GroupCallPeekInfoType,
|
||||||
|
GroupCallStateType,
|
||||||
|
} from './calling';
|
||||||
|
|
||||||
|
// In theory, there could be multiple incoming calls, or an incoming call while there's
|
||||||
|
// an active call. In practice, the UI is not ready for this, and RingRTC doesn't
|
||||||
|
// support it for direct calls.
|
||||||
|
export const getIncomingCall = (
|
||||||
|
callsByConversation: Readonly<CallsByConversationType>,
|
||||||
|
ourUuid: UUIDStringType
|
||||||
|
): undefined | DirectCallStateType | GroupCallStateType =>
|
||||||
|
Object.values(callsByConversation).find(call => {
|
||||||
|
switch (call.callMode) {
|
||||||
|
case CallMode.Direct:
|
||||||
|
return call.isIncoming && call.callState === CallState.Ringing;
|
||||||
|
case CallMode.Group:
|
||||||
|
return (
|
||||||
|
call.ringerUuid &&
|
||||||
|
call.connectionState === GroupCallConnectionState.NotConnected &&
|
||||||
|
isAnybodyElseInGroupCall(call.peekInfo, ourUuid)
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
throw missingCaseError(call);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export const isAnybodyElseInGroupCall = (
|
||||||
|
peekInfo: undefined | Readonly<Pick<GroupCallPeekInfoType, 'uuids'>>,
|
||||||
|
ourUuid: UUIDStringType
|
||||||
|
): boolean => Boolean(peekInfo?.uuids.some(id => id !== ourUuid));
|
|
@ -11,7 +11,7 @@ import type {
|
||||||
DirectCallStateType,
|
DirectCallStateType,
|
||||||
GroupCallStateType,
|
GroupCallStateType,
|
||||||
} from '../ducks/calling';
|
} from '../ducks/calling';
|
||||||
import { getIncomingCall as getIncomingCallHelper } from '../ducks/calling';
|
import { getIncomingCall as getIncomingCallHelper } from '../ducks/callingHelpers';
|
||||||
import { getUserACI } from './user';
|
import { getUserACI } from './user';
|
||||||
import { getOwn } from '../../util/getOwn';
|
import { getOwn } from '../../util/getOwn';
|
||||||
import { CallViewMode } from '../../types/Calling';
|
import { CallViewMode } from '../../types/Calling';
|
||||||
|
|
|
@ -17,11 +17,8 @@ import {
|
||||||
isMissingRequiredProfileSharing,
|
isMissingRequiredProfileSharing,
|
||||||
} from '../selectors/conversations';
|
} from '../selectors/conversations';
|
||||||
import { CallMode } from '../../types/Calling';
|
import { CallMode } from '../../types/Calling';
|
||||||
import {
|
import { getActiveCall, useCallingActions } from '../ducks/calling';
|
||||||
getActiveCall,
|
import { isAnybodyElseInGroupCall } from '../ducks/callingHelpers';
|
||||||
isAnybodyElseInGroupCall,
|
|
||||||
useCallingActions,
|
|
||||||
} from '../ducks/calling';
|
|
||||||
import {
|
import {
|
||||||
getConversationCallMode,
|
getConversationCallMode,
|
||||||
useConversationsActions,
|
useConversationsActions,
|
||||||
|
|
|
@ -15,9 +15,9 @@ import {
|
||||||
actions,
|
actions,
|
||||||
getActiveCall,
|
getActiveCall,
|
||||||
getEmptyState,
|
getEmptyState,
|
||||||
isAnybodyElseInGroupCall,
|
|
||||||
reducer,
|
reducer,
|
||||||
} from '../../../state/ducks/calling';
|
} from '../../../state/ducks/calling';
|
||||||
|
import { isAnybodyElseInGroupCall } from '../../../state/ducks/callingHelpers';
|
||||||
import { truncateAudioLevel } from '../../../calling/truncateAudioLevel';
|
import { truncateAudioLevel } from '../../../calling/truncateAudioLevel';
|
||||||
import { calling as callingService } from '../../../services/calling';
|
import { calling as callingService } from '../../../services/calling';
|
||||||
import {
|
import {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue