Fix shortcuts with pinned chats

This commit is contained in:
Chris Svenningsen 2020-10-09 14:53:20 -07:00 committed by Josh Perez
parent b199d5fe58
commit e5fae1a346

View file

@ -784,16 +784,23 @@ type WhatIsThis = typeof window.WhatIsThis;
} }
}; };
function getConversationByIndex(index: WhatIsThis) { function getConversationsToSearch() {
const state = store.getState(); const state = store.getState();
const lists = window.Signal.State.Selectors.conversations.getLeftPaneLists( const {
state archivedConversations,
); conversations: unpinnedConversations,
const toSearch = state.conversations.showArchived pinnedConversations,
? lists.archivedConversations } = window.Signal.State.Selectors.conversations.getLeftPaneLists(state);
: lists.conversations;
const target = toSearch[index]; return state.conversations.showArchived
? archivedConversations
: [...pinnedConversations, ...unpinnedConversations];
}
function getConversationByIndex(index: WhatIsThis) {
const conversationsToSearch = getConversationsToSearch();
const target = conversationsToSearch[index];
if (target) { if (target) {
return target.id; return target.id;
@ -807,34 +814,28 @@ type WhatIsThis = typeof window.WhatIsThis;
direction: WhatIsThis, direction: WhatIsThis,
unreadOnly: WhatIsThis unreadOnly: WhatIsThis
) { ) {
const state = store.getState(); const conversationsToSearch = getConversationsToSearch();
const lists = window.Signal.State.Selectors.conversations.getLeftPaneLists(
state
);
const toSearch = state.conversations.showArchived
? lists.archivedConversations
: lists.conversations;
const increment = direction === 'up' ? -1 : 1; const increment = direction === 'up' ? -1 : 1;
let startIndex; let startIndex;
if (conversationId) { if (conversationId) {
const index = toSearch.findIndex( const index = conversationsToSearch.findIndex(
(item: WhatIsThis) => item.id === conversationId (item: WhatIsThis) => item.id === conversationId
); );
if (index >= 0) { if (index >= 0) {
startIndex = index + increment; startIndex = index + increment;
} }
} else { } else {
startIndex = direction === 'up' ? toSearch.length - 1 : 0; startIndex = direction === 'up' ? conversationsToSearch.length - 1 : 0;
} }
for ( for (
let i = startIndex, max = toSearch.length; let i = startIndex, max = conversationsToSearch.length;
i >= 0 && i < max; i >= 0 && i < max;
i += increment i += increment
) { ) {
const target = toSearch[i]; const target = conversationsToSearch[i];
if (!unreadOnly) { if (!unreadOnly) {
return target.id; return target.id;
} }