Introduce optional unfurling of nsfw content

This commit is contained in:
rinpatch 2019-01-17 11:00:02 +03:00
parent 0256bd2f1d
commit 4d5f15cd42
4 changed files with 14 additions and 4 deletions

View file

@ -212,6 +212,7 @@ curl "http://localhost:4000/api/pleroma/admin/invite_token?admin_token=somerando
* `max_retries`: The maximum number of times a federation job is retried
## Pleroma.Web.Metadata
* `providers`: a list of metadata providers to enable. Providers avalible:
* `providers`: a list of metadata providers to enable. Providers availible:
* Pleroma.Web.Metadata.Providers.OpenGraph
* Pleroma.Web.Metadata.Providers.TwitterCard
* `unfurl_nsfw`: If set to `true` nsfw attachments will be shown in previews

View file

@ -28,4 +28,12 @@ def to_tag(data) do
raise ArgumentError, message: "make_tag invalid args"
end
end
def activity_nsfw?(%{data: %{"object" => %{"tag" => tags}}}) do
if(Pleroma.Config.get([__MODULE__, :unfurl_nsfw], false) == false) do
Enum.any?(tags, fn tag -> tag == "nsfw" end)
else
false
end
end
end

View file

@ -3,6 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.Providers.OpenGraph do
alias Pleroma.Web.Metadata.Providers.Provider
alias Pleroma.Web.Metadata
alias Pleroma.{HTML, Formatter, User}
alias Pleroma.Web.MediaProxy
@ -32,7 +33,7 @@ def build_tags(%{activity: %{data: %{"object" => %{"id" => object_id}}} = activi
], []},
{:meta, [property: "og:type", content: "website"], []}
] ++
if attachments == [] do
if attachments == [] or Metadata.activity_nsfw?(activity) do
[
{:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []},
{:meta, [property: "og:image:width", content: 150], []},

View file

@ -3,13 +3,13 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
alias Pleroma.Web.Metadata.Providers.Provider
alias Pleroma.Web.Metadata
@behaviour Provider
@impl Provider
def build_tags(%{activity: activity}) do
if Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) or
activity.data["object"]["attachment"] == [] do
if Metadata.activity_nsfw?(activity) or activity.data["object"]["attachment"] == [] do
build_tags(nil)
else
case find_first_acceptable_media_type(activity) do