comparison 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
comparison
equal deleted inserted replaced
78:2a602ef53eef 79:b5a316575e64
58 function addPost() { 58 function addPost() {
59 let textarea = document.querySelector('div[input] textarea'); 59 let textarea = document.querySelector('div[input] textarea');
60 let text = textarea.value; 60 let text = textarea.value;
61 if( text.trim() === '' ) 61 if( text.trim() === '' )
62 return; 62 return;
63 ajax(`add_post.js?chat=${currentChatId}`,`content=${encodeURIComponent(text)}`); 63 let url = `add_post.js?chat=${currentChatId}`;
64 let reply = document.querySelector('div[reply]').getAttribute('reply');
65 if( reply )
66 url += `&reply=${reply}`;
67 ajax(url,`content=${encodeURIComponent(text)}`);
64 textarea.value = ''; 68 textarea.value = '';
69 closeReply();
65 } 70 }
66 71
67 function textareaKey(event) { 72 function textareaKey(event) {
68 if( event.keyCode===13 && !event.shiftKey && !event.ctrlKey && !isMobile ) { 73 if( event.keyCode===13 && !event.shiftKey && !event.ctrlKey && !isMobile ) {
69 event.preventDefault(); 74 event.preventDefault();
79 } 84 }
80 85
81 function fixPosts() { 86 function fixPosts() {
82 let divs = document.querySelectorAll('div[post][fix]'); 87 let divs = document.querySelectorAll('div[post][fix]');
83 for( let div of divs ) { 88 for( let div of divs ) {
84 let whenSpan = div.querySelector('span[when]'); 89 for( let whenSpan of div.querySelectorAll('[when]') ) {
85 whenSpan.textContent = new Date(Number(whenSpan.textContent)).toLocaleString([],{dateStyle:'short',timeStyle:'short'}); 90 whenSpan.textContent = new Date(Number(whenSpan.textContent)).toLocaleString([],{dateStyle:'short',timeStyle:'short'});
91 }
86 let textDiv = div.querySelector('div[text]'); 92 let textDiv = div.querySelector('div[text]');
87 textDiv.innerHTML = urlsToLinks(textDiv.innerHTML); 93 textDiv.innerHTML = urlsToLinks(textDiv.innerHTML);
88 if( div.getAttribute('author') === userId ) 94 let reply = div.querySelector('blockquote');
89 div.querySelector('span[pulldown]').innerHTML = document.querySelector('div[hidden] span[pulldown]').innerHTML; 95 if( reply )
96 reply.innerHTML = urlsToLinks(reply.innerHTML);
97 let html;
98 if( div.getAttribute('author') === userId ) {
99 html = document.querySelector('div[hidden] span[pulldown=author]').innerHTML;
100 } else {
101 html = document.querySelector('div[hidden] span[pulldown=other]').innerHTML;
102 }
103 div.querySelector('span[pulldown]').innerHTML = html;
90 div.removeAttribute('fix'); 104 div.removeAttribute('fix');
91 } 105 }
92 } 106 }
93 107
94 function deleteChat() { 108 function deleteChat() {
404 } 418 }
405 //console.log('readUpTo'); 419 //console.log('readUpTo');
406 let html = `<div user="${userId}" unread="${unread}">read by ${userNameHtml}</div>`; 420 let html = `<div user="${userId}" unread="${unread}">read by ${userNameHtml}</div>`;
407 div.insertAdjacentHTML('beforeend',html); 421 div.insertAdjacentHTML('beforeend',html);
408 } 422 }
423
424 function replyPost(el) {
425 let postId = getPostId(el);
426 let div = document.querySelector('div[reply]');
427 div.removeAttribute('hidden');
428 div.setAttribute('reply',postId);
429 document.querySelector('div[reply] div[text]').innerHTML = document.querySelector(`div[post="${postId}"] div[text]`).innerHTML
430 let a = document.querySelector('div[reply] a');
431 a.href = `#p${postId}`;
432 a.textContent = document.querySelector(`div[post="${postId}"] span[when]`).textContent;
433 document.querySelector('div[input] textarea').focus();
434 document.querySelector('div[input]').scrollIntoView({block: 'end'});
435 }
436
437 function closeReply() {
438 let div = document.querySelector('div[reply]');
439 div.setAttribute('hidden','');
440 div.setAttribute('reply','');
441 }