forked from YokaiRick/akkoma
Merge branch 'fix/issue_272' into 'develop'
[#272] fix tags See merge request pleroma/pleroma!540
This commit is contained in:
commit
acec11626d
2 changed files with 49 additions and 2 deletions
|
@ -140,7 +140,7 @@ def render("status.json", %{activity: %{data: %{"object" => object}} = activity}
|
||||||
visibility: get_visibility(object),
|
visibility: get_visibility(object),
|
||||||
media_attachments: attachments |> Enum.take(4),
|
media_attachments: attachments |> Enum.take(4),
|
||||||
mentions: mentions,
|
mentions: mentions,
|
||||||
tags: tags,
|
tags: build_tags(tags),
|
||||||
application: %{
|
application: %{
|
||||||
name: "Web",
|
name: "Web",
|
||||||
website: nil
|
website: nil
|
||||||
|
@ -234,6 +234,27 @@ def render_content(%{"type" => object_type} = object)
|
||||||
|
|
||||||
def render_content(object), do: object["content"] || ""
|
def render_content(object), do: object["content"] || ""
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Builds a dictionary tags.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> Pleroma.Web.MastodonAPI.StatusView.build_tags(["fediverse", "nextcloud"])
|
||||||
|
[{"name": "fediverse", "url": "/tag/fediverse"},
|
||||||
|
{"name": "nextcloud", "url": "/tag/nextcloud"}]
|
||||||
|
|
||||||
|
"""
|
||||||
|
@spec build_tags(list(any())) :: list(map())
|
||||||
|
def build_tags(object_tags) when is_list(object_tags) do
|
||||||
|
object_tags = for tag when is_binary(tag) <- object_tags, do: tag
|
||||||
|
|
||||||
|
Enum.reduce(object_tags, [], fn tag, tags ->
|
||||||
|
tags ++ [%{name: tag, url: "/tag/#{tag}"}]
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_tags(_), do: []
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Builds list emojis.
|
Builds list emojis.
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,12 @@ test "a note activity" do
|
||||||
visibility: "public",
|
visibility: "public",
|
||||||
media_attachments: [],
|
media_attachments: [],
|
||||||
mentions: [],
|
mentions: [],
|
||||||
tags: note.data["object"]["tag"],
|
tags: [
|
||||||
|
%{
|
||||||
|
name: "#{note.data["object"]["tag"]}",
|
||||||
|
url: "/tag/#{note.data["object"]["tag"]}"
|
||||||
|
}
|
||||||
|
],
|
||||||
application: %{
|
application: %{
|
||||||
name: "Web",
|
name: "Web",
|
||||||
website: nil
|
website: nil
|
||||||
|
@ -151,4 +156,25 @@ test "a reblog" do
|
||||||
assert represented[:reblog][:id] == to_string(activity.id)
|
assert represented[:reblog][:id] == to_string(activity.id)
|
||||||
assert represented[:emojis] == []
|
assert represented[:emojis] == []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "build_tags/1" do
|
||||||
|
test "it returns a a dictionary tags" do
|
||||||
|
object_tags = [
|
||||||
|
"fediverse",
|
||||||
|
"mastodon",
|
||||||
|
"nextcloud",
|
||||||
|
%{
|
||||||
|
"href" => "https://kawen.space/users/lain",
|
||||||
|
"name" => "@lain@kawen.space",
|
||||||
|
"type" => "Mention"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
assert StatusView.build_tags(object_tags) == [
|
||||||
|
%{name: "fediverse", url: "/tag/fediverse"},
|
||||||
|
%{name: "mastodon", url: "/tag/mastodon"},
|
||||||
|
%{name: "nextcloud", url: "/tag/nextcloud"}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue