annotate src/index.html.luan @ 83:a47036fd0158

group chat
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 11 Mar 2025 13:56:59 -0600
parents b5a316575e64
children 3053a4fc10be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Io = require "luan:Io.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Http = require "luan:http/Http.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Shared = require "site:/lib/Shared.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local head = Shared.head or error()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local header = Shared.header or error()
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
8 local started = Shared.started or error()
15
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
9 local chats_html = Shared.chats_html or error()
4
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
10 local User = require "site:/lib/User.luan"
5
a49866b52cc2 login to chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
11 local current_user = User.current or error()
4
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
12 local Chat = require "site:/lib/Chat.luan"
59
8270106644db add chat.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 58
diff changeset
13 local get_chat_by_id = Chat.get_by_id or error()
8
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
14 local Logging = require "luan:logging/Logging.luan"
21
5a56297713a3 move chat to home
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
15 local logger = Logging.logger "index.html"
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 return function()
4
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
19 local user = current_user()
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
20 if user == nil then
59
8270106644db add chat.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 58
diff changeset
21 Http.response.send_redirect("/login.html")
4
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
22 return
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
23 end
59
8270106644db add chat.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 58
diff changeset
24 local user_id = user.id
8270106644db add chat.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 58
diff changeset
25 local chat = Http.request.parameters.chat
65
6cfef9850520 people popup
Franklin Schmidt <fschmidt@gmail.com>
parents: 63
diff changeset
26 chat = chat and get_chat_by_id(chat)
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 Io.stdout = Http.response.text_writer()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 <!doctype html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 <html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 <head>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 <% head() %>
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
33 <style>
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
34 @import "chat.css?s=<%=started%>";
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
35 </style>
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
36 <script src="chat.js?s=<%=started%>"></script>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 </head>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 <body>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 <% header() %>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
40 <div chat_content show="intro">
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
41 <div chats>
15
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
42 <% chats_html() %>
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
43 </div>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
44 <div intro>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
45 <h3 or>Choose a chat on the left</h3>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
46 <p or>or</p>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
47 <h3>Chat with another person</h3>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
48 <form action="javascript:invite()">
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
49 <p>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
50 <label>Person's email</label><br>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
51 <input type=email name=email required><br>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
52 </p>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
53 <p>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
54 <input type=submit>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
55 </p>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
56 </form>
34
Franklin Schmidt <fschmidt@gmail.com>
parents: 33
diff changeset
57 </div>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
58 <div posts></div>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 </div>
35
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
60 <div hidden>
79
Franklin Schmidt <fschmidt@gmail.com>
parents: 78
diff changeset
61 <span pulldown=author>
35
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
62 <img onclick="clickMenu(this)" src="/images/more_vert.svg">
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
63 <div>
38
436216d17a1b fix edit and delete
Franklin Schmidt <fschmidt@gmail.com>
parents: 35
diff changeset
64 <span onclick="editPost(this)">Edit</span>
79
Franklin Schmidt <fschmidt@gmail.com>
parents: 78
diff changeset
65 <span onclick="replyPost(this)">Reply</span>
38
436216d17a1b fix edit and delete
Franklin Schmidt <fschmidt@gmail.com>
parents: 35
diff changeset
66 <span onclick="deletePost(this)">Delete</span>
35
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
67 </div>
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
68 </span>
79
Franklin Schmidt <fschmidt@gmail.com>
parents: 78
diff changeset
69 <span pulldown=other>
Franklin Schmidt <fschmidt@gmail.com>
parents: 78
diff changeset
70 <img onclick="clickMenu(this)" src="/images/more_vert.svg">
Franklin Schmidt <fschmidt@gmail.com>
parents: 78
diff changeset
71 <div>
Franklin Schmidt <fschmidt@gmail.com>
parents: 78
diff changeset
72 <span onclick="replyPost(this)">Reply</span>
Franklin Schmidt <fschmidt@gmail.com>
parents: 78
diff changeset
73 </div>
Franklin Schmidt <fschmidt@gmail.com>
parents: 78
diff changeset
74 </span>
35
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
75 </div>
20
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
76 <dialog delete_chat>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
77 <h2>Delete Chat</h2>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
78 <p>Are you sure that you want to delete this chat?</p>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
79 <div buttons>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
80 <button onclick="closeModal(this)">Cancel</button>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
81 <button onclick="doDeleteChat(this)">Delete</button>
20
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
82 </div>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
83 </dialog>
23
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
84 <dialog delete_post>
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
85 <h2>Delete Message</h2>
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
86 <p>Are you sure that you want to delete this message?</p>
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
87 <div buttons>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
88 <button onclick="closeModal(this)">Cancel</button>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
89 <button onclick="doDeletePost(this)">Delete</button>
23
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
90 </div>
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
91 </dialog>
24
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
92 <dialog edit_post>
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
93 <h2>Edit Message</h2>
78
Franklin Schmidt <fschmidt@gmail.com>
parents: 72
diff changeset
94 <p><textarea onfocus="fixTextarea(event)" oninput="fixTextarea(event)" onkeydown="editTextareaKey(event)"></textarea></p>
24
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
95 <div buttons>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
96 <button onclick="closeModal(this)">Cancel</button>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
97 <button onclick="savePost(this)">Save</button>
24
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
98 </div>
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
99 </dialog>
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
100 <dialog invite>
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
101 <h2>Chat with another person</h2>
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
102 <p>We have sent an invite to <span email></span></p>
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
103 <div buttons>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
104 <button onclick="gotoInvite(this)">Close</button>
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
105 </div>
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
106 </dialog>
65
6cfef9850520 people popup
Franklin Schmidt <fschmidt@gmail.com>
parents: 63
diff changeset
107 <dialog people>
6cfef9850520 people popup
Franklin Schmidt <fschmidt@gmail.com>
parents: 63
diff changeset
108 <h2>People in the chat</h2>
6cfef9850520 people popup
Franklin Schmidt <fschmidt@gmail.com>
parents: 63
diff changeset
109 <div people></div>
6cfef9850520 people popup
Franklin Schmidt <fschmidt@gmail.com>
parents: 63
diff changeset
110 <div buttons>
6cfef9850520 people popup
Franklin Schmidt <fschmidt@gmail.com>
parents: 63
diff changeset
111 <button onclick="closeModal(this)">Close</button>
6cfef9850520 people popup
Franklin Schmidt <fschmidt@gmail.com>
parents: 63
diff changeset
112 </div>
6cfef9850520 people popup
Franklin Schmidt <fschmidt@gmail.com>
parents: 63
diff changeset
113 </dialog>
83
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
114 <dialog add>
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
115 <h2>Add Someone to Chat</h2>
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
116 <form action="javascript:addToChat()">
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
117 <p>
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
118 <label>Person's email</label><br>
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
119 <input type=email name=email required><br>
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
120 <span error></span>
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
121 </p>
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
122 <div buttons>
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
123 <button onclick="closeModal(this)">Cancel</button>
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
124 <button type=submit>Add</button>
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
125 </div>
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
126 </form>
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 79
diff changeset
127 </dialog>
63
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 60
diff changeset
128 <input type="file" required onchange="loadedFile(this)">
15
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
129 <script>
35
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
130 'use strict';
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
131
8
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
132 <%
65
6cfef9850520 people popup
Franklin Schmidt <fschmidt@gmail.com>
parents: 63
diff changeset
133 if chat ~= nil then
8
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
134 %>
65
6cfef9850520 people popup
Franklin Schmidt <fschmidt@gmail.com>
parents: 63
diff changeset
135 selectChat('<%=chat.id%>');
8
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
136 <%
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
137 end
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
138 %>
35
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
139 setUserEventSource(<%=user_id%>);
30
f4708943f29e add heartbeat
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
140 lastUpdate = <%=user.last_update()%>;
35
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
141 userId = '<%=user_id%>';
15
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
142 </script>
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
143 </body>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144 </html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
145 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146 end