Skip to content
GitLab
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
7c3991f5
Commit
7c3991f5
authored
Feb 09, 2020
by
Ivan Tashkinov
Browse files
[
#1505
] Fixed `replies` serialization (included objects' ids instead of activities' ids).
parent
4e6bbdc7
Pipeline
#22636
passed with stages
in 3 minutes and 37 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/activity.ex
View file @
7c3991f5
...
...
@@ -330,23 +330,4 @@ def direct_conversation_id(activity, for_user) do
_
->
nil
end
end
def
replies
(
activity
,
opts
\\
[])
do
object
=
Object
.
normalize
(
activity
)
query
=
Activity
|>
Queries
.
by_type
(
"Create"
)
|>
Queries
.
by_object_in_reply_to_id
(
object
.
data
[
"id"
],
skip_preloading:
true
)
|>
order_by
([
activity
],
asc:
activity
.
id
)
if
opts
[
:self_only
]
do
where
(
query
,
[
a
],
a
.
actor
==
^
activity
.
actor
)
else
query
end
end
def
self_replies
(
activity
,
opts
\\
[]),
do
:
replies
(
activity
,
Keyword
.
put
(
opts
,
:self_only
,
true
))
end
lib/pleroma/object.ex
View file @
7c3991f5
...
...
@@ -301,4 +301,26 @@ def update_data(%Object{data: data} = object, attrs \\ %{}) do
def
local?
(%
Object
{
data:
%{
"id"
=>
id
}})
do
String
.
starts_with?
(
id
,
Pleroma
.
Web
.
base_url
()
<>
"/"
)
end
def
replies
(
object
,
opts
\\
[])
do
object
=
Object
.
normalize
(
object
)
query
=
Object
|>
where
(
[
o
],
fragment
(
"(?)->>'inReplyTo' = ?"
,
o
.
data
,
^
object
.
data
[
"id"
])
)
|>
order_by
([
o
],
asc:
o
.
id
)
if
opts
[
:self_only
]
do
actor
=
object
.
data
[
"actor"
]
where
(
query
,
[
o
],
fragment
(
"(?)->>'actor' = ?"
,
o
.
data
,
^
actor
))
else
query
end
end
def
self_replies
(
object
,
opts
\\
[]),
do
:
replies
(
object
,
Keyword
.
put
(
opts
,
:self_only
,
true
))
end
lib/pleroma/web/activity_pub/transmogrifier.ex
View file @
7c3991f5
...
...
@@ -407,7 +407,7 @@ def handle_incoming(
with
nil
<-
Activity
.
get_create_by_object_ap_id
(
object
[
"id"
]),
{
:ok
,
%
User
{}
=
user
}
<-
User
.
get_or_fetch_by_ap_id
(
data
[
"actor"
])
do
options
=
Keyword
.
put
(
options
,
:depth
,
(
options
[
:depth
]
||
0
)
+
1
)
object
=
fix_object
(
data
[
"
object
"
]
,
options
)
object
=
fix_object
(
object
,
options
)
params
=
%{
to:
data
[
"to"
],
...
...
@@ -913,20 +913,20 @@ def set_reply_to_uri(obj), do: obj
Serialized Mastodon-compatible `replies` collection containing _self-replies_.
Based on Mastodon's ActivityPub::NoteSerializer#replies.
"""
def
set_replies
(
obj
)
do
def
set_replies
(
obj
_data
)
do
limit
=
Pleroma
.
Config
.
get
([
:activitypub
,
:note_replies_output_limit
],
0
)
replies_uris
=
with
true
<-
limit
>
0
||
nil
,
%
Activity
{}
=
activity
<-
Activity
.
get_create_by_object
_ap_id
(
obj
[
"id"
])
do
activity
|>
Activity
.
self_replies
()
|>
select
([
a
],
fragment
(
"?->>'id'"
,
a
.
data
))
%
Object
{}
=
object
<-
Object
.
get_cached_by
_ap_id
(
obj
_data
[
"id"
])
do
object
|>
Object
.
self_replies
()
|>
select
([
o
],
fragment
(
"?->>'id'"
,
o
.
data
))
|>
limit
(
^
limit
)
|>
Repo
.
all
()
end
set_replies
(
obj
,
replies_uris
||
[])
set_replies
(
obj
_data
,
replies_uris
||
[])
end
defp
set_replies
(
obj
,
replies_uris
)
when
replies_uris
in
[
nil
,
[]]
do
...
...
@@ -952,7 +952,7 @@ defp set_replies(obj, replies_uris) do
Map
.
merge
(
obj
,
%{
"replies"
=>
replies_collection
})
end
def
replies
(%{
"replies"
=>
replies
=
%{}}
)
do
def
replies
(%{
"replies"
=>
replies
}
=
_object
)
when
is_map
(
replies
)
do
replies
=
if
is_map
(
replies
[
"first"
])
do
replies
[
"first"
]
...
...
test/web/activity_pub/transmogrifier_test.exs
View file @
7c3991f5
...
...
@@ -2133,7 +2133,7 @@ test "sets `replies` collection with a limited number of self-replies" do
})
object
=
Object
.
normalize
(
activity
)
replies_uris
=
Enum
.
map
([
self_reply1
,
self_reply2
],
fn
a
->
a
.
data
[
"id"
]
end
)
replies_uris
=
Enum
.
map
([
self_reply1
,
self_reply2
],
fn
a
->
a
.
object
.
data
[
"id"
]
end
)
assert
%{
"type"
=>
"Collection"
,
...
...
test/web/activity_pub/views/object_view_test.exs
View file @
7c3991f5
...
...
@@ -48,8 +48,8 @@ test "renders `replies` collection for a note activity" do
{
:ok
,
self_reply1
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"self-reply 1"
,
"in_reply_to_status_id"
=>
activity
.
id
})
replies_uris
=
[
self_reply1
.
object
.
data
[
"id"
]]
result
=
ObjectView
.
render
(
"object.json"
,
%{
object:
refresh_record
(
activity
)})
replies_uris
=
[
self_reply1
.
data
[
"id"
]]
assert
%{
"type"
=>
"Collection"
,
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment