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: %{
items: ChatResponse,
example: [
%{
- "recipient" => "https://dontbulling.me/users/lain",
- "recipient_account" => %{
+ "account" => %{
"pleroma" => %{
"is_admin" => false,
"confirmation_pending" => false,
"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",
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",
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,
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)
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"])
}
%{
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
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)
end
end
- describe "POST /api/v1/pleroma/chats/by-ap-id/:id" do
+ describe "POST /api/v1/pleroma/chats/by-account-id/:id" do
setup do: oauth_access(["write:statuses"])
test "it creates or returns a chat", %{conn: conn} do
result =
conn
- |> post("/api/v1/pleroma/chats/by-ap-id/#{URI.encode_www_form(other_user.ap_id)}")
+ |> post("/api/v1/pleroma/chats/by-account-id/#{other_user.id}")
|> json_response_and_validate_schema(200)
assert result["id"]
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[:account_id] == user.id
assert chat_message[:chat_id]
assert chat_message[:created_at]
assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
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[:account_id] == recipient.id
assert chat_message_two[:chat_id] == chat_message[:chat_id]
end
end
assert represented_chat == %{
id: "#{chat.id}",
- recipient: recipient.ap_id,
- recipient_account: AccountView.render("show.json", user: recipient),
+ account: AccountView.render("show.json", user: recipient),
unread: 0
}
end