Fix moderator data misalignment. (#7139)

## Issue
Closes 7121 Missing mod block option (large number of moderated channels?)

## Notes
It was bad to assume `channelSignatures` would be the same length as the promise result -- any failure in signing would cause a misalignment.

For my case, an accidentally-merged channel couldn't be signed due to a missing private key. I think it's the same for Drew.
This commit is contained in:
infinite-persistence 2021-09-21 22:40:44 +08:00 committed by GitHub
parent fcea4005eb
commit 63fd867757
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,7 @@ import { doAlertWaitingForSync } from 'redux/actions/app';
const isDev = process.env.NODE_ENV !== 'production';
const FETCH_API_FAILED_TO_FETCH = 'Failed to fetch';
const PROMISE_FULFILLED = 'fulfilled';
declare type CommentronErrorMap = {
[string]: {
@ -1377,9 +1378,7 @@ export function doFetchCommentModAmIList(channelClaim: ChannelClaim) {
const state = getState();
const myChannels = selectMyChannelClaims(state);
dispatch({
type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_STARTED,
});
dispatch({ type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_STARTED });
let channelSignatures = [];
@ -1399,13 +1398,13 @@ export function doFetchCommentModAmIList(channelClaim: ChannelClaim) {
})
)
)
.then((res) => {
.then((results) => {
const delegatorsById = {};
channelSignatures.forEach((chanSig, index) => {
if (chanSig && res[index]) {
const value = res[index].value;
delegatorsById[chanSig.claim_id] = {
results.forEach((result, index) => {
if (result.status === PROMISE_FULFILLED) {
const value = result.value;
delegatorsById[value.channel_id] = {
global: value ? value.type === 'Global' : false,
delegators: value && value.authorized_channels ? value.authorized_channels : {},
};
@ -1418,15 +1417,12 @@ export function doFetchCommentModAmIList(channelClaim: ChannelClaim) {
});
})
.catch((err) => {
dispatch({
type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_FAILED,
});
devToast(dispatch, `AmI: ${err}`);
dispatch({ type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_FAILED });
});
})
.catch(() => {
dispatch({
type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_FAILED,
});
dispatch({ type: ACTIONS.COMMENT_MODERATION_AM_I_LIST_FAILED });
});
};
}