Parse mentions, save them, output them in TwAPI.
This commit is contained in:
parent
2e88cc4cbd
commit
a83fa053de
4 changed files with 93 additions and 17 deletions
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
|
||||
test "an activity" do
|
||||
{:ok, user} = UserBuilder.insert
|
||||
{:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
|
||||
{:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
|
||||
|
||||
object = %Object{
|
||||
|
|
@ -22,7 +23,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
}
|
||||
}
|
||||
|
||||
content = "Some content"
|
||||
content = "Some content mentioning @shp"
|
||||
date = DateTime.utc_now() |> DateTime.to_iso8601
|
||||
|
||||
activity = %Activity{
|
||||
|
|
@ -31,7 +32,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
"type" => "Create",
|
||||
"to" => [
|
||||
User.ap_followers(user),
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
mentioned_user.ap_id
|
||||
],
|
||||
"actor" => User.ap_id(user),
|
||||
"object" => %{
|
||||
|
|
@ -62,9 +64,12 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
"statusnet_conversation_id" => 4711,
|
||||
"attachments" => [
|
||||
ObjectRepresenter.to_map(object)
|
||||
],
|
||||
"attentions" => [
|
||||
UserRepresenter.to_map(mentioned_user, %{for: follower})
|
||||
]
|
||||
}
|
||||
|
||||
assert ActivityRepresenter.to_map(activity, %{user: user, for: follower}) == expected_status
|
||||
assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
|
||||
|
||||
test "create a status" do
|
||||
user = UserBuilder.build
|
||||
user = UserBuilder.build(%{ap_id: "142344"})
|
||||
_mentioned_user = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
|
||||
|
||||
object_data = %{
|
||||
"type" => "Image",
|
||||
"url" => [
|
||||
|
|
@ -22,17 +24,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
object = Repo.insert!(%Object{data: object_data})
|
||||
|
||||
input = %{
|
||||
"status" => "Hello again.",
|
||||
"status" => "Hello again, @shp.<script></script>",
|
||||
"media_ids" => [object.id]
|
||||
}
|
||||
|
||||
{ :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input)
|
||||
|
||||
assert get_in(activity.data, ["object", "content"]) == "Hello again."
|
||||
assert get_in(activity.data, ["object", "content"]) == "Hello again, <a href='shp'>@shp</a>."
|
||||
assert get_in(activity.data, ["object", "type"]) == "Note"
|
||||
assert get_in(activity.data, ["actor"]) == User.ap_id(user)
|
||||
assert get_in(activity.data, ["actor"]) == user.ap_id
|
||||
assert Enum.member?(get_in(activity.data, ["to"]), User.ap_followers(user))
|
||||
assert Enum.member?(get_in(activity.data, ["to"]), "https://www.w3.org/ns/activitystreams#Public")
|
||||
assert Enum.member?(get_in(activity.data, ["to"]), "shp")
|
||||
|
||||
# Add a context + 'statusnet_conversation_id'
|
||||
assert is_binary(get_in(activity.data, ["context"]))
|
||||
|
|
@ -44,7 +47,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
test "create a status that is a reply" do
|
||||
user = UserBuilder.build
|
||||
user = UserBuilder.build(%{ap_id: "some_cool_id"})
|
||||
input = %{
|
||||
"status" => "Hello again."
|
||||
}
|
||||
|
|
@ -64,6 +67,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
assert get_in(reply.data, ["object", "statusnetConversationId"]) == get_in(activity.data, ["object", "statusnetConversationId"])
|
||||
assert get_in(reply.data, ["object", "inReplyTo"]) == get_in(activity.data, ["object", "id"])
|
||||
assert get_in(reply.data, ["object", "inReplyToStatusId"]) == activity.id
|
||||
assert Enum.member?(get_in(reply.data, ["to"]), "some_cool_id")
|
||||
end
|
||||
|
||||
test "fetch public statuses" do
|
||||
|
|
@ -141,4 +145,30 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
assert is_binary(response)
|
||||
end
|
||||
|
||||
test "it can parse mentions and return the relevant users" do
|
||||
text = "@gsimg According to @archaeme , that is @daggsy."
|
||||
|
||||
{:ok, gsimg} = UserBuilder.insert(%{nickname: "gsimg"})
|
||||
{:ok, archaeme} = UserBuilder.insert(%{nickname: "archaeme"})
|
||||
|
||||
expected_result = [
|
||||
{"@gsimg", gsimg},
|
||||
{"@archaeme", archaeme}
|
||||
]
|
||||
|
||||
assert TwitterAPI.parse_mentions(text) == expected_result
|
||||
end
|
||||
|
||||
test "it adds user links to an existing text" do
|
||||
text = "@gsimg According to @archaeme , that is @daggsy."
|
||||
|
||||
{:ok, _gsimg} = UserBuilder.insert(%{nickname: "gsimg", ap_id: "first_link" })
|
||||
{:ok, _archaeme} = UserBuilder.insert(%{nickname: "archaeme", ap_id: "second_link"})
|
||||
|
||||
mentions = TwitterAPI.parse_mentions(text)
|
||||
expected_text = "<a href='first_link'>@gsimg</a> According to <a href='second_link'>@archaeme</a> , that is @daggsy."
|
||||
|
||||
assert TwitterAPI.add_user_links(text, mentions) == expected_text
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue