fix: fixed legacy disappearing messages on call notifications and others

pull/2660/head
William Grant 3 years ago
parent f7e5719eac
commit e5ecff7ec3

@ -774,6 +774,8 @@ export async function handleDataExtractionNotification(
const envelopeTimestamp = toNumber(timestamp); const envelopeTimestamp = toNumber(timestamp);
const referencedAttachmentTimestamp = toNumber(referencedAttachment); const referencedAttachmentTimestamp = toNumber(referencedAttachment);
const expirationType = convo.get('expirationType'); const expirationType = convo.get('expirationType');
// TODO legacy messages support will be removed in a future release
const isLegacyMode = convo && convo.isPrivate() && expirationType === 'legacy';
await convo.addSingleIncomingMessage({ await convo.addSingleIncomingMessage({
source, source,
@ -787,7 +789,10 @@ export async function handleDataExtractionNotification(
expirationType: expirationType !== 'off' ? expirationType : undefined, expirationType: expirationType !== 'off' ? expirationType : undefined,
expireTimer: convo.get('expireTimer') ? convo.get('expireTimer') : 0, expireTimer: convo.get('expireTimer') ? convo.get('expireTimer') : 0,
// TODO should this only be for delete after send? // TODO should this only be for delete after send?
expirationStartTimestamp: setExpirationStartTimestamp(expirationType), expirationStartTimestamp:
isLegacyMode || expirationType === 'deleteAfterSend'
? setExpirationStartTimestamp('deleteAfterSend', undefined, isLegacyMode)
: undefined,
}); });
convo.updateLastMessage(); convo.updateLastMessage();
} }

@ -345,7 +345,8 @@ export async function handleMessageJob(
messageModel.set({ messageModel.set({
expirationStartTimestamp: setExpirationStartTimestamp( expirationStartTimestamp: setExpirationStartTimestamp(
'deleteAfterSend', 'deleteAfterSend',
messageModel.get('sent_at') messageModel.get('sent_at'),
messageModel.get('expirationType') === 'legacy'
), ),
}); });
} }

