Reaction-fetch: handle "no results"
If there are no API errors but no reactions returned, consider the requested IDs as "done" and stop requesting again. When a channel is being confirmed, Commentron doesn't return the reaction object. Also added extra guard in case Commentron does return an object in the future, but an empty one.
This commit is contained in:
parent
08738ffcee
commit
e5f32b21c4
2 changed files with 21 additions and 7 deletions
|
@ -236,9 +236,10 @@ 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,
|
||||
},
|
||||
});
|
||||
})
|
||||
|
@ -379,7 +380,7 @@ export function doCommentCreate(
|
|||
livestream?: boolean = false,
|
||||
txid?: string,
|
||||
payment_intent_id?: string,
|
||||
environment?: string,
|
||||
environment?: string
|
||||
) {
|
||||
return async (dispatch: Dispatch, getState: GetState) => {
|
||||
const state = getState();
|
||||
|
|
|
@ -182,12 +182,15 @@ export default handleActions(
|
|||
},
|
||||
|
||||
[ACTIONS.COMMENT_REACTION_LIST_COMPLETED]: (state: CommentsState, action: any): CommentsState => {
|
||||
const { myReactions, othersReactions, channelId } = action.data;
|
||||
const { myReactions, othersReactions, channelId, commentIds } = action.data;
|
||||
const myReacts = Object.assign({}, state.myReactsByCommentId);
|
||||
const othersReacts = Object.assign({}, state.othersReactsByCommentId);
|
||||
|
||||
if (myReactions) {
|
||||
Object.entries(myReactions).forEach(([commentId, reactions]) => {
|
||||
const myReactionsEntries = myReactions ? Object.entries(myReactions) : [];
|
||||
const othersReactionsEntries = othersReactions ? Object.entries(othersReactions) : [];
|
||||
|
||||
if (myReactionsEntries.length > 0) {
|
||||
myReactionsEntries.forEach(([commentId, reactions]) => {
|
||||
const key = channelId ? `${commentId}:${channelId}` : commentId;
|
||||
myReacts[key] = Object.entries(reactions).reduce((acc, [name, count]) => {
|
||||
if (count === 1) {
|
||||
|
@ -196,13 +199,23 @@ export default handleActions(
|
|||
return acc;
|
||||
}, []);
|
||||
});
|
||||
} else {
|
||||
commentIds.forEach((commentId) => {
|
||||
const key = channelId ? `${commentId}:${channelId}` : commentId;
|
||||
myReacts[key] = [];
|
||||
});
|
||||
}
|
||||
|
||||
if (othersReactions) {
|
||||
Object.entries(othersReactions).forEach(([commentId, reactions]) => {
|
||||
if (othersReactionsEntries.length > 0) {
|
||||
othersReactionsEntries.forEach(([commentId, reactions]) => {
|
||||
const key = channelId ? `${commentId}:${channelId}` : commentId;
|
||||
othersReacts[key] = reactions;
|
||||
});
|
||||
} else {
|
||||
commentIds.forEach((commentId) => {
|
||||
const key = channelId ? `${commentId}:${channelId}` : commentId;
|
||||
othersReacts[key] = {};
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue