7
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
10
|
3 local ipairs = Luan.ipairs or error()
|
7
|
4 local Parsers = require "luan:Parsers.luan"
|
|
5 local json_string = Parsers.json_string or error()
|
10
|
6 local Html = require "luan:Html.luan"
|
|
7 local html_encode = Html.encode or error()
|
7
|
8 local Io = require "luan:Io.luan"
|
|
9 local Http = require "luan:http/Http.luan"
|
|
10 local User = require "site:/lib/User.luan"
|
10
|
11 local get_user_by_id = User.get_by_id or error()
|
7
|
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()
|
10
|
15 local Post = require "site:/lib/Post.luan"
|
|
16 local post_search = Post.search or error()
|
7
|
17
|
|
18
|
10
|
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
|
7
|
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()
|
10
|
37 local posts = post_search( "post_chat_id:"..chat.id, "id" )
|
7
|
38 %>
|
10
|
39 <div top>
|
|
40 <h3><%= chat.other_users_email(user) %></h3>
|
11
|
41 <button onclick='deleteChat()'>delete</button>
|
10
|
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>
|
7
|
54 <%
|
|
55 end
|
|
56
|
|
57 return function()
|
|
58 Io.stdout = Http.response.text_writer()
|
|
59 %>
|
|
60 document.querySelector('div[posts]').innerHTML = <%=json_string(`html()`)%>;
|
10
|
61 fixDates();
|
|
62 document.querySelector('div[input] textarea').focus();
|
7
|
63 <%
|
|
64 end
|