0
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
4
|
3 local ipairs = Luan.ipairs or error()
|
23
|
4 local pairs = Luan.pairs or error()
|
0
|
5 local Io = require "luan:Io.luan"
|
|
6 local Http = require "luan:http/Http.luan"
|
|
7 local Shared = require "site:/lib/Shared.luan"
|
|
8 local head = Shared.head or error()
|
|
9 local header = Shared.header or error()
|
4
|
10 local User = require "site:/lib/User.luan"
|
|
11 local current_user = User.current or error()
|
|
12 local Chat = require "site:/lib/Chat.luan"
|
|
13 local chat_search = Chat.search or error()
|
23
|
14 local languages = require "site:/lib/languages.luan"
|
|
15 local Logging = require "luan:logging/Logging.luan"
|
|
16 local logger = Logging.logger "chats.html"
|
0
|
17
|
|
18
|
|
19 return function()
|
4
|
20 local user = current_user()
|
|
21 if user == nil then
|
|
22 Http.response.send_redirect("/login.html")
|
|
23 return
|
|
24 end
|
|
25 local chats = chat_search( "chat_user_id:"..user.id, "chat_updated desc" )
|
23
|
26 local select_language = #chats > 0 and chats[1].language or nil
|
0
|
27 Io.stdout = Http.response.text_writer()
|
|
28 %>
|
|
29 <!doctype html>
|
|
30 <html lang="en">
|
|
31 <head>
|
|
32 <% head() %>
|
21
|
33 <style>
|
23
|
34 form {
|
|
35 margin-bottom: 20px;
|
|
36 }
|
21
|
37 td {
|
|
38 padding: 8px 8px;
|
|
39 }
|
|
40 </style>
|
0
|
41 </head>
|
|
42 <body>
|
|
43 <% header() %>
|
|
44 <div content>
|
15
|
45 <h1>Your Chats</h1>
|
23
|
46 <form action="new_chat.red">
|
|
47 <select name=language>
|
|
48 <% for _, lang in pairs(languages) do
|
|
49 local code = lang.code
|
|
50 local selected = code==select_language and "selected" or ""
|
|
51 %>
|
|
52 <option value="<%=code%>" <%=selected%> ><%=lang.name%></option>
|
|
53 <% end %>
|
|
54 </select>
|
|
55 <input type=submit value="new chat">
|
|
56 </form>
|
21
|
57 <table>
|
4
|
58 <% for _, chat in ipairs(chats) do %>
|
21
|
59 <tr>
|
|
60 <td><%= chat.language_name() %></td>
|
|
61 <td><a href="chat.html?chat=<%=chat.id%>"><%= chat.name_html() %></a></td>
|
|
62 </tr>
|
4
|
63 <% end %>
|
21
|
64 </table>
|
0
|
65 </div>
|
|
66 </body>
|
|
67 </html>
|
|
68 <%
|
|
69 end
|