diff options
| author | rinpatch <rinpatch@sdf.org> | 2019-04-05 15:19:44 +0300 | 
|---|---|---|
| committer | rinpatch <rinpatch@sdf.org> | 2019-04-05 15:19:44 +0300 | 
| commit | f0f30019e1c9992cb420ba54457840cddaeb6a3a (patch) | |
| tree | 667bdd7fb652aef9c4eea58dbad0be6b43644da3 /lib | |
| parent | 9c9eec62c2fb67507708dd9e5d3f80a098881a6e (diff) | |
| download | pleroma-f0f30019e1c9992cb420ba54457840cddaeb6a3a.tar.gz pleroma-f0f30019e1c9992cb420ba54457840cddaeb6a3a.zip | |
Refactor html caching functions to have a key instead of a module, use more correct terminology and fix summaries in mastoapi
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pleroma/html.ex | 15 | ||||
| -rw-r--r-- | lib/pleroma/web/mastodon_api/views/status_view.ex | 14 | ||||
| -rw-r--r-- | lib/pleroma/web/metadata/utils.ex | 2 | ||||
| -rw-r--r-- | lib/pleroma/web/twitter_api/views/activity_view.ex | 6 | 
4 files changed, 22 insertions, 15 deletions
| diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 1e48749a8..7f1dbe28c 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -28,21 +28,20 @@ defmodule Pleroma.HTML do    def filter_tags(html), do: filter_tags(html, nil)    def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags) -  # TODO: rename object to activity because that's what it is really working with -  def get_cached_scrubbed_html_for_object(content, scrubbers, object, module) do -    key = "#{module}#{generate_scrubber_signature(scrubbers)}|#{object.id}" +  def get_cached_scrubbed_html_for_activity(content, scrubbers, activity, key \\ "") do +    key = "#{key}#{generate_scrubber_signature(scrubbers)}|#{activity.id}"      Cachex.fetch!(:scrubber_cache, key, fn _key -> -      ensure_scrubbed_html(content, scrubbers, object.data["object"]["fake"] || false) +      ensure_scrubbed_html(content, scrubbers, activity.data["object"]["fake"] || false)      end)    end -  def get_cached_stripped_html_for_object(content, object, module) do -    get_cached_scrubbed_html_for_object( +  def get_cached_stripped_html_for_activity(content, activity, key) do +    get_cached_scrubbed_html_for_activity(        content,        HtmlSanitizeEx.Scrubber.StripTags, -      object, -      module +      activity, +      key      )    end diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 200bb453d..4c0b53bdd 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -147,10 +147,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do      content =        object        |> render_content() -      |> HTML.get_cached_scrubbed_html_for_object( +      |> HTML.get_cached_scrubbed_html_for_activity(          User.html_filter_policy(opts[:for]),          activity, -        __MODULE__ +        "mastoapi:content" +      ) + +    summary = +      (object["summary"] || "") +      |> HTML.get_cached_scrubbed_html_for_activity( +        User.html_filter_policy(opts[:for]), +        activity, +        "mastoapi:summary"        )      card = render("card.json", Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)) @@ -182,7 +190,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do        muted: CommonAPI.thread_muted?(user, activity) || User.mutes?(opts[:for], user),        pinned: pinned?(activity, user),        sensitive: sensitive, -      spoiler_text: object["summary"] || "", +      spoiler_text: summary,        visibility: get_visibility(object),        media_attachments: attachments,        mentions: mentions, diff --git a/lib/pleroma/web/metadata/utils.ex b/lib/pleroma/web/metadata/utils.ex index 23bbde1a6..58385a3d1 100644 --- a/lib/pleroma/web/metadata/utils.ex +++ b/lib/pleroma/web/metadata/utils.ex @@ -12,7 +12,7 @@ defmodule Pleroma.Web.Metadata.Utils do      # 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(object, __MODULE__) +    |> HTML.get_cached_stripped_html_for_activity(object, "metadata")      |> Formatter.demojify()      |> Formatter.truncate()    end diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index aa1d41fa2..433322eb8 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -254,10 +254,10 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do      html =        content -      |> HTML.get_cached_scrubbed_html_for_object( +      |> HTML.get_cached_scrubbed_html_for_activity(          User.html_filter_policy(opts[:for]),          activity, -        __MODULE__ +        "twitterapi:content"        )        |> Formatter.emojify(object["emoji"]) @@ -265,7 +265,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do        if content do          content          |> String.replace(~r/<br\s?\/?>/, "\n") -        |> HTML.get_cached_stripped_html_for_object(activity, __MODULE__) +        |> HTML.get_cached_stripped_html_for_activity(activity, "twitterapi:content")        else          ""        end | 
