Merge branch 'feature/render-mentions-for-tags' into 'develop'
Create mentions only for explicitly mentioned users Closes #999 See merge request pleroma/pleroma!1375
This commit is contained in:
commit
b972b972e0
|
@ -149,8 +149,14 @@ def render("status.json", %{activity: %{data: %{"object" => _object}} = activity
|
||||||
tags = object.data["tag"] || []
|
tags = object.data["tag"] || []
|
||||||
sensitive = object.data["sensitive"] || Enum.member?(tags, "nsfw")
|
sensitive = object.data["sensitive"] || Enum.member?(tags, "nsfw")
|
||||||
|
|
||||||
|
tag_mentions =
|
||||||
|
tags
|
||||||
|
|> Enum.filter(fn tag -> is_map(tag) and tag["type"] == "Mention" end)
|
||||||
|
|> Enum.map(fn tag -> tag["href"] end)
|
||||||
|
|
||||||
mentions =
|
mentions =
|
||||||
activity.recipients
|
(object.data["to"] ++ tag_mentions)
|
||||||
|
|> Enum.uniq()
|
||||||
|> Enum.map(fn ap_id -> User.get_cached_by_ap_id(ap_id) end)
|
|> Enum.map(fn ap_id -> User.get_cached_by_ap_id(ap_id) end)
|
||||||
|> Enum.filter(& &1)
|
|> Enum.filter(& &1)
|
||||||
|> Enum.map(fn user -> AccountView.render("mention.json", %{user: user}) end)
|
|> Enum.map(fn user -> AccountView.render("mention.json", %{user: user}) end)
|
||||||
|
|
|
@ -117,6 +117,7 @@ def direct_note_activity_factory do
|
||||||
def note_activity_factory(attrs \\ %{}) do
|
def note_activity_factory(attrs \\ %{}) do
|
||||||
user = attrs[:user] || insert(:user)
|
user = attrs[:user] || insert(:user)
|
||||||
note = attrs[:note] || insert(:note, user: user)
|
note = attrs[:note] || insert(:note, user: user)
|
||||||
|
attrs = Map.drop(attrs, [:user, :note])
|
||||||
|
|
||||||
data = %{
|
data = %{
|
||||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||||
|
@ -133,6 +134,7 @@ def note_activity_factory(attrs \\ %{}) do
|
||||||
actor: data["actor"],
|
actor: data["actor"],
|
||||||
recipients: data["to"]
|
recipients: data["to"]
|
||||||
}
|
}
|
||||||
|
|> Map.merge(attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
def article_activity_factory do
|
def article_activity_factory do
|
||||||
|
|
|
@ -1234,7 +1234,6 @@ test "returns created dm", %{conn: conn} do
|
||||||
|
|
||||||
recipients = Enum.map(response["mentions"], & &1["username"])
|
recipients = Enum.map(response["mentions"], & &1["username"])
|
||||||
|
|
||||||
assert conn.assigns[:user].nickname in recipients
|
|
||||||
assert reporter.nickname in recipients
|
assert reporter.nickname in recipients
|
||||||
assert response["content"] == "I will check it out"
|
assert response["content"] == "I will check it out"
|
||||||
assert response["visibility"] == "direct"
|
assert response["visibility"] == "direct"
|
||||||
|
|
|
@ -203,10 +203,71 @@ test "contains mentions" do
|
||||||
|
|
||||||
status = StatusView.render("status.json", %{activity: activity})
|
status = StatusView.render("status.json", %{activity: activity})
|
||||||
|
|
||||||
actor = User.get_cached_by_ap_id(activity.actor)
|
|
||||||
|
|
||||||
assert status.mentions ==
|
assert status.mentions ==
|
||||||
Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end)
|
Enum.map([user], fn u -> AccountView.render("mention.json", %{user: u}) end)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "create mentions from the 'to' field" do
|
||||||
|
%User{ap_id: recipient_ap_id} = insert(:user)
|
||||||
|
cc = insert_pair(:user) |> Enum.map(& &1.ap_id)
|
||||||
|
|
||||||
|
object =
|
||||||
|
insert(:note, %{
|
||||||
|
data: %{
|
||||||
|
"to" => [recipient_ap_id],
|
||||||
|
"cc" => cc
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
activity =
|
||||||
|
insert(:note_activity, %{
|
||||||
|
note: object,
|
||||||
|
recipients: [recipient_ap_id | cc]
|
||||||
|
})
|
||||||
|
|
||||||
|
assert length(activity.recipients) == 3
|
||||||
|
|
||||||
|
%{mentions: [mention] = mentions} = StatusView.render("status.json", %{activity: activity})
|
||||||
|
|
||||||
|
assert length(mentions) == 1
|
||||||
|
assert mention.url == recipient_ap_id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "create mentions from the 'tag' field" do
|
||||||
|
recipient = insert(:user)
|
||||||
|
cc = insert_pair(:user) |> Enum.map(& &1.ap_id)
|
||||||
|
|
||||||
|
object =
|
||||||
|
insert(:note, %{
|
||||||
|
data: %{
|
||||||
|
"cc" => cc,
|
||||||
|
"tag" => [
|
||||||
|
%{
|
||||||
|
"href" => recipient.ap_id,
|
||||||
|
"name" => recipient.nickname,
|
||||||
|
"type" => "Mention"
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
"href" => "https://example.com/search?tag=test",
|
||||||
|
"name" => "#test",
|
||||||
|
"type" => "Hashtag"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
activity =
|
||||||
|
insert(:note_activity, %{
|
||||||
|
note: object,
|
||||||
|
recipients: [recipient.ap_id | cc]
|
||||||
|
})
|
||||||
|
|
||||||
|
assert length(activity.recipients) == 3
|
||||||
|
|
||||||
|
%{mentions: [mention] = mentions} = StatusView.render("status.json", %{activity: activity})
|
||||||
|
|
||||||
|
assert length(mentions) == 1
|
||||||
|
assert mention.url == recipient.ap_id
|
||||||
end
|
end
|
||||||
|
|
||||||
test "attachments" do
|
test "attachments" do
|
||||||
|
|
Loading…
Reference in a new issue