Mercurial Hosting > chat
diff src/chat.js @ 79:b5a316575e64
reply
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 10 Mar 2025 21:41:53 -0600 |
parents | 2a602ef53eef |
children | a0d3477d5694 |
line wrap: on
line diff
--- a/src/chat.js Sun Mar 09 22:20:36 2025 -0600 +++ b/src/chat.js Mon Mar 10 21:41:53 2025 -0600 @@ -60,8 +60,13 @@ let text = textarea.value; if( text.trim() === '' ) return; - ajax(`add_post.js?chat=${currentChatId}`,`content=${encodeURIComponent(text)}`); + let url = `add_post.js?chat=${currentChatId}`; + let reply = document.querySelector('div[reply]').getAttribute('reply'); + if( reply ) + url += `&reply=${reply}`; + ajax(url,`content=${encodeURIComponent(text)}`); textarea.value = ''; + closeReply(); } function textareaKey(event) { @@ -81,12 +86,21 @@ function fixPosts() { let divs = document.querySelectorAll('div[post][fix]'); for( let div of divs ) { - let whenSpan = div.querySelector('span[when]'); - whenSpan.textContent = new Date(Number(whenSpan.textContent)).toLocaleString([],{dateStyle:'short',timeStyle:'short'}); + for( let whenSpan of div.querySelectorAll('[when]') ) { + whenSpan.textContent = new Date(Number(whenSpan.textContent)).toLocaleString([],{dateStyle:'short',timeStyle:'short'}); + } let textDiv = div.querySelector('div[text]'); textDiv.innerHTML = urlsToLinks(textDiv.innerHTML); - if( div.getAttribute('author') === userId ) - div.querySelector('span[pulldown]').innerHTML = document.querySelector('div[hidden] span[pulldown]').innerHTML; + let reply = div.querySelector('blockquote'); + if( reply ) + reply.innerHTML = urlsToLinks(reply.innerHTML); + let html; + if( div.getAttribute('author') === userId ) { + html = document.querySelector('div[hidden] span[pulldown=author]').innerHTML; + } else { + html = document.querySelector('div[hidden] span[pulldown=other]').innerHTML; + } + div.querySelector('span[pulldown]').innerHTML = html; div.removeAttribute('fix'); } } @@ -406,3 +420,22 @@ let html = `<div user="${userId}" unread="${unread}">read by ${userNameHtml}</div>`; div.insertAdjacentHTML('beforeend',html); } + +function replyPost(el) { + let postId = getPostId(el); + let div = document.querySelector('div[reply]'); + div.removeAttribute('hidden'); + div.setAttribute('reply',postId); + document.querySelector('div[reply] div[text]').innerHTML = document.querySelector(`div[post="${postId}"] div[text]`).innerHTML + let a = document.querySelector('div[reply] a'); + a.href = `#p${postId}`; + a.textContent = document.querySelector(`div[post="${postId}"] span[when]`).textContent; + document.querySelector('div[input] textarea').focus(); + document.querySelector('div[input]').scrollIntoView({block: 'end'}); +} + +function closeReply() { + let div = document.querySelector('div[reply]'); + div.setAttribute('hidden',''); + div.setAttribute('reply',''); +}