Fixed bug that was causing story playback to not play all unread
This commit is contained in:
parent
95bee1c881
commit
958f13b9f2
3 changed files with 69 additions and 41 deletions
|
@ -777,7 +777,7 @@ const getSelectedStoryDataForConversationId = (
|
||||||
// Find the index of the storyId provided, or if none provided then find the
|
// Find the index of the storyId provided, or if none provided then find the
|
||||||
// oldest unread story from the user. If all stories are read then we can
|
// oldest unread story from the user. If all stories are read then we can
|
||||||
// start at the first story.
|
// start at the first story.
|
||||||
let currentIndex = 0;
|
let currentIndex: number | undefined;
|
||||||
let hasUnread = false;
|
let hasUnread = false;
|
||||||
storiesByConversationId.forEach((item, index) => {
|
storiesByConversationId.forEach((item, index) => {
|
||||||
if (selectedStoryId && item.messageId === selectedStoryId) {
|
if (selectedStoryId && item.messageId === selectedStoryId) {
|
||||||
|
@ -786,7 +786,7 @@ const getSelectedStoryDataForConversationId = (
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!selectedStoryId &&
|
!selectedStoryId &&
|
||||||
!currentIndex &&
|
currentIndex === undefined &&
|
||||||
item.readStatus === ReadStatus.Unread
|
item.readStatus === ReadStatus.Unread
|
||||||
) {
|
) {
|
||||||
hasUnread = true;
|
hasUnread = true;
|
||||||
|
@ -806,7 +806,7 @@ const getSelectedStoryDataForConversationId = (
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentIndex,
|
currentIndex: currentIndex ?? 0,
|
||||||
hasUnread,
|
hasUnread,
|
||||||
numStories,
|
numStories,
|
||||||
storiesByConversationId,
|
storiesByConversationId,
|
||||||
|
@ -989,35 +989,38 @@ const viewStory: ViewStoryActionCreatorType = (
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const storiesSelectorState = getStories(state);
|
||||||
|
const conversationStories =
|
||||||
|
storyViewMode === StoryViewModeType.Hidden
|
||||||
|
? storiesSelectorState.hiddenStories
|
||||||
|
: storiesSelectorState.stories;
|
||||||
|
const conversationStoryIndex = conversationStories.findIndex(
|
||||||
|
item => item.conversationId === story.conversationId
|
||||||
|
);
|
||||||
|
|
||||||
// Are there any unviewed stories left? If so we should play the unviewed
|
// Are there any unviewed stories left? If so we should play the unviewed
|
||||||
// stories first. But only if we're going "next"
|
// stories first. But only if we're going "next"
|
||||||
if (viewDirection === StoryViewDirectionType.Next) {
|
if (viewDirection === StoryViewDirectionType.Next) {
|
||||||
// Only stories that succeed the current story we're on.
|
// TODO: DESKTOP-4341 only stories that succeed the current story we're on.
|
||||||
const currentStoryIndex = stories.findIndex(
|
const unreadStory = conversationStories.find(
|
||||||
item => item.messageId === storyId
|
item => item.storyView.isUnread
|
||||||
);
|
|
||||||
// No hidden stories
|
|
||||||
const hiddenConversationIds = new Set(getHideStoryConversationIds(state));
|
|
||||||
const unreadStory = stories.find(
|
|
||||||
(item, index) =>
|
|
||||||
index > currentStoryIndex &&
|
|
||||||
!item.deletedForEveryone &&
|
|
||||||
item.readStatus === ReadStatus.Unread &&
|
|
||||||
!hiddenConversationIds.has(item.conversationId)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (unreadStory) {
|
if (unreadStory) {
|
||||||
const nextSelectedStoryData = getSelectedStoryDataForConversationId(
|
const nextSelectedStoryData = getSelectedStoryDataForConversationId(
|
||||||
dispatch,
|
dispatch,
|
||||||
getState,
|
getState,
|
||||||
unreadStory.conversationId,
|
unreadStory.conversationId
|
||||||
unreadStory.messageId
|
|
||||||
);
|
);
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: VIEW_STORY,
|
type: VIEW_STORY,
|
||||||
payload: {
|
payload: {
|
||||||
currentIndex: nextSelectedStoryData.currentIndex,
|
currentIndex: nextSelectedStoryData.currentIndex,
|
||||||
messageId: unreadStory.messageId,
|
messageId:
|
||||||
|
nextSelectedStoryData.storiesByConversationId[
|
||||||
|
nextSelectedStoryData.currentIndex
|
||||||
|
].messageId,
|
||||||
numStories: nextSelectedStoryData.numStories,
|
numStories: nextSelectedStoryData.numStories,
|
||||||
shouldShowDetailsModal: false,
|
shouldShowDetailsModal: false,
|
||||||
storyViewMode,
|
storyViewMode,
|
||||||
|
@ -1037,15 +1040,6 @@ const viewStory: ViewStoryActionCreatorType = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const storiesSelectorState = getStories(state);
|
|
||||||
const conversationStories =
|
|
||||||
storyViewMode === StoryViewModeType.Hidden
|
|
||||||
? storiesSelectorState.hiddenStories
|
|
||||||
: storiesSelectorState.stories;
|
|
||||||
const conversationStoryIndex = conversationStories.findIndex(
|
|
||||||
item => item.conversationId === story.conversationId
|
|
||||||
);
|
|
||||||
|
|
||||||
if (conversationStoryIndex < 0) {
|
if (conversationStoryIndex < 0) {
|
||||||
log.warn('stories.viewStory: No stories found for conversation', {
|
log.warn('stories.viewStory: No stories found for conversation', {
|
||||||
storiesLength: conversationStories.length,
|
storiesLength: conversationStories.length,
|
||||||
|
|
|
@ -394,7 +394,6 @@ export const getStories = createSelector(
|
||||||
}
|
}
|
||||||
|
|
||||||
let storiesMap: Map<string, ConversationStoryType>;
|
let storiesMap: Map<string, ConversationStoryType>;
|
||||||
|
|
||||||
if (conversationStory.isHidden) {
|
if (conversationStory.isHidden) {
|
||||||
storiesMap = hiddenStoriesById;
|
storiesMap = hiddenStoriesById;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -31,6 +31,7 @@ import {
|
||||||
import { noopAction } from '../../../state/ducks/noop';
|
import { noopAction } from '../../../state/ducks/noop';
|
||||||
import { reducer as rootReducer } from '../../../state/reducer';
|
import { reducer as rootReducer } from '../../../state/reducer';
|
||||||
import { dropNull } from '../../../util/dropNull';
|
import { dropNull } from '../../../util/dropNull';
|
||||||
|
import type { UUIDStringType } from '../../../types/UUID';
|
||||||
|
|
||||||
describe('both/state/ducks/stories', () => {
|
describe('both/state/ducks/stories', () => {
|
||||||
const getEmptyRootState = () => ({
|
const getEmptyRootState = () => ({
|
||||||
|
@ -244,14 +245,29 @@ describe('both/state/ducks/stories', () => {
|
||||||
const storyId1 = uuid();
|
const storyId1 = uuid();
|
||||||
const storyId2 = uuid();
|
const storyId2 = uuid();
|
||||||
const storyId3 = uuid();
|
const storyId3 = uuid();
|
||||||
const getState = getStateFunction([
|
|
||||||
getStoryData(storyId1),
|
const convoId1 = uuid();
|
||||||
|
const convoId2 = uuid();
|
||||||
|
const convoId3 = uuid();
|
||||||
|
|
||||||
|
const getState = getStateFunction(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
...getStoryData(storyId1, convoId1),
|
||||||
|
readStatus: ReadStatus.Viewed,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...getStoryData(storyId2, convoId2),
|
||||||
|
readStatus: ReadStatus.Viewed,
|
||||||
|
},
|
||||||
|
getStoryData(storyId3, convoId3),
|
||||||
|
],
|
||||||
{
|
{
|
||||||
...getStoryData(storyId2),
|
[convoId1]: getMockConversation({ id: convoId1 }),
|
||||||
readStatus: ReadStatus.Viewed,
|
[convoId2]: getMockConversation({ id: convoId2 }),
|
||||||
},
|
[convoId3]: getMockConversation({ id: convoId3 }),
|
||||||
getStoryData(storyId3),
|
}
|
||||||
]);
|
);
|
||||||
|
|
||||||
const dispatch = sinon.spy();
|
const dispatch = sinon.spy();
|
||||||
viewStory({
|
viewStory({
|
||||||
|
@ -277,16 +293,29 @@ describe('both/state/ducks/stories', () => {
|
||||||
const storyId2 = uuid();
|
const storyId2 = uuid();
|
||||||
const storyId3 = uuid();
|
const storyId3 = uuid();
|
||||||
const conversationId = uuid();
|
const conversationId = uuid();
|
||||||
|
const conversationIdHide: UUIDStringType = 'test-convo-uuid-hide-story';
|
||||||
|
|
||||||
const getState = getStateFunction(
|
const getState = getStateFunction(
|
||||||
[
|
[
|
||||||
getStoryData(storyId1),
|
{
|
||||||
getStoryData(storyId2, conversationId),
|
...getStoryData(storyId1, conversationId),
|
||||||
getStoryData(storyId3, conversationId),
|
readStatus: ReadStatus.Viewed,
|
||||||
|
},
|
||||||
|
|
||||||
|
// selector looks up conversation by sourceUuid
|
||||||
|
{
|
||||||
|
...getStoryData(storyId2, conversationIdHide),
|
||||||
|
sourceUuid: conversationIdHide,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...getStoryData(storyId3, conversationIdHide),
|
||||||
|
sourceUuid: conversationIdHide,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
[conversationId]: getMockConversation({
|
[conversationId]: getMockConversation({ id: conversationId }),
|
||||||
id: conversationId,
|
[conversationIdHide]: getMockConversation({
|
||||||
|
id: conversationIdHide,
|
||||||
hideStory: true,
|
hideStory: true,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -305,6 +334,8 @@ describe('both/state/ducks/stories', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: DESKTOP-4341 - removed until implemented
|
||||||
|
/*
|
||||||
it('does not select stories that precede the currently viewed story', () => {
|
it('does not select stories that precede the currently viewed story', () => {
|
||||||
const storyId1 = uuid();
|
const storyId1 = uuid();
|
||||||
const storyId2 = uuid();
|
const storyId2 = uuid();
|
||||||
|
@ -327,6 +358,7 @@ describe('both/state/ducks/stories', () => {
|
||||||
payload: undefined,
|
payload: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
it('closes the viewer when there are no more unviewed stories', () => {
|
it('closes the viewer when there are no more unviewed stories', () => {
|
||||||
const storyId1 = uuid();
|
const storyId1 = uuid();
|
||||||
|
@ -337,7 +369,10 @@ describe('both/state/ducks/stories', () => {
|
||||||
|
|
||||||
const getState = getStateFunction(
|
const getState = getStateFunction(
|
||||||
[
|
[
|
||||||
getStoryData(storyId1, conversationId1),
|
{
|
||||||
|
...getStoryData(storyId1, conversationId1),
|
||||||
|
readStatus: ReadStatus.Viewed,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
...getStoryData(storyId2, conversationId2),
|
...getStoryData(storyId2, conversationId2),
|
||||||
readStatus: ReadStatus.Viewed,
|
readStatus: ReadStatus.Viewed,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue