feat: add message edit time limit and broadcast full record on update

- Add `get_seconds_since_last_update` method to `ChannelMessageModel` for age checking
- Reject edits on messages older than 3 seconds in `updateMessageText` RPC handler
- Broadcast full message record (including html) instead of just text in socket event
- Update frontend `updateMessageText` to parse and set innerHTML from received html field
- Fix CSS selector for chat message images to use descendant combinator
- Add 3-second auto-clear timeout for liveType input field
- Prevent liveType submission on trailing newline or space
- Hide empty messages in channel-message event by setting display none
This commit is contained in:
2025-05-15 17:32:40 +00:00
parent 10b0c3448a
commit af7be99ab9
5 changed files with 55 additions and 19 deletions
+25 -2
View File
@@ -47,7 +47,18 @@
if(textBox.liveType == undefined){
textBox.liveType = false
}
let typeTimeout = null;
textBox.addEventListener('keydown',async (e) => {
if(typeTimeout){
clearTimeout(typeTimeout)
typeTimeout = null
}
if(e.target.liveType){
typeTimeout = setTimeout(()=>{
e.target.lastMessageUid = null
e.target.value = ''
},3000)
}
if(e.key === "ArrowUp"){
const value = findDivAboveText(e.target.value).querySelector('.text')
e.target.value = value.textContent
@@ -102,7 +113,9 @@
}else{
if(textBox.liveType){
if(e.target.value.endsWith("\n") || e.target.value.endsWith(" ")){
return
}
if(e.target.value[0] == "/"){
return
}
@@ -116,8 +129,10 @@
return;
}
app.rpc.updateMessageText(textBox.lastMessageUid, e.target.value)
}else{
app.rpc.set_typing(channelUid)
}
app.rpc.set_typing(channelUid)
}
});
@@ -294,6 +309,10 @@
}
app.addEventListener("channel-message", (data) => {
let display = 'block';
if(!data.text || !data.text.trim()){
display = "none";
}
if (data.channel_uid !== channelUid) {
if(!isMentionForSomeoneElse(data.message)){
channelSidebar.notify(data);
@@ -316,6 +335,7 @@
const message = document.createElement("div");
message.innerHTML = data.html;
message.style.display = display
document.querySelector(".chat-messages").appendChild(message.firstChild);
updateLayout(doScrollDownBecauseLastMessageIsVisible);
setTimeout(() => {
@@ -373,6 +393,9 @@
if(e.target.tagName != 'IMG')
return
const img = e.target
if(e.target.classList.contains('avatar')){
return
}
const overlay = document.createElement('div');
overlay.style.position = 'fixed';
overlay.style.top = 0;