add threads n posts
This commit is contained in:
28
util.lua
28
util.lua
@ -4,6 +4,8 @@ local db = require("lapis.db")
|
||||
|
||||
local Avatars = require("models").Avatars
|
||||
local Users = require("models").Users
|
||||
local Posts = require("models").Posts
|
||||
local PostHistory = require("models").PostHistory
|
||||
|
||||
util.TransientUser = {
|
||||
is_admin = function (self)
|
||||
@ -15,6 +17,7 @@ util.TransientUser = {
|
||||
is_logged_in_guest = function (self)
|
||||
return false
|
||||
end,
|
||||
username = "Deleted User",
|
||||
}
|
||||
|
||||
function util.get_user_avatar_url(req, user)
|
||||
@ -94,4 +97,29 @@ function util.form_bool_to_sqlite(s)
|
||||
return util.bton(util.stob(s))
|
||||
end
|
||||
|
||||
function util.is_thread_locked(thread)
|
||||
return util.ntob(thread.is_locked)
|
||||
end
|
||||
|
||||
function util.create_post(thread_id, user_id, content)
|
||||
db.query("BEGIN")
|
||||
local post = Posts:create({
|
||||
thread_id = thread_id,
|
||||
user_id = user_id,
|
||||
current_revision_id = db.NULL,
|
||||
})
|
||||
|
||||
local revision = PostHistory:create({
|
||||
post_id = post.id,
|
||||
user_id = user_id,
|
||||
content = content,
|
||||
is_initial_revision = true,
|
||||
})
|
||||
|
||||
post:update({current_revision_id = revision.id})
|
||||
|
||||
db.query("COMMIT")
|
||||
return post
|
||||
end
|
||||
|
||||
return util
|
Reference in New Issue
Block a user