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
21c39782
Commit
21c39782
authored
7 years ago
by
lain
Browse files
Options
Downloads
Patches
Plain Diff
Add announcements to activitypub.
parent
7a47afed
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
+24
-0
24 additions, 0 deletions
lib/pleroma/web/activity_pub/activity_pub.ex
test/web/activity_pub/activity_pub_test.exs
+15
-0
15 additions, 0 deletions
test/web/activity_pub/activity_pub_test.exs
with
39 additions
and
0 deletions
lib/pleroma/web/activity_pub/activity_pub.ex
+
24
−
0
View file @
21c39782
...
...
@@ -137,6 +137,30 @@ def fetch_activities(recipients, opts \\ %{}) do
|>
Enum
.
reverse
end
def
announce
(%
User
{
ap_id:
ap_id
}
=
user
,
%
Object
{
data:
%{
"id"
=>
id
}}
=
object
)
do
data
=
%{
"type"
=>
"Announce"
,
"actor"
=>
ap_id
,
"object"
=>
id
,
"to"
=>
[
User
.
ap_followers
(
user
)]
}
{
:ok
,
activity
}
=
insert
(
data
)
announcements
=
[
ap_id
|
(
object
.
data
[
"announcements"
]
||
[])]
|>
Enum
.
uniq
new_data
=
object
.
data
|>
Map
.
put
(
"announcement_count"
,
length
(
announcements
))
|>
Map
.
put
(
"announcements"
,
announcements
)
changeset
=
Ecto
.
Changeset
.
change
(
object
,
data:
new_data
)
{
:ok
,
object
}
=
Repo
.
update
(
changeset
)
update_object_in_activities
(
object
)
{
:ok
,
activity
,
object
}
end
def
fetch_activities_for_context
(
context
)
do
query
=
from
activity
in
Activity
,
where:
fragment
(
"? @> ?"
,
activity
.
data
,
^
%{
context:
context
})
...
...
This diff is collapsed.
Click to expand it.
test/web/activity_pub/activity_pub_test.exs
+
15
−
0
View file @
21c39782
...
...
@@ -162,6 +162,21 @@ test "unliking a previously liked object" do
end
end
describe
"announcing an object"
do
test
"adds an announce activity to the db"
do
note_activity
=
insert
(
:note_activity
)
object
=
Object
.
get_by_ap_id
(
note_activity
.
data
[
"object"
][
"id"
])
user
=
insert
(
:user
)
{
:ok
,
announce_activity
,
object
}
=
ActivityPub
.
announce
(
user
,
object
)
assert
object
.
data
[
"announcement_count"
]
==
1
assert
object
.
data
[
"announcements"
]
==
[
user
.
ap_id
]
assert
announce_activity
.
data
[
"to"
]
==
[
User
.
ap_followers
(
user
)]
assert
announce_activity
.
data
[
"object"
]
==
object
.
data
[
"id"
]
assert
announce_activity
.
data
[
"actor"
]
==
user
.
ap_id
end
end
describe
"uploading files"
do
test
"copies the file to the configured folder"
do
file
=
%
Plug
.
Upload
{
content_type:
"image/jpg"
,
path:
Path
.
absname
(
"test/fixtures/image.jpg"
),
filename:
"an_image.jpg"
}
...
...
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