Mercurial Hosting > chat
changeset 75:377bdda60f0b
read up to
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 09 Mar 2025 18:26:49 -0600 |
parents | 1c0336a7380f |
children | 4dfe5af67f91 |
files | src/chat.css src/chat.js src/heartbeat.js.luan |
diffstat | 3 files changed, 42 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/chat.css Sun Mar 09 10:55:30 2025 -0600 +++ b/src/chat.css Sun Mar 09 18:26:49 2025 -0600 @@ -80,6 +80,12 @@ max-width: 100%; } +div[unread] { + font-size: 12px; + color: grey; + text-align: right; +} + div[who] { display: flex; justify-content: space-between;
--- a/src/chat.js Sun Mar 09 10:55:30 2025 -0600 +++ b/src/chat.js Sun Mar 09 18:26:49 2025 -0600 @@ -227,7 +227,10 @@ } function heartbeat() { - ajax(`heartbeat.js?last_update=${lastUpdate}`); + let url = `heartbeat.js?last_update=${lastUpdate}`; + if( currentChatId ) + url += `&chat=${currentChatId}`; + ajax(url); } setInterval( heartbeat, 10000 ); @@ -372,3 +375,19 @@ } openModal(dialog); } + +function readUpTo(userId,userNameHtml,unread) { + let div = document.querySelector(`div[user="${userId}"]`); + if( div ) { + if( unread == div.getAttribute('unread') ) + return; + div.outerHTML = ''; + } + console.log('readUpTo'); + let divs = document.querySelectorAll('div[post]'); + if( unread >= divs.length ) + return; + div = divs[divs.length - unread - 1]; + let html = `<div user="${userId}" unread="${unread}">read by ${userNameHtml}</div>`; + div.insertAdjacentHTML('beforeend',html); +}
--- a/src/heartbeat.js.luan Sun Mar 09 10:55:30 2025 -0600 +++ b/src/heartbeat.js.luan Sun Mar 09 18:26:49 2025 -0600 @@ -1,5 +1,6 @@ local Luan = require "luan:Luan.luan" local error = Luan.error +local ipairs = Luan.ipairs or error() local String = require "luan:String.luan" local to_number = String.to_number or error() local Parsers = require "luan:Parsers.luan" @@ -10,11 +11,14 @@ local Http = require "luan:http/Http.luan" local User = require "site:/lib/User.luan" local current_user = User.current or error() +local get_user_by_id = User.get_by_id or error() local Shared = require "site:/lib/Shared.luan" local compressed = Shared.compressed or error() local Online = require "site:/lib/Online.luan" local set_online = Online.set or error() local get_online = Online.get or error() +local Chat = require "site:/lib/Chat.luan" +local get_chat_by_id = Chat.get_by_id or error() local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "heartbeat.js" @@ -40,4 +44,16 @@ online = <%=json_string(online,compressed)%>; showOnline(); <% + local chat = Http.request.parameters.chat + if chat ~= nil then + chat = get_chat_by_id(chat) or error() + local my_user_id = user.id + for _, user_id in ipairs(chat.user_ids) do + if user_id == my_user_id then continue end + local user = get_user_by_id(user_id) +%> + readUpTo(<%=user_id%>,<%=json_string(user.name_html())%>,<%=chat.unread(user)%>); +<% + end + end end