Mercurial Hosting > chat
diff src/lib/Chat.luan @ 7:41d35b72c774
chat page
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 29 Oct 2024 22:11:40 -0600 |
parents | 2da10ece826f |
children | 563a5358f2ee |
line wrap: on
line diff
--- a/src/lib/Chat.luan Tue Oct 29 16:47:11 2024 -0600 +++ b/src/lib/Chat.luan Tue Oct 29 22:11:40 2024 -0600 @@ -1,6 +1,9 @@ local Luan = require "luan:Luan.luan" local error = Luan.error local ipairs = Luan.ipairs or error() +local Table = require "luan:Table.luan" +local concat = Table.concat or error() +local is_empty = Table.is_empty or error() local Time = require "luan:Time.luan" local time_now = Time.now or error() local Db = require "site:/lib/Db.luan" @@ -44,6 +47,21 @@ end ) end + function chat.other_users_email(user) + local User = require "site:/lib/User.luan" + local get_user_by_id = User.get_by_id or error() + + local my_id = user.id + local t = {} + for _, user_id in ipairs(chat.user_ids) do + if user_id ~= my_id then + local other_user = get_user_by_id(user_id) or error() + t[#t+1] = other_user.email + end + end + return concat( t, ", " ) + end + return chat end @@ -57,4 +75,9 @@ return chats end +function Chat.get_by_id(id) + local doc = Db.get_document("id:"..id) + return doc and doc.type=="chat" and from_doc(doc) or nil +end + return Chat