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
db08498a
Commit
db08498a
authored
May 07, 2017
by
lain
Browse files
Prevent double insertions.
parent
4f9328c6
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/activity_pub/activity_pub.ex
View file @
db08498a
...
@@ -8,15 +8,19 @@ def insert(map, local \\ true) when is_map(map) do
...
@@ -8,15 +8,19 @@ def insert(map, local \\ true) when is_map(map) do
|>
Map
.
put_new_lazy
(
"id"
,
&
generate_activity_id
/
0
)
|>
Map
.
put_new_lazy
(
"id"
,
&
generate_activity_id
/
0
)
|>
Map
.
put_new_lazy
(
"published"
,
&
make_date
/
0
)
|>
Map
.
put_new_lazy
(
"published"
,
&
make_date
/
0
)
map
=
if
is_map
(
map
[
"object"
])
do
with
%
Activity
{}
=
activity
<-
Activity
.
get_by_ap_id
(
map
[
"id"
])
do
object
=
Map
.
put_new_lazy
(
map
[
"object"
],
"id"
,
&
generate_object_id
/
0
)
{
:ok
,
activity
}
Repo
.
insert!
(%
Object
{
data:
object
})
else
_e
->
Map
.
put
(
map
,
"object"
,
object
)
map
=
if
is_map
(
map
[
"object"
])
do
else
object
=
Map
.
put_new_lazy
(
map
[
"object"
],
"id"
,
&
generate_object_id
/
0
)
map
Repo
.
insert!
(%
Object
{
data:
object
})
end
Map
.
put
(
map
,
"object"
,
object
)
else
map
end
Repo
.
insert
(%
Activity
{
data:
map
,
local:
local
})
Repo
.
insert
(%
Activity
{
data:
map
,
local:
local
})
end
end
end
def
create
(
to
,
actor
,
context
,
object
,
additional
\\
%{},
published
\\
nil
,
local
\\
true
)
do
def
create
(
to
,
actor
,
context
,
object
,
additional
\\
%{},
published
\\
nil
,
local
\\
true
)
do
...
...
test/web/activity_pub/activity_pub_test.exs
View file @
db08498a
...
@@ -7,6 +7,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
...
@@ -7,6 +7,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
import
Pleroma
.
Factory
import
Pleroma
.
Factory
describe
"insertion"
do
describe
"insertion"
do
test
"returns the activity if one with the same id is already in"
do
activity
=
insert
(
:note_activity
)
{
:ok
,
new_activity
}
=
ActivityPub
.
insert
(
activity
.
data
)
assert
activity
==
new_activity
end
test
"inserts a given map into the activity database, giving it an id if it has none."
do
test
"inserts a given map into the activity database, giving it an id if it has none."
do
data
=
%{
data
=
%{
"ok"
=>
true
"ok"
=>
true
...
...
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