WIP: Move the remaining activity creation paths onto the pipeline #7988

Draft
lambadalambda wants to merge 48 commits from refactor/move-to-pipeline into develop

Local posts, unfollows, reports, scrobbles and account moves were still created through ActivityPub.insert and notified/streamed from inside their own transaction. This moves them onto Pipeline.common_pipeline and removes ActivityPub.create/2, unfollow/4, flag/1, listen/1, move/3 and notify_and_stream/1.

Fixed along the way:

  • side effects stream activities after the transaction commits; the streamer processes use their own DB connections and could not see uncommitted rows, so websocket clients got different data than the timeline API
  • conversations and participations are created for incoming direct messages (only the legacy path did this)
  • application is present in the POST /api/v1/statuses response (the generator map was built with atom keys)
  • incoming Move activities pass the inbox guard again

Behaviour changes worth a look:

  • local hashtags are stored as AS2 Hashtag tags plus the plain string copy the validator adds; StatusView.build_tags handles both
  • posts without recipients (direct messages without mentions) get their author in cc, and direct objects carry directMessage
  • replies and quotes counts only count public and unlisted posts for remote replies too (already the case for local ones)
  • the Undo of a Follow is stored with the Follow's id; prepare_activity embeds the Follow when federating
  • expires_in with expiring posts disabled is rejected by the draft, since the pipeline does not roll back on persist errors
  • Audio objects with scrobble fields no longer require an attachment; the Audio validator knows the scrobble fields
  • directMessage is an internal field now (stripped from incoming payloads and outgoing objects), objects don't federate bcc/bto
  • tests that posted as remote users through CommonAPI.post use the new post_as_remote/2 helper, since the pipeline validates that the actor owns the object

Not done here, worth follow-ups: the pipeline does not roll back the transaction when a stage after persist fails; Utils.update_activity_visibility still edits activities in place; nested pipelines (object creation, group boosts) run their after-transaction hooks inside the outer transaction.

Local posts, unfollows, reports, scrobbles and account moves were still created through `ActivityPub.insert` and notified/streamed from inside their own transaction. This moves them onto `Pipeline.common_pipeline` and removes `ActivityPub.create/2`, `unfollow/4`, `flag/1`, `listen/1`, `move/3` and `notify_and_stream/1`. Fixed along the way: - side effects stream activities after the transaction commits; the streamer processes use their own DB connections and could not see uncommitted rows, so websocket clients got different data than the timeline API - conversations and participations are created for incoming direct messages (only the legacy path did this) - `application` is present in the `POST /api/v1/statuses` response (the generator map was built with atom keys) - incoming `Move` activities pass the inbox guard again Behaviour changes worth a look: - local hashtags are stored as AS2 `Hashtag` tags plus the plain string copy the validator adds; `StatusView.build_tags` handles both - posts without recipients (direct messages without mentions) get their author in `cc`, and direct objects carry `directMessage` - replies and quotes counts only count public and unlisted posts for remote replies too (already the case for local ones) - the Undo of a Follow is stored with the Follow's id; `prepare_activity` embeds the Follow when federating - `expires_in` with expiring posts disabled is rejected by the draft, since the pipeline does not roll back on persist errors - `Audio` objects with scrobble fields no longer require an attachment; the Audio validator knows the scrobble fields - `directMessage` is an internal field now (stripped from incoming payloads and outgoing objects), objects don't federate `bcc`/`bto` - tests that posted as remote users through `CommonAPI.post` use the new `post_as_remote/2` helper, since the pipeline validates that the actor owns the object Not done here, worth follow-ups: the pipeline does not roll back the transaction when a stage after persist fails; `Utils.update_activity_visibility` still edits activities in place; nested pipelines (object creation, group boosts) run their after-transaction hooks inside the outer transaction.
Create, Announce and Delete side effects queue stream_out calls in the
pipeline meta and run them from handle_after_transaction, matching how
notifications and chat streamables are already handled.
The Create side effect now creates or bumps the conversation of direct
messages, marks it read for the author and streams the participations
after the transaction. This was only done by the legacy
ActivityPub.notify_and_stream path, so remote DMs never got
participations. The Update side effect uses the same helper instead of
calling notify_and_stream inline.
CommonAPI.post/2 now builds a Create activity from the draft and runs it
through Pipeline.common_pipeline, replacing ActivityPub.create/2 (which
inserted, notified and streamed inside its own transaction).

To keep local posts intact through the validators:
- Builder.note sets the object id and published date and emits AS2
  Hashtag tags; StatusView.build_tags understands them
- the Create and status object validators keep the local-only fields
  generator, listMessage, directMessage and published
- fix_emoji keeps the emoji map of locally built objects
- posts without recipients (direct messages without mentions) are
  addressed to their author, and direct objects carry directMessage
- the expiry check moved to the draft, since the pipeline does not
  roll back on persist errors

