Browse Source

also suppress link previews from posts marked #nsfw

tags/v1.1.4
William Pitcock 5 years ago
parent
commit
dc08159538
3 changed files with 26 additions and 3 deletions
  1. +3
    -1
      lib/pleroma/web/common_api/common_api.ex
  2. +3
    -1
      lib/pleroma/web/common_api/utils.ex
  3. +20
    -1
      test/web/rich_media/helpers_test.exs

+ 3
- 1
lib/pleroma/web/common_api/common_api.ex View File

@@ -157,6 +157,7 @@ defmodule Pleroma.Web.CommonAPI do
{to, cc} <- to_for_user_and_mentions(user, mentions, in_reply_to, visibility),
context <- make_context(in_reply_to),
cw <- data["spoiler_text"] || "",
sensitive <- data["sensitive"] || Enum.member?(tags, {"#nsfw", "nsfw"}),
full_payload <- String.trim(status <> cw),
length when length in 1..limit <- String.length(full_payload),
object <-
@@ -169,7 +170,8 @@ defmodule Pleroma.Web.CommonAPI do
in_reply_to,
tags,
cw,
cc
cc,
sensitive
),
object <-
Map.put(


+ 3
- 1
lib/pleroma/web/common_api/utils.ex View File

@@ -223,7 +223,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do
in_reply_to,
tags,
cw \\ nil,
cc \\ []
cc \\ [],
sensitive \\ false
) do
object = %{
"type" => "Note",
@@ -231,6 +232,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
"cc" => cc,
"content" => content_html,
"summary" => cw,
"sensitive" => sensitive,
"context" => context,
"attachment" => attachments,
"actor" => actor,


+ 20
- 1
test/web/rich_media/helpers_test.exs View File

@@ -67,7 +67,26 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
{:ok, activity} =
CommonAPI.post(user, %{
"status" => "http://example.com/ogp",
"spoiler_text" => "."
"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)


Loading…
Cancel
Save