Commit 3cc3539a authored by Yábir García's avatar Yábir García

Federate statuses to followers

parent 46f0cecb
......@@ -6,6 +6,7 @@ from typing import List
from models.status import Status
from models.user import (User, UserProfile)
from models.notification import Notification, notification_types
from models.followers import FollowerRelation
from tasks.config import huey
......@@ -14,7 +15,9 @@ from managers.notification_manager import NotificationManager
from activityPub.create_activities import generate_create_note
from activityPub.identity_manager import ActivityPubId
from activityPub.activitypub import push_to_remote_actor
@huey.task(retries=3, retry_delay=5)
def spread_status(status: Status, mentions: List[str], ap_spread: bool = False) -> None:
Given a status we have to:
......@@ -30,7 +33,7 @@ def spread_status(status: Status, mentions: List[str], ap_spread: bool = False)
r = redis.StrictRedis(host=os.environ.get('REDIS_HOST', 'localhost'))
time = status.created_at.timestamp()
#Populate all the followers timelines
json_file = json.dumps(status.to_json(), default=str)
for follower in status.user.followers():
......@@ -58,14 +61,36 @@ def spread_status(status: Status, mentions: List[str], ap_spread: bool = False)
# First we check that there is an user with this username
# and then we get it's profile
if not target_user.is_remote:
# Spread via AP
if ap_spread:
create = generate_create_note(status, remote)
# Can this be the coolest var in the project?
# it's just a set of addresses. Here I'm taking care
# to minimize the number of requests to external actors
# targeting shared inboxes (like a pro, look at me mom)
targets_spotted = set()
remote_followers = (UserProfile
.join(FollowerRelation, on=FollowerRelation.user)
.where( (UserProfile.is_remote == True) & (FollowerRelation.follows == status.user) ))
for follower in remote_followers:
if follower.public_inbox:
# We're ready mike, drop cargo to the target
for inbox in targets_spotted:
push_to_remote_actor(inbox, create.to_json())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment