add message editing to all forums
This commit is contained in:
parent
3a083f99f6
commit
9f645f5582
@ -178,6 +178,21 @@
|
|||||||
background-color: #3d1919;
|
background-color: #3d1919;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.edit-button {
|
||||||
|
align-self: flex-end;
|
||||||
|
margin-top: 1vh;
|
||||||
|
background-color: #897016;
|
||||||
|
color: #ffffff;
|
||||||
|
border: none;
|
||||||
|
border-radius: 1vh;
|
||||||
|
padding: 0.3vh 0.6vh;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-button:hover {
|
||||||
|
background-color: #402d09;
|
||||||
|
}
|
||||||
|
|
||||||
/* forum-styles.css additions */
|
/* forum-styles.css additions */
|
||||||
|
|
||||||
.message-input-section {
|
.message-input-section {
|
||||||
|
@ -470,6 +470,7 @@ let selectedImages = []
|
|||||||
let selectedFiles = []
|
let selectedFiles = []
|
||||||
let multiResource = []
|
let multiResource = []
|
||||||
let attachmentIdentifiers = []
|
let attachmentIdentifiers = []
|
||||||
|
let editMessageIdentifier = null
|
||||||
|
|
||||||
// Set up file input handling
|
// Set up file input handling
|
||||||
const setupFileInputs = (room) => {
|
const setupFileInputs = (room) => {
|
||||||
@ -560,9 +561,14 @@ const processSelectedImages = async (selectedImages, multiResource, room) => {
|
|||||||
|
|
||||||
// Handle send message
|
// Handle send message
|
||||||
const handleSendMessage = async (room, messageHtml, selectedFiles, selectedImages, multiResource) => {
|
const handleSendMessage = async (room, messageHtml, selectedFiles, selectedImages, multiResource) => {
|
||||||
const messageIdentifier = room === "admins"
|
let messageIdentifier
|
||||||
|
if (editMessageIdentifier) {
|
||||||
|
messageIdentifier = editMessageIdentifier
|
||||||
|
} else {
|
||||||
|
messageIdentifier = room === "admins"
|
||||||
? `${messageIdentifierPrefix}-${room}-e-${randomID()}`
|
? `${messageIdentifierPrefix}-${room}-e-${randomID()}`
|
||||||
: `${messageIdentifierPrefix}-${room}-${randomID()}`
|
: `${messageIdentifierPrefix}-${room}-${randomID()}`
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Process selected images
|
// Process selected images
|
||||||
@ -674,6 +680,34 @@ const handleDeleteMessage = async (room, existingMessageIdentifier) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleEditMessage = async (room, existingMessageIdentifier) => {
|
||||||
|
try {
|
||||||
|
const editedMessageObject = {
|
||||||
|
messageHtml: "", // TODO: Add Quill editor content here
|
||||||
|
hasAttachment: false,
|
||||||
|
attachments: [],
|
||||||
|
replyTo: null
|
||||||
|
}
|
||||||
|
const base64Message = btoa(JSON.stringify(editedMessageObject))
|
||||||
|
const service = (room === "admins") ? "MAIL_PRIVATE" : "BLOG_POST"
|
||||||
|
const request = {
|
||||||
|
action: 'PUBLISH_QDN_RESOURCE',
|
||||||
|
name: userState.accountName,
|
||||||
|
service: service,
|
||||||
|
identifier: existingMessageIdentifier,
|
||||||
|
data64: base64Message
|
||||||
|
}
|
||||||
|
if (room === "admins") {
|
||||||
|
request.encrypt = true
|
||||||
|
request.publicKeys = adminPublicKeys
|
||||||
|
}
|
||||||
|
console.log("Editing forum message...")
|
||||||
|
await qortalRequest(request)
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error editing message:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function clearInputs() {
|
function clearInputs() {
|
||||||
// Clear the file input elements and preview container
|
// Clear the file input elements and preview container
|
||||||
document.getElementById('file-input').value = ''
|
document.getElementById('file-input').value = ''
|
||||||
@ -691,6 +725,7 @@ function clearInputs() {
|
|||||||
attachmentIdentifiers = []
|
attachmentIdentifiers = []
|
||||||
selectedImages = []
|
selectedImages = []
|
||||||
selectedFiles = []
|
selectedFiles = []
|
||||||
|
editMessageIdentifier = null
|
||||||
|
|
||||||
// Remove the reply container
|
// Remove the reply container
|
||||||
const replyContainer = document.querySelector('.reply-container')
|
const replyContainer = document.querySelector('.reply-container')
|
||||||
@ -790,6 +825,7 @@ const loadMessagesFromQDN = async (room, page, isPolling = false) => {
|
|||||||
|
|
||||||
handleReplyLogic(fetchMessages)
|
handleReplyLogic(fetchMessages)
|
||||||
handleDeleteLogic(fetchMessages, room)
|
handleDeleteLogic(fetchMessages, room)
|
||||||
|
handleEditLogic(fetchMessages, room)
|
||||||
|
|
||||||
await updatePaginationControls(room, limit)
|
await updatePaginationControls(room, limit)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -1010,6 +1046,7 @@ const buildMessageHTML = async (message, fetchMessages, room, isNewMessage) => {
|
|||||||
const attachmentHtml = await buildAttachmentHtml(message, room)
|
const attachmentHtml = await buildAttachmentHtml(message, room)
|
||||||
const avatarUrl = `/arbitrary/THUMBNAIL/${message.name}/qortal_avatar`
|
const avatarUrl = `/arbitrary/THUMBNAIL/${message.name}/qortal_avatar`
|
||||||
let deleteButtonHtml = ''
|
let deleteButtonHtml = ''
|
||||||
|
let editButtonHtml = ''
|
||||||
if (message.name === userState.accountName) {
|
if (message.name === userState.accountName) {
|
||||||
deleteButtonHtml = `
|
deleteButtonHtml = `
|
||||||
<button class="delete-button"
|
<button class="delete-button"
|
||||||
@ -1018,6 +1055,13 @@ const buildMessageHTML = async (message, fetchMessages, room, isNewMessage) => {
|
|||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
`
|
`
|
||||||
|
editButtonHtml = `
|
||||||
|
<button class="edit-button"
|
||||||
|
data-message-identifier="${message.identifier}"
|
||||||
|
data-room="${room}">
|
||||||
|
Edit
|
||||||
|
</button>
|
||||||
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
return `
|
return `
|
||||||
@ -1036,7 +1080,7 @@ const buildMessageHTML = async (message, fetchMessages, room, isNewMessage) => {
|
|||||||
${attachmentHtml}
|
${attachmentHtml}
|
||||||
</div>
|
</div>
|
||||||
<div class="message-actions">
|
<div class="message-actions">
|
||||||
${deleteButtonHtml}
|
${deleteButtonHtml}${editButtonHtml}
|
||||||
<button class="reply-button" data-message-identifier="${message.identifier}">Reply</button>
|
<button class="reply-button" data-message-identifier="${message.identifier}">Reply</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -1208,6 +1252,23 @@ const handleDeleteLogic = (fetchMessages, room) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleEditLogic = (fetchMessages, room) => {
|
||||||
|
// Only select buttons that do NOT already have a listener
|
||||||
|
const editButtons = document.querySelectorAll('.edit-button:not(.bound-edit)')
|
||||||
|
editButtons.forEach(button => {
|
||||||
|
button.classList.add('bound-edit')
|
||||||
|
button.addEventListener('click', async () => {
|
||||||
|
const existingMessageIdentifier = button.dataset.messageIdentifier
|
||||||
|
const originalMessage = messagesById[existingMessageIdentifier]
|
||||||
|
if (!originalMessage) return
|
||||||
|
editMessageIdentifier = existingMessageIdentifier
|
||||||
|
const quill = new Quill('#editor')
|
||||||
|
quill.clipboard.dangerouslyPasteHTML(originalMessage.content)
|
||||||
|
// Optionally show a small notice: "Editing message..."
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const showReplyPreview = (repliedMessage) => {
|
const showReplyPreview = (repliedMessage) => {
|
||||||
replyToMessageIdentifier = repliedMessage.identifier
|
replyToMessageIdentifier = repliedMessage.identifier
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user