diff src/lib/Shared.luan @ 15:8b8905f63d80

add get_chats
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 03 Nov 2024 17:36:49 -0700
parents 9f45d32670ae
children 82b55186a4a0
line wrap: on
line diff
--- a/src/lib/Shared.luan	Fri Nov 01 11:22:01 2024 -0600
+++ b/src/lib/Shared.luan	Sun Nov 03 17:36:49 2024 -0700
@@ -13,6 +13,8 @@
 local User = require "site:/lib/User.luan"
 local current_user = User.current or error()
 local get_user_by_id = User.get_by_id or error()
+local Chat = require "site:/lib/Chat.luan"
+local chat_search = Chat.search or error()
 
 
 local Shared = {}
@@ -100,4 +102,14 @@
 <%
 end
 
+function Shared.chats_html()
+	local user = current_user() or error()
+	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_email(user) %></div>
+<%
+	end
+end
+
 return Shared