From f53cdabcdf5e64c862e0532e6d5ad26666e9c83f Mon Sep 17 00:00:00 2001 From: eal Date: Sat, 18 Nov 2017 16:30:18 +0200 Subject: Add #nsfw tag if sensitive content bit is set --- lib/pleroma/formatter.ex | 3 ++- lib/pleroma/web/common_api/common_api.ex | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 27e2adc16..fbcbca979 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -7,9 +7,10 @@ defmodule Pleroma.Formatter do end @tag_regex ~r/\#\w+/u - def parse_tags(text) do + def parse_tags(text, data \\ %{}) do Regex.scan(@tag_regex, text) |> Enum.map(fn (["#" <> tag = full_tag]) -> {full_tag, String.downcase(tag)} end) + |> (fn map -> if data["sensitive"], do: [{"#nsfw", "nsfw"}] ++ map, else: map end).() end def parse_mentions(text) do diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 9ae7b095a..9bc7f2ce6 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -55,7 +55,7 @@ defmodule Pleroma.Web.CommonAPI do mentions <- Formatter.parse_mentions(status), inReplyTo <- get_replied_to_activity(data["in_reply_to_status_id"]), to <- to_for_user_and_mentions(user, mentions, inReplyTo), - tags <- Formatter.parse_tags(status), + tags <- Formatter.parse_tags(status, data), content_html <- make_content_html(status, mentions, attachments, tags), context <- make_context(inReplyTo), cw <- data["spoiler_text"], -- cgit v1.2.3