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,
"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())
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