diff src/get_chat.js.luan @ 12:9f45d32670ae

server push
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 31 Oct 2024 21:40:57 -0600
parents 563a5358f2ee
children 809193524522
line wrap: on
line diff
--- a/src/get_chat.js.luan	Thu Oct 31 19:17:53 2024 -0600
+++ b/src/get_chat.js.luan	Thu Oct 31 21:40:57 2024 -0600
@@ -3,32 +3,17 @@
 local ipairs = Luan.ipairs or error()
 local Parsers = require "luan:Parsers.luan"
 local json_string = Parsers.json_string or error()
-local Html = require "luan:Html.luan"
-local html_encode = Html.encode or error()
 local Io = require "luan:Io.luan"
 local Http = require "luan:http/Http.luan"
 local User = require "site:/lib/User.luan"
-local get_user_by_id = User.get_by_id or error()
 local current_user = User.current or error()
 local Chat = require "site:/lib/Chat.luan"
 local get_chat_by_id = Chat.get_by_id or error()
 local Post = require "site:/lib/Post.luan"
 local post_search = Post.search or error()
-
+local Shared = require "site:/lib/Shared.luan"
+local post_html = Shared.post_html or error()
 
-local function post_html(post)
-	local author = get_user_by_id(post.author_id)
-	local id = post.id
-%>
-		<div post="<%=id%>">
-			<div who>
-				<span author><%=author.email%></span>
-				<span when fix><%=post.date%></span>
-			</div>
-			<div text><%= html_encode(post.content) %></div>
-		</div>
-<%
-end
 
 local function html()
 	local user = current_user() or error()
@@ -57,8 +42,6 @@
 return function()
 	Io.stdout = Http.response.text_writer()
 %>
-	document.querySelector('div[posts]').innerHTML = <%=json_string(`html()`)%>;
-	fixDates();
-	document.querySelector('div[input] textarea').focus();
+	gotChat(<%=json_string(`html()`)%>);
 <%
 end