Mercurial Hosting > freedit
comparison src/lib/Post.luan @ 56:7ce54f6d93f2
add change name
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 28 Nov 2022 22:00:43 -0700 |
parents | 289718f121e4 |
children |
comparison
equal
deleted
inserted
replaced
55:c57b84f461ae | 56:7ce54f6d93f2 |
---|---|
44 doc.type == "post" or error "wrong type" | 44 doc.type == "post" or error "wrong type" |
45 local post = Post.new { | 45 local post = Post.new { |
46 id = doc.id | 46 id = doc.id |
47 content = doc.content | 47 content = doc.content |
48 date = doc.date | 48 date = doc.date |
49 author_name = doc.post_author_name | 49 author_id = doc.post_author_id |
50 root_id = doc.post_root_id | 50 root_id = doc.post_root_id |
51 is_root = doc.post_is_root == "true" | 51 is_root = doc.post_is_root == "true" |
52 | 52 |
53 -- root only | 53 -- root only |
54 subject = doc.subject | 54 subject = doc.subject |
61 return { | 61 return { |
62 type = "post" | 62 type = "post" |
63 id = post.id | 63 id = post.id |
64 content = post.content or error() | 64 content = post.content or error() |
65 date = long(post.date) | 65 date = long(post.date) |
66 post_author_name = post.author_name or error() | 66 post_author_id = long(post.author_id) |
67 post_root_id = long(post.root_id) | 67 post_root_id = long(post.root_id) |
68 post_is_root = post.is_root and "true" or nil | 68 post_is_root = post.is_root and "true" or nil |
69 | 69 |
70 -- root only | 70 -- root only |
71 subject = post.subject | 71 subject = post.subject |
74 | 74 |
75 local metatable = {} | 75 local metatable = {} |
76 function metatable.__index(post,key) | 76 function metatable.__index(post,key) |
77 if key == "author" then | 77 if key == "author" then |
78 local User = require "site:/lib/User.luan" | 78 local User = require "site:/lib/User.luan" |
79 return User.get_by_name(post.author_name) | 79 return User.get_by_id(post.author_id) |
80 end | 80 end |
81 if key == "subject_html" then | 81 if key == "subject_html" then |
82 return post.subject and html_encode(post.subject) | 82 return post.subject and html_encode(post.subject) |
83 end | 83 end |
84 if key == "root" then | 84 if key == "root" then |
104 end | 104 end |
105 | 105 |
106 function post.author_is_current() | 106 function post.author_is_current() |
107 local User = require "site:/lib/User.luan" | 107 local User = require "site:/lib/User.luan" |
108 local user = User.current() | 108 local user = User.current() |
109 return user ~= nil and user.name == post.author_name | 109 return user ~= nil and user.id == post.author_id |
110 end | 110 end |
111 | 111 |
112 function post.ago(now) | 112 function post.ago(now) |
113 local diff = now - post.date | 113 local diff = now - post.date |
114 for _, t in ipairs(times) do | 114 for _, t in ipairs(times) do |
138 function Post.new_thread(author,subject,content) | 138 function Post.new_thread(author,subject,content) |
139 return Db.run_in_transaction( function() | 139 return Db.run_in_transaction( function() |
140 local post = Post.new{ | 140 local post = Post.new{ |
141 subject = subject or error() | 141 subject = subject or error() |
142 content = content | 142 content = content |
143 author_name = author.name | 143 author_id = author.id |
144 is_root = true | 144 is_root = true |
145 } | 145 } |
146 post.root_id = -1 | 146 post.root_id = -1 |
147 post.save() | 147 post.save() |
148 post.root_id = post.id or error() | 148 post.root_id = post.id or error() |