Mercurial Hosting > chat
comparison src/chat.html.luan @ 15:8b8905f63d80
add get_chats
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 03 Nov 2024 17:36:49 -0700 |
parents | f9e6a4cc4f7d |
children | 7230c821c368 |
comparison
equal
deleted
inserted
replaced
14:0df3a63a895f | 15:8b8905f63d80 |
---|---|
11 local Http = require "luan:http/Http.luan" | 11 local Http = require "luan:http/Http.luan" |
12 local Shared = require "site:/lib/Shared.luan" | 12 local Shared = require "site:/lib/Shared.luan" |
13 local head = Shared.head or error() | 13 local head = Shared.head or error() |
14 local header = Shared.header or error() | 14 local header = Shared.header or error() |
15 local started = Shared.started or error() | 15 local started = Shared.started or error() |
16 local chats_html = Shared.chats_html or error() | |
16 local User = require "site:/lib/User.luan" | 17 local User = require "site:/lib/User.luan" |
17 local current_user = User.current or error() | 18 local current_user = User.current or error() |
18 local get_user_by_email = User.get_by_email or error() | 19 local get_user_by_email = User.get_by_email or error() |
19 local Utils = require "site:/lib/Utils.luan" | 20 local Utils = require "site:/lib/Utils.luan" |
20 local to_set = Utils.to_set or error() | 21 local to_set = Utils.to_set or error() |
74 with[user.email] = true | 75 with[user.email] = true |
75 if size(with) > 1 then | 76 if size(with) > 1 then |
76 selected = get_chat(with) | 77 selected = get_chat(with) |
77 end | 78 end |
78 end | 79 end |
79 local chats = Chat.search( "chat_user_ids:"..user.id, "chat_updated desc" ) | |
80 Io.stdout = Http.response.text_writer() | 80 Io.stdout = Http.response.text_writer() |
81 %> | 81 %> |
82 <!doctype html> | 82 <!doctype html> |
83 <html> | 83 <html> |
84 <head> | 84 <head> |
90 </head> | 90 </head> |
91 <body> | 91 <body> |
92 <% header() %> | 92 <% header() %> |
93 <div content> | 93 <div content> |
94 <div chats> | 94 <div chats> |
95 <% chats_html() %> | |
96 </div> | |
97 <div posts></div> | |
98 </div> | |
99 <script> | |
95 <% | 100 <% |
96 for _, chat in ipairs(chats) do | 101 if selected ~= nil then |
97 %> | 102 %> |
98 <div chat="<%=chat.id%>" onclick="selectChat(this)"><%= chat.other_users_email(user) %></div> | 103 let div = document.querySelector('div[chat="<%=selected.id%>"]'); |
104 selectChat(div); | |
99 <% | 105 <% |
100 end | 106 end |
101 %> | 107 %> |
102 </div> | 108 setUserEventSource(<%=user.id%>); |
103 <div posts></div> | 109 </script> |
104 </div> | |
105 </body> | 110 </body> |
106 <% | |
107 if selected ~= nil then | |
108 %> | |
109 <script> | |
110 let div = document.querySelector('div[chat="<%=selected.id%>"]'); | |
111 selectChat(div); | |
112 </script> | |
113 <% | |
114 end | |
115 %> | |
116 </html> | 111 </html> |
117 <% | 112 <% |
118 end | 113 end |