Mercurial Hosting > chat
changeset 60:3521166513b3
finish invite
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 04 Mar 2025 20:31:00 -0700 |
parents | 8270106644db |
children | d4d154b404f8 |
files | src/account.html.luan src/chat.css src/chat.js src/index.html.luan src/invite.js.luan |
diffstat | 5 files changed, 104 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/account.html.luan Tue Mar 04 08:22:45 2025 -0700 +++ b/src/account.html.luan Tue Mar 04 20:31:00 2025 -0700 @@ -157,8 +157,8 @@ <input type=text name=username placeholder="<%=html_encode(user.email)%>"><br> </p> <div buttons> - <button type=button cancel onclick="closeModal(this)">Cancel</button> - <button type=submit go>Save</button> + <button type=button onclick="closeModal(this)">Cancel</button> + <button type=submit>Save</button> </div> </form> </dialog> @@ -181,8 +181,8 @@ </label> </p> <div buttons> - <button type=button cancel onclick="closeModal(this)">Cancel</button> - <button type=submit go>Save</button> + <button type=button onclick="closeModal(this)">Cancel</button> + <button type=submit>Save</button> </div> </form> </dialog> @@ -195,8 +195,8 @@ <span note>Leave blank for no voice URL</span> </p> <div buttons> - <button type=button cancel onclick="closeModal(this)">Cancel</button> - <button type=submit go>Save</button> + <button type=button onclick="closeModal(this)">Cancel</button> + <button type=submit>Save</button> </div> </form> </dialog> @@ -204,8 +204,8 @@ <h2>Delete Account</h2> <p>Are you sure that you want to delete your account?</p> <div buttons> - <button cancel onclick="closeModal(this)">Cancel</button> - <button go onclick="doDeleteUser(this)">Delete</button> + <button onclick="closeModal(this)">Cancel</button> + <button onclick="doDeleteUser(this)">Delete</button> </div> </dialog> <script> init(); </script>
--- a/src/chat.css Tue Mar 04 08:22:45 2025 -0700 +++ b/src/chat.css Tue Mar 04 20:31:00 2025 -0700 @@ -7,16 +7,10 @@ } div[chat_content] { - margin-left: 3%; - margin-right: 3%; display: flex; height: calc(100% - 32px); } -div[chats] { - overflow-y: auto; -} - div[chats] > div { margin-top: 2px; margin-bottom: 2px; @@ -40,6 +34,10 @@ justify-content: space-between; } +div[chat_content][show="intro"] div[posts] { + display: none; +} + div[posts] > * { padding-right: 3vw; } @@ -67,14 +65,19 @@ margin-bottom: 16px; } -[intro] { +div[intro] { + width: 100%; display: flex; flex-direction: column; align-items: center; } -[intro] input[type=email] { +div[intro] form { + max-width: 100%; +} +div[intro] input[type=email] { width: 250px; + max-width: 100%; } div[who] { @@ -170,12 +173,19 @@ margin-right: 0; } + div[chat_content][show="chats"] div[intro], + div[chat_content][show="posts"] div[intro] { + display: none; + } + div[chats] { + overflow-y: auto; width: 250px; padding-right: 8px; flex-shrink: 0; } + div[intro], div[posts] { padding-left: 8px; border-left: 1px solid grey; @@ -187,15 +197,40 @@ } @media (max-width: 699px) { + div[chat_content][show="intro"], + div[chat_content][show="chats"] { + flex-direction: column; + overflow-y: auto; + } + div[chat_content][show="posts"] { + margin-left: 3%; + } + div[chat_content][show="chats"] div[posts], + div[chat_content][show="posts"] div[intro], div[chat_content][show="posts"] div[chats] { display: none; } + div[chats], + div[intro] { + padding-left: 3%; + padding-right: 3%; + } + div[chats] { width: 100%; } + div[intro] { + margin-top: 20px; + border-top: 1px solid grey; + } + + div[intro] [or] { + display: none; + } + div[chat_content][show="posts"] { margin-right: 0; }
--- a/src/chat.js Tue Mar 04 08:22:45 2025 -0700 +++ b/src/chat.js Tue Mar 04 20:31:00 2025 -0700 @@ -280,3 +280,10 @@ span.textContent = email; openModal(dialog); } + +function gotoInvite(el) { + let email = document.querySelector('dialog[invite] span[email]').textContent; + closeModal(el); + location = `chat?with=${email}`; + ajax(`save_post.js?post=${currentPostId}`,`content=${encodeURIComponent(text)}`); +}
--- a/src/index.html.luan Tue Mar 04 08:22:45 2025 -0700 +++ b/src/index.html.luan Tue Mar 04 20:31:00 2025 -0700 @@ -41,26 +41,25 @@ </head> <body> <% header() %> - <div chat_content show="chats"> + <div chat_content show="intro"> <div chats> <% chats_html() %> </div> - <div posts> - <div intro> - <h3>Choose a chat on the left</h3> - <p>or</p> - <h3>Chat with another person</h3> - <form action="javascript:invite()"> - <p> - <label>Person's email</label><br> - <input type=email name=email required><br> - </p> - <p> - <input type=submit> - </p> - </form> - </div> + <div intro> + <h3 or>Choose a chat on the left</h3> + <p or>or</p> + <h3>Chat with another person</h3> + <form action="javascript:invite()"> + <p> + <label>Person's email</label><br> + <input type=email name=email required><br> + </p> + <p> + <input type=submit> + </p> + </form> </div> + <div posts></div> </div> <div hidden> <span pulldown> @@ -75,31 +74,31 @@ <h2>Delete Chat</h2> <p>Are you sure that you want to delete this chat?</p> <div buttons> - <button cancel onclick="closeModal(this)">Cancel</button> - <button go onclick="doDeleteChat(this)">Delete</button> + <button onclick="closeModal(this)">Cancel</button> + <button onclick="doDeleteChat(this)">Delete</button> </div> </dialog> <dialog delete_post> <h2>Delete Message</h2> <p>Are you sure that you want to delete this message?</p> <div buttons> - <button cancel onclick="closeModal(this)">Cancel</button> - <button go onclick="doDeletePost(this)">Delete</button> + <button onclick="closeModal(this)">Cancel</button> + <button onclick="doDeletePost(this)">Delete</button> </div> </dialog> <dialog edit_post> <h2>Edit Message</h2> <p><textarea onfocus="fixTextarea(event)" oninput="fixTextarea(event)"></textarea></p> <div buttons> - <button cancel onclick="closeModal(this)">Cancel</button> - <button go onclick="savePost(this)">Save</button> + <button onclick="closeModal(this)">Cancel</button> + <button onclick="savePost(this)">Save</button> </div> </dialog> <dialog invite> <h2>Chat with another person</h2> <p>We have sent an invite to <span email></span></p> <div buttons> - <button cancel onclick="closeModal(this)">Close</button> + <button onclick="gotoInvite(this)">Close</button> </div> </dialog> <script>
--- a/src/invite.js.luan Tue Mar 04 08:22:45 2025 -0700 +++ b/src/invite.js.luan Tue Mar 04 20:31:00 2025 -0700 @@ -6,9 +6,16 @@ local Io = require "luan:Io.luan" local User = require "site:/lib/User.luan" local get_user_by_email = User.get_by_email or error() +local get_or_create_user_by_email = User.get_or_create_by_email or error() +local current_user = User.current or error() +local Shared = require "site:/lib/Shared.luan" +local send_mail = Shared.send_mail or error() +local Utils = require "site:/lib/Utils.luan" +local base_url = Utils.base_url or error() return function() + local user = current_user() or error() local email = Http.request.parameters.email or error() Io.stdout = Http.response.text_writer() if get_user_by_email(email) ~= nil then @@ -17,6 +24,23 @@ <% return end + local invitee = get_or_create_user_by_email(email) + local password = invitee.password + local url = base_url().."/do_login.html?user="..invitee.id.."&password="..password.."&with="..user.email + local who = user.name or user.email + send_mail { + To = email + Subject = "Chat with "..who + body = `%> +<%=who%> has invited you to chat on Luan Chat. + +Here is the link to login: + +<%= url %> + +Or login with your email and the password: <%=password%> +<% ` + } %> openInvite(<%=json_string(email)%>); <%