Sync call link create/update
This commit is contained in:
parent
554f5dbe7a
commit
92ca681d3a
3 changed files with 52 additions and 19 deletions
|
@ -158,6 +158,7 @@ import type {
|
||||||
} from '../types/CallLink';
|
} from '../types/CallLink';
|
||||||
import { CallLinkRestrictions } from '../types/CallLink';
|
import { CallLinkRestrictions } from '../types/CallLink';
|
||||||
import { getConversationIdForLogging } from '../util/idForLogging';
|
import { getConversationIdForLogging } from '../util/idForLogging';
|
||||||
|
import { sendCallLinkUpdateSync } from '../util/sendCallLinkUpdateSync';
|
||||||
|
|
||||||
const { wasGroupCallRingPreviouslyCanceled } = DataReader;
|
const { wasGroupCallRingPreviouslyCanceled } = DataReader;
|
||||||
const {
|
const {
|
||||||
|
@ -671,12 +672,16 @@ export class CallingClass {
|
||||||
log.info(`${logId}: success`);
|
log.info(`${logId}: success`);
|
||||||
const state = callLinkStateFromRingRTC(result.value);
|
const state = callLinkStateFromRingRTC(result.value);
|
||||||
|
|
||||||
return {
|
const callLink: CallLinkType = {
|
||||||
roomId: roomIdHex,
|
roomId: roomIdHex,
|
||||||
rootKey: rootKey.toString(),
|
rootKey: rootKey.toString(),
|
||||||
adminKey: adminKey.toString('base64'),
|
adminKey: adminKey.toString('base64'),
|
||||||
...state,
|
...state,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
drop(sendCallLinkUpdateSync(callLink));
|
||||||
|
|
||||||
|
return callLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateCallLinkName(
|
async updateCallLinkName(
|
||||||
|
@ -711,6 +716,8 @@ export class CallingClass {
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop(sendCallLinkUpdateSync(callLink));
|
||||||
|
|
||||||
log.info(`${logId}: success`);
|
log.info(`${logId}: success`);
|
||||||
return callLinkStateFromRingRTC(result.value);
|
return callLinkStateFromRingRTC(result.value);
|
||||||
}
|
}
|
||||||
|
@ -754,6 +761,8 @@ export class CallingClass {
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop(sendCallLinkUpdateSync(callLink));
|
||||||
|
|
||||||
log.info(`${logId}: success`);
|
log.info(`${logId}: success`);
|
||||||
return callLinkStateFromRingRTC(result.value);
|
return callLinkStateFromRingRTC(result.value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import {
|
||||||
GroupCallEndReason,
|
GroupCallEndReason,
|
||||||
type Reaction as CallReaction,
|
type Reaction as CallReaction,
|
||||||
} from '@signalapp/ringrtc';
|
} from '@signalapp/ringrtc';
|
||||||
import { v4 as generateUuid } from 'uuid';
|
|
||||||
import { getOwn } from '../../util/getOwn';
|
import { getOwn } from '../../util/getOwn';
|
||||||
import * as Errors from '../../types/errors';
|
import * as Errors from '../../types/errors';
|
||||||
import { getIntl, getPlatform } from '../selectors/user';
|
import { getIntl, getPlatform } from '../selectors/user';
|
||||||
|
@ -55,6 +54,7 @@ import {
|
||||||
getRoomIdFromRootKey,
|
getRoomIdFromRootKey,
|
||||||
isCallLinksCreateEnabled,
|
isCallLinksCreateEnabled,
|
||||||
toAdminKeyBytes,
|
toAdminKeyBytes,
|
||||||
|
toCallHistoryFromUnusedCallLink,
|
||||||
} from '../../util/callLinks';
|
} from '../../util/callLinks';
|
||||||
import { sendCallLinkUpdateSync } from '../../util/sendCallLinkUpdateSync';
|
import { sendCallLinkUpdateSync } from '../../util/sendCallLinkUpdateSync';
|
||||||
import { sleep } from '../../util/sleep';
|
import { sleep } from '../../util/sleep';
|
||||||
|
@ -88,15 +88,10 @@ import { ButtonVariant } from '../../components/Button';
|
||||||
import { getConversationIdForLogging } from '../../util/idForLogging';
|
import { getConversationIdForLogging } from '../../util/idForLogging';
|
||||||
import { DataReader, DataWriter } from '../../sql/Client';
|
import { DataReader, DataWriter } from '../../sql/Client';
|
||||||
import { isAciString } from '../../util/isAciString';
|
import { isAciString } from '../../util/isAciString';
|
||||||
import type { CallHistoryDetails } from '../../types/CallDisposition';
|
|
||||||
import {
|
|
||||||
AdhocCallStatus,
|
|
||||||
CallDirection,
|
|
||||||
CallType,
|
|
||||||
} from '../../types/CallDisposition';
|
|
||||||
import type { CallHistoryAdd } from './callHistory';
|
import type { CallHistoryAdd } from './callHistory';
|
||||||
import { addCallHistory } from './callHistory';
|
import { addCallHistory } from './callHistory';
|
||||||
import { saveDraftRecordingIfNeeded } from './composer';
|
import { saveDraftRecordingIfNeeded } from './composer';
|
||||||
|
import type { CallHistoryDetails } from '../../types/CallDisposition';
|
||||||
|
|
||||||
// State
|
// State
|
||||||
|
|
||||||
|
@ -1396,7 +1391,12 @@ function groupCallStateChange(
|
||||||
// From sync messages, to notify us that another device joined or changed a call link.
|
// From sync messages, to notify us that another device joined or changed a call link.
|
||||||
function handleCallLinkUpdate(
|
function handleCallLinkUpdate(
|
||||||
payload: HandleCallLinkUpdateType
|
payload: HandleCallLinkUpdateType
|
||||||
): ThunkAction<void, RootStateType, unknown, HandleCallLinkUpdateActionType> {
|
): ThunkAction<
|
||||||
|
void,
|
||||||
|
RootStateType,
|
||||||
|
unknown,
|
||||||
|
HandleCallLinkUpdateActionType | CallHistoryAdd
|
||||||
|
> {
|
||||||
return async dispatch => {
|
return async dispatch => {
|
||||||
const { rootKey, adminKey } = payload;
|
const { rootKey, adminKey } = payload;
|
||||||
const callLinkRootKey = CallLinkRootKey.parse(rootKey);
|
const callLinkRootKey = CallLinkRootKey.parse(rootKey);
|
||||||
|
@ -1432,6 +1432,8 @@ function handleCallLinkUpdate(
|
||||||
adminKey,
|
adminKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let callHistory: CallHistoryDetails | null = null;
|
||||||
|
|
||||||
if (existingCallLink) {
|
if (existingCallLink) {
|
||||||
if (adminKey && adminKey !== existingCallLink.adminKey) {
|
if (adminKey && adminKey !== existingCallLink.adminKey) {
|
||||||
await DataWriter.updateCallLinkAdminKeyByRoomId(roomId, adminKey);
|
await DataWriter.updateCallLinkAdminKeyByRoomId(roomId, adminKey);
|
||||||
|
@ -1444,6 +1446,10 @@ function handleCallLinkUpdate(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await DataWriter.insertCallLink(callLink);
|
await DataWriter.insertCallLink(callLink);
|
||||||
|
if (adminKey != null) {
|
||||||
|
callHistory = toCallHistoryFromUnusedCallLink(callLink);
|
||||||
|
await DataWriter.saveCallHistory(callHistory);
|
||||||
|
}
|
||||||
log.info(`${logId}: Saved new call link`);
|
log.info(`${logId}: Saved new call link`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1451,6 +1457,10 @@ function handleCallLinkUpdate(
|
||||||
type: HANDLE_CALL_LINK_UPDATE,
|
type: HANDLE_CALL_LINK_UPDATE,
|
||||||
payload: { callLink },
|
payload: { callLink },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (callHistory != null) {
|
||||||
|
dispatch(addCallHistory(callHistory));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1974,16 +1984,7 @@ function createCallLink(
|
||||||
strictAssert(isCallLinksCreateEnabled(), 'Call links creation is disabled');
|
strictAssert(isCallLinksCreateEnabled(), 'Call links creation is disabled');
|
||||||
|
|
||||||
const callLink = await calling.createCallLink();
|
const callLink = await calling.createCallLink();
|
||||||
const callHistory: CallHistoryDetails = {
|
const callHistory = toCallHistoryFromUnusedCallLink(callLink);
|
||||||
callId: generateUuid(),
|
|
||||||
peerId: callLink.roomId,
|
|
||||||
ringerId: null,
|
|
||||||
mode: CallMode.Adhoc,
|
|
||||||
type: CallType.Adhoc,
|
|
||||||
direction: CallDirection.Incoming,
|
|
||||||
timestamp: Date.now(),
|
|
||||||
status: AdhocCallStatus.Pending,
|
|
||||||
};
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
DataWriter.insertCallLink(callLink),
|
DataWriter.insertCallLink(callLink),
|
||||||
DataWriter.saveCallHistory(callHistory),
|
DataWriter.saveCallHistory(callHistory),
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
} from '@signalapp/ringrtc';
|
} from '@signalapp/ringrtc';
|
||||||
import { Aci } from '@signalapp/libsignal-client';
|
import { Aci } from '@signalapp/libsignal-client';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import { v4 as generateUuid } from 'uuid';
|
||||||
import * as RemoteConfig from '../RemoteConfig';
|
import * as RemoteConfig from '../RemoteConfig';
|
||||||
import type { CallLinkAuthCredentialPresentation } from './zkgroup';
|
import type { CallLinkAuthCredentialPresentation } from './zkgroup';
|
||||||
import {
|
import {
|
||||||
|
@ -31,6 +32,13 @@ import {
|
||||||
import type { LocalizerType } from '../types/Util';
|
import type { LocalizerType } from '../types/Util';
|
||||||
import { isTestOrMockEnvironment } from '../environment';
|
import { isTestOrMockEnvironment } from '../environment';
|
||||||
import { getColorForCallLink } from './getColorForCallLink';
|
import { getColorForCallLink } from './getColorForCallLink';
|
||||||
|
import {
|
||||||
|
AdhocCallStatus,
|
||||||
|
CallDirection,
|
||||||
|
CallType,
|
||||||
|
type CallHistoryDetails,
|
||||||
|
} from '../types/CallDisposition';
|
||||||
|
import { CallMode } from '../types/Calling';
|
||||||
|
|
||||||
export const CALL_LINK_DEFAULT_STATE = {
|
export const CALL_LINK_DEFAULT_STATE = {
|
||||||
name: '',
|
name: '',
|
||||||
|
@ -204,3 +212,18 @@ export function callLinkFromRecord(record: CallLinkRecord): CallLinkType {
|
||||||
expiration: record.expiration,
|
expiration: record.expiration,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toCallHistoryFromUnusedCallLink(
|
||||||
|
callLink: CallLinkType
|
||||||
|
): CallHistoryDetails {
|
||||||
|
return {
|
||||||
|
callId: generateUuid(),
|
||||||
|
peerId: callLink.roomId,
|
||||||
|
ringerId: null,
|
||||||
|
mode: CallMode.Adhoc,
|
||||||
|
type: CallType.Adhoc,
|
||||||
|
direction: CallDirection.Incoming,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
status: AdhocCallStatus.Pending,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue