From cd033bc756be20b0c72290b984e812c260acda29 Mon Sep 17 00:00:00 2001 From: crowetic Date: Fri, 27 Dec 2024 11:49:07 -0800 Subject: [PATCH] Moved repo to new location to prevent file issues, fixed a few loading issues. Seems QDN is causing issues when people are not able to obtain the newest version of the published data. --- .nextcloudsync.log | 0 assets/js/AdminBoard.js | 90 +++++++++++++----- assets/js/Q-Mintership.js | 95 +++++++++++-------- assets/js/css-scratch.css | 195 -------------------------------------- index.html | 24 ++--- 5 files changed, 133 insertions(+), 271 deletions(-) delete mode 100644 .nextcloudsync.log delete mode 100644 assets/js/css-scratch.css diff --git a/.nextcloudsync.log b/.nextcloudsync.log deleted file mode 100644 index e69de29..0000000 diff --git a/assets/js/AdminBoard.js b/assets/js/AdminBoard.js index 4eda5b0..26b97e9 100644 --- a/assets/js/AdminBoard.js +++ b/assets/js/AdminBoard.js @@ -310,6 +310,12 @@ const fetchAllEncryptedCards = async () => { // Fetch poll results const pollResults = await fetchPollResults(decryptedCardData.poll); + + if (pollResults?.error) { + console.warn(`Skipping card with non-existent poll: ${card.identifier}, poll=${decryptedCardData.poll}`); + removeEncryptedSkeleton(card.identifier); + return; + } // const minterNameFromIdentifier = await extractCardsMinterName(card.identifier); const encryptedCommentCount = await getEncryptedCommentCount(card.identifier); // Generate final card HTML @@ -712,45 +718,83 @@ const displayEncryptedComments = async (cardIdentifier) => { }; const calculateAdminBoardPollResults = async (pollData, minterGroupMembers, minterAdmins) => { - const memberAddresses = minterGroupMembers.map(member => member.member) - const minterAdminAddresses = minterAdmins.map(member => member.member) - const adminGroupsMembers = await fetchAllAdminGroupsMembers() - const groupAdminAddresses = adminGroupsMembers.map(member => member.member) + // 1) Validate pollData structure + if (!pollData || !Array.isArray(pollData.voteWeights) || !Array.isArray(pollData.votes)) { + console.warn("Poll data is missing or invalid. pollData:", pollData); + return { + adminYes: 0, + adminNo: 0, + minterYes: 0, + minterNo: 0, + totalYes: 0, + totalNo: 0, + totalYesWeight: 0, + totalNoWeight: 0 + }; + } + + // 2) Prepare admin & minter addresses + const memberAddresses = minterGroupMembers.map(member => member.member); + const minterAdminAddresses = minterAdmins.map(member => member.member); + const adminGroupsMembers = await fetchAllAdminGroupsMembers(); + const groupAdminAddresses = adminGroupsMembers.map(member => member.member); const adminAddresses = []; - adminAddresses.push(...minterAdminAddresses,...groupAdminAddresses); + adminAddresses.push(...minterAdminAddresses, ...groupAdminAddresses); - let adminYes = 0, adminNo = 0, minterYes = 0, minterNo = 0, yesWeight = 0 , noWeight = 0 + let adminYes = 0, adminNo = 0; + let minterYes = 0, minterNo = 0; + let yesWeight = 0, noWeight = 0; + // 3) Process voteWeights pollData.voteWeights.forEach(weightData => { if (weightData.optionName === 'Yes') { - yesWeight = weightData.voteWeight + yesWeight = weightData.voteWeight; } else if (weightData.optionName === 'No') { - noWeight = weightData.voteWeight + noWeight = weightData.voteWeight; } - }) + }); + // 4) Process votes for (const vote of pollData.votes) { - const voterAddress = await getAddressFromPublicKey(vote.voterPublicKey) - console.log(`voter address: ${voterAddress}`) + const voterAddress = await getAddressFromPublicKey(vote.voterPublicKey); + console.log(`voter address: ${voterAddress}, optionIndex: ${vote.optionIndex}`); if (vote.optionIndex === 0) { - adminAddresses.includes(voterAddress) ? adminYes++ : memberAddresses.includes(voterAddress) ? minterYes++ : console.log(`voter ${voterAddress} is not a minter nor an admin...Not including results...`) + if (adminAddresses.includes(voterAddress)) { + adminYes++; + } else if (memberAddresses.includes(voterAddress)) { + minterYes++; + } else { + console.log(`voter ${voterAddress} is not a minter nor an admin... Not including results...`); + } } else if (vote.optionIndex === 1) { - adminAddresses.includes(voterAddress) ? adminNo++ : memberAddresses.includes(voterAddress) ? minterNo++ : console.log(`voter ${voterAddress} is not a minter nor an admin...Not including results...`) + if (adminAddresses.includes(voterAddress)) { + adminNo++; + } else if (memberAddresses.includes(voterAddress)) { + minterNo++; + } else { + console.log(`voter ${voterAddress} is not a minter nor an admin... Not including results...`); + } } } - // TODO - create a new function to calculate the weights of each voting MINTER only. - // This will give ALL weight whether voter is in minter group or not... - // until that is changed on the core we must calculate manually. - const totalYesWeight = yesWeight - const totalNoWeight = noWeight + // 5) Summaries + const totalYesWeight = yesWeight; + const totalNoWeight = noWeight; + const totalYes = adminYes + minterYes; + const totalNo = adminNo + minterNo; - const totalYes = adminYes + minterYes - const totalNo = adminNo + minterNo - - return { adminYes, adminNo, minterYes, minterNo, totalYes, totalNo, totalYesWeight, totalNoWeight } -} + return { + adminYes, + adminNo, + minterYes, + minterNo, + totalYes, + totalNo, + totalYesWeight, + totalNoWeight + }; +}; const toggleEncryptedComments = async (cardIdentifier) => { const commentsSection = document.getElementById(`comments-section-${cardIdentifier}`) diff --git a/assets/js/Q-Mintership.js b/assets/js/Q-Mintership.js index 74450b6..de115e8 100644 --- a/assets/js/Q-Mintership.js +++ b/assets/js/Q-Mintership.js @@ -954,57 +954,70 @@ const buildMessageHTML = async (message, fetchMessages, room, isNewMessage) => { } const buildReplyHtml = async (message, room) => { - if (!message.replyTo) return "" + // 1) If no replyTo, skip + if (!message.replyTo) return ""; + + // 2) Decide which QDN service for this room const replyService = (room === "admins") ? "MAIL_PRIVATE" : "BLOG_POST"; - const replyIdentifier = message.replyTo + const replyIdentifier = message.replyTo; - const savedRepliedToMessage = messagesById[message.replyTo]; + // 3) Check if we already have a *saved* message + const savedRepliedToMessage = messagesById[replyIdentifier]; + console.log("savedRepliedToMessage", savedRepliedToMessage); + // 4) If we do, try to process/decrypt it if (savedRepliedToMessage) { - const processedMessage = await processMessageObject(savedRepliedToMessage, room) - console.log('message is saved in saved message data, returning from that',savedRepliedToMessage) - return ` -
-
- In reply to: ${processedMessage.name} - ${processedMessage.date} -
-
${processedMessage.content}
-
- `; - } - try { - - const replyData = await searchSimple(replyService, replyIdentifier, "", 1) - if ((!replyData) || (!replyData.name)){ - // No result found. You can either return an empty string or handle differently - console.log("No data found via searchSimple. Skipping reply rendering."); - return ""; - } - const replyName = await replyData.name - const replyTimestamp = await replyData.updated || await replyData.created - console.log('message not found in saved message data, using searchSimple', replyData) - - - // const repliedMessage = fetchMessages.find(m => m && m.identifier === message.replyTo) - // const repliedMessageIdentifier = message.replyTo - const repliedMessage = await fetchReplyData(replyService, replyName, replyIdentifier, room, replyTimestamp) - storeMessageInMap(repliedMessage) - if (!repliedMessage) return "" - - + if (savedRepliedToMessage) { + // We successfully processed the cached message + console.log("Using saved message data for reply:", savedRepliedToMessage); return `
- In reply to: ${repliedMessage.name} ${repliedMessage.date} + In reply to: ${savedRepliedToMessage.name} + ${savedRepliedToMessage.date}
-
${repliedMessage.content}
+
${savedRepliedToMessage.content}
- ` - } catch (error) { - throw (error) + `; + } else { + // The cached message is invalid + console.log("Saved message found but processMessageObject returned null. Falling back..."); + } } -} + + // 5) Fallback approach: If we don't have it in memory OR the cached version was invalid + try { + const replyData = await searchSimple(replyService, replyIdentifier, "", 1); + if (!replyData || !replyData.name) { + console.log("No data found via searchSimple. Skipping reply rendering."); + return ""; + } + + // We'll use replyData to fetch the actual message from QDN + const replyName = replyData.name; + const replyTimestamp = replyData.updated || replyData.created; + console.log("message not found in workable form, using searchSimple result =>", replyData); + + // This fetches and decrypts the actual message + const repliedMessage = await fetchReplyData(replyService, replyName, replyIdentifier, room, replyTimestamp); + if (!repliedMessage) return ""; + + // Now store the final message in the map for next time + storeMessageInMap(repliedMessage); + + // Return final HTML + return ` +
+
+ In reply to: ${repliedMessage.name} ${repliedMessage.date} +
+
${repliedMessage.content}
+
+ `; + } catch (error) { + throw error; + } +}; const buildAttachmentHtml = async (message, room) => { if (!message.attachments || message.attachments.length === 0) { diff --git a/assets/js/css-scratch.css b/assets/js/css-scratch.css deleted file mode 100644 index 3c4379c..0000000 --- a/assets/js/css-scratch.css +++ /dev/null @@ -1,195 +0,0 @@ -/* forum-styles.css */ - -.forum-main { - color: #ffffff; - background-color: #000000; - padding: 0; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: flex-start; - width: 100vw; - box-sizing: border-box; - background-size: cover; - background-position: center; - } - - .forum-header { - width: 100%; - padding: 2vh; - background-color: #000000; - color: #add8e6; /* Light blue color */ - text-align: center; - font-size: 2.5rem; - font-weight: bold; - margin-bottom: 0; - } - - .forum-submenu { - width: 100%; - padding: 1vh 2vh; - background: rgba(0, 0, 0, 0.8); - text-align: center; - margin-top: 0; - } - - .forum-rooms { - display: flex; - justify-content: center; - gap: 2vh; /* Increased gap for better spacing */ - margin-top: 0; - flex-wrap: wrap; - } - - .room-button { - background-color: #317e78; - color: #ffffff; - border: 2px solid #317e78; - border-radius: 2vh; - padding: 1vh 2vh; - font-size: 1.1rem; - cursor: pointer; - } - - .room-button:hover { - background-color: #19403d; - } - - .forum-content { - flex-grow: 1; - width: 90%; - padding: 3vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: flex-start; - box-sizing: border-box; - border: 3px solid #ffffff; /* Increased border width */ - } - - .room-content { - background: rgba(0, 0, 0, 0.6); - padding: 2vh; - border-radius: 1vh; - width: 100%; - box-sizing: border-box; - text-align: center; - } - - .room-title { - color: #add8e6; /* Light blue color for room name */ - text-align: center; - margin-bottom: 2vh; - font-size: 2rem; - } - - .message-item { - background: #1c1c1c; - color: #ffffff; - padding: 1vh; - margin-bottom: 1vh; - border-radius: 0.8vh; - width: 100%; - box-sizing: border-box; - display: flex; - flex-direction: column; - align-items: flex-start; - border: 1px solid #ffffff; - } - - .message-header { - display: flex; - justify-content: space-between; - width: 100%; - margin-bottom: 1vh; - font-size: 1.25rem; - color: white - } - - .message-header.username { - color: #228ec0; - } - - .username { - font-weight: bold; - color:#228ec0 - } - - .timestamp { - font-style: italic; - color: rgb(157, 167, 151) - } - - .message-text { - margin: 0; - font-size: 1.25rem; - } - - .reply-button { - align-self: flex-end; - margin-top: 1vh; - background-color: #167089; - color: #ffffff; - border: none; - border-radius: 1vh; - padding: 0.3vh 0.6vh; - cursor: pointer; - } - - .reply-button:hover { - background-color: #19403d; - } - -/* forum-styles.css additions */ - - .message-input-section { - display: flex; - flex-direction: column; - align-items: stretch; - box-sizing: border-box; - width: 100%; - gap: 1vh; /* Spacing between toolbar and editor */ - background-color: black; - padding: 1vh; - } - - .ql-editor { - flex-grow: 1; - text-size: 1.25rem; - } - - .message-input { - flex-grow: 1; - padding: 2vh; - border-radius: 1vh; - border: 1px solid #cccccc; - font-size: 1.25rem; - /* margin-right: 8vh; */ - box-sizing: border-box; - min-height: 15vh; - } - - .send-button { - background-color: #13a97c; - color: #ffffff; - border: none; - border-radius: 1vh; - padding: 2vh 4vh; - cursor: pointer; - } - - .send-button:hover { - background-color: #19403d; - } - - .messages-container { - width: 100%; - margin-bottom: 5vh; /* Ensure space above input section */ - overflow-y: auto; - padding-bottom: 1vh; - box-sizing: border-box; - } - - - \ No newline at end of file diff --git a/index.html b/index.html index 855b20c..b20e496 100644 --- a/index.html +++ b/index.html @@ -29,12 +29,12 @@ - - - - - - + + + + + + @@ -329,12 +329,12 @@ - - - - - - + + + + + +