Skip to content

Commit

Permalink
relay: fanout public posts to relays
Browse files Browse the repository at this point in the history
  • Loading branch information
alphatownsman committed Jan 2, 2024
1 parent 9f48467 commit 4bf9ed5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions activities/models/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
from core.snowflake import Snowflake
from stator.exceptions import TryAgainLater
from stator.models import State, StateField, StateGraph, StatorModel
from users.models import relay
from users.models.follow import FollowStates
from users.models.hashtag_follow import HashtagFollow
from users.models.identity import Identity, IdentityStates
from users.models.inbox_message import InboxMessage
from users.models.relay import Relay
from users.models.system_actor import SystemActor

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -77,6 +79,30 @@ def targets_fan_out(cls, post: "Post", type_: str) -> None:
type=type_,
subject_post=post,
)
cls.fan_out_to_relay(post, type_)

@classmethod
def fan_out_to_relay(cls, post: "Post", type_: str) -> None:
if not post.local or post.visibility != Post.Visibilities.public:
return
relay_uris = Relay.active_inbox_uris()
if not relay_uris:
return
obj = None
match type_:
case FanOut.Types.post:
obj = canonicalise(post.to_create_ap())
case FanOut.Types.post_edited:
obj = canonicalise(post.to_update_ap())
case FanOut.Types.post_deleted:
obj = canonicalise(post.to_delete_ap())
if not obj:
return
for uri in relay_uris:
try:
post.author.signed_request(method="post", uri=uri, body=obj)
except Exception as e:
logger.warning(f"Error sending relay: {uri} {e}")

@classmethod
def handle_new(cls, instance: "Post"):
Expand Down

0 comments on commit 4bf9ed5

Please sign in to comment.