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
959e993c
Commit
959e993c
authored
Sep 16, 2017
by
lain
Browse files
Apply incoming custom emoji.
parent
16b1fcd2
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/formatter.ex
View file @
959e993c
...
...
@@ -95,8 +95,14 @@ def parse_mentions(text) do
@emoji
@finmoji_with_filenames
def
emojify
(
text
)
do
Enum
.
reduce
(
@emoji
,
text
,
fn
({
emoji
,
file
},
text
)
->
def
emojify
(
text
,
additional
\\
nil
)
do
all_emoji
=
if
additional
do
@emoji
++
Map
.
to_list
(
additional
)
else
@emoji
end
Enum
.
reduce
(
all_emoji
,
text
,
fn
({
emoji
,
file
},
text
)
->
String
.
replace
(
text
,
":
#{
emoji
}
:"
,
"<img height='32px' width='32px' alt='
#{
emoji
}
' title='
#{
emoji
}
' src='
#{
file
}
' />"
)
end
)
end
...
...
lib/pleroma/web/twitter_api/representers/activity_representer.ex
View file @
959e993c
...
...
@@ -135,11 +135,13 @@ def to_map(%Activity{data: %{"object" => %{"content" => content} = object}} = ac
tags
=
activity
.
data
[
"object"
][
"tag"
]
||
[]
possibly_sensitive
=
Enum
.
member?
(
tags
,
"nsfw"
)
html
=
HtmlSanitizeEx
.
basic_html
(
content
)
|>
Formatter
.
emojify
(
object
[
"emoji"
])
%{
"id"
=>
activity
.
id
,
"uri"
=>
activity
.
data
[
"object"
][
"id"
],
"user"
=>
UserView
.
render
(
"show.json"
,
%{
user:
user
,
for:
opts
[
:for
]}),
"statusnet_html"
=>
HtmlSanitizeEx
.
basic_html
(
content
)
|>
Formatter
.
emojify
,
"statusnet_html"
=>
html
,
"text"
=>
HtmlSanitizeEx
.
strip_tags
(
content
),
"is_local"
=>
activity
.
local
,
"is_post_verb"
=>
true
,
...
...
test/web/twitter_api/representers/activity_representer_test.exs
View file @
959e993c
...
...
@@ -70,7 +70,7 @@ test "an activity" do
}
}
content_html
=
"<script>alert('YAY')</script>Some content mentioning <a href='
#{
mentioned_user
.
ap_id
}
'>@shp</shp>"
content_html
=
"<script>alert('YAY')</script>Some
:2hu:
content mentioning <a href='
#{
mentioned_user
.
ap_id
}
'>@shp</shp>"
content
=
HtmlSanitizeEx
.
strip_tags
(
content_html
)
date
=
DateTime
.
from_naive!
(
~N[2016-05-24 13:26:08.003]
,
"Etc/UTC"
)
|>
DateTime
.
to_iso8601
...
...
@@ -99,7 +99,10 @@ test "an activity" do
"like_count"
=>
5
,
"announcement_count"
=>
3
,
"context"
=>
"2hu"
,
"tag"
=>
[
"content"
,
"mentioning"
,
"nsfw"
]
"tag"
=>
[
"content"
,
"mentioning"
,
"nsfw"
],
"emoji"
=>
%{
"2hu"
=>
"corndog.png"
}
},
"published"
=>
date
,
"context"
=>
"2hu"
...
...
@@ -107,12 +110,13 @@ test "an activity" do
local:
false
}
expected_html
=
"alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=
\"
#{
mentioned_user
.
ap_id
}
\"
>@shp</a>"
expected_status
=
%{
"id"
=>
activity
.
id
,
"user"
=>
UserView
.
render
(
"show.json"
,
%{
user:
user
,
for:
follower
}),
"is_local"
=>
false
,
"statusnet_html"
=>
HtmlSanitizeEx
.
basic_html
(
content
_html
)
,
"statusnet_html"
=>
expected
_html
,
"text"
=>
content
,
"is_post_verb"
=>
true
,
"created_at"
=>
"Tue May 24 13:26:08 +0000 2016"
,
...
...
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