diff --git a/assets/js/ARBoard.js b/assets/js/ARBoard.js index fe97c4c..05e7fed 100644 --- a/assets/js/ARBoard.js +++ b/assets/js/ARBoard.js @@ -3,6 +3,7 @@ let minterGroupAddresses let minterAdminAddresses let isTest = false let isAddRemoveBoard = true +let otherPublisher = false const addRemoveIdentifierPrefix = "QM-AR-card" const loadAddRemoveAdminPage = async () => { console.log("Loading Add/Remove Admin page...") @@ -69,35 +70,6 @@ const loadAddRemoveAdminPage = async () => { document.getElementById("propose-promotion-button").addEventListener("click", async () => { try { - const fetchedCard = await fetchExistingARCard(addRemoveIdentifierPrefix) - if (fetchedCard) { - // An existing card is found - if (isTest) { - const updateCard = confirm("You have already published a promotion card, would you like to update that one or publish a new one?") - - if (updateCard) { - isExistingCard = true - await loadCardIntoForm(existingCardData) - alert("Edit your existing card and publish.") - } else { - alert("New Card Selected: You can now create a new promotion card.") - isExistingCard = false - existingCardData = {} - document.getElementById("publish-card-form").reset() - } - - } else { - // Not in test mode, force editing - alert("A card already exists. Publishing of multiple cards is not allowed. Please update your card.") - isExistingCard = true - await loadCardIntoForm(existingCardData) - } - - } else { - // No existing card found - console.log("No existing card found. Creating a new card.") - isExistingCard = false - } // Show the form const publishCardView = document.getElementById("promotion-form-container") publishCardView.style.display = 'flex' @@ -317,13 +289,12 @@ const handleProposeDemotion = async (adminName, adminAddress) => { const proposeButton = document.getElementById('propose-promotion-button') proposeButton.style.display = 'none' const fetchedCard = await fetchExistingARCard(addRemoveIdentifierPrefix, adminName) + if (fetchedCard) { alert("A card already exists. Publishing of multiple cards is not allowed. Please update your card.") isExistingCard = true await loadCardIntoForm(fetchedCard) } - - // Populate the form with the admin's name const nameInput = document.getElementById("minter-name-input") nameInput.value = adminName @@ -342,37 +313,29 @@ const handleProposeDemotion = async (adminName, adminAddress) => { const fetchExistingARCard = async (cardIdentifierPrefix, minterName) => { try { - // 1. Fetch all cards with the specified prefix const response = await searchSimple( 'BLOG_POST', `${cardIdentifierPrefix}`, - '', // Empty name to fetch all cards + '', 0, 0, '', + false, true ) - - console.log(`SEARCH_QDN_RESOURCES response: ${JSON.stringify(response, null, 2)}`) + + console.log(`fetchExistingCard searchSimple response: ${JSON.stringify(response, null, 2)}`) if (!response || !Array.isArray(response) || response.length === 0) { console.log("No cards found.") return null } - // 2. Fetch minterGroupAddresses if not already fetched - if (!minterGroupAddresses) { - const groupData = await fetchMinterGroupMembers() - minterGroupAddresses = groupData.map((m) => m.member) - } - - // 3. Validate all fetched cards and check for duplicate `minterName` const validatedCards = await Promise.all( response.map(async (card) => { const isValid = await validateCardStructure(card) if (!isValid) return null - // Fetch full card data for validation const cardDataResponse = await qortalRequest({ action: "FETCH_QDN_RESOURCE", @@ -381,30 +344,28 @@ const handleProposeDemotion = async (adminName, adminAddress) => { identifier: card.identifier, }) - // Check if `minterName` matches the input or is a duplicate if (cardDataResponse.minterName === minterName) { console.log(`Card with the same minterName found: ${minterName}`) - return { - card, - cardData: cardDataResponse, + if (cardDataResponse.creator === userState.accountName) { + console.log(`The user is the publisher, adding card...`) + return { + card, + cardData: cardDataResponse, + } + } else { + console.warn(`Card found, but user is not the creator!`) + otherPublisher = true + return null } } - return null }) ) - - // 4. Filter out null results and check for duplicates + // Filter out null results and check for duplicates const matchingCards = validatedCards.filter((result) => result !== null) - + if (matchingCards.length > 0) { - const { card, cardData } = matchingCards[0] // Use the first matching card - - // Determine if the card is a promotion card - // const nameInfo = await getNameInfo(cardData.minterName) - // const ownerAddress = nameInfo?.owner - - // Set flags and return the existing card data + const { card, cardData } = matchingCards[0] // Use the first matching card, which should be the first published for the minterName existingCardIdentifier = card.identifier existingCardData = cardData isExistingCard = true @@ -429,11 +390,12 @@ const publishARCard = async (cardIdentifierPrefix) => { let minterName let address let isPromotionCard - + if (potentialNameInfo.owner) { console.log(`MINTER NAME FOUND:`, minterNameInput) minterName = minterNameInput address = potentialNameInfo.owner + } else { console.warn(`user input an address?...`, minterNameInput) if (!address){ @@ -447,6 +409,7 @@ const publishARCard = async (cardIdentifierPrefix) => { } } const checkForName = await getNameFromAddress(minterNameInput) + if (checkForName) { minterName = checkForName } else if (!checkForName && address){ @@ -459,21 +422,32 @@ const publishARCard = async (cardIdentifierPrefix) => { return } } - + const exists = await fetchExistingARCard(cardIdentifierPrefix, minterName) + + if (exists) { + alert(`An existing card was found, you must update it, two cards for the samme name cannot be published! Loading card data...`) + await loadCardIntoForm(existingCardData) + minterName = exists.minterName + const nameInfo = await getNameInfo(exists.minterName) + address = nameInfo.owner + isExistingCard = true + } else if (otherPublisher){ + alert(`An existing card was found, but you are NOT the publisher, you may not publish duplicates, and you may not update a non-owned card! Please try again with another name, or use the existing card for ${minterNameInput}`) + return + } + const minterGroupData = await fetchMinterGroupMembers() minterGroupAddresses = minterGroupData.map(m => m.member) const minterAdminGroupData = await fetchMinterGroupAdmins() minterAdminAddresses = minterAdminGroupData.map(m => m.member) - - if (minterGroupAddresses.includes(address)) { - isPromotionCard = true - console.warn(`address is a MINTER, this is a promotion card...`) - } if (minterAdminAddresses.includes(address)){ isPromotionCard = false console.warn(`this is a DEMOTION`, address) + }else if (minterGroupAddresses.includes(address)) { + isPromotionCard = true + console.warn(`address is a MINTER, this is a promotion card...`) } if (!minterAdminAddresses.includes(address) && !minterGroupAddresses.includes(address)) { @@ -491,7 +465,7 @@ const publishARCard = async (cardIdentifierPrefix) => { if (!header || !content) { alert("Header and content are required!") return - } + } const cardIdentifier = isExistingCard ? existingCardIdentifier : `${cardIdentifierPrefix}-${await uid()}` const pollName = `${cardIdentifier}-poll` @@ -538,6 +512,10 @@ const publishARCard = async (cardIdentifierPrefix) => { alert("Card Updated Successfully! (No poll updates are possible at this time...)") isExistingCard = false } + + if (isPromotionCard){ + isPromotionCard = false + } document.getElementById("publish-card-form").reset() document.getElementById("promotion-form-container").style.display = "none" @@ -763,36 +741,37 @@ const createARCardHTML = async (cardData, pollResults, cardIdentifier, commentCo const minterAdmins = await fetchMinterGroupAdmins() let showPromotionCard = false - showPromotionCard = await fallbackMinterCheck(minterName, minterGroupMembers, minterAdmins) + // showPromotionCard = await fallbackMinterCheck(minterName, minterGroupMembers, minterAdmins) - // if (typeof promotionCard === 'boolean') { - // showPromotionCard = promotionCard; - // } else if (typeof promotionCard === 'string') { - // // Could be "true" or "false" or something else - // const lower = promotionCard.trim().toLowerCase() - // if (lower === "true") { - // showPromotionCard = true - // } else if (lower === "false") { - // showPromotionCard = false - // } else { - // // Unexpected string => fallback - // console.warn(`Unexpected string in promotionCard="${promotionCard}"`) - // showPromotionCard = await fallbackMinterCheck(minterName, minterGroupMembers) - // } - // } else if (promotionCard == null) { - // // null or undefined => fallback check - // console.warn(`No promotionCard field in card data, doing manual check...`) - // showPromotionCard = await fallbackMinterCheck(minterName, minterGroupMembers) - // } else { - // // If it’s an object or something else weird => fallback - // console.warn(`promotionCard has unexpected type, fallback...`) - // showPromotionCard = await fallbackMinterCheck(minterName, minterGroupMembers) - // } + if (typeof promotionCard === 'boolean') { + showPromotionCard = promotionCard; + } else if (typeof promotionCard === 'string') { + // Could be "true" or "false" or something else + const lower = promotionCard.trim().toLowerCase() + if (lower === "true") { + showPromotionCard = true + } else if (lower === "false") { + showPromotionCard = false + } else { + // Unexpected string => fallback + console.warn(`Unexpected string in promotionCard="${promotionCard}"`) + showPromotionCard = await fallbackMinterCheck(minterName, minterGroupMembers) + } + } else if (promotionCard == null) { + // null or undefined => fallback check + console.warn(`No promotionCard field in card data, doing manual check...`) + showPromotionCard = await fallbackMinterCheck(minterName, minterGroupMembers) + } else { + // If it’s an object or something else weird => fallback + console.warn(`promotionCard has unexpected type, fallback...`) + showPromotionCard = await fallbackMinterCheck(minterName, minterGroupMembers) + } let cardColorCode = (showPromotionCard) ? 'rgb(17, 44, 46)' : 'rgb(57, 11, 13)' const promotionDemotionHtml = (showPromotionCard) ? `
REGARDING (Promotion):
+ ${minterAvatar}

${minterName}

` : `
REGARDING (Demotion):
@@ -807,8 +786,8 @@ const createARCardHTML = async (cardData, pollResults, cardIdentifier, commentCo createModal('links') createModal('poll-details') - let actionsHtml - let altText + let actionsHtml = '' + let altText = '' const verifiedName = await validateMinterName(minterName) if (verifiedName) { @@ -847,7 +826,7 @@ const createARCardHTML = async (cardData, pollResults, cardIdentifier, commentCo } } else { - console.log(`name could not be validated, assuming topic card (or some other issue with name validation) for removalActions`) + console.warn(`name could not be validated, not setting actionsHtml`) actionsHtml = '' } diff --git a/assets/js/MinterBoard.js b/assets/js/MinterBoard.js index ed724cf..788b8b5 100644 --- a/assets/js/MinterBoard.js +++ b/assets/js/MinterBoard.js @@ -658,8 +658,8 @@ const publishCard = async (cardIdentifierPrefix) => { const minterGroupData = await fetchMinterGroupMembers() const minterGroupAddresses = minterGroupData.map(m => m.member) + const userAddress = userState.accountAddress - const userAddress = userState.accountAddress; if (minterGroupAddresses.includes(userAddress)) { alert("You are already a Minter and cannot publish a new card!") return @@ -991,7 +991,6 @@ const postComment = async (cardIdentifier) => { data64: base64CommentData, }) - alert('Comment posted successfully!') commentInput.value = '' } catch (error) { console.error('Error posting comment:', error) diff --git a/assets/js/QortalApi.js b/assets/js/QortalApi.js index 6ce85ae..0108f4a 100644 --- a/assets/js/QortalApi.js +++ b/assets/js/QortalApi.js @@ -802,9 +802,9 @@ const searchAllWithOffset = async (service, query, limit, offset, room) => { } } // NOTE - This function does a search and will return EITHER AN ARRAY OR A SINGLE OBJECT. if you want to guarantee a single object, pass 1 as limit. i.e. await searchSimple(service, identifier, "", 1) will return a single object. -const searchSimple = async (service, identifier, name, limit = 1500, offset = 0, room='', reverse='true') => { +const searchSimple = async (service, identifier, name, limit=1500, offset=0, room='', reverse=true, prefixOnly=true) => { try { - let urlSuffix = `service=${service}&identifier=${identifier}&name=${name}&prefix=true&limit=${limit}&offset=${offset}&reverse=${reverse}` + let urlSuffix = `service=${service}&identifier=${identifier}&name=${name}&prefix=true&limit=${limit}&offset=${offset}&reverse=${reverse}&prefix=${prefixOnly}` if (name && !identifier && !room) { console.log('name only searchSimple', name) diff --git a/index.html b/index.html index c90d753..94cb5f1 100644 --- a/index.html +++ b/index.html @@ -42,7 +42,7 @@ - Q-Mintership (v1.01b) + Q-Mintership (v1.02b) @@ -61,7 +61,7 @@ - Q-Mintership v1.01b
+ Q-Mintership v1.02b
@@ -93,7 +93,7 @@
Mintership Forum
-

New Minters - Start Here

+

Minting Rights? - Start Here - MinterBoard

@@ -191,6 +191,24 @@
+
+
+
+
+

+ v1.02beta 01-22-2025

+
+
+
+
+

+ v1.02b Fixes- There were publish issues on ARA Board - These publish issues have now been resolved. DUPLICATES ARE NOT ALLOWED, and if you did not publish a card for a name, you cannot publish an update. Also removed the 'alert' for comment publish, as it was unnecessary. Also resolved an issue preventing a user from publishing more than a single card (regardless of duplicates). +

+
+
+
+
+
@@ -202,7 +220,8 @@

- v1.01b Major changes in 1.0.- Every feature required for the new featureTriggers have been added, and a minor bug on the ARA Board has been resolved. Pull Request from QuickMythril has also been added. Allowing cards to be arranged based on various parameters. + v1.01b - Improving Major changes in 1.0.- Every feature required for the new featureTriggers have been added, and a minor bug on the ARA Board has been resolved. Pull Request from QuickMythril has also been added. Allowing cards to be arranged based on various parameters. +

@@ -517,12 +536,12 @@
-

Q-Mintership (v1.01b)

+

Q-Mintership (v1.02b)

- +