def to_activity_dataclass(self, pure=False): # pylint: disable=arguments-differ """return tombstone if the status is deleted""" if self.deleted: return activitypub.Tombstone( id=self.remote_id, url=self.remote_id, deleted=self.deleted_date.isoformat(), published=self.deleted_date.isoformat(), ) activity = ActivitypubMixin.to_activity_dataclass(self) activity.replies = self.to_replies() # "pure" serialization for non-bookwyrm instances if pure and hasattr(self, "pure_content"): activity.content = self.pure_content if hasattr(activity, "name"): activity.name = self.pure_name activity.type = self.pure_type activity.attachment = [ image_serializer(b.cover, b.alt_text) for b in self.mention_books.all()[:4] if b.cover ] if hasattr(self, "book") and self.book.cover: activity.attachment.append( image_serializer(self.book.cover, self.book.alt_text)) return activity
def to_activity(self, pure=False): ''' return tombstone if the status is deleted ''' if self.deleted: return activitypub.Tombstone( id=self.remote_id, url=self.remote_id, deleted=self.deleted_date.isoformat(), published=self.deleted_date.isoformat()).serialize() return ActivitypubMixin.to_activity(self, pure=pure)
def to_activity(self, pure=False): ''' return tombstone if the status is deleted ''' if self.deleted: return activitypub.Tombstone( id=self.remote_id, url=self.remote_id, deleted=self.deleted_date.isoformat(), published=self.deleted_date.isoformat()).serialize() activity = ActivitypubMixin.to_activity(self) activity['replies'] = self.to_replies() # privacy controls public = 'https://www.w3.org/ns/activitystreams#Public' mentions = [u.remote_id for u in self.mention_users.all()] # this is a link to the followers list: followers = self.user.__class__._meta.get_field('followers')\ .field_to_activity(self.user.followers) if self.privacy == 'public': activity['to'] = [public] activity['cc'] = [followers] + mentions elif self.privacy == 'unlisted': activity['to'] = [followers] activity['cc'] = [public] + mentions elif self.privacy == 'followers': activity['to'] = [followers] activity['cc'] = mentions if self.privacy == 'direct': activity['to'] = mentions activity['cc'] = [] # "pure" serialization for non-bookwyrm instances if pure: activity['content'] = self.pure_content if 'name' in activity: activity['name'] = self.pure_name activity['type'] = self.pure_type activity['attachment'] = [ image_serializer(b.cover) for b in self.mention_books.all() \ if b.cover] if hasattr(self, 'book'): activity['attachment'].append(image_serializer( self.book.cover)) return activity
def to_activity_dataclass(self, pure=False): # pylint: disable=arguments-differ """return tombstone if the status is deleted""" if self.deleted: return activitypub.Tombstone( id=self.remote_id, url=self.remote_id, deleted=self.deleted_date.isoformat(), published=self.deleted_date.isoformat(), ) activity = ActivitypubMixin.to_activity_dataclass(self) activity.replies = self.to_replies() # "pure" serialization for non-bookwyrm instances if pure and hasattr(self, "pure_content"): activity.content = self.pure_content if hasattr(activity, "name"): activity.name = self.pure_name activity.type = self.pure_type book = getattr(self, "book", None) books = [book] if book else [] books += list(self.mention_books.all()) if len(books) == 1 and getattr(books[0], "preview_image", None): covers = [ activitypub.Document( url=fields.get_absolute_url(books[0].preview_image), name=books[0].alt_text, ) ] else: covers = [ activitypub.Document( url=fields.get_absolute_url(b.cover), name=b.alt_text, ) for b in books if b and b.cover ] activity.attachment = covers return activity