# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Metadata do
alias Phoenix.HTML
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
+ def activity_nsfw?(%{data: %{"sensitive" => sensitive}}) do
+ Pleroma.Config.get([__MODULE__, :unfurl_nsfw], false) == false and sensitive
+ end
+
+ def activity_nsfw?(_) do
+ false
end
end
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Metadata.Providers.OpenGraph do
alias Pleroma.Web.Metadata.Providers.Provider
alias Pleroma.Web.Metadata
@impl Provider
def build_tags(%{
- activity: %{data: %{"object" => %{"id" => object_id}}} = activity,
+ object: object,
user: user
}) do
- attachments = build_attachments(activity)
- scrubbed_content = scrub_html_and_truncate(activity)
+ attachments = build_attachments(object)
+ scrubbed_content = scrub_html_and_truncate(object)
# Zero width space
content =
if scrubbed_content != "" and scrubbed_content != "\u200B" do
property: "og:title",
content: "#{user.name}" <> content
], []},
- {:meta, [property: "og:url", content: object_id], []},
+ {:meta, [property: "og:url", content: object.data["id"]], []},
{:meta,
[
property: "og:description",
], []},
{:meta, [property: "og:type", content: "website"], []}
] ++
- if attachments == [] or Metadata.activity_nsfw?(activity) do
+ if attachments == [] or Metadata.activity_nsfw?(object) do
[
{:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []},
{:meta, [property: "og:image:width", content: 150], []},
end
end
- defp build_attachments(%{data: %{"object" => %{"attachment" => attachments}}} = _activity) do
+ defp build_attachments(%{data: %{"attachment" => attachments}}) do
Enum.reduce(attachments, [], fn attachment, acc ->
rendered_tags =
Enum.reduce(attachment["url"], [], fn url, acc ->
end)
end
- defp scrub_html_and_truncate(%{data: %{"object" => %{"content" => content}}} = activity) do
+ defp scrub_html_and_truncate(%{data: %{"content" => content}} = object) do
content
# html content comes from DB already encoded, decode first and scrub after
|> HtmlEntities.decode()
|> String.replace(~r/<br\s?\/?>/, " ")
- |> HTML.get_cached_stripped_html_for_object(activity, __MODULE__)
+ |> HTML.get_cached_stripped_html_for_object(object, __MODULE__)
|> Formatter.truncate()
end
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Metadata.Providers.Provider do
@callback build_tags(map()) :: list()
end
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# 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 Metadata.activity_nsfw?(activity) or activity.data["object"]["attachment"] == [] do
+ def build_tags(%{object: object}) do
+ if Metadata.activity_nsfw?(object) or object.data["attachment"] == [] do
build_tags(nil)
else
- case find_first_acceptable_media_type(activity) do
+ case find_first_acceptable_media_type(object) do
"image" ->
[{:meta, [property: "twitter:card", content: "summary_large_image"], []}]
[{:meta, [property: "twitter:card", content: "summary"], []}]
end
- def find_first_acceptable_media_type(%{data: %{"object" => %{"attachment" => attachment}}}) do
+ def find_first_acceptable_media_type(%{data: %{"attachment" => attachment}}) do
Enum.find_value(attachment, fn attachment ->
Enum.find_value(attachment["url"], fn url ->
Enum.find(["image", "audio", "video"], fn media_type ->
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
case format = get_format(conn) do
"html" ->
- # Only Create actvities have a map at object
- if is_map(activity.data["object"]) do
+ if activity.data["type"] == "Create" do
+ %Object{} = object = Object.normalize(activity.data["object"])
+
Fallback.RedirectController.redirector_with_meta(conn, %{
- activity: activity,
+ object: object,
user: user
})
else
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
use Pleroma.DataCase
import Pleroma.Factory
}
})
- note_activity =
- insert(:note_activity, %{
- data: %{
- "actor" => note.data["actor"],
- "to" => note.data["to"],
- "object" => note.data,
- "context" => note.data["context"]
- },
- actor: note.data["actor"],
- recipients: note.data["to"]
- })
-
- result = OpenGraph.build_tags(%{activity: note_activity, user: user})
+ result = OpenGraph.build_tags(%{object: note, user: user})
assert Enum.all?(
[
"id" => "https://pleroma.gov/objects/whatever",
"content" => "#cuteposting #nsfw #hambaga",
"tag" => ["cuteposting", "nsfw", "hambaga"],
+ "sensitive" => true,
"attachment" => [
%{
"url" => [
}
})
- note_activity =
- insert(:note_activity, %{
- data: %{
- "actor" => note.data["actor"],
- "to" => note.data["to"],
- "object" => note.data,
- "context" => note.data["context"]
- },
- actor: note.data["actor"],
- recipients: note.data["to"]
- })
-
- result = OpenGraph.build_tags(%{activity: note_activity, user: user})
+ result = OpenGraph.build_tags(%{object: note, user: user})
assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result