Skip to content

Commit

Permalink
Fix for UnregisteredUserError handling when fetching UUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny-signal authored and josh-signal committed Mar 19, 2021
1 parent 6df8286 commit fd8339e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
22 changes: 11 additions & 11 deletions ts/test-both/state/selectors/conversations_test.ts
Expand Up @@ -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'),
Expand All @@ -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;
Expand Down Expand Up @@ -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',
]);
Expand All @@ -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']);
});
});

Expand Down Expand Up @@ -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: {
Expand All @@ -624,15 +624,15 @@ 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', () => {
const state = getRootState('system contacts');
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']);
});
});

Expand Down
16 changes: 8 additions & 8 deletions ts/test-both/util/isConversationUnregistered_test.ts
Expand Up @@ -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(),
})
Expand Down
5 changes: 5 additions & 0 deletions ts/textsecure/OutgoingMessage.ts
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion ts/util/isConversationUnregistered.ts
Expand Up @@ -8,6 +8,6 @@ export function isConversationUnregistered({
}: Readonly<{ discoveredUnregisteredAt?: number }>): boolean {
return Boolean(
discoveredUnregisteredAt &&
discoveredUnregisteredAt < Date.now() - SIX_HOURS
discoveredUnregisteredAt > Date.now() - SIX_HOURS
);
}

0 comments on commit fd8339e

Please sign in to comment.