From a8ea3c08c9eb39a8bf94ff83f3abd4b49aba4fd2 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 12 Mar 2020 17:16:55 -0700 Subject: [PATCH] Don't duplicate incoming statuses --- fedireads/incoming.py | 2 +- fedireads/status.py | 11 +++++++---- fedireads/templates/snippets/status.html | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/fedireads/incoming.py b/fedireads/incoming.py index 41389ce7..b975707e 100644 --- a/fedireads/incoming.py +++ b/fedireads/incoming.py @@ -285,7 +285,7 @@ def handle_incoming_create(activity): elif not user.local: try: status = create_status_from_activity(user, activity['object']) - if status.reply_parent: + if status and status.reply_parent: create_notification( status.reply_parent.user, 'REPLY', diff --git a/fedireads/status.py b/fedireads/status.py index 51a5cc16..34bd8050 100644 --- a/fedireads/status.py +++ b/fedireads/status.py @@ -48,9 +48,10 @@ def create_status_from_activity(author, activity): reply_parent = get_status(reply_parent_id) remote_id = activity['id'] - - status = create_status(author, content, reply_parent=reply_parent) - status.remote_id = remote_id + if models.Status.objects.filter(remote_id=remote_id).count(): + return None + status = create_status(author, content, reply_parent=reply_parent, + remote_id=remote_id) status.published_date = activity.get('published') status.save() return status @@ -80,7 +81,8 @@ def get_status(absolute_id): -def create_status(user, content, reply_parent=None, mention_books=None): +def create_status(user, content, reply_parent=None, mention_books=None, + remote_id=None): ''' a status update ''' # TODO: handle @'ing users @@ -93,6 +95,7 @@ def create_status(user, content, reply_parent=None, mention_books=None): user=user, content=content, reply_parent=reply_parent, + remote_id=remote_id, ) if mention_books: diff --git a/fedireads/templates/snippets/status.html b/fedireads/templates/snippets/status.html index 545184b8..3ede48cc 100644 --- a/fedireads/templates/snippets/status.html +++ b/fedireads/templates/snippets/status.html @@ -14,7 +14,7 @@ {% if status.status_type == 'Review' %}

{{ status.name }} {{ status.rating | stars }} stars, by {% include 'snippets/username.html' with user=status.user %}

{% endif %} -
{{ status.content }}
+
{{ status.content | safe }}
{% if not max_depth and status.reply_parent or status|replies %}

Thread{% endif %} {% include 'snippets/interaction.html' with activity=status %}