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
b4499586
Commit
b4499586
authored
Jan 16, 2019
by
rinpatch
Browse files
Replace map with reduce to remove nils
parent
ff01fd3c
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/metadata/opengraph.ex
View file @
b4499586
...
...
@@ -50,23 +50,25 @@ def build_tags(%{user: user}) do
end
end
defp
build_attachments
(
activity
)
do
Enum
.
reduce
(
activity
.
data
[
"object"
][
"
attachment
"
]
,
[],
fn
attachment
,
acc
->
defp
build_attachments
(
%{
data:
%{
"object"
=>
%{
"attachment"
=>
attachments
}}}
=
_
activity
)
do
Enum
.
reduce
(
attachment
s
,
[],
fn
attachment
,
acc
->
rendered_tags
=
Enum
.
map
(
attachment
[
"url"
],
fn
url
->
Enum
.
reduce
(
attachment
[
"url"
],
[],
fn
url
,
acc
->
media_type
=
Enum
.
find
([
"image"
,
"audio"
,
"video"
],
fn
media_type
->
String
.
starts_with?
(
url
[
"mediaType"
],
media_type
)
end
)
if
media_type
do
{
:meta
,
[
property:
"og:"
<>
media_type
,
content:
attachment_url
(
url
[
"href"
])],
[]}
[
{
:meta
,
[
property:
"og:"
<>
media_type
,
content:
attachment_url
(
url
[
"href"
])],
[]}
|
acc
]
else
nil
acc
end
end
)
Enum
.
reject
(
rendered_tags
,
&
is_nil
/
1
)
acc
++
rendered_tags
end
)
end
...
...
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