Mercurial Hosting > chat
diff src/add_post.js.luan @ 12:9f45d32670ae
server push
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 31 Oct 2024 21:40:57 -0600 |
parents | f9e6a4cc4f7d |
children | 8b8905f63d80 |
line wrap: on
line diff
--- a/src/add_post.js.luan Thu Oct 31 19:17:53 2024 -0600 +++ b/src/add_post.js.luan Thu Oct 31 21:40:57 2024 -0600 @@ -2,6 +2,8 @@ local error = Luan.error local Time = require "luan:Time.luan" local time_now = Time.now or error() +local Parsers = require "luan:Parsers.luan" +local json_string = Parsers.json_string or error() local Io = require "luan:Io.luan" local Http = require "luan:http/Http.luan" local User = require "site:/lib/User.luan" @@ -12,16 +14,19 @@ local get_chat_by_id = Chat.get_by_id or error() local Post = require "site:/lib/Post.luan" local new_post = Post.new or error() +local Shared = require "site:/lib/Shared.luan" +local post_html = Shared.post_html or error() return function() local user = current_user() or error() local chat = Http.request.parameters.chat or error() local content = Http.request.parameters.content or error() + local post run_in_transaction( function() chat = get_chat_by_id(chat) or error() local now = time_now() - local post = new_post{ + post = new_post{ chat_id = chat.id author_id = user.id date = now @@ -31,4 +36,7 @@ chat.updated = now chat.save() end ) + local html = `post_html(post)` + local js = "added("..json_string(html)..")" + chat.http_push(js) end