diff --git a/src/reducers/models/comments.js b/src/reducers/models/comments.js index 784f223a1..43cbd6883 100644 --- a/src/reducers/models/comments.js +++ b/src/reducers/models/comments.js @@ -6,6 +6,7 @@ import unionBy from "lodash/unionBy"; import compose from "lodash/fp/compose"; import set from "lodash/fp/set"; import update from "lodash/fp/update"; +import { shortRecordToken } from "src/helpers"; import { PROPOSAL_STATUS_PUBLIC, PROPOSAL_STATUS_UNREVIEWED @@ -23,7 +24,7 @@ const comments = (state = DEFAULT_STATE, action) => { [act.RECEIVE_RECORD_COMMENTS]: () => { const { token, comments, accesstime } = action.payload; - const fullToken = comments[0]?.token || token; + const shortToken = shortRecordToken(token); // Filter duplicated comments by signature. The latest copy found // will be kept. const filteredComments = uniqWith( @@ -32,37 +33,38 @@ const comments = (state = DEFAULT_STATE, action) => arrVal.signature && arrVal.signaure !== othVal.signaure ); return compose( - set(["comments", "byToken", fullToken], filteredComments), - set(["comments", "accessTimeByToken", fullToken], accesstime) + set(["comments", "byToken", shortToken], filteredComments), + set(["comments", "accessTimeByToken", shortToken], accesstime) )(state); }, [act.RECEIVE_NEW_COMMENT]: () => { const comment = action.payload; return update( - ["comments", "byToken", comment.token], + ["comments", "byToken", shortRecordToken(comment.token)], (comments = []) => [...comments, comment] )(state); }, [act.RECEIVE_LIKED_COMMENTS]: () => { const { token, commentslikes } = action.payload; return set( - ["commentsLikes", "byToken", token], + ["commentsLikes", "byToken", shortRecordToken(token)], commentslikes )(state); }, [act.RECEIVE_SYNC_LIKE_COMMENT]: () => { const { token, vote, commentid } = action.payload; - const commentsLikes = state.commentsLikes.byToken[token]; + const shortToken = shortRecordToken(token); + const commentsLikes = state.commentsLikes.byToken[shortToken]; const backupForCommentLikes = cloneDeep(commentsLikes); - const comments = state.comments.byToken[token]; + const comments = state.comments.byToken[shortToken]; const isTargetCommentLike = (commentLike) => commentLike.commentid === commentid && - commentLike.token === token; + commentLike.token === shortToken; const oldCommentVote = commentsLikes && commentsLikes.find(isTargetCommentLike); const oldVote = oldCommentVote ? oldCommentVote.vote : 0; const newCommentLike = { - token, + shortToken, commentid, vote: vote === oldVote ? 0 : vote }; @@ -100,9 +102,9 @@ const comments = (state = DEFAULT_STATE, action) => return compose( set(["commentsLikes", "backup"], backupForCommentLikes), - set(["commentsLikes", "byToken", token], newCommentsLikes), + set(["commentsLikes", "byToken", shortToken], newCommentsLikes), set(["comments", "backup"], comments), - update(["comments", "byToken", token], (value) => + update(["comments", "byToken", shortToken], (value) => value.map(updateCommentResultAndTotalVotes) ) )(state); @@ -111,11 +113,12 @@ const comments = (state = DEFAULT_STATE, action) => const { backup: commentsBackup } = state.comments; const { backup: commentsLikesBackup } = state.commentsLikes; const { token } = action.payload; + const shortToken = shortRecordToken(token); return compose( set(["commentsLikes", "backup"], null), - set(["commentsLikes", "byToken", token], commentsLikesBackup), + set(["commentsLikes", "byToken", shortToken], commentsLikesBackup), set(["comments", "backup"], null), - set(["comments", "byToken", token], commentsBackup) + set(["comments", "byToken", shortToken], commentsBackup) )(state); }, [act.RECEIVE_LIKE_COMMENT]: () => { @@ -135,7 +138,7 @@ const comments = (state = DEFAULT_STATE, action) => }; }; return compose( - update(["comments", "byToken", token], (comments) => + update(["comments", "byToken", shortRecordToken(token)], (comments) => comments.map(censorTargetComment) ) )(state); @@ -146,7 +149,9 @@ const comments = (state = DEFAULT_STATE, action) => proposal.status === PROPOSAL_STATUS_PUBLIC && oldStatus === PROPOSAL_STATUS_UNREVIEWED ) { - delete state.comments.byToken[proposal.censorshiprecord.token]; + delete state.comments.byToken[ + shortRecordToken(proposal.censorshiprecord.token) + ]; } return state; }, diff --git a/src/selectors/models/comments.js b/src/selectors/models/comments.js index 55d20b621..27e93543c 100644 --- a/src/selectors/models/comments.js +++ b/src/selectors/models/comments.js @@ -15,12 +15,13 @@ export const commentsLikesByToken = get([ ]); const getCommentsByToken = (token) => (commentsByToken) => { - const comment = commentsByToken[token]; + const shortToken = token && shortRecordToken(token); + const comment = commentsByToken[shortToken]; if (comment) return comment; const commentsTokens = Object.keys(commentsByToken); // check if the provided token is prefix of original token const matchedTokenByPrefix = commentsTokens.find( - (key) => shortRecordToken(key) === token + (key) => key === shortToken ); return commentsByToken[matchedTokenByPrefix]; };