add subscribing and unsubscribing, add post editing

This commit is contained in:
2026-04-28 19:03:29 +03:00
parent f3acf64e6d
commit ff2c6606f8
8 changed files with 219 additions and 33 deletions

View File

@@ -102,6 +102,9 @@ class Users(Model):
def get_badges(self):
return Badges.findall({'user_id': int(self.id)})
def is_subscribed(self, thread_id):
return Subscriptions.count({'user_id': self.id, 'thread_id': thread_id}) > 0
class Topics(Model):
table = 'topics'
@@ -327,7 +330,8 @@ class Posts(Model):
for mention in html_content.mentions:
Mentions.create({
'revision_id': revision.id,
'mentioned_iser_id': mention['mentioned_iser_id'],
'mentioned_user_id': mention['mentioned_user_id'],
'original_mention_text': mention['mention_text'],
'start_index': mention['start'],
'end_index': mention['end'],
})
@@ -335,6 +339,32 @@ class Posts(Model):
post.update({'current_revision_id': revision.id})
return post
def edit(self, new_content: str, language: str = 'babycode'):
from .lib.babycode import babycode_to_html, babycode_to_rssxml, BABYCODE_VERSION
html_content = babycode_to_html(new_content)
rssxml_content = babycode_to_rssxml(new_content)
with db.transaction():
revision = PostHistory.create({
'post_id': self.id,
'content': html_content.result,
'content_rss': rssxml_content,
'is_initial_revision': False,
'original_markup': new_content,
'markup_language': language,
'format_version': BABYCODE_VERSION,
})
for mention in html_content.mentions:
Mentions.create({
'revision_id': revision.id,
'mentioned_user_id': mention['mentioned_user_id'],
'original_mention_text': mention['mention_text'],
'start_index': mention['start'],
'end_index': mention['end'],
})
self.update({'current_revision_id': revision.id})
class PostHistory(Model):
table = 'post_history'