diff --git a/boards/mdx_neboard.py b/boards/mdx_neboard.py --- a/boards/mdx_neboard.py +++ b/boards/mdx_neboard.py @@ -130,6 +130,22 @@ def render_reflink(tag_name, value, opti return '>>%s' % value +def render_multithread(tag_name, value, options, parent, context): + result = '>>>%s' % value + + if REFLINK_PATTERN.match(value): + post_id = int(value) + + posts = boards.models.Post.objects.filter(id=post_id) + if posts.exists(): + post = posts[0] + + if post.is_opening(): + result = '>>>%s' % (post.get_url(), post_id) + + return result + + def render_quote(tag_name, value, options, parent, context): source = '' if 'source' in options: @@ -163,6 +179,7 @@ def bbcode_extended(markup): # browsers except firefox, when the div's does. parser = bbcode.Parser(newline='
') parser.add_formatter('post', render_reflink, strip=True) + parser.add_formatter('thread', render_multithread, strip=True) parser.add_formatter('quote', render_quote, strip=True) parser.add_formatter('user', render_notification, strip=True) parser.add_simple_formatter('comment', diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -43,6 +43,7 @@ NO_IP = '0.0.0.0' UNKNOWN_UA = '' REGEX_REPLY = re.compile(r'\[post\](\d+)\[/post\]') +REGEX_MULTI_THREAD = re.compile(r'\[thread\](\d+)\[/thread\]') REGEX_URL = re.compile(r'https?\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?') REGEX_NOTIFICATION = re.compile(r'\[user\](\w+)\[/user\]') @@ -63,7 +64,8 @@ DIFF_TYPE_HTML = 'html' DIFF_TYPE_JSON = 'json' PREPARSE_PATTERNS = { - r'>>(\d+)': r'[post]\1[/post]', # Reflink ">>123" + r'>>>(\d+)': r'[thread]\1[/thread]', # Multi-thread post ">>>123" + r'(?)>>(\d+)': r'[post]\1[/post]', # Reflink ">>123" r'^>([^>].+)': r'[quote]\1[/quote]', # Quote ">text" r'^//(.+)': r'[comment]\1[/comment]', # Comment "//text" r'\B@(\w+)': r'[user]\1[/user]', # User notification "@user" @@ -119,6 +121,7 @@ class PostManager(models.Manager): thread.save() post.connect_replies() + post.connect_threads() post.connect_notifications() return post @@ -450,4 +453,20 @@ class Post(models.Model, Viewable): thread.last_edit_time = self.pub_time thread.save(update_fields=['last_edit_time', 'bumpable']) - self.threads.add(thread) + def connect_threads(self): + for reply_number in re.finditer(REGEX_MULTI_THREAD, self.get_raw_text()): + post_id = reply_number.group(1) + ref_post = Post.objects.filter(id=post_id) + if ref_post.count() > 0: + referenced_post = ref_post[0] + + if referenced_post.is_opening(): + referenced_threads = referenced_post.get_threads().all() + for thread in referenced_threads: + if thread.can_bump(): + thread.update_bump_status() + + thread.last_edit_time = self.pub_time + thread.save(update_fields=['last_edit_time', 'bumpable']) + + self.threads.add(thread)