Mercurial Hosting > chat
comparison src/lib/Shared.luan @ 83:a47036fd0158
group chat
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 11 Mar 2025 13:56:59 -0600 |
parents | b5a316575e64 |
children | 625ffdf6499d |
comparison
equal
deleted
inserted
replaced
82:0bc5e0d098f7 | 83:a47036fd0158 |
---|---|
1 local Luan = require "luan:Luan.luan" | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | 2 local error = Luan.error |
3 local ipairs = Luan.ipairs or error() | 3 local ipairs = Luan.ipairs or error() |
4 local parse = Luan.parse or error() | 4 local parse = Luan.parse or error() |
5 local Table = require "luan:Table.luan" | |
6 local concat = Table.concat or error() | |
5 local Time = require "luan:Time.luan" | 7 local Time = require "luan:Time.luan" |
6 local Thread = require "luan:Thread.luan" | 8 local Thread = require "luan:Thread.luan" |
7 local thread_run = Thread.run or error() | 9 local thread_run = Thread.run or error() |
8 local Html = require "luan:Html.luan" | 10 local Html = require "luan:Html.luan" |
9 local html_encode = Html.encode or error() | 11 local html_encode = Html.encode or error() |
143 <div text><%= html_encode(post.content) %></div> | 145 <div text><%= html_encode(post.content) %></div> |
144 </div> | 146 </div> |
145 <% | 147 <% |
146 end | 148 end |
147 | 149 |
150 local function group_name(user_ids) | |
151 local t = {nil} | |
152 for _, user_id in ipairs(user_ids) do | |
153 t[#t+1] = get_user_by_id(user_id).name_html() | |
154 end | |
155 return concat(t,", ") | |
156 end | |
157 Shared.group_name = group_name | |
158 | |
148 function Shared.chats_html() | 159 function Shared.chats_html() |
149 local user = current_user() or error() | 160 local user = current_user() or error() |
150 local chats = chat_search( "chat_user_ids:"..user.id, "chat_updated desc" ) | 161 local chats = chat_search( "chat_user_ids:"..user.id, "chat_updated desc" ) |
151 for _, chat in ipairs(chats) do | 162 for _, chat in ipairs(chats) do |
152 local chat_id = chat.id | 163 local chat_id = chat.id |
153 local user_id = chat.other_user_id(user.id) | |
154 local other_user = get_user_by_id(user_id) or error() | |
155 local unread = chat.unread(user) | 164 local unread = chat.unread(user) |
156 %> | 165 %> |
157 <div chat="<%=chat_id%>" onclick="selectChat('<%=chat_id%>')"> | 166 <div chat="<%=chat_id%>" onclick="selectChat('<%=chat_id%>')"> |
167 <% | |
168 local user_ids = chat.other_user_ids(user.id) | |
169 if #user_ids > 1 then | |
170 %> | |
171 <%= group_name(user_ids) %> | |
172 <% | |
173 else | |
174 local other_user = get_user_by_id(user_ids[1]) or error() | |
175 %> | |
158 <%= other_user.name_html() %> | 176 <%= other_user.name_html() %> |
159 <span online="<%= other_user.id %>"></span> | 177 <span online="<%= other_user.id %>"></span> |
178 <% | |
179 end | |
180 %> | |
160 <span unread="<%=unread%>"><%=unread%></span> | 181 <span unread="<%=unread%>"><%=unread%></span> |
161 </div> | 182 </div> |
162 <% | 183 <% |
163 end | 184 end |
164 end | 185 end |