Mercurial Hosting > chat
comparison src/chat.html.luan @ 7:41d35b72c774
chat page
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Tue, 29 Oct 2024 22:11:40 -0600 |
| parents | a49866b52cc2 |
| children | d654e3471132 |
comparison
equal
deleted
inserted
replaced
| 6:e22a1ba4b2ed | 7:41d35b72c774 |
|---|---|
| 11 local Shared = require "site:/lib/Shared.luan" | 11 local Shared = require "site:/lib/Shared.luan" |
| 12 local head = Shared.head or error() | 12 local head = Shared.head or error() |
| 13 local header = Shared.header or error() | 13 local header = Shared.header or error() |
| 14 local User = require "site:/lib/User.luan" | 14 local User = require "site:/lib/User.luan" |
| 15 local current_user = User.current or error() | 15 local current_user = User.current or error() |
| 16 local get_user_by_id = User.get_by_id or error() | |
| 17 local get_user_by_email = User.get_by_email or error() | 16 local get_user_by_email = User.get_by_email or error() |
| 18 local Utils = require "site:/lib/Utils.luan" | 17 local Utils = require "site:/lib/Utils.luan" |
| 19 local to_set = Utils.to_set or error() | 18 local to_set = Utils.to_set or error() |
| 20 local Db = require "site:/lib/Db.luan" | 19 local Db = require "site:/lib/Db.luan" |
| 21 local run_in_transaction = Db.run_in_transaction or error() | 20 local run_in_transaction = Db.run_in_transaction or error() |
| 22 local Chat = require "site:/lib/Chat.luan" | 21 local Chat = require "site:/lib/Chat.luan" |
| 23 local chat_search = Chat.search or error() | 22 local chat_search = Chat.search or error() |
| 24 | 23 |
| 25 | |
| 26 local function other_users(user,chat) | |
| 27 local my_id = user.id | |
| 28 local t = {} | |
| 29 for _, user_id in ipairs(chat.user_ids) do | |
| 30 if user_id ~= my_id then | |
| 31 local other_user = get_user_by_id(user_id) or error() | |
| 32 t[#t+1] = other_user.email | |
| 33 end | |
| 34 end | |
| 35 return concat( t, ", " ) | |
| 36 end | |
| 37 | 24 |
| 38 local function get_chat(with) | 25 local function get_chat(with) |
| 39 local t = {} | 26 local t = {} |
| 40 local ids = {} | 27 local ids = {} |
| 41 for email in pairs(with) do | 28 for email in pairs(with) do |
| 89 %> | 76 %> |
| 90 <!doctype html> | 77 <!doctype html> |
| 91 <html> | 78 <html> |
| 92 <head> | 79 <head> |
| 93 <% head() %> | 80 <% head() %> |
| 81 <style> | |
| 82 body { | |
| 83 height: 100vh; | |
| 84 display: flex; | |
| 85 flex-direction: column; | |
| 86 } | |
| 87 div[content] { | |
| 88 margin-bottom: 0; | |
| 89 display: flex; | |
| 90 height: 100%; | |
| 91 margin-left: calc(3% - 8px); | |
| 92 } | |
| 93 div[chats] { | |
| 94 width: 250px; | |
| 95 padding-right: 8px; | |
| 96 } | |
| 97 div[chats] > div { | |
| 98 margin-top: 2px; | |
| 99 margin-bottom: 2px; | |
| 100 padding-top: 16px; | |
| 101 padding-bottom: 16px; | |
| 102 padding-left: 8px; | |
| 103 padding-right: 8px; | |
| 104 border-radius: 4px; | |
| 105 } | |
| 106 div[chats] > div:hover, | |
| 107 div[chats] > div[selected] { | |
| 108 background-color: LightBlue; | |
| 109 } | |
| 110 div[posts] { | |
| 111 padding-left: 8px; | |
| 112 border-left: 1px solid; | |
| 113 } | |
| 114 </style> | |
| 115 <script> | |
| 116 'use strict'; | |
| 117 | |
| 118 let currentChatId = null; | |
| 119 | |
| 120 function selectChat(div) { | |
| 121 let chatId = div.getAttribute('chat'); | |
| 122 if( chatId === currentChatId ) | |
| 123 return; | |
| 124 let selected = div.parentNode.querySelector('[selected]'); | |
| 125 if( selected ) selected.removeAttribute('selected'); | |
| 126 div.setAttribute('selected',''); | |
| 127 ajax(`chat.js?chat=${chatId}`); | |
| 128 } | |
| 129 </script> | |
| 94 </head> | 130 </head> |
| 95 <body> | 131 <body> |
| 96 <% header() %> | 132 <% header() %> |
| 97 <div content> | 133 <div content> |
| 98 <h1>Chat</h1> | 134 <div chats> |
| 99 <% for _, chat in ipairs(chats) do %> | 135 <% |
| 100 <p><%= other_users(user,chat) %></p> | 136 for _, chat in ipairs(chats) do |
| 101 <% end %> | 137 %> |
| 138 <div chat="<%=chat.id%>" onclick="selectChat(this)"><%= chat.other_users_email(user) %></div> | |
| 139 <% | |
| 140 end | |
| 141 %> | |
| 142 </div> | |
| 143 <div posts></div> | |
| 102 </div> | 144 </div> |
| 103 </body> | 145 </body> |
| 104 </html> | 146 </html> |
| 105 <% | 147 <% |
| 106 end | 148 end |
