diff options
Diffstat (limited to 'lib')
7 files changed, 17 insertions, 26 deletions
| diff --git a/lib/pleroma/web/api_spec/operations/chat_operation.ex b/lib/pleroma/web/api_spec/operations/chat_operation.ex index 546bc4d9b..59539e890 100644 --- a/lib/pleroma/web/api_spec/operations/chat_operation.ex +++ b/lib/pleroma/web/api_spec/operations/chat_operation.ex @@ -23,12 +23,12 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do        operationId: "ChatController.create",        parameters: [          Operation.parameter( -          :ap_id, +          :id,            :path,            :string, -          "The ActivityPub id of the recipient of this chat.", +          "The account id of the recipient of this chat",            required: true, -          example: "https://lain.com/users/lain" +          example: "someflakeid"          )        ],        responses: %{ @@ -128,8 +128,7 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do        items: ChatResponse,        example: [          %{ -          "recipient" => "https://dontbulling.me/users/lain", -          "recipient_account" => %{ +          "account" => %{              "pleroma" => %{                "is_admin" => false,                "confirmation_pending" => false, @@ -202,10 +201,10 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do            "content" => "Check this out :firefox:",            "id" => "13",            "chat_id" => "1", -          "actor" => "https://dontbulling.me/users/lain" +          "actor_id" => "someflakeid"          },          %{ -          "actor" => "https://dontbulling.me/users/lain", +          "actor_id" => "someflakeid",            "content" => "Whats' up?",            "id" => "12",            "chat_id" => "1", diff --git a/lib/pleroma/web/api_spec/schemas/chat_message_response.ex b/lib/pleroma/web/api_spec/schemas/chat_message_response.ex index 9459d210b..b7a662cbb 100644 --- a/lib/pleroma/web/api_spec/schemas/chat_message_response.ex +++ b/lib/pleroma/web/api_spec/schemas/chat_message_response.ex @@ -13,16 +13,14 @@ defmodule Pleroma.Web.ApiSpec.Schemas.ChatMessageResponse do      type: :object,      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"}, +      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},        emojis: %Schema{type: :array}      },      example: %{ -      "actor" => "https://dontbulling.me/users/lain", -      "actor_account_id" => "someflakeid", +      "account_id" => "someflakeid",        "chat_id" => "1",        "content" => "hey you again",        "created_at" => "2020-04-21T15:06:45.000Z", diff --git a/lib/pleroma/web/api_spec/schemas/chat_response.ex b/lib/pleroma/web/api_spec/schemas/chat_response.ex index a80f4d173..aa435165d 100644 --- a/lib/pleroma/web/api_spec/schemas/chat_response.ex +++ b/lib/pleroma/web/api_spec/schemas/chat_response.ex @@ -12,15 +12,12 @@ defmodule Pleroma.Web.ApiSpec.Schemas.ChatResponse do      description: "Response schema for a Chat",      type: :object,      properties: %{ -      id: %Schema{type: :string}, -      recipient: %Schema{type: :string}, -      # TODO: Make this reference the account structure. -      recipient_account: %Schema{type: :object}, -      unread: %Schema{type: :integer} +      id: %Schema{type: :string, nullable: false}, +      account: %Schema{type: :object, nullable: false}, +      unread: %Schema{type: :integer, nullable: false}      },      example: %{ -      "recipient" => "https://dontbulling.me/users/lain", -      "recipient_account" => %{ +      "account" => %{          "pleroma" => %{            "is_admin" => false,            "confirmation_pending" => false, diff --git a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex index 771ad6217..8654f4295 100644 --- a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex @@ -99,9 +99,8 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do    end    def create(%{assigns: %{user: user}} = conn, params) do -    recipient = params[:ap_id] - -    with {:ok, %Chat{} = chat} <- Chat.get_or_create(user.id, recipient) do +    with %User{ap_id: recipient} <- User.get_by_id(params[:id]), +         {:ok, %Chat{} = chat} <- Chat.get_or_create(user.id, recipient) do        conn        |> put_view(ChatView)        |> render("show.json", chat: chat) diff --git a/lib/pleroma/web/pleroma_api/views/chat_message_view.ex b/lib/pleroma/web/pleroma_api/views/chat_message_view.ex index 5b740cc44..28f12d9b0 100644 --- a/lib/pleroma/web/pleroma_api/views/chat_message_view.ex +++ b/lib/pleroma/web/pleroma_api/views/chat_message_view.ex @@ -21,8 +21,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageView do        id: id |> to_string(),        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, +      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"])      } diff --git a/lib/pleroma/web/pleroma_api/views/chat_view.ex b/lib/pleroma/web/pleroma_api/views/chat_view.ex index 1e9ef4356..bc3af5ef5 100644 --- a/lib/pleroma/web/pleroma_api/views/chat_view.ex +++ b/lib/pleroma/web/pleroma_api/views/chat_view.ex @@ -14,8 +14,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatView do      %{        id: chat.id |> to_string(), -      recipient: chat.recipient, -      recipient_account: AccountView.render("show.json", Map.put(opts, :user, recipient)), +      account: AccountView.render("show.json", Map.put(opts, :user, recipient)),        unread: chat.unread      }    end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 0c56318ee..aad2e3b98 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -275,7 +275,7 @@ defmodule Pleroma.Web.Router do      scope [] do        pipe_through(:authenticated_api) -      post("/chats/by-ap-id/:ap_id", ChatController, :create) +      post("/chats/by-account-id/:id", ChatController, :create)        get("/chats", ChatController, :index)        get("/chats/:id/messages", ChatController, :messages)        post("/chats/:id/messages", ChatController, :post_chat_message) | 
