annotate src/get_chat.js.luan @ 63:afd5ab5b02a2

file upload
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 05 Mar 2025 18:43:06 -0700
parents 9298b04607ae
children 6cfef9850520
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()
63
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 53
diff changeset
4 local String = require "luan:String.luan"
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 53
diff changeset
5 local digest_message = String.digest_message or error()
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Parsers = require "luan:Parsers.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local json_string = Parsers.json_string or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Io = require "luan:Io.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Http = require "luan:http/Http.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local User = require "site:/lib/User.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local current_user = User.current or error()
46
42b741a1d5c6 add username
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
12 local get_user_by_id = User.get_by_id or error()
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local Chat = require "site:/lib/Chat.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local get_chat_by_id = Chat.get_by_id or error()
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
15 local Post = require "site:/lib/Post.luan"
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
16 local post_search = Post.search or error()
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
17 local Shared = require "site:/lib/Shared.luan"
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
18 local post_html = Shared.post_html or error()
27
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
19 local Logging = require "luan:logging/Logging.luan"
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
20 local logger = Logging.logger "get_chat.js"
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
22
63
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 53
diff changeset
23 local function get_html(user,chat)
53
9298b04607ae add unread
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
24 chat.read(user)
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
25 local posts = post_search( "post_chat_id:"..chat.id, "id" )
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 %>
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
27 <div top>
27
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
28 <h3>
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
29 <img back onclick="back()" src="/images/arrow_back.svg">
46
42b741a1d5c6 add username
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
30 <span><%
42b741a1d5c6 add username
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
31 local user_id = chat.other_user_id(user.id)
42b741a1d5c6 add username
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
32 local other_user = get_user_by_id(user_id) or error(user_id)
42b741a1d5c6 add username
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
33 %><%= other_user.name_html() %><span online="<%= other_user.id %>"></span><%
42b741a1d5c6 add username
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
34 local voice_url = other_user.voice_url
42b741a1d5c6 add username
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
35 if voice_url ~= nil then
42b741a1d5c6 add username
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
36 %> <a href="<%=voice_url%>" title="Call" target="voice"><img phone src="/images/call.svg"></a><%
42b741a1d5c6 add username
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
37 end
42b741a1d5c6 add username
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
38 %></span>
27
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
39 </h3>
34
Franklin Schmidt <fschmidt@gmail.com>
parents: 33
diff changeset
40 <button onclick='deleteChat()'>Delete</button>
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
41 </div>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
42 <div main>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
43 <%
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
44 for _, post in ipairs(posts) do
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
45 post_html(post)
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
46 end
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
47 %>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
48 <div input>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
49 <textarea oninput="fixTextarea(event)" onkeydown="textareaKey(event)"></textarea>
63
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 53
diff changeset
50 <button onclick="uploadFile()" title="Add file"><img src="/images/upload_file.svg"></button>
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
51 <button onclick="addPost()" title="Send"><img src="/images/send.svg"></button>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
52 </div>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
53 </div>
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 <%
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 end
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 return function()
63
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 53
diff changeset
58 local user = current_user() or error()
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 53
diff changeset
59 local chat = Http.request.parameters.chat or error()
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 53
diff changeset
60 chat = get_chat_by_id(chat) or error()
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 53
diff changeset
61 local html = `get_html(user,chat)`
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 53
diff changeset
62 local digest = digest_message("MD5",user.password..chat.id)
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 Io.stdout = Http.response.text_writer()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 %>
63
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 53
diff changeset
65 gotChat(<%=json_string(html)%>);
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 53
diff changeset
66 filebinUrl = 'https://filebin.net/<%=digest%>/';
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 <%
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 end