comparison src/add_post.js.luan @ 30:f4708943f29e

add heartbeat
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 09 Nov 2024 19:17:21 -0700
parents 82b55186a4a0
children 7ea33179592a
comparison
equal deleted inserted replaced
29:5beadcd541aa 30:f4708943f29e
23 return function() 23 return function()
24 local user = current_user() or error() 24 local user = current_user() or error()
25 local chat = Http.request.parameters.chat or error() 25 local chat = Http.request.parameters.chat or error()
26 local content = Http.request.parameters.content or error() 26 local content = Http.request.parameters.content or error()
27 local post 27 local post
28 local now = time_now()
28 run_in_transaction( function() 29 run_in_transaction( function()
29 chat = get_chat_by_id(chat) or error() 30 chat = get_chat_by_id(chat) or error()
30 local now = time_now()
31 post = new_post{ 31 post = new_post{
32 chat_id = chat.id 32 chat_id = chat.id
33 author_id = user.id 33 author_id = user.id
34 date = now 34 date = now
35 content = content 35 content = content
39 chat.save() 39 chat.save()
40 end ) 40 end )
41 local html = `post_html(post)` 41 local html = `post_html(post)`
42 local js = "added("..json_string(html)..")" 42 local js = "added("..json_string(html)..")"
43 chat.http_push(js) 43 chat.http_push(js)
44 js = "getChats('"..chat.id.."')" 44 js = "getChats('"..chat.id.."',"..now..")"
45 http_push_to_users( chat.user_ids, js ) 45 http_push_to_users( chat.user_ids, js )
46 end 46 end