0
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Io = require "luan:Io.luan"
|
|
4 local Http = require "luan:http/Http.luan"
|
|
5 local Shared = require "site:/lib/Shared.luan"
|
|
6 local head = Shared.head or error()
|
|
7 local header = Shared.header or error()
|
4
|
8 local started = Shared.started or error()
|
|
9 local User = require "site:/lib/User.luan"
|
|
10 local current_user = User.current or error()
|
|
11 local Chat = require "site:/lib/Chat.luan"
|
|
12 local get_chat_by_id = Chat.get_by_id or error()
|
0
|
13
|
|
14
|
|
15 return function()
|
4
|
16 local user = current_user()
|
|
17 if user == nil then
|
|
18 Http.response.send_redirect("/login.html")
|
|
19 return
|
|
20 end
|
|
21 local chat_id = Http.request.parameters.chat
|
|
22 local chat
|
|
23 if chat_id ~= nil then
|
|
24 chat = get_chat_by_id(chat_id) or error()
|
|
25 else
|
|
26 chat = Chat.new{
|
|
27 user_id = user.id
|
|
28 name = "whatever"
|
|
29 }
|
|
30 chat.save()
|
|
31 end
|
0
|
32 Io.stdout = Http.response.text_writer()
|
|
33 %>
|
|
34 <!doctype html>
|
|
35 <html lang="en">
|
|
36 <head>
|
|
37 <% head() %>
|
4
|
38 <style>
|
|
39 @import "/chat.css?s=<%=started%>";
|
|
40 </style>
|
|
41 <script>
|
|
42 let chatId = <%=chat_id%>;
|
|
43 </script>
|
|
44 <script src="/chat.js?s=<%=started%>"></script>
|
0
|
45 </head>
|
|
46 <body>
|
|
47 <% header() %>
|
4
|
48 <div content ai_container>
|
|
49 <div top>
|
|
50 <h3 name><%= chat.name_html() %></h3>
|
|
51 <span pulldown>
|
|
52 <img onclick="clickMenu(this)" src="/images/menu.svg">
|
|
53 <div>
|
|
54 <span onclick="renameChat()">Rename Chat</span>
|
|
55 <span onclick="deleteChat()">Delete Chat</span>
|
1
|
56 </div>
|
4
|
57 </span>
|
|
58 </div>
|
|
59 <div scroll>
|
|
60 <div messages>
|
5
|
61 <% chat.output_messages_html() %>
|
1
|
62 </div>
|
4
|
63 </div>
|
|
64 <div ask>
|
|
65 <textarea autofocus oninput="fixTextarea(event)" onkeydown="textareaKey(event)"></textarea>
|
|
66 <button onclick="askAi()" title="Send"><img src="/images/send.svg"></button>
|
1
|
67 </div>
|
4
|
68 <img waiting-ai-icon src="/images/spinner_green.gif">
|
0
|
69 </div>
|
4
|
70 <dialog rename>
|
|
71 <h2>Rename Chat</h2>
|
|
72 <form action="javascript:saveRenameChat()">
|
|
73 <p>
|
|
74 <label>Chat name</label><br>
|
|
75 <input name=name required><br>
|
|
76 <span error></span>
|
|
77 </p>
|
|
78 <div buttons>
|
|
79 <button type=button onclick="closeModal(this)">Cancel</button>
|
|
80 <button type=submit>Rename</button>
|
|
81 </div>
|
|
82 </form>
|
|
83 </dialog>
|
|
84 <dialog delete>
|
|
85 <h2>Delete Chat</h2>
|
|
86 <p>Are you sure that you want to delete this chat?</p>
|
|
87 <div buttons>
|
|
88 <button onclick="closeModal(this)">Cancel</button>
|
|
89 <button onclick="doDeleteChat(this)">Delete</button>
|
|
90 </div>
|
|
91 </dialog>
|
0
|
92 </body>
|
|
93 </html>
|
|
94 <%
|
|
95 end
|