diff options
| -rw-r--r-- | config/config.exs | 2 | ||||
| -rw-r--r-- | lib/pleroma/formatter.ex | 23 | ||||
| -rw-r--r-- | lib/pleroma/web/activity_pub/transmogrifier.ex | 3 | ||||
| -rw-r--r-- | lib/pleroma/web/activity_pub/utils.ex | 2 | ||||
| -rw-r--r-- | lib/pleroma/web/activity_pub/views/user_view.ex | 2 | ||||
| -rw-r--r-- | lib/pleroma/web/mastodon_api/views/status_view.ex | 22 | ||||
| -rw-r--r-- | lib/pleroma/web/twitter_api/representers/activity_representer.ex | 11 | ||||
| -rw-r--r-- | lib/pleroma/web/twitter_api/views/activity_view.ex | 43 | ||||
| -rw-r--r-- | test/web/activity_pub/views/user_view_test.exs | 2 | ||||
| -rw-r--r-- | test/web/twitter_api/representers/activity_representer_test.exs | 2 | 
10 files changed, 85 insertions, 27 deletions
| diff --git a/config/config.exs b/config/config.exs index cf6cbaa9d..0616fe4fb 100644 --- a/config/config.exs +++ b/config/config.exs @@ -12,6 +12,8 @@ config :pleroma, Pleroma.Repo, types: Pleroma.PostgresTypes  config :pleroma, Pleroma.Upload, uploads: "uploads" +config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png"] +  # Configures the endpoint  config :pleroma, Pleroma.Web.Endpoint,    url: [host: "localhost"], diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index df7ffbc41..0aaf21538 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -116,7 +116,28 @@ defmodule Pleroma.Formatter do                        _ -> []                      end) -  @emoji @finmoji_with_filenames ++ @emoji_from_file +  @emoji_from_globs ( +                      static_path = Path.join(:code.priv_dir(:pleroma), "static") + +                      globs = +                        Application.get_env(:pleroma, :emoji, []) +                        |> Keyword.get(:shortcode_globs, []) + +                      paths = +                        Enum.map(globs, fn glob -> +                          Path.join(static_path, glob) +                          |> Path.wildcard() +                        end) +                        |> Enum.concat() + +                      Enum.map(paths, fn path -> +                        shortcode = Path.basename(path, Path.extname(path)) +                        external_path = Path.join("/", Path.relative_to(path, static_path)) +                        {shortcode, external_path} +                      end) +                    ) + +  @emoji @finmoji_with_filenames ++ @emoji_from_globs ++ @emoji_from_file    def emojify(text, emoji \\ @emoji)    def emojify(text, nil), do: text diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 30cd70fb6..59c4b90e7 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -122,7 +122,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do    # TODO: validate those with a Ecto scheme    # - tags    # - emoji -  def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do +  def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data) +      when objtype in ["Article", "Note"] do      with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),           %User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do        object = fix_object(data["object"]) diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 64329b710..8b41a3bec 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -128,7 +128,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do    Inserts a full object if it is contained in an activity.    """    def insert_full_object(%{"object" => %{"type" => type} = object_data}) -      when is_map(object_data) and type in ["Note"] do +      when is_map(object_data) and type in ["Article", "Note"] do      with {:ok, _} <- Object.create(object_data) do        :ok      end diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index f4b2e0610..41bfe5048 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -12,7 +12,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do    def render("user.json", %{user: user}) do      {:ok, user} = WebFinger.ensure_keys_present(user)      {:ok, _, public_key} = Salmon.keys_from_pem(user.info["keys"]) -    public_key = :public_key.pem_entry_encode(:RSAPublicKey, public_key) +    public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key)      public_key = :public_key.pem_encode([public_key])      %{ diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 59898457b..4c20581d6 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -54,8 +54,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do      %{        id: to_string(activity.id),        uri: object, -      # TODO: This might be wrong, check with mastodon. -      url: nil, +      url: object,        account: AccountView.render("account.json", %{user: user}),        in_reply_to_id: nil,        in_reply_to_account_id: nil, @@ -128,7 +127,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do        in_reply_to_id: reply_to && to_string(reply_to.id),        in_reply_to_account_id: reply_to_user && to_string(reply_to_user.id),        reblog: nil, -      content: HtmlSanitizeEx.basic_html(object["content"]), +      content: render_content(object),        created_at: created_at,        reblogs_count: announcement_count,        favourites_count: like_count, @@ -207,4 +206,21 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do          "direct"      end    end + +  def render_content(%{"type" => "Article"} = object) do +    summary = object["name"] + +    content = +      if !!summary and summary != "" do +        "<p><a href=\"#{object["url"]}\">#{summary}</a></p>#{object["content"]}" +      else +        object["content"] +      end + +    HtmlSanitizeEx.basic_html(content) +  end + +  def render_content(object) do +    HtmlSanitizeEx.basic_html(object["content"]) +  end  end diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 57837205e..bb77e61f3 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -4,7 +4,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do    use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter    alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter    alias Pleroma.{Activity, User} -  alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView} +  alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView}    alias Pleroma.Web.CommonAPI.Utils    alias Pleroma.Formatter @@ -164,14 +164,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do      tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags -    summary = activity.data["object"]["summary"] - -    content = -      if !!summary and summary != "" do -        "<span>#{activity.data["object"]["summary"]}</span><br />#{content}</span>" -      else -        content -      end +    {summary, content} = ActivityView.render_content(object)      html =        HtmlSanitizeEx.basic_html(content) diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 62ce3b7b5..f418249e2 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -228,15 +228,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do      tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags -    summary = activity.data["object"]["summary"] -    content = object["content"] - -    content = -      if !!summary and summary != "" do -        "<span>#{activity.data["object"]["summary"]}</span><br />#{content}</span>" -      else -        content -      end +    {summary, content} = render_content(object)      html =        HtmlSanitizeEx.basic_html(content) @@ -266,4 +258,37 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do        "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object)      }    end + +  def render_content(%{"type" => "Note"} = object) do +    summary = object["summary"] + +    content = +      if !!summary and summary != "" do +        "<p>#{summary}</p>#{object["content"]}" +      else +        object["content"] +      end + +    {summary, content} +  end + +  def render_content(%{"type" => "Article"} = object) do +    summary = object["name"] || object["summary"] + +    content = +      if !!summary and summary != "" do +        "<p><a href=\"#{object["url"]}\">#{summary}</a></p>#{object["content"]}" +      else +        object["content"] +      end + +    {summary, content} +  end + +  def render_content(object) do +    summary = object["summary"] || "Unhandled activity type: #{object["type"]}" +    content = "<p>#{summary}</p>#{object["content"]}" + +    {summary, content} +  end  end diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs index 0c64e62c3..7fc870e96 100644 --- a/test/web/activity_pub/views/user_view_test.exs +++ b/test/web/activity_pub/views/user_view_test.exs @@ -13,6 +13,6 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do      assert result["id"] == user.ap_id      assert result["preferredUsername"] == user.nickname -    assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN RSA PUBLIC KEY") +    assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")    end  end diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 16c6e7b0d..7505093dd 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -126,7 +126,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do      }      expected_html = -      "<span>2hu</span><br />alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{ +      "<p>2hu</p>alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{          mentioned_user.ap_id        }\">@shp</a>" | 
