Mercurial Hosting > lang
comparison src/chat.html.luan @ 41:2a4c83ce3deb
public chat
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 11 Aug 2025 07:58:32 +0900 |
parents | 2737eeedc1d5 |
children | 1d9d9786d76f |
comparison
equal
deleted
inserted
replaced
40:6cdb2c761e08 | 41:2a4c83ce3deb |
---|---|
11 local head = Shared.head or error() | 11 local head = Shared.head or error() |
12 local header = Shared.header or error() | 12 local header = Shared.header or error() |
13 local started = Shared.started or error() | 13 local started = Shared.started or error() |
14 local voices = Shared.voices or error() | 14 local voices = Shared.voices or error() |
15 local User = require "site:/lib/User.luan" | 15 local User = require "site:/lib/User.luan" |
16 local current_user = User.current_required or error() | 16 local current_user = User.current or error() |
17 local Chat = require "site:/lib/Chat.luan" | 17 local Chat = require "site:/lib/Chat.luan" |
18 local get_chat_by_id = Chat.get_by_id or error() | 18 local get_chat_by_id = Chat.get_by_id or error() |
19 local languages = require "site:/lib/languages.luan" | 19 local languages = require "site:/lib/languages.luan" |
20 | 20 |
21 | 21 |
22 return function() | 22 return function() |
23 local user = current_user() | |
24 if user == nil then return end | |
25 local chat_id = Http.request.parameters.chat or error() | 23 local chat_id = Http.request.parameters.chat or error() |
26 local chat = get_chat_by_id(chat_id) or error() | 24 local chat = get_chat_by_id(chat_id) or error() |
25 local user = current_user() | |
26 local is_owner = user ~= nil and user.id == chat.user_id | |
27 is_owner or not chat.is_private or error "private" | |
27 local init_text = chat.init_text() | 28 local init_text = chat.init_text() |
28 Io.stdout = Http.response.text_writer() | 29 Io.stdout = Http.response.text_writer() |
29 %> | 30 %> |
30 <!doctype html> | 31 <!doctype html> |
31 <html lang="en"> | 32 <html lang="en"> |
42 <div top> | 43 <div top> |
43 <h3 name></h3> | 44 <h3 name></h3> |
44 <span pulldown> | 45 <span pulldown> |
45 <img onclick="clickMenu(this)" src="/images/menu.svg"> | 46 <img onclick="clickMenu(this)" src="/images/menu.svg"> |
46 <div> | 47 <div> |
48 <% if is_owner then %> | |
47 <span onclick="editChat()">Edit Chat</span> | 49 <span onclick="editChat()">Edit Chat</span> |
48 <span onclick="deleteChat()">Delete Chat</span> | 50 <span onclick="deleteChat()">Delete Chat</span> |
51 <% end %> | |
49 <span onclick="systemPrompt()">System Prompt</span> | 52 <span onclick="systemPrompt()">System Prompt</span> |
50 </div> | 53 </div> |
51 </span> | 54 </span> |
52 </div> | 55 </div> |
53 <div messages> | 56 <div messages> |
54 <% chat.output_messages_html() %> | 57 <% chat.output_messages_html() %> |
55 </div> | 58 </div> |
59 <% if is_owner then %> | |
56 <div ask> | 60 <div ask> |
57 <textarea autofocus oninput="fixTextarea(event.target)" onkeydown="textareaKey(event)"><%= html_encode(init_text) %></textarea> | 61 <textarea autofocus oninput="fixTextarea(event.target)" onkeydown="textareaKey(event)"><%= html_encode(init_text) %></textarea> |
58 <div buttons> | 62 <div buttons> |
59 <audio controls preload=none></audio> | 63 <audio controls preload=none></audio> |
60 <button record onclick="toggleRecording()">Record</button> | 64 <button record onclick="toggleRecording()">Record</button> |
61 <button onclick="askAi()" title="Send"><img src="/images/send.svg"></button> | 65 <button onclick="askAi()" title="Send"><img src="/images/send.svg"></button> |
62 </div> | 66 </div> |
63 </div> | 67 </div> |
68 <% end %> | |
64 </div> | 69 </div> |
65 <img waiting-ai-icon src="/images/spinner_green.gif"> | 70 <img waiting-ai-icon src="/images/spinner_green.gif"> |
66 <dialog edit> | 71 <dialog edit> |
67 <h2>Edit Chat</h2> | 72 <h2>Edit Chat</h2> |
68 <form onsubmit="saveChat(this)" action="javascript:"> | 73 <form onsubmit="saveChat(this)" action="javascript:"> |
93 <label clickable><input type=checkbox name=autoplay>Autoplay</label> | 98 <label clickable><input type=checkbox name=autoplay>Autoplay</label> |
94 </p> | 99 </p> |
95 <p> | 100 <p> |
96 <label clickable><input type=checkbox name=show_text>Show text</label> | 101 <label clickable><input type=checkbox name=show_text>Show text</label> |
97 </p> | 102 </p> |
103 <p> | |
104 <label clickable><input type=checkbox name=is_private>Private chat</label> | |
105 </p> | |
98 <div buttons> | 106 <div buttons> |
99 <button type=button onclick="closeModal(this)">Cancel</button> | 107 <button type=button onclick="closeModal(this)">Cancel</button> |
100 <button type=submit>Save</button> | 108 <button type=submit>Save</button> |
101 </div> | 109 </div> |
102 </form> | 110 </form> |
119 <button onclick="closeModal(this)">Close</button> | 127 <button onclick="closeModal(this)">Close</button> |
120 </div> | 128 </div> |
121 </dialog> | 129 </dialog> |
122 <input name=initialized style="display:none"> | 130 <input name=initialized style="display:none"> |
123 <script> | 131 <script> |
132 'use strict'; | |
133 //let test = 'a'; | |
134 //alert(test); | |
135 //test = 'b'; | |
124 setChat(<%= json_string(chat.info()) %>); | 136 setChat(<%= json_string(chat.info()) %>); |
125 handleChatMarkdown(); | 137 handleChatMarkdown(); |
138 scrollToEnd(); | |
139 /* | |
126 setTimeout(function(){ | 140 setTimeout(function(){ |
127 let initialized = document.querySelector('[name=initialized]'); | 141 let initialized = document.querySelector('[name=initialized]'); |
128 if( !initialized.value ) { | 142 if( !initialized.value ) { |
129 initialized.value = 'yes'; | 143 initialized.value = 'yes'; |
130 //alert('init'); | 144 //alert('init'); |
131 scrollToEnd(); | 145 scrollToEnd(); |
132 } | 146 } |
133 },10); | 147 },10); |
148 */ | |
134 </script> | 149 </script> |
135 </body> | 150 </body> |
136 </html> | 151 </html> |
137 <% | 152 <% |
138 end | 153 end |