Skip to content

Commit

Permalink
Add FediverseNode methods unlike_object and unannounce_object
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Ernst authored and jernst committed Oct 18, 2024
1 parent ac63081 commit e402676
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/feditest/nodedrivers/fallback/fediverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,27 @@ def like_object(self, actor_acct_uri: str, object_uri: str) -> None:
+ ' and hit return when done.')


# Python 3.12 @override
def unlike_object(self, actor_acct_uri: str, object_uri: str) -> None:
prompt_user(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" unlike the object at "{ object_uri }"'
+ ' and hit return when done.')


# Python 3.12 @override
def announce_object(self, actor_acct_uri: str, object_uri: str) -> None:
prompt_user(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" announce/reblog/boost the object at "{ object_uri }"'
+ ' and hit return when done.')


# Python 3.12 @override
def unannounce_object(self, actor_acct_uri: str, object_uri: str) -> None:
prompt_user(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" unannounce/undo reblog/undo boost the object at "{ object_uri }"'
+ ' and hit return when done.')


# Python 3.12 @override
def actor_has_received_object(self, actor_acct_uri: str, object_uri: str) -> str | None:
answer = prompt_user(
Expand Down
30 changes: 30 additions & 0 deletions src/feditest/nodedrivers/mastodon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ def like_object(self, object_uri: str) -> None:
raise ValueError(f'Cannot find Note on { self }: "{ object_uri }"')


def unlike_object(self, object_uri: str) -> None:
if note := self._find_note_dict_by_uri(object_uri):
note_id = note['id']
response = self.http_post(f'/api/v1/statuses/{ note_id }/unfavourite')
return response
raise ValueError(f'Cannot find Note on { self }: "{ object_uri }"')


def announce_object(self, object_uri: str) -> None:
if note := self._find_note_dict_by_uri(object_uri):
note_id = note['id']
Expand All @@ -329,6 +337,14 @@ def announce_object(self, object_uri: str) -> None:
raise ValueError(f'Cannot find Note on { self }: "{ object_uri }"')


def unannounce_object(self, object_uri: str) -> None:
if note := self._find_note_dict_by_uri(object_uri):
note_id = note['id']
response = self.http_post(f'/api/v1/statuses/{ note_id }/unreblog')
return response
raise ValueError(f'Cannot find Note on { self }: "{ object_uri }"')


def actor_has_received_object(self, object_uri: str) -> dict[str, Any]:
# Depending on how the Note is addressed and follow status, Mastodon puts it into the Home timeline or only
# into notifications.
Expand Down Expand Up @@ -690,13 +706,27 @@ def like_object(self, actor_acct_uri: str, object_uri: str) -> None:
self._run_poor_mans_cron()


# Python 3.12 @override
def unlike_object(self, actor_acct_uri: str, object_uri: str) -> None:
mastodon_client = self._get_mastodon_client_by_actor_acct_uri(actor_acct_uri)
mastodon_client.unlike_object(object_uri)
self._run_poor_mans_cron()


# Python 3.12 @override
def announce_object(self, actor_acct_uri: str, object_uri: str) -> None:
mastodon_client = self._get_mastodon_client_by_actor_acct_uri(actor_acct_uri)
mastodon_client.announce_object(object_uri)
self._run_poor_mans_cron()


# Python 3.12 @override
def unannounce_object(self, actor_acct_uri: str, object_uri: str) -> None:
mastodon_client = self._get_mastodon_client_by_actor_acct_uri(actor_acct_uri)
mastodon_client.unannounce_object(object_uri)
self._run_poor_mans_cron()


# Python 3.12 @override
def actor_has_received_object(self, actor_acct_uri: str, object_uri: str) -> str | None:
mastodon_client = self._get_mastodon_client_by_actor_acct_uri(actor_acct_uri)
Expand Down
14 changes: 14 additions & 0 deletions src/feditest/protocols/fediverse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,27 @@ def like_object(self, actor_acct_uri: str, object_uri: str) -> None:
raise NotImplementedByNodeError(self, FediverseNode.like_object)


def unlike_object(self, actor_acct_uri: str, object_uri: str) -> None:
"""
Unlike an object (like a note) that was previously liked
"""
raise NotImplementedByNodeError(self, FediverseNode.unlike_object)


def announce_object(self, actor_acct_uri: str, object_uri: str) -> None:
"""
Announce an object (boost, reblog).
"""
raise NotImplementedByNodeError(self, FediverseNode.announce_object)


def unannounce_object(self, actor_acct_uri: str, object_uri: str) -> None:
"""
Undo a previous announce of an object (boost, reblog).
"""
raise NotImplementedByNodeError(self, FediverseNode.unannounce_object)


def actor_has_received_object(self, actor_acct_uri: str, object_uri: str) -> str | None:
"""
If the object at object_uri has arrived with the Actor at actor_acct_uri, return the content
Expand Down

0 comments on commit e402676

Please sign in to comment.