Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NEETzsche
pleroma
Commits
1f0f79d9
Commit
1f0f79d9
authored
8 years ago
by
lain
Browse files
Options
Downloads
Patches
Plain Diff
Generate ids for activities.
parent
9ad045fd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pleroma/web/activity_pub/activity_pub.ex
+10
-0
10 additions, 0 deletions
lib/pleroma/web/activity_pub/activity_pub.ex
test/web/activity_pub/activity_pub_test.exs
+14
-4
14 additions, 4 deletions
test/web/activity_pub/activity_pub_test.exs
with
24 additions
and
4 deletions
lib/pleroma/web/activity_pub/activity_pub.ex
+
10
−
0
View file @
1f0f79d9
...
...
@@ -4,9 +4,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
import
Ecto
.
Query
def
insert
(
map
)
when
is_map
(
map
)
do
map
=
Map
.
put_new_lazy
(
map
,
"id"
,
&
generate_activity_id
/
0
)
Repo
.
insert
(%
Activity
{
data:
map
})
end
def
generate_activity_id
do
host
=
Application
.
get_env
(
:pleroma
,
Pleroma
.
Web
.
Endpoint
)
|>
Keyword
.
fetch!
(
:url
)
|>
Keyword
.
fetch!
(
:host
)
"https://
#{
host
}
/activities/
#{
Ecto
.
UUID
.
generate
}
"
end
def
fetch_public_activities
(
opts
\\
%{})
do
public
=
[
"https://www.w3.org/ns/activitystreams#Public"
]
fetch_activities
(
public
,
opts
)
...
...
This diff is collapsed.
Click to expand it.
test/web/activity_pub/activity_pub_test.exs
+
14
−
4
View file @
1f0f79d9
...
...
@@ -5,17 +5,27 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
alias
Pleroma
.
Builders
.
ActivityBuilder
describe
"insertion"
do
test
"inserts a given map into the activity database"
do
test
"inserts a given map into the activity database
, giving it an id if it has none.
"
do
data
=
%{
ok
:
true
"
ok
"
=>
true
}
{
:ok
,
%
Activity
{}
=
activity
}
=
ActivityPub
.
insert
(
data
)
assert
activity
.
data
==
data
assert
activity
.
data
[
"ok"
]
==
data
[
"ok"
]
assert
is_binary
(
activity
.
data
[
"id"
])
given_id
=
"bla"
data
=
%{
"ok"
=>
true
,
"id"
=>
given_id
}
{
:ok
,
%
Activity
{}
=
activity
}
=
ActivityPub
.
insert
(
data
)
assert
activity
.
data
[
"ok"
]
==
data
[
"ok"
]
assert
activity
.
data
[
"id"
]
==
given_id
end
end
describe
"fetch activities for recipients"
do
test
"retrieve the activities for certain recipients"
do
{
:ok
,
activity_one
}
=
ActivityBuilder
.
insert
(%{
"to"
=>
[
"someone"
]})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment