Introduce comments below events

Also add tomstones

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-11-15 18:36:47 +01:00
parent 45155a3bde
commit dc07f34d78
71 changed files with 2642 additions and 879 deletions

View File

@@ -581,7 +581,7 @@ defmodule Mobilizon.EventsTest do
test "delete_comment/1 deletes the comment" do
comment = insert(:comment)
assert {:ok, %Comment{}} = Events.delete_comment(comment)
assert_raise Ecto.NoResultsError, fn -> Events.get_comment!(comment.id) end
refute is_nil(Events.get_comment!(comment.id).deleted_at)
end
end
end

View File

@@ -148,13 +148,14 @@ defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
test "it creates a delete activity and deletes the original comment" do
comment = insert(:comment)
comment = Events.get_comment_from_url_with_preload!(comment.url)
assert is_nil(Events.get_comment_from_url(comment.url).deleted_at)
{:ok, delete, _} = ActivityPub.delete(comment)
assert delete.data["type"] == "Delete"
assert delete.data["actor"] == comment.actor.url
assert delete.data["object"] == comment.url
assert Events.get_comment_from_url(comment.url) == nil
refute is_nil(Events.get_comment_from_url(comment.url).deleted_at)
end
end

View File

@@ -91,31 +91,50 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
# assert activity == returned_activity.data
# end
# test "it fetches replied-to activities if we don't have them" do
# data =
# File.read!("test/fixtures/mastodon-post-activity.json")
# |> Jason.decode!()
test "it fetches replied-to activities if we don't have them" do
data =
File.read!("test/fixtures/mastodon-post-activity.json")
|> Jason.decode!()
# object =
# data["object"]
# |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
object =
data["object"]
|> Map.put("inReplyTo", "https://blob.cat/objects/02fdea3d-932c-4348-9ecb-3f9eb3fbdd94")
# data =
# data
# |> Map.put("object", object)
data =
data
|> Map.put("object", object)
# {:ok, returned_activity, _} = Transmogrifier.handle_incoming(data)
{:ok, returned_activity, _} = Transmogrifier.handle_incoming(data)
# assert activity =
# Activity.get_create_activity_by_object_ap_id(
# "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
# )
%Comment{} =
origin_comment =
Events.get_comment_from_url(
"https://blob.cat/objects/02fdea3d-932c-4348-9ecb-3f9eb3fbdd94"
)
# assert returned_activity.data["object"]["inReplyToAtomUri"] ==
# "https://shitposter.club/notice/2827873"
assert returned_activity.data["object"]["inReplyTo"] ==
"https://blob.cat/objects/02fdea3d-932c-4348-9ecb-3f9eb3fbdd94"
# assert returned_activity.data["object"]["inReplyToStatusId"] == activity.id
# end
assert returned_activity.data["object"]["inReplyTo"] == origin_comment.url
end
test "it does not crash if the object in inReplyTo can't be fetched" do
data =
File.read!("test/fixtures/mastodon-post-activity.json")
|> Poison.decode!()
object =
data["object"]
|> Map.put("inReplyTo", "https://404.site/whatever")
data =
data
|> Map.put("object", object)
assert ExUnit.CaptureLog.capture_log([level: :warn], fn ->
{:ok, _returned_activity, _entity} = Transmogrifier.handle_incoming(data)
end) =~ "[warn] Parent object is something we don't handle"
end
test "it works for incoming notices" do
use_cassette "activity_pub/mastodon_post_activity" do
@@ -440,10 +459,11 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|> Map.put("actor", actor_url)
assert Events.get_comment_from_url(comment_url)
assert is_nil(Events.get_comment_from_url(comment_url).deleted_at)
{:ok, %Activity{local: false}, _} = Transmogrifier.handle_incoming(data)
refute Events.get_comment_from_url(comment_url)
refute is_nil(Events.get_comment_from_url(comment_url).deleted_at)
end
# TODO : make me ASAP

View File

@@ -117,37 +117,32 @@ defmodule Mobilizon.Service.FormatterTest do
describe "add_user_links" do
test "gives a replacement for user links, using local nicknames in user links text" do
text = "@gsimg According to @archa_eme_, that is @daggsy. Also hello @archaeme@archae.me"
gsimg = insert(:actor, preferred_username: "gsimg")
_gsimg = insert(:actor, preferred_username: "gsimg")
archaeme =
_archaeme =
insert(:actor, preferred_username: "archa_eme_", url: "https://archeme/@archa_eme_")
archaeme_remote = insert(:actor, preferred_username: "archaeme", domain: "archae.me")
_archaeme_remote = insert(:actor, preferred_username: "archaeme", domain: "archae.me")
{text, mentions, []} = Formatter.linkify(text)
assert length(mentions) == 3
expected_text =
"<span class='h-card'><a data-user='#{gsimg.id}' class='u-url mention' href='#{gsimg.url}'>@<span>gsimg</span></a></span> According to <span class='h-card'><a data-user='#{
archaeme.id
}' class='u-url mention' href='#{"https://archeme/@archa_eme_"}'>@<span>archa_eme_</span></a></span>, that is @daggsy. Also hello <span class='h-card'><a data-user='#{
archaeme_remote.id
}' class='u-url mention' href='#{archaeme_remote.url}'>@<span>archaeme</span></a></span>"
"<span class='h-card mention'>@<span>gsimg</span></span> According to <span class='h-card mention'>@<span>archa_eme_</span></span>, that is @daggsy. Also hello <span class='h-card mention'>@<span>archaeme</span></span>"
assert expected_text == text
end
test "gives a replacement for single-character local nicknames" do
text = "@o hi"
o = insert(:actor, preferred_username: "o")
_o = insert(:actor, preferred_username: "o")
{text, mentions, []} = Formatter.linkify(text)
assert length(mentions) == 1
expected_text =
"<span class='h-card'><a data-user='#{o.id}' class='u-url mention' href='#{o.url}'>@<span>o</span></a></span> hi"
expected_text = "<span class='h-card mention'>@<span>o</span></span> hi"
assert expected_text == text
end