mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-11 03:39:13 +00:00
Merge branch 'fix/mrf-sample-doc' into 'develop'
Update MRF docs, make sample code actually compile See merge request pleroma/pleroma!2210
This commit is contained in:
commit
3b78695c98
1 changed files with 14 additions and 7 deletions
|
@ -76,16 +76,18 @@ As discussed above, the MRF system is a modular system that supports pluggable p
|
||||||
For example, here is a sample policy module which rewrites all messages to "new message content":
|
For example, here is a sample policy module which rewrites all messages to "new message content":
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
# This is a sample MRF policy which rewrites all Notes to have "new message
|
defmodule Pleroma.Web.ActivityPub.MRF.RewritePolicy do
|
||||||
# content."
|
@moduledoc "MRF policy which rewrites all Notes to have 'new message content'."
|
||||||
defmodule Site.RewritePolicy do
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
@behavior Pleroma.Web.ActivityPub.MRF
|
|
||||||
|
|
||||||
# Catch messages which contain Note objects with actual data to filter.
|
# Catch messages which contain Note objects with actual data to filter.
|
||||||
# Capture the object as `object`, the message content as `content` and the
|
# Capture the object as `object`, the message content as `content` and the
|
||||||
# message itself as `message`.
|
# message itself as `message`.
|
||||||
@impl true
|
@impl true
|
||||||
def filter(%{"type" => "Create", "object" => {"type" => "Note", "content" => content} = object} = message)
|
def filter(
|
||||||
|
%{"type" => "Create", "object" => %{"type" => "Note", "content" => content} = object} =
|
||||||
|
message
|
||||||
|
)
|
||||||
when is_binary(content) do
|
when is_binary(content) do
|
||||||
# Subject / CW is stored as summary instead of `name` like other AS2 objects
|
# Subject / CW is stored as summary instead of `name` like other AS2 objects
|
||||||
# because of Mastodon doing it that way.
|
# because of Mastodon doing it that way.
|
||||||
|
@ -108,16 +110,21 @@ defmodule Site.RewritePolicy do
|
||||||
# Let all other messages through without modifying them.
|
# Let all other messages through without modifying them.
|
||||||
@impl true
|
@impl true
|
||||||
def filter(message), do: {:ok, message}
|
def filter(message), do: {:ok, message}
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def describe do
|
||||||
|
{:ok, %{mrf_sample: %{content: "new message content"}}}`
|
||||||
|
end
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
If you save this file as `lib/site/mrf/rewrite_policy.ex`, it will be included when you next rebuild Pleroma. You can enable it in the configuration like so:
|
If you save this file as `lib/pleroma/web/activity_pub/mrf/rewrite_policy.ex`, it will be included when you next rebuild Pleroma. You can enable it in the configuration like so:
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
config :pleroma, :instance,
|
config :pleroma, :instance,
|
||||||
rewrite_policy: [
|
rewrite_policy: [
|
||||||
Pleroma.Web.ActivityPub.MRF.SimplePolicy,
|
Pleroma.Web.ActivityPub.MRF.SimplePolicy,
|
||||||
Site.RewritePolicy
|
Pleroma.Web.ActivityPub.MRF.RewritePolicy
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue