Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into develop

This commit is contained in:
Roger Braun 2017-05-08 19:35:16 +02:00
commit 8f9c43343e
3 changed files with 131 additions and 4 deletions

View file

@ -176,7 +176,7 @@ def handle_note(entry, doc \\ nil) do
# TODO: Bail out sooner and use transaction.
if Object.get_by_ap_id(id) do
{:error, "duplicate activity"}
{:ok, Activity.get_create_activity_by_object_ap_id(id)}
else
ActivityPub.create(to, actor, context, object, %{}, date, false)
end

99
test/fixtures/share-gs-local.xml vendored Normal file
View file

@ -0,0 +1,99 @@
<?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-03T08:05:41+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-03:noticeId=2028428:objectType=note</id>
<title>lambadalambda repeated a notice by lain</title>
<content type="html">RT @&lt;a href=&quot;https://pleroma.soykaf.com/users/lain&quot; class=&quot;h-card u-url p-nickname mention&quot; title=&quot;Lain Iwakura&quot;&gt;lain&lt;/a&gt; Added returning the entries as xml... let's see if the mastodon hammering stops now.</content>
<link rel="alternate" type="text/html" href="https://social.heldscal.la/notice/2028428"/>
<activity:verb>http://activitystrea.ms/schema/1.0/share</activity:verb>
<published>2017-05-03T08:05:41+00:00</published>
<updated>2017-05-03T08:05:41+00:00</updated>
<activity:object>
<activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
<id>LOCAL_ID</id>
<title></title>
<content type="html">Added returning the entries as xml... let's see if the mastodon hammering stops now.</content>
<link rel="alternate" type="text/html" href="https://pleroma.soykaf.com/objects/4c1bda26-902e-4525-9fcd-b9fd44925193"/>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<published>2017-05-03T08:04:44+00:00</published>
<updated>2017-05-03T08:04:44+00:00</updated>
<author>
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
<uri>LOCAL_USER</uri>
<name>lain</name>
<summary>Test account</summary>
<link rel="alternate" type="text/html" href="https://pleroma.soykaf.com/users/lain"/>
<link rel="avatar" type="image/jpeg" media:width="250" media:height="202" href="https://social.heldscal.la/avatar/43188-original-20170429171039.jpeg"/>
<link rel="avatar" type="image/jpeg" media:width="96" media:height="96" href="https://social.heldscal.la/avatar/43188-96-20170429172422.jpeg"/>
<link rel="avatar" type="image/jpeg" media:width="48" media:height="48" href="https://social.heldscal.la/avatar/43188-48-20170429172422.jpeg"/>
<link rel="avatar" type="image/jpeg" media:width="24" media:height="24" href="https://social.heldscal.la/avatar/43188-24-20170429181411.jpeg"/>
<poco:preferredUsername>lain</poco:preferredUsername>
<poco:displayName>Lain Iwakura</poco:displayName>
<poco:note>Test account</poco:note>
<statusnet:profile_info local_id="43188"></statusnet:profile_info>
</author>
<activity:object>
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
<id>https://pleroma.soykaf.com/objects/4c1bda26-902e-4525-9fcd-b9fd44925193</id>
<title>New note by lain</title>
<content type="html">Added returning the entries as xml... let's see if the mastodon hammering stops now.</content>
<link rel="alternate" type="text/html" href="https://pleroma.soykaf.com/objects/4c1bda26-902e-4525-9fcd-b9fd44925193"/>
<status_net notice_id="2028424"></status_net>
</activity:object>
<link rel="ostatus:conversation" href="https://social.heldscal.la/conversation/1042737"/>
<ostatus:conversation href="https://social.heldscal.la/conversation/1042737" local_id="1042737" ref="https://pleroma.soykaf.com/contexts/ede39a2b-7cf3-4fa4-8ccd-cb97431bcc22">https://pleroma.soykaf.com/contexts/ede39a2b-7cf3-4fa4-8ccd-cb97431bcc22</ostatus:conversation>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
<source>
<id>https://pleroma.soykaf.com/users/lain/feed.atom</id>
<title>Lain Iwakura</title>
<link rel="alternate" type="text/html" href="https://pleroma.soykaf.com/users/lain"/>
<link rel="self" type="application/atom+xml" href="https://pleroma.soykaf.com/users/lain/feed.atom"/>
<icon>https://social.heldscal.la/avatar/43188-96-20170429172422.jpeg</icon>
<updated>2017-05-03T08:04:44+00:00</updated>
</source>
</activity:object>
<link rel="ostatus:conversation" href="https://social.heldscal.la/conversation/1042737"/>
<ostatus:conversation href="https://social.heldscal.la/conversation/1042737" local_id="1042737" ref="https://pleroma.soykaf.com/contexts/ede39a2b-7cf3-4fa4-8ccd-cb97431bcc22">https://pleroma.soykaf.com/contexts/ede39a2b-7cf3-4fa4-8ccd-cb97431bcc22</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/2028428.atom"/>
<link rel="edit" type="application/atom+xml" href="https://social.heldscal.la/api/statuses/show/2028428.atom"/>
<statusnet:notice_info local_id="2028428" source="api" repeat_of="2028424"></statusnet:notice_info>
</entry>
</feed>

View file

@ -2,13 +2,13 @@ defmodule Pleroma.Web.OStatusTest do
use Pleroma.DataCase
alias Pleroma.Web.OStatus
alias Pleroma.Web.XML
alias Pleroma.{Object, Repo, User}
alias Pleroma.{Object, Repo, User, Activity}
import Pleroma.Factory
test "don't insert create notes twice" do
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
{:ok, [_activity]} = OStatus.handle_incoming(incoming)
assert {:ok, [{:error, "duplicate activity"}]} == OStatus.handle_incoming(incoming)
{:ok, [activity]} = OStatus.handle_incoming(incoming)
assert {:ok, [activity]} == OStatus.handle_incoming(incoming)
end
test "handle incoming note - GS, Salmon" do
@ -80,10 +80,38 @@ test "handle incoming retweets - GS, subscription" do
assert activity.data["type"] == "Announce"
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
assert activity.data["object"] == retweeted_activity.data["object"]["id"]
assert "https://pleroma.soykaf.com/users/lain" in activity.data["to"]
refute activity.local
retweeted_activity = Repo.get(Activity, retweeted_activity.id)
assert retweeted_activity.data["type"] == "Create"
assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
refute retweeted_activity.local
assert retweeted_activity.data["object"]["announcement_count"] == 1
end
test "handle incoming retweets - GS, subscription - local message" do
incoming = File.read!("test/fixtures/share-gs-local.xml")
note_activity = insert(:note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
incoming = incoming
|> String.replace("LOCAL_ID", note_activity.data["object"]["id"])
|> String.replace("LOCAL_USER", user.ap_id)
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
assert activity.data["type"] == "Announce"
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
assert activity.data["object"] == retweeted_activity.data["object"]["id"]
assert user.ap_id in activity.data["to"]
refute activity.local
retweeted_activity = Repo.get(Activity, retweeted_activity.id)
assert note_activity.id == retweeted_activity.id
assert retweeted_activity.data["type"] == "Create"
assert retweeted_activity.data["actor"] == user.ap_id
assert retweeted_activity.local
assert retweeted_activity.data["object"]["announcement_count"] == 1
end
test "handle incoming retweets - Mastodon, salmon" do