Skip to content
GitLab
Menu
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
13ab8def
Commit
13ab8def
authored
May 04, 2020
by
lain
Browse files
Pipeline: Move transctioning to common pipeline.
parent
09563545
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/activity_pub/pipeline.ex
View file @
13ab8def
...
...
@@ -4,20 +4,33 @@
defmodule
Pleroma
.
Web
.
ActivityPub
.
Pipeline
do
alias
Pleroma
.
Activity
alias
Pleroma
.
Object
alias
Pleroma
.
Repo
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
alias
Pleroma
.
Web
.
ActivityPub
.
MRF
alias
Pleroma
.
Web
.
ActivityPub
.
ObjectValidator
alias
Pleroma
.
Web
.
ActivityPub
.
SideEffects
alias
Pleroma
.
Web
.
Federator
@spec
common_pipeline
(
map
(),
keyword
())
::
{
:ok
,
Activity
.
t
(),
keyword
()}
|
{
:error
,
any
()}
@spec
common_pipeline
(
map
(),
keyword
())
::
{
:ok
,
Activity
.
t
()
|
Object
.
t
(),
keyword
()}
|
{
:error
,
any
()}
def
common_pipeline
(
object
,
meta
)
do
case
Repo
.
transaction
(
fn
->
do_common_pipeline
(
object
,
meta
)
end
)
do
{
:ok
,
value
}
->
value
{
:error
,
e
}
->
{
:error
,
e
}
end
end
def
do_common_pipeline
(
object
,
meta
)
do
with
{
_
,
{
:ok
,
validated_object
,
meta
}}
<-
{
:validate_object
,
ObjectValidator
.
validate
(
object
,
meta
)},
{
_
,
{
:ok
,
mrfd_object
}}
<-
{
:mrf_object
,
MRF
.
filter
(
validated_object
)},
{
_
,
{
:ok
,
%
Activity
{}
=
activity
,
meta
}}
<-
{
_
,
{
:ok
,
activity
,
meta
}}
<-
{
:persist_object
,
ActivityPub
.
persist
(
mrfd_object
,
meta
)},
{
_
,
{
:ok
,
%
Activity
{}
=
activity
,
meta
}}
<-
{
_
,
{
:ok
,
activity
,
meta
}}
<-
{
:execute_side_effects
,
SideEffects
.
handle
(
activity
,
meta
)},
{
_
,
{
:ok
,
_
}}
<-
{
:federation
,
maybe_federate
(
activity
,
meta
)}
do
{
:ok
,
activity
,
meta
}
...
...
@@ -27,7 +40,9 @@ def common_pipeline(object, meta) do
end
end
defp
maybe_federate
(
activity
,
meta
)
do
defp
maybe_federate
(%
Object
{},
_
),
do
:
{
:ok
,
:not_federated
}
defp
maybe_federate
(%
Activity
{}
=
activity
,
meta
)
do
with
{
:ok
,
local
}
<-
Keyword
.
fetch
(
meta
,
:local
)
do
if
local
do
Federator
.
publish
(
activity
)
...
...
lib/pleroma/web/activity_pub/side_effects.ex
View file @
13ab8def
...
...
@@ -15,17 +15,12 @@ def handle(object, meta \\ [])
# - Add like to object
# - Set up notification
def
handle
(%{
data:
%{
"type"
=>
"Like"
}}
=
object
,
meta
)
do
{
:ok
,
result
}
=
Pleroma
.
Repo
.
transaction
(
fn
->
liked_object
=
Object
.
get_by_ap_id
(
object
.
data
[
"object"
])
Utils
.
add_like_to_object
(
object
,
liked_object
)
liked_object
=
Object
.
get_by_ap_id
(
object
.
data
[
"object"
])
Utils
.
add_like_to_object
(
object
,
liked_object
)
Notification
.
create_notifications
(
object
)
Notification
.
create_notifications
(
object
)
{
:ok
,
object
,
meta
}
end
)
result
{
:ok
,
object
,
meta
}
end
# Nothing to do
...
...
Write
Preview
Supports
Markdown
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