Skip to content

Federate reports#3188

Open
mouse-reeve wants to merge 27 commits intomainfrom
federate-reports
Open

Federate reports#3188
mouse-reeve wants to merge 27 commits intomainfrom
federate-reports

Conversation

@mouse-reeve
Copy link
Copy Markdown
Member

@mouse-reeve mouse-reeve commented Jan 3, 2024

Reports should be sent (if the user wants) to the home instance for remote users. I'm using mastodon's Flag activity as a template: https://docs.joinmastodon.org/spec/activitypub/#Flag

Fixes #962

Components:

  • Fix the report model so that user means the user doing the reporting, not the reported user
  • Make the report model activitypub-y
    • Produce the easy parts of the activitypub object
    • Get the "objects" part of the Flag activity in place
  • Allow users to opt out of federating reports
  • Broadcast reports
  • Receive broadcasted reports
  • Test between bookwyrm instances
  • Test between bookwyrm and mastodon instances

@mouse-reeve mouse-reeve marked this pull request as ready for review August 24, 2024 23:54
def object(self):
"""Generate a list of reported objects in a format Mastodon will like"""
items = [self.reported_user.remote_id]
if self.statuses:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When I test this self.statuses is always bookwyrm.Status.None here. So the status is never sent to Mastodon. However statuses obviously isn't empty because in the BookWyrm admin interface I can see it. So I have no idea what is going on but it's weird and means statuses aren't passed through to federated servers with the report.

@mouse-reeve
Copy link
Copy Markdown
Member Author

@hughrun Would you be able to take another look at this? I haven't meaningfully changed anything besides resolving merge conflicts, but I'm puzzled as to why Mastodon wouldn't be able to parse it. This is an Activity from my local:

{
  "id": "https://--.ngrok-free.app/settings/reports/4",
  "type": "Flag",
  "actor": "https://--.ngrok-free.app/user/rat2",
  "object": [
    "https://bookwyrm.social/user/mouse",
    "https://bookwyrm.social/user/mouse/review/8092282"
  ],
  "to": "https://bookwyrm.social/user/mouse",
  "links": [],
  "content": "",
  "@context": [
    "https://www.w3.org/ns/activitystreams",
    {
      "Hashtag": "as:Hashtag"
    }
  ]
}

And it seems to match the expected format according to the docs:

{
  "@context": "https://www.w3.org/ns/activitystreams",
  "id": "https://mastodon.example/ccb4f39a-506a-490e-9a8c-71831c7713a4",
  "type": "Flag",
  "actor": "https://mastodon.example/actor",
  "content": "Please take a look at this user and their posts",
  "object": [
    "https://example.com/users/1",
    "https://example.com/posts/380590",
    "https://example.com/posts/380591"
  ],
  "to": "https://example.com/users/1"
}

@hughrun
Copy link
Copy Markdown
Member

hughrun commented Feb 16, 2026

Hi @mouse-reeve I took another look at this.

There is a problem, but I think I misunderstood what it was earlier.

First of all, reports are definitely sent TO Mastodon if you report a user from Mastodon.

However, Mastodon is not sending Flag activities according to your example above. Notably and most importantly, despite what their docs say, Mastodon doesn't set a to field in Flag activities:

{
    "@context": "https://www.w3.org/ns/activitystreams",
    "id": "https://ausglam.space/bd5b93f7-177c-4418-abc1-7b703fe508fc",
    "type": "Flag",
    "actor": "https://ausglam.space/actor",
    "content": "testing 123",
    "object": [
        "https://example.com/user/h",
        "https://example.com/user/h/status/2"
    ]
}

In this regard they are kind of compliant with the actual spec, but also noncompliant because they're sending object as an array which frankly makes no sense.

The fact that there's a compulsory field missing basically breaks everything: reports are received from Mastodon, but I can't even load the Reports page because none of the external Report objects have user ids.

I do wonder a bit about the sense of sending a report about a user "to" that user's inbox address, but I guess if we have the correct logic, it won't actually hit their feed for them to see it.

As you can see above, Mastodon sends the user as the first item in object. But it also sends the object to the user inbox. So we have two options I think:

  1. Give to a default value of None and do something funky I can't work out how to do in terms of mapping reported_user to the first value in "object" if "to" is None.
  2. Grab request.path right up top in activitypub.parse and run some kind of check to see whether there is a missing "to" field, and swap the request path in if it's missing.

There's probably a third less hacky option but those are two off the top of my head.

As a much less problematic issue, I noticed that reports from external servers have a message that they were not reported to an external server which, uh obviously not so maybe that needs to be adjusted.

@hughrun hughrun added activitypub safety To do with privacy, user blocking, spoiler alerts etc labels Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

activitypub safety To do with privacy, user blocking, spoiler alerts etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reports should create Flag activities

2 participants