Fix 1:1 message to/from in search results

See [#5161][0].

[0]: https://github.com/signalapp/Signal-Desktop/pull/5161
This commit is contained in:
Evan Hahn 2021-04-16 15:52:21 -05:00 committed by Scott Nonnenberg
commit 37ff4a1df4
2 changed files with 49 additions and 0 deletions

View file

@ -200,6 +200,9 @@ export const getMessageSearchResultSelector = createSelector(
if (type === 'incoming') { if (type === 'incoming') {
from = conversationSelector(sourceUuid || source); from = conversationSelector(sourceUuid || source);
to = conversationSelector(conversationId); to = conversationSelector(conversationId);
if (from === to) {
to = conversationSelector(ourConversationId);
}
} else if (type === 'outgoing') { } else if (type === 'outgoing') {
from = conversationSelector(ourConversationId); from = conversationSelector(ourConversationId);
to = conversationSelector(conversationId); to = conversationSelector(conversationId);

View file

@ -144,6 +144,52 @@ describe('both/state/selectors/search', () => {
assert.deepEqual(actual, expected); assert.deepEqual(actual, expected);
}); });
it('returns the correct "from" and "to" when sent to me', () => {
const searchId = 'search-id';
const fromId = 'from-id';
const toId = fromId;
const myId = 'my-id';
const from = getDefaultConversation(fromId);
const meAsRecipient = getDefaultConversation(myId);
const state = {
...getEmptyRootState(),
conversations: {
...getEmptyConversationState(),
conversationLookup: {
[fromId]: from,
[myId]: meAsRecipient,
},
},
ourConversationId: myId,
search: {
...getEmptySearchState(),
messageLookup: {
[searchId]: {
...getDefaultMessage(searchId),
type: 'incoming' as const,
sourceUuid: fromId,
conversationId: toId,
snippet: 'snippet',
body: 'snippet',
bodyRanges: [],
},
},
},
user: {
...getEmptyUserState(),
ourConversationId: myId,
},
};
const selector = getMessageSearchResultSelector(state);
const actual = selector(searchId);
assert.deepEqual(actual?.from, from);
assert.deepEqual(actual?.to, meAsRecipient);
});
it('returns outgoing message and caches appropriately', () => { it('returns outgoing message and caches appropriately', () => {
const searchId = 'search-id'; const searchId = 'search-id';
const fromId = 'from-id'; const fromId = 'from-id';