Don't call out if we have the favorited notice locally.
This commit is contained in:
parent
fa2610c795
commit
2d9fdbcc0d
3 changed files with 101 additions and 9 deletions
|
@ -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 handle_favorite(entry, doc) do
|
||||
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),
|
||||
{:ok, [favorited_activity]} <- fetch_activity_from_html_url(href) do
|
||||
{:ok, favorited_activity}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def handle_favorite(entry, doc) do
|
||||
with {:ok, favorited_activity} <- get_or_try_fetching(entry),
|
||||
{:ok, activity} <- make_favorite(entry, doc, favorited_activity) do
|
||||
{:ok, activity, favorited_activity}
|
||||
else
|
||||
|
|
64
test/fixtures/favorite_with_local_note.xml
vendored
Normal file
64
test/fixtures/favorite_with_local_note.xml
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:media="http://purl.org/syndication/atommedia" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:statusnet="http://status.net/schema/api/1/">
|
||||
<generator uri="https://gnu.io/social" version="1.0.2-dev">GNU social</generator>
|
||||
<id>https://social.heldscal.la/api/statuses/user_timeline/23211.atom</id>
|
||||
<title>lambadalambda timeline</title>
|
||||
<subtitle>Updates from lambadalambda on social.heldscal.la!</subtitle>
|
||||
<logo>https://social.heldscal.la/avatar/23211-96-20170416114255.jpeg</logo>
|
||||
<updated>2017-05-05T09:12:53+00:00</updated>
|
||||
<author>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
||||
<uri>https://social.heldscal.la/user/23211</uri>
|
||||
<name>lambadalambda</name>
|
||||
<summary>Call me Deacon Blues.</summary>
|
||||
<link rel="alternate" type="text/html" href="https://social.heldscal.la/lambadalambda"/>
|
||||
<link rel="avatar" type="image/jpeg" media:width="236" media:height="236" href="https://social.heldscal.la/avatar/23211-original-20170416114255.jpeg"/>
|
||||
<link rel="avatar" type="image/jpeg" media:width="96" media:height="96" href="https://social.heldscal.la/avatar/23211-96-20170416114255.jpeg"/>
|
||||
<link rel="avatar" type="image/jpeg" media:width="48" media:height="48" href="https://social.heldscal.la/avatar/23211-48-20170416114255.jpeg"/>
|
||||
<link rel="avatar" type="image/jpeg" media:width="24" media:height="24" href="https://social.heldscal.la/avatar/23211-24-20170416114257.jpeg"/>
|
||||
<poco:preferredUsername>lambadalambda</poco:preferredUsername>
|
||||
<poco:displayName>Constance Variable</poco:displayName>
|
||||
<poco:note>Call me Deacon Blues.</poco:note>
|
||||
<poco:address>
|
||||
<poco:formatted>Berlin</poco:formatted>
|
||||
</poco:address>
|
||||
<poco:urls>
|
||||
<poco:type>homepage</poco:type>
|
||||
<poco:value>https://heldscal.la</poco:value>
|
||||
<poco:primary>true</poco:primary>
|
||||
</poco:urls>
|
||||
<followers url="https://social.heldscal.la/lambadalambda/subscribers"></followers>
|
||||
<statusnet:profile_info local_id="23211"></statusnet:profile_info>
|
||||
</author>
|
||||
<link href="https://social.heldscal.la/lambadalambda" rel="alternate" type="text/html"/>
|
||||
<link href="https://social.heldscal.la/main/sup" rel="http://api.friendfeed.com/2008/03#sup" type="application/json"/>
|
||||
<link href="https://social.heldscal.la/main/push/hub" rel="hub"/>
|
||||
<link href="https://social.heldscal.la/main/salmon/user/23211" rel="salmon"/>
|
||||
<link href="https://social.heldscal.la/main/salmon/user/23211" rel="http://salmon-protocol.org/ns/salmon-replies"/>
|
||||
<link href="https://social.heldscal.la/main/salmon/user/23211" rel="http://salmon-protocol.org/ns/salmon-mention"/>
|
||||
<link href="https://social.heldscal.la/api/statuses/user_timeline/23211.atom" rel="self" type="application/atom+xml"/>
|
||||
<entry>
|
||||
<id>tag:social.heldscal.la,2017-05-05:fave:23211:comment:2061643:2017-05-05T09:12:50+00:00</id>
|
||||
<title>Favorite</title>
|
||||
<content type="html">lambadalambda favorited something by moonman: @<a href="https://shitposter.club/user/9655" class="h-card mention" title="Solidarity for Pigs">neimzr4luzerz</a> @<a href="https://gs.smuglo.li/user/2326" class="h-card mention" title="Dolus_McHonest">dolus</a> childhood poring over Strong's concordance and a koine Greek dictionary, fast forward to 2017 and some fuckstick who translates japanese jackoff material tells me you just need to make it sound right in English</content>
|
||||
<link rel="alternate" type="text/html" href="https://social.heldscal.la/notice/2061828"/>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/favorite</activity:verb>
|
||||
<published>2017-05-05T09:12:50+00:00</published>
|
||||
<updated>2017-05-05T09:12:50+00:00</updated>
|
||||
<activity:object>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/comment</activity:object-type>
|
||||
<id>localid</id>
|
||||
<title>New comment by moonman</title>
|
||||
<content type="html">@<a href="https://shitposter.club/user/9655" class="h-card mention" title="Solidarity for Pigs">neimzr4luzerz</a> @<a href="https://gs.smuglo.li/user/2326" class="h-card mention" title="Dolus_McHonest">dolus</a> childhood poring over Strong's concordance and a koine Greek dictionary, fast forward to 2017 and some fuckstick who translates japanese jackoff material tells me you just need to make it sound right in English</content>
|
||||
<status_net notice_id="2061643"></status_net>
|
||||
</activity:object>
|
||||
<thr:in-reply-to ref="tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" href="https://shitposter.club/notice/2827873"></thr:in-reply-to>
|
||||
<link rel="related" href="https://shitposter.club/notice/2827873"/>
|
||||
<link rel="ostatus:conversation" href="https://social.heldscal.la/conversation/1061781"/>
|
||||
<ostatus:conversation href="https://social.heldscal.la/conversation/1061781" local_id="1061781" ref="tag:social.heldscal.la,2017-05-05:objectType=thread:nonce=55ead90125cd4bd4">tag:social.heldscal.la,2017-05-05:objectType=thread:nonce=55ead90125cd4bd4</ostatus:conversation>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
||||
<link rel="self" type="application/atom+xml" href="https://social.heldscal.la/api/statuses/show/2061828.atom"/>
|
||||
<link rel="edit" type="application/atom+xml" href="https://social.heldscal.la/api/statuses/show/2061828.atom"/>
|
||||
<statusnet:notice_info local_id="2061828" source="unknown"></statusnet:notice_info>
|
||||
</entry>
|
||||
</feed>
|
|
@ -3,6 +3,7 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.XML
|
||||
alias Pleroma.{Object, Repo}
|
||||
import Pleroma.Factory
|
||||
|
||||
test "don't insert create notes twice" do
|
||||
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
||||
|
@ -98,16 +99,32 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
|
||||
test "handle incoming favorites - GS, websub" do
|
||||
incoming = File.read!("test/fixtures/favorite.xml")
|
||||
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
|
||||
{:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
assert activity.data["type"] == "Like"
|
||||
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
|
||||
assert activity.data["object"] == retweeted_activity.data["object"]["id"]
|
||||
assert activity.data["object"] == favorited_activity.data["object"]["id"]
|
||||
refute activity.local
|
||||
assert retweeted_activity.data["type"] == "Create"
|
||||
assert retweeted_activity.data["actor"] == "https://shitposter.club/user/1"
|
||||
assert retweeted_activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
||||
refute retweeted_activity.local
|
||||
assert favorited_activity.data["type"] == "Create"
|
||||
assert favorited_activity.data["actor"] == "https://shitposter.club/user/1"
|
||||
assert favorited_activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
||||
refute favorited_activity.local
|
||||
end
|
||||
|
||||
test "handle incoming favorites with locally available object - GS, websub" do
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
incoming = File.read!("test/fixtures/favorite_with_local_note.xml")
|
||||
|> String.replace("localid", note_activity.data["object"]["id"])
|
||||
|
||||
{:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
assert activity.data["type"] == "Like"
|
||||
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
|
||||
assert activity.data["object"] == favorited_activity.data["object"]["id"]
|
||||
refute activity.local
|
||||
assert note_activity.id == favorited_activity.id
|
||||
assert favorited_activity.local
|
||||
end
|
||||
|
||||
test "handle incoming replies" do
|
||||
|
|
Loading…
Reference in a new issue