forked from AkkomaGang/akkoma
ActivityPub: Add new 'capabilities' to user.
This commit is contained in:
parent
74b88c0a8b
commit
208baf157a
5 changed files with 19 additions and 9 deletions
|
@ -1224,7 +1224,8 @@ defp object_to_user_data(data) do
|
||||||
end)
|
end)
|
||||||
|
|
||||||
locked = data["manuallyApprovesFollowers"] || false
|
locked = data["manuallyApprovesFollowers"] || false
|
||||||
accepts_chat_messages = data["acceptsChatMessages"]
|
capabilities = data["capabilities"] || %{}
|
||||||
|
accepts_chat_messages = capabilities["acceptsChatMessages"]
|
||||||
data = Transmogrifier.maybe_fix_user_object(data)
|
data = Transmogrifier.maybe_fix_user_object(data)
|
||||||
discoverable = data["discoverable"] || false
|
discoverable = data["discoverable"] || false
|
||||||
invisible = data["invisible"] || false
|
invisible = data["invisible"] || false
|
||||||
|
|
|
@ -81,7 +81,7 @@ def render("user.json", %{user: user}) do
|
||||||
|
|
||||||
fields = Enum.map(user.fields, &Map.put(&1, "type", "PropertyValue"))
|
fields = Enum.map(user.fields, &Map.put(&1, "type", "PropertyValue"))
|
||||||
|
|
||||||
chat_message_acceptance =
|
capabilities =
|
||||||
if is_boolean(user.accepts_chat_messages) do
|
if is_boolean(user.accepts_chat_messages) do
|
||||||
%{
|
%{
|
||||||
"acceptsChatMessages" => user.accepts_chat_messages
|
"acceptsChatMessages" => user.accepts_chat_messages
|
||||||
|
@ -110,9 +110,9 @@ def render("user.json", %{user: user}) do
|
||||||
"endpoints" => endpoints,
|
"endpoints" => endpoints,
|
||||||
"attachment" => fields,
|
"attachment" => fields,
|
||||||
"tag" => emoji_tags,
|
"tag" => emoji_tags,
|
||||||
"discoverable" => user.discoverable
|
"discoverable" => user.discoverable,
|
||||||
|
"capabilities" => capabilities
|
||||||
}
|
}
|
||||||
|> Map.merge(chat_message_acceptance)
|
|
||||||
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|
||||||
|> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
|
|> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
|
||||||
|> Map.merge(Utils.make_json_ld_header())
|
|> Map.merge(Utils.make_json_ld_header())
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
},
|
},
|
||||||
"discoverable": "toot:discoverable",
|
"discoverable": "toot:discoverable",
|
||||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
"acceptsChatMessages": "litepub:acceptsChatMessages",
|
"capabilities": "litepub:capabilities",
|
||||||
"ostatus": "http://ostatus.org#",
|
"ostatus": "http://ostatus.org#",
|
||||||
"schema": "http://schema.org#",
|
"schema": "http://schema.org#",
|
||||||
"toot": "http://joinmastodon.org/ns#",
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
"summary": "\u003cp\u003e\u003c/p\u003e",
|
"summary": "\u003cp\u003e\u003c/p\u003e",
|
||||||
"url": "http://mastodon.example.org/@admin",
|
"url": "http://mastodon.example.org/@admin",
|
||||||
"manuallyApprovesFollowers": false,
|
"manuallyApprovesFollowers": false,
|
||||||
"acceptsChatMessages": true,
|
"capabilities": {
|
||||||
|
"acceptsChatMessages": true
|
||||||
|
},
|
||||||
"publicKey": {
|
"publicKey": {
|
||||||
"id": "http://mastodon.example.org/users/admin#main-key",
|
"id": "http://mastodon.example.org/users/admin#main-key",
|
||||||
"owner": "http://mastodon.example.org/users/admin",
|
"owner": "http://mastodon.example.org/users/admin",
|
||||||
|
|
|
@ -165,9 +165,16 @@ test "it returns this value if it is set" do
|
||||||
false_user = insert(:user, accepts_chat_messages: false)
|
false_user = insert(:user, accepts_chat_messages: false)
|
||||||
nil_user = insert(:user, accepts_chat_messages: nil)
|
nil_user = insert(:user, accepts_chat_messages: nil)
|
||||||
|
|
||||||
assert %{"acceptsChatMessages" => true} = UserView.render("user.json", user: true_user)
|
assert %{"capabilities" => %{"acceptsChatMessages" => true}} =
|
||||||
assert %{"acceptsChatMessages" => false} = UserView.render("user.json", user: false_user)
|
UserView.render("user.json", user: true_user)
|
||||||
refute Map.has_key?(UserView.render("user.json", user: nil_user), "acceptsChatMessages")
|
|
||||||
|
assert %{"capabilities" => %{"acceptsChatMessages" => false}} =
|
||||||
|
UserView.render("user.json", user: false_user)
|
||||||
|
|
||||||
|
refute Map.has_key?(
|
||||||
|
UserView.render("user.json", user: nil_user)["capabilities"],
|
||||||
|
"acceptsChatMessages"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue