only put linked mfm in source #171

Merged
floatingghost merged 3 commits from strip-mfm-policy into develop 2022-08-17 09:35:12 +00:00
3 changed files with 8 additions and 12 deletions
Showing only changes of commit 4b095d9f1c - Show all commits

View file

@ -119,7 +119,7 @@ defp fix_misskey_content(
{linked, _, _} =
Utils.format_input(content, "text/x.misskeymarkdown", mention_handler: mention_handler)
Map.put(object, "content", linked)
put_in(object, ["source", "content"], linked)
end
defp fix_misskey_content(%{"_misskey_content" => content} = object) when is_binary(content) do
@ -132,10 +132,9 @@ defp fix_misskey_content(%{"_misskey_content" => content} = object) when is_bina
object
|> Map.put("source", %{
"content" => content,
"content" => linked,
"mediaType" => "text/x.misskeymarkdown"
})
|> Map.put("content", linked)
|> Map.delete("_misskey_content")
end

View file

@ -3,7 +3,7 @@
"type": "Note",
"attributedTo": "https://misskey.local.live/users/92hzkskwgy",
"summary": null,
"content": "this gets replaced",
"content": "this does not get replaced",
"source": {
"content": "@akkoma_user @remote_user @full_tag_remote_user@misskey.local.live @oops_not_a_mention linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
"mediaType": "text/x.misskeymarkdown"

View file

@ -96,10 +96,9 @@ test "a misskey MFM status with a content field should work and be linked", _ do
%{
valid?: true,
changes: %{
content: content,
content: "this does not get replaced",
source: %{
"content" =>
"@akkoma_user @remote_user @full_tag_remote_user@misskey.local.live @oops_not_a_mention linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
"content" => content,
"mediaType" => "text/x.misskeymarkdown"
}
}
@ -129,22 +128,20 @@ test "a misskey MFM status with a _misskey_content field should work and be link
|> File.read!()
|> Jason.decode!()
expected_content =
"<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span> linkifylink <a class=\"hashtag\" data-tag=\"dancedance\" href=\"http://localhost:4001/tag/dancedance\">#dancedance</a> $[jelly mfm goes here] <br><br>## aaa"
changes = ArticleNotePageValidator.cast_and_validate(note)
%{
valid?: true,
changes: %{
source: %{
"content" => "@akkoma_user linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
"content" => content,
"mediaType" => "text/x.misskeymarkdown"
}
}
} = changes
assert changes.changes[:content] == expected_content
assert content =~
"<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span>"
end
end
end