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
018a1a39
Commit
018a1a39
authored
May 02, 2017
by
lain
Browse files
Use inReplyTo to find context.
parent
33c803d6
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/ostatus/ostatus.ex
View file @
018a1a39
...
...
@@ -44,13 +44,19 @@ def handle_note(entry, doc \\ nil) do
[
author
]
=
:xmerl_xpath
.
string
(
'//author[1]'
,
doc
)
{
:ok
,
actor
}
=
find_make_or_update_user
(
author
)
inReplyTo
=
string_from_xpath
(
"/entry/thr:in-reply-to[1]/@ref"
,
entry
)
context
=
(
string_from_xpath
(
"/entry/ostatus:conversation[1]"
,
entry
)
||
""
)
|>
String
.
trim
context
=
if
String
.
length
(
context
)
>
0
do
context
else
ActivityPub
.
generate_context_id
end
context
=
with
%{
data:
%{
"context"
=>
context
}}
<-
Object
.
get_cached_by_ap_id
(
inReplyTo
)
do
context
else
_e
->
if
String
.
length
(
context
)
>
0
do
context
else
ActivityPub
.
generate_context_id
end
end
to
=
[
"https://www.w3.org/ns/activitystreams#Public"
...
...
@@ -74,8 +80,6 @@ def handle_note(entry, doc \\ nil) do
"actor"
=>
actor
.
ap_id
}
inReplyTo
=
string_from_xpath
(
"/entry/thr:in-reply-to[1]/@ref"
,
entry
)
object
=
if
inReplyTo
do
Map
.
put
(
object
,
"inReplyTo"
,
inReplyTo
)
else
...
...
test/fixtures/incoming_reply_mastodon.xml
0 → 100644
View file @
018a1a39
<?xml version="1.0"?>
<entry
xmlns=
"http://www.w3.org/2005/Atom"
xmlns:thr=
"http://purl.org/syndication/thread/1.0"
xmlns:activity=
"http://activitystrea.ms/spec/1.0/"
xmlns:poco=
"http://portablecontacts.net/spec/1.0"
xmlns:media=
"http://purl.org/syndication/atommedia"
xmlns:ostatus=
"http://ostatus.org/schema/1.0"
xmlns:mastodon=
"http://mastodon.social/schema/1.0"
>
<id>
tag:mastodon.social,2017-05-02:objectId=4901603:objectType=Status
</id>
<published>
2017-05-02T18:33:06Z
</published>
<updated>
2017-05-02T18:33:06Z
</updated>
<title>
New status by lambadalambda
</title>
<author>
<id>
https://mastodon.social/users/lambadalambda
</id>
<activity:object-type>
http://activitystrea.ms/schema/1.0/person
</activity:object-type>
<uri>
https://mastodon.social/users/lambadalambda
</uri>
<name>
lambadalambda
</name>
<email>
lambadalambda@mastodon.social
</email>
<link
rel=
"alternate"
type=
"text/html"
href=
"https://mastodon.social/@lambadalambda"
/>
<link
rel=
"avatar"
type=
"image/gif"
media:width=
"120"
media:height=
"120"
href=
"https://files.mastodon.social/accounts/avatars/000/000/264/original/1429214160519.gif"
/>
<link
rel=
"header"
type=
""
media:width=
"700"
media:height=
"335"
href=
"/headers/original/missing.png"
/>
<poco:preferredUsername>
lambadalambda
</poco:preferredUsername>
<poco:displayName>
Critical Value
</poco:displayName>
<mastodon:scope>
public
</mastodon:scope>
</author>
<activity:object-type>
http://activitystrea.ms/schema/1.0/comment
</activity:object-type>
<activity:verb>
http://activitystrea.ms/schema/1.0/post
</activity:verb>
<content
type=
"html"
xml:lang=
"el"
>
<
p
><
span class="h-card"
><
a href="https://pleroma.soykaf.com/users/lain" class="u-url mention"
>
@
<
span
>
lain
<
/span
><
/a
><
/span
>
hey
<
/p
>
</content>
<link
rel=
"mentioned"
ostatus:object-type=
"http://activitystrea.ms/schema/1.0/person"
href=
"https://pleroma.soykaf.com/users/lain"
/>
<link
rel=
"mentioned"
ostatus:object-type=
"http://activitystrea.ms/schema/1.0/collection"
href=
"http://activityschema.org/collection/public"
/>
<mastodon:scope>
public
</mastodon:scope>
<link
rel=
"alternate"
type=
"text/html"
href=
"https://mastodon.social/users/lambadalambda/updates/2224923"
/>
<link
rel=
"self"
type=
"application/atom+xml"
href=
"https://mastodon.social/users/lambadalambda/updates/2224923.atom"
/>
<thr:in-reply-to
ref=
"https://pleroma.soykaf.com/objects/c237d966-ac75-4fe3-a87a-d89d71a3a7a4"
href=
""
/>
</entry>
test/web/ostatus/ostatus_test.exs
View file @
018a1a39
...
...
@@ -2,6 +2,7 @@ defmodule Pleroma.Web.OStatusTest do
use
Pleroma
.
DataCase
alias
Pleroma
.
Web
.
OStatus
alias
Pleroma
.
Web
.
XML
alias
Pleroma
.
{
Object
,
Repo
}
test
"don't insert create notes twice"
do
incoming
=
File
.
read!
(
"test/fixtures/incoming_note_activity.xml"
)
...
...
@@ -32,6 +33,22 @@ test "handle incoming notes - GS, subscription" do
assert
activity
.
data
[
"object"
][
"content"
]
==
"Will it blend?"
end
test
"handle incoming notes - Mastodon, salmon, reply"
do
# It uses the context of the replied to object
Repo
.
insert!
(%
Object
{
data:
%{
"id"
=>
"https://pleroma.soykaf.com/objects/c237d966-ac75-4fe3-a87a-d89d71a3a7a4"
,
"context"
=>
"2hu"
}})
incoming
=
File
.
read!
(
"test/fixtures/incoming_reply_mastodon.xml"
)
{
:ok
,
[
activity
]}
=
OStatus
.
handle_incoming
(
incoming
)
assert
activity
.
data
[
"type"
]
==
"Create"
assert
activity
.
data
[
"object"
][
"type"
]
==
"Note"
assert
activity
.
data
[
"object"
][
"actor"
]
==
"https://mastodon.social/users/lambadalambda"
assert
activity
.
data
[
"context"
]
==
"2hu"
end
test
"handle incoming notes - GS, subscription, reply"
do
incoming
=
File
.
read!
(
"test/fixtures/ostatus_incoming_reply.xml"
)
{
:ok
,
[
activity
]}
=
OStatus
.
handle_incoming
(
incoming
)
...
...
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