From 6313ad2e5dd28a51447c53ed335a056864806d40 Mon Sep 17 00:00:00 2001 From: freamon Date: Tue, 2 Apr 2024 18:44:42 +0100 Subject: [PATCH] Find cross-posts for items in remote community outbox --- app/community/util.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/community/util.py b/app/community/util.py index f58c067c..e328b02d 100644 --- a/app/community/util.py +++ b/app/community/util.py @@ -106,10 +106,23 @@ def retrieve_mods_and_backfill(community_id: int): db.session.add(activity_log) if user: post = post_json_to_model(activity_log, activity['object']['object'], user, community) - post.ap_create_id = activity['object']['id'] - post.ap_announce_id = activity['id'] - post.ranking = post_ranking(post.score, post.posted_at) - db.session.commit() + if post: + post.ap_create_id = activity['object']['id'] + post.ap_announce_id = activity['id'] + post.ranking = post_ranking(post.score, post.posted_at) + if post.url: + other_posts = Post.query.filter(Post.id != post.id, Post.url == post.url, + Post.posted_at > post.posted_at - timedelta(days=3), Post.posted_at < post.posted_at + timedelta(days=3)).all() + for op in other_posts: + if op.cross_posts is None: + op.cross_posts = [post.id] + else: + op.cross_posts.append(post.id) + if post.cross_posts is None: + post.cross_posts = [op.id] + else: + post.cross_posts.append(op.id) + db.session.commit() else: activity_log.exception_message = 'Could not find or create actor' db.session.commit()