Add ForceMentionsInContentPolicy
Even though latest PleromaFE supports displaying these properly, mobile apps still exist, so I think we should offer a workaround to those who want it.
This commit is contained in:
parent
70fbd1f09e
commit
a02cfd7f52
7 changed files with 221 additions and 20 deletions
79
test/fixtures/soapbox_no_mentions_in_content.json
vendored
Normal file
79
test/fixtures/soapbox_no_mentions_in_content.json
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://gleasonator.com/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
],
|
||||
"actor": "https://gleasonator.com/users/alex",
|
||||
"attachment": [
|
||||
{
|
||||
"blurhash": "b15#-6_3~l%eDkNraAM#HYMf",
|
||||
"height": 2147,
|
||||
"mediaType": "image/png",
|
||||
"name": "",
|
||||
"type": "Document",
|
||||
"url": "https://media.gleasonator.com/2df1c9cc26c35028db65848143971da0c5a6e04dbd423b194bb018b6c601db9b.png",
|
||||
"width": 966
|
||||
},
|
||||
{
|
||||
"blurhash": "b168EX~q~W-;DiM{VtIUD%Io",
|
||||
"height": 2147,
|
||||
"mediaType": "image/png",
|
||||
"name": "",
|
||||
"type": "Document",
|
||||
"url": "https://media.gleasonator.com/22b42b4cddc1aecc7e2d3dc20bcdd66d5c4e44c2bef119de948e95a587e36b66.png",
|
||||
"width": 966
|
||||
}
|
||||
],
|
||||
"attributedTo": "https://gleasonator.com/users/alex",
|
||||
"cc": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"content": "<p>Haha yeah, you can control who you reply to.</p>",
|
||||
"context": "https://gleasonator.com/contexts/ba6c8bd9-ac4d-479e-9bd9-5bf570068ae7",
|
||||
"conversation": "https://gleasonator.com/contexts/ba6c8bd9-ac4d-479e-9bd9-5bf570068ae7",
|
||||
"id": "https://gleasonator.com/objects/02af65fe-04f8-46bc-9b1e-31dfe76eaffd",
|
||||
"inReplyTo": "https://shitposter.club/objects/c686d811-4368-48e1-ba11-82c129f93165",
|
||||
"published": "2022-01-19T03:37:35.976545Z",
|
||||
"sensitive": false,
|
||||
"source": "Haha yeah, you can control who you reply to.",
|
||||
"summary": "",
|
||||
"tag": [
|
||||
{
|
||||
"href": "https://lain.com/users/lain",
|
||||
"name": "@lain@lain.com",
|
||||
"type": "Mention"
|
||||
},
|
||||
{
|
||||
"href": "https://shitposter.club/users/coolboymew",
|
||||
"name": "@coolboymew@shitposter.club",
|
||||
"type": "Mention"
|
||||
},
|
||||
{
|
||||
"href": "https://shitposter.club/users/dielan",
|
||||
"name": "@dielan@shitposter.club",
|
||||
"type": "Mention"
|
||||
},
|
||||
{
|
||||
"href": "https://tuusin.misono-ya.info/users/hakui",
|
||||
"name": "@hakui@tuusin.misono-ya.info",
|
||||
"type": "Mention"
|
||||
},
|
||||
{
|
||||
"href": "https://xyzzy.link/users/fence",
|
||||
"name": "@fence@xyzzy.link",
|
||||
"type": "Mention"
|
||||
}
|
||||
],
|
||||
"to": [
|
||||
"https://shitposter.club/users/dielan",
|
||||
"https://gleasonator.com/users/alex/followers",
|
||||
"https://shitposter.club/users/coolboymew",
|
||||
"https://xyzzy.link/users/fence",
|
||||
"https://tuusin.misono-ya.info/users/hakui",
|
||||
"https://lain.com/users/lain"
|
||||
],
|
||||
"type": "Note"
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContentTest do
|
||||
alias Pleroma.Web.ActivityPub.MRF.ForceMentionsInContent
|
||||
import Pleroma.Factory
|
||||
use Pleroma.DataCase
|
||||
|
||||
test "adds mentions to post content" do
|
||||
users = %{
|
||||
"lain@lain.com" => "https://lain.com/users/lain",
|
||||
"coolboymew@shitposter.club" => "https://shitposter.club/users/coolboymew",
|
||||
"dielan@shitposter.club" => "https://shitposter.club/users/dielan",
|
||||
"hakui@tuusin.misono-ya.info" => "https://tuusin.misono-ya.info/users/hakui",
|
||||
"fence@xyzzy.link" => "https://xyzzy.link/users/fence"
|
||||
}
|
||||
|
||||
Enum.each(users, fn {nickname, ap_id} ->
|
||||
insert(:user, ap_id: ap_id, nickname: nickname, local: false)
|
||||
end)
|
||||
|
||||
object = File.read!("test/fixtures/soapbox_no_mentions_in_content.json") |> Jason.decode!()
|
||||
|
||||
activity = %{
|
||||
"type" => "Create",
|
||||
"actor" => "https://gleasonator.com/users/alex",
|
||||
"object" => object
|
||||
}
|
||||
|
||||
{:ok, %{"object" => %{"content" => filtered}}} = ForceMentionsInContent.filter(activity)
|
||||
Enum.each(users, fn {nickname, _} -> assert filtered =~ nickname end)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue