finesse my earlier fix

This commit is contained in:
rimu 2024-11-06 14:38:58 +13:00
parent 108b3f9422
commit 70bb9ab68f

View file

@ -1384,17 +1384,18 @@ def restore_post_or_comment(object_json, aplog_id):
to_restore.deleted_by = None to_restore.deleted_by = None
community.post_count += 1 community.post_count += 1
to_restore.author.post_count += 1 to_restore.author.post_count += 1
new_cross_posts = Post.query.filter(Post.id != to_restore.id, Post.url == to_restore.url, Post.deleted == False, Post.url != None, Post.url != '', if to_restore.url:
Post.posted_at > utcnow() - timedelta(days=6)).all() new_cross_posts = Post.query.filter(Post.id != to_restore.id, Post.url == to_restore.url, Post.deleted == False,
for ncp in new_cross_posts: Post.posted_at > utcnow() - timedelta(days=6)).all()
if ncp.cross_posts is None: for ncp in new_cross_posts:
ncp.cross_posts = [to_restore.id] if ncp.cross_posts is None:
else: ncp.cross_posts = [to_restore.id]
ncp.cross_posts.append(to_restore.id) else:
if to_restore.cross_posts is None: ncp.cross_posts.append(to_restore.id)
to_restore.cross_posts = [ncp.id] if to_restore.cross_posts is None:
else: to_restore.cross_posts = [ncp.id]
to_restore.cross_posts.append(ncp.id) else:
to_restore.cross_posts.append(ncp.id)
db.session.commit() db.session.commit()
if to_restore.author.id != restorer.id: if to_restore.author.id != restorer.id:
add_to_modlog_activitypub('restore_post', restorer, community_id=community.id, add_to_modlog_activitypub('restore_post', restorer, community_id=community.id,
@ -1872,7 +1873,7 @@ def update_post_from_activity(post: Post, request_json: dict):
if ocp.cross_posts is not None and post.id in ocp.cross_posts: if ocp.cross_posts is not None and post.id in ocp.cross_posts:
ocp.cross_posts.remove(post.id) ocp.cross_posts.remove(post.id)
new_cross_posts = Post.query.filter(Post.id != post.id, Post.url == post.url, Post.deleted == False, Post.url != None, Post.url != '', new_cross_posts = Post.query.filter(Post.id != post.id, Post.url == post.url, Post.deleted == False,
Post.posted_at > utcnow() - timedelta(days=6)).all() Post.posted_at > utcnow() - timedelta(days=6)).all()
for ncp in new_cross_posts: for ncp in new_cross_posts:
if ncp.cross_posts is None: if ncp.cross_posts is None: