comparison src/lib/Shared.luan @ 46:42b741a1d5c6

add username
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 28 Feb 2025 19:25:12 -0700
parents e138343b2c76
children 38c209714df9
comparison
equal deleted inserted replaced
45:e138343b2c76 46:42b741a1d5c6
5 local Io = require "luan:Io.luan" 5 local Io = require "luan:Io.luan"
6 local uri = Io.uri or error() 6 local uri = Io.uri or error()
7 local Time = require "luan:Time.luan" 7 local Time = require "luan:Time.luan"
8 local Thread = require "luan:Thread.luan" 8 local Thread = require "luan:Thread.luan"
9 local thread_run = Thread.run or error() 9 local thread_run = Thread.run or error()
10 local Parsers = require "luan:Parsers.luan"
11 local json_string = Parsers.json_string or error()
10 local Html = require "luan:Html.luan" 12 local Html = require "luan:Html.luan"
11 local html_encode = Html.encode or error() 13 local html_encode = Html.encode or error()
12 local Http = require "luan:http/Http.luan" 14 local Http = require "luan:http/Http.luan"
13 local Mail = require "luan:mail/Mail.luan" 15 local Mail = require "luan:mail/Mail.luan"
14 local User = require "site:/lib/User.luan" 16 local User = require "site:/lib/User.luan"
126 local author = get_user_by_id(author_id) 128 local author = get_user_by_id(author_id)
127 local id = post.id 129 local id = post.id
128 %> 130 %>
129 <div post="<%=id%>" author="<%=author.id%>" fix> 131 <div post="<%=id%>" author="<%=author.id%>" fix>
130 <div who> 132 <div who>
131 <span author><%=author.email%></span> 133 <span author><%=author.name_html()%></span>
132 <span right> 134 <span right>
133 <span when><%=post.date%></span> 135 <span when><%=post.date%></span>
134 <span pulldown></span> 136 <span pulldown></span>
135 </span> 137 </span>
136 </div> 138 </div>
137 <div text><%= html_encode(post.content) %></div> 139 <div text><%= html_encode(post.content) %></div>
138 </div> 140 </div>
139 <% 141 <%
140 end 142 end
141 143
142 local function chat_other_users_html(chat,user,show_phone)
143 local my_id = user.id
144 local is_first = true
145 for _, user_id in ipairs(chat.user_ids) do
146 if user_id ~= my_id then
147 local other_user = get_user_by_id(user_id) or error()
148 if is_first then
149 is_first = false
150 else
151 %>, <%
152 end
153 %><span email><%= other_user.email %></span><span online="<%= other_user.id %>"></span><%
154 local voice_url = other_user.voice_url
155 if voice_url ~= nil and show_phone then
156 %> <a href="<%=voice_url%>" title="Call" target="voice"><img phone src="/images/call.svg"></a><%
157 end
158 end
159 end
160 end
161 Shared.chat_other_users_html = chat_other_users_html
162
163 function Shared.chats_html() 144 function Shared.chats_html()
164 local user = current_user() or error() 145 local user = current_user() or error()
165 local chats = chat_search( "chat_user_ids:"..user.id, "chat_updated desc" ) 146 local chats = chat_search( "chat_user_ids:"..user.id, "chat_updated desc" )
166 for _, chat in ipairs(chats) do 147 for _, chat in ipairs(chats) do
148 local user_id = chat.other_user_id(user.id)
149 local other_user = get_user_by_id(user_id) or error()
167 %> 150 %>
168 <div chat="<%=chat.id%>" onclick="selectChat(this)"><% chat_other_users_html(chat,user,false) %></div> 151 <div chat="<%=chat.id%>" onclick='selectChat(this,<%=json_string(other_user.email)%>)'><%
152 %><%= other_user.name_html() %><span online="<%= other_user.id %>"></span><%
153 %></div>
169 <% 154 <%
170 end 155 end
171 end 156 end
172 157
173 function Shared.http_push_to_users(user_ids,message) 158 function Shared.http_push_to_users(user_ids,message)