@ -180,7 +180,10 @@ export async function addUpdateMessage(
group_update: groupUpdate, group_update: groupUpdate,
expirationType: expirationType || undefined, expirationType: expirationType || undefined,
expireTimer: expireTimer || 0, expireTimer: expireTimer || 0,
expirationStartTimestamp: setExpirationStartTimestamp(expirationType, sentAt), // closed groups are always deleteAfterSend
expirationStartTimestamp: expirationType
? setExpirationStartTimestamp('deleteAfterSend', sentAt, expirationType === 'legacy')
: undefined,
}; };
if (UserUtils.isUsFromCache(sender)) { if (UserUtils.isUsFromCache(sender)) {

@ -147,7 +147,8 @@ async function handleMessageSentSuccess(
fetchedMessage.set({ fetchedMessage.set({
expirationStartTimestamp: setExpirationStartTimestamp( expirationStartTimestamp: setExpirationStartTimestamp(
'deleteAfterSend', 'deleteAfterSend',
fetchedMessage.get('sent_at') fetchedMessage.get('sent_at'),
isLegacySentMode
), ),
}); });
} }

@ -504,7 +504,9 @@ export async function USER_callRecipient(recipient: string) {
calledConvo.set('active_at', Date.now()); // addSingleOutgoingMessage does the commit for us on the convo calledConvo.set('active_at', Date.now()); // addSingleOutgoingMessage does the commit for us on the convo
weAreCallerOnCurrentCall = true; weAreCallerOnCurrentCall = true;
const expirationType = calledConvo.get('expirationType'); // TODO legacy messages support will be removed in a future release
const isLegacyMode = calledConvo.get('expirationType') !== 'legacy';
const expirationType = isLegacyMode ? calledConvo.get('expirationType') : 'deleteAfterSend';
await calledConvo?.addSingleOutgoingMessage({ await calledConvo?.addSingleOutgoingMessage({
callNotificationType: 'started-call', callNotificationType: 'started-call',
sent_at: now, sent_at: now,
@ -512,7 +514,8 @@ export async function USER_callRecipient(recipient: string) {
expireTimer: calledConvo.get('expireTimer') ? calledConvo.get('expireTimer') : 0, expireTimer: calledConvo.get('expireTimer') ? calledConvo.get('expireTimer') : 0,
expirationStartTimestamp: setExpirationStartTimestamp( expirationStartTimestamp: setExpirationStartTimestamp(
expirationType, expirationType,
expirationType === 'deleteAfterSend' ? now : undefined expirationType === 'deleteAfterSend' ? now : undefined,
isLegacyMode
), ),
}); });
@ -804,8 +807,15 @@ export async function USER_acceptIncomingCallRequest(fromSender: string) {
window?.log?.info('incoming call request cannot be accepted as uuid is invalid'); window?.log?.info('incoming call request cannot be accepted as uuid is invalid');
return; return;
} }
window.inboxStore?.dispatch(answerCall({ pubkey: fromSender })); window.inboxStore?.dispatch(
await openConversationWithMessages({ conversationKey: fromSender, messageId: null }); answerCall({
pubkey: fromSender,
})
);
await openConversationWithMessages({
conversationKey: fromSender,
messageId: null,
});
if (peerConnection) { if (peerConnection) {
throw new Error('USER_acceptIncomingCallRequest: peerConnection is already set.'); throw new Error('USER_acceptIncomingCallRequest: peerConnection is already set.');
} }
@ -824,7 +834,10 @@ export async function USER_acceptIncomingCallRequest(fromSender: string) {
} }
try { try {
await peerConnection.setRemoteDescription( await peerConnection.setRemoteDescription(
new RTCSessionDescription({ sdp: sdps[0], type: 'offer' }) new RTCSessionDescription({
sdp: sdps[0],
type: 'offer',
})
); );
} catch (e) { } catch (e) {
window.log?.error(`Error setting RTC Session Description ${e}`); window.log?.error(`Error setting RTC Session Description ${e}`);
@ -841,7 +854,11 @@ export async function USER_acceptIncomingCallRequest(fromSender: string) {
const sdp = lastCandidatesFromSender.sdps[index]; const sdp = lastCandidatesFromSender.sdps[index];
const sdpMLineIndex = lastCandidatesFromSender.sdpMLineIndexes[index]; const sdpMLineIndex = lastCandidatesFromSender.sdpMLineIndexes[index];
const sdpMid = lastCandidatesFromSender.sdpMids[index]; const sdpMid = lastCandidatesFromSender.sdpMids[index];
const candicate = new RTCIceCandidate({ sdpMid, sdpMLineIndex, candidate: sdp }); const candicate = new RTCIceCandidate({
sdpMid,
sdpMLineIndex,
candidate: sdp,
});
await peerConnection.addIceCandidate(candicate); await peerConnection.addIceCandidate(candicate);
} }
} }
@ -849,7 +866,9 @@ export async function USER_acceptIncomingCallRequest(fromSender: string) {
const callerConvo = getConversationController().get(fromSender); const callerConvo = getConversationController().get(fromSender);
callerConvo.set('active_at', networkTimestamp); callerConvo.set('active_at', networkTimestamp);
const expirationType = callerConvo.get('expirationType'); // TODO legacy messages support will be removed in a future release
const isLegacyMode = callerConvo.get('expirationType') !== 'legacy';
const expirationType = isLegacyMode ? callerConvo.get('expirationType') : 'deleteAfterSend';
await callerConvo?.addSingleIncomingMessage({ await callerConvo?.addSingleIncomingMessage({
callNotificationType: 'answered-a-call', callNotificationType: 'answered-a-call',
source: UserUtils.getOurPubKeyStrFromCache(), source: UserUtils.getOurPubKeyStrFromCache(),
@ -860,7 +879,8 @@ export async function USER_acceptIncomingCallRequest(fromSender: string) {
expireTimer: callerConvo.get('expireTimer') ? callerConvo.get('expireTimer') : 0, expireTimer: callerConvo.get('expireTimer') ? callerConvo.get('expireTimer') : 0,
expirationStartTimestamp: setExpirationStartTimestamp( expirationStartTimestamp: setExpirationStartTimestamp(
expirationType, expirationType,
expirationType === 'deleteAfterSend' ? networkTimestamp : undefined expirationType === 'deleteAfterSend' ? networkTimestamp : undefined,
isLegacyMode
), ),
}); });
await buildAnswerAndSendIt(fromSender); await buildAnswerAndSendIt(fromSender);
@ -1181,7 +1201,11 @@ async function addMissedCallMessage(callerPubkey: string, sentAt: number) {
incomingCallConversation.set('active_at', getNowWithNetworkOffset()); incomingCallConversation.set('active_at', getNowWithNetworkOffset());
} }
const expirationType = incomingCallConversation.get('expirationType'); // TODO legacy messages support will be removed in a future release
const isLegacyMode = incomingCallConversation.get('expirationType') !== 'legacy';
const expirationType = isLegacyMode
? incomingCallConversation.get('expirationType')
: 'deleteAfterSend';
await incomingCallConversation?.addSingleIncomingMessage({ await incomingCallConversation?.addSingleIncomingMessage({
callNotificationType: 'missed-call', callNotificationType: 'missed-call',
source: callerPubkey, source: callerPubkey,
@ -1194,7 +1218,8 @@ async function addMissedCallMessage(callerPubkey: string, sentAt: number) {
: 0, : 0,
expirationStartTimestamp: setExpirationStartTimestamp( expirationStartTimestamp: setExpirationStartTimestamp(
expirationType, expirationType,
expirationType === 'deleteAfterSend' ? sentAt : undefined expirationType === 'deleteAfterSend' ? sentAt : undefined,
isLegacyMode
), ),
}); });
} }

@ -282,7 +282,6 @@ export async function checkForExpireUpdate(
convoToUpdate: ConversationModel, convoToUpdate: ConversationModel,
content: SignalService.Content content: SignalService.Content
): Promise<DisappearingMessageUpdate | undefined> { ): Promise<DisappearingMessageUpdate | undefined> {
// debugger;
const dataMessage = content.dataMessage as SignalService.DataMessage; const dataMessage = content.dataMessage as SignalService.DataMessage;
// We will only support legacy disappearing messages for a short period before disappearing messages v2 is unlocked // We will only support legacy disappearing messages for a short period before disappearing messages v2 is unlocked
const isDisappearingMessagesV2Released = await checkIsFeatureReleased('Disappearing Messages V2'); const isDisappearingMessagesV2Released = await checkIsFeatureReleased('Disappearing Messages V2');

Loading…
Cancel
Save