diff options
author | Roger Braun <roger@rogerbraun.net> | 2017-05-05 16:27:03 +0200 |
---|---|---|
committer | Roger Braun <roger@rogerbraun.net> | 2017-05-05 16:27:03 +0200 |
commit | 2d9fdbcc0d41f00c9996962ea20d6ff58f0a32b8 (patch) | |
tree | 7d256fd8f4e11104c3c30757610ec8d5eca2b150 /lib | |
parent | fa2610c7959500c18b64d70828123a817de78864 (diff) | |
download | pleroma-2d9fdbcc0d41f00c9996962ea20d6ff58f0a32b8.tar.gz |
Don't call out if we have the favorited notice locally.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/ostatus/ostatus.ex | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 0a4361393..5a44b8661 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Web.OStatus do import Pleroma.Web.XML require Logger - alias Pleroma.{Repo, User, Web, Object} + alias Pleroma.{Repo, User, Web, Object, Activity} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.{WebFinger, Websub} @@ -75,9 +75,20 @@ defmodule Pleroma.Web.OStatus do end end + def get_or_try_fetching(entry) do + with id when not is_nil(id) <- string_from_xpath("//activity:object[1]/id", entry), + %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + {:ok, activity} + else _e -> + with href when not is_nil(href) <- string_from_xpath("//activity:object[1]/link[@type=\"text/html\"]/@href", entry), + {:ok, [favorited_activity]} <- fetch_activity_from_html_url(href) do + {:ok, favorited_activity} + end + end + end + def handle_favorite(entry, doc) do - with href when not is_nil(href) <- string_from_xpath("//activity:object[1]/link[@type=\"text/html\"]/@href", entry), - {:ok, [favorited_activity]} <- fetch_activity_from_html_url(href), + with {:ok, favorited_activity} <- get_or_try_fetching(entry), {:ok, activity} <- make_favorite(entry, doc, favorited_activity) do {:ok, activity, favorited_activity} else |