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