Mercurial Hosting > chat
comparison src/get_chat.js.luan @ 10:f9e6a4cc4f7d
add Post
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Wed, 30 Oct 2024 23:18:45 -0600 |
| parents | src/chat.js.luan@41d35b72c774 |
| children | 563a5358f2ee |
comparison
equal
deleted
inserted
replaced
| 9:b8b12fd8be22 | 10:f9e6a4cc4f7d |
|---|---|
| 1 local Luan = require "luan:Luan.luan" | |
| 2 local error = Luan.error | |
| 3 local ipairs = Luan.ipairs or error() | |
| 4 local Parsers = require "luan:Parsers.luan" | |
| 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" | |
| 9 local Http = require "luan:http/Http.luan" | |
| 10 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() | |
| 13 local Chat = require "site:/lib/Chat.luan" | |
| 14 local get_chat_by_id = Chat.get_by_id or error() | |
| 15 local Post = require "site:/lib/Post.luan" | |
| 16 local post_search = Post.search or error() | |
| 17 | |
| 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 | |
| 33 local function html() | |
| 34 local user = current_user() or error() | |
| 35 local chat = Http.request.parameters.chat or error() | |
| 36 chat = get_chat_by_id(chat) or error() | |
| 37 local posts = post_search( "post_chat_id:"..chat.id, "id" ) | |
| 38 %> | |
| 39 <div top> | |
| 40 <h3><%= chat.other_users_email(user) %></h3> | |
| 41 <button>delete</button> | |
| 42 </div> | |
| 43 <div main> | |
| 44 <% | |
| 45 for _, post in ipairs(posts) do | |
| 46 post_html(post) | |
| 47 end | |
| 48 %> | |
| 49 <div input> | |
| 50 <textarea oninput="fixTextarea(event)" onkeydown="textareaKey(event)"></textarea> | |
| 51 <button onclick="addPost()" title="Send"><img src="/images/send.svg"></button> | |
| 52 </div> | |
| 53 </div> | |
| 54 <% | |
| 55 end | |
| 56 | |
| 57 return function() | |
| 58 Io.stdout = Http.response.text_writer() | |
| 59 %> | |
| 60 document.querySelector('div[posts]').innerHTML = <%=json_string(`html()`)%>; | |
| 61 fixDates(); | |
| 62 document.querySelector('div[input] textarea').focus(); | |
| 63 <% | |
| 64 end |
