changeset 18:820136c5ee33

add new_chat.red
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 30 Jul 2025 15:11:24 -0600
parents 19901d6fb56f
children 0351b3d474f8
files src/chat.html.luan src/chats.html.luan src/new_chat.red.luan
diffstat 3 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/chat.html.luan	Wed Jul 30 15:01:31 2025 -0600
+++ b/src/chat.html.luan	Wed Jul 30 15:11:24 2025 -0600
@@ -18,18 +18,8 @@
 		Http.response.send_redirect("/login.html")
 		return
 	end
-	local chat_id = Http.request.parameters.chat
-	local chat
-	if chat_id ~= nil then
-		chat = get_chat_by_id(chat_id) or error()
-	else
-		chat = Chat.new{
-			user_id = user.id
-			name = "whatever"
-			language = "jp"
-		}
-		chat.save()
-	end
+	local chat_id = Http.request.parameters.chat or error()
+	local chat = get_chat_by_id(chat_id) or error()
 	Io.stdout = Http.response.text_writer()
 %>
 <!doctype html>
--- a/src/chats.html.luan	Wed Jul 30 15:01:31 2025 -0600
+++ b/src/chats.html.luan	Wed Jul 30 15:11:24 2025 -0600
@@ -30,7 +30,7 @@
 <%		header() %>
 		<div content>
 			<h1>Your Chats</h1>
-			<p><a href="chat.html">new chat</a></p>
+			<p><a href="new_chat.red">new chat</a></p>
 <%	for _, chat in ipairs(chats) do %>
 			<p><a href="chat.html?chat=<%=chat.id%>"><%= chat.name_html() %></a></p>
 <%	end %>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/new_chat.red.luan	Wed Jul 30 15:11:24 2025 -0600
@@ -0,0 +1,18 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+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"
+
+
+return function()
+	local user = current_user() or error()
+	local chat = Chat.new{
+		user_id = user.id
+		name = "whatever"
+		language = "jp"
+	}
+	chat.save()
+	Http.response.send_redirect("chat.html?chat="..chat.id)
+end