Fix sync CallEvent peerId for call link roomIds

Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2024-10-16 12:36:32 -05:00 committed by GitHub
parent fffdf7f42c
commit 173a7b729a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 74 additions and 17 deletions

View file

@ -74,3 +74,7 @@ export function InAnotherCallAndCallActive(
/>
);
}
export function MissingCallLink(args: CallLinkDetailsProps): JSX.Element {
return <CallLinkDetails {...args} callLink={undefined} />;
}

View file

@ -31,7 +31,7 @@ function toUrlWithoutProtocol(url: URL): string {
export type CallLinkDetailsProps = Readonly<{
callHistoryGroup: CallHistoryGroup;
callLink: CallLinkType;
callLink: CallLinkType | undefined;
isAnybodyInCall: boolean;
isInCall: boolean;
isInAnotherCall: boolean;
@ -58,6 +58,11 @@ export function CallLinkDetails({
}: CallLinkDetailsProps): JSX.Element {
const [isDeleteCallLinkModalOpen, setIsDeleteCallLinkModalOpen] =
useState(false);
if (!callLink) {
return renderMissingCallLink({ callHistoryGroup, i18n });
}
const webUrl = linkCallRoute.toWebUrl({
key: callLink.rootKey,
});
@ -256,3 +261,35 @@ export function CallLinkDetails({
</div>
);
}
function renderMissingCallLink({
callHistoryGroup,
i18n,
}: Pick<CallLinkDetailsProps, 'callHistoryGroup' | 'i18n'>): JSX.Element {
return (
<div className="CallLinkDetails__Container">
<header className="CallLinkDetails__Header">
<Avatar
className="CallLinkDetails__HeaderAvatar"
i18n={i18n}
badge={undefined}
conversationType="callLink"
size={AvatarSize.SIXTY_FOUR}
acceptedMessageRequest
isMe={false}
sharedGroupNames={[]}
title={i18n('icu:calling__call-link-default-title')}
/>
<div className="CallLinkDetails__HeaderDetails">
<h1 className="CallLinkDetails__HeaderTitle">
{i18n('icu:calling__call-link-default-title')}
</h1>
</div>
</header>
<CallHistoryGroupPanelSection
callHistoryGroup={callHistoryGroup}
i18n={i18n}
/>
</div>
);
}

View file

@ -12,7 +12,6 @@ import {
} from '../selectors/calling';
import { useGlobalModalActions } from '../ducks/globalModals';
import { useCallingActions } from '../ducks/calling';
import * as log from '../../logging/log';
import { strictAssert } from '../../util/assert';
import type { CallLinkRestrictions } from '../../types/CallLink';
import { isAnybodyInGroupCall } from '../ducks/callingHelpers';
@ -77,11 +76,6 @@ export const SmartCallLinkDetails = memo(function SmartCallLinkDetails({
activeCall && callLink && activeCall.conversationId === callLink.roomId
);
if (callLink == null) {
log.error(`SmartCallLinkDetails: callLink not found for room ${roomId}`);
return null;
}
return (
<CallLinkDetails
callHistoryGroup={callHistoryGroup}

View file

@ -252,10 +252,14 @@ const peerIdInBytesSchema = z.instanceof(Uint8Array).transform(value => {
}
}
// groupId or call link roomId
// groupId
return Bytes.toBase64(value);
});
const roomIdInBytesSchema = z
.instanceof(Uint8Array)
.transform(value => Bytes.toHex(value));
const longToStringSchema = z
.instanceof(Long)
.transform(long => long.toString());
@ -264,14 +268,29 @@ const longToNumberSchema = z
.instanceof(Long)
.transform(long => long.toNumber());
export const callEventNormalizeSchema = z.object({
peerId: peerIdInBytesSchema,
export const callEventNormalizeSchema = z
.object({
callId: longToStringSchema,
timestamp: longToNumberSchema,
type: z.nativeEnum(Proto.SyncMessage.CallEvent.Type),
direction: z.nativeEnum(Proto.SyncMessage.CallEvent.Direction),
event: z.nativeEnum(Proto.SyncMessage.CallEvent.Event),
});
})
.and(
z.union([
z.object({
type: z
.nativeEnum(Proto.SyncMessage.CallEvent.Type)
.refine(val => val === Proto.SyncMessage.CallEvent.Type.AD_HOC_CALL),
peerId: roomIdInBytesSchema,
}),
z.object({
type: z
.nativeEnum(Proto.SyncMessage.CallEvent.Type)
.refine(val => val !== Proto.SyncMessage.CallEvent.Type.AD_HOC_CALL),
peerId: peerIdInBytesSchema,
}),
])
);
export const callLogEventNormalizeSchema = z.object({
type: z.nativeEnum(Proto.SyncMessage.CallLogEvent.Type),

View file

@ -338,10 +338,13 @@ function shouldSyncStatus(callStatus: CallStatus) {
return statusToProto[callStatus] != null;
}
// For outgoing sync messages. peerId contains direct or group conversationId or
// call link peerId. Locally conversationId is Base64 encoded but roomIds
// are hex encoded.
export function getBytesForPeerId(callHistory: CallHistoryDetails): Uint8Array {
let peerId =
callHistory.mode === CallMode.Adhoc
? Bytes.fromBase64(callHistory.peerId)
? Bytes.fromHex(callHistory.peerId)
: uuidToBytes(callHistory.peerId);
if (peerId.length === 0) {
peerId = Bytes.fromBase64(callHistory.peerId);