Fix comment_create verification

## Why
Lost in a rebase. The GUI clamping was just meant to complement this (so that user knows what's going on), but ended up being the only thing that was pushed.

## Changes
- If the fetch failed or still in progress, we ask the user to wait or simply refresh the page.
- If already commented from another channel, bail and inform via Toast.
This commit is contained in:
infinite-persistence 2022-05-06 13:14:40 +08:00 committed by Thomas Zarebczan
parent 2698cc7001
commit 2bdae7637b
3 changed files with 23 additions and 1 deletions

View file

@ -2257,6 +2257,9 @@
"Attach images by pasting or drag-and-drop.": "Attach images by pasting or drag-and-drop.",
"There was a network error, but the publish may have been completed. Wait a few minutes, then check your Uploads or Wallet page to confirm.": "There was a network error, but the publish may have been completed. Wait a few minutes, then check your Uploads or Wallet page to confirm.",
"Already reacted to this comment from another channel.": "Already reacted to this comment from another channel.",
"Commenting from multiple channels is not allowed.": "Commenting from multiple channels is not allowed.",
"Failed to perform action.": "Failed to perform action.",
"Please wait a while before re-submitting, or try refreshing the page.": "Please wait a while before re-submitting, or try refreshing the page.",
"Unable to react. Please try again later.": "Unable to react. Please try again later.",
"Username (cannot be changed)": "Username (cannot be changed)",
"Display Name": "Display Name",

View file

@ -16,6 +16,7 @@ import {
selectPendingCommentReacts,
selectModerationBlockList,
selectModerationDelegatorsById,
selectMyCommentedChannelIdsForId,
} from 'redux/selectors/comments';
import { makeSelectNotificationForCommentId } from 'redux/selectors/notifications';
import { selectActiveChannelClaim } from 'redux/selectors/app';
@ -620,6 +621,7 @@ export function doCommentCreate(uri: string, livestream: boolean, params: Commen
const state = getState();
const activeChannelClaim = selectActiveChannelClaim(state);
const myCommentedChannelIds = selectMyCommentedChannelIdsForId(state, claim_id);
const mentionedChannels: Array<MentionedChannel> = [];
if (!activeChannelClaim) {
@ -627,6 +629,23 @@ export function doCommentCreate(uri: string, livestream: boolean, params: Commen
return;
}
if (myCommentedChannelIds === undefined) {
dispatchToast(
dispatch,
__('Failed to perform action.'),
__('Please wait a while before re-submitting, or try refreshing the page.'),
'long'
);
return;
}
if (myCommentedChannelIds && myCommentedChannelIds.length) {
if (!myCommentedChannelIds.includes(activeChannelClaim.claim_id)) {
dispatchToast(dispatch, __('Commenting from multiple channels is not allowed.'));
return;
}
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll
// $FlowFixMe
const mentionMatches = [...comment.matchAll(MENTION_REGEX)];

View file

@ -478,7 +478,7 @@ export const selectChannelMentionData = createCachedSelector(
*
* @param state
* @param claimId
* @returns {null | undefined | Array<string>} 'undefined' = "not fetched"; 'null' = "no claim";
* @returns {null | undefined | Array<string>} 'undefined' = "not fetched for this ID"; 'null' = "no claim";
*/
export const selectMyCommentedChannelIdsForId = (state: State, claimId: string) => {
return claimId ? selectState(state).myCommentedChannelIdsById[claimId] : null;