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
9e411372
Commit
9e411372
authored
Jun 10, 2020
by
lain
Browse files
ActivityPub: Don't show announces of your own objects in timeline.
parent
1b746cfb
Pipeline
#27044
passed with stages
in 11 minutes and 32 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/activity_pub/activity_pub.ex
View file @
9e411372
...
...
@@ -31,25 +31,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
require
Logger
require
Pleroma
.
Constants
# For Announce activities, we filter the recipients based on following status for any actors
# that match actual users. See issue #164 for more information about why this is necessary.
defp
get_recipients
(%{
"type"
=>
"Announce"
}
=
data
)
do
to
=
Map
.
get
(
data
,
"to"
,
[])
cc
=
Map
.
get
(
data
,
"cc"
,
[])
bcc
=
Map
.
get
(
data
,
"bcc"
,
[])
actor
=
User
.
get_cached_by_ap_id
(
data
[
"actor"
])
recipients
=
Enum
.
filter
(
Enum
.
concat
([
to
,
cc
,
bcc
]),
fn
recipient
->
case
User
.
get_cached_by_ap_id
(
recipient
)
do
nil
->
true
user
->
User
.
following?
(
user
,
actor
)
end
end
)
{
recipients
,
to
,
cc
}
end
defp
get_recipients
(%{
"type"
=>
"Create"
}
=
data
)
do
to
=
Map
.
get
(
data
,
"to"
,
[])
cc
=
Map
.
get
(
data
,
"cc"
,
[])
...
...
@@ -702,6 +683,26 @@ defp user_activities_recipients(%{reading_user: reading_user}) do
end
end
defp
restrict_announce_object_actor
(
_query
,
%{
announce_filtering_user:
_
,
skip_preload:
true
})
do
raise
"Can't use the child object without preloading!"
end
defp
restrict_announce_object_actor
(
query
,
%{
announce_filtering_user:
%{
ap_id:
actor
}})
do
from
(
[
activity
,
object
]
in
query
,
where:
fragment
(
"?->>'type' != ? or ?->>'actor' != ?"
,
activity
.
data
,
"Announce"
,
object
.
data
,
^
actor
)
)
end
defp
restrict_announce_object_actor
(
query
,
_
),
do
:
query
defp
restrict_since
(
query
,
%{
since_id:
""
}),
do
:
query
defp
restrict_since
(
query
,
%{
since_id:
since_id
})
do
...
...
@@ -1113,6 +1114,7 @@ def fetch_activities_query(recipients, opts \\ %{}) do
|>
restrict_pinned
(
opts
)
|>
restrict_muted_reblogs
(
restrict_muted_reblogs_opts
)
|>
restrict_instance
(
opts
)
|>
restrict_announce_object_actor
(
opts
)
|>
Activity
.
restrict_deactivated_users
()
|>
exclude_poll_votes
(
opts
)
|>
exclude_invisible_actors
(
opts
)
...
...
lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex
View file @
9e411372
...
...
@@ -48,6 +48,7 @@ def home(%{assigns: %{user: user}} = conn, params) do
|>
Map
.
put
(
:blocking_user
,
user
)
|>
Map
.
put
(
:muting_user
,
user
)
|>
Map
.
put
(
:reply_filtering_user
,
user
)
|>
Map
.
put
(
:announce_filtering_user
,
user
)
|>
Map
.
put
(
:user
,
user
)
activities
=
...
...
test/web/activity_pub/activity_pub_test.exs
View file @
9e411372
...
...
@@ -1643,6 +1643,30 @@ test "home timeline with reply_visibility `self`", %{
assert
Enum
.
all?
(
visible_ids
,
&
(
&1
in
activities_ids
))
end
test
"filtering out announces where the user is the actor of the announced message"
do
user
=
insert
(
:user
)
other_user
=
insert
(
:user
)
third_user
=
insert
(
:user
)
User
.
follow
(
user
,
other_user
)
{
:ok
,
post
}
=
CommonAPI
.
post
(
user
,
%{
status:
"yo"
})
{
:ok
,
other_post
}
=
CommonAPI
.
post
(
third_user
,
%{
status:
"yo"
})
{
:ok
,
_announce
}
=
CommonAPI
.
repeat
(
post
.
id
,
other_user
)
{
:ok
,
_announce
}
=
CommonAPI
.
repeat
(
post
.
id
,
third_user
)
{
:ok
,
announce
}
=
CommonAPI
.
repeat
(
other_post
.
id
,
other_user
)
params
=
%{
type:
[
"Announce"
],
announce_filtering_user:
user
}
[
result
]
=
[
user
.
ap_id
|
User
.
following
(
user
)]
|>
ActivityPub
.
fetch_activities
(
params
)
assert
result
.
id
==
announce
.
id
end
end
describe
"replies filtering with private messages"
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