Skip to content

Conversation

@aaronjae22
Copy link
Collaborator

Refactor FollowActivity

Following what we did with the LikeActivity, we got the following refactor for FollowActivity:

  • Added target_actor_url and target_actor_data fields for remote actors
  • Updated the clean() method to validate that either local or remote data is provided
  • get_json_ld handle both local and remote actors

image

The first one is a Remote Follow Activity and the second one is a Local Follow Activity.

image

We are able to represent both scenarios, when an Actor follows another Actor within the same server and the other one in which an Actor follows another one from other server.

Closes #72

Adding test data in previously field

previously field in the Actor model should contain historical identifiers or data about the account if it was moved/migrated from another server.

In a real federation scenario, it might look like:

"previously": [
    {
        "type": "Move",
        "object": "https://mastodon.social/users/alice",
        "published": "2023-07-20T00:00:00Z"
    },
    {
        "type": "Move",
        "object": "https://pixelfed.social/users/alice",
        "published": "2022-12-01T00:00:00Z"
    }
]
  • First, we extend the Actor model with a method to handle moves
  • Then, modify the seed command to create some actors with history

Thoughts

During seeding I thought that it doesn't make sense for every Actor to have a previously field filled. The previously field should only be populated for actors that have actually moved or migrated from another server.

So in our seed data, it would be more realistic to:

  1. Have most actors with empty previously (new accounts)
  2. Only give some actors a migration history

With no move:
image

With move history:
image

previously field being display in Actors outboxes when referencing FollowActivities and so on?

I figured that when a FollowActivity or other activities reference an Actor with a migration history, that history should be part of the Actor's JSON-LD representation in those activities.

So when we see a Follow activity in the outbox, if it's following a local actor who has migration history, we’ll see something like the following scenario:

For example, if Bob moved from mastodon.social to our server, and Alice follows Bob, the activity should show:

{
    "type": "Follow",
    "actor": "https://example.com/users/alice",
    "object": {
        "type": "Person",
        "id": "https://example.com/users/bob",
        "preferredUsername": "bob",
        "previously": [
            {
                "type": "Move",
                "object": "https://old-server.com/users/bob",
                "published": "2025-03-20T00:00:00Z"
            }
        ]
    }
}

I believe this is good because it maintains the portability information throughout the activity stream.

This is only for Actors who has moved or migrated from one server to another. I am sure we'll need to add previously data to each Activity when doing migration.

Closes #52

@aaronjae22 aaronjae22 added the models Models related label Mar 21, 2025
@aaronjae22 aaronjae22 requested review from alexeyqu and lisad March 21, 2025 00:03
@aaronjae22 aaronjae22 self-assigned this Mar 21, 2025
# Create some follow relationships
for _ in range(2): # Each actor follows 2 other actors
# Create local follows
for _ in range(1): # Each actor follows 1 local actor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need a for here then? Perhaps we are planning to change this param later?
If so, maybe we can move this to a const or some parameter (if we want to set this dynamically during runtime)?

Copy link
Collaborator Author

@aaronjae22 aaronjae22 Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The seeding in here is just trying to recreate the FollowActivities; as you said, I agree if we move it to a constant.

Maybe we could work in some other way to create the seeding. Any idea is good.

local_follow_count += 1

# Create remote follows
for _ in range(1): # Each actor follows 1 remote actor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto + in similar for loops across the file

username = factory.SelfAttribute('user.username')
full_name = factory.Faker('name')
previously = factory.Dict({})
previously = factory.List([])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC previously is semantically similar to the stack behaviour?
https://swicg.github.io/activitypub-data-portability/lola.html#adding-breadcrumbs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is

created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
previously = models.JSONField(default=dict, null=True, blank=True)
previously = models.JSONField(default=list, null=True, blank=True)
Copy link
Collaborator

@alexeyqu alexeyqu Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we explicitly convert it to an empty list in several places (i.e. self.previously or [] on L77) why don't we set null=False here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Makes sense.

Copy link
Collaborator

@alexeyqu alexeyqu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments -- overall looks good to me, however I'll defer the "does the model fit the proposal?" to someone else 😉

@aaronjae22 aaronjae22 merged commit e306d98 into main Apr 2, 2025
1 check passed
@aaronjae22 aaronjae22 deleted the refactor-follow-activities-and-test-data-previously branch April 2, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models Models related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor FollowActivity to reference another server Add test values to ‘previously’ property

2 participants