Revert "Reactions: consider failures as "fetched""

This reverts commit 84a2a74c8c.
This commit is contained in:
infinite-persistence 2021-07-18 10:54:01 +08:00
parent 0bf03c4a35
commit abe32e5f5c
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
2 changed files with 24 additions and 45 deletions

View file

@ -221,13 +221,6 @@ export function doCommentReactList(commentIds: Array<string>) {
if (activeChannelClaim) {
const signatureData = await channelSignName(activeChannelClaim.claim_id, activeChannelClaim.name);
if (!signatureData) {
dispatch({
type: ACTIONS.COMMENT_REACTION_LIST_FAILED,
data: {
channelId: activeChannelClaim ? activeChannelClaim.claim_id : undefined,
commentIds,
},
});
return dispatch(doToast({ isError: true, message: __('Unable to verify your channel. Please try again.') }));
}
@ -243,10 +236,9 @@ export function doCommentReactList(commentIds: Array<string>) {
dispatch({
type: ACTIONS.COMMENT_REACTION_LIST_COMPLETED,
data: {
myReactions,
myReactions: myReactions || {},
othersReactions,
channelId: activeChannelClaim ? activeChannelClaim.claim_id : undefined,
commentIds,
},
});
})
@ -254,10 +246,7 @@ export function doCommentReactList(commentIds: Array<string>) {
devToast(dispatch, `doCommentReactList: ${error.message}`);
dispatch({
type: ACTIONS.COMMENT_REACTION_LIST_FAILED,
data: {
channelId: activeChannelClaim ? activeChannelClaim.claim_id : undefined,
commentIds,
},
data: error,
});
});
};

View file

@ -143,24 +143,10 @@ export default handleActions(
isFetchingReacts: true,
}),
[ACTIONS.COMMENT_REACTION_LIST_FAILED]: (state: CommentsState, action: any) => {
const { channelId, commentIds } = action.data;
const myReactsByCommentId = Object.assign({}, state.myReactsByCommentId);
const othersReactsByCommentId = Object.assign({}, state.othersReactsByCommentId);
commentIds.forEach((commentId) => {
const key = channelId ? `${commentId}:${channelId}` : commentId;
myReactsByCommentId[key] = [];
othersReactsByCommentId[key] = {};
});
return {
...state,
isFetchingReacts: false,
myReactsByCommentId,
othersReactsByCommentId,
};
},
[ACTIONS.COMMENT_REACTION_LIST_FAILED]: (state: CommentsState, action: any) => ({
...state,
isFetchingReacts: false,
}),
[ACTIONS.COMMENT_REACT_FAILED]: (state: CommentsState, action: any): CommentsState => {
const commentReaction = action.data; // String: reactionHash + type
@ -196,24 +182,28 @@ export default handleActions(
},
[ACTIONS.COMMENT_REACTION_LIST_COMPLETED]: (state: CommentsState, action: any): CommentsState => {
const { myReactions, othersReactions, channelId, commentIds } = action.data;
const { myReactions, othersReactions, channelId } = action.data;
const myReacts = Object.assign({}, state.myReactsByCommentId);
const othersReacts = Object.assign({}, state.othersReactsByCommentId);
commentIds.forEach((commentId) => {
const key = channelId ? `${commentId}:${channelId}` : commentId;
const mine = myReactions ? myReactions[commentId] : {};
const others = othersReactions ? othersReactions[commentId] : {};
if (myReactions) {
Object.entries(myReactions).forEach(([commentId, reactions]) => {
const key = channelId ? `${commentId}:${channelId}` : commentId;
myReacts[key] = Object.entries(reactions).reduce((acc, [name, count]) => {
if (count === 1) {
acc.push(name);
}
return acc;
}, []);
});
}
myReacts[key] = Object.entries(mine).reduce((acc, [name, count]) => {
if (count === 1) {
acc.push(name);
}
return acc;
}, []);
othersReacts[key] = others;
});
if (othersReactions) {
Object.entries(othersReactions).forEach(([commentId, reactions]) => {
const key = channelId ? `${commentId}:${channelId}` : commentId;
othersReacts[key] = reactions;
});
}
return {
...state,