Replies and quotes now only count public and unlisted posts on the
remote path too. Tests posting as remote users go through the new
post_as_remote/2 helper, since local posting validates the actor owns
the object.
CommonAPI.undo_follow/2 builds the Undo with Builder.undo and runs it
through the pipeline; the Undo side effect marks the Follow as
cancelled. Incoming Undo Follow activities use the pipeline like the
other Undo types. The stored Undo references the Follow by id, so
prepare_activity embeds the Follow again for federation. Removes
ActivityPub.unfollow/4 and Utils.make_unfollow_data/4.
Adds Builder.flag/1, a FlagValidator and a Flag side effect that
notifies moderators, triggers the report webhooks and sends the report
emails. CommonAPI.report/2 and incoming Flag activities use the
pipeline; ActivityPub.flag/1 is removed.
Listen activities are validated like Create activities and their Audio
object with the Audio validator, which learned the scrobble fields and
no longer requires an attachment for Audio. Removes ActivityPub.listen/1,
Utils.make_listen_data/2 and CommonAPI.Utils.maybe_add_list_data/3.
Statuses of local reports are linked by notice, statuses of forwarded
reports by their id, as before.
Adds Builder.move/2, a MoveValidator and a Move side effect that
notifies the followers and schedules moving the follows.
CommonAPI.move/2 and incoming Move activities use the pipeline;
ActivityPub.move/3 and the legacy notify_and_stream/1 are removed.
Move is added to the accepted activity types, so incoming Moves pass
the inbox guard again.
The Create and status object validators accept directMessage for local
posts, so remote actors could have set it to make public posts look
direct. It is now an internal field like listMessage and generator.
Objects carry AS2 Hashtag tags and their plain copies; the names are
downcased and deduplicated instead of listed twice.
List posts carry the list in the object's bcc now.
Validation errors reach the controllers as changesets, which the
fallback controller renders; the status controller delegates them.
Audio objects with scrobble fields are the only Audio objects without
attachments; the length is stored as given.
The Update side effect returned {:ok, ...} when the updater failed.
test: assert the stored scrobble fields in the object view test
Some checks failed
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline failed
610a97e0c1
The assertions compared against the activity data, where the fields
never were, so both sides were nil.
fix: render disclosed applications without a website
Some checks failed
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline is pending
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline was canceled
b3f325e25c
fix: preserve poll reply counts when deleting votes
Some checks failed
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline is pending
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline was canceled
ad93070154
fix: refresh cached objects after response counter updates
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
516b95ed28
fix: normalize Listen hashtags before validation
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
286b0c6547
Merge branch 'develop' into refactor/move-to-pipeline
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
0ade8739a0
Merge remote-tracking branch 'origin/develop' into refactor/move-to-pipeline
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline was successful
02191c889d
# Conflicts:
#	lib/pleroma/web/activity_pub/activity_pub.ex
#	lib/pleroma/web/activity_pub/object_validator.ex
fix(feed): tolerate a missing date in the publish time fallback
Some checks failed
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline failed
ci/woodpecker/pr/unit-testing-elixir-1.19 unknown status
ci/woodpecker/pr/unit-testing-elixir-1.17 unknown status
a27e3c26de
Author
Owner

Merged develop (02191c889) and added C2S hardening (19 commits up to a27e3c26d). C2S already used the pipeline, but rules that lived only in CommonAPI/the Builder were skipped. They now live in the validators, so every path gets them: poll votes (no double, author, closed or invisible votes), pins only of own public posts, local Updates validated with server-built history, poll limits, reply/quote visibility, attachments must be own uploads. C2S objects get a normalization step (server sets published/id/context; client edit history, replies, source, counters dropped; contentMap counted; HTML scrubbed; emoji names checked). Feeds scrub content and survive a missing date. Regression tests in activity_pub_controller_c2s_test.exs. Full suite green except the known local exiftool/table-list failures.

Merged develop (02191c889) and added C2S hardening (19 commits up to a27e3c26d). C2S already used the pipeline, but rules that lived only in CommonAPI/the Builder were skipped. They now live in the validators, so every path gets them: poll votes (no double, author, closed or invisible votes), pins only of own public posts, local Updates validated with server-built history, poll limits, reply/quote visibility, attachments must be own uploads. C2S objects get a normalization step (server sets published/id/context; client edit history, replies, source, counters dropped; contentMap counted; HTML scrubbed; emoji names checked). Feeds scrub content and survive a missing date. Regression tests in activity_pub_controller_c2s_test.exs. Full suite green except the known local exiftool/table-list failures.
Some checks failed
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline failed
ci/woodpecker/pr/unit-testing-elixir-1.19 unknown status
ci/woodpecker/pr/unit-testing-elixir-1.17 unknown status
This pull request has changes conflicting with the target branch.
  • lib/pleroma/web/activity_pub/transmogrifier.ex
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin refactor/move-to-pipeline:refactor/move-to-pipeline
git switch refactor/move-to-pipeline

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch develop
git merge --no-ff refactor/move-to-pipeline
git switch refactor/move-to-pipeline
git rebase develop
git switch develop
git merge --ff-only refactor/move-to-pipeline
git switch refactor/move-to-pipeline
git rebase develop
git switch develop
git merge --no-ff refactor/move-to-pipeline
git switch develop
git merge --squash refactor/move-to-pipeline
git switch develop
git merge --ff-only refactor/move-to-pipeline
git switch develop
git merge refactor/move-to-pipeline
git push origin develop
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pleroma/pleroma!7988
No description provided.