Fix for UnregisteredUserError handling when fetching UUIDs
This commit is contained in:
parent
6df82867a0
commit
fd8339e2ff
4 changed files with 25 additions and 20 deletions
|
@ -501,7 +501,8 @@ describe('both/state/selectors/conversations', () => {
|
|||
'convo-5': {
|
||||
...getDefaultConversation('convo-5'),
|
||||
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': {
|
||||
...getDefaultConversation('convo-6'),
|
||||
|
@ -511,8 +512,7 @@ describe('both/state/selectors/conversations', () => {
|
|||
'convo-7': {
|
||||
...getDefaultConversation('convo-7'),
|
||||
discoveredUnregisteredAt: Date.now(),
|
||||
name: 'In System Contacts (and only recently unregistered)',
|
||||
title: 'B. Sorted Second',
|
||||
title: 'Should Be Dropped (unregistered)',
|
||||
},
|
||||
});
|
||||
return result;
|
||||
|
@ -540,7 +540,7 @@ describe('both/state/selectors/conversations', () => {
|
|||
const ids = result.map(contact => contact.id);
|
||||
assert.deepEqual(ids, [
|
||||
'convo-1',
|
||||
'convo-7',
|
||||
'convo-5',
|
||||
'convo-6',
|
||||
'our-conversation-id',
|
||||
]);
|
||||
|
@ -551,7 +551,7 @@ describe('both/state/selectors/conversations', () => {
|
|||
const result = getComposeContacts(state);
|
||||
|
||||
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': {
|
||||
...getDefaultConversation('convo-5'),
|
||||
discoveredUnregisteredAt: new Date(1999, 3, 20).getTime(),
|
||||
name: 'My Name',
|
||||
title: 'Should Be Dropped (unregistered)',
|
||||
name: 'In System Contacts (and unregistered too long ago)',
|
||||
title: 'C. Sorted Third',
|
||||
},
|
||||
'convo-6': {
|
||||
...getDefaultConversation('convo-6'),
|
||||
discoveredUnregisteredAt: Date.now(),
|
||||
name: 'In System Contacts (and only recently unregistered)',
|
||||
title: 'C. Sorted Third',
|
||||
name: 'My Name',
|
||||
title: 'Should Be Dropped (unregistered)',
|
||||
},
|
||||
},
|
||||
composer: {
|
||||
|
@ -624,7 +624,7 @@ describe('both/state/selectors/conversations', () => {
|
|||
const result = getCandidateContactsForNewGroup(state);
|
||||
|
||||
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', () => {
|
||||
|
@ -632,7 +632,7 @@ describe('both/state/selectors/conversations', () => {
|
|||
const result = getCandidateContactsForNewGroup(state);
|
||||
|
||||
const ids = result.map(contact => contact.id);
|
||||
assert.deepEqual(ids, ['convo-1', 'convo-6']);
|
||||
assert.deepEqual(ids, ['convo-1', 'convo-5']);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -13,35 +13,35 @@ describe('isConversationUnregistered', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('returns false if passed a time fewer than 6 hours ago', () => {
|
||||
assert.isFalse(
|
||||
it('returns true if passed a time fewer than 6 hours ago', () => {
|
||||
assert.isTrue(
|
||||
isConversationUnregistered({ discoveredUnregisteredAt: Date.now() })
|
||||
);
|
||||
|
||||
const fiveHours = 1000 * 60 * 60 * 5;
|
||||
assert.isFalse(
|
||||
assert.isTrue(
|
||||
isConversationUnregistered({
|
||||
discoveredUnregisteredAt: Date.now() - fiveHours,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('returns false if passed a time in the future', () => {
|
||||
assert.isFalse(
|
||||
it('returns true if passed a time in the future', () => {
|
||||
assert.isTrue(
|
||||
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 sixHours = 1000 * 60 * 60 * 6;
|
||||
|
||||
assert.isTrue(
|
||||
assert.isFalse(
|
||||
isConversationUnregistered({
|
||||
discoveredUnregisteredAt: Date.now() - sixHours - oneMinute,
|
||||
})
|
||||
);
|
||||
assert.isTrue(
|
||||
assert.isFalse(
|
||||
isConversationUnregistered({
|
||||
discoveredUnregisteredAt: new Date(1999, 3, 20).getTime(),
|
||||
})
|
||||
|
|
|
@ -633,6 +633,11 @@ export default class OutgoingMessage {
|
|||
});
|
||||
identifier = uuid;
|
||||
} else {
|
||||
const c = window.ConversationController.get(identifier);
|
||||
if (c) {
|
||||
c.setUnregistered();
|
||||
}
|
||||
|
||||
throw new UnregisteredUserError(
|
||||
identifier,
|
||||
new Error('User is not registered')
|
||||
|
|
|
@ -8,6 +8,6 @@ export function isConversationUnregistered({
|
|||
}: Readonly<{ discoveredUnregisteredAt?: number }>): boolean {
|
||||
return Boolean(
|
||||
discoveredUnregisteredAt &&
|
||||
discoveredUnregisteredAt < Date.now() - SIX_HOURS
|
||||
discoveredUnregisteredAt > Date.now() - SIX_HOURS
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue