kopia lustrzana https://github.com/tsileo/little-boxes
Re-add Announce support
rodzic
31b9b40b35
commit
998eb90e71
|
@ -754,15 +754,16 @@ class Announce(BaseActivity):
|
|||
ACTOR_REQUIRED = True
|
||||
|
||||
def _recipients(self) -> List[str]:
|
||||
recipients = []
|
||||
recipients = [self.get_object().get_actor().id]
|
||||
|
||||
for field in ["to", "cc"]:
|
||||
if field in self._data:
|
||||
recipients.extend(_to_list(self._data[field]))
|
||||
|
||||
return recipients
|
||||
return list(set(recipients))
|
||||
|
||||
def _process_from_inbox(self, as_actor: "Person") -> None:
|
||||
# XXX(tsileo): Mastodon will try to send Announce for OStatus only acitivities which we cannot parse
|
||||
if isinstance(self._data["object"], str) and not self._data[
|
||||
"object"
|
||||
].startswith("http"):
|
||||
|
@ -772,8 +773,7 @@ class Announce(BaseActivity):
|
|||
)
|
||||
return
|
||||
|
||||
# ABC
|
||||
self.inbox_announce(self)
|
||||
BACKEND.inbox_announce(as_actor, self)
|
||||
|
||||
def _undo_inbox(self, as_actor: "Person") -> None:
|
||||
if BACKEND is None:
|
||||
|
@ -788,8 +788,7 @@ class Announce(BaseActivity):
|
|||
activity: ObjectType,
|
||||
recipients: List[str],
|
||||
) -> None:
|
||||
# ABC
|
||||
self.outbox_announce(self)
|
||||
BACKEND.outbox_announce(as_actor, self)
|
||||
|
||||
def _undo_outbox(self, as_actor: "Person") -> None:
|
||||
if BACKEND is None:
|
||||
|
|
|
@ -77,3 +77,21 @@ class Backend(abc.ABC):
|
|||
@abc.abstractmethod
|
||||
def outbox_undo_like(self, as_actor: "ap.Person", activity: "ap.Like") -> None:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def inbox_announce(self, as_actor: "ap.Person", activity: "ap.Announce") -> None:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def inbox_undo_announce(self, as_actor: "ap.Person", activity: "ap.Announce") -> None:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def outbox_announce(self, as_actor: "ap.Person", activity: "ap.Announce") -> None:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def outbox_undo_announce(
|
||||
self, as_actor: "ap.Person", activity: "ap.Announce"
|
||||
) -> None:
|
||||
pass
|
||||
|
|
|
@ -144,7 +144,7 @@ class InMemBackend(Backend):
|
|||
|
||||
def activity_url(self, obj_id: str) -> str:
|
||||
# from the random hex ID
|
||||
return f"todo/{obj_id}"
|
||||
return f"https://todo/{obj_id}"
|
||||
|
||||
@track_call
|
||||
def outbox_new(self, as_actor: ap.Person, activity: ap.BaseActivity) -> None:
|
||||
|
@ -211,16 +211,20 @@ class InMemBackend(Backend):
|
|||
def outbox_undo_like(self, as_actor: ap.Person, activity: ap.Like) -> None:
|
||||
pass
|
||||
|
||||
def inbox_announce(self, activity: ap.Announce) -> None:
|
||||
@track_call
|
||||
def inbox_announce(self, as_actor: ap.Person, activity: ap.Announce) -> None:
|
||||
pass
|
||||
|
||||
def inbox_undo_announce(self, activity: ap.Announce) -> None:
|
||||
@track_call
|
||||
def inbox_undo_announce(self, as_actor: ap.Person, activity: ap.Announce) -> None:
|
||||
pass
|
||||
|
||||
def outbox_announce(self, activity: ap.Announce) -> None:
|
||||
@track_call
|
||||
def outbox_announce(self, as_actor: ap.Person, activity: ap.Announce) -> None:
|
||||
pass
|
||||
|
||||
def outbox_undo_announce(self, activity: ap.Announce) -> None:
|
||||
@track_call
|
||||
def outbox_undo_announce(self, as_actor: ap.Person, activity: ap.Announce) -> None:
|
||||
pass
|
||||
|
||||
@track_call
|
||||
|
|
|
@ -539,7 +539,7 @@ def test_little_boxes_follow_and_new_create_note_and_like():
|
|||
lambda remote_actor: _assert_eq(remote_actor, me.id),
|
||||
),
|
||||
(
|
||||
"receiving the Delete activity",
|
||||
"receiving the Like activity",
|
||||
"inbox_new",
|
||||
lambda as_actor: _assert_eq(as_actor.id, other.id),
|
||||
lambda activity: _assert_eq(activity.id, like.id),
|
||||
|
@ -551,3 +551,60 @@ def test_little_boxes_follow_and_new_create_note_and_like():
|
|||
lambda _like: _assert_eq(_like.id, like.id),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def test_little_boxes_follow_and_new_create_note_and_announce():
|
||||
back, create = test_little_boxes_follow_and_new_create_note()
|
||||
|
||||
me = back.get_user("tom")
|
||||
other = back.get_user("tom2")
|
||||
|
||||
outbox = ap.Outbox(me)
|
||||
|
||||
announce = ap.Announce(actor=me.id, object=create.get_object().id)
|
||||
outbox.post(announce)
|
||||
|
||||
back.assert_called_methods(
|
||||
me,
|
||||
(
|
||||
"an Announce activity is published",
|
||||
"outbox_new",
|
||||
lambda as_actor: _assert_eq(as_actor.id, me.id),
|
||||
lambda activity: _assert_eq(activity.id, announce.id),
|
||||
),
|
||||
(
|
||||
'"outbox_announce" hook is called',
|
||||
"outbox_announce",
|
||||
lambda as_actor: _assert_eq(as_actor.id, me.id),
|
||||
lambda _announce: _assert_eq(_announce.id, announce.id),
|
||||
),
|
||||
(
|
||||
"the Announce activity is posted to the note creator",
|
||||
"post_to_remote_inbox",
|
||||
lambda as_actor: _assert_eq(as_actor.id, me.id),
|
||||
lambda payload: None,
|
||||
lambda recipient: _assert_eq(recipient, other.inbox),
|
||||
),
|
||||
)
|
||||
|
||||
back.assert_called_methods(
|
||||
other,
|
||||
(
|
||||
"receiving the Announce, ensure we check the actor is not blocked",
|
||||
"outbox_is_blocked",
|
||||
lambda as_actor: _assert_eq(as_actor.id, other.id),
|
||||
lambda remote_actor: _assert_eq(remote_actor, me.id),
|
||||
),
|
||||
(
|
||||
"receiving the Announce activity",
|
||||
"inbox_new",
|
||||
lambda as_actor: _assert_eq(as_actor.id, other.id),
|
||||
lambda activity: _assert_eq(activity.id, announce.id),
|
||||
),
|
||||
(
|
||||
'"inbox_announce" hook is called',
|
||||
"inbox_announce",
|
||||
lambda as_actor: _assert_eq(as_actor.id, other.id),
|
||||
lambda _announce: _assert_eq(_announce.id, announce.id),
|
||||
),
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue