Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
081e8206
Commit
081e8206
authored
Oct 16, 2019
by
lain
Browse files
Transmogrifier: Use new ingestion pipeline for Likes.
parent
6e4f52f8
Pipeline
#18701
failed with stages
in 10 minutes and 35 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/object/containment.ex
View file @
081e8206
...
...
@@ -32,6 +32,18 @@ def get_actor(%{"actor" => nil, "attributedTo" => actor}) when not is_nil(actor)
get_actor
(%{
"actor"
=>
actor
})
end
def
get_object
(%{
"object"
=>
id
})
when
is_binary
(
id
)
do
id
end
def
get_object
(%{
"object"
=>
%{
"id"
=>
id
}})
when
is_binary
(
id
)
do
id
end
def
get_object
(
_
)
do
nil
end
@doc
"""
Checks that an imported AP object's actor matches the domain it came from.
"""
...
...
lib/pleroma/web/activity_pub/object_validator.ex
View file @
081e8206
...
...
@@ -31,7 +31,7 @@ def validate_actor(object, meta) do
def
common_validations
(
object
,
meta
)
do
with
{
_
,
{
:ok
,
object
,
meta
}}
<-
{
:validate_id
,
validate_id
(
object
,
meta
)},
{
_
,
{
:ok
,
object
,
meta
}}
<-
{
:validate_actor
,
validate_actor
(
object
,
meta
)}
do
{
_
,
{
:ok
,
object
,
meta
}}
<-
{
:validate_actor
,
validate_actor
(
object
,
meta
)}
do
{
:ok
,
object
,
meta
}
else
e
->
{
:error
,
e
}
...
...
@@ -43,7 +43,8 @@ def validate(object, meta)
def
validate
(%{
"type"
=>
"Like"
}
=
object
,
meta
)
do
with
{
:ok
,
object
,
meta
}
<-
common_validations
(
object
,
meta
),
{
_
,
%
Object
{}
=
liked_object
}
<-
{
:find_liked_object
,
Object
.
normalize
(
object
[
"object"
])},
{
_
,
%
Object
{}
=
liked_object
}
<-
{
:find_liked_object
,
Object
.
normalize
(
object
[
"object"
])},
{
_
,
nil
}
<-
{
:existing_like
,
Utils
.
get_existing_like
(
object
[
"actor"
],
liked_object
)}
do
{
:ok
,
object
,
meta
}
else
...
...
lib/pleroma/web/activity_pub/transmogrifier.ex
View file @
081e8206
...
...
@@ -563,19 +563,38 @@ def handle_incoming(
end
def
handle_incoming
(
%{
"type"
=>
"Like"
,
"object"
=>
object_id
,
"actor"
=>
_actor
,
"id"
=>
id
}
=
data
,
%{
"type"
=>
"Like"
,
"object"
=>
_
object_id
,
"actor"
=>
_actor
,
"id"
=>
_
id
}
=
data
,
_options
)
do
with
actor
<-
Containment
.
get_actor
(
data
),
{
:ok
,
%
User
{}
=
actor
}
<-
User
.
get_or_fetch_by_ap_id
(
actor
),
{
:ok
,
object
}
<-
get_obj_helper
(
object_id
),
{
:ok
,
activity
,
_object
}
<-
ActivityPub
.
like
(
actor
,
object
,
id
,
false
)
do
with
data
<-
Map
.
take
(
data
,
[
"type"
,
"object"
,
"actor"
,
"context"
,
"id"
]),
actor
<-
Containment
.
get_actor
(
data
),
object
<-
Containment
.
get_object
(
data
),
data
<-
data
|>
Map
.
put
(
"actor"
,
actor
)
|>
Map
.
put
(
"object"
,
object
),
_user
<-
User
.
get_or_fetch_by_ap_id
(
actor
),
object
<-
Object
.
normalize
(
object
),
data
<-
Map
.
put_new
(
data
,
"context"
,
object
.
data
[
"context"
]),
{
_
,
{
:ok
,
activity
,
_meta
}}
<-
{
:common_pipeline
,
ActivityPub
.
common_pipeline
(
data
,
local:
false
)}
do
{
:ok
,
activity
}
else
_
e
->
:error
e
->
{
:error
,
e
}
end
end
# def handle_incoming(
# %{"type" => "Like", "object" => object_id, "actor" => _actor, "id" => id} = data,
# _options
# ) do
# with actor <- Containment.get_actor(data),
# {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
# {:ok, object} <- get_obj_helper(object_id),
# {:ok, activity, _object} <- ActivityPub.like(actor, object, id, false) do
# {:ok, activity}
# else
# _e -> :error
# end
# end
def
handle_incoming
(
%{
"type"
=>
"Announce"
,
"object"
=>
object_id
,
"actor"
=>
_actor
,
"id"
=>
id
}
=
data
,
_options
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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