Mercurial Hosting > chat
changeset 11:563a5358f2ee
add delete_chat
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 31 Oct 2024 19:17:53 -0600 |
parents | f9e6a4cc4f7d |
children | 9f45d32670ae |
files | src/chat.css src/chat.js src/delete_chat.js.luan src/get_chat.js.luan src/lib/Chat.luan |
diffstat | 5 files changed, 27 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/chat.css Wed Oct 30 23:18:45 2024 -0600 +++ b/src/chat.css Thu Oct 31 19:17:53 2024 -0600 @@ -1,7 +1,6 @@ div[content] { margin-bottom: 0; display: flex; - xheight: 100%; height: calc(100vh - 32px); margin-left: calc(3% - 8px); margin-right: 0; @@ -22,6 +21,7 @@ padding-left: 8px; padding-right: 8px; border-radius: 4px; + cursor: pointer; } div[chats] > div:hover,
--- a/src/chat.js Wed Oct 30 23:18:45 2024 -0600 +++ b/src/chat.js Thu Oct 31 19:17:53 2024 -0600 @@ -46,3 +46,7 @@ span.removeAttribute('fix'); } } + +function deleteChat() { + ajax(`delete_chat.js?chat=${currentChatId}`); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/delete_chat.js.luan Thu Oct 31 19:17:53 2024 -0600 @@ -0,0 +1,20 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local Io = require "luan:Io.luan" +local Http = require "luan:http/Http.luan" +local User = require "site:/lib/User.luan" +local current_user = User.current or error() +local Chat = require "site:/lib/Chat.luan" +local get_chat_by_id = Chat.get_by_id or error() + + +return function() + local chat = Http.request.parameters.chat or error() + chat = get_chat_by_id(chat) or error() + local user = current_user() or error() + chat.delete() + Io.stdout = Http.response.text_writer() +%> + location = '/chat.html'; +<% +end
--- a/src/get_chat.js.luan Wed Oct 30 23:18:45 2024 -0600 +++ b/src/get_chat.js.luan Thu Oct 31 19:17:53 2024 -0600 @@ -38,7 +38,7 @@ %> <div top> <h3><%= chat.other_users_email(user) %></h3> - <button>delete</button> + <button onclick='deleteChat()'>delete</button> </div> <div main> <%
--- a/src/lib/Chat.luan Wed Oct 30 23:18:45 2024 -0600 +++ b/src/lib/Chat.luan Thu Oct 31 19:17:53 2024 -0600 @@ -42,7 +42,7 @@ function chat.delete() run_in_transaction( function() local id = chat.id - -- Db.delete("chat_user_ids:"..id) + Db.delete("post_chat_id:"..id) Db.delete("id:"..id) end ) end