Mercurial Hosting > chat
changeset 41:818697418dbe
add voice link
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 27 Feb 2025 19:05:57 -0700 |
parents | 7ea33179592a |
children | e09747b199e9 |
files | src/account.html.luan src/chat.css src/get_chat.js.luan src/images/call.svg src/lib/Notify.luan src/lib/Shared.luan src/lib/User.luan src/save_voice.js.luan src/site.css |
diffstat | 9 files changed, 105 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/account.html.luan Thu Feb 27 16:44:20 2025 -0700 +++ b/src/account.html.luan Thu Feb 27 19:05:57 2025 -0700 @@ -16,7 +16,6 @@ return function() local user = current_user() if user == nil then return end - local notify_email = user.notify_email Io.stdout = Http.response.text_writer() %> <!doctype html> @@ -26,12 +25,13 @@ <script> 'use strict'; - let notifyEmail = <%= json_string(notify_email or "") %>; + let notifyEmail = <%= json_string(user.notify_email or "") %>; let multiNotify = <%= user.multi_notify %>; + let voice = <%= json_string(user.voice_url or "") %>; function showNotify() { let span = document.querySelector('span[notify]'); - span.textContent = notifyEmail ? `Send notifications to ${notifyEmail}` : 'No notifications' + span.textContent = notifyEmail ? `Send notifications to ${notifyEmail}` : 'No notifications'; } function editNotify() { @@ -54,6 +54,27 @@ ajax(`save_notify.js?email=${encodeURIComponent(notifyEmail)}&multi=${multiNotify}`); } + function showVoice() { + let span = document.querySelector('span[voice]'); + span.textContent = voice ? `Your voice URL: ${voice}` : 'No voice URL'; + } + + function editVoice() { + let dialog = document.querySelector('dialog[edit_voice]'); + let input = dialog.querySelector('input[name=voice]'); + input.value = voice; + openModal(dialog); + } + + function saveVoice() { + let dialog = document.querySelector('dialog[edit_voice]'); + let input = dialog.querySelector('input[name=voice]'); + voice = input.value; + closeModal(input); + showVoice(); + ajax(`save_voice.js?url=${encodeURIComponent(voice)}`); + } + function deleteUser() { let dialog = document.querySelector('dialog[delete_user]'); openModal(dialog); @@ -66,6 +87,7 @@ function init() { showNotify(); + showVoice(); } </script> <style> @@ -79,6 +101,11 @@ } input[name=notify_email] { width: 300px; + max-width: 100%; + } + input[name=voice] { + width: 500px; + max-width: 100%; } span[note] { font-size: small; @@ -92,6 +119,7 @@ <p><a href="about.html">About Web Chat</a></p> <p>Your URL: <%= base_url() %>/?with=<%=user.email%></p> <p><span notify></span> <a href="javascript:editNotify()">Edit</a></p> + <p><span voice></span> <a href="javascript:editVoice()">Edit</a></p> <p><a href="javascript:logout()">Logout</a></p> <p><a href="javascript:deleteUser()">Delete account</a></p> </div> @@ -119,6 +147,20 @@ </div> </form> </dialog> + <dialog edit_voice> + <h2>Edit Voice URL</h2> + <form action="javascript:saveVoice()"> + <p> + <label>URL for receiving voice calls</label><br> + <input type=url name=voice><br> + <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> + </div> + </form> + </dialog> <dialog delete_user> <h2>Delete Account</h2> <p>Are you sure that you want to delete your account?</p>
--- a/src/chat.css Thu Feb 27 16:44:20 2025 -0700 +++ b/src/chat.css Thu Feb 27 19:05:57 2025 -0700 @@ -49,6 +49,14 @@ align-items: center; } +div[top] h3 a { + display: inline-block; + margin-bottom: -5px; +} +div[top] h3 a img { + display: block; +} + div[main] { overflow-y: auto; } @@ -67,7 +75,7 @@ justify-content: space-between; } -span[right] { +div[content] span[right] { font-size: 12px; color: grey; } @@ -155,7 +163,7 @@ border-left: 1px solid grey; } - div[top] img { + div[top] img[back] { display: none; } }
--- a/src/get_chat.js.luan Thu Feb 27 16:44:20 2025 -0700 +++ b/src/get_chat.js.luan Thu Feb 27 19:05:57 2025 -0700 @@ -27,7 +27,7 @@ <div top> <h3> <img back onclick="back()" src="/images/arrow_back.svg"> - <span><% chat_other_users_html(chat,user) %></span> + <span><% chat_other_users_html(chat,user,true) %></span> </h3> <button onclick='deleteChat()'>Delete</button> </div>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/images/call.svg Thu Feb 27 19:05:57 2025 -0700 @@ -0,0 +1,1 @@ +<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px"><path d="M798-120q-125 0-247-54.5T329-329Q229-429 174.5-551T120-798q0-18 12-30t30-12h162q14 0 25 9.5t13 22.5l26 140q2 16-1 27t-11 19l-97 98q20 37 47.5 71.5T387-386q31 31 65 57.5t72 48.5l94-94q9-9 23.5-13.5T670-390l138 28q14 4 23 14.5t9 23.5v162q0 18-12 30t-30 12ZM241-600l66-66-17-94h-89q5 41 14 81t26 79Zm358 358q39 17 79.5 27t81.5 13v-88l-94-19-67 67ZM241-600Zm358 358Z"/></svg> \ No newline at end of file
--- a/src/lib/Notify.luan Thu Feb 27 16:44:20 2025 -0700 +++ b/src/lib/Notify.luan Thu Feb 27 19:05:57 2025 -0700 @@ -44,23 +44,23 @@ local user = get_user_by_id(user_id) if users[user_id] == nil and user.notify_email ~= nil and (user.multi_notify or not user.was_notified) then users[user_id] = now -logger.info("add "..user_id) + -- logger.info("add "..user_id) end end end function fns.remove(user_id) users[user_id] = nil -logger.info("remove "..user_id) + -- logger.info("remove "..user_id) end function fns.notify() -logger.info("notify") + -- logger.info("notify") local now = time_now() for user_id, when in pairs(shallow_copy(users)) do if now - when > wait then local user = get_user_by_id(user_id) -logger.info("notify "..user.notify_email.." "..user_id) + -- logger.info("notify "..user.notify_email.." "..user_id) send_mail { From = "Web Chat <chat@luan.software>" To = user.notify_email
--- a/src/lib/Shared.luan Thu Feb 27 16:44:20 2025 -0700 +++ b/src/lib/Shared.luan Thu Feb 27 19:05:57 2025 -0700 @@ -46,10 +46,17 @@ / <%=crumb%> <% end %> </span> - <span> + <span right> <% if user == nil then %> <a href="/login.html">Login / Register</a> -<% else %> +<% else + local voice_url = user.voice_url + if voice_url ~= nil then +%> + <a href="<%=voice_url%>" title="Call" target="voice"><img phone src="/images/call.svg"></a> +<% + end +%> <a href="/account.html"><%= user.email %></a> <% end %> </span> @@ -111,7 +118,7 @@ <% end -local function chat_other_users_html(chat,user) +local function chat_other_users_html(chat,user,show_phone) local my_id = user.id local is_first = true for _, user_id in ipairs(chat.user_ids) do @@ -123,6 +130,10 @@ %>, <% end %><span email><%= other_user.email %></span><span online="<%= other_user.id %>"></span><% + local voice_url = other_user.voice_url + if voice_url ~= nil and show_phone then + %> <a href="<%=voice_url%>" title="Call" target="voice"><img phone src="/images/call.svg"></a><% + end end end end @@ -133,7 +144,7 @@ local chats = chat_search( "chat_user_ids:"..user.id, "chat_updated desc" ) for _, chat in ipairs(chats) do %> - <div chat="<%=chat.id%>" onclick="selectChat(this)"><% chat_other_users_html(chat,user) %></div> + <div chat="<%=chat.id%>" onclick="selectChat(this)"><% chat_other_users_html(chat,user,false) %></div> <% end end
--- a/src/lib/User.luan Thu Feb 27 16:44:20 2025 -0700 +++ b/src/lib/User.luan Thu Feb 27 19:05:57 2025 -0700 @@ -36,6 +36,7 @@ was_notified = doc.was_notified=="true" notify_email = doc.notify_email multi_notify = doc.multi_notify=="true" + voice_url = doc.voice_url } end @@ -48,6 +49,7 @@ was_notified = user.was_notified and "true" or nil notify_email = user.notify_email multi_notify = user.multi_notify and "true" or nil + voice_url = user.voice_url } end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/save_voice.js.luan Thu Feb 27 19:05:57 2025 -0700 @@ -0,0 +1,20 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local Http = require "luan:http/Http.luan" +local Db = require "site:/lib/Db.luan" +local run_in_transaction = Db.run_in_transaction or error() +local User = require "site:/lib/User.luan" +local current_user = User.current or error() + + +return function() + local url = Http.request.parameters.url or error() + if url == "" then + url = nil + end + run_in_transaction( function() + local user = current_user() or error() + user.voice_url = url + user.save() + end ) +end
--- a/src/site.css Thu Feb 27 16:44:20 2025 -0700 +++ b/src/site.css Thu Feb 27 19:05:57 2025 -0700 @@ -32,6 +32,13 @@ padding: 8px 3%; display: flex; justify-content: space-between; + align-items: center; +} + +div[header] span[right] { + display: flex; + align-items: center; + gap: 8px; } [content] {