comparison src/lib/Chat.luan @ 33:e2b7f6393dab

add online
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 10 Nov 2024 19:57:14 -0700
parents 9f45d32670ae
children 42b741a1d5c6
comparison
equal deleted inserted replaced
32:0f40501b0b56 33:e2b7f6393dab
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 Table = require "luan:Table.luan"
5 local concat = Table.concat or error()
6 local is_empty = Table.is_empty or error()
7 local Time = require "luan:Time.luan" 4 local Time = require "luan:Time.luan"
8 local time_now = Time.now or error() 5 local time_now = Time.now or error()
9 local Http = require "luan:http/Http.luan" 6 local Http = require "luan:http/Http.luan"
10 local Db = require "site:/lib/Db.luan" 7 local Db = require "site:/lib/Db.luan"
11 local run_in_transaction = Db.run_in_transaction or error() 8 local run_in_transaction = Db.run_in_transaction or error()
48 Db.delete("post_chat_id:"..id) 45 Db.delete("post_chat_id:"..id)
49 Db.delete("id:"..id) 46 Db.delete("id:"..id)
50 end ) 47 end )
51 end 48 end
52 49
53 function chat.other_users_email(user)
54 local User = require "site:/lib/User.luan"
55 local get_user_by_id = User.get_by_id or error()
56
57 local my_id = user.id
58 local t = {}
59 for _, user_id in ipairs(chat.user_ids) do
60 if user_id ~= my_id then
61 local other_user = get_user_by_id(user_id) or error()
62 t[#t+1] = other_user.email
63 end
64 end
65 return concat( t, ", " )
66 end
67
68 function chat.http_push(message) 50 function chat.http_push(message)
69 local url = base_url().."/chat/"..chat.id 51 local url = base_url().."/chat/"..chat.id
70 Http.push(url,message) 52 Http.push(url,message)
71 end 53 end
72 54