Add attachment link to posts.

This commit is contained in:
Roger Braun 2017-05-02 18:25:39 +02:00
parent b104348fa5
commit 33c803d6da
2 changed files with 14 additions and 2 deletions

View File

@ -32,11 +32,23 @@ def get_replied_to_activity(id) when not is_nil(id) do
def get_replied_to_activity(_), do: nil def get_replied_to_activity(_), do: nil
def add_attachments(text, attachments) do
attachment_text = Enum.map(attachments, fn
(%{"url" => [%{"href" => href} | _]}) ->
"<a href='#{href}'>#{href}</a>"
_ -> ""
end)
Enum.join([text | attachment_text], "<br>")
end
def create_status(user = %User{}, data = %{"status" => status}) do def create_status(user = %User{}, data = %{"status" => status}) do
attachments = attachments_from_ids(data["media_ids"]) attachments = attachments_from_ids(data["media_ids"])
context = ActivityPub.generate_context_id context = ActivityPub.generate_context_id
mentions = parse_mentions(status) mentions = parse_mentions(status)
content_html = format_input(status, mentions) content_html = status
|> format_input(mentions)
|> add_attachments(attachments)
to = to_for_user_and_mentions(user, mentions) to = to_for_user_and_mentions(user, mentions)
date = make_date() date = make_date()

View File

@ -33,7 +33,7 @@ test "create a status" do
{ :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input) { :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input)
assert get_in(activity.data, ["object", "content"]) == "Hello again, <a href='shp'>@shp</a>.<br>This is on another line." assert get_in(activity.data, ["object", "content"]) == "Hello again, <a href='shp'>@shp</a>.<br>This is on another line.<br><a href='http://example.org/image.jpg'>http://example.org/image.jpg</a>"
assert get_in(activity.data, ["object", "type"]) == "Note" assert get_in(activity.data, ["object", "type"]) == "Note"
assert get_in(activity.data, ["object", "actor"]) == user.ap_id assert get_in(activity.data, ["object", "actor"]) == user.ap_id
assert get_in(activity.data, ["actor"]) == user.ap_id assert get_in(activity.data, ["actor"]) == user.ap_id