basic posting
This commit is contained in:
@@ -267,6 +267,39 @@ class Posts(Model):
|
||||
q = f'{self.FULL_POSTS_QUERY} WHERE posts.id = ?'
|
||||
return db.fetch_one(q, self.id)
|
||||
|
||||
@classmethod
|
||||
def new(cls, user_id: int, thread_id: int, content: str, language: str = 'babycode') -> Posts:
|
||||
from .lib.babycode import babycode_to_html, babycode_to_rssxml, BABYCODE_VERSION
|
||||
html_content = babycode_to_html(content)
|
||||
rssxml_content = babycode_to_rssxml(content)
|
||||
with db.transaction():
|
||||
post = Posts.create({
|
||||
'thread_id': thread_id,
|
||||
'user_id': user_id,
|
||||
'current_revision_id': None,
|
||||
})
|
||||
|
||||
revision = PostHistory.create({
|
||||
'post_id': post.id,
|
||||
'content': html_content.result,
|
||||
'content_rss': rssxml_content,
|
||||
'is_initial_revision': True,
|
||||
'original_markup': content,
|
||||
'markup_language': language,
|
||||
'format_version': BABYCODE_VERSION,
|
||||
})
|
||||
|
||||
for mention in html_content.mentions:
|
||||
Mentions.create({
|
||||
'revision_id': revision.id,
|
||||
'mentioned_iser_id': mention['mentioned_iser_id'],
|
||||
'start_index': mention['start'],
|
||||
'end_index': mention['end'],
|
||||
})
|
||||
|
||||
post.update({'current_revision_id': revision.id})
|
||||
return post
|
||||
|
||||
class PostHistory(Model):
|
||||
table = 'post_history'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user