annotate src/chat.js.luan @ 7:41d35b72c774

chat page
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 29 Oct 2024 22:11:40 -0600
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Parsers = require "luan:Parsers.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local json_string = Parsers.json_string or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Io = require "luan:Io.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Http = require "luan:http/Http.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local User = require "site:/lib/User.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local current_user = User.current or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Chat = require "site:/lib/Chat.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local get_chat_by_id = Chat.get_by_id or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local function html()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local user = current_user() or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 local chat = Http.request.parameters.chat or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 chat = get_chat_by_id(chat) or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 %>
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 <p><%= chat.other_users_email(user) %></p>
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 <%
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 end
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 return function()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 Io.stdout = Http.response.text_writer()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 %>
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 document.querySelector('div[posts]').innerHTML = <%=json_string(`html()`)%>;
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 <%
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 end