Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
pleroma
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
404
Issues
404
List
Boards
Labels
Service Desk
Milestones
Merge Requests
58
Merge Requests
58
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pleroma
pleroma
Commits
810cf861
Commit
810cf861
authored
Feb 21, 2018
by
lain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ActivityPub: Fetch missing activities on reply.
parent
947ba649
Pipeline
#784
failed with stage
in 2 minutes and 55 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
5 deletions
+41
-5
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/activity_pub.ex
+9
-4
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
+4
-0
test/web/activity_pub/activity_pub_test.exs
test/web/activity_pub/activity_pub_test.exs
+13
-1
test/web/activity_pub/transmogrifier_test.exs
test/web/activity_pub/transmogrifier_test.exs
+15
-0
No files found.
lib/pleroma/web/activity_pub/activity_pub.ex
View file @
810cf861
...
...
@@ -3,6 +3,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
alias
Pleroma
.
Web
.
ActivityPub
.
Transmogrifier
alias
Pleroma
.
Web
.
WebFinger
alias
Pleroma
.
Web
.
Federator
alias
Pleroma
.
Web
.
OStatus
import
Ecto
.
Query
import
Pleroma
.
Web
.
ActivityPub
.
Utils
require
Logger
...
...
@@ -325,14 +326,18 @@ def fetch_object_from_id(id) do
else
with
{
:ok
,
%{
body:
body
,
status_code:
code
}}
when
code
in
200
..
299
<-
@httpoison
.
get
(
id
,
[
Accept:
"application/activity+json"
],
follow_redirect:
true
,
timeout:
10000
,
recv_timeout:
20000
),
{
:ok
,
data
}
<-
Poison
.
decode
(
body
),
data
<-
Transmogrifier
.
fix_object
(
data
),
nil
<-
Object
.
get_by_ap_id
(
data
[
"id"
]),
%
User
{}
=
user
<-
User
.
get_or_fetch_by_ap_id
(
data
[
"attributedTo"
])
,
{
:ok
,
activity
}
=
create
(%{
to:
data
[
"to"
],
actor:
user
,
context:
data
[
"context"
],
object:
data
,
local:
false
,
additional:
%{
"cc"
=>
data
[
"cc"
]}}
)
do
params
<-
%{
"type"
=>
"Create"
,
"to"
=>
data
[
"to"
],
"cc"
=>
data
[
"cc"
],
"actor"
=>
data
[
"attributedTo"
],
"object"
=>
data
}
,
{
:ok
,
activity
}
<-
Transmogrifier
.
handle_incoming
(
params
)
do
{
:ok
,
Object
.
get_by_ap_id
(
activity
.
data
[
"object"
][
"id"
])}
else
object
=
%
Object
{}
->
{
:ok
,
object
}
e
->
e
e
->
Logger
.
info
(
"Couldn't get object via AP, trying out OStatus fetching..."
)
case
OStatus
.
fetch_activity_from_url
(
id
)
do
{
:ok
,
[
activity
|
_
]}
->
{
:ok
,
Object
.
get_by_ap_id
(
activity
.
data
[
"object"
][
"id"
])}
_
->
e
end
end
end
end
...
...
lib/pleroma/web/activity_pub/transmogrifier.ex
View file @
810cf861
...
...
@@ -53,6 +53,10 @@ def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = obje
])
}
if
object
[
"inReplyTo"
]
do
{
:ok
,
object
}
=
ActivityPub
.
fetch_object_from_id
(
object
[
"inReplyTo"
])
end
ActivityPub
.
create
(
params
)
else
%
Activity
{}
=
activity
->
{
:ok
,
activity
}
...
...
test/web/activity_pub/activity_pub_test.exs
View file @
810cf861
...
...
@@ -268,7 +268,9 @@ test "fetches the latest Follow activity" do
describe
"fetching an object"
do
test
"it fetches an object"
do
{
:ok
,
object
}
=
ActivityPub
.
fetch_object_from_id
(
"http://mastodon.example.org/@admin/99541947525187367"
)
assert
Activity
.
get_create_activity_by_object_ap_id
(
object
.
data
[
"id"
])
assert
activity
=
Activity
.
get_create_activity_by_object_ap_id
(
object
.
data
[
"id"
])
assert
activity
.
data
[
"id"
]
{
:ok
,
object_again
}
=
ActivityPub
.
fetch_object_from_id
(
"http://mastodon.example.org/@admin/99541947525187367"
)
assert
[
attachment
]
=
object
.
data
[
"attachment"
]
...
...
@@ -276,6 +278,16 @@ test "it fetches an object" do
assert
object
==
object_again
end
test
"it works with objects only available via Ostatus"
do
{
:ok
,
object
}
=
ActivityPub
.
fetch_object_from_id
(
"https://shitposter.club/notice/2827873"
)
assert
activity
=
Activity
.
get_create_activity_by_object_ap_id
(
object
.
data
[
"id"
])
assert
activity
.
data
[
"id"
]
{
:ok
,
object_again
}
=
ActivityPub
.
fetch_object_from_id
(
"https://shitposter.club/notice/2827873"
)
assert
object
==
object_again
end
end
describe
"following / unfollowing"
do
...
...
test/web/activity_pub/transmogrifier_test.exs
View file @
810cf861
...
...
@@ -22,6 +22,21 @@ test "it ignores an incoming notice if we already have it" do
assert
activity
==
returned_activity
end
test
"it fetches replied-to activities if we don't have them"
do
data
=
File
.
read!
(
"test/fixtures/mastodon-post-activity.json"
)
|>
Poison
.
decode!
object
=
data
[
"object"
]
|>
Map
.
put
(
"inReplyTo"
,
"https://shitposter.club/notice/2827873"
)
data
=
data
|>
Map
.
put
(
"object"
,
object
)
{
:ok
,
returned_activity
}
=
Transmogrifier
.
handle_incoming
(
data
)
assert
Activity
.
get_create_activity_by_object_ap_id
(
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
)
end
test
"it works for incoming notices"
do
data
=
File
.
read!
(
"test/fixtures/mastodon-post-activity.json"
)
|>
Poison
.
decode!
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment