diff src/chat.html.luan @ 5:a49866b52cc2

login to chat
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 29 Oct 2024 13:10:47 -0600
parents 2da10ece826f
children 41d35b72c774
line wrap: on
line diff
--- a/src/chat.html.luan	Sun Oct 27 20:39:18 2024 -0600
+++ b/src/chat.html.luan	Tue Oct 29 13:10:47 2024 -0600
@@ -4,13 +4,15 @@
 local pairs = Luan.pairs or error()
 local Table = require "luan:Table.luan"
 local concat = Table.concat or error()
+local is_empty = Table.is_empty or error()
+local size = Table.size or error()
 local Io = require "luan:Io.luan"
 local Http = require "luan:http/Http.luan"
 local Shared = require "site:/lib/Shared.luan"
 local head = Shared.head or error()
 local header = Shared.header or error()
 local User = require "site:/lib/User.luan"
-local current_user = User.current_required or error()
+local current_user = User.current or error()
 local get_user_by_id = User.get_by_id or error()
 local get_user_by_email = User.get_by_email or error()
 local Utils = require "site:/lib/Utils.luan"
@@ -61,15 +63,26 @@
 end
 
 return function()
+	local with = Http.request.parameters.with
+	with = to_set(with)
 	local user = current_user()
 	if user == nil then
+		local url = "/login.html"
+		if not is_empty(with) then
+			local t = {}
+			for email in pairs(with) do
+				t[#t+1] = "with="..email
+			end
+			url = url.."?"..concat(t,"&")
+		end
+		Http.response.send_redirect(url)
 		return
 	end
-	local with = Http.request.parameters.with
-	if with ~= nil then
-		with = to_set(with)
+	if not is_empty(with) then
 		with[user.email] = true
-		get_chat(with)
+		if size(with) > 1 then
+			get_chat(with)
+		end
 	end
 	local chats = user.get_chats()
 	Io.stdout = Http.response.text_writer()