forked from YokaiRick/akkoma
Merge branch 'feature/mrf-always-nsfw' into 'develop'
suppress link previews from posts marked sensitive Closes #865 See merge request pleroma/pleroma!1173
This commit is contained in:
commit
8e9a764dfc
6 changed files with 50 additions and 5 deletions
|
@ -71,6 +71,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Deps: Updated Ecto to 3.0.7
|
- Deps: Updated Ecto to 3.0.7
|
||||||
- Don't ship finmoji by default, they can be installed as an emoji pack
|
- Don't ship finmoji by default, they can be installed as an emoji pack
|
||||||
- Hide deactivated users and their statuses
|
- Hide deactivated users and their statuses
|
||||||
|
- Posts which are marked sensitive or tagged nsfw no longer have link previews.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Added an FTS index on objects. Running `vacuum analyze` and setting a larger `work_mem` is recommended.
|
- Added an FTS index on objects. Running `vacuum analyze` and setting a larger `work_mem` is recommended.
|
||||||
|
|
|
@ -48,10 +48,9 @@ defp check_media_nsfw(
|
||||||
%{host: actor_host} = _actor_info,
|
%{host: actor_host} = _actor_info,
|
||||||
%{
|
%{
|
||||||
"type" => "Create",
|
"type" => "Create",
|
||||||
"object" => %{"attachment" => child_attachment} = child_object
|
"object" => child_object
|
||||||
} = object
|
} = object
|
||||||
)
|
) do
|
||||||
when length(child_attachment) > 0 do
|
|
||||||
object =
|
object =
|
||||||
if Enum.member?(Pleroma.Config.get([:mrf_simple, :media_nsfw]), actor_host) do
|
if Enum.member?(Pleroma.Config.get([:mrf_simple, :media_nsfw]), actor_host) do
|
||||||
tags = (child_object["tag"] || []) ++ ["nsfw"]
|
tags = (child_object["tag"] || []) ++ ["nsfw"]
|
||||||
|
|
|
@ -157,6 +157,7 @@ def post(user, %{"status" => status} = data) do
|
||||||
{to, cc} <- to_for_user_and_mentions(user, mentions, in_reply_to, visibility),
|
{to, cc} <- to_for_user_and_mentions(user, mentions, in_reply_to, visibility),
|
||||||
context <- make_context(in_reply_to),
|
context <- make_context(in_reply_to),
|
||||||
cw <- data["spoiler_text"] || "",
|
cw <- data["spoiler_text"] || "",
|
||||||
|
sensitive <- data["sensitive"] || Enum.member?(tags, {"#nsfw", "nsfw"}),
|
||||||
full_payload <- String.trim(status <> cw),
|
full_payload <- String.trim(status <> cw),
|
||||||
length when length in 1..limit <- String.length(full_payload),
|
length when length in 1..limit <- String.length(full_payload),
|
||||||
object <-
|
object <-
|
||||||
|
@ -169,7 +170,8 @@ def post(user, %{"status" => status} = data) do
|
||||||
in_reply_to,
|
in_reply_to,
|
||||||
tags,
|
tags,
|
||||||
cw,
|
cw,
|
||||||
cc
|
cc,
|
||||||
|
sensitive
|
||||||
),
|
),
|
||||||
object <-
|
object <-
|
||||||
Map.put(
|
Map.put(
|
||||||
|
|
|
@ -223,7 +223,8 @@ def make_note_data(
|
||||||
in_reply_to,
|
in_reply_to,
|
||||||
tags,
|
tags,
|
||||||
cw \\ nil,
|
cw \\ nil,
|
||||||
cc \\ []
|
cc \\ [],
|
||||||
|
sensitive \\ false
|
||||||
) do
|
) do
|
||||||
object = %{
|
object = %{
|
||||||
"type" => "Note",
|
"type" => "Note",
|
||||||
|
@ -231,6 +232,7 @@ def make_note_data(
|
||||||
"cc" => cc,
|
"cc" => cc,
|
||||||
"content" => content_html,
|
"content" => content_html,
|
||||||
"summary" => cw,
|
"summary" => cw,
|
||||||
|
"sensitive" => !Enum.member?(["false", "False", "0", false], sensitive),
|
||||||
"context" => context,
|
"context" => context,
|
||||||
"attachment" => attachments,
|
"attachment" => attachments,
|
||||||
"actor" => actor,
|
"actor" => actor,
|
||||||
|
|
|
@ -24,6 +24,7 @@ defp validate_page_url(_), do: :error
|
||||||
def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) do
|
def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) do
|
||||||
with true <- Pleroma.Config.get([:rich_media, :enabled]),
|
with true <- Pleroma.Config.get([:rich_media, :enabled]),
|
||||||
%Object{} = object <- Object.normalize(activity),
|
%Object{} = object <- Object.normalize(activity),
|
||||||
|
false <- object.data["sensitive"] || false,
|
||||||
{:ok, page_url} <- HTML.extract_first_external_url(object, object.data["content"]),
|
{:ok, page_url} <- HTML.extract_first_external_url(object, object.data["content"]),
|
||||||
:ok <- validate_page_url(page_url),
|
:ok <- validate_page_url(page_url),
|
||||||
{:ok, rich_media} <- Parser.parse(page_url) do
|
{:ok, rich_media} <- Parser.parse(page_url) do
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
defmodule Pleroma.Web.RichMedia.HelpersTest do
|
defmodule Pleroma.Web.RichMedia.HelpersTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
|
alias Pleroma.Object
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
@ -59,4 +60,43 @@ test "crawls valid, complete URLs" do
|
||||||
|
|
||||||
Pleroma.Config.put([:rich_media, :enabled], false)
|
Pleroma.Config.put([:rich_media, :enabled], false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "refuses to crawl URLs from posts marked sensitive" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} =
|
||||||
|
CommonAPI.post(user, %{
|
||||||
|
"status" => "http://example.com/ogp",
|
||||||
|
"sensitive" => true
|
||||||
|
})
|
||||||
|
|
||||||
|
%Object{} = object = Object.normalize(activity)
|
||||||
|
|
||||||
|
assert object.data["sensitive"]
|
||||||
|
|
||||||
|
Pleroma.Config.put([:rich_media, :enabled], true)
|
||||||
|
|
||||||
|
assert %{} = Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||||
|
|
||||||
|
Pleroma.Config.put([:rich_media, :enabled], false)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "refuses to crawl URLs from posts tagged NSFW" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} =
|
||||||
|
CommonAPI.post(user, %{
|
||||||
|
"status" => "http://example.com/ogp #nsfw"
|
||||||
|
})
|
||||||
|
|
||||||
|
%Object{} = object = Object.normalize(activity)
|
||||||
|
|
||||||
|
assert object.data["sensitive"]
|
||||||
|
|
||||||
|
Pleroma.Config.put([:rich_media, :enabled], true)
|
||||||
|
|
||||||
|
assert %{} = Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||||
|
|
||||||
|
Pleroma.Config.put([:rich_media, :enabled], false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue