UserView: Add acceptsChatMessages field
This commit is contained in:
parent
db76c26469
commit
26a7cc3f00
@ -81,6 +81,15 @@ def render("user.json", %{user: user}) do
|
||||
|
||||
fields = Enum.map(user.fields, &Map.put(&1, "type", "PropertyValue"))
|
||||
|
||||
chat_message_acceptance =
|
||||
if is_boolean(user.accepts_chat_messages) do
|
||||
%{
|
||||
"acceptsChatMessages" => user.accepts_chat_messages
|
||||
}
|
||||
else
|
||||
%{}
|
||||
end
|
||||
|
||||
%{
|
||||
"id" => user.ap_id,
|
||||
"type" => user.actor_type,
|
||||
@ -103,6 +112,7 @@ def render("user.json", %{user: user}) do
|
||||
"tag" => emoji_tags,
|
||||
"discoverable" => user.discoverable
|
||||
}
|
||||
|> Map.merge(chat_message_acceptance)
|
||||
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|
||||
|> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
|
||||
|> Map.merge(Utils.make_json_ld_header())
|
||||
|
@ -158,4 +158,16 @@ test "sets correct totalItems when follows are hidden but the follow counter is
|
||||
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "acceptsChatMessages" do
|
||||
test "it returns this value if it is set" do
|
||||
true_user = insert(:user, accepts_chat_messages: true)
|
||||
false_user = insert(:user, accepts_chat_messages: false)
|
||||
nil_user = insert(:user, accepts_chat_messages: nil)
|
||||
|
||||
assert %{"acceptsChatMessages" => true} = UserView.render("user.json", user: true_user)
|
||||
assert %{"acceptsChatMessages" => false} = UserView.render("user.json", user: false_user)
|
||||
refute Map.has_key?(UserView.render("user.json", user: nil_user), "acceptsChatMessages")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user