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 sinonSandbox: sinon.SinonSandbox;
|
||||||
|
|
||||||
let fakeGetUuidsForE164s: sinon.SinonStub;
|
let fakeGetUuidsForE164s: sinon.SinonStub;
|
||||||
let fakeMessaging: Pick<SendMessage, 'getUuidsForE164s'>;
|
let fakeCheckAccountExistence: sinon.SinonStub;
|
||||||
|
let fakeMessaging: Pick<
|
||||||
|
SendMessage,
|
||||||
|
'getUuidsForE164s' | 'checkAccountExistence'
|
||||||
|
>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
sinonSandbox = sinon.createSandbox();
|
sinonSandbox = sinon.createSandbox();
|
||||||
|
@ -106,7 +110,11 @@ describe('updateConversationsWithUuidLookup', () => {
|
||||||
sinonSandbox.stub(window.Signal.Data, 'updateConversation');
|
sinonSandbox.stub(window.Signal.Data, 'updateConversation');
|
||||||
|
|
||||||
fakeGetUuidsForE164s = sinonSandbox.stub().resolves({});
|
fakeGetUuidsForE164s = sinonSandbox.stub().resolves({});
|
||||||
fakeMessaging = { getUuidsForE164s: fakeGetUuidsForE164s };
|
fakeCheckAccountExistence = sinonSandbox.stub().resolves(false);
|
||||||
|
fakeMessaging = {
|
||||||
|
getUuidsForE164s: fakeGetUuidsForE164s,
|
||||||
|
checkAccountExistence: fakeCheckAccountExistence,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
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 existingUuid = UUID.generate().toString();
|
||||||
const conversation = createConversation({
|
const conversation = createConversation({
|
||||||
e164: '+13215559876',
|
e164: '+13215559876',
|
||||||
|
@ -198,6 +206,7 @@ describe('updateConversationsWithUuidLookup', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
fakeGetUuidsForE164s.resolves({ '+13215559876': null });
|
fakeGetUuidsForE164s.resolves({ '+13215559876': null });
|
||||||
|
fakeCheckAccountExistence.resolves(true);
|
||||||
|
|
||||||
await updateConversationsWithUuidLookup({
|
await updateConversationsWithUuidLookup({
|
||||||
conversationController: new FakeConversationController([conversation]),
|
conversationController: new FakeConversationController([conversation]),
|
||||||
|
@ -208,4 +217,28 @@ describe('updateConversationsWithUuidLookup', () => {
|
||||||
assert.strictEqual(conversation.get('uuid'), existingUuid);
|
assert.strictEqual(conversation.get('uuid'), existingUuid);
|
||||||
assert.isUndefined(conversation.get('discoveredUnregisteredAt'));
|
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'
|
'ensureContactIds' | 'get'
|
||||||
>;
|
>;
|
||||||
conversations: ReadonlyArray<ConversationModel>;
|
conversations: ReadonlyArray<ConversationModel>;
|
||||||
messaging: Pick<SendMessage, 'getUuidsForE164s'>;
|
messaging: Pick<SendMessage, 'getUuidsForE164s' | 'checkAccountExistence'>;
|
||||||
}>): Promise<void> {
|
}>): Promise<void> {
|
||||||
const e164s = conversations
|
const e164s = conversations
|
||||||
.map(conversation => conversation.get('e164'))
|
.map(conversation => conversation.get('e164'))
|
||||||
|
@ -29,35 +29,51 @@ export async function updateConversationsWithUuidLookup({
|
||||||
|
|
||||||
const serverLookup = await messaging.getUuidsForE164s(e164s);
|
const serverLookup = await messaging.getUuidsForE164s(e164s);
|
||||||
|
|
||||||
conversations.forEach(conversation => {
|
await Promise.all(
|
||||||
const e164 = conversation.get('e164');
|
conversations.map(async conversation => {
|
||||||
if (!e164) {
|
const e164 = conversation.get('e164');
|
||||||
return;
|
if (!e164) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let finalConversation: ConversationModel;
|
let finalConversation: ConversationModel;
|
||||||
|
|
||||||
const uuidFromServer = getOwn(serverLookup, e164);
|
const uuidFromServer = getOwn(serverLookup, e164);
|
||||||
if (uuidFromServer) {
|
if (uuidFromServer) {
|
||||||
const finalConversationId = conversationController.ensureContactIds({
|
const finalConversationId = conversationController.ensureContactIds({
|
||||||
e164,
|
e164,
|
||||||
uuid: uuidFromServer,
|
uuid: uuidFromServer,
|
||||||
highTrust: true,
|
highTrust: true,
|
||||||
reason: 'updateConversationsWithUuidLookup',
|
reason: 'updateConversationsWithUuidLookup',
|
||||||
});
|
});
|
||||||
const maybeFinalConversation =
|
const maybeFinalConversation =
|
||||||
conversationController.get(finalConversationId);
|
conversationController.get(finalConversationId);
|
||||||
assert(
|
assert(
|
||||||
maybeFinalConversation,
|
maybeFinalConversation,
|
||||||
'updateConversationsWithUuidLookup: expected a conversation to be found or created'
|
'updateConversationsWithUuidLookup: expected a conversation to be found or created'
|
||||||
);
|
);
|
||||||
finalConversation = maybeFinalConversation;
|
finalConversation = maybeFinalConversation;
|
||||||
} else {
|
} else {
|
||||||
finalConversation = conversation;
|
finalConversation = conversation;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!finalConversation.get('e164') || !finalConversation.get('uuid')) {
|
// We got no uuid from CDS so either the person is now unregistered or
|
||||||
finalConversation.setUnregistered();
|
// 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…
Add table
Add a link
Reference in a new issue