Mercurial Hosting > chat
comparison src/add_post.js.luan @ 79:b5a316575e64
reply
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 10 Mar 2025 21:41:53 -0600 |
parents | d4d154b404f8 |
children | c41e200c3e76 |
comparison
equal
deleted
inserted
replaced
78:2a602ef53eef | 79:b5a316575e64 |
---|---|
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 Time = require "luan:Time.luan" | 4 local Time = require "luan:Time.luan" |
5 local time_now = Time.now or error() | 5 local time_now = Time.now or error() |
6 local String = require "luan:String.luan" | |
7 local to_number = String.to_number or error() | |
6 local Parsers = require "luan:Parsers.luan" | 8 local Parsers = require "luan:Parsers.luan" |
7 local json_string = Parsers.json_string or error() | 9 local json_string = Parsers.json_string or error() |
8 local Io = require "luan:Io.luan" | 10 local Io = require "luan:Io.luan" |
9 local Http = require "luan:http/Http.luan" | 11 local Http = require "luan:http/Http.luan" |
10 local User = require "site:/lib/User.luan" | 12 local User = require "site:/lib/User.luan" |
27 local content = Http.request.parameters.content or error() | 29 local content = Http.request.parameters.content or error() |
28 local post | 30 local post |
29 local now = time_now() | 31 local now = time_now() |
30 run_in_transaction( function() | 32 run_in_transaction( function() |
31 chat = get_chat_by_id(chat) or error() | 33 chat = get_chat_by_id(chat) or error() |
32 post = new_post{ | 34 post = { |
33 chat_id = chat.id | 35 chat_id = chat.id |
34 author_id = user.id | 36 author_id = user.id |
35 date = now | 37 date = now |
36 content = content | 38 content = content |
37 } | 39 } |
40 local reply = Http.request.parameters.reply | |
41 if reply ~= nil then | |
42 post.reply = to_number(reply) or error() | |
43 end | |
44 post = new_post(post) | |
38 post.save() | 45 post.save() |
39 chat.updated = now | 46 chat.updated = now |
40 chat.save() | 47 chat.save() |
41 end ) | 48 end ) |
42 Notify.add(chat) | 49 Notify.add(chat) |