Use checkAccountExistence
This commit is contained in:
parent
5c9718f268
commit
033b4830d1
2 changed files with 81 additions and 32 deletions
|
@ -98,7 +98,11 @@ describe('updateConversationsWithUuidLookup', () => {
|
|||
let sinonSandbox: sinon.SinonSandbox;
|
||||
|
||||
let fakeGetUuidsForE164s: sinon.SinonStub;
|
||||
let fakeMessaging: Pick<SendMessage, 'getUuidsForE164s'>;
|
||||
let fakeCheckAccountExistence: sinon.SinonStub;
|
||||
let fakeMessaging: Pick<
|
||||
SendMessage,
|
||||
'getUuidsForE164s' | 'checkAccountExistence'
|
||||
>;
|
||||
|
||||
beforeEach(() => {
|
||||
sinonSandbox = sinon.createSandbox();
|
||||
|
@ -106,7 +110,11 @@ describe('updateConversationsWithUuidLookup', () => {
|
|||
sinonSandbox.stub(window.Signal.Data, 'updateConversation');
|
||||
|
||||
fakeGetUuidsForE164s = sinonSandbox.stub().resolves({});
|
||||
fakeMessaging = { getUuidsForE164s: fakeGetUuidsForE164s };
|
||||
fakeCheckAccountExistence = sinonSandbox.stub().resolves(false);
|
||||
fakeMessaging = {
|
||||
getUuidsForE164s: fakeGetUuidsForE164s,
|
||||
checkAccountExistence: fakeCheckAccountExistence,
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -186,7 +194,7 @@ describe('updateConversationsWithUuidLookup', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it("doesn't mark conversations unregistered if we already had a UUID for them, even if the server doesn't return one", async () => {
|
||||
it("doesn't mark conversations unregistered if we already had a UUID for them, even if the account exists on server", async () => {
|
||||
const existingUuid = UUID.generate().toString();
|
||||
const conversation = createConversation({
|
||||
e164: '+13215559876',
|
||||
|
@ -198,6 +206,7 @@ describe('updateConversationsWithUuidLookup', () => {
|
|||
);
|
||||
|
||||
fakeGetUuidsForE164s.resolves({ '+13215559876': null });
|
||||
fakeCheckAccountExistence.resolves(true);
|
||||
|
||||
await updateConversationsWithUuidLookup({
|
||||
conversationController: new FakeConversationController([conversation]),
|
||||
|
@ -208,4 +217,28 @@ describe('updateConversationsWithUuidLookup', () => {
|
|||
assert.strictEqual(conversation.get('uuid'), existingUuid);
|
||||
assert.isUndefined(conversation.get('discoveredUnregisteredAt'));
|
||||
});
|
||||
|
||||
it('marks conversations unregistered if we already had a UUID for them, even if the account does not exist on server', async () => {
|
||||
const existingUuid = UUID.generate().toString();
|
||||
const conversation = createConversation({
|
||||
e164: '+13215559876',
|
||||
uuid: existingUuid,
|
||||
});
|
||||
assert.isUndefined(
|
||||
conversation.get('discoveredUnregisteredAt'),
|
||||
'Test was not set up correctly'
|
||||
);
|
||||
|
||||
fakeGetUuidsForE164s.resolves({ '+13215559876': null });
|
||||
fakeCheckAccountExistence.resolves(false);
|
||||
|
||||
await updateConversationsWithUuidLookup({
|
||||
conversationController: new FakeConversationController([conversation]),
|
||||
conversations: [conversation],
|
||||
messaging: fakeMessaging,
|
||||
});
|
||||
|
||||
assert.strictEqual(conversation.get('uuid'), existingUuid);
|
||||
assert.isNumber(conversation.get('discoveredUnregisteredAt'));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@ export async function updateConversationsWithUuidLookup({
|
|||
'ensureContactIds' | 'get'
|
||||
>;
|
||||
conversations: ReadonlyArray<ConversationModel>;
|
||||
messaging: Pick<SendMessage, 'getUuidsForE164s'>;
|
||||
messaging: Pick<SendMessage, 'getUuidsForE164s' | 'checkAccountExistence'>;
|
||||
}>): Promise<void> {
|
||||
const e164s = conversations
|
||||
.map(conversation => conversation.get('e164'))
|
||||
|
@ -29,35 +29,51 @@ export async function updateConversationsWithUuidLookup({
|
|||
|
||||
const serverLookup = await messaging.getUuidsForE164s(e164s);
|
||||
|
||||
conversations.forEach(conversation => {
|
||||
const e164 = conversation.get('e164');
|
||||
if (!e164) {
|
||||
return;
|
||||
}
|
||||
await Promise.all(
|
||||
conversations.map(async conversation => {
|
||||
const e164 = conversation.get('e164');
|
||||
if (!e164) {
|
||||
return;
|
||||
}
|
||||
|
||||
let finalConversation: ConversationModel;
|
||||
let finalConversation: ConversationModel;
|
||||
|
||||
const uuidFromServer = getOwn(serverLookup, e164);
|
||||
if (uuidFromServer) {
|
||||
const finalConversationId = conversationController.ensureContactIds({
|
||||
e164,
|
||||
uuid: uuidFromServer,
|
||||
highTrust: true,
|
||||
reason: 'updateConversationsWithUuidLookup',
|
||||
});
|
||||
const maybeFinalConversation =
|
||||
conversationController.get(finalConversationId);
|
||||
assert(
|
||||
maybeFinalConversation,
|
||||
'updateConversationsWithUuidLookup: expected a conversation to be found or created'
|
||||
);
|
||||
finalConversation = maybeFinalConversation;
|
||||
} else {
|
||||
finalConversation = conversation;
|
||||
}
|
||||
const uuidFromServer = getOwn(serverLookup, e164);
|
||||
if (uuidFromServer) {
|
||||
const finalConversationId = conversationController.ensureContactIds({
|
||||
e164,
|
||||
uuid: uuidFromServer,
|
||||
highTrust: true,
|
||||
reason: 'updateConversationsWithUuidLookup',
|
||||
});
|
||||
const maybeFinalConversation =
|
||||
conversationController.get(finalConversationId);
|
||||
assert(
|
||||
maybeFinalConversation,
|
||||
'updateConversationsWithUuidLookup: expected a conversation to be found or created'
|
||||
);
|
||||
finalConversation = maybeFinalConversation;
|
||||
} else {
|
||||
finalConversation = conversation;
|
||||
}
|
||||
|
||||
if (!finalConversation.get('e164') || !finalConversation.get('uuid')) {
|
||||
finalConversation.setUnregistered();
|
||||
}
|
||||
});
|
||||
// We got no uuid from CDS so either the person is now unregistered or
|
||||
// they can't be looked up by a phone number. Check that uuid still exists,
|
||||
// and if not - drop it.
|
||||
let finalUuid = finalConversation.getUuid();
|
||||
if (!uuidFromServer && finalUuid) {
|
||||
const doesAccountExist = await messaging.checkAccountExistence(
|
||||
finalUuid
|
||||
);
|
||||
if (!doesAccountExist) {
|
||||
finalConversation.updateUuid(undefined);
|
||||
finalUuid = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
if (!finalConversation.get('e164') || !finalUuid) {
|
||||
finalConversation.setUnregistered();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue