Fixes deletion

This commit is contained in:
Mouse Reeve 2021-02-16 09:35:00 -08:00
parent 08c1553e71
commit b393df8cab
3 changed files with 16 additions and 0 deletions

View file

@ -1,6 +1,7 @@
''' note serializer and children thereof '''
from dataclasses import dataclass, field
from typing import Dict, List
from django.apps import apps
from .base_activity import ActivityObject, Link
from .image import Image
@ -10,6 +11,11 @@ class Tombstone(ActivityObject):
''' the placeholder for a deleted status '''
type: str = 'Tombstone'
def to_model(self, *args, **kwargs):
''' this should never really get serialized, just searched for '''
model = apps.get_model('bookwyrm.Status')
return model.find_existing_by_remote_id(self.id)
@dataclass(init=False)
class Note(ActivityObject):

View file

@ -84,6 +84,12 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
related_status=self,
)
def delete(self, *args, **kwargs):
''' "delete" a status '''
self.deleted = True
self.deleted_date = timezone.now()
self.save()
@property
def recipients(self):
''' tagged users who definitely need to get this status in broadcast '''

View file

@ -422,6 +422,8 @@ class Inbox(TestCase):
self.assertFalse(self.status.deleted)
activity = {
'type': 'Delete',
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"cc": ["https://example.com/user/mouse/followers"],
'id': '%s/activity' % self.status.remote_id,
'actor': self.remote_user.remote_id,
'object': {'id': self.status.remote_id, 'type': 'Tombstone'},
@ -451,6 +453,8 @@ class Inbox(TestCase):
self.assertEqual(models.Notification.objects.count(), 2)
activity = {
'type': 'Delete',
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"cc": ["https://example.com/user/mouse/followers"],
'id': '%s/activity' % self.status.remote_id,
'actor': self.remote_user.remote_id,
'object': {'id': self.status.remote_id, 'type': 'Tombstone'},