Don't subclass ActivitypubComment from ActivitypubPost

Leads to annoying base class comparison problems since
this will make ActivitypubComment also a Post.
merge-requests/148/head
Jason Robinson 2019-06-30 01:29:49 +03:00
rodzic b4a4d7128a
commit fcb5d1147c
2 zmienionych plików z 30 dodań i 8 usunięć

Wyświetl plik

@ -33,6 +33,36 @@ class ActivitypubAccept(ActivitypubObjectMixin, Accept):
return as2
class ActivitypubComment(ActivitypubObjectMixin, Comment):
_type = ObjectType.NOTE.value
def to_as2(self) -> Dict:
as2 = {
"@context": CONTEXTS_DEFAULT + [
CONTEXT_HASHTAG,
CONTEXT_LD_SIGNATURES,
CONTEXT_SENSITIVE,
],
"type": self.activity.value,
"id": self.activity_id,
"actor": self.actor_id,
"object": {
"id": self.id,
"type": self._type,
"attributedTo": self.actor_id,
"content": self.raw_content, # TODO render to html, add source markdown
"published": self.created_at.isoformat(),
"inReplyTo": self.target_id,
"sensitive": True if "nsfw" in self.tags else False,
"summary": None, # TODO Short text? First sentence? First line?
"tag": [], # TODO add tags
"url": self.url,
},
"published": self.created_at.isoformat(),
}
return as2
class ActivitypubFollow(ActivitypubObjectMixin, Follow):
_type = ActivityType.FOLLOW.value
@ -138,13 +168,6 @@ class ActivitypubPost(ActivitypubObjectMixin, Post):
return as2
class ActivitypubComment(ActivitypubPost, Comment):
def to_as2(self) -> Dict:
as2 = super().to_as2()
as2["object"]["inReplyTo"] = self.target_id
return as2
class ActivitypubProfile(ActivitypubActorMixin, Profile):
_type = ActorType.PERSON.value
public = True

Wyświetl plik

@ -87,7 +87,6 @@ class TestActivitypubEntityMappersReceive:
'class="u-url mention">@<span>jaywink</span></a></span> boom</p>'
assert comment.id == "https://diaspodon.fr/users/jaywink/statuses/102356911717767237"
assert comment.actor_id == "https://diaspodon.fr/users/jaywink"
assert comment.public is True
assert comment.target_id == "https://dev.jasonrobinson.me/content/653bad70-41b3-42c9-89cb-c4ee587e68e4/"
@pytest.mark.skip