Fix for UnregisteredUserError handling when fetching UUIDs

This commit is contained in:
Fedor Indutny 2021-03-15 16:44:43 -07:00 committed by Josh Perez
parent 6df82867a0
commit fd8339e2ff
4 changed files with 25 additions and 20 deletions

View file

@ -501,7 +501,8 @@ describe('both/state/selectors/conversations', () => {
'convo-5': { 'convo-5': {
...getDefaultConversation('convo-5'), ...getDefaultConversation('convo-5'),
discoveredUnregisteredAt: new Date(1999, 3, 20).getTime(), discoveredUnregisteredAt: new Date(1999, 3, 20).getTime(),
title: 'Should Be Dropped (unregistered)', name: 'In System Contacts (and unregistered too long ago)',
title: 'B. Sorted Second',
}, },
'convo-6': { 'convo-6': {
...getDefaultConversation('convo-6'), ...getDefaultConversation('convo-6'),
@ -511,8 +512,7 @@ describe('both/state/selectors/conversations', () => {
'convo-7': { 'convo-7': {
...getDefaultConversation('convo-7'), ...getDefaultConversation('convo-7'),
discoveredUnregisteredAt: Date.now(), discoveredUnregisteredAt: Date.now(),
name: 'In System Contacts (and only recently unregistered)', title: 'Should Be Dropped (unregistered)',
title: 'B. Sorted Second',
}, },
}); });
return result; return result;
@ -540,7 +540,7 @@ describe('both/state/selectors/conversations', () => {
const ids = result.map(contact => contact.id); const ids = result.map(contact => contact.id);
assert.deepEqual(ids, [ assert.deepEqual(ids, [
'convo-1', 'convo-1',
'convo-7', 'convo-5',
'convo-6', 'convo-6',
'our-conversation-id', 'our-conversation-id',
]); ]);
@ -551,7 +551,7 @@ describe('both/state/selectors/conversations', () => {
const result = getComposeContacts(state); const result = getComposeContacts(state);
const ids = result.map(contact => contact.id); const ids = result.map(contact => contact.id);
assert.deepEqual(ids, ['convo-1', 'convo-7']); assert.deepEqual(ids, ['convo-1', 'convo-5']);
}); });
}); });
@ -590,14 +590,14 @@ describe('both/state/selectors/conversations', () => {
'convo-5': { 'convo-5': {
...getDefaultConversation('convo-5'), ...getDefaultConversation('convo-5'),
discoveredUnregisteredAt: new Date(1999, 3, 20).getTime(), discoveredUnregisteredAt: new Date(1999, 3, 20).getTime(),
name: 'My Name', name: 'In System Contacts (and unregistered too long ago)',
title: 'Should Be Dropped (unregistered)', title: 'C. Sorted Third',
}, },
'convo-6': { 'convo-6': {
...getDefaultConversation('convo-6'), ...getDefaultConversation('convo-6'),
discoveredUnregisteredAt: Date.now(), discoveredUnregisteredAt: Date.now(),
name: 'In System Contacts (and only recently unregistered)', name: 'My Name',
title: 'C. Sorted Third', title: 'Should Be Dropped (unregistered)',
}, },
}, },
composer: { composer: {
@ -624,7 +624,7 @@ describe('both/state/selectors/conversations', () => {
const result = getCandidateContactsForNewGroup(state); const result = getCandidateContactsForNewGroup(state);
const ids = result.map(contact => contact.id); const ids = result.map(contact => contact.id);
assert.deepEqual(ids, ['convo-1', 'convo-6']); assert.deepEqual(ids, ['convo-1', 'convo-5']);
}); });
it('can search for contacts', () => { it('can search for contacts', () => {
@ -632,7 +632,7 @@ describe('both/state/selectors/conversations', () => {
const result = getCandidateContactsForNewGroup(state); const result = getCandidateContactsForNewGroup(state);
const ids = result.map(contact => contact.id); const ids = result.map(contact => contact.id);
assert.deepEqual(ids, ['convo-1', 'convo-6']); assert.deepEqual(ids, ['convo-1', 'convo-5']);
}); });
}); });

View file

@ -13,35 +13,35 @@ describe('isConversationUnregistered', () => {
); );
}); });
it('returns false if passed a time fewer than 6 hours ago', () => { it('returns true if passed a time fewer than 6 hours ago', () => {
assert.isFalse( assert.isTrue(
isConversationUnregistered({ discoveredUnregisteredAt: Date.now() }) isConversationUnregistered({ discoveredUnregisteredAt: Date.now() })
); );
const fiveHours = 1000 * 60 * 60 * 5; const fiveHours = 1000 * 60 * 60 * 5;
assert.isFalse( assert.isTrue(
isConversationUnregistered({ isConversationUnregistered({
discoveredUnregisteredAt: Date.now() - fiveHours, discoveredUnregisteredAt: Date.now() - fiveHours,
}) })
); );
}); });
it('returns false if passed a time in the future', () => { it('returns true if passed a time in the future', () => {
assert.isFalse( assert.isTrue(
isConversationUnregistered({ discoveredUnregisteredAt: Date.now() + 123 }) isConversationUnregistered({ discoveredUnregisteredAt: Date.now() + 123 })
); );
}); });
it('returns true if passed a time more than 6 hours ago', () => { it('returns false if passed a time more than 6 hours ago', () => {
const oneMinute = 1000 * 60; const oneMinute = 1000 * 60;
const sixHours = 1000 * 60 * 60 * 6; const sixHours = 1000 * 60 * 60 * 6;
assert.isTrue( assert.isFalse(
isConversationUnregistered({ isConversationUnregistered({
discoveredUnregisteredAt: Date.now() - sixHours - oneMinute, discoveredUnregisteredAt: Date.now() - sixHours - oneMinute,
}) })
); );
assert.isTrue( assert.isFalse(
isConversationUnregistered({ isConversationUnregistered({
discoveredUnregisteredAt: new Date(1999, 3, 20).getTime(), discoveredUnregisteredAt: new Date(1999, 3, 20).getTime(),
}) })

View file

@ -633,6 +633,11 @@ export default class OutgoingMessage {
}); });
identifier = uuid; identifier = uuid;
} else { } else {
const c = window.ConversationController.get(identifier);
if (c) {
c.setUnregistered();
}
throw new UnregisteredUserError( throw new UnregisteredUserError(
identifier, identifier,
new Error('User is not registered') new Error('User is not registered')

View file

@ -8,6 +8,6 @@ export function isConversationUnregistered({
}: Readonly<{ discoveredUnregisteredAt?: number }>): boolean { }: Readonly<{ discoveredUnregisteredAt?: number }>): boolean {
return Boolean( return Boolean(
discoveredUnregisteredAt && discoveredUnregisteredAt &&
discoveredUnregisteredAt < Date.now() - SIX_HOURS discoveredUnregisteredAt > Date.now() - SIX_HOURS
); );
} }