Changes story sort order
This commit is contained in:
parent
bb989455a7
commit
0a0fabd2ca
2 changed files with 34 additions and 3 deletions
|
@ -105,6 +105,10 @@ function markStoryRead(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isDownloaded(matchingStory.attachment)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (matchingStory.readStatus !== ReadStatus.Unread) {
|
if (matchingStory.readStatus !== ReadStatus.Unread) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,32 @@ export const shouldShowStoriesView = createSelector(
|
||||||
({ isShowingStoriesView }): boolean => isShowingStoriesView
|
({ isShowingStoriesView }): boolean => isShowingStoriesView
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function getNewestStory(x: ConversationStoryType): StoryViewType {
|
||||||
|
return x.stories[x.stories.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortByRecencyAndUnread(
|
||||||
|
a: ConversationStoryType,
|
||||||
|
b: ConversationStoryType
|
||||||
|
): number {
|
||||||
|
const storyA = getNewestStory(a);
|
||||||
|
const storyB = getNewestStory(b);
|
||||||
|
|
||||||
|
if (storyA.isUnread && storyB.isUnread) {
|
||||||
|
return storyA.timestamp > storyB.timestamp ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (storyB.isUnread) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (storyA.isUnread) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return storyA.timestamp > storyB.timestamp ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
export const getStories = createSelector(
|
export const getStories = createSelector(
|
||||||
getConversationSelector,
|
getConversationSelector,
|
||||||
getStoriesState,
|
getStoriesState,
|
||||||
|
@ -99,10 +125,11 @@ export const getStories = createSelector(
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reversing so that the story list is in DESC order
|
|
||||||
return {
|
return {
|
||||||
hiddenStories: Array.from(hiddenStoriesById.values()).reverse(),
|
hiddenStories: Array.from(hiddenStoriesById.values()).sort(
|
||||||
stories: Array.from(storiesById.values()).reverse(),
|
sortByRecencyAndUnread
|
||||||
|
),
|
||||||
|
stories: Array.from(storiesById.values()).sort(sortByRecencyAndUnread),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue