ChatView: Add actor_account_id
authorlain <lain@soykaf.club>
Mon, 27 Apr 2020 14:08:03 +0000 (16:08 +0200)
committerlain <lain@soykaf.club>
Mon, 27 Apr 2020 14:08:03 +0000 (16:08 +0200)
lib/pleroma/web/api_spec/schemas/chat_message_response.ex
lib/pleroma/web/pleroma_api/views/chat_message_view.ex
test/web/pleroma_api/views/chat_message_view_test.exs

index e94c0036932ec4b53522c725eccc1cbbf248e646..9459d210b5c82165c68c36cfe469535990732eb0 100644 (file)
@@ -14,6 +14,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.ChatMessageResponse do
     properties: %{
       id: %Schema{type: :string},
       actor: %Schema{type: :string, description: "The ActivityPub id of the actor"},
+      actor_account_id: %Schema{type: :string, description: "The Mastodon API id of the actor"},
       chat_id: %Schema{type: :string},
       content: %Schema{type: :string},
       created_at: %Schema{type: :string, format: :datetime},
@@ -21,6 +22,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.ChatMessageResponse do
     },
     example: %{
       "actor" => "https://dontbulling.me/users/lain",
+      "actor_account_id" => "someflakeid",
       "chat_id" => "1",
       "content" => "hey you again",
       "created_at" => "2020-04-21T15:06:45.000Z",
index b40ab92a023cdb605e27aca516283f9c92fdef86..5b740cc44c08ef7b4adde41926611d86c3c1d4eb 100644 (file)
@@ -8,6 +8,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageView do
   alias Pleroma.Chat
   alias Pleroma.Web.CommonAPI.Utils
   alias Pleroma.Web.MastodonAPI.StatusView
+  alias Pleroma.User
 
   def render(
         "show.json",
@@ -21,6 +22,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageView do
       content: chat_message["content"],
       chat_id: chat_id |> to_string(),
       actor: chat_message["actor"],
+      actor_account_id: User.get_cached_by_ap_id(chat_message["actor"]).id,
       created_at: Utils.to_masto_date(chat_message["published"]),
       emojis: StatusView.build_emojis(chat_message["emoji"])
     }
index 115335f10aa9f0eeb2387a4613a5a2d39192cb9e..7e3aeefab1a724ffff685af3f23ecc8e7c643f3e 100644 (file)
@@ -26,6 +26,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageViewTest do
     assert chat_message[:id] == object.id |> to_string()
     assert chat_message[:content] == "kippis :firefox:"
     assert chat_message[:actor] == user.ap_id
+    assert chat_message[:actor_account_id] == user.id
     assert chat_message[:chat_id]
     assert chat_message[:created_at]
     assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
@@ -39,6 +40,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageViewTest do
     assert chat_message_two[:id] == object.id |> to_string()
     assert chat_message_two[:content] == "gkgkgk"
     assert chat_message_two[:actor] == recipient.ap_id
+    assert chat_message_two[:actor_account_id] == recipient.id
     assert chat_message_two[:chat_id] == chat_message[:chat_id]
   end
 end