Mercurial Hosting > chat
diff 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 |
line wrap: on
line diff
--- a/src/lib/Shared.luan Mon Mar 10 22:42:46 2025 -0600 +++ b/src/lib/Shared.luan Tue Mar 11 13:56:59 2025 -0600 @@ -2,6 +2,8 @@ local error = Luan.error local ipairs = Luan.ipairs or error() local parse = Luan.parse or error() +local Table = require "luan:Table.luan" +local concat = Table.concat or error() local Time = require "luan:Time.luan" local Thread = require "luan:Thread.luan" local thread_run = Thread.run or error() @@ -145,18 +147,37 @@ <% end +local function group_name(user_ids) + local t = {nil} + for _, user_id in ipairs(user_ids) do + t[#t+1] = get_user_by_id(user_id).name_html() + end + return concat(t,", ") +end +Shared.group_name = group_name + 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 local chat_id = chat.id - local user_id = chat.other_user_id(user.id) - local other_user = get_user_by_id(user_id) or error() local unread = chat.unread(user) %> <div chat="<%=chat_id%>" onclick="selectChat('<%=chat_id%>')"> +<% + local user_ids = chat.other_user_ids(user.id) + if #user_ids > 1 then +%> + <%= group_name(user_ids) %> +<% + else + local other_user = get_user_by_id(user_ids[1]) or error() +%> <%= other_user.name_html() %> <span online="<%= other_user.id %>"></span> +<% + end +%> <span unread="<%=unread%>"><%=unread%></span> </div> <%