forked from AkkomaGang/akkoma
Store the client application data in ActivityStreams format
This commit is contained in:
parent
26b620d676
commit
d35b6254b4
3 changed files with 13 additions and 6 deletions
|
@ -423,7 +423,7 @@ def bookmarks(%{assigns: %{user: user}} = conn, params) do
|
||||||
defp put_application(params, %{assigns: %{token: %Token{user: %User{} = user} = token}} = _conn) do
|
defp put_application(params, %{assigns: %{token: %Token{user: %User{} = user} = token}} = _conn) do
|
||||||
if user.disclose_client do
|
if user.disclose_client do
|
||||||
%{client_name: client_name, website: website} = Repo.preload(token, :app).app
|
%{client_name: client_name, website: website} = Repo.preload(token, :app).app
|
||||||
Map.put(params, :application, %{name: client_name, website: website})
|
Map.put(params, :application, %{type: "Application", name: client_name, url: website})
|
||||||
else
|
else
|
||||||
Map.put(params, :application, nil)
|
Map.put(params, :application, nil)
|
||||||
end
|
end
|
||||||
|
|
|
@ -180,7 +180,7 @@ def render(
|
||||||
media_attachments: reblogged[:media_attachments] || [],
|
media_attachments: reblogged[:media_attachments] || [],
|
||||||
mentions: mentions,
|
mentions: mentions,
|
||||||
tags: reblogged[:tags] || [],
|
tags: reblogged[:tags] || [],
|
||||||
application: activity_object.data["application"] || nil,
|
application: build_application(activity_object.data["application"]),
|
||||||
language: nil,
|
language: nil,
|
||||||
emojis: [],
|
emojis: [],
|
||||||
pleroma: %{
|
pleroma: %{
|
||||||
|
@ -345,7 +345,7 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity}
|
||||||
poll: render(PollView, "show.json", object: object, for: opts[:for]),
|
poll: render(PollView, "show.json", object: object, for: opts[:for]),
|
||||||
mentions: mentions,
|
mentions: mentions,
|
||||||
tags: build_tags(tags),
|
tags: build_tags(tags),
|
||||||
application: object.data["application"] || nil,
|
application: build_application(object.data["application"]),
|
||||||
language: nil,
|
language: nil,
|
||||||
emojis: build_emojis(object.data["emoji"]),
|
emojis: build_emojis(object.data["emoji"]),
|
||||||
pleroma: %{
|
pleroma: %{
|
||||||
|
@ -534,4 +534,8 @@ defp build_emoji_map(emoji, users, current_user) do
|
||||||
me: !!(current_user && current_user.ap_id in users)
|
me: !!(current_user && current_user.ap_id in users)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec build_application(map() | nil) :: map() | nil
|
||||||
|
defp build_application(%{type: _type, name: name, url: url}), do: %{name: name, website: url}
|
||||||
|
defp build_application(_), do: nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -205,14 +205,17 @@ test "it strips internal fields" do
|
||||||
{:ok, activity} =
|
{:ok, activity} =
|
||||||
CommonAPI.post(user, %{
|
CommonAPI.post(user, %{
|
||||||
status: "#2hu :firefox:",
|
status: "#2hu :firefox:",
|
||||||
application: %{name: "TestClient", website: "https://pleroma.social"}
|
application: %{type: "Application", name: "TestClient", url: "https://pleroma.social"}
|
||||||
})
|
})
|
||||||
|
|
||||||
# Ensure injected application data made it into the activity
|
# Ensure injected application data made it into the activity
|
||||||
# as we don't have a Token to derive it from, otherwise it will
|
# as we don't have a Token to derive it from, otherwise it will
|
||||||
# be nil and the test will pass
|
# be nil and the test will pass
|
||||||
assert %{"application" => %{name: "TestClient", website: "https://pleroma.social"}} =
|
assert %{
|
||||||
activity.object.data
|
type: "Application",
|
||||||
|
name: "TestClient",
|
||||||
|
url: "https://pleroma.social"
|
||||||
|
} == activity.object.data["application"]
|
||||||
|
|
||||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue