annotate src/get_chat.js.luan @ 12:9f45d32670ae

server push
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 31 Oct 2024 21:40:57 -0600
parents 563a5358f2ee
children 809193524522
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
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
3 local ipairs = Luan.ipairs or error()
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Parsers = require "luan:Parsers.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local json_string = Parsers.json_string or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Io = require "luan:Io.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Http = require "luan:http/Http.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local User = require "site:/lib/User.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local current_user = User.current or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local Chat = require "site:/lib/Chat.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local get_chat_by_id = Chat.get_by_id or error()
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
12 local Post = require "site:/lib/Post.luan"
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
13 local post_search = Post.search or error()
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
14 local Shared = require "site:/lib/Shared.luan"
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
15 local post_html = Shared.post_html or error()
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
17
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 local function html()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 local user = current_user() or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local chat = Http.request.parameters.chat or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 chat = get_chat_by_id(chat) or error()
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
22 local posts = post_search( "post_chat_id:"..chat.id, "id" )
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 %>
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
24 <div top>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
25 <h3><%= chat.other_users_email(user) %></h3>
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
26 <button onclick='deleteChat()'>delete</button>
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
27 </div>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
28 <div main>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
29 <%
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
30 for _, post in ipairs(posts) do
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
31 post_html(post)
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
32 end
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
33 %>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
34 <div input>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
35 <textarea oninput="fixTextarea(event)" onkeydown="textareaKey(event)"></textarea>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
36 <button onclick="addPost()" title="Send"><img src="/images/send.svg"></button>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
37 </div>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
38 </div>
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 <%
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 end
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 return function()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 Io.stdout = Http.response.text_writer()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 %>
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
45 gotChat(<%=json_string(`html()`)%>);
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 <%
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 end