Fixes double redux data loading for story replies
This commit is contained in:
parent
d6afae64d9
commit
169d89aa0b
1 changed files with 23 additions and 52 deletions
|
@ -113,7 +113,6 @@ const LIST_MEMBERS_VERIFIED = 'stories/LIST_MEMBERS_VERIFIED';
|
||||||
const LOAD_STORY_REPLIES = 'stories/LOAD_STORY_REPLIES';
|
const LOAD_STORY_REPLIES = 'stories/LOAD_STORY_REPLIES';
|
||||||
const MARK_STORY_READ = 'stories/MARK_STORY_READ';
|
const MARK_STORY_READ = 'stories/MARK_STORY_READ';
|
||||||
const QUEUE_STORY_DOWNLOAD = 'stories/QUEUE_STORY_DOWNLOAD';
|
const QUEUE_STORY_DOWNLOAD = 'stories/QUEUE_STORY_DOWNLOAD';
|
||||||
const REPLY_TO_STORY = 'stories/REPLY_TO_STORY';
|
|
||||||
export const RESOLVE_ATTACHMENT_URL = 'stories/RESOLVE_ATTACHMENT_URL';
|
export const RESOLVE_ATTACHMENT_URL = 'stories/RESOLVE_ATTACHMENT_URL';
|
||||||
const SEND_STORY_MODAL_OPEN_STATE_CHANGED =
|
const SEND_STORY_MODAL_OPEN_STATE_CHANGED =
|
||||||
'stories/SEND_STORY_MODAL_OPEN_STATE_CHANGED';
|
'stories/SEND_STORY_MODAL_OPEN_STATE_CHANGED';
|
||||||
|
@ -156,14 +155,6 @@ type QueueStoryDownloadActionType = {
|
||||||
payload: string;
|
payload: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ReplyToStoryActionType = {
|
|
||||||
type: typeof REPLY_TO_STORY;
|
|
||||||
payload: {
|
|
||||||
message: MessageAttributesType;
|
|
||||||
storyId: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
type ResolveAttachmentUrlActionType = {
|
type ResolveAttachmentUrlActionType = {
|
||||||
type: typeof RESOLVE_ATTACHMENT_URL;
|
type: typeof RESOLVE_ATTACHMENT_URL;
|
||||||
payload: {
|
payload: {
|
||||||
|
@ -204,7 +195,6 @@ export type StoriesActionType =
|
||||||
| MessageDeletedActionType
|
| MessageDeletedActionType
|
||||||
| MessagesAddedActionType
|
| MessagesAddedActionType
|
||||||
| QueueStoryDownloadActionType
|
| QueueStoryDownloadActionType
|
||||||
| ReplyToStoryActionType
|
|
||||||
| ResolveAttachmentUrlActionType
|
| ResolveAttachmentUrlActionType
|
||||||
| SendStoryModalOpenStateChanged
|
| SendStoryModalOpenStateChanged
|
||||||
| StoryChangedActionType
|
| StoryChangedActionType
|
||||||
|
@ -453,7 +443,7 @@ function replyToStory(
|
||||||
mentions: Array<BodyRangeType>,
|
mentions: Array<BodyRangeType>,
|
||||||
timestamp: number,
|
timestamp: number,
|
||||||
story: StoryViewType
|
story: StoryViewType
|
||||||
): ThunkAction<void, RootStateType, unknown, ReplyToStoryActionType> {
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
||||||
return async dispatch => {
|
return async dispatch => {
|
||||||
const conversation = window.ConversationController.get(conversationId);
|
const conversation = window.ConversationController.get(conversationId);
|
||||||
|
|
||||||
|
@ -462,7 +452,7 @@ function replyToStory(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const messageAttributes = await conversation.enqueueMessageForSend(
|
await conversation.enqueueMessageForSend(
|
||||||
{
|
{
|
||||||
body: messageBody,
|
body: messageBody,
|
||||||
attachments: [],
|
attachments: [],
|
||||||
|
@ -474,15 +464,10 @@ function replyToStory(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (messageAttributes) {
|
dispatch({
|
||||||
dispatch({
|
type: 'NOOP',
|
||||||
type: REPLY_TO_STORY,
|
payload: null,
|
||||||
payload: {
|
});
|
||||||
message: messageAttributes,
|
|
||||||
storyId: story.messageId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1373,8 +1358,25 @@ export function reducer(
|
||||||
|
|
||||||
// New message
|
// New message
|
||||||
if (messageIndex < 0) {
|
if (messageIndex < 0) {
|
||||||
|
const storyIndex = state.stories.findIndex(
|
||||||
|
story => story.messageId === replyState.messageId
|
||||||
|
);
|
||||||
|
|
||||||
|
const stories =
|
||||||
|
storyIndex >= 0
|
||||||
|
? replaceIndex(state.stories, storyIndex, {
|
||||||
|
...state.stories[storyIndex],
|
||||||
|
hasReplies: true,
|
||||||
|
hasRepliesFromSelf:
|
||||||
|
state.stories[storyIndex].hasRepliesFromSelf ||
|
||||||
|
state.stories[storyIndex].conversationId ===
|
||||||
|
action.payload.conversationId,
|
||||||
|
})
|
||||||
|
: state.stories;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
stories,
|
||||||
replyState: {
|
replyState: {
|
||||||
messageId: replyState.messageId,
|
messageId: replyState.messageId,
|
||||||
replies: [...replyState.replies, action.payload.data],
|
replies: [...replyState.replies, action.payload.data],
|
||||||
|
@ -1396,37 +1398,6 @@ export function reducer(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.type === REPLY_TO_STORY) {
|
|
||||||
const { replyState } = state;
|
|
||||||
|
|
||||||
const stories = state.stories.map(story => {
|
|
||||||
if (story.messageId === action.payload.storyId) {
|
|
||||||
return {
|
|
||||||
...story,
|
|
||||||
hasRepliesFromSelf: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return story;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!replyState) {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
stories,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
stories,
|
|
||||||
replyState: {
|
|
||||||
messageId: replyState.messageId,
|
|
||||||
replies: [...replyState.replies, action.payload.message],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action.type === RESOLVE_ATTACHMENT_URL) {
|
if (action.type === RESOLVE_ATTACHMENT_URL) {
|
||||||
const { messageId, attachmentUrl } = action.payload;
|
const { messageId, attachmentUrl } = action.payload;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue