Fixed validation fail if at least one ID was valid

This commit is contained in:
AntonMacG 2023-11-13 10:17:33 +00:00
parent 400e9705e5
commit 4ac6d97ec8

View file

@ -24,12 +24,13 @@ export const settings = definePluginSettings({
default: "", default: "",
disabled: () => settings.store.alwaysPingOnReply, disabled: () => settings.store.alwaysPingOnReply,
onChange: newValue => { onChange: newValue => {
const newWhitelist = parseWhitelist(newValue); const originalIDs = newValue.split(",").map(id => id.trim()).filter(id => id !== "");
const validatedIDs = originalIDs.filter(isValidUserId);
if (newWhitelist.length === 0 && newValue.trim() !== "") { if (originalIDs.length !== validatedIDs.length) {
showToast("Invalid User ID: One or more User IDs in the whitelist are invalid. Please check your input."); showToast("Invalid User ID: One or more User IDs in the whitelist are invalid. Please check your input.");
} else { } else {
cachedWhitelist = newWhitelist; cachedWhitelist = validatedIDs;
showToast("Whitelist Updated: Reply ping whitelist has been successfully updated."); showToast("Whitelist Updated: Reply ping whitelist has been successfully updated.");
} }
} }
@ -78,7 +79,7 @@ export default definePlugin({
function parseWhitelist(value: string) { function parseWhitelist(value: string) {
return value.split(",") return value.split(",")
.map(id => id.trim()) .map(id => id.trim())
.filter(id => id !== "" && isValidUserId(id)); .filter(id => id !== "");
} }
function isValidUserId(id: string) { function isValidUserId(id: string) {