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
dd12cf72
Commit
dd12cf72
authored
May 11, 2017
by
lain
Browse files
Fix cws.
parent
932e0e87
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/user.ex
View file @
dd12cf72
...
...
@@ -136,9 +136,13 @@ def following?(%User{} = follower, %User{} = followed) do
Enum
.
member?
(
follower
.
following
,
User
.
ap_followers
(
followed
))
end
def
get_by_ap_id
(
ap_id
)
do
Repo
.
get_by
(
User
,
ap_id:
ap_id
)
end
def
get_cached_by_ap_id
(
ap_id
)
do
key
=
"ap_id:
#{
ap_id
}
"
Cachex
.
get!
(
:user_cache
,
key
,
fallback:
fn
(
_
)
->
Repo
.
get_by
(
User
,
ap_id
:
ap_id
)
end
)
Cachex
.
get!
(
:user_cache
,
key
,
fallback:
fn
(
_
)
->
get_by
_
ap_id
(
ap_id
)
end
)
end
def
get_cached_by_nickname
(
nickname
)
do
...
...
lib/pleroma/web/ostatus/ostatus.ex
View file @
dd12cf72
...
...
@@ -81,11 +81,11 @@ def make_favorite(entry, doc, favorited_activity) do
end
def
get_or_try_fetching
(
entry
)
do
Logger
.
debug
(
"Trying to
f
et
ch
entry"
)
Logger
.
debug
(
"Trying to
g
et entry
from db
"
)
with
id
when
not
is_nil
(
id
)
<-
string_from_xpath
(
"//activity:object[1]/id"
,
entry
),
%
Activity
{}
=
activity
<-
Activity
.
get_create_activity_by_object_ap_id
(
id
)
do
{
:ok
,
activity
}
else
_
e
->
else
e
->
Logger
.
debug
(
"Couldn't get, will try to fetch"
)
with
href
when
not
is_nil
(
href
)
<-
string_from_xpath
(
"//activity:object[1]/link[@type=
\"
text/html
\"
]/@href"
,
entry
),
{
:ok
,
[
favorited_activity
]}
<-
fetch_activity_from_html_url
(
href
)
do
...
...
@@ -126,7 +126,7 @@ def get_content(entry) do
base_content
=
string_from_xpath
(
"//content"
,
entry
)
with
scope
when
not
is_nil
(
scope
)
<-
string_from_xpath
(
"//mastodon:scope"
,
entry
),
cw
when
not
is_nil
(
cw
)
<-
string_from_xpath
(
"//summary"
,
entry
)
do
cw
when
not
is_nil
(
cw
)
<-
string_from_xpath
(
"/
*
/summary"
,
entry
)
do
"<span class='mastodon-cw'>
#{
cw
}
</span><br>
#{
base_content
}
"
else
_e
->
base_content
end
...
...
@@ -297,7 +297,7 @@ def fetch_activity_from_html_url(url) do
with
{
:ok
,
%{
body:
body
}}
<-
@httpoison
.
get
(
url
,
[],
follow_redirect:
true
),
{
:ok
,
atom_url
}
<-
get_atom_url
(
body
),
{
:ok
,
%{
status_code:
code
,
body:
body
}}
when
code
in
200
..
299
<-
@httpoison
.
get
(
atom_url
,
[],
follow_redirect:
true
)
do
Logger
.
debug
(
"Got
#{
url
}
, handling..."
)
Logger
.
debug
(
"Got
document from
#{
url
}
, handling..."
)
handle_incoming
(
body
)
else
e
->
Logger
.
debug
(
"Couldn't get
#{
url
}
:
#{
inspect
(
e
)
}
"
)
end
...
...
test/fixtures/cw_retweet.xml
0 → 100644
View file @
dd12cf72
<?xml version="1.0"?>
<feed
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>
https://mastodon.social/users/lambadalambda.atom
</id>
<title>
Critical Value
</title>
<subtitle></subtitle>
<updated>
2017-04-16T21:47:25Z
</updated>
<logo>
https://files.mastodon.social/accounts/avatars/000/000/264/original/1429214160519.gif
</logo>
<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>
<link
rel=
"alternate"
type=
"text/html"
href=
"https://mastodon.social/@lambadalambda"
/>
<link
rel=
"self"
type=
"application/atom+xml"
href=
"https://mastodon.social/users/lambadalambda.atom"
/>
<link
rel=
"hub"
href=
"https://mastodon.social/api/push"
/>
<link
rel=
"salmon"
href=
"https://mastodon.social/api/salmon/264"
/>
<entry>
<id>
tag:mastodon.social,2017-05-11:objectId=5647963:objectType=Status
</id>
<published>
2017-05-11T10:23:15Z
</published>
<updated>
2017-05-11T10:23:15Z
</updated>
<title>
lambadalambda shared a status by Skruyb@mamot.fr
</title>
<activity:object-type>
http://activitystrea.ms/schema/1.0/activity
</activity:object-type>
<activity:verb>
http://activitystrea.ms/schema/1.0/share
</activity:verb>
<activity:object>
<id>
tag:mamot.fr,2017-05-10:objectId=1294943:objectType=Status
</id>
<published>
2017-05-10T17:31:44Z
</published>
<updated>
2017-05-10T17:31:45Z
</updated>
<title>
New status by Skruyb@mamot.fr
</title>
<author>
<id>
https://mamot.fr/users/Skruyb
</id>
<activity:object-type>
http://activitystrea.ms/schema/1.0/person
</activity:object-type>
<uri>
https://mamot.fr/users/Skruyb
</uri>
<name>
Skruyb
</name>
<email>
Skruyb@mamot.fr
</email>
<summary
type=
"html"
>
<
p
>
Fr and En.
<
br
>
Posts will disappear on a regular basis.
<
/p
>
</summary>
<link
rel=
"alternate"
type=
"text/html"
href=
"https://mamot.fr/@Skruyb"
/>
<link
rel=
"avatar"
type=
"image/jpeg"
media:width=
"120"
media:height=
"120"
href=
"https://files.mastodon.social/accounts/avatars/000/106/282/original/d95dbcfc76f77f4c.jpg"
/>
<link
rel=
"header"
type=
"image/jpeg"
media:width=
"700"
media:height=
"335"
href=
"https://files.mastodon.social/accounts/headers/000/106/282/original/c1aabdf5c97eb875.jpg"
/>
<poco:preferredUsername>
Skruyb
</poco:preferredUsername>
<poco:displayName>
The 7th Son
</poco:displayName>
<poco:note>
Fr and En.Posts will disappear on a regular basis.
</poco:note>
<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>
<summary
xml:lang=
"it"
>
Hey.
</summary>
<content
type=
"html"
xml:lang=
"it"
>
<
p
><
span class="h-card"
><
a href="https://mastodon.social/@lambadalambda"
>
@
<
span
>
lambadalambda
<
/span
><
/a
><
/span
><
/p
><
p
>
Hey!!!
<
/p
>
</content>
<link
rel=
"mentioned"
ostatus:object-type=
"http://activitystrea.ms/schema/1.0/person"
href=
"https://mastodon.social/users/lambadalambda"
/>
<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://mamot.fr/users/Skruyb/updates/176041"
/>
<thr:in-reply-to
ref=
"tag:mastodon.social,2017-05-10:objectId=5582979:objectType=Status"
href=
"https://mastodon.social/@lambadalambda/5582979"
/>
</activity:object>
<content
type=
"html"
xml:lang=
"en"
>
<
p
><
span class="h-card"
><
a href="https://mastodon.social/@lambadalambda"
>
@
<
span
>
lambadalambda
<
/span
><
/a
><
/span
><
/p
><
p
>
Hey!!!
<
/p
>
</content>
<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/2325225"
/>
<link
rel=
"self"
type=
"application/atom+xml"
href=
"https://mastodon.social/users/lambadalambda/updates/2325225.atom"
/>
</entry>
</feed>
test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom
0 → 100644
View file @
dd12cf72
This diff is collapsed.
Click to expand it.
test/fixtures/httpoison_mock/skruyb@mamot.fr.atom
0 → 100644
View file @
dd12cf72
<?xml version="1.0"?>
<XRD
xmlns=
"http://docs.oasis-open.org/ns/xri/xrd-1.0"
>
<Subject>
acct:Skruyb@mamot.fr
</Subject>
<Alias>
https://mamot.fr/@Skruyb
</Alias>
<Alias>
https://mamot.fr/users/Skruyb
</Alias>
<Link
rel=
"http://webfinger.net/rel/profile-page"
type=
"text/html"
href=
"https://mamot.fr/@Skruyb"
/>
<Link
rel=
"http://schemas.google.com/g/2010#updates-from"
type=
"application/atom+xml"
href=
"https://mamot.fr/users/Skruyb.atom"
/>
<Link
rel=
"salmon"
href=
"https://mamot.fr/api/salmon/26213"
/>
<Link
rel=
"magic-public-key"
href=
"data:application/magic-public-key,RSA.oguRI4WsZfm-6wne1Y-_y8-8QmWFOrpqfyLemzc_bX-qCttWb-TXjZhE3iv-yg79i9qcJhCKvmTKwscJTcjr0Jp2KsGTLJrUodsR0zYAhYkugdv6EJHvbJVA0bXZKCk5XieGvBn-t7xQC5mclbEgQs58kY3cavJ70b5XFFAWeDloga9G3E2TMygnuzQ3oZlxBa6b3HzjY3RxB3bYirCZLV_bipPGHkI7xr7TDV7fnGTjRm9IUz6UOboixT5UIRvZ6EZ_rCJaMIFXj47bmwj74pxiNlughYpmSLhI0Ka7hofoYmZ7CbUEfBWIzfgEiB-SO99tACy8pDwyQ5d9P7pt0w==.AQAB"
/>
<Link
rel=
"http://ostatus.org/schema/1.0/subscribe"
template=
"https://mamot.fr/authorize_follow?acct={uri}"
/>
</XRD>
test/support/httpoison_mock.ex
View file @
dd12cf72
...
...
@@ -135,6 +135,20 @@ def get("https://pawoo.net/users/pekorino.atom", _, _) do
}}
end
def
get
(
"https://mamot.fr/.well-known/webfinger"
,
[
Accept:
"application/xrd+xml"
],
[
params:
[
resource:
"https://mamot.fr/users/Skruyb"
]])
do
{
:ok
,
%
Response
{
status_code:
200
,
body:
File
.
read!
(
"test/fixtures/httpoison_mock/skruyb@mamot.fr.atom"
)
}}
end
def
get
(
"https://mamot.fr/users/Skruyb.atom"
,
_
,
_
)
do
{
:ok
,
%
Response
{
status_code:
200
,
body:
File
.
read!
(
"test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom"
)
}}
end
def
get
(
url
,
body
,
headers
)
do
{
:error
,
"Not implemented the mock response for get
#{
inspect
(
url
)
}
,
#{
inspect
(
body
)
}
,
#{
inspect
(
headers
)
}
"
}
end
...
...
test/web/ostatus/ostatus_test.exs
View file @
dd12cf72
...
...
@@ -72,6 +72,13 @@ test "handle incoming notes - Mastodon, with CW" do
assert
String
.
contains?
(
activity
.
data
[
"object"
][
"content"
],
"technologic"
)
end
test
"handle incoming retweets - Mastodon, with CW"
do
incoming
=
File
.
read!
(
"test/fixtures/cw_retweet.xml"
)
{
:ok
,
[[
activity
,
retweeted_activity
]]}
=
OStatus
.
handle_incoming
(
incoming
)
assert
String
.
contains?
(
retweeted_activity
.
data
[
"object"
][
"content"
],
"Hey."
)
end
test
"handle incoming notes - GS, subscription, reply"
do
incoming
=
File
.
read!
(
"test/fixtures/ostatus_incoming_reply.xml"
)
{
:ok
,
[
activity
]}
=
OStatus
.
handle_incoming
(
incoming
)
...
...
@@ -99,6 +106,7 @@ test "handle incoming retweets - GS, subscription" do
refute
retweeted_activity
.
local
assert
retweeted_activity
.
data
[
"object"
][
"announcement_count"
]
==
1
assert
String
.
contains?
(
retweeted_activity
.
data
[
"object"
][
"content"
],
"mastodon"
)
refute
String
.
contains?
(
retweeted_activity
.
data
[
"object"
][
"content"
],
"Test account"
)
end
test
"handle incoming retweets - GS, subscription - local message"
do
...
...
@@ -138,6 +146,7 @@ test "handle incoming retweets - Mastodon, salmon" do
assert
retweeted_activity
.
data
[
"type"
]
==
"Create"
assert
retweeted_activity
.
data
[
"actor"
]
==
"https://pleroma.soykaf.com/users/lain"
refute
retweeted_activity
.
local
refute
String
.
contains?
(
retweeted_activity
.
data
[
"object"
][
"content"
],
"Test account"
)
end
test
"handle incoming favorites - GS, websub"
do
...
...
@@ -192,8 +201,8 @@ test "handle incoming follows" do
assert
activity
.
data
[
"object"
]
==
"https://pawoo.net/users/pekorino"
refute
activity
.
local
follower
=
User
.
get_
cached_
by_ap_id
(
activity
.
data
[
"actor"
])
followed
=
User
.
get_
cached_
by_ap_id
(
activity
.
data
[
"object"
])
follower
=
User
.
get_by_ap_id
(
activity
.
data
[
"actor"
])
followed
=
User
.
get_by_ap_id
(
activity
.
data
[
"object"
])
assert
User
.
following?
(
follower
,
followed
)
end
...
...
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