Add 'chat session refreshed' to timeline for every error
This commit is contained in:
parent
733c86ee8e
commit
1ee47735d9
1 changed files with 46 additions and 36 deletions
|
@ -1106,7 +1106,7 @@ class MessageReceiverInner extends EventTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uuid && deviceId) {
|
if (uuid && deviceId) {
|
||||||
await this.lightSessionReset(uuid, deviceId);
|
await this.maybeLightSessionReset(uuid, deviceId);
|
||||||
} else {
|
} else {
|
||||||
const envelopeId = this.getEnvelopeId(envelope);
|
const envelopeId = this.getEnvelopeId(envelope);
|
||||||
window.log.error(
|
window.log.error(
|
||||||
|
@ -1145,7 +1145,7 @@ class MessageReceiverInner extends EventTarget {
|
||||||
window.storage.put('sessionResets', sessionResets);
|
window.storage.put('sessionResets', sessionResets);
|
||||||
}
|
}
|
||||||
|
|
||||||
async lightSessionReset(uuid: string, deviceId: number) {
|
async maybeLightSessionReset(uuid: string, deviceId: number): Promise<void> {
|
||||||
const id = `${uuid}.${deviceId}`;
|
const id = `${uuid}.${deviceId}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1155,31 +1155,58 @@ class MessageReceiverInner extends EventTarget {
|
||||||
) as SessionResetsType;
|
) as SessionResetsType;
|
||||||
const lastReset = sessionResets[id];
|
const lastReset = sessionResets[id];
|
||||||
|
|
||||||
|
// We emit this event every time we encounter an error, not just when we reset the
|
||||||
|
// session. This is because a message might have been lost with every decryption
|
||||||
|
// failure.
|
||||||
|
const event = new Event('light-session-reset');
|
||||||
|
event.senderUuid = uuid;
|
||||||
|
this.dispatchAndWait(event);
|
||||||
|
|
||||||
if (lastReset && !this.isOverHourIntoPast(lastReset)) {
|
if (lastReset && !this.isOverHourIntoPast(lastReset)) {
|
||||||
window.log.warn(
|
window.log.warn(
|
||||||
`lightSessionReset: Skipping session reset for ${id}, last reset at ${lastReset}`
|
`maybeLightSessionReset/${id}: Skipping session reset, last reset at ${lastReset}`
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionResets[id] = Date.now();
|
sessionResets[id] = Date.now();
|
||||||
window.storage.put('sessionResets', sessionResets);
|
window.storage.put('sessionResets', sessionResets);
|
||||||
|
|
||||||
|
await this.lightSessionReset(uuid, deviceId);
|
||||||
|
} catch (error) {
|
||||||
|
// If we failed to do the session reset, then we'll allow another attempt sooner
|
||||||
|
// than one hour from now.
|
||||||
|
const sessionResets = window.storage.get(
|
||||||
|
'sessionResets',
|
||||||
|
{}
|
||||||
|
) as SessionResetsType;
|
||||||
|
delete sessionResets[id];
|
||||||
|
window.storage.put('sessionResets', sessionResets);
|
||||||
|
|
||||||
|
const errorString = error && error.stack ? error.stack : error;
|
||||||
|
window.log.error(
|
||||||
|
`maybeLightSessionReset/${id}: Enountered error`,
|
||||||
|
errorString
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async lightSessionReset(uuid: string, deviceId: number): Promise<void> {
|
||||||
|
const id = `${uuid}.${deviceId}`;
|
||||||
|
|
||||||
// First, fetch this conversation
|
// First, fetch this conversation
|
||||||
const conversationId = window.ConversationController.ensureContactIds({
|
const conversationId = window.ConversationController.ensureContactIds({
|
||||||
uuid,
|
uuid,
|
||||||
});
|
});
|
||||||
assert(conversationId, 'lightSessionReset: missing conversationId');
|
assert(conversationId, `lightSessionReset/${id}: missing conversationId`);
|
||||||
|
|
||||||
const conversation = window.ConversationController.get(conversationId);
|
const conversation = window.ConversationController.get(conversationId);
|
||||||
assert(conversation, 'lightSessionReset: missing conversation');
|
assert(conversation, `lightSessionReset/${id}: missing conversation`);
|
||||||
|
|
||||||
window.log.warn(`lightSessionReset: Resetting session for ${id}`);
|
window.log.warn(`lightSessionReset/${id}: Resetting session`);
|
||||||
|
|
||||||
// Archive open session with this device
|
// Archive open session with this device
|
||||||
const address = new window.libsignal.SignalProtocolAddress(
|
const address = new window.libsignal.SignalProtocolAddress(uuid, deviceId);
|
||||||
uuid,
|
|
||||||
deviceId
|
|
||||||
);
|
|
||||||
const sessionCipher = new window.libsignal.SessionCipher(
|
const sessionCipher = new window.libsignal.SessionCipher(
|
||||||
window.textsecure.storage.protocol,
|
window.textsecure.storage.protocol,
|
||||||
address
|
address
|
||||||
|
@ -1190,23 +1217,6 @@ class MessageReceiverInner extends EventTarget {
|
||||||
// Send a null message with newly-created session
|
// Send a null message with newly-created session
|
||||||
const sendOptions = conversation.getSendOptions();
|
const sendOptions = conversation.getSendOptions();
|
||||||
await window.textsecure.messaging.sendNullMessage({ uuid }, sendOptions);
|
await window.textsecure.messaging.sendNullMessage({ uuid }, sendOptions);
|
||||||
|
|
||||||
// Emit event for app to put item into conversation timeline
|
|
||||||
const event = new Event('light-session-reset');
|
|
||||||
event.senderUuid = uuid;
|
|
||||||
await this.dispatchAndWait(event);
|
|
||||||
} catch (error) {
|
|
||||||
// If we failed to do the session reset, then we'll allow another attempt
|
|
||||||
const sessionResets = window.storage.get(
|
|
||||||
'sessionResets',
|
|
||||||
{}
|
|
||||||
) as SessionResetsType;
|
|
||||||
delete sessionResets[id];
|
|
||||||
window.storage.put('sessionResets', sessionResets);
|
|
||||||
|
|
||||||
const errorString = error && error.stack ? error.stack : error;
|
|
||||||
window.log.error('lightSessionReset: Enountered error', errorString);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async decryptPreKeyWhisperMessage(
|
async decryptPreKeyWhisperMessage(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue