7
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
10
|
3 local ipairs = Luan.ipairs or error()
|
63
|
4 local String = require "luan:String.luan"
|
|
5 local digest_message = String.digest_message or error()
|
7
|
6 local Parsers = require "luan:Parsers.luan"
|
|
7 local json_string = Parsers.json_string or error()
|
65
|
8 local Html = require "luan:Html.luan"
|
|
9 local html_encode = Html.encode or error()
|
96
|
10 local Math = require "luan:Math.luan"
|
|
11 local random = Math.random or error()
|
7
|
12 local Io = require "luan:Io.luan"
|
|
13 local Http = require "luan:http/Http.luan"
|
|
14 local User = require "site:/lib/User.luan"
|
|
15 local current_user = User.current or error()
|
46
|
16 local get_user_by_id = User.get_by_id or error()
|
7
|
17 local Chat = require "site:/lib/Chat.luan"
|
|
18 local get_chat_by_id = Chat.get_by_id or error()
|
10
|
19 local Post = require "site:/lib/Post.luan"
|
|
20 local post_search = Post.search or error()
|
12
|
21 local Shared = require "site:/lib/Shared.luan"
|
|
22 local post_html = Shared.post_html or error()
|
83
|
23 local group_name = Shared.group_name or error()
|
27
|
24 local Logging = require "luan:logging/Logging.luan"
|
|
25 local logger = Logging.logger "get_chat.js"
|
7
|
26
|
10
|
27
|
63
|
28 local function get_html(user,chat)
|
89
|
29 local spy = Http.request.cookies.spy ~= nil
|
|
30 if not spy then
|
|
31 chat.read(user)
|
|
32 end
|
10
|
33 local posts = post_search( "post_chat_id:"..chat.id, "id" )
|
7
|
34 %>
|
10
|
35 <div top>
|
27
|
36 <h3>
|
|
37 <img back onclick="back()" src="/images/arrow_back.svg">
|
83
|
38 <span>
|
|
39 <%
|
|
40 local user_ids = chat.other_user_ids(user.id)
|
|
41 if #user_ids > 1 then
|
|
42 %>
|
|
43 <%= group_name(user_ids) %>
|
|
44 <%
|
|
45 else
|
|
46 local other_user = get_user_by_id(user_ids[1]) or error()
|
|
47 %>
|
|
48 <%= other_user.name_html() %><span online="<%= other_user.id %>"></span>
|
|
49 <%
|
|
50 local voice_url = other_user.voice_url
|
|
51 if voice_url ~= nil then
|
|
52 %>
|
|
53 <a href="<%=voice_url%>" title="Call" target="voice"><img phone src="/images/call.svg"></a>
|
|
54 <%
|
|
55 end
|
|
56 end
|
|
57 %>
|
|
58 </span>
|
27
|
59 </h3>
|
68
|
60 <span pulldown>
|
|
61 <img onclick="clickMenu(this)" src="/images/menu.svg">
|
|
62 <div>
|
|
63 <span onclick="openPeople()">People in Chat</span>
|
104
|
64 <span onclick="openMute()">Mute Chat</span>
|
83
|
65 <span onclick="openAddToChat()">Add Someone to Chat</span>
|
107
|
66 <span onclick="deleteOld()">Delete Old Messages</span>
|
68
|
67 <span onclick="deleteChat()">Delete Chat</span>
|
|
68 </div>
|
|
69 </span>
|
10
|
70 </div>
|
|
71 <div main>
|
|
72 <%
|
|
73 for _, post in ipairs(posts) do
|
|
74 post_html(post)
|
|
75 end
|
|
76 %>
|
|
77 <div input>
|
79
|
78 <span textarea>
|
|
79 <div reply hidden>
|
|
80 <div reply_top>
|
|
81 <span>Reply to</span>
|
|
82 <img src="/images/close.svg" onclick="closeReply()">
|
|
83 </div>
|
|
84 <div text></div>
|
|
85 <div><a when></a></div>
|
|
86 </div>
|
|
87 <textarea oninput="fixTextarea(event)" onkeydown="textareaKey(event)"></textarea>
|
|
88 </span>
|
63
|
89 <button onclick="uploadFile()" title="Add file"><img src="/images/upload_file.svg"></button>
|
10
|
90 <button onclick="addPost()" title="Send"><img src="/images/send.svg"></button>
|
|
91 </div>
|
|
92 </div>
|
7
|
93 <%
|
|
94 end
|
|
95
|
65
|
96 local function people(chat)
|
|
97 for _, user_id in ipairs(chat.user_ids) do
|
|
98 local user = get_user_by_id(user_id)
|
|
99 local name = user.name
|
|
100 local email = user.email
|
|
101 local voice_url = user.voice_url
|
73
|
102 local voice = voice_url and `%> <a href="<%=voice_url%>" title="Call" target="voice"><img phone src="/images/call.svg"></a><%` or ""
|
65
|
103 %>
|
|
104 <p>
|
|
105 <%
|
|
106 if name == nil then
|
|
107 %>
|
73
|
108 <b><%=html_encode(email)%></b><%=voice%><br>
|
65
|
109 <%
|
|
110 else
|
|
111 %>
|
|
112 <b><%=html_encode(name)%></b><%=voice%><br>
|
73
|
113 <%=html_encode(email)%><br>
|
65
|
114 <%
|
|
115 end
|
|
116 %>
|
73
|
117 <span last_seen="<%=user_id%>"></span>
|
65
|
118 </p>
|
|
119 <%
|
|
120 end
|
|
121 end
|
|
122
|
7
|
123 return function()
|
63
|
124 local user = current_user() or error()
|
|
125 local chat = Http.request.parameters.chat or error()
|
|
126 chat = get_chat_by_id(chat) or error()
|
|
127 local html = `get_html(user,chat)`
|
97
|
128 local digest = digest_message("MD5","luan chat "..random())
|
7
|
129 Io.stdout = Http.response.text_writer()
|
|
130 %>
|
63
|
131 gotChat(<%=json_string(html)%>);
|
|
132 filebinUrl = 'https://filebin.net/<%=digest%>/';
|
65
|
133 document.querySelector('dialog[people] div[people]').innerHTML = <%=json_string(`people(chat)`)%>;
|
7
|
134 <%
|
|
135 end
|