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
f53cdabc
Commit
f53cdabc
authored
Nov 18, 2017
by
eal
Browse files
Add #nsfw tag if sensitive content bit is set
parent
4647bcd6
Pipeline
#252
passed with stage
in 2 minutes and 7 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/formatter.ex
View file @
f53cdabc
...
...
@@ -7,9 +7,10 @@ def linkify(text) do
end
@tag_regex
~r/\#\w+/u
def
parse_tags
(
text
)
do
def
parse_tags
(
text
,
data
\\
%{}
)
do
Regex
.
scan
(
@tag_regex
,
text
)
|>
Enum
.
map
(
fn
([
"#"
<>
tag
=
full_tag
])
->
{
full_tag
,
String
.
downcase
(
tag
)}
end
)
|>
(
fn
map
->
if
data
[
"sensitive"
],
do
:
[{
"#nsfw"
,
"nsfw"
}]
++
map
,
else
:
map
end
)
.
()
end
def
parse_mentions
(
text
)
do
...
...
lib/pleroma/web/common_api/common_api.ex
View file @
f53cdabc
...
...
@@ -55,7 +55,7 @@ def post(user, %{"status" => status} = data) do
mentions
<-
Formatter
.
parse_mentions
(
status
),
inReplyTo
<-
get_replied_to_activity
(
data
[
"in_reply_to_status_id"
]),
to
<-
to_for_user_and_mentions
(
user
,
mentions
,
inReplyTo
),
tags
<-
Formatter
.
parse_tags
(
status
),
tags
<-
Formatter
.
parse_tags
(
status
,
data
),
content_html
<-
make_content_html
(
status
,
mentions
,
attachments
,
tags
),
context
<-
make_context
(
inReplyTo
),
cw
<-
data
[
"spoiler_text"
],
...
...
test/web/mastodon_api/mastodon_api_controller_test.exs
View file @
f53cdabc
...
...
@@ -56,6 +56,17 @@ test "posting a status", %{conn: conn} do
assert
Repo
.
get
(
Activity
,
id
)
end
test
"posting a sensitive status"
,
%{
conn:
conn
}
do
user
=
insert
(
:user
)
conn
=
conn
|>
assign
(
:user
,
user
)
|>
post
(
"/api/v1/statuses"
,
%{
"status"
=>
"cofe"
,
"sensitive"
=>
true
})
assert
%{
"content"
=>
"cofe"
,
"id"
=>
id
,
"sensitive"
=>
true
}
=
json_response
(
conn
,
200
)
assert
Repo
.
get
(
Activity
,
id
)
end
test
"replying to a status"
,
%{
conn:
conn
}
do
user
=
insert
(
:user
)
...
...
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