kopia lustrzana https://github.com/tsileo/little-boxes
Add support for Article
rodzic
0326bb9309
commit
f06202c382
|
@ -97,6 +97,8 @@ ACTOR_TYPES = [
|
|||
ActivityType.SERVICE,
|
||||
]
|
||||
|
||||
CREATE_TYPES = [ActivityType.NOTE, ActivityType.ARTICLE]
|
||||
|
||||
COLLECTION_TYPES = [ActivityType.COLLECTION, ActivityType.ORDERED_COLLECTION]
|
||||
|
||||
|
||||
|
@ -224,7 +226,7 @@ class BaseActivity(object, metaclass=_ActivityMeta):
|
|||
kwargs.pop("actor")
|
||||
actor = self._validate_actor(actor)
|
||||
self._data["actor"] = actor
|
||||
elif self.ACTIVITY_TYPE == ActivityType.NOTE:
|
||||
elif self.ACTIVITY_TYPE in CREATE_TYPES:
|
||||
if "attributedTo" not in kwargs:
|
||||
raise BadActivityError(f"Note is missing attributedTo")
|
||||
else:
|
||||
|
@ -445,7 +447,7 @@ class BaseActivity(object, metaclass=_ActivityMeta):
|
|||
actor = self._data.get("actor")
|
||||
if not actor and self.ACTOR_REQUIRED:
|
||||
# Quick hack for Note objects
|
||||
if self.ACTIVITY_TYPE == ActivityType.NOTE:
|
||||
if self.ACTIVITY_TYPE in CREATE_TYPES:
|
||||
actor = str(self._data.get("attributedTo"))
|
||||
else:
|
||||
raise BadActivityError(f"failed to fetch actor: {self._data!r}")
|
||||
|
@ -834,7 +836,7 @@ class Undo(BaseActivity):
|
|||
|
||||
class Like(BaseActivity):
|
||||
ACTIVITY_TYPE = ActivityType.LIKE
|
||||
ALLOWED_OBJECT_TYPES = [ActivityType.NOTE, ActivityType.ARTICLE]
|
||||
ALLOWED_OBJECT_TYPES = CREATE_TYPES
|
||||
OBJECT_REQUIRED = True
|
||||
ACTOR_REQUIRED = True
|
||||
|
||||
|
@ -880,7 +882,7 @@ class Like(BaseActivity):
|
|||
|
||||
class Announce(BaseActivity):
|
||||
ACTIVITY_TYPE = ActivityType.ANNOUNCE
|
||||
ALLOWED_OBJECT_TYPES = [ActivityType.NOTE, ActivityType.ARTICLE]
|
||||
ALLOWED_OBJECT_TYPES = CREATE_TYPES
|
||||
OBJECT_REQUIRED = True
|
||||
ACTOR_REQUIRED = True
|
||||
|
||||
|
@ -939,7 +941,7 @@ class Announce(BaseActivity):
|
|||
|
||||
class Delete(BaseActivity):
|
||||
ACTIVITY_TYPE = ActivityType.DELETE
|
||||
ALLOWED_OBJECT_TYPES = [ActivityType.NOTE, ActivityType.TOMBSTONE]
|
||||
ALLOWED_OBJECT_TYPES = CREATE_TYPES + [ActivityType.TOMBSTONE]
|
||||
OBJECT_REQUIRED = True
|
||||
|
||||
def _get_actual_object(self) -> BaseActivity:
|
||||
|
@ -1008,7 +1010,7 @@ class Delete(BaseActivity):
|
|||
|
||||
class Update(BaseActivity):
|
||||
ACTIVITY_TYPE = ActivityType.UPDATE
|
||||
ALLOWED_OBJECT_TYPES = [ActivityType.NOTE, ActivityType.PERSON]
|
||||
ALLOWED_OBJECT_TYPES = CREATE_TYPES + [ActivityType.PERSON]
|
||||
OBJECT_REQUIRED = True
|
||||
ACTOR_REQUIRED = True
|
||||
|
||||
|
@ -1047,7 +1049,7 @@ class Update(BaseActivity):
|
|||
|
||||
class Create(BaseActivity):
|
||||
ACTIVITY_TYPE = ActivityType.CREATE
|
||||
ALLOWED_OBJECT_TYPES = [ActivityType.NOTE]
|
||||
ALLOWED_OBJECT_TYPES = CREATE_TYPES
|
||||
OBJECT_REQUIRED = True
|
||||
ACTOR_REQUIRED = True
|
||||
|
||||
|
@ -1196,6 +1198,12 @@ class Note(BaseActivity):
|
|||
return False
|
||||
|
||||
|
||||
class Article(Note):
|
||||
ACTIVITY_TYPE = ActivityType.ARTICLE
|
||||
ACTOR_REQUIRED = True
|
||||
OBJECT_REQURIED = False
|
||||
|
||||
|
||||
def fetch_remote_activity(
|
||||
iri: str, expected: Optional[ActivityType] = None
|
||||
) -> BaseActivity:
|
||||
|
@ -1214,7 +1222,7 @@ class Outbox(Box):
|
|||
f"{activity.get_actor()!r} cannot post into {self.actor!r} outbox"
|
||||
)
|
||||
|
||||
if activity.ACTIVITY_TYPE == ActivityType.NOTE:
|
||||
if activity.ACTIVITY_TYPE in CREATE_TYPES:
|
||||
activity = activity.build_create()
|
||||
|
||||
activity.post_to_outbox()
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
from little_boxes import activitypub as ap
|
||||
from little_boxes.collection import parse_collection
|
||||
from little_boxes.errors import RecursionLimitExceededError
|
||||
from little_boxes.errors import UnexpectedActivityTypeError
|
||||
|
||||
from test_backend import InMemBackend
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
|
|
@ -3,6 +3,7 @@ from unittest import mock
|
|||
|
||||
from little_boxes import activitypub as ap
|
||||
from little_boxes import content_helper
|
||||
|
||||
from test_backend import InMemBackend
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import logging
|
||||
|
||||
import httpretty
|
||||
import requests
|
||||
|
||||
from little_boxes import activitypub as ap
|
||||
from little_boxes import httpsig
|
||||
from little_boxes.key import Key
|
||||
|
||||
import httpretty
|
||||
from test_backend import InMemBackend
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import logging
|
||||
|
||||
from little_boxes import activitypub as ap
|
||||
|
||||
from test_backend import InMemBackend
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from little_boxes import urlutils
|
||||
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@ import json
|
|||
import logging
|
||||
from unittest import mock
|
||||
|
||||
import httpretty
|
||||
import pytest
|
||||
|
||||
from little_boxes import urlutils
|
||||
from little_boxes import webfinger
|
||||
|
||||
import httpretty
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue