Bubble [main]
Fixes for issue cross-references
[1mdiff --git a/feeds.py b/feeds.py[m
[1mindex 0e164b9..61ee7ce 100644[m
[1m--- a/feeds.py[m
[1m+++ b/feeds.py[m
[36m@@ -168,6 +168,23 @@[m [mdef make_post_page(session, post):[m
[m
page = session.render_post(post)[m
[m
[32m+[m[32m commits = [][m
[32m+[m[32m incoming_xrefs = [][m
[32m+[m[32m outgoing_xrefs = {}[m
[32m+[m[32m if post.issueid:[m
[32m+[m[32m repo = db.get_repository(subspace=session.context)[m
[32m+[m[32m commits = db.get_commits(repo, issueid=post.issueid)[m
[32m+[m[32m incoming_xrefs = db.get_issue_crossrefs(session.context,[m
[32m+[m[32m incoming_to_issueid=post.issueid)[m
[32m+[m[32m outgoing_xrefs = db.get_issue_crossrefs(session.context,[m
[32m+[m[32m outgoing_from_issueid=post.issueid)[m
[32m+[m
[32m+[m[32m # Cross references outgoing from the main post itself.[m
[32m+[m[32m if outgoing_xrefs and post.id in outgoing_xrefs:[m
[32m+[m[32m page += '\n'[m
[32m+[m[32m for xref in outgoing_xrefs[post.id]:[m
[32m+[m[32m page += xref.outgoing_entry()[m
[32m+[m
# Poll.[m
poll = session.render_poll(post, show_results=not session.user)[m
if poll:[m
[36m@@ -249,16 +266,7 @@[m [mdef make_post_page(session, post):[m
display_order_desc = not session.user or \[m
session.user.sort_cmt == User.SORT_COMMENT_NEWEST[m
comments = db.get_posts(parent=post.id, draft=False, sort_descending=False, limit=None)[m
[31m- commits = [][m
[31m- incoming_xrefs = [][m
[31m- outgoing_xrefs = {}[m
[31m- if post.issueid:[m
[31m- repo = db.get_repository(subspace=session.context)[m
[31m- commits = db.get_commits(repo, issueid=post.issueid)[m
[31m- incoming_xrefs = db.get_issue_crossrefs(session.context,[m
[31m- incoming_to_issueid=post.issueid)[m
[31m- outgoing_xrefs = db.get_issue_crossrefs(session.context,[m
[31m- outgoing_from_issueid=post.issueid)[m
[32m+[m
n = len(comments)[m
if n > 0 or commits or incoming_xrefs:[m
if n > 1:[m
[36m@@ -279,19 +287,12 @@[m [mdef make_post_page(session, post):[m
[m
# Commits are shown as links to the Git viewer.[m
if isinstance(cmt, Commit):[m
[31m- rendered_comments.append([m
[31m- f'=> {repo.view_url}/{cmt.hash} Commit {cmt.hash[:8]} · {clean_title(cmt.msg)}\n' +[m
[31m- ago_text(cmt.ts) + '\n'[m
[31m- )[m
[32m+[m[32m rendered_comments.append(cmt.entry(repo.view_url))[m
continue[m
[m
# Cross-references incoming from other issues.[m
if isinstance(cmt, Crossref):[m
[31m- x_url = f'/s/{cmt.sub_name}/{cmt.id}'[m
[31m- x_icon = '✔︎' if '✔︎' in cmt.tags else '🐞'[m
[31m- rendered_comments.append([m
[31m- f'=> {x_url} {x_icon} Mentioned in #{cmt.issueid}: {cmt.title}\n{ago_text(cmt.ts_created)}\n'[m
[31m- )[m
[32m+[m[32m rendered_comments.append(cmt.incoming_entry())[m
continue[m
[m
src = f'=> /u/{cmt.poster_name} {cmt.poster_avatar} {cmt.poster_name}\n'[m
[36m@@ -300,9 +301,7 @@[m [mdef make_post_page(session, post):[m
# Cross-references to other issues.[m
if outgoing_xrefs and cmt.id in outgoing_xrefs:[m
for xref in outgoing_xrefs[cmt.id]:[m
[31m- x_url = f'/s/{xref.sub_name}/{xref.id}'[m
[31m- x_icon = '✔︎' if '✔︎' in xref.tags else '🐞'[m
[31m- src += f'=> {x_url} {x_icon} — #{xref.issueid}: {xref.title}\n'[m
[32m+[m[32m src += xref.outgoing_entry()[m
[m
# Hide the `age` if it's the same as the previous entry (in reading order).[m
comment_age = cmt.age()[m
[1mdiff --git a/model.py b/model.py[m
[1mindex f475a14..e118b8b 100644[m
[1m--- a/model.py[m
[1m+++ b/model.py[m
[36m@@ -229,6 +229,9 @@[m [mclass Commit:[m
dt = datetime.datetime.fromtimestamp(self.ts, UTC)[m
return dt.strftime('%Y-%m-%d')[m
[m
[32m+[m[32m def entry(self, view_url):[m
[32m+[m[32m return f'=> {view_url}/{self.hash} Commit {self.hash[:8]} · {clean_title(self.msg)}\n' + ago_text(self.ts) + '\n'[m
[32m+[m
[m
class Post:[m
TAG_PINNED = 'pinned'[m
[36m@@ -300,6 +303,16 @@[m [mclass Crossref (Post):[m
None, None, None, None, tags, ts_created,[m
None, None, sub_name)[m
[m
[32m+[m[32m def incoming_entry(self):[m
[32m+[m[32m x_url = f'/s/{self.sub_name}/{self.id}'[m
[32m+[m[32m x_icon = '✔︎' if '✔︎' in self.tags else '🐞'[m
[32m+[m[32m return f'=> {x_url} {x_icon} Mentioned in #{self.issueid}: {self.title}\n{ago_text(self.ts_created)}\n'[m
[32m+[m
[32m+[m[32m def outgoing_entry(self):[m
[32m+[m[32m x_url = f'/s/{self.sub_name}/{self.id}'[m
[32m+[m[32m x_icon = '✔︎' if '✔︎' in self.tags else '🐞'[m
[32m+[m[32m return f'=> {x_url} {x_icon} — #{self.issueid}: {self.title}\n'[m
[32m+[m
[m
class File:[m
def __init__(self, id, segment, user, name, mimetype, data,[m
[36m@@ -1090,25 +1103,29 @@[m [mclass Database:[m
[m
self.commit()[m
[m
[31m- # Notify mentioned users.[m
all_text = [][m
for segment in self.get_segments(post):[m
if segment.type == Segment.TEXT:[m
all_text.append(segment.content)[m
[32m+[m
[32m+[m[32m # Notify mentioned users.[m
self.notify_mentioned(post, ' '.join(all_text))[m
[m
[31m- if self.get_subspace(post.subspace).flags & Subspace.ISSUE_TRACKER and \[m
[31m- post.issueid is None and \[m
[31m- post.parent == 0:[m
[31m- # Time to assign a new issue number.[m
[31m- cur.execute("""[m
[31m- UPDATE posts[m
[31m- SET issueid=(SELECT nextissueid FROM subspaces WHERE id=?)[m
[31m- WHERE id=?[m
[31m- """, (post.subspace, post.id))[m
[31m- cur.execute("UPDATE subspaces SET nextissueid=nextissueid+1 WHERE id=?",[m
[31m- (post.subspace,))[m
[31m- self.commit()[m
[32m+[m[32m if self.get_subspace(post.subspace).flags & Subspace.ISSUE_TRACKER:[m
[32m+[m[32m if post.issueid is None and post.parent == 0:[m
[32m+[m[32m # Time to assign a new issue number.[m
[32m+[m[32m cur.execute("""[m
[32m+[m[32m UPDATE posts[m
[32m+[m[32m SET issueid=(SELECT nextissueid FROM subspaces WHERE id=?)[m
[32m+[m[32m WHERE id=?[m
[32m+[m[32m """, (post.subspace, post.id))[m
[32m+[m[32m cur.execute("UPDATE subspaces SET nextissueid=nextissueid+1 WHERE id=?",[m
[32m+[m[32m (post.subspace,))[m
[32m+[m[32m self.commit()[m
[32m+[m
[32m+[m[32m # Update all crossrefrences found in text segments (posts and comments).[m
[32m+[m[32m for segment in self.get_segments(post):[m
[32m+[m[32m self.update_segment_crossrefs(segment)[m
[m
self.update_user(post.user, active=True)[m
self.update_subspace(post.subspace, active=True)[m
[36m@@ -1162,6 +1179,7 @@[m [mclass Database:[m
if content != None:[m
set_stm.append('content=?')[m
values.append(content)[m
[32m+[m[32m segment.content = content[m
if url != None:[m
set_stm.append('url=?')[m
values.append(url)[m
[36m@@ -1175,8 +1193,8 @@[m [mclass Database:[m
if not post.is_draft:[m
self.update_post_summary(post)[m
if content:[m
[31m- self.update_segment_crossrefs(segment) # from text segments[m
if not post.is_draft:[m
[32m+[m[32m self.update_segment_crossrefs(segment)[m
self.notify_mentioned(post, content)[m
[m
def get_segments(self, post, poll=None):[m
[36m@@ -1213,6 +1231,7 @@[m [mclass Database:[m
seg_post = self.get_post(id=segment.post)[m
parent_post = self.get_post(id=seg_post.parent) if seg_post.parent else None[m
issue_post = parent_post if parent_post else seg_post[m
[32m+[m[32m print('xref', issue_post.issueid)[m
if not issue_post.issueid:[m
return[m
[m
[36m@@ -1226,7 +1245,8 @@[m [mclass Database:[m
INSERT IGNORE INTO crossrefs[m
(subspace, post, segment, issueid, dst_post, dst_issueid, ts)[m
SELECT[m
[31m- {issue_post.subspace}, {issue_post.id}, {segment.id}, {issue_post.issueid}, id, {dst_issueid}, ?[m
[32m+[m[32m {issue_post.subspace}, {issue_post.id}, {segment.id},[m
[32m+[m[32m {issue_post.issueid}, id, {dst_issueid}, ?[m
FROM posts[m
WHERE issueid=?[m
""", (datetime.datetime.fromtimestamp(seg_post.ts_created),[m