Mercurial Hosting > chat
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 11:563a5358f2ee | 12:9f45d32670ae |
|---|---|
| 1 local Luan = require "luan:Luan.luan" | 1 local Luan = require "luan:Luan.luan" |
| 2 local error = Luan.error | 2 local error = Luan.error |
| 3 local ipairs = Luan.ipairs or error() | 3 local ipairs = Luan.ipairs or error() |
| 4 local Parsers = require "luan:Parsers.luan" | 4 local Parsers = require "luan:Parsers.luan" |
| 5 local json_string = Parsers.json_string or error() | 5 local json_string = Parsers.json_string or error() |
| 6 local Html = require "luan:Html.luan" | |
| 7 local html_encode = Html.encode or error() | |
| 8 local Io = require "luan:Io.luan" | 6 local Io = require "luan:Io.luan" |
| 9 local Http = require "luan:http/Http.luan" | 7 local Http = require "luan:http/Http.luan" |
| 10 local User = require "site:/lib/User.luan" | 8 local User = require "site:/lib/User.luan" |
| 11 local get_user_by_id = User.get_by_id or error() | |
| 12 local current_user = User.current or error() | 9 local current_user = User.current or error() |
| 13 local Chat = require "site:/lib/Chat.luan" | 10 local Chat = require "site:/lib/Chat.luan" |
| 14 local get_chat_by_id = Chat.get_by_id or error() | 11 local get_chat_by_id = Chat.get_by_id or error() |
| 15 local Post = require "site:/lib/Post.luan" | 12 local Post = require "site:/lib/Post.luan" |
| 16 local post_search = Post.search or error() | 13 local post_search = Post.search or error() |
| 14 local Shared = require "site:/lib/Shared.luan" | |
| 15 local post_html = Shared.post_html or error() | |
| 17 | 16 |
| 18 | |
| 19 local function post_html(post) | |
| 20 local author = get_user_by_id(post.author_id) | |
| 21 local id = post.id | |
| 22 %> | |
| 23 <div post="<%=id%>"> | |
| 24 <div who> | |
| 25 <span author><%=author.email%></span> | |
| 26 <span when fix><%=post.date%></span> | |
| 27 </div> | |
| 28 <div text><%= html_encode(post.content) %></div> | |
| 29 </div> | |
| 30 <% | |
| 31 end | |
| 32 | 17 |
| 33 local function html() | 18 local function html() |
| 34 local user = current_user() or error() | 19 local user = current_user() or error() |
| 35 local chat = Http.request.parameters.chat or error() | 20 local chat = Http.request.parameters.chat or error() |
| 36 chat = get_chat_by_id(chat) or error() | 21 chat = get_chat_by_id(chat) or error() |
| 55 end | 40 end |
| 56 | 41 |
| 57 return function() | 42 return function() |
| 58 Io.stdout = Http.response.text_writer() | 43 Io.stdout = Http.response.text_writer() |
| 59 %> | 44 %> |
| 60 document.querySelector('div[posts]').innerHTML = <%=json_string(`html()`)%>; | 45 gotChat(<%=json_string(`html()`)%>); |
| 61 fixDates(); | |
| 62 document.querySelector('div[input] textarea').focus(); | |
| 63 <% | 46 <% |
| 64 end | 47 end |
