diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 153ce5a7a9..1fb2242d79 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -881,6 +881,10 @@ export const getConversationByAnyIdSelector = createSelector( return undefined; } + const onGroupId = getOwn(byGroupId, id); + if (onGroupId) { + return onGroupId; + } const onServiceId = getOwn( byServiceId, normalizeServiceId(id, 'getConversationSelector') @@ -892,10 +896,6 @@ export const getConversationByAnyIdSelector = createSelector( if (onE164) { return onE164; } - const onGroupId = getOwn(byGroupId, id); - if (onGroupId) { - return onGroupId; - } const onId = getOwn(byId, id); if (onId) { return onId; diff --git a/ts/test-both/state/selectors/conversations_test.ts b/ts/test-both/state/selectors/conversations_test.ts index af3d245ede..039b879aec 100644 --- a/ts/test-both/state/selectors/conversations_test.ts +++ b/ts/test-both/state/selectors/conversations_test.ts @@ -149,7 +149,7 @@ describe('both/state/selectors/conversations-extra', () => { assert.deepEqual(actual, getPlaceholderContact()); }); - it('returns conversation by uuid first', () => { + it('returns conversation by uuid', () => { const id = 'id'; const conversation = makeConversation(id); @@ -168,9 +168,6 @@ describe('both/state/selectors/conversations-extra', () => { conversationsByServiceId: { [id]: conversation, }, - conversationsByGroupId: { - [id]: wrongConversation, - }, }, }; @@ -196,9 +193,6 @@ describe('both/state/selectors/conversations-extra', () => { conversationsByE164: { [id]: conversation, }, - conversationsByGroupId: { - [id]: wrongConversation, - }, }, }; @@ -233,6 +227,37 @@ describe('both/state/selectors/conversations-extra', () => { assert.strictEqual(actual, conversation); }); + it('returns conversation by groupId first', () => { + const id = 'id'; + + const conversation = makeConversation(id); + const wrongConversation = makeConversation('wrong'); + + const state = { + ...getEmptyRootState(), + conversations: { + ...getEmptyState(), + conversationLookup: { + [id]: wrongConversation, + }, + conversationsByGroupId: { + [id]: conversation, + }, + conversationsByE164: { + [id]: wrongConversation, + }, + conversationsByServiceId: { + [id]: wrongConversation, + }, + }, + }; + + const selector = getConversationSelector(state); + + const actual = selector(id); + + assert.strictEqual(actual, conversation); + }); it('returns conversation by conversationId', () => { const id = 'id';