comparison src/chat.html.luan @ 8:d654e3471132

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 30 Oct 2024 00:08:59 -0600
parents 41d35b72c774
children b8b12fd8be22
comparison
equal deleted inserted replaced
7:41d35b72c774 8:d654e3471132
18 local to_set = Utils.to_set or error() 18 local to_set = Utils.to_set or error()
19 local Db = require "site:/lib/Db.luan" 19 local Db = require "site:/lib/Db.luan"
20 local run_in_transaction = Db.run_in_transaction or error() 20 local run_in_transaction = Db.run_in_transaction or error()
21 local Chat = require "site:/lib/Chat.luan" 21 local Chat = require "site:/lib/Chat.luan"
22 local chat_search = Chat.search or error() 22 local chat_search = Chat.search or error()
23 local Logging = require "luan:logging/Logging.luan"
24 local logger = Logging.logger "chat.html"
23 25
24 26
25 local function get_chat(with) 27 local function get_chat(with)
26 local t = {} 28 local t = {}
27 local ids = {} 29 local ids = {}
30 local id = with_user.id 32 local id = with_user.id
31 t[#t+1] = "+chat_user_ids:"..id 33 t[#t+1] = "+chat_user_ids:"..id
32 ids[#ids+1] = id 34 ids[#ids+1] = id
33 end 35 end
34 local query = concat(t," ") 36 local query = concat(t," ")
35 run_in_transaction( function() 37 return run_in_transaction( function()
36 local chats = chat_search(query) 38 local chats = chat_search(query)
37 local n = #chats 39 local n = #chats
38 if n == 0 then 40 if n == 0 then
39 local chat = Chat.new{ 41 local chat = Chat.new{
40 user_ids = ids 42 user_ids = ids
63 url = url.."?"..concat(t,"&") 65 url = url.."?"..concat(t,"&")
64 end 66 end
65 Http.response.send_redirect(url) 67 Http.response.send_redirect(url)
66 return 68 return
67 end 69 end
70 local selected = nil
68 if not is_empty(with) then 71 if not is_empty(with) then
69 with[user.email] = true 72 with[user.email] = true
70 if size(with) > 1 then 73 if size(with) > 1 then
71 get_chat(with) 74 selected = get_chat(with)
72 end 75 end
73 end 76 end
74 local chats = user.get_chats() 77 local chats = user.get_chats()
75 Io.stdout = Http.response.text_writer() 78 Io.stdout = Http.response.text_writer()
76 %> 79 %>
141 %> 144 %>
142 </div> 145 </div>
143 <div posts></div> 146 <div posts></div>
144 </div> 147 </div>
145 </body> 148 </body>
149 <%
150 if selected ~= nil then
151 %>
152 <script>
153 let div = document.querySelector('div[chat="<%=selected.id%>"]');
154 selectChat(div);
155 </script>
156 <%
157 end
158 %>
146 </html> 159 </html>
147 <% 160 <%
148 end 161 end