mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
Make verified notifications consistent
Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
@@ -2386,7 +2386,7 @@ export class SignalProtocolStore extends EventEmitter {
|
||||
serviceId: ServiceIdString,
|
||||
verifiedStatus: number,
|
||||
publicKey: Uint8Array
|
||||
): Promise<boolean> {
|
||||
): Promise<{ shouldAddVerifiedChangedMessage: boolean }> {
|
||||
strictAssert(
|
||||
validateVerifiedStatus(verifiedStatus),
|
||||
`Invalid verified status: ${verifiedStatus}`
|
||||
@@ -2436,23 +2436,27 @@ export class SignalProtocolStore extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
// We only want to show a notification if the key is the same as before
|
||||
if (hadEntry && !keyMatches) {
|
||||
return { shouldAddVerifiedChangedMessage: false };
|
||||
}
|
||||
|
||||
// See: https://github.com/signalapp/Signal-Android/blob/fc3db538bcaa38dc149712a483d3032c9c1f3998/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.kt#L921-L936
|
||||
if (
|
||||
verifiedStatus === VerifiedStatus.VERIFIED &&
|
||||
(!hadEntry || identityRecord?.verified !== VerifiedStatus.VERIFIED)
|
||||
) {
|
||||
// Needs a notification.
|
||||
return true;
|
||||
return { shouldAddVerifiedChangedMessage: true };
|
||||
}
|
||||
if (
|
||||
verifiedStatus !== VerifiedStatus.VERIFIED &&
|
||||
hadEntry &&
|
||||
identityRecord?.verified === VerifiedStatus.VERIFIED
|
||||
) {
|
||||
// Needs a notification.
|
||||
return true;
|
||||
return { shouldAddVerifiedChangedMessage: true };
|
||||
}
|
||||
return false;
|
||||
|
||||
return { shouldAddVerifiedChangedMessage: false };
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1512,11 +1512,12 @@ export async function mergeContactRecord(
|
||||
}
|
||||
const newVerified = fromRecordVerified(identityState);
|
||||
|
||||
const needsNotification = await signalProtocolStore.updateIdentityAfterSync(
|
||||
serviceId,
|
||||
newVerified,
|
||||
contactRecord.identityKey
|
||||
);
|
||||
const { shouldAddVerifiedChangedMessage } =
|
||||
await signalProtocolStore.updateIdentityAfterSync(
|
||||
serviceId,
|
||||
newVerified,
|
||||
contactRecord.identityKey
|
||||
);
|
||||
|
||||
if (verified !== newVerified) {
|
||||
details.push(
|
||||
@@ -1528,7 +1529,7 @@ export async function mergeContactRecord(
|
||||
}
|
||||
|
||||
const VERIFIED_ENUM = signalProtocolStore.VerifiedStatus;
|
||||
if (needsNotification) {
|
||||
if (shouldAddVerifiedChangedMessage) {
|
||||
details.push('adding a verified notification');
|
||||
await conversation.addVerifiedChange(
|
||||
conversation.id,
|
||||
|
||||
@@ -710,12 +710,13 @@ describe('SignalProtocolStore', () => {
|
||||
it('should create an identity and set verified to DEFAULT', async () => {
|
||||
const newAci = generateAci();
|
||||
|
||||
const needsNotification = await store.updateIdentityAfterSync(
|
||||
newAci,
|
||||
store.VerifiedStatus.DEFAULT,
|
||||
newIdentity
|
||||
);
|
||||
assert.isFalse(needsNotification);
|
||||
const { shouldAddVerifiedChangedMessage } =
|
||||
await store.updateIdentityAfterSync(
|
||||
newAci,
|
||||
store.VerifiedStatus.DEFAULT,
|
||||
newIdentity
|
||||
);
|
||||
assert.isFalse(shouldAddVerifiedChangedMessage);
|
||||
assert.strictEqual(keychangeTriggered, 0);
|
||||
|
||||
const identity = await DataReader.getIdentityKeyById(newAci);
|
||||
@@ -729,12 +730,13 @@ describe('SignalProtocolStore', () => {
|
||||
it('should create an identity and set verified to VERIFIED', async () => {
|
||||
const newAci = generateAci();
|
||||
|
||||
const needsNotification = await store.updateIdentityAfterSync(
|
||||
newAci,
|
||||
store.VerifiedStatus.VERIFIED,
|
||||
newIdentity
|
||||
);
|
||||
assert.isTrue(needsNotification);
|
||||
const { shouldAddVerifiedChangedMessage } =
|
||||
await store.updateIdentityAfterSync(
|
||||
newAci,
|
||||
store.VerifiedStatus.VERIFIED,
|
||||
newIdentity
|
||||
);
|
||||
assert.isTrue(shouldAddVerifiedChangedMessage);
|
||||
assert.strictEqual(keychangeTriggered, 0);
|
||||
|
||||
const identity = await DataReader.getIdentityKeyById(newAci);
|
||||
@@ -746,12 +748,13 @@ describe('SignalProtocolStore', () => {
|
||||
});
|
||||
|
||||
it('should update public key without verified change', async () => {
|
||||
const needsNotification = await store.updateIdentityAfterSync(
|
||||
theirAci,
|
||||
store.VerifiedStatus.DEFAULT,
|
||||
newIdentity
|
||||
);
|
||||
assert.isFalse(needsNotification);
|
||||
const { shouldAddVerifiedChangedMessage } =
|
||||
await store.updateIdentityAfterSync(
|
||||
theirAci,
|
||||
store.VerifiedStatus.DEFAULT,
|
||||
newIdentity
|
||||
);
|
||||
assert.isFalse(shouldAddVerifiedChangedMessage);
|
||||
assert.strictEqual(keychangeTriggered, 1);
|
||||
|
||||
const identity = await DataReader.getIdentityKeyById(theirAci);
|
||||
@@ -763,12 +766,13 @@ describe('SignalProtocolStore', () => {
|
||||
});
|
||||
|
||||
it('should update verified without public key change', async () => {
|
||||
const needsNotification = await store.updateIdentityAfterSync(
|
||||
theirAci,
|
||||
store.VerifiedStatus.VERIFIED,
|
||||
testKey.publicKey.serialize()
|
||||
);
|
||||
assert.isTrue(needsNotification);
|
||||
const { shouldAddVerifiedChangedMessage } =
|
||||
await store.updateIdentityAfterSync(
|
||||
theirAci,
|
||||
store.VerifiedStatus.VERIFIED,
|
||||
testKey.publicKey.serialize()
|
||||
);
|
||||
assert.isTrue(shouldAddVerifiedChangedMessage);
|
||||
assert.strictEqual(keychangeTriggered, 0);
|
||||
|
||||
const identity = await DataReader.getIdentityKeyById(theirAci);
|
||||
|
||||
Reference in New Issue
Block a user