with %Activity{} <- Activity.get_by_id(activity_id),
{:ok, _activity} <-
- CommonAPI.post(user, %{"status" => rest, "in_reply_to_status_id" => activity_id}) do
+ CommonAPI.post(user, %{status: rest, in_reply_to_status_id: activity_id}) do
IO.puts("Replied!")
else
_e -> IO.puts("Could not reply...")
def handle_command(%{user: user} = state, "p " <> text) do
text = String.trim(text)
- with {:ok, _activity} <- CommonAPI.post(user, %{"status" => text}) do
+ with {:ok, _activity} <- CommonAPI.post(user, %{status: text}) do
IO.puts("Posted!")
else
_e -> IO.puts("Could not post...")
%{changes: %{params: %{"media_ids" => media_ids} = params}} = changeset
)
when is_list(media_ids) do
- media_attachments = Utils.attachments_from_ids(%{"media_ids" => media_ids})
+ media_attachments = Utils.attachments_from_ids(%{media_ids: media_ids})
params =
params
with %User{} = sender_user <- welcome_user(),
message when is_binary(message) <- welcome_message() do
CommonAPI.post(sender_user, %{
- "visibility" => "direct",
- "status" => "@#{user.nickname}\n#{message}"
+ visibility: "direct",
+ status: "@#{user.nickname}\n#{message}"
})
else
_ -> {:ok, nil}
end
def status_update(%{assigns: %{user: admin}} = conn, %{"id" => id} = params) do
+ params =
+ params
+ |> Map.take(["sensitive", "visibility"])
+ |> Map.new(fn {key, value} -> {String.to_existing_atom(key), value} end)
+
with {:ok, activity} <- CommonAPI.update_activity_scope(id, params) do
- {:ok, sensitive} = Ecto.Type.cast(:boolean, params["sensitive"])
+ {:ok, sensitive} = Ecto.Type.cast(:boolean, params[:sensitive])
ModerationLog.insert_log(%{
action: "status_update",
actor: admin,
subject: activity,
sensitive: sensitive,
- visibility: params["visibility"]
+ visibility: params[:visibility]
})
conn
--- /dev/null
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ApiSpec.StatusOperation do
+ alias OpenApiSpex.Operation
+ alias OpenApiSpex.Schema
+ alias Pleroma.Web.ApiSpec.AccountOperation
+ alias Pleroma.Web.ApiSpec.Schemas.ApiError
+ alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
+ alias Pleroma.Web.ApiSpec.Schemas.FlakeID
+ alias Pleroma.Web.ApiSpec.Schemas.ScheduledStatus
+ alias Pleroma.Web.ApiSpec.Schemas.Status
+ alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
+
+ import Pleroma.Web.ApiSpec.Helpers
+
+ def open_api_operation(action) do
+ operation = String.to_existing_atom("#{action}_operation")
+ apply(__MODULE__, operation, [])
+ end
+
+ def index_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Get multiple statuses by IDs",
+ security: [%{"oAuth" => ["read:statuses"]}],
+ parameters: [
+ Operation.parameter(
+ :ids,
+ :query,
+ %Schema{type: :array, items: FlakeID},
+ "Array of account IDs"
+ )
+ ],
+ operationId: "StatusController.index",
+ responses: %{
+ 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
+ }
+ }
+ end
+
+ def create_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Publish new status",
+ security: [%{"oAuth" => ["write:statuses"]}],
+ description: "Post a new status",
+ operationId: "StatusController.create",
+ requestBody: request_body("Parameters", create_request(), required: true),
+ responses: %{
+ 200 =>
+ Operation.response(
+ "Status. When `scheduled_at` is present, ScheduledStatus is returned instead",
+ "application/json",
+ %Schema{oneOf: [Status, ScheduledStatus]}
+ ),
+ 422 => Operation.response("Bad Request", "application/json", ApiError)
+ }
+ }
+ end
+
+ def show_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "View specific status",
+ description: "View information about a status",
+ operationId: "StatusController.show",
+ security: [%{"oAuth" => ["read:statuses"]}],
+ parameters: [id_param()],
+ responses: %{
+ 200 => status_response(),
+ 404 => Operation.response("Not Found", "application/json", ApiError)
+ }
+ }
+ end
+
+ def delete_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Delete status",
+ security: [%{"oAuth" => ["write:statuses"]}],
+ description: "Delete one of your own statuses",
+ operationId: "StatusController.delete",
+ parameters: [id_param()],
+ responses: %{
+ 200 => empty_object_response(),
+ 403 => Operation.response("Forbidden", "application/json", ApiError),
+ 404 => Operation.response("Not Found", "application/json", ApiError)
+ }
+ }
+ end
+
+ def reblog_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Boost",
+ security: [%{"oAuth" => ["write:statuses"]}],
+ description: "Reshare a status",
+ operationId: "StatusController.reblog",
+ parameters: [id_param()],
+ requestBody:
+ request_body("Parameters", %Schema{
+ type: :object,
+ properties: %{
+ visibility: %Schema{allOf: [VisibilityScope], default: "public"}
+ }
+ }),
+ responses: %{
+ 200 => status_response(),
+ 404 => Operation.response("Not Found", "application/json", ApiError)
+ }
+ }
+ end
+
+ def unreblog_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Undo boost",
+ security: [%{"oAuth" => ["write:statuses"]}],
+ description: "Undo a reshare of a status",
+ operationId: "StatusController.unreblog",
+ parameters: [id_param()],
+ responses: %{
+ 200 => status_response(),
+ 404 => Operation.response("Not Found", "application/json", ApiError)
+ }
+ }
+ end
+
+ def favourite_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Favourite",
+ security: [%{"oAuth" => ["write:favourites"]}],
+ description: "Add a status to your favourites list",
+ operationId: "StatusController.favourite",
+ parameters: [id_param()],
+ responses: %{
+ 200 => status_response(),
+ 404 => Operation.response("Not Found", "application/json", ApiError)
+ }
+ }
+ end
+
+ def unfavourite_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Undo favourite",
+ security: [%{"oAuth" => ["write:favourites"]}],
+ description: "Remove a status from your favourites list",
+ operationId: "StatusController.unfavourite",
+ parameters: [id_param()],
+ responses: %{
+ 200 => status_response(),
+ 404 => Operation.response("Not Found", "application/json", ApiError)
+ }
+ }
+ end
+
+ def pin_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Pin to profile",
+ security: [%{"oAuth" => ["write:accounts"]}],
+ description: "Feature one of your own public statuses at the top of your profile",
+ operationId: "StatusController.pin",
+ parameters: [id_param()],
+ responses: %{
+ 200 => status_response(),
+ 400 => Operation.response("Error", "application/json", ApiError)
+ }
+ }
+ end
+
+ def unpin_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Unpin to profile",
+ security: [%{"oAuth" => ["write:accounts"]}],
+ description: "Unfeature a status from the top of your profile",
+ operationId: "StatusController.unpin",
+ parameters: [id_param()],
+ responses: %{
+ 200 => status_response(),
+ 400 => Operation.response("Error", "application/json", ApiError)
+ }
+ }
+ end
+
+ def bookmark_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Bookmark",
+ security: [%{"oAuth" => ["write:bookmarks"]}],
+ description: "Privately bookmark a status",
+ operationId: "StatusController.bookmark",
+ parameters: [id_param()],
+ responses: %{
+ 200 => status_response()
+ }
+ }
+ end
+
+ def unbookmark_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Undo bookmark",
+ security: [%{"oAuth" => ["write:bookmarks"]}],
+ description: "Remove a status from your private bookmarks",
+ operationId: "StatusController.unbookmark",
+ parameters: [id_param()],
+ responses: %{
+ 200 => status_response()
+ }
+ }
+ end
+
+ def mute_conversation_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Mute conversation",
+ security: [%{"oAuth" => ["write:mutes"]}],
+ description:
+ "Do not receive notifications for the thread that this status is part of. Must be a thread in which you are a participant.",
+ operationId: "StatusController.mute_conversation",
+ parameters: [id_param()],
+ responses: %{
+ 200 => status_response(),
+ 400 => Operation.response("Error", "application/json", ApiError)
+ }
+ }
+ end
+
+ def unmute_conversation_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Unmute conversation",
+ security: [%{"oAuth" => ["write:mutes"]}],
+ description:
+ "Start receiving notifications again for the thread that this status is part of",
+ operationId: "StatusController.unmute_conversation",
+ parameters: [id_param()],
+ responses: %{
+ 200 => status_response(),
+ 400 => Operation.response("Error", "application/json", ApiError)
+ }
+ }
+ end
+
+ def card_operation do
+ %Operation{
+ tags: ["Statuses"],
+ deprecated: true,
+ summary: "Preview card",
+ description: "Deprecated in favor of card property inlined on Status entity",
+ operationId: "StatusController.card",
+ parameters: [id_param()],
+ security: [%{"oAuth" => ["read:statuses"]}],
+ responses: %{
+ 200 =>
+ Operation.response("Card", "application/json", %Schema{
+ type: :object,
+ nullable: true,
+ properties: %{
+ type: %Schema{type: :string, enum: ["link", "photo", "video", "rich"]},
+ provider_name: %Schema{type: :string, nullable: true},
+ provider_url: %Schema{type: :string, format: :uri},
+ url: %Schema{type: :string, format: :uri},
+ image: %Schema{type: :string, nullable: true, format: :uri},
+ title: %Schema{type: :string},
+ description: %Schema{type: :string}
+ }
+ })
+ }
+ }
+ end
+
+ def favourited_by_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Favourited by",
+ description: "View who favourited a given status",
+ operationId: "StatusController.favourited_by",
+ security: [%{"oAuth" => ["read:accounts"]}],
+ parameters: [id_param()],
+ responses: %{
+ 200 =>
+ Operation.response(
+ "Array of Accounts",
+ "application/json",
+ AccountOperation.array_of_accounts()
+ ),
+ 404 => Operation.response("Not Found", "application/json", ApiError)
+ }
+ }
+ end
+
+ def reblogged_by_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Boosted by",
+ description: "View who boosted a given status",
+ operationId: "StatusController.reblogged_by",
+ security: [%{"oAuth" => ["read:accounts"]}],
+ parameters: [id_param()],
+ responses: %{
+ 200 =>
+ Operation.response(
+ "Array of Accounts",
+ "application/json",
+ AccountOperation.array_of_accounts()
+ ),
+ 404 => Operation.response("Not Found", "application/json", ApiError)
+ }
+ }
+ end
+
+ def context_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Parent and child statuses",
+ description: "View statuses above and below this status in the thread",
+ operationId: "StatusController.context",
+ security: [%{"oAuth" => ["read:statuses"]}],
+ parameters: [id_param()],
+ responses: %{
+ 200 => Operation.response("Context", "application/json", context())
+ }
+ }
+ end
+
+ def favourites_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Favourited statuses",
+ description: "Statuses the user has favourited",
+ operationId: "StatusController.favourites",
+ parameters: pagination_params(),
+ security: [%{"oAuth" => ["read:favourites"]}],
+ responses: %{
+ 200 => Operation.response("Array of Statuses", "application/json", array_of_statuses())
+ }
+ }
+ end
+
+ def bookmarks_operation do
+ %Operation{
+ tags: ["Statuses"],
+ summary: "Bookmarked statuses",
+ description: "Statuses the user has bookmarked",
+ operationId: "StatusController.bookmarks",
+ parameters: [
+ Operation.parameter(:with_relationships, :query, BooleanLike, "Include relationships")
+ | pagination_params()
+ ],
+ security: [%{"oAuth" => ["read:bookmarks"]}],
+ responses: %{
+ 200 => Operation.response("Array of Statuses", "application/json", array_of_statuses())
+ }
+ }
+ end
+
+ defp array_of_statuses do
+ %Schema{type: :array, items: Status, example: [Status.schema().example]}
+ end
+
+ defp create_request do
+ %Schema{
+ title: "StatusCreateRequest",
+ type: :object,
+ properties: %{
+ status: %Schema{
+ type: :string,
+ description:
+ "Text content of the status. If `media_ids` is provided, this becomes optional. Attaching a `poll` is optional while `status` is provided."
+ },
+ media_ids: %Schema{
+ type: :array,
+ items: %Schema{type: :string},
+ description:
+ "Array of Attachment ids to be attached as media. If provided, `status` becomes optional, and `poll` cannot be used."
+ },
+ poll: %Schema{
+ type: :object,
+ required: [:options],
+ properties: %{
+ options: %Schema{
+ type: :array,
+ items: %Schema{type: :string},
+ description:
+ "Array of possible answers. If provided, `media_ids` cannot be used, and `poll[expires_in]` must be provided."
+ },
+ expires_in: %Schema{
+ type: :integer,
+ description:
+ "Duration the poll should be open, in seconds. If provided, `media_ids` cannot be used, and `poll[options]` must be provided."
+ },
+ multiple: %Schema{type: :boolean, description: "Allow multiple choices?"},
+ hide_totals: %Schema{
+ type: :boolean,
+ description: "Hide vote counts until the poll ends?"
+ }
+ }
+ },
+ in_reply_to_id: %Schema{
+ allOf: [FlakeID],
+ description: "ID of the status being replied to, if status is a reply"
+ },
+ sensitive: %Schema{
+ type: :boolean,
+ description: "Mark status and attached media as sensitive?"
+ },
+ spoiler_text: %Schema{
+ type: :string,
+ description:
+ "Text to be shown as a warning or subject before the actual content. Statuses are generally collapsed behind this field."
+ },
+ scheduled_at: %Schema{
+ type: :string,
+ format: :"date-time",
+ nullable: true,
+ description:
+ "ISO 8601 Datetime at which to schedule a status. Providing this paramter will cause ScheduledStatus to be returned instead of Status. Must be at least 5 minutes in the future."
+ },
+ language: %Schema{type: :string, description: "ISO 639 language code for this status."},
+ # Pleroma-specific properties:
+ preview: %Schema{
+ type: :boolean,
+ description:
+ "If set to `true` the post won't be actually posted, but the status entitiy would still be rendered back. This could be useful for previewing rich text/custom emoji, for example"
+ },
+ content_type: %Schema{
+ type: :string,
+ description:
+ "The MIME type of the status, it is transformed into HTML by the backend. You can get the list of the supported MIME types with the nodeinfo endpoint."
+ },
+ to: %Schema{
+ type: :array,
+ items: %Schema{type: :string},
+ description:
+ "A list of nicknames (like `lain@soykaf.club` or `lain` on the local server) that will be used to determine who is going to be addressed by this post. Using this will disable the implicit addressing by mentioned names in the `status` body, only the people in the `to` list will be addressed. The normal rules for for post visibility are not affected by this and will still apply"
+ },
+ visibility: %Schema{
+ anyOf: [
+ VisibilityScope,
+ %Schema{type: :string, description: "`list:LIST_ID`", example: "LIST:123"}
+ ],
+ description:
+ "Visibility of the posted status. Besides standard MastoAPI values (`direct`, `private`, `unlisted` or `public`) it can be used to address a List by setting it to `list:LIST_ID`"
+ },
+ expires_in: %Schema{
+ type: :integer,
+ description:
+ "The number of seconds the posted activity should expire in. When a posted activity expires it will be deleted from the server, and a delete request for it will be federated. This needs to be longer than an hour."
+ },
+ in_reply_to_conversation_id: %Schema{
+ type: :string,
+ description:
+ "Will reply to a given conversation, addressing only the people who are part of the recipient set of that conversation. Sets the visibility to `direct`."
+ }
+ },
+ example: %{
+ "status" => "What time is it?",
+ "sensitive" => "false",
+ "poll" => %{
+ "options" => ["Cofe", "Adventure"],
+ "expires_in" => 420
+ }
+ }
+ }
+ end
+
+ defp id_param do
+ Operation.parameter(:id, :path, FlakeID, "Status ID",
+ example: "9umDrYheeY451cQnEe",
+ required: true
+ )
+ end
+
+ defp status_response do
+ Operation.response("Status", "application/json", Status)
+ end
+
+ defp context do
+ %Schema{
+ title: "StatusContext",
+ description:
+ "Represents the tree around a given status. Used for reconstructing threads of statuses.",
+ type: :object,
+ required: [:ancestors, :descendants],
+ properties: %{
+ ancestors: array_of_statuses(),
+ descendants: array_of_statuses()
+ },
+ example: %{
+ "ancestors" => [Status.schema().example],
+ "descendants" => [Status.schema().example]
+ }
+ }
+ end
+end
description: "Response schema for a status",
type: :object,
properties: %{
- account: Account,
+ account: %Schema{allOf: [Account], description: "The account that authored this status"},
application: %Schema{
+ description: "The application used to post this status",
type: :object,
properties: %{
name: %Schema{type: :string},
website: %Schema{type: :string, nullable: true, format: :uri}
}
},
- bookmarked: %Schema{type: :boolean},
+ bookmarked: %Schema{type: :boolean, description: "Have you bookmarked this status?"},
card: %Schema{
type: :object,
nullable: true,
+ description: "Preview card for links included within status content",
+ required: [:url, :title, :description, :type],
properties: %{
- type: %Schema{type: :string, enum: ["link", "photo", "video", "rich"]},
- provider_name: %Schema{type: :string, nullable: true},
- provider_url: %Schema{type: :string, format: :uri},
- url: %Schema{type: :string, format: :uri},
- image: %Schema{type: :string, nullable: true, format: :uri},
- title: %Schema{type: :string},
- description: %Schema{type: :string}
+ type: %Schema{
+ type: :string,
+ enum: ["link", "photo", "video", "rich"],
+ description: "The type of the preview card"
+ },
+ provider_name: %Schema{
+ type: :string,
+ nullable: true,
+ description: "The provider of the original resource"
+ },
+ provider_url: %Schema{
+ type: :string,
+ format: :uri,
+ description: "A link to the provider of the original resource"
+ },
+ url: %Schema{type: :string, format: :uri, description: "Location of linked resource"},
+ image: %Schema{
+ type: :string,
+ nullable: true,
+ format: :uri,
+ description: "Preview thumbnail"
+ },
+ title: %Schema{type: :string, description: "Title of linked resource"},
+ description: %Schema{type: :string, description: "Description of preview"}
}
},
- content: %Schema{type: :string, format: :html},
- created_at: %Schema{type: :string, format: "date-time"},
- emojis: %Schema{type: :array, items: Emoji},
- favourited: %Schema{type: :boolean},
- favourites_count: %Schema{type: :integer},
+ content: %Schema{type: :string, format: :html, description: "HTML-encoded status content"},
+ created_at: %Schema{
+ type: :string,
+ format: "date-time",
+ description: "The date when this status was created"
+ },
+ emojis: %Schema{
+ type: :array,
+ items: Emoji,
+ description: "Custom emoji to be used when rendering status content"
+ },
+ favourited: %Schema{type: :boolean, description: "Have you favourited this status?"},
+ favourites_count: %Schema{
+ type: :integer,
+ description: "How many favourites this status has received"
+ },
id: FlakeID,
- in_reply_to_account_id: %Schema{type: :string, nullable: true},
- in_reply_to_id: %Schema{type: :string, nullable: true},
- language: %Schema{type: :string, nullable: true},
+ in_reply_to_account_id: %Schema{
+ allOf: [FlakeID],
+ nullable: true,
+ description: "ID of the account being replied to"
+ },
+ in_reply_to_id: %Schema{
+ allOf: [FlakeID],
+ nullable: true,
+ description: "ID of the status being replied"
+ },
+ language: %Schema{
+ type: :string,
+ nullable: true,
+ description: "Primary language of this status"
+ },
media_attachments: %Schema{
type: :array,
- items: Attachment
+ items: Attachment,
+ description: "Media that is attached to this status"
},
mentions: %Schema{
type: :array,
+ description: "Mentions of users within the status content",
items: %Schema{
type: :object,
properties: %{
- id: %Schema{type: :string},
- acct: %Schema{type: :string},
- username: %Schema{type: :string},
- url: %Schema{type: :string, format: :uri}
+ id: %Schema{allOf: [FlakeID], description: "The account id of the mentioned user"},
+ acct: %Schema{
+ type: :string,
+ description:
+ "The webfinger acct: URI of the mentioned user. Equivalent to `username` for local users, or `username@domain` for remote users."
+ },
+ username: %Schema{type: :string, description: "The username of the mentioned user"},
+ url: %Schema{
+ type: :string,
+ format: :uri,
+ description: "The location of the mentioned user's profile"
+ }
}
}
},
- muted: %Schema{type: :boolean},
- pinned: %Schema{type: :boolean},
+ muted: %Schema{
+ type: :boolean,
+ description: "Have you muted notifications for this status's conversation?"
+ },
+ pinned: %Schema{
+ type: :boolean,
+ description: "Have you pinned this status? Only appears if the status is pinnable."
+ },
pleroma: %Schema{
type: :object,
properties: %{
- content: %Schema{type: :object, additionalProperties: %Schema{type: :string}},
- conversation_id: %Schema{type: :integer},
+ content: %Schema{
+ type: :object,
+ additionalProperties: %Schema{type: :string},
+ description:
+ "A map consisting of alternate representations of the `content` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`"
+ },
+ conversation_id: %Schema{
+ type: :integer,
+ description: "The ID of the AP context the status is associated with (if any)"
+ },
direct_conversation_id: %Schema{
type: :integer,
nullable: true,
},
emoji_reactions: %Schema{
type: :array,
+ description:
+ "A list with emoji / reaction maps. Contains no information about the reacting users, for that use the /statuses/:id/reactions endpoint.",
items: %Schema{
type: :object,
properties: %{
}
}
},
- expires_at: %Schema{type: :string, format: "date-time", nullable: true},
- in_reply_to_account_acct: %Schema{type: :string, nullable: true},
- local: %Schema{type: :boolean},
- spoiler_text: %Schema{type: :object, additionalProperties: %Schema{type: :string}},
- thread_muted: %Schema{type: :boolean}
+ expires_at: %Schema{
+ type: :string,
+ format: "date-time",
+ nullable: true,
+ description:
+ "A datetime (ISO 8601) that states when the post will expire (be deleted automatically), or empty if the post won't expire"
+ },
+ in_reply_to_account_acct: %Schema{
+ type: :string,
+ nullable: true,
+ description: "The `acct` property of User entity for replied user (if any)"
+ },
+ local: %Schema{
+ type: :boolean,
+ description: "`true` if the post was made on the local instance"
+ },
+ spoiler_text: %Schema{
+ type: :object,
+ additionalProperties: %Schema{type: :string},
+ description:
+ "A map consisting of alternate representations of the `spoiler_text` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`."
+ },
+ thread_muted: %Schema{
+ type: :boolean,
+ description: "`true` if the thread the post belongs to is muted"
+ }
}
},
- poll: %Schema{type: Poll, nullable: true},
+ poll: %Schema{allOf: [Poll], nullable: true, description: "The poll attached to the status"},
reblog: %Schema{
allOf: [%OpenApiSpex.Reference{"$ref": "#/components/schemas/Status"}],
- nullable: true
+ nullable: true,
+ description: "The status being reblogged"
+ },
+ reblogged: %Schema{type: :boolean, description: "Have you boosted this status?"},
+ reblogs_count: %Schema{
+ type: :integer,
+ description: "How many boosts this status has received"
+ },
+ replies_count: %Schema{
+ type: :integer,
+ description: "How many replies this status has received"
+ },
+ sensitive: %Schema{
+ type: :boolean,
+ description: "Is this status marked as sensitive content?"
+ },
+ spoiler_text: %Schema{
+ type: :string,
+ description:
+ "Subject or summary line, below which status content is collapsed until expanded"
},
- reblogged: %Schema{type: :boolean},
- reblogs_count: %Schema{type: :integer},
- replies_count: %Schema{type: :integer},
- sensitive: %Schema{type: :boolean},
- spoiler_text: %Schema{type: :string},
tags: %Schema{type: :array, items: Tag},
- uri: %Schema{type: :string, format: :uri},
- url: %Schema{type: :string, nullable: true, format: :uri},
- visibility: VisibilityScope
+ uri: %Schema{
+ type: :string,
+ format: :uri,
+ description: "URI of the status used for federation"
+ },
+ url: %Schema{
+ type: :string,
+ nullable: true,
+ format: :uri,
+ description: "A link to the status's HTML representation"
+ },
+ visibility: %Schema{
+ allOf: [VisibilityScope],
+ description: "Visibility of this status"
+ }
},
example: %{
"account" => %{
title: "VisibilityScope",
description: "Status visibility",
type: :string,
- enum: ["public", "unlisted", "private", "direct"]
+ enum: ["public", "unlisted", "private", "direct", "list"]
})
end
end
defp put_params(draft, params) do
- params = Map.put_new(params, "in_reply_to_status_id", params["in_reply_to_id"])
+ params = Map.put_new(params, :in_reply_to_status_id, params[:in_reply_to_id])
%__MODULE__{draft | params: params}
end
- defp status(%{params: %{"status" => status}} = draft) do
+ defp status(%{params: %{status: status}} = draft) do
%__MODULE__{draft | status: String.trim(status)}
end
defp summary(%{params: params} = draft) do
- %__MODULE__{draft | summary: Map.get(params, "spoiler_text", "")}
+ %__MODULE__{draft | summary: Map.get(params, :spoiler_text, "")}
end
defp full_payload(%{status: status, summary: summary} = draft) do
%__MODULE__{draft | attachments: attachments}
end
- defp in_reply_to(%{params: %{"in_reply_to_status_id" => ""}} = draft), do: draft
+ defp in_reply_to(%{params: %{in_reply_to_status_id: ""}} = draft), do: draft
- defp in_reply_to(%{params: %{"in_reply_to_status_id" => id}} = draft) when is_binary(id) do
+ defp in_reply_to(%{params: %{in_reply_to_status_id: id}} = draft) when is_binary(id) do
%__MODULE__{draft | in_reply_to: Activity.get_by_id(id)}
end
- defp in_reply_to(%{params: %{"in_reply_to_status_id" => %Activity{} = in_reply_to}} = draft) do
+ defp in_reply_to(%{params: %{in_reply_to_status_id: %Activity{} = in_reply_to}} = draft) do
%__MODULE__{draft | in_reply_to: in_reply_to}
end
defp in_reply_to(draft), do: draft
defp in_reply_to_conversation(draft) do
- in_reply_to_conversation = Participation.get(draft.params["in_reply_to_conversation_id"])
+ in_reply_to_conversation = Participation.get(draft.params[:in_reply_to_conversation_id])
%__MODULE__{draft | in_reply_to_conversation: in_reply_to_conversation}
end
end
defp expires_at(draft) do
- case CommonAPI.check_expiry_date(draft.params["expires_in"]) do
+ case CommonAPI.check_expiry_date(draft.params[:expires_in]) do
{:ok, expires_at} -> %__MODULE__{draft | expires_at: expires_at}
{:error, message} -> add_error(draft, message)
end
addressed_users =
draft.mentions
|> Enum.map(fn {_, mentioned_user} -> mentioned_user.ap_id end)
- |> Utils.get_addressed_users(draft.params["to"])
+ |> Utils.get_addressed_users(draft.params[:to])
{to, cc} =
Utils.get_to_and_cc(
end
defp sensitive(draft) do
- sensitive = draft.params["sensitive"] || Enum.member?(draft.tags, {"#nsfw", "nsfw"})
+ sensitive = draft.params[:sensitive] || Enum.member?(draft.tags, {"#nsfw", "nsfw"})
%__MODULE__{draft | sensitive: sensitive}
end
end
defp preview?(draft) do
- preview? = Pleroma.Web.ControllerHelper.truthy_param?(draft.params["preview"])
+ preview? = Pleroma.Web.ControllerHelper.truthy_param?(draft.params[:preview])
%__MODULE__{draft | preview?: preview?}
end
end
def repeat(id, user, params \\ %{}) do
- with {_, %Activity{data: %{"type" => "Create"}} = activity} <-
- {:find_activity, Activity.get_by_id(id)},
- object <- Object.normalize(activity),
- announce_activity <- Utils.get_existing_announce(user.ap_id, object),
- public <- public_announce?(object, params) do
+ with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id(id) do
+ object = Object.normalize(activity)
+ announce_activity = Utils.get_existing_announce(user.ap_id, object)
+ public = public_announce?(object, params)
+
if announce_activity do
{:ok, announce_activity, object}
else
ActivityPub.announce(user, object, nil, true, public)
end
else
- {:find_activity, _} -> {:error, :not_found}
- _ -> {:error, dgettext("errors", "Could not repeat")}
+ _ -> {:error, :not_found}
end
end
end
end
- def public_announce?(_, %{"visibility" => visibility})
+ def public_announce?(_, %{visibility: visibility})
when visibility in ~w{public unlisted private direct},
do: visibility in ~w(public unlisted)
def get_visibility(_, _, %Participation{}), do: {"direct", "direct"}
- def get_visibility(%{"visibility" => visibility}, in_reply_to, _)
+ def get_visibility(%{visibility: visibility}, in_reply_to, _)
when visibility in ~w{public unlisted private direct},
do: {visibility, get_replied_to_visibility(in_reply_to)}
- def get_visibility(%{"visibility" => "list:" <> list_id}, in_reply_to, _) do
+ def get_visibility(%{visibility: "list:" <> list_id}, in_reply_to, _) do
visibility = {:list, String.to_integer(list_id)}
{visibility, get_replied_to_visibility(in_reply_to)}
end
end
end
- def post(user, %{"status" => _} = data) do
+ def post(user, %{status: _} = data) do
with {:ok, draft} <- Pleroma.Web.CommonAPI.ActivityDraft.create(user, data) do
draft.changes
|> ActivityPub.create(draft.preview?)
end
end
- defp toggle_sensitive(activity, %{"sensitive" => sensitive}) when sensitive in ~w(true false) do
- toggle_sensitive(activity, %{"sensitive" => String.to_existing_atom(sensitive)})
+ defp toggle_sensitive(activity, %{sensitive: sensitive}) when sensitive in ~w(true false) do
+ toggle_sensitive(activity, %{sensitive: String.to_existing_atom(sensitive)})
end
- defp toggle_sensitive(%Activity{object: object} = activity, %{"sensitive" => sensitive})
+ defp toggle_sensitive(%Activity{object: object} = activity, %{sensitive: sensitive})
when is_boolean(sensitive) do
new_data = Map.put(object.data, "sensitive", sensitive)
defp toggle_sensitive(activity, _), do: {:ok, activity}
- defp set_visibility(activity, %{"visibility" => visibility}) do
+ defp set_visibility(activity, %{visibility: visibility}) do
Utils.update_activity_visibility(activity, visibility)
end
require Logger
require Pleroma.Constants
- def attachments_from_ids(%{"media_ids" => ids, "descriptions" => desc} = _) do
+ def attachments_from_ids(%{media_ids: ids, descriptions: desc}) do
attachments_from_ids_descs(ids, desc)
end
- def attachments_from_ids(%{"media_ids" => ids} = _) do
+ def attachments_from_ids(%{media_ids: ids}) do
attachments_from_ids_no_descs(ids)
end
def attachments_from_ids_no_descs(ids) do
Enum.map(ids, fn media_id ->
case Repo.get(Object, media_id) do
- %Object{data: data} = _ -> data
+ %Object{data: data} -> data
_ -> nil
end
end)
- |> Enum.filter(& &1)
+ |> Enum.reject(&is_nil/1)
end
def attachments_from_ids_descs([], _), do: []
Enum.map(ids, fn media_id ->
case Repo.get(Object, media_id) do
- %Object{data: data} = _ ->
+ %Object{data: data} ->
Map.put(data, "name", descs[media_id])
_ ->
nil
end
end)
- |> Enum.filter(& &1)
+ |> Enum.reject(&is_nil/1)
end
@spec get_to_and_cc(
|> make_poll_data()
end
- def make_poll_data(%{"poll" => %{"options" => options, "expires_in" => expires_in}} = data)
+ def make_poll_data(%{poll: %{options: options, expires_in: expires_in}} = data)
when is_list(options) do
limits = Pleroma.Config.get([:instance, :poll_limits])
|> DateTime.add(expires_in)
|> DateTime.to_iso8601()
- key = if truthy_param?(data["poll"]["multiple"]), do: "anyOf", else: "oneOf"
+ key = if truthy_param?(data.poll[:multiple]), do: "anyOf", else: "oneOf"
poll = %{"type" => "Question", key => option_notes, "closed" => end_time}
{:ok, {poll, emoji}}
|> Map.get("attachment_links", Config.get([:instance, :attachment_links]))
|> truthy_param?()
- content_type = get_content_type(data["content_type"])
+ content_type = get_content_type(data[:content_type])
options =
if visibility == "direct" && Config.get([:instance, :safe_dm_mentions]) do
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.MastodonAPI.ScheduledActivityView
+ plug(Pleroma.Web.ApiSpec.CastAndValidate)
plug(:skip_plug, Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug when action in [:index, :show])
@unauthenticated_access %{fallback: :proceed_unauthenticated, scopes: []}
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
+ defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.StatusOperation
+
@doc """
GET `/api/v1/statuses?ids[]=1&ids[]=2`
`ids` query param is required
"""
- def index(%{assigns: %{user: user}} = conn, %{"ids" => ids} = params) do
+ def index(%{assigns: %{user: user}} = conn, %{ids: ids} = params) do
limit = 100
activities =
Creates a scheduled status when `scheduled_at` param is present and it's far enough
"""
def create(
- %{assigns: %{user: user}} = conn,
- %{"status" => _, "scheduled_at" => scheduled_at} = params
+ %{
+ assigns: %{user: user},
+ body_params: %{status: _, scheduled_at: scheduled_at} = params
+ } = conn,
+ _
)
when not is_nil(scheduled_at) do
- params = Map.put(params, "in_reply_to_status_id", params["in_reply_to_id"])
+ params = Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id])
+
+ attrs = %{
+ params: Map.new(params, fn {key, value} -> {to_string(key), value} end),
+ scheduled_at: scheduled_at
+ }
with {:far_enough, true} <- {:far_enough, ScheduledActivity.far_enough?(scheduled_at)},
- attrs <- %{"params" => params, "scheduled_at" => scheduled_at},
{:ok, scheduled_activity} <- ScheduledActivity.create(user, attrs) do
conn
|> put_view(ScheduledActivityView)
|> render("show.json", scheduled_activity: scheduled_activity)
else
{:far_enough, _} ->
- create(conn, Map.drop(params, ["scheduled_at"]))
+ params = Map.drop(params, [:scheduled_at])
+ create(%Plug.Conn{conn | body_params: params}, %{})
error ->
error
Creates a regular status
"""
- def create(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do
- params = Map.put(params, "in_reply_to_status_id", params["in_reply_to_id"])
+ def create(%{assigns: %{user: user}, body_params: %{status: _} = params} = conn, _) do
+ params = Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id])
with {:ok, activity} <- CommonAPI.post(user, params) do
try_render(conn, "show.json",
end
end
- def create(%{assigns: %{user: _user}} = conn, %{"media_ids" => _} = params) do
- create(conn, Map.put(params, "status", ""))
+ def create(%{assigns: %{user: _user}, body_params: %{media_ids: _} = params} = conn, _) do
+ params = Map.put(params, :status, "")
+ create(%Plug.Conn{conn | body_params: params}, %{})
end
@doc "GET /api/v1/statuses/:id"
- def show(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ def show(%{assigns: %{user: user}} = conn, %{id: id}) do
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
true <- Visibility.visible_for_user?(activity, user) do
try_render(conn, "show.json",
end
@doc "DELETE /api/v1/statuses/:id"
- def delete(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ def delete(%{assigns: %{user: user}} = conn, %{id: id}) do
with {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
json(conn, %{})
else
end
@doc "POST /api/v1/statuses/:id/reblog"
- def reblog(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id} = params) do
+ def reblog(%{assigns: %{user: user}, body_params: params} = conn, %{id: ap_id_or_id}) do
with {:ok, announce, _activity} <- CommonAPI.repeat(ap_id_or_id, user, params),
%Activity{} = announce <- Activity.normalize(announce.data) do
try_render(conn, "show.json", %{activity: announce, for: user, as: :activity})
end
@doc "POST /api/v1/statuses/:id/unreblog"
- def unreblog(%{assigns: %{user: user}} = conn, %{"id" => activity_id}) do
+ def unreblog(%{assigns: %{user: user}} = conn, %{id: activity_id}) do
with {:ok, _unannounce} <- CommonAPI.unrepeat(activity_id, user),
%Activity{} = activity <- Activity.get_by_id(activity_id) do
try_render(conn, "show.json", %{activity: activity, for: user, as: :activity})
end
@doc "POST /api/v1/statuses/:id/favourite"
- def favourite(%{assigns: %{user: user}} = conn, %{"id" => activity_id}) do
+ def favourite(%{assigns: %{user: user}} = conn, %{id: activity_id}) do
with {:ok, _fav} <- CommonAPI.favorite(user, activity_id),
%Activity{} = activity <- Activity.get_by_id(activity_id) do
try_render(conn, "show.json", activity: activity, for: user, as: :activity)
end
@doc "POST /api/v1/statuses/:id/unfavourite"
- def unfavourite(%{assigns: %{user: user}} = conn, %{"id" => activity_id}) do
+ def unfavourite(%{assigns: %{user: user}} = conn, %{id: activity_id}) do
with {:ok, _unfav} <- CommonAPI.unfavorite(activity_id, user),
%Activity{} = activity <- Activity.get_by_id(activity_id) do
try_render(conn, "show.json", activity: activity, for: user, as: :activity)
end
@doc "POST /api/v1/statuses/:id/pin"
- def pin(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
+ def pin(%{assigns: %{user: user}} = conn, %{id: ap_id_or_id}) do
with {:ok, activity} <- CommonAPI.pin(ap_id_or_id, user) do
try_render(conn, "show.json", activity: activity, for: user, as: :activity)
end
end
@doc "POST /api/v1/statuses/:id/unpin"
- def unpin(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
+ def unpin(%{assigns: %{user: user}} = conn, %{id: ap_id_or_id}) do
with {:ok, activity} <- CommonAPI.unpin(ap_id_or_id, user) do
try_render(conn, "show.json", activity: activity, for: user, as: :activity)
end
end
@doc "POST /api/v1/statuses/:id/bookmark"
- def bookmark(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ def bookmark(%{assigns: %{user: user}} = conn, %{id: id}) do
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
%User{} = user <- User.get_cached_by_nickname(user.nickname),
true <- Visibility.visible_for_user?(activity, user),
end
@doc "POST /api/v1/statuses/:id/unbookmark"
- def unbookmark(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ def unbookmark(%{assigns: %{user: user}} = conn, %{id: id}) do
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
%User{} = user <- User.get_cached_by_nickname(user.nickname),
true <- Visibility.visible_for_user?(activity, user),
end
@doc "POST /api/v1/statuses/:id/mute"
- def mute_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ def mute_conversation(%{assigns: %{user: user}} = conn, %{id: id}) do
with %Activity{} = activity <- Activity.get_by_id(id),
{:ok, activity} <- CommonAPI.add_mute(user, activity) do
try_render(conn, "show.json", activity: activity, for: user, as: :activity)
end
@doc "POST /api/v1/statuses/:id/unmute"
- def unmute_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ def unmute_conversation(%{assigns: %{user: user}} = conn, %{id: id}) do
with %Activity{} = activity <- Activity.get_by_id(id),
{:ok, activity} <- CommonAPI.remove_mute(user, activity) do
try_render(conn, "show.json", activity: activity, for: user, as: :activity)
@doc "GET /api/v1/statuses/:id/card"
@deprecated "https://github.com/tootsuite/mastodon/pull/11213"
- def card(%{assigns: %{user: user}} = conn, %{"id" => status_id}) do
+ def card(%{assigns: %{user: user}} = conn, %{id: status_id}) do
with %Activity{} = activity <- Activity.get_by_id(status_id),
true <- Visibility.visible_for_user?(activity, user) do
data = Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
end
@doc "GET /api/v1/statuses/:id/favourited_by"
- def favourited_by(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ def favourited_by(%{assigns: %{user: user}} = conn, %{id: id}) do
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
{:visible, true} <- {:visible, Visibility.visible_for_user?(activity, user)},
%Object{data: %{"likes" => likes}} <- Object.normalize(activity) do
end
@doc "GET /api/v1/statuses/:id/reblogged_by"
- def reblogged_by(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ def reblogged_by(%{assigns: %{user: user}} = conn, %{id: id}) do
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
{:visible, true} <- {:visible, Visibility.visible_for_user?(activity, user)},
%Object{data: %{"announcements" => announces, "id" => ap_id}} <-
end
@doc "GET /api/v1/statuses/:id/context"
- def context(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ def context(%{assigns: %{user: user}} = conn, %{id: id}) do
with %Activity{} = activity <- Activity.get_by_id(id) do
activities =
ActivityPub.fetch_activities_for_context(activity.data["context"], %{
@doc "GET /api/v1/favourites"
def favourites(%{assigns: %{user: %User{} = user}} = conn, params) do
- activities =
- ActivityPub.fetch_favourites(
- user,
- Map.take(params, Pleroma.Pagination.page_keys())
- )
+ params =
+ params
+ |> Map.new(fn {key, value} -> {to_string(key), value} end)
+ |> Map.take(Pleroma.Pagination.page_keys())
+
+ activities = ActivityPub.fetch_favourites(user, params)
conn
|> add_link_headers(activities)
defp maybe_put_role(data, _, _), do: data
defp maybe_put_notification_settings(data, %User{id: user_id} = user, %User{id: user_id}) do
- Kernel.put_in(data, [:pleroma, :notification_settings], user.notification_settings)
+ Kernel.put_in(
+ data,
+ [:pleroma, :notification_settings],
+ Map.from_struct(user.notification_settings)
+ )
end
defp maybe_put_notification_settings(data, _, _), do: data
end
defp post_activity(%ScheduledActivity{user_id: user_id, params: params} = scheduled_activity) do
+ params = Map.new(params, fn {key, value} -> {String.to_existing_atom(key), value} end)
+
with {:delete, {:ok, _}} <- {:delete, ScheduledActivity.delete(scheduled_activity)},
{:user, %User{} = user} <- {:user, User.get_cached_by_id(user_id)},
{:post, {:ok, _}} <- {:post, CommonAPI.post(user, params)} do
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
- {:ok, local_activity} = Pleroma.Web.CommonAPI.post(user, %{"status" => "find me!"})
- {:ok, japanese_activity} = Pleroma.Web.CommonAPI.post(user, %{"status" => "更新情報"})
+ {:ok, local_activity} = Pleroma.Web.CommonAPI.post(user, %{status: "find me!"})
+ {:ok, japanese_activity} = Pleroma.Web.CommonAPI.post(user, %{status: "更新情報"})
{:ok, job} = Pleroma.Web.Federator.incoming_ap_doc(params)
{:ok, remote_activity} = ObanHelpers.perform(job)
test "all_by_actor_and_id/2" do
user = insert(:user)
- {:ok, %{id: id1}} = Pleroma.Web.CommonAPI.post(user, %{"status" => "cofe"})
- {:ok, %{id: id2}} = Pleroma.Web.CommonAPI.post(user, %{"status" => "cofefe"})
+ {:ok, %{id: id1}} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
+ {:ok, %{id: id2}} = Pleroma.Web.CommonAPI.post(user, %{status: "cofefe"})
assert [] == Activity.all_by_actor_and_id(user, [])
{:ok, user} = User.follow(user, followed)
- {:ok, _first} = CommonAPI.post(user, %{"status" => "hey"})
- {:ok, _second} = CommonAPI.post(followed, %{"status" => "hello"})
+ {:ok, _first} = CommonAPI.post(user, %{status: "hey"})
+ {:ok, _second} = CommonAPI.post(followed, %{status: "hello"})
output =
capture_io(fn ->
user = insert(:user)
another_user = insert(:user)
- {:ok, activity} = CommonAPI.post(another_user, %{"status" => "this is a test post"})
+ {:ok, activity} = CommonAPI.post(another_user, %{status: "this is a test post"})
activity_object = Object.normalize(activity)
output =
describe "create/2" do
test "with valid params" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Some cool information"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "Some cool information"})
{:ok, bookmark} = Bookmark.create(user.id, activity.id)
assert bookmark.user_id == user.id
assert bookmark.activity_id == activity.id
test "with valid params" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Some cool information"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "Some cool information"})
{:ok, _bookmark} = Bookmark.create(user.id, activity.id)
{:ok, _deleted_bookmark} = Bookmark.destroy(user.id, activity.id)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
+ status:
"Scientists Discover The Secret Behind Tenshi Eating A Corndog Being So Cute – Science Daily"
})
other_user = insert(:user)
{:ok, _activity} =
- CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "Hey @#{other_user.nickname}.", visibility: "direct"})
[participation] = Participation.for_user(user)
other_user = insert(:user)
{:ok, _} =
- CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "Hey @#{other_user.nickname}.", visibility: "direct"})
user = User.get_cached_by_id(user.id)
other_user = User.get_cached_by_id(other_user.id)
{:ok, _} =
CommonAPI.post(other_user, %{
- "status" => "Hey @#{user.nickname}.",
- "visibility" => "direct",
- "in_reply_to_conversation_id" => participation.id
+ status: "Hey @#{user.nickname}.",
+ visibility: "direct",
+ in_reply_to_conversation_id: participation.id
})
user = User.get_cached_by_id(user.id)
third_user = insert(:user)
{:ok, activity} =
- CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "Hey @#{other_user.nickname}.", visibility: "direct"})
user = User.get_cached_by_id(user.id)
other_user = User.get_cached_by_id(other_user.id)
{:ok, _activity} =
CommonAPI.post(user, %{
- "in_reply_to_status_id" => activity.id,
- "status" => "Hey @#{third_user.nickname}.",
- "visibility" => "direct"
+ in_reply_to_status_id: activity.id,
+ status: "Hey @#{third_user.nickname}.",
+ visibility: "direct"
})
[participation] = Participation.for_user(user)
test "gets all the participations for a user, ordered by updated at descending" do
user = insert(:user)
- {:ok, activity_one} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
- {:ok, activity_two} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
+ {:ok, activity_one} = CommonAPI.post(user, %{status: "x", visibility: "direct"})
+ {:ok, activity_two} = CommonAPI.post(user, %{status: "x", visibility: "direct"})
{:ok, activity_three} =
CommonAPI.post(user, %{
- "status" => "x",
- "visibility" => "direct",
- "in_reply_to_status_id" => activity_one.id
+ status: "x",
+ visibility: "direct",
+ in_reply_to_status_id: activity_one.id
})
# Offset participations because the accuracy of updated_at is down to a second
test "Doesn't die when the conversation gets empty" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ {:ok, activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
[participation] = Participation.for_user_with_last_activity_id(user)
assert participation.last_activity_id == activity.id
user = insert(:user)
other_user = insert(:user)
- {:ok, _activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ {:ok, _activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
[participation] = Participation.for_user_with_last_activity_id(user)
participation = Repo.preload(participation, :recipients)
{:ok, _direct1} =
CommonAPI.post(third_user, %{
- "status" => "Hi @#{blocker.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}",
+ visibility: "direct"
})
{:ok, _direct2} =
CommonAPI.post(third_user, %{
- "status" => "Hi @#{blocker.nickname}, @#{blocked.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}, @#{blocked.nickname}",
+ visibility: "direct"
})
{:ok, _direct3} =
CommonAPI.post(blocked, %{
- "status" => "Hi @#{blocker.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}",
+ visibility: "direct"
})
{:ok, _direct4} =
CommonAPI.post(blocked, %{
- "status" => "Hi @#{blocker.nickname}, @#{third_user.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}, @#{third_user.nickname}",
+ visibility: "direct"
})
assert [%{read: false}, %{read: false}, %{read: false}, %{read: false}] =
# When the blocked user is the author
{:ok, _direct1} =
CommonAPI.post(blocked, %{
- "status" => "Hi @#{blocker.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}",
+ visibility: "direct"
})
assert [%{read: true}] = Participation.for_user(blocker)
# When the blocked user is a recipient
{:ok, _direct2} =
CommonAPI.post(third_user, %{
- "status" => "Hi @#{blocker.nickname}, @#{blocked.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}, @#{blocked.nickname}",
+ visibility: "direct"
})
assert [%{read: true}, %{read: true}] = Participation.for_user(blocker)
{:ok, _direct1} =
CommonAPI.post(blocker, %{
- "status" => "Hi @#{third_user.nickname}, @#{blocked.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{third_user.nickname}, @#{blocked.nickname}",
+ visibility: "direct"
})
{:ok, _user_relationship} = User.block(blocker, blocked)
# When it's a reply from the blocked user
{:ok, _direct2} =
CommonAPI.post(blocked, %{
- "status" => "reply",
- "visibility" => "direct",
- "in_reply_to_conversation_id" => blocked_participation.id
+ status: "reply",
+ visibility: "direct",
+ in_reply_to_conversation_id: blocked_participation.id
})
assert [%{read: true}] = Participation.for_user(blocker)
# When it's a reply from the third user
{:ok, _direct3} =
CommonAPI.post(third_user, %{
- "status" => "reply",
- "visibility" => "direct",
- "in_reply_to_conversation_id" => third_user_participation.id
+ status: "reply",
+ visibility: "direct",
+ in_reply_to_conversation_id: third_user_participation.id
})
assert [%{read: true}] = Participation.for_user(blocker)
other_user = insert(:user)
{:ok, _activity} =
- CommonAPI.post(user, %{"visibility" => "direct", "status" => "hey @#{other_user.nickname}"})
+ CommonAPI.post(user, %{visibility: "direct", status: "hey @#{other_user.nickname}"})
Pleroma.Tests.ObanHelpers.perform_all()
test "public posts don't create conversations" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "Hey"})
object = Pleroma.Object.normalize(activity)
context = object.data["context"]
tridi = insert(:user)
{:ok, activity} =
- CommonAPI.post(har, %{"status" => "Hey @#{jafnhar.nickname}", "visibility" => "direct"})
+ CommonAPI.post(har, %{status: "Hey @#{jafnhar.nickname}", visibility: "direct"})
object = Pleroma.Object.normalize(activity)
context = object.data["context"]
{:ok, activity} =
CommonAPI.post(jafnhar, %{
- "status" => "Hey @#{har.nickname}",
- "visibility" => "direct",
- "in_reply_to_status_id" => activity.id
+ status: "Hey @#{har.nickname}",
+ visibility: "direct",
+ in_reply_to_status_id: activity.id
})
object = Pleroma.Object.normalize(activity)
{:ok, activity} =
CommonAPI.post(tridi, %{
- "status" => "Hey @#{har.nickname}",
- "visibility" => "direct",
- "in_reply_to_status_id" => activity.id
+ status: "Hey @#{har.nickname}",
+ visibility: "direct",
+ in_reply_to_status_id: activity.id
})
object = Pleroma.Object.normalize(activity)
jafnhar = insert(:user, local: false)
{:ok, activity} =
- CommonAPI.post(har, %{"status" => "Hey @#{jafnhar.nickname}", "visibility" => "direct"})
+ CommonAPI.post(har, %{status: "Hey @#{jafnhar.nickname}", visibility: "direct"})
{:ok, conversation} = Conversation.create_or_bump_for(activity)
assert length(conversation.participations) == 2
{:ok, activity} =
- CommonAPI.post(har, %{"status" => "Hey @#{jafnhar.nickname}", "visibility" => "public"})
+ CommonAPI.post(har, %{status: "Hey @#{jafnhar.nickname}", visibility: "public"})
assert {:error, _} = Conversation.create_or_bump_for(activity)
end
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
+ status:
"I think I just found the best github repo https://github.com/komeiji-satori/Dress"
})
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
+ status:
"@#{other_user.nickname} install misskey! https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md"
})
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
- "#cofe https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
+ status: "#cofe https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
})
object = Object.normalize(activity)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
+ status:
"<a href=\"https://pleroma.gov/tags/cofe\" rel=\"tag\">#cofe</a> https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140",
- "content_type" => "text/html"
+ content_type: "text/html"
})
object = Object.normalize(activity)
test "does not crash when there is an HTML entity in a link" do
user = insert(:user)
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "\"http://cofe.com/?boomer=ok&foo=bar\""})
+ {:ok, activity} = CommonAPI.post(user, %{status: "\"http://cofe.com/?boomer=ok&foo=bar\""})
object = Object.normalize(activity)
test "receives well formatted events" do
user = insert(:user)
{:ok, _} = start_socket("?stream=public")
- {:ok, activity} = CommonAPI.post(user, %{"status" => "nice echo chamber"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "nice echo chamber"})
assert_receive {:text, raw_json}, 1_000
assert {:ok, json} = Jason.decode(raw_json)
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "yeah"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "yeah"})
{:ok, activity} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
{:ok, [notification]} = Notification.create_notifications(activity)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "hey @#{other_user.nickname} and @#{third_user.nickname}"
+ status: "hey @#{other_user.nickname} and @#{third_user.nickname}"
})
{:ok, [notification, other_notification]} = Notification.create_notifications(activity)
User.subscribe(subscriber, user)
- {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
+ {:ok, status} = CommonAPI.post(user, %{status: "Akariiiin"})
{:ok, [notification]} = Notification.create_notifications(status)
assert notification.user_id == subscriber.id
User.subscribe(subscriber, other_user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test post"})
{:ok, _reply_activity} =
CommonAPI.post(other_user, %{
- "status" => "test reply",
- "in_reply_to_status_id" => activity.id
+ status: "test reply",
+ in_reply_to_status_id: activity.id
})
user_notifications = Notification.for_user(user)
blocker = insert(:user)
{:ok, _user_relationship} = User.block(blocker, user)
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "hey @#{blocker.nickname}!"})
+ {:ok, _activity} = CommonAPI.post(user, %{status: "hey @#{blocker.nickname}!"})
blocker_id = blocker.id
assert [%Notification{user_id: ^blocker_id}] = Repo.all(Notification)
muter = insert(:user)
{:ok, _user_relationships} = User.mute(muter, user)
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "hey @#{muter.nickname}!"})
+ {:ok, _activity} = CommonAPI.post(user, %{status: "hey @#{muter.nickname}!"})
muter_id = muter.id
assert [%Notification{user_id: ^muter_id}] = Repo.all(Notification)
user = insert(:user)
thread_muter = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{thread_muter.nickname}!"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{thread_muter.nickname}!"})
{:ok, _} = CommonAPI.add_mute(thread_muter, activity)
{:ok, _same_context_activity} =
CommonAPI.post(user, %{
- "status" => "hey-hey-hey @#{thread_muter.nickname}!",
- "in_reply_to_status_id" => activity.id
+ status: "hey-hey-hey @#{thread_muter.nickname}!",
+ in_reply_to_status_id: activity.id
})
[pre_mute_notification, post_mute_notification] =
muted = insert(:user)
{:ok, _} = User.mute(muter, muted)
muter = Repo.get(User, muter.id)
- {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
+ {:ok, activity} = CommonAPI.post(muted, %{status: "Hi @#{muter.nickname}"})
assert Notification.create_notification(activity, muter)
end
{:ok, _user_relationships} = User.mute(muter, muted, false)
- {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
+ {:ok, activity} = CommonAPI.post(muted, %{status: "Hi @#{muter.nickname}"})
assert Notification.create_notification(activity, muter)
end
test "it creates a notification for an activity from a muted thread" do
muter = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(muter, %{"status" => "hey"})
+ {:ok, activity} = CommonAPI.post(muter, %{status: "hey"})
CommonAPI.add_mute(muter, activity)
{:ok, activity} =
CommonAPI.post(other_user, %{
- "status" => "Hi @#{muter.nickname}",
- "in_reply_to_status_id" => activity.id
+ status: "Hi @#{muter.nickname}",
+ in_reply_to_status_id: activity.id
})
assert Notification.create_notification(activity, muter)
insert(:user, notification_settings: %Pleroma.User.NotificationSetting{followers: false})
User.follow(follower, followed)
- {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
+ {:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"})
refute Notification.create_notification(activity, followed)
end
notification_settings: %Pleroma.User.NotificationSetting{non_followers: false}
)
- {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
+ {:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"})
refute Notification.create_notification(activity, followed)
end
followed = insert(:user)
User.follow(follower, followed)
follower = Repo.get(User, follower.id)
- {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
+ {:ok, activity} = CommonAPI.post(followed, %{status: "hey @#{follower.nickname}"})
refute Notification.create_notification(activity, follower)
end
insert(:user, notification_settings: %Pleroma.User.NotificationSetting{non_follows: false})
followed = insert(:user)
- {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
+ {:ok, activity} = CommonAPI.post(followed, %{status: "hey @#{follower.nickname}"})
refute Notification.create_notification(activity, follower)
end
{:ok, _, _, _} = CommonAPI.follow(subscriber, user)
User.subscribe(subscriber, user)
- {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
+ {:ok, status} = CommonAPI.post(user, %{status: "Akariiiin"})
{:ok, [_notif]} = Notification.create_notifications(status)
end
User.subscribe(subscriber, user)
- {:ok, status} = CommonAPI.post(user, %{"status" => "inwisible", "visibility" => "direct"})
+ {:ok, status} = CommonAPI.post(user, %{status: "inwisible", visibility: "direct"})
assert {:ok, []} == Notification.create_notifications(status)
end
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
{:ok, notification} = Notification.get(other_user, notification.id)
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
{:error, _notification} = Notification.get(user, notification.id)
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
{:ok, notification} = Notification.dismiss(other_user, notification.id)
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
{:error, _notification} = Notification.dismiss(user, notification.id)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
+ status: "hey @#{other_user.nickname} and @#{third_user.nickname} !"
})
{:ok, _notifs} = Notification.create_notifications(activity)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
+ status: "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
})
{:ok, _notifs} = Notification.create_notifications(activity)
{:ok, _activity} =
CommonAPI.post(user, %{
- "status" => "hey @#{other_user.nickname}!"
+ status: "hey @#{other_user.nickname}!"
})
{:ok, _activity} =
CommonAPI.post(user, %{
- "status" => "hey again @#{other_user.nickname}!"
+ status: "hey again @#{other_user.nickname}!"
})
[n2, n1] = notifs = Notification.for_user(other_user)
{:ok, _activity} =
CommonAPI.post(user, %{
- "status" => "hey yet again @#{other_user.nickname}!"
+ status: "hey yet again @#{other_user.nickname}!"
})
Notification.set_read_up_to(other_user, n2.id)
Enum.each(0..10, fn i ->
{:ok, _activity} =
CommonAPI.post(user1, %{
- "status" => "hey ##{i} @#{user2.nickname}!"
+ status: "hey ##{i} @#{user2.nickname}!"
})
end)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "hey @#{other_user.nickname}!"
+ status: "hey @#{other_user.nickname}!"
})
{enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
{:ok, activity_one} =
CommonAPI.post(user, %{
- "status" => "hey @#{other_user.nickname}!"
+ status: "hey @#{other_user.nickname}!"
})
{:ok, activity_two} = CommonAPI.favorite(third_user, activity_one.id)
{:ok, activity_one} =
CommonAPI.post(user, %{
- "status" => "hey @#{other_user.nickname}!"
+ status: "hey @#{other_user.nickname}!"
})
{:ok, like_data, _} = Builder.like(third_user, activity_one.object)
{:ok, activity_one} =
CommonAPI.post(user, %{
- "status" => "hey @#{other_user.nickname}!"
+ status: "hey @#{other_user.nickname}!"
})
{:ok, activity_two, _} = CommonAPI.repeat(activity_one.id, third_user)
other_user = insert(:user)
{:ok, _user_relationship} = User.block(other_user, user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
{enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
other_user = insert(:user)
{:ok, _user_relationships} = User.mute(other_user, user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
{enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
{:ok, _} = CommonAPI.add_mute(other_user, activity)
{:ok, same_context_activity} =
CommonAPI.post(user, %{
- "status" => "hey-hey-hey @#{other_user.nickname}!",
- "in_reply_to_status_id" => activity.id
+ status: "hey-hey-hey @#{other_user.nickname}!",
+ in_reply_to_status_id: activity.id
})
{enabled_receivers, disabled_receivers} =
{:ok, other_user} = User.block_domain(other_user, blocked_domain)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
{enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
{:ok, other_user} = User.block_domain(other_user, blocked_domain)
{:ok, other_user} = User.follow(other_user, user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
{enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test post"})
assert Enum.empty?(Notification.for_user(user))
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test post"})
assert Enum.empty?(Notification.for_user(user))
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test post"})
assert Enum.empty?(Notification.for_user(user))
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test post"})
assert Enum.empty?(Notification.for_user(user))
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test post"})
assert Enum.empty?(Notification.for_user(user))
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test post"})
assert Enum.empty?(Notification.for_user(user))
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test post"})
{:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
{:ok, _reply_activity} =
CommonAPI.post(other_user, %{
- "status" => "test reply",
- "in_reply_to_status_id" => activity.id
+ status: "test reply",
+ in_reply_to_status_id: activity.id
})
assert Enum.empty?(Notification.for_user(user))
other_user = insert(:user)
{:ok, _activity} =
- CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "hi @#{other_user.nickname}", visibility: "direct"})
refute Enum.empty?(Notification.for_user(other_user))
muted = insert(:user)
{:ok, _user_relationships} = User.mute(user, muted, false)
- {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(muted, %{status: "hey @#{user.nickname}"})
assert length(Notification.for_user(user)) == 1
end
muted = insert(:user)
{:ok, _user_relationships} = User.mute(user, muted)
- {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(muted, %{status: "hey @#{user.nickname}"})
assert Notification.for_user(user) == []
end
blocked = insert(:user)
{:ok, _user_relationship} = User.block(user, blocked)
- {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(blocked, %{status: "hey @#{user.nickname}"})
assert Notification.for_user(user) == []
end
blocked = insert(:user, ap_id: "http://some-domain.com")
{:ok, user} = User.block_domain(user, "some-domain.com")
- {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(blocked, %{status: "hey @#{user.nickname}"})
assert Notification.for_user(user) == []
end
{:ok, user} = User.block_domain(user, "some-domain.com")
{:ok, _} = User.follow(user, blocked)
- {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(blocked, %{status: "hey @#{user.nickname}"})
assert length(Notification.for_user(user)) == 1
end
user = insert(:user)
another_user = insert(:user)
- {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(another_user, %{status: "hey @#{user.nickname}"})
{:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
assert Notification.for_user(user) == []
muted = insert(:user)
{:ok, _user_relationships} = User.mute(user, muted)
- {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(muted, %{status: "hey @#{user.nickname}"})
assert length(Notification.for_user(user, %{with_muted: true})) == 1
end
blocked = insert(:user)
{:ok, _user_relationship} = User.block(user, blocked)
- {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(blocked, %{status: "hey @#{user.nickname}"})
assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
end
blocked = insert(:user, ap_id: "http://some-domain.com")
{:ok, user} = User.block_domain(user, "some-domain.com")
- {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(blocked, %{status: "hey @#{user.nickname}"})
assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
end
user = insert(:user)
another_user = insert(:user)
- {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(another_user, %{status: "hey @#{user.nickname}"})
{:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
assert length(Notification.for_user(user, %{with_muted: true})) == 1
user = insert(:user)
other_user = insert(:user)
- CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"})
+ CommonAPI.post(user, %{visibility: "public", status: "hey"})
Enum.each(0..1, fn _ ->
CommonAPI.post(user, %{
- "visibility" => "unlisted",
- "status" => "hey"
+ visibility: "unlisted",
+ status: "hey"
})
end)
Enum.each(0..2, fn _ ->
CommonAPI.post(user, %{
- "visibility" => "direct",
- "status" => "hey @#{other_user.nickname}"
+ visibility: "direct",
+ status: "hey @#{other_user.nickname}"
})
end)
Enum.each(0..3, fn _ ->
CommonAPI.post(user, %{
- "visibility" => "private",
- "status" => "hey"
+ visibility: "private",
+ status: "hey"
})
end)
test "on status delete" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"})
+ {:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
assert %{public: 1} = Pleroma.Stats.get_status_visibility_count()
CommonAPI.delete(activity.id, user)
assert %{public: 0} = Pleroma.Stats.get_status_visibility_count()
test "on status visibility update" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"})
+ {:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
assert %{public: 1, private: 0} = Pleroma.Stats.get_status_visibility_count()
- {:ok, _} = CommonAPI.update_activity_scope(activity.id, %{"visibility" => "private"})
+ {:ok, _} = CommonAPI.update_activity_scope(activity.id, %{visibility: "private"})
assert %{public: 0, private: 1} = Pleroma.Stats.get_status_visibility_count()
end
test "doesn't count unrelated activities" do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"})
+ {:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
_ = CommonAPI.follow(user, other_user)
CommonAPI.favorite(other_user, activity.id)
CommonAPI.repeat(activity.id, other_user)
test "counts statuses" do
user = insert(:user)
- {:ok, _} = CommonAPI.post(user, %{"status" => "test"})
- {:ok, _} = CommonAPI.post(user, %{"status" => "test2"})
+ {:ok, _} = CommonAPI.post(user, %{status: "test"})
+ {:ok, _} = CommonAPI.post(user, %{status: "test2"})
user2 = insert(:user)
- {:ok, _} = CommonAPI.post(user2, %{"status" => "test3"})
+ {:ok, _} = CommonAPI.post(user2, %{status: "test3"})
user = refresh_record(user)
user2 = refresh_record(user2)
describe "running remove_embedded_objects" do
test "it replaces objects with references" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test"})
new_data = Map.put(activity.data, "object", activity.object.data)
{:ok, activity} =
test "it turns OrderedCollection likes into empty arrays" do
[user, user2] = insert_pair(:user)
- {:ok, %{id: id, object: object}} = CommonAPI.post(user, %{"status" => "test"})
- {:ok, %{object: object2}} = CommonAPI.post(user, %{"status" => "test test"})
+ {:ok, %{id: id, object: object}} = CommonAPI.post(user, %{status: "test"})
+ {:ok, %{object: object2}} = CommonAPI.post(user, %{status: "test test"})
CommonAPI.favorite(user2, id)
Enum.each(0..10, fn i ->
{:ok, _activity} =
CommonAPI.post(user1, %{
- "status" => "hey ##{i} @#{user2.nickname}!"
+ status: "hey ##{i} @#{user2.nickname}!"
})
end)
user = insert(:user)
other_user = insert(:user)
- CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"})
+ CommonAPI.post(user, %{visibility: "public", status: "hey"})
Enum.each(0..1, fn _ ->
CommonAPI.post(user, %{
- "visibility" => "unlisted",
- "status" => "hey"
+ visibility: "unlisted",
+ status: "hey"
})
end)
Enum.each(0..2, fn _ ->
CommonAPI.post(user, %{
- "visibility" => "direct",
- "status" => "hey @#{other_user.nickname}"
+ visibility: "direct",
+ status: "hey @#{other_user.nickname}"
})
end)
Enum.each(0..3, fn _ ->
CommonAPI.post(user, %{
- "visibility" => "private",
- "status" => "hey"
+ visibility: "private",
+ status: "hey"
})
end)
test "a remote user's create activity is deleted when the object has been pruned" do
user = insert(:user)
- {:ok, post} = CommonAPI.post(user, %{"status" => "uguu"})
+ {:ok, post} = CommonAPI.post(user, %{status: "uguu"})
object = Object.normalize(post)
Object.prune(object)
actor = insert(:user)
user = insert(:user, local: true)
- {:ok, activity} = CommonAPI.post(actor, %{"status" => "hello"})
+ {:ok, activity} = CommonAPI.post(actor, %{status: "hello"})
{:ok, announce, _} = CommonAPI.repeat(activity.id, user)
recipients = User.get_recipients_from_activity(announce)
{:ok, activity} =
CommonAPI.post(actor, %{
- "status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"
+ status: "hey @#{addressed.nickname} @#{addressed_remote.nickname}"
})
assert Enum.map([actor, addressed], & &1.ap_id) --
{:ok, activity} =
CommonAPI.post(actor, %{
- "status" => "hey @#{addressed.nickname}"
+ status: "hey @#{addressed.nickname}"
})
assert Enum.map([actor, addressed], & &1.ap_id) --
{:ok, user2} = User.follow(user2, user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{user2.nickname}"})
activity = Repo.preload(activity, :bookmark)
setup do: clear_config([:instance, :federating])
test ".delete_user_activities deletes all create activities", %{user: user} do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "2hu"})
User.delete_user_activities(user)
{:ok, _} =
CommonAPI.post(user, %{
- "status" => "hey @#{to.nickname}"
+ status: "hey @#{to.nickname}"
})
end)
Enum.each(recipients, fn to ->
{:ok, _} =
CommonAPI.post(sender, %{
- "status" => "hey @#{to.nickname}"
+ status: "hey @#{to.nickname}"
})
{:ok, _} =
CommonAPI.post(sender, %{
- "status" => "hey again @#{to.nickname}"
+ status: "hey again @#{to.nickname}"
})
end)
test "cached purged after activity deletion", %{conn: conn} do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "cofe"})
uuid = String.split(activity.data["id"], "/") |> List.last()
describe "streaming out participations" do
test "it streams them out" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ {:ok, activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
{:ok, conversation} = Pleroma.Conversation.create_or_bump_for(activity)
stream: fn _, _ -> nil end do
{:ok, activity} =
CommonAPI.post(user_one, %{
- "status" => "@#{user_two.nickname}",
- "visibility" => "direct"
+ status: "@#{user_two.nickname}",
+ visibility: "direct"
})
conversation =
test "it restricts by the appropriate visibility" do
user = insert(:user)
- {:ok, public_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
+ {:ok, public_activity} = CommonAPI.post(user, %{status: ".", visibility: "public"})
- {:ok, direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ {:ok, direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
- {:ok, unlisted_activity} =
- CommonAPI.post(user, %{"status" => ".", "visibility" => "unlisted"})
+ {:ok, unlisted_activity} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"})
- {:ok, private_activity} =
- CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
+ {:ok, private_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
activities =
ActivityPub.fetch_activities([], %{:visibility => "direct", "actor_id" => user.ap_id})
test "it excludes by the appropriate visibility" do
user = insert(:user)
- {:ok, public_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
+ {:ok, public_activity} = CommonAPI.post(user, %{status: ".", visibility: "public"})
- {:ok, direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ {:ok, direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
- {:ok, unlisted_activity} =
- CommonAPI.post(user, %{"status" => ".", "visibility" => "unlisted"})
+ {:ok, unlisted_activity} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"})
- {:ok, private_activity} =
- CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
+ {:ok, private_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
activities =
ActivityPub.fetch_activities([], %{
test "it fetches the appropriate tag-restricted posts" do
user = insert(:user)
- {:ok, status_one} = CommonAPI.post(user, %{"status" => ". #test"})
- {:ok, status_two} = CommonAPI.post(user, %{"status" => ". #essais"})
- {:ok, status_three} = CommonAPI.post(user, %{"status" => ". #test #reject"})
+ {:ok, status_one} = CommonAPI.post(user, %{status: ". #test"})
+ {:ok, status_two} = CommonAPI.post(user, %{status: ". #essais"})
+ {:ok, status_three} = CommonAPI.post(user, %{status: ". #test #reject"})
fetch_one = ActivityPub.fetch_activities([], %{"type" => "Create", "tag" => "test"})
{:ok, _} =
CommonAPI.post(User.get_cached_by_id(user.id), %{
- "status" => "1",
- "visibility" => "public"
+ status: "1",
+ visibility: "public"
})
{:ok, _} =
CommonAPI.post(User.get_cached_by_id(user.id), %{
- "status" => "2",
- "visibility" => "unlisted"
+ status: "2",
+ visibility: "unlisted"
})
{:ok, _} =
CommonAPI.post(User.get_cached_by_id(user.id), %{
- "status" => "2",
- "visibility" => "private"
+ status: "2",
+ visibility: "private"
})
{:ok, _} =
CommonAPI.post(User.get_cached_by_id(user.id), %{
- "status" => "3",
- "visibility" => "direct"
+ status: "3",
+ visibility: "direct"
})
user = User.get_cached_by_id(user.id)
user = insert(:user)
user2 = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "1", "visibility" => "public"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "1", visibility: "public"})
ap_id = activity.data["id"]
- reply_data = %{"status" => "1", "in_reply_to_status_id" => activity.id}
+ reply_data = %{status: "1", in_reply_to_status_id: activity.id}
# public
- {:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "public"))
+ {:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "public"))
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert object.data["repliesCount"] == 1
# unlisted
- {:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "unlisted"))
+ {:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "unlisted"))
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert object.data["repliesCount"] == 2
# private
- {:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "private"))
+ {:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "private"))
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert object.data["repliesCount"] == 2
# direct
- {:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "direct"))
+ {:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "direct"))
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert object.data["repliesCount"] == 2
end
{:ok, _user_relationship} = User.block(blocker, blockee)
- {:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey!"})
+ {:ok, activity_one} = CommonAPI.post(friend, %{status: "hey!"})
- {:ok, activity_two} = CommonAPI.post(friend, %{"status" => "hey! @#{blockee.nickname}"})
+ {:ok, activity_two} = CommonAPI.post(friend, %{status: "hey! @#{blockee.nickname}"})
- {:ok, activity_three} = CommonAPI.post(blockee, %{"status" => "hey! @#{friend.nickname}"})
+ {:ok, activity_three} = CommonAPI.post(blockee, %{status: "hey! @#{friend.nickname}"})
- {:ok, activity_four} = CommonAPI.post(blockee, %{"status" => "hey! @#{blocker.nickname}"})
+ {:ok, activity_four} = CommonAPI.post(blockee, %{status: "hey! @#{blocker.nickname}"})
activities = ActivityPub.fetch_activities([], %{"blocking_user" => blocker})
{:ok, _user_relationship} = User.block(blocker, blockee)
- {:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey!"})
+ {:ok, activity_one} = CommonAPI.post(friend, %{status: "hey!"})
- {:ok, activity_two} = CommonAPI.post(blockee, %{"status" => "hey! @#{friend.nickname}"})
+ {:ok, activity_two} = CommonAPI.post(blockee, %{status: "hey! @#{friend.nickname}"})
{:ok, activity_three, _} = CommonAPI.repeat(activity_two.id, friend)
test "doesn't retrieve unlisted activities" do
user = insert(:user)
- {:ok, _unlisted_activity} =
- CommonAPI.post(user, %{"status" => "yeah", "visibility" => "unlisted"})
+ {:ok, _unlisted_activity} = CommonAPI.post(user, %{status: "yeah", visibility: "unlisted"})
- {:ok, listed_activity} = CommonAPI.post(user, %{"status" => "yeah"})
+ {:ok, listed_activity} = CommonAPI.post(user, %{status: "yeah"})
[activity] = ActivityPub.fetch_public_activities()
describe "announcing a private object" do
test "adds an announce activity to the db if the audience is not widened" do
user = insert(:user)
- {:ok, note_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
+ {:ok, note_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
object = Object.normalize(note_activity)
{:ok, announce_activity, object} = ActivityPub.announce(user, object, nil, true, false)
test "does not add an announce activity to the db if the audience is widened" do
user = insert(:user)
- {:ok, note_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
+ {:ok, note_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
object = Object.normalize(note_activity)
assert {:error, _} = ActivityPub.announce(user, object, nil, true, true)
test "does not add an announce activity to the db if the announcer is not the author" do
user = insert(:user)
announcer = insert(:user)
- {:ok, note_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
+ {:ok, note_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
object = Object.normalize(note_activity)
assert {:error, _} = ActivityPub.announce(announcer, object, nil, true, false)
{:ok, user3} = User.follow(user3, user2)
assert User.following?(user3, user2)
- {:ok, public_activity} = CommonAPI.post(user3, %{"status" => "hi 1"})
+ {:ok, public_activity} = CommonAPI.post(user3, %{status: "hi 1"})
- {:ok, private_activity_1} =
- CommonAPI.post(user3, %{"status" => "hi 2", "visibility" => "private"})
+ {:ok, private_activity_1} = CommonAPI.post(user3, %{status: "hi 2", visibility: "private"})
{:ok, private_activity_2} =
CommonAPI.post(user2, %{
- "status" => "hi 3",
- "visibility" => "private",
- "in_reply_to_status_id" => private_activity_1.id
+ status: "hi 3",
+ visibility: "private",
+ in_reply_to_status_id: private_activity_1.id
})
{:ok, private_activity_3} =
CommonAPI.post(user3, %{
- "status" => "hi 4",
- "visibility" => "private",
- "in_reply_to_status_id" => private_activity_2.id
+ status: "hi 4",
+ visibility: "private",
+ in_reply_to_status_id: private_activity_2.id
})
activities =
Config.put([:instance, :max_pinned_statuses], 3)
user = insert(:user)
- {:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
- {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
- {:ok, activity_three} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity_one} = CommonAPI.post(user, %{status: "HI!!!"})
+ {:ok, activity_two} = CommonAPI.post(user, %{status: "HI!!!"})
+ {:ok, activity_three} = CommonAPI.post(user, %{status: "HI!!!"})
CommonAPI.pin(activity_one.id, user)
user = refresh_record(user)
reporter = insert(:user)
target_account = insert(:user)
content = "foobar"
- {:ok, activity} = CommonAPI.post(target_account, %{"status" => content})
+ {:ok, activity} = CommonAPI.post(target_account, %{status: content})
context = Utils.generate_context_id()
reporter_ap_id = reporter.ap_id
{:ok, list} = Pleroma.List.create("foo", user)
{:ok, list} = Pleroma.List.follow(list, member)
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})
activity = Repo.preload(activity, :bookmark)
activity = %Activity{activity | thread_muted?: !!activity.thread_muted?}
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "thought I looked cute might delete later :3",
- "visibility" => "private"
+ status: "thought I looked cute might delete later :3",
+ visibility: "private"
})
[result] = ActivityPub.fetch_activities_bounded([user.follower_address], [])
test "fetches only public posts for other users" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe", "visibility" => "public"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "#cofe", visibility: "public"})
{:ok, _private_activity} =
CommonAPI.post(user, %{
- "status" => "why is tenshi eating a corndog so cute?",
- "visibility" => "private"
+ status: "why is tenshi eating a corndog so cute?",
+ visibility: "private"
})
[result] = ActivityPub.fetch_activities_bounded([], [user.follower_address])
other_user = insert(:user)
user1 = insert(:user)
user2 = insert(:user)
- {:ok, a1} = CommonAPI.post(user1, %{"status" => "bla"})
- {:ok, _a2} = CommonAPI.post(user2, %{"status" => "traps are happy"})
- {:ok, a3} = CommonAPI.post(user2, %{"status" => "Trees Are "})
- {:ok, a4} = CommonAPI.post(user2, %{"status" => "Agent Smith "})
- {:ok, a5} = CommonAPI.post(user1, %{"status" => "Red or Blue "})
+ {:ok, a1} = CommonAPI.post(user1, %{status: "bla"})
+ {:ok, _a2} = CommonAPI.post(user2, %{status: "traps are happy"})
+ {:ok, a3} = CommonAPI.post(user2, %{status: "Trees Are "})
+ {:ok, a4} = CommonAPI.post(user2, %{status: "Agent Smith "})
+ {:ok, a5} = CommonAPI.post(user1, %{status: "Red or Blue "})
{:ok, _} = CommonAPI.favorite(user, a4.id)
{:ok, _} = CommonAPI.favorite(other_user, a3.id)
test "doesn't retrieve replies activities with exclude_replies" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "yeah"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "yeah"})
- {:ok, _reply} =
- CommonAPI.post(user, %{"status" => "yeah", "in_reply_to_status_id" => activity.id})
+ {:ok, _reply} = CommonAPI.post(user, %{status: "yeah", in_reply_to_status_id: activity.id})
[result] = ActivityPub.fetch_public_activities(%{"exclude_replies" => "true"})
{:ok, u2} = User.follow(u2, u3)
{:ok, u3} = User.follow(u3, u2)
- {:ok, a1} = CommonAPI.post(u1, %{"status" => "Status"})
+ {:ok, a1} = CommonAPI.post(u1, %{status: "Status"})
{:ok, r1_1} =
CommonAPI.post(u2, %{
- "status" => "@#{u1.nickname} reply from u2 to u1",
- "in_reply_to_status_id" => a1.id
+ status: "@#{u1.nickname} reply from u2 to u1",
+ in_reply_to_status_id: a1.id
})
{:ok, r1_2} =
CommonAPI.post(u3, %{
- "status" => "@#{u1.nickname} reply from u3 to u1",
- "in_reply_to_status_id" => a1.id
+ status: "@#{u1.nickname} reply from u3 to u1",
+ in_reply_to_status_id: a1.id
})
{:ok, r1_3} =
CommonAPI.post(u4, %{
- "status" => "@#{u1.nickname} reply from u4 to u1",
- "in_reply_to_status_id" => a1.id
+ status: "@#{u1.nickname} reply from u4 to u1",
+ in_reply_to_status_id: a1.id
})
- {:ok, a2} = CommonAPI.post(u2, %{"status" => "Status"})
+ {:ok, a2} = CommonAPI.post(u2, %{status: "Status"})
{:ok, r2_1} =
CommonAPI.post(u1, %{
- "status" => "@#{u2.nickname} reply from u1 to u2",
- "in_reply_to_status_id" => a2.id
+ status: "@#{u2.nickname} reply from u1 to u2",
+ in_reply_to_status_id: a2.id
})
{:ok, r2_2} =
CommonAPI.post(u3, %{
- "status" => "@#{u2.nickname} reply from u3 to u2",
- "in_reply_to_status_id" => a2.id
+ status: "@#{u2.nickname} reply from u3 to u2",
+ in_reply_to_status_id: a2.id
})
{:ok, r2_3} =
CommonAPI.post(u4, %{
- "status" => "@#{u2.nickname} reply from u4 to u2",
- "in_reply_to_status_id" => a2.id
+ status: "@#{u2.nickname} reply from u4 to u2",
+ in_reply_to_status_id: a2.id
})
- {:ok, a3} = CommonAPI.post(u3, %{"status" => "Status"})
+ {:ok, a3} = CommonAPI.post(u3, %{status: "Status"})
{:ok, r3_1} =
CommonAPI.post(u1, %{
- "status" => "@#{u3.nickname} reply from u1 to u3",
- "in_reply_to_status_id" => a3.id
+ status: "@#{u3.nickname} reply from u1 to u3",
+ in_reply_to_status_id: a3.id
})
{:ok, r3_2} =
CommonAPI.post(u2, %{
- "status" => "@#{u3.nickname} reply from u2 to u3",
- "in_reply_to_status_id" => a3.id
+ status: "@#{u3.nickname} reply from u2 to u3",
+ in_reply_to_status_id: a3.id
})
{:ok, r3_3} =
CommonAPI.post(u4, %{
- "status" => "@#{u3.nickname} reply from u4 to u3",
- "in_reply_to_status_id" => a3.id
+ status: "@#{u3.nickname} reply from u4 to u3",
+ in_reply_to_status_id: a3.id
})
- {:ok, a4} = CommonAPI.post(u4, %{"status" => "Status"})
+ {:ok, a4} = CommonAPI.post(u4, %{status: "Status"})
{:ok, r4_1} =
CommonAPI.post(u1, %{
- "status" => "@#{u4.nickname} reply from u1 to u4",
- "in_reply_to_status_id" => a4.id
+ status: "@#{u4.nickname} reply from u1 to u4",
+ in_reply_to_status_id: a4.id
})
{:ok, r4_2} =
CommonAPI.post(u2, %{
- "status" => "@#{u4.nickname} reply from u2 to u4",
- "in_reply_to_status_id" => a4.id
+ status: "@#{u4.nickname} reply from u2 to u4",
+ in_reply_to_status_id: a4.id
})
{:ok, r4_3} =
CommonAPI.post(u3, %{
- "status" => "@#{u4.nickname} reply from u3 to u4",
- "in_reply_to_status_id" => a4.id
+ status: "@#{u4.nickname} reply from u3 to u4",
+ in_reply_to_status_id: a4.id
})
{:ok,
{:ok, u2} = User.follow(u2, u3)
{:ok, u3} = User.follow(u3, u2)
- {:ok, a1} = CommonAPI.post(u1, %{"status" => "Status", "visibility" => "private"})
+ {:ok, a1} = CommonAPI.post(u1, %{status: "Status", visibility: "private"})
{:ok, r1_1} =
CommonAPI.post(u2, %{
- "status" => "@#{u1.nickname} reply from u2 to u1",
- "in_reply_to_status_id" => a1.id,
- "visibility" => "private"
+ status: "@#{u1.nickname} reply from u2 to u1",
+ in_reply_to_status_id: a1.id,
+ visibility: "private"
})
{:ok, r1_2} =
CommonAPI.post(u3, %{
- "status" => "@#{u1.nickname} reply from u3 to u1",
- "in_reply_to_status_id" => a1.id,
- "visibility" => "private"
+ status: "@#{u1.nickname} reply from u3 to u1",
+ in_reply_to_status_id: a1.id,
+ visibility: "private"
})
{:ok, r1_3} =
CommonAPI.post(u4, %{
- "status" => "@#{u1.nickname} reply from u4 to u1",
- "in_reply_to_status_id" => a1.id,
- "visibility" => "private"
+ status: "@#{u1.nickname} reply from u4 to u1",
+ in_reply_to_status_id: a1.id,
+ visibility: "private"
})
- {:ok, a2} = CommonAPI.post(u2, %{"status" => "Status", "visibility" => "private"})
+ {:ok, a2} = CommonAPI.post(u2, %{status: "Status", visibility: "private"})
{:ok, r2_1} =
CommonAPI.post(u1, %{
- "status" => "@#{u2.nickname} reply from u1 to u2",
- "in_reply_to_status_id" => a2.id,
- "visibility" => "private"
+ status: "@#{u2.nickname} reply from u1 to u2",
+ in_reply_to_status_id: a2.id,
+ visibility: "private"
})
{:ok, r2_2} =
CommonAPI.post(u3, %{
- "status" => "@#{u2.nickname} reply from u3 to u2",
- "in_reply_to_status_id" => a2.id,
- "visibility" => "private"
+ status: "@#{u2.nickname} reply from u3 to u2",
+ in_reply_to_status_id: a2.id,
+ visibility: "private"
})
- {:ok, a3} = CommonAPI.post(u3, %{"status" => "Status", "visibility" => "private"})
+ {:ok, a3} = CommonAPI.post(u3, %{status: "Status", visibility: "private"})
{:ok, r3_1} =
CommonAPI.post(u1, %{
- "status" => "@#{u3.nickname} reply from u1 to u3",
- "in_reply_to_status_id" => a3.id,
- "visibility" => "private"
+ status: "@#{u3.nickname} reply from u1 to u3",
+ in_reply_to_status_id: a3.id,
+ visibility: "private"
})
{:ok, r3_2} =
CommonAPI.post(u2, %{
- "status" => "@#{u3.nickname} reply from u2 to u3",
- "in_reply_to_status_id" => a3.id,
- "visibility" => "private"
+ status: "@#{u3.nickname} reply from u2 to u3",
+ in_reply_to_status_id: a3.id,
+ visibility: "private"
})
- {:ok, a4} = CommonAPI.post(u4, %{"status" => "Status", "visibility" => "private"})
+ {:ok, a4} = CommonAPI.post(u4, %{status: "Status", visibility: "private"})
{:ok, r4_1} =
CommonAPI.post(u1, %{
- "status" => "@#{u4.nickname} reply from u1 to u4",
- "in_reply_to_status_id" => a4.id,
- "visibility" => "private"
+ status: "@#{u4.nickname} reply from u1 to u4",
+ in_reply_to_status_id: a4.id,
+ visibility: "private"
})
{:ok,
describe "EmojiReacts" do
setup do
user = insert(:user)
- {:ok, post_activity} = CommonAPI.post(user, %{"status" => "uguu"})
+ {:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"})
object = Pleroma.Object.get_by_ap_id(post_activity.data["object"])
describe "Undos" do
setup do
user = insert(:user)
- {:ok, post_activity} = CommonAPI.post(user, %{"status" => "uguu"})
+ {:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"})
{:ok, like} = CommonAPI.favorite(user, post_activity.id)
{:ok, valid_like_undo, []} = Builder.undo(user, like)
describe "deletes" do
setup do
user = insert(:user)
- {:ok, post_activity} = CommonAPI.post(user, %{"status" => "cancel me daddy"})
+ {:ok, post_activity} = CommonAPI.post(user, %{status: "cancel me daddy"})
{:ok, valid_post_delete, _} = Builder.delete(user, post_activity.data["object"])
{:ok, valid_user_delete, _} = Builder.delete(user, user.ap_id)
describe "likes" do
setup do
user = insert(:user)
- {:ok, post_activity} = CommonAPI.post(user, %{"status" => "uguu"})
+ {:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"})
valid_like = %{
"to" => [user.ap_id],
user = insert(:user)
other_user = insert(:user)
- {:ok, op} = CommonAPI.post(other_user, %{"status" => "big oof"})
- {:ok, post} = CommonAPI.post(user, %{"status" => "hey", "in_reply_to_id" => op})
+ {:ok, op} = CommonAPI.post(other_user, %{status: "big oof"})
+ {:ok, post} = CommonAPI.post(user, %{status: "hey", in_reply_to_id: op})
{:ok, favorite} = CommonAPI.favorite(user, post.id)
object = Object.normalize(post)
{:ok, delete_data, _meta} = Builder.delete(user, object.data["id"])
poster = insert(:user)
user = insert(:user)
- {:ok, post} = CommonAPI.post(poster, %{"status" => "hey"})
+ {:ok, post} = CommonAPI.post(poster, %{status: "hey"})
{:ok, emoji_react_data, []} = Builder.emoji_react(user, post.object, "👌")
{:ok, emoji_react, _meta} = ActivityPub.persist(emoji_react_data, local: true)
setup do
poster = insert(:user)
user = insert(:user)
- {:ok, post} = CommonAPI.post(poster, %{"status" => "hey"})
+ {:ok, post} = CommonAPI.post(poster, %{status: "hey"})
{:ok, like} = CommonAPI.favorite(user, post.id)
{:ok, reaction} = CommonAPI.react_with_emoji(post.id, user, "👍")
{:ok, announce, _} = CommonAPI.repeat(post.id, user)
setup do
poster = insert(:user)
user = insert(:user)
- {:ok, post} = CommonAPI.post(poster, %{"status" => "hey"})
+ {:ok, post} = CommonAPI.post(poster, %{status: "hey"})
{:ok, like_data, _meta} = Builder.like(user, post.object)
{:ok, like, _meta} = ActivityPub.persist(like_data, local: true)
test "it works for incoming emoji reactions" do
user = insert(:user)
other_user = insert(:user, local: false)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
data =
File.read!("test/fixtures/emoji-reaction.json")
test "it reject invalid emoji reactions" do
user = insert(:user)
other_user = insert(:user, local: false)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
data =
File.read!("test/fixtures/emoji-reaction-too-long.json")
test "it works for incoming likes" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
data =
File.read!("test/fixtures/mastodon-like.json")
test "it works for incoming misskey likes, turning them into EmojiReacts" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
data =
File.read!("test/fixtures/misskey-like.json")
test "it works for incoming misskey likes that contain unicode emojis, turning them into EmojiReacts" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
data =
File.read!("test/fixtures/misskey-like.json")
test "it works for incoming emoji reaction undos" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
{:ok, reaction_activity} = CommonAPI.react_with_emoji(activity.id, user, "👌")
data =
test "it returns an error for incoming unlikes wihout a like activity" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "leave a like pls"})
data =
File.read!("test/fixtures/mastodon-undo-like.json")
test "it works for incoming unlikes with an existing like activity" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "leave a like pls"})
like_data =
File.read!("test/fixtures/mastodon-like.json")
test "it works for incoming unlikes with an existing like activity and a compact object" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "leave a like pls"})
like_data =
File.read!("test/fixtures/mastodon-like.json")
test "it works for incoming unannounces with an existing notice" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
announce_data =
File.read!("test/fixtures/mastodon-announce.json")
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "suya...",
- "poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
+ status: "suya...",
+ poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
})
object = Object.normalize(activity)
test "it works for incoming honk announces" do
_user = insert(:user, ap_id: "https://honktest/u/test", local: false)
other_user = insert(:user)
- {:ok, post} = CommonAPI.post(other_user, %{"status" => "bonkeronk"})
+ {:ok, post} = CommonAPI.post(other_user, %{status: "bonkeronk"})
announce = %{
"@context" => "https://www.w3.org/ns/activitystreams",
test "it works for incoming announces with an existing activity" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
data =
File.read!("test/fixtures/mastodon-announce.json")
test "it does not clobber the addressing on announce activities" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
data =
File.read!("test/fixtures/mastodon-announce.json")
test "it strips internal reactions" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "#cofe"})
{:ok, _} = CommonAPI.react_with_emoji(activity.id, user, "📢")
%{object: object} = Activity.get_by_id_with_object(activity.id)
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test post"})
object = Object.normalize(activity)
note_obj = %{
setup do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "post1"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "post1"})
{:ok, reply1} =
- CommonAPI.post(user, %{"status" => "reply1", "in_reply_to_status_id" => activity.id})
+ CommonAPI.post(user, %{status: "reply1", in_reply_to_status_id: activity.id})
{:ok, reply2} =
- CommonAPI.post(user, %{"status" => "reply2", "in_reply_to_status_id" => activity.id})
+ CommonAPI.post(user, %{status: "reply2", in_reply_to_status_id: activity.id})
replies_uris = Enum.map([reply1, reply2], fn a -> a.object.data["id"] end)
test "it inlines private announced objects" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey", "visibility" => "private"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey", visibility: "private"})
{:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
other_user = insert(:user)
{:ok, activity} =
- CommonAPI.post(user, %{"status" => "hey, @#{other_user.nickname}, how are ya? #2hu"})
+ CommonAPI.post(user, %{status: "hey, @#{other_user.nickname}, how are ya? #2hu"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
object = modified["object"]
test "it adds the sensitive property" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#nsfw hey"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "#nsfw hey"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
assert modified["object"]["sensitive"]
test "it adds the json-ld context and the conversation property" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
assert modified["@context"] ==
test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
assert modified["object"]["actor"] == modified["object"]["attributedTo"]
test "it strips internal hashtag data" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "#2hu"})
expected_tag = %{
"href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
test "it strips internal fields" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :firefox:"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "#2hu :firefox:"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu :moominmamma:"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "2hu :moominmamma:"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
assert modified["directMessage"] == false
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "@#{other_user.nickname} :moominmamma:"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "@#{other_user.nickname} :moominmamma:"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "@#{other_user.nickname} :moominmamma:",
- "visibility" => "direct"
+ status: "@#{other_user.nickname} :moominmamma:",
+ visibility: "direct"
})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
user = insert(:user)
{:ok, list} = Pleroma.List.create("foo", user)
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
user_two = insert(:user)
Pleroma.FollowingRelationship.follow(user_two, user, :follow_accept)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
- {:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test"})
+ {:ok, unrelated_activity} = CommonAPI.post(user_two, %{status: "test"})
assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
user = User.get_cached_by_id(user.id)
{:ok, poll_activity} =
CommonAPI.post(user, %{
- "status" => "suya...",
- "poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
+ status: "suya...",
+ poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
})
poll_object = Object.normalize(poll_activity)
test "sets `replies` collection with a limited number of self-replies" do
[user, another_user] = insert_list(2, :user)
- {:ok, %{id: id1} = activity} = CommonAPI.post(user, %{"status" => "1"})
+ {:ok, %{id: id1} = activity} = CommonAPI.post(user, %{status: "1"})
{:ok, %{id: id2} = self_reply1} =
- CommonAPI.post(user, %{"status" => "self-reply 1", "in_reply_to_status_id" => id1})
+ CommonAPI.post(user, %{status: "self-reply 1", in_reply_to_status_id: id1})
{:ok, self_reply2} =
- CommonAPI.post(user, %{"status" => "self-reply 2", "in_reply_to_status_id" => id1})
+ CommonAPI.post(user, %{status: "self-reply 2", in_reply_to_status_id: id1})
# Assuming to _not_ be present in `replies` due to :note_replies_output_limit is set to 2
- {:ok, _} =
- CommonAPI.post(user, %{"status" => "self-reply 3", "in_reply_to_status_id" => id1})
+ {:ok, _} = CommonAPI.post(user, %{status: "self-reply 3", in_reply_to_status_id: id1})
{:ok, _} =
CommonAPI.post(user, %{
- "status" => "self-reply to self-reply",
- "in_reply_to_status_id" => id2
+ status: "self-reply to self-reply",
+ in_reply_to_status_id: id2
})
{:ok, _} =
CommonAPI.post(another_user, %{
- "status" => "another user's reply",
- "in_reply_to_status_id" => id1
+ status: "another user's reply",
+ in_reply_to_status_id: id1
})
object = Object.normalize(activity)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
+ status:
"hey @#{other_user.nickname}, @#{third_user.nickname} how about beering together this weekend?"
})
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "@#{other_user.nickname} @#{third_user.nickname} bought a new swimsuit!",
- "visibility" => "private"
+ status: "@#{other_user.nickname} @#{third_user.nickname} bought a new swimsuit!",
+ visibility: "private"
})
%{"to" => to, "cc" => cc} = Utils.make_like_data(other_user, activity, nil)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "How do I pronounce LaTeX?",
- "poll" => %{
- "options" => ["laytekh", "lahtekh", "latex"],
- "expires_in" => 20,
- "multiple" => true
+ status: "How do I pronounce LaTeX?",
+ poll: %{
+ options: ["laytekh", "lahtekh", "latex"],
+ expires_in: 20,
+ multiple: true
}
})
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "Are we living in a society?",
- "poll" => %{
- "options" => ["yes", "no"],
- "expires_in" => 20
+ status: "Are we living in a society?",
+ poll: %{
+ options: ["yes", "no"],
+ expires_in: 20
}
})
test "returns map with Flag object" do
reporter = insert(:user)
target_account = insert(:user)
- {:ok, activity} = CommonAPI.post(target_account, %{"status" => "foobar"})
+ {:ok, activity} = CommonAPI.post(target_account, %{status: "foobar"})
context = Utils.generate_context_id()
content = "foobar"
activity = insert(:note_activity, user: user)
{:ok, self_reply1} =
- CommonAPI.post(user, %{"status" => "self-reply 1", "in_reply_to_status_id" => activity.id})
+ CommonAPI.post(user, %{status: "self-reply 1", in_reply_to_status_id: activity.id})
replies_uris = [self_reply1.object.data["id"]]
result = ObjectView.render("object.json", %{object: refresh_record(activity)})
posts =
for i <- 0..25 do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "post #{i}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "post #{i}"})
activity
end
Pleroma.List.follow(list, unrelated)
{:ok, public} =
- CommonAPI.post(user, %{"status" => "@#{mentioned.nickname}", "visibility" => "public"})
+ CommonAPI.post(user, %{status: "@#{mentioned.nickname}", visibility: "public"})
{:ok, private} =
- CommonAPI.post(user, %{"status" => "@#{mentioned.nickname}", "visibility" => "private"})
+ CommonAPI.post(user, %{status: "@#{mentioned.nickname}", visibility: "private"})
{:ok, direct} =
- CommonAPI.post(user, %{"status" => "@#{mentioned.nickname}", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "@#{mentioned.nickname}", visibility: "direct"})
{:ok, unlisted} =
- CommonAPI.post(user, %{"status" => "@#{mentioned.nickname}", "visibility" => "unlisted"})
+ CommonAPI.post(user, %{status: "@#{mentioned.nickname}", visibility: "unlisted"})
{:ok, list} =
CommonAPI.post(user, %{
- "status" => "@#{mentioned.nickname}",
- "visibility" => "list:#{list.id}"
+ status: "@#{mentioned.nickname}",
+ visibility: "list:#{list.id}"
})
%{
test "change visibility flag", %{conn: conn, id: id, admin: admin} do
response =
conn
- |> put("/api/pleroma/admin/statuses/#{id}", %{"visibility" => "public"})
+ |> put("/api/pleroma/admin/statuses/#{id}", %{visibility: "public"})
|> json_response(:ok)
assert response["visibility"] == "public"
response =
conn
- |> put("/api/pleroma/admin/statuses/#{id}", %{"visibility" => "private"})
+ |> put("/api/pleroma/admin/statuses/#{id}", %{visibility: "private"})
|> json_response(:ok)
assert response["visibility"] == "private"
response =
conn
- |> put("/api/pleroma/admin/statuses/#{id}", %{"visibility" => "unlisted"})
+ |> put("/api/pleroma/admin/statuses/#{id}", %{visibility: "unlisted"})
|> json_response(:ok)
assert response["visibility"] == "unlisted"
end
test "returns 400 when visibility is unknown", %{conn: conn, id: id} do
- conn = put(conn, "/api/pleroma/admin/statuses/#{id}", %{"visibility" => "test"})
+ conn = put(conn, "/api/pleroma/admin/statuses/#{id}", %{visibility: "test"})
assert json_response(conn, :bad_request) == "Unsupported visibility"
end
user = insert(:user)
User.block(admin, blocked)
- {:ok, _} =
- CommonAPI.post(user, %{"status" => "@#{admin.nickname}", "visibility" => "direct"})
+ {:ok, _} = CommonAPI.post(user, %{status: "@#{admin.nickname}", visibility: "direct"})
- {:ok, _} = CommonAPI.post(user, %{"status" => ".", "visibility" => "unlisted"})
- {:ok, _} = CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
- {:ok, _} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
- {:ok, _} = CommonAPI.post(blocked, %{"status" => ".", "visibility" => "public"})
+ {:ok, _} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"})
+ {:ok, _} = CommonAPI.post(user, %{status: ".", visibility: "private"})
+ {:ok, _} = CommonAPI.post(user, %{status: ".", visibility: "public"})
+ {:ok, _} = CommonAPI.post(blocked, %{status: ".", visibility: "public"})
response =
conn
test "returns private and direct statuses with godmode on", %{conn: conn, admin: admin} do
user = insert(:user)
- {:ok, _} =
- CommonAPI.post(user, %{"status" => "@#{admin.nickname}", "visibility" => "direct"})
+ {:ok, _} = CommonAPI.post(user, %{status: "@#{admin.nickname}", visibility: "direct"})
- {:ok, _} = CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
- {:ok, _} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
+ {:ok, _} = CommonAPI.post(user, %{status: ".", visibility: "private"})
+ {:ok, _} = CommonAPI.post(user, %{status: ".", visibility: "public"})
conn = get(conn, "/api/pleroma/admin/statuses?godmode=true")
assert json_response(conn, 200) |> length() == 3
end
end
test "doesn't return private statuses by default", %{conn: conn, user: user} do
- {:ok, _private_status} =
- CommonAPI.post(user, %{"status" => "private", "visibility" => "private"})
+ {:ok, _private_status} = CommonAPI.post(user, %{status: "private", visibility: "private"})
- {:ok, _public_status} =
- CommonAPI.post(user, %{"status" => "public", "visibility" => "public"})
+ {:ok, _public_status} = CommonAPI.post(user, %{status: "public", visibility: "public"})
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses")
end
test "returns private statuses with godmode on", %{conn: conn, user: user} do
- {:ok, _private_status} =
- CommonAPI.post(user, %{"status" => "private", "visibility" => "private"})
+ {:ok, _private_status} = CommonAPI.post(user, %{status: "private", visibility: "private"})
- {:ok, _public_status} =
- CommonAPI.post(user, %{"status" => "public", "visibility" => "public"})
+ {:ok, _public_status} = CommonAPI.post(user, %{status: "public", visibility: "public"})
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?godmode=true")
test "excludes reblogs by default", %{conn: conn, user: user} do
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "."})
+ {:ok, activity} = CommonAPI.post(user, %{status: "."})
{:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, other_user)
conn_res = get(conn, "/api/pleroma/admin/users/#{other_user.nickname}/statuses")
test "status visibility count", %{conn: conn} do
admin = insert(:user, is_admin: true)
user = insert(:user)
- CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"})
- CommonAPI.post(user, %{"visibility" => "unlisted", "status" => "hey"})
- CommonAPI.post(user, %{"visibility" => "unlisted", "status" => "hey"})
+ CommonAPI.post(user, %{visibility: "public", status: "hey"})
+ CommonAPI.post(user, %{visibility: "unlisted", status: "hey"})
+ CommonAPI.post(user, %{visibility: "unlisted", status: "hey"})
response =
conn
test "includes reported statuses" do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "toot"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "toot"})
{:ok, report_activity} =
CommonAPI.report(user, %{account_id: other_user.id, status_ids: [activity.id]})
test "it works with pruned objects" do
user = insert(:user)
- {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+ {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
Object.normalize(post, false)
|> Object.prune()
test "it allows users to delete their posts" do
user = insert(:user)
- {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+ {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
with_mock Pleroma.Web.Federator,
publish: fn _ -> nil end do
user = insert(:user)
other_user = insert(:user)
- {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+ {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
assert {:error, "Could not delete"} = CommonAPI.delete(post.id, other_user)
assert Activity.get_by_id(post.id)
user = insert(:user)
moderator = insert(:user, is_moderator: true)
- {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+ {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
assert delete.local
user = insert(:user)
moderator = insert(:user, is_admin: true)
- {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+ {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
assert delete.local
users_serial = insert_list(10, :user)
users = insert_list(10, :user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "."})
+ {:ok, activity} = CommonAPI.post(user, %{status: "."})
users_serial
|> Enum.map(fn user ->
users_serial = insert_list(10, :user)
users = insert_list(10, :user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "."})
+ {:ok, activity} = CommonAPI.post(user, %{status: "."})
users_serial
|> Enum.map(fn user ->
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ {:ok, activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
[participation] = Participation.for_user(user)
{:ok, convo_reply} =
- CommonAPI.post(user, %{"status" => ".", "in_reply_to_conversation_id" => participation.id})
+ CommonAPI.post(user, %{status: ".", in_reply_to_conversation_id: participation.id})
assert Visibility.is_direct?(convo_reply)
{:ok, activity} =
CommonAPI.post(har, %{
- "status" => "@#{jafnhar.nickname} hey",
- "visibility" => "direct"
+ status: "@#{jafnhar.nickname} hey",
+ visibility: "direct"
})
assert har.ap_id in activity.recipients
{:ok, activity} =
CommonAPI.post(har, %{
- "status" => "I don't really like @#{tridi.nickname}",
- "visibility" => "direct",
- "in_reply_to_status_id" => activity.id,
- "in_reply_to_conversation_id" => participation.id
+ status: "I don't really like @#{tridi.nickname}",
+ visibility: "direct",
+ in_reply_to_status_id: activity.id,
+ in_reply_to_conversation_id: participation.id
})
assert har.ap_id in activity.recipients
{:ok, activity} =
CommonAPI.post(har, %{
- "status" => "@#{jafnhar.nickname} hey, i never want to see @#{tridi.nickname} again",
- "visibility" => "direct"
+ status: "@#{jafnhar.nickname} hey, i never want to see @#{tridi.nickname} again",
+ visibility: "direct"
})
refute tridi.ap_id in activity.recipients
test "it de-duplicates tags" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu #2HU"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU"})
object = Object.normalize(activity)
test "it adds emoji in the object" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => ":firefox:"})
+ {:ok, activity} = CommonAPI.post(user, %{status: ":firefox:"})
assert Object.normalize(activity).data["emoji"]["firefox"]
end
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
+ status:
"Hey, I think @#{user_three.nickname} is ugly. @#{user_four.nickname} is alright though.",
- "to" => [user_two.nickname, user_four.nickname, "nonexistent"]
+ to: [user_two.nickname, user_four.nickname, "nonexistent"]
})
assert user.ap_id in activity.recipients
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => post,
- "content_type" => "text/html"
+ status: post,
+ content_type: "text/html"
})
object = Object.normalize(activity)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => post,
- "content_type" => "text/markdown"
+ status: post,
+ content_type: "text/markdown"
})
object = Object.normalize(activity)
test "it does not allow replies to direct messages that are not direct messages themselves" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "suya..", "visibility" => "direct"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "suya..", visibility: "direct"})
assert {:ok, _} =
CommonAPI.post(user, %{
- "status" => "suya..",
- "visibility" => "direct",
- "in_reply_to_status_id" => activity.id
+ status: "suya..",
+ visibility: "direct",
+ in_reply_to_status_id: activity.id
})
Enum.each(["public", "private", "unlisted"], fn visibility ->
assert {:error, "The message visibility must be direct"} =
CommonAPI.post(user, %{
- "status" => "suya..",
- "visibility" => visibility,
- "in_reply_to_status_id" => activity.id
+ status: "suya..",
+ visibility: visibility,
+ in_reply_to_status_id: activity.id
})
end)
end
user = insert(:user)
{:ok, list} = Pleroma.List.create("foo", user)
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})
assert activity.data["bcc"] == [list.ap_id]
assert activity.recipients == [list.ap_id, user.ap_id]
user = insert(:user)
assert {:error, "Cannot post an empty status without attachments"} =
- CommonAPI.post(user, %{"status" => ""})
+ CommonAPI.post(user, %{status: ""})
end
test "it validates character limits are correctly enforced" do
user = insert(:user)
assert {:error, "The status is over the character limit"} =
- CommonAPI.post(user, %{"status" => "foobar"})
+ CommonAPI.post(user, %{status: "foobar"})
- assert {:ok, activity} = CommonAPI.post(user, %{"status" => "12345"})
+ assert {:ok, activity} = CommonAPI.post(user, %{status: "12345"})
end
test "it can handle activities that expire" do
|> NaiveDateTime.truncate(:second)
|> NaiveDateTime.add(1_000_000, :second)
- assert {:ok, activity} =
- CommonAPI.post(user, %{"status" => "chai", "expires_in" => 1_000_000})
+ assert {:ok, activity} = CommonAPI.post(user, %{status: "chai", expires_in: 1_000_000})
assert expiration = Pleroma.ActivityExpiration.get_by_activity_id(activity.id)
assert expiration.scheduled_at == expires_at
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
assert reaction.data["actor"] == user.ap_id
assert reaction.data["content"] == "👍"
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:error, _} = CommonAPI.react_with_emoji(activity.id, user, ".")
end
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
{:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, user)
end
test "can't repeat a repeat" do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{} = announce, _} = CommonAPI.repeat(activity.id, other_user)
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{} = announce_activity, _} =
- CommonAPI.repeat(activity.id, user, %{"visibility" => "private"})
+ CommonAPI.repeat(activity.id, user, %{visibility: "private"})
assert Visibility.is_private?(announce_activity)
end
user = insert(:user)
other_user = insert(:user)
- {:ok, post_activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, post_activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{data: data}} = CommonAPI.favorite(user, post_activity.id)
assert data["type"] == "Like"
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{} = announce, object} = CommonAPI.repeat(activity.id, user)
{:ok, ^announce, ^object} = CommonAPI.repeat(activity.id, user)
end
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
assert {:ok, :already_liked} = CommonAPI.favorite(user, activity.id)
end
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
[user: user, activity: activity]
end
test "pin poll", %{user: user} do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "How is fediverse today?",
- "poll" => %{"options" => ["Absolutely outstanding", "Not good"], "expires_in" => 20}
+ status: "How is fediverse today?",
+ poll: %{options: ["Absolutely outstanding", "Not good"], expires_in: 20}
})
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
end
test "unlisted statuses can be pinned", %{user: user} do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!", "visibility" => "unlisted"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!", visibility: "unlisted"})
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
end
end
test "max pinned statuses", %{user: user, activity: activity_one} do
- {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity_two} = CommonAPI.post(user, %{status: "HI!!!"})
assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
reporter = insert(:user)
target_user = insert(:user)
- {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
+ {:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})
reporter_ap_id = reporter.ap_id
target_ap_id = target_user.ap_id
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "Am I cute?",
- "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
+ status: "Am I cute?",
+ poll: %{options: ["Yes", "No"], expires_in: 20}
})
object = Object.normalize(activity)
user = insert(:user)
mentioned_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "public", nil)
user = insert(:user)
mentioned_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "unlisted", nil)
user = insert(:user)
mentioned_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private", nil)
user = insert(:user)
mentioned_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct", nil)
desc = Jason.encode!(%{object.id => "test-desc"})
assert Utils.attachments_from_ids(%{
- "media_ids" => ["#{object.id}"],
- "descriptions" => desc
+ media_ids: ["#{object.id}"],
+ descriptions: desc
}) == [
Map.merge(object.data, %{"name" => "test-desc"})
]
test "returns attachments without descs" do
object = insert(:note)
- assert Utils.attachments_from_ids(%{"media_ids" => ["#{object.id}"]}) == [object.data]
+ assert Utils.attachments_from_ids(%{media_ids: ["#{object.id}"]}) == [object.data]
end
test "returns [] when not pass media_ids" do
describe "Publish an activity" do
setup do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
relay_mock = {
Pleroma.Web.ActivityPub.Relay,
Instances.set_consistently_unreachable(URI.parse(inbox2).host)
{:ok, _activity} =
- CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
+ CommonAPI.post(user, %{status: "HI @nick1@domain.com, @nick2@domain2.com!"})
expected_dt = NaiveDateTime.to_iso8601(dt)
)
user = insert(:user)
- {:ok, activity1} = CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
+ {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"})
object = Object.normalize(activity1)
|> Ecto.Changeset.change(data: object_data)
|> Pleroma.Repo.update()
- {:ok, activity2} = CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
+ {:ok, activity2} = CommonAPI.post(user, %{status: "42 This is :moominmamma #PleromaArt"})
- {:ok, _activity3} = CommonAPI.post(user, %{"status" => "This is :moominmamma"})
+ {:ok, _activity3} = CommonAPI.post(user, %{status: "This is :moominmamma"})
response =
conn
)
user = insert(:user)
- {:ok, activity1} = CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
+ {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"})
object = Object.normalize(activity1)
|> Ecto.Changeset.change(data: object_data)
|> Pleroma.Repo.update()
- {:ok, activity2} = CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
+ {:ok, activity2} = CommonAPI.post(user, %{status: "42 This is :moominmamma #PleromaArt"})
- {:ok, _activity3} = CommonAPI.post(user, %{"status" => "This is :moominmamma"})
+ {:ok, _activity3} = CommonAPI.post(user, %{status: "This is :moominmamma"})
response =
conn
user = insert(:user, ap_id: "https://honktest/u/test", local: false)
other_user = insert(:user)
- {:ok, post} = CommonAPI.post(other_user, %{"status" => "bonkeronk"})
+ {:ok, post} = CommonAPI.post(other_user, %{status: "bonkeronk"})
{:ok, announce, _} =
%{
User.block(user_one, user_two)
- {:ok, activity} = CommonAPI.post(user_two, %{"status" => "User one sux0rz"})
+ {:ok, activity} = CommonAPI.post(user_two, %{status: "User one sux0rz"})
{:ok, repeat, _} = CommonAPI.repeat(activity.id, user_three)
assert resp =
{:ok, _user_three} = User.follow(user_three, user_one)
- {:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"})
+ {:ok, activity} = CommonAPI.post(user_one, %{status: "HI!!!"})
{:ok, direct_activity} =
CommonAPI.post(user_one, %{
- "status" => "Hi, @#{user_two.nickname}.",
- "visibility" => "direct"
+ status: "Hi, @#{user_two.nickname}.",
+ visibility: "direct"
})
{:ok, private_activity} =
- CommonAPI.post(user_one, %{"status" => "private", "visibility" => "private"})
+ CommonAPI.post(user_one, %{status: "private", visibility: "private"})
# TODO!!!
resp =
{:ok, %{id: media_id}} = ActivityPub.upload(file, actor: user.ap_id)
- {:ok, %{id: image_post_id}} =
- CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media_id]})
+ {:ok, %{id: image_post_id}} = CommonAPI.post(user, %{status: "cofe", media_ids: [media_id]})
conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?only_media=true")
end
test "gets a user's statuses without reblogs", %{user: user, conn: conn} do
- {:ok, %{id: post_id}} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, %{id: post_id}} = CommonAPI.post(user, %{status: "HI!!!"})
{:ok, _, _} = CommonAPI.repeat(post_id, user)
conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?exclude_reblogs=true")
end
test "filters user's statuses by a hashtag", %{user: user, conn: conn} do
- {:ok, %{id: post_id}} = CommonAPI.post(user, %{"status" => "#hashtag"})
- {:ok, _post} = CommonAPI.post(user, %{"status" => "hashtag"})
+ {:ok, %{id: post_id}} = CommonAPI.post(user, %{status: "#hashtag"})
+ {:ok, _post} = CommonAPI.post(user, %{status: "hashtag"})
conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?tagged=hashtag")
assert [%{"id" => ^post_id}] = json_response_and_validate_schema(conn, 200)
conn: conn
} do
{:ok, %{id: public_activity_id}} =
- CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
+ CommonAPI.post(user, %{status: ".", visibility: "public"})
- {:ok, _direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ {:ok, _direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?exclude_visibilities[]=direct")
assert [%{"id" => ^public_activity_id}] = json_response_and_validate_schema(conn, 200)
assert %{"showing_reblogs" => false} = json_response_and_validate_schema(ret_conn, 200)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
{:ok, %{id: reblog_id}, _} = CommonAPI.repeat(activity.id, followed)
assert [] ==
describe "pinned statuses" do
setup do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
%{conn: conn} = oauth_access(["read:statuses"], user: user)
[conn: conn, user: user, activity: activity]
{:ok, direct} =
CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
+ visibility: "direct"
})
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 1
{:ok, _follower_only} =
CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
- "visibility" => "private"
+ status: "Hi @#{user_two.nickname}!",
+ visibility: "private"
})
res_conn = get(conn, "/api/v1/conversations")
{:ok, direct1} =
CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{user_two.nickname}!",
+ visibility: "direct"
})
{:ok, _direct2} =
CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_three.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{user_three.nickname}!",
+ visibility: "direct"
})
{:ok, direct3} =
CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
+ visibility: "direct"
})
{:ok, _direct4} =
CommonAPI.post(user_two, %{
- "status" => "Hi @#{user_three.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{user_three.nickname}!",
+ visibility: "direct"
})
{:ok, direct5} =
CommonAPI.post(user_two, %{
- "status" => "Hi @#{user_one.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{user_one.nickname}!",
+ visibility: "direct"
})
assert [conversation1, conversation2] =
{:ok, direct} =
CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{user_two.nickname}",
+ visibility: "direct"
})
{:ok, direct_reply} =
CommonAPI.post(user_two, %{
- "status" => "reply",
- "visibility" => "direct",
- "in_reply_to_status_id" => direct.id
+ status: "reply",
+ visibility: "direct",
+ in_reply_to_status_id: direct.id
})
[%{"last_status" => res_last_status}] =
{:ok, direct} =
CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{user_two.nickname}",
+ visibility: "direct"
})
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0
# The conversation is marked as unread on reply
{:ok, _} =
CommonAPI.post(user_two, %{
- "status" => "reply",
- "visibility" => "direct",
- "in_reply_to_status_id" => direct.id
+ status: "reply",
+ visibility: "direct",
+ in_reply_to_status_id: direct.id
})
[%{"unread" => true}] =
# A reply doesn't increment the user's unread_conversation_count if the conversation is unread
{:ok, _} =
CommonAPI.post(user_two, %{
- "status" => "reply",
- "visibility" => "direct",
- "in_reply_to_status_id" => direct.id
+ status: "reply",
+ visibility: "direct",
+ in_reply_to_status_id: direct.id
})
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 1
{:ok, direct} =
CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{user_two.nickname}!",
+ visibility: "direct"
})
res_conn = get(conn, "/api/v1/statuses/#{direct.id}/context")
insert(:user, %{local: false, nickname: "u@peer1.com"})
insert(:user, %{local: false, nickname: "u@peer2.com"})
- {:ok, _} = Pleroma.Web.CommonAPI.post(user, %{"status" => "cofe"})
+ {:ok, _} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
Pleroma.Stats.force_update()
%{user: user, conn: conn} = oauth_access(["read:notifications"])
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
{:ok, [_notification]} = Notification.create_notifications(activity)
response =
%{user: user, conn: conn} = oauth_access(["read:notifications"])
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
{:ok, [_notification]} = Notification.create_notifications(activity)
%{user: user, conn: conn} = oauth_access(["read:notifications"])
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
%{user: user, conn: conn} = oauth_access(["write:notifications"])
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
%{user: user, conn: conn} = oauth_access(["write:notifications"])
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
%{user: user, conn: conn} = oauth_access(["write:notifications", "read:notifications"])
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
{:ok, [_notification]} = Notification.create_notifications(activity)
%{user: user, conn: conn} = oauth_access(["read:notifications"])
other_user = insert(:user)
- {:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
- {:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
- {:ok, activity3} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
- {:ok, activity4} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity1} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
+ {:ok, activity2} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
+ {:ok, activity3} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
+ {:ok, activity4} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
notification1_id = get_notification_id_by_activity(activity1)
notification2_id = get_notification_id_by_activity(activity2)
other_user = insert(:user)
{:ok, public_activity} =
- CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "public"})
+ CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "public"})
{:ok, direct_activity} =
- CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "direct"})
+ CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "direct"})
{:ok, unlisted_activity} =
- CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "unlisted"})
+ CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "unlisted"})
{:ok, private_activity} =
- CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "private"})
+ CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "private"})
query = params_to_query(%{exclude_visibilities: ["public", "unlisted", "private"]})
conn_res = get(conn, "/api/v1/notifications?" <> query)
user = insert(:user)
%{user: other_user, conn: conn} = oauth_access(["read:notifications"])
- {:ok, public_activity} =
- CommonAPI.post(other_user, %{"status" => ".", "visibility" => "public"})
+ {:ok, public_activity} = CommonAPI.post(other_user, %{status: ".", visibility: "public"})
{:ok, direct_activity} =
- CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "direct"})
+ CommonAPI.post(other_user, %{status: "@#{user.nickname}", visibility: "direct"})
{:ok, unlisted_activity} =
- CommonAPI.post(other_user, %{"status" => ".", "visibility" => "unlisted"})
+ CommonAPI.post(other_user, %{status: ".", visibility: "unlisted"})
- {:ok, private_activity} =
- CommonAPI.post(other_user, %{"status" => ".", "visibility" => "private"})
+ {:ok, private_activity} = CommonAPI.post(other_user, %{status: ".", visibility: "private"})
{:ok, _} = CommonAPI.favorite(user, public_activity.id)
{:ok, _} = CommonAPI.favorite(user, direct_activity.id)
user = insert(:user)
%{user: other_user, conn: conn} = oauth_access(["read:notifications"])
- {:ok, public_activity} =
- CommonAPI.post(other_user, %{"status" => ".", "visibility" => "public"})
+ {:ok, public_activity} = CommonAPI.post(other_user, %{status: ".", visibility: "public"})
{:ok, unlisted_activity} =
- CommonAPI.post(other_user, %{"status" => ".", "visibility" => "unlisted"})
+ CommonAPI.post(other_user, %{status: ".", visibility: "unlisted"})
{:ok, _, _} = CommonAPI.repeat(public_activity.id, user)
{:ok, _, _} = CommonAPI.repeat(unlisted_activity.id, user)
%{user: user, conn: conn} = oauth_access(["read:notifications"])
other_user = insert(:user)
- {:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
- {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"})
+ {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id)
{:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
%{user: user, conn: conn} = oauth_access(["read:notifications"])
other_user = insert(:user)
- {:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
- {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"})
+ {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id)
{:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
%{user: user, conn: conn} = oauth_access(["read:notifications", "write:notifications"])
other_user = insert(:user)
- {:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
- {:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
- {:ok, activity3} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
- {:ok, activity4} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
+ {:ok, activity1} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
+ {:ok, activity2} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
+ {:ok, activity3} = CommonAPI.post(user, %{status: "hi @#{other_user.nickname}"})
+ {:ok, activity4} = CommonAPI.post(user, %{status: "hi @#{other_user.nickname}"})
notification1_id = get_notification_id_by_activity(activity1)
notification2_id = get_notification_id_by_activity(activity2)
user2 = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, user2)
- {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})
ret_conn = get(conn, "/api/v1/notifications")
user2 = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, user2)
- {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})
ret_conn = get(conn, "/api/v1/notifications")
user2 = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, user2)
- {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})
ret_conn = get(conn, "/api/v1/notifications")
{:ok, activity1} =
CommonAPI.post(other_user, %{
- "status" => "hi @#{user.nickname}",
- "visibility" => "public"
+ status: "hi @#{user.nickname}",
+ visibility: "public"
})
{:ok, activity2} =
CommonAPI.post(other_user, %{
- "status" => "hi @#{user.nickname}",
- "visibility" => "public"
+ status: "hi @#{user.nickname}",
+ visibility: "public"
})
notification1 = Repo.get_by(Notification, activity_id: activity1.id)
%{id: account_id} = other_user1 = insert(:user)
other_user2 = insert(:user)
- {:ok, _activity} = CommonAPI.post(other_user1, %{"status" => "hi @#{user.nickname}"})
- {:ok, _activity} = CommonAPI.post(other_user2, %{"status" => "bye @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(other_user1, %{status: "hi @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(other_user2, %{status: "bye @#{user.nickname}"})
assert [%{"account" => %{"id" => ^account_id}}] =
conn
test "returns poll entity for object id", %{user: user, conn: conn} do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "Pleroma does",
- "poll" => %{"options" => ["what Mastodon't", "n't what Mastodoes"], "expires_in" => 20}
+ status: "Pleroma does",
+ poll: %{options: ["what Mastodon't", "n't what Mastodoes"], expires_in: 20}
})
object = Object.normalize(activity)
{:ok, activity} =
CommonAPI.post(other_user, %{
- "status" => "Pleroma does",
- "poll" => %{"options" => ["what Mastodon't", "n't what Mastodoes"], "expires_in" => 20},
- "visibility" => "private"
+ status: "Pleroma does",
+ poll: %{options: ["what Mastodon't", "n't what Mastodoes"], expires_in: 20},
+ visibility: "private"
})
object = Object.normalize(activity)
{:ok, activity} =
CommonAPI.post(other_user, %{
- "status" => "A very delicious sandwich",
- "poll" => %{
- "options" => ["Lettuce", "Grilled Bacon", "Tomato"],
- "expires_in" => 20,
- "multiple" => true
+ status: "A very delicious sandwich",
+ poll: %{
+ options: ["Lettuce", "Grilled Bacon", "Tomato"],
+ expires_in: 20,
+ multiple: true
}
})
test "author can't vote", %{user: user, conn: conn} do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "Am I cute?",
- "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
+ status: "Am I cute?",
+ poll: %{options: ["Yes", "No"], expires_in: 20}
})
object = Object.normalize(activity)
{:ok, activity} =
CommonAPI.post(other_user, %{
- "status" => "The glass is",
- "poll" => %{"options" => ["half empty", "half full"], "expires_in" => 20}
+ status: "The glass is",
+ poll: %{options: ["half empty", "half full"], expires_in: 20}
})
object = Object.normalize(activity)
{:ok, activity} =
CommonAPI.post(other_user, %{
- "status" => "Am I cute?",
- "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
+ status: "Am I cute?",
+ poll: %{options: ["Yes", "No"], expires_in: 20}
})
object = Object.normalize(activity)
{:ok, activity} =
CommonAPI.post(other_user, %{
- "status" => "Am I cute?",
- "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20},
- "visibility" => "private"
+ status: "Am I cute?",
+ poll: %{options: ["Yes", "No"], expires_in: 20},
+ visibility: "private"
})
object = Object.normalize(activity)
setup do
target_user = insert(:user)
- {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
+ {:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})
[target_user: target_user, activity: activity]
end
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
- {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu private 天子"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "This is about 2hu private 天子"})
{:ok, _activity} =
CommonAPI.post(user, %{
- "status" => "This is about 2hu, but private",
- "visibility" => "private"
+ status: "This is about 2hu, but private",
+ visibility: "private"
})
- {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
+ {:ok, _} = CommonAPI.post(user_two, %{status: "This isn't"})
results =
conn
user_smith = insert(:user, %{nickname: "Agent", name: "I love 2hu"})
user_neo = insert(:user, %{nickname: "Agent Neo", name: "Agent"})
- {:ok, act1} = CommonAPI.post(user, %{"status" => "This is about 2hu private 天子"})
- {:ok, act2} = CommonAPI.post(user_smith, %{"status" => "Agent Smith"})
- {:ok, act3} = CommonAPI.post(user_neo, %{"status" => "Agent Smith"})
+ {:ok, act1} = CommonAPI.post(user, %{status: "This is about 2hu private 天子"})
+ {:ok, act2} = CommonAPI.post(user_smith, %{status: "Agent Smith"})
+ {:ok, act3} = CommonAPI.post(user_neo, %{status: "Agent Smith"})
Pleroma.User.block(user, user_smith)
results =
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
- {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "This is about 2hu"})
{:ok, _activity} =
CommonAPI.post(user, %{
- "status" => "This is about 2hu, but private",
- "visibility" => "private"
+ status: "This is about 2hu, but private",
+ visibility: "private"
})
- {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
+ {:ok, _} = CommonAPI.post(user_two, %{status: "This isn't"})
results =
conn
capture_log(fn ->
{:ok, %{id: activity_id}} =
CommonAPI.post(insert(:user), %{
- "status" => "check out https://shitposter.club/notice/2827873"
+ status: "check out https://shitposter.club/notice/2827873"
})
results =
test "search doesn't show statuses that it shouldn't", %{conn: conn} do
{:ok, activity} =
CommonAPI.post(insert(:user), %{
- "status" => "This is about 2hu, but private",
- "visibility" => "private"
+ status: "This is about 2hu, but private",
+ visibility: "private"
})
capture_log(fn ->
_user_two = insert(:user, %{nickname: "shp@shitposter.club"})
_user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
- {:ok, _activity1} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
- {:ok, _activity2} = CommonAPI.post(user, %{"status" => "This is also about 2hu"})
+ {:ok, _activity1} = CommonAPI.post(user, %{status: "This is about 2hu"})
+ {:ok, _activity2} = CommonAPI.post(user, %{status: "This is also about 2hu"})
result =
conn
user = insert(:user)
_user_two = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
+ {:ok, _activity} = CommonAPI.post(user, %{status: "This is about 2hu"})
assert %{"statuses" => [_activity], "accounts" => [], "hashtags" => []} =
conn
user = insert(:user, %{nickname: "shp@shitposter.club"})
user_two = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
- {:ok, activity1} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
- {:ok, activity2} = CommonAPI.post(user_two, %{"status" => "This is also about 2hu"})
+ {:ok, activity1} = CommonAPI.post(user, %{status: "This is about 2hu"})
+ {:ok, activity2} = CommonAPI.post(user_two, %{status: "This is also about 2hu"})
results =
conn
response =
conn
+ |> put_req_header("content-type", "application/json")
|> post("api/v1/statuses", %{
"content_type" => "text/plain",
"source" => "Pleroma FE",
"status" => "Hello world",
"visibility" => "public"
})
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert response["reblogs_count"] == 0
ObanHelpers.perform_all()
response =
conn
|> get("api/v1/statuses/#{response["id"]}", %{})
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert response["reblogs_count"] == 0
end
conn_one =
conn
+ |> put_req_header("content-type", "application/json")
|> put_req_header("idempotency-key", idempotency_key)
|> post("/api/v1/statuses", %{
"status" => "cofe",
assert ttl > :timer.seconds(6 * 60 * 60 - 1)
assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} =
- json_response(conn_one, 200)
+ json_response_and_validate_schema(conn_one, 200)
assert Activity.get_by_id(id)
conn_two =
conn
+ |> put_req_header("content-type", "application/json")
|> put_req_header("idempotency-key", idempotency_key)
|> post("/api/v1/statuses", %{
"status" => "cofe",
conn_three =
conn
+ |> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses", %{
"status" => "cofe",
"spoiler_text" => "2hu",
"sensitive" => "false"
})
- assert %{"id" => third_id} = json_response(conn_three, 200)
+ assert %{"id" => third_id} = json_response_and_validate_schema(conn_three, 200)
refute id == third_id
# An activity that will expire:
conn_four =
conn
+ |> put_req_header("content-type", "application/json")
|> post("api/v1/statuses", %{
"status" => "oolong",
"expires_in" => expires_in
})
- assert fourth_response = %{"id" => fourth_id} = json_response(conn_four, 200)
+ assert fourth_response =
+ %{"id" => fourth_id} = json_response_and_validate_schema(conn_four, 200)
+
assert activity = Activity.get_by_id(fourth_id)
assert expiration = ActivityExpiration.get_by_activity_id(fourth_id)
assert %{"error" => "Expiry date is too soon"} =
conn
+ |> put_req_header("content-type", "application/json")
|> post("api/v1/statuses", %{
"status" => "oolong",
"expires_in" => expires_in
})
- |> json_response(422)
+ |> json_response_and_validate_schema(422)
# 30 minutes
expires_in = 30 * 60
assert %{"error" => "Expiry date is too soon"} =
conn
+ |> put_req_header("content-type", "application/json")
|> post("api/v1/statuses", %{
"status" => "oolong",
"expires_in" => expires_in
})
- |> json_response(422)
+ |> json_response_and_validate_schema(422)
end
test "posting an undefined status with an attachment", %{user: user, conn: conn} do
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"media_ids" => [to_string(upload.id)]
})
- assert json_response(conn, 200)
+ assert json_response_and_validate_schema(conn, 200)
end
test "replying to a status", %{user: user, conn: conn} do
- {:ok, replied_to} = CommonAPI.post(user, %{"status" => "cofe"})
+ {:ok, replied_to} = CommonAPI.post(user, %{status: "cofe"})
conn =
conn
+ |> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
- assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
+ assert %{"content" => "xD", "id" => id} = json_response_and_validate_schema(conn, 200)
activity = Activity.get_by_id(id)
user: user,
conn: conn
} do
- {:ok, replied_to} = CommonAPI.post(user, %{"status" => "suya..", "visibility" => "direct"})
+ {:ok, replied_to} = CommonAPI.post(user, %{status: "suya..", visibility: "direct"})
Enum.each(["public", "private", "unlisted"], fn visibility ->
conn =
conn
+ |> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses", %{
"status" => "@#{user.nickname} hey",
"in_reply_to_id" => replied_to.id,
"visibility" => visibility
})
- assert json_response(conn, 422) == %{"error" => "The message visibility must be direct"}
+ assert json_response_and_validate_schema(conn, 422) == %{
+ "error" => "The message visibility must be direct"
+ }
end)
end
test "posting a status with an invalid in_reply_to_id", %{conn: conn} do
- conn = post(conn, "/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => ""})
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => ""})
- assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
+ assert %{"content" => "xD", "id" => id} = json_response_and_validate_schema(conn, 200)
assert Activity.get_by_id(id)
end
test "posting a sensitive status", %{conn: conn} do
- conn = post(conn, "/api/v1/statuses", %{"status" => "cofe", "sensitive" => true})
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{"status" => "cofe", "sensitive" => true})
+
+ assert %{"content" => "cofe", "id" => id, "sensitive" => true} =
+ json_response_and_validate_schema(conn, 200)
- assert %{"content" => "cofe", "id" => id, "sensitive" => true} = json_response(conn, 200)
assert Activity.get_by_id(id)
end
test "posting a fake status", %{conn: conn} do
real_conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"status" =>
"\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it"
})
- real_status = json_response(real_conn, 200)
+ real_status = json_response_and_validate_schema(real_conn, 200)
assert real_status
assert Object.get_by_ap_id(real_status["uri"])
|> Kernel.put_in(["pleroma", "conversation_id"], nil)
fake_conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"status" =>
"\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it",
"preview" => true
})
- fake_status = json_response(fake_conn, 200)
+ fake_status = json_response_and_validate_schema(fake_conn, 200)
assert fake_status
refute Object.get_by_ap_id(fake_status["uri"])
Config.put([:rich_media, :enabled], true)
conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"status" => "https://example.com/ogp"
})
- assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
+ assert %{"id" => id, "card" => %{"title" => "The Rock"}} =
+ json_response_and_validate_schema(conn, 200)
+
assert Activity.get_by_id(id)
end
user2 = insert(:user)
content = "direct cofe @#{user2.nickname}"
- conn = post(conn, "api/v1/statuses", %{"status" => content, "visibility" => "direct"})
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"})
- assert %{"id" => id} = response = json_response(conn, 200)
+ assert %{"id" => id} = response = json_response_and_validate_schema(conn, 200)
assert response["visibility"] == "direct"
assert response["pleroma"]["direct_conversation_id"]
assert activity = Activity.get_by_id(id)
setup do: oauth_access(["write:statuses"])
test "creates a scheduled activity", %{conn: conn} do
- scheduled_at = NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
+ scheduled_at =
+ NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
+ |> NaiveDateTime.to_iso8601()
+ |> Kernel.<>("Z")
conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"status" => "scheduled",
"scheduled_at" => scheduled_at
})
- assert %{"scheduled_at" => expected_scheduled_at} = json_response(conn, 200)
+ assert %{"scheduled_at" => expected_scheduled_at} =
+ json_response_and_validate_schema(conn, 200)
+
assert expected_scheduled_at == CommonAPI.Utils.to_masto_date(scheduled_at)
assert [] == Repo.all(Activity)
end
test "ignores nil values", %{conn: conn} do
conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"status" => "not scheduled",
"scheduled_at" => nil
})
- assert result = json_response(conn, 200)
+ assert result = json_response_and_validate_schema(conn, 200)
assert Activity.get_by_id(result["id"])
end
test "creates a scheduled activity with a media attachment", %{user: user, conn: conn} do
- scheduled_at = NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
+ scheduled_at =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(:timer.minutes(120), :millisecond)
+ |> NaiveDateTime.to_iso8601()
+ |> Kernel.<>("Z")
file = %Plug.Upload{
content_type: "image/jpg",
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"media_ids" => [to_string(upload.id)],
"status" => "scheduled",
"scheduled_at" => scheduled_at
})
- assert %{"media_attachments" => [media_attachment]} = json_response(conn, 200)
+ assert %{"media_attachments" => [media_attachment]} =
+ json_response_and_validate_schema(conn, 200)
+
assert %{"type" => "image"} = media_attachment
end
%{conn: conn} do
scheduled_at =
NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(5) - 1, :millisecond)
+ |> NaiveDateTime.to_iso8601()
+ |> Kernel.<>("Z")
conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"status" => "not scheduled",
"scheduled_at" => scheduled_at
})
- assert %{"content" => "not scheduled"} = json_response(conn, 200)
+ assert %{"content" => "not scheduled"} = json_response_and_validate_schema(conn, 200)
assert [] == Repo.all(ScheduledActivity)
end
NaiveDateTime.utc_now()
|> NaiveDateTime.add(:timer.minutes(6), :millisecond)
|> NaiveDateTime.to_iso8601()
+ # TODO
+ |> Kernel.<>("Z")
attrs = %{params: %{}, scheduled_at: today}
{:ok, _} = ScheduledActivity.create(user, attrs)
{:ok, _} = ScheduledActivity.create(user, attrs)
- conn = post(conn, "/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => today})
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => today})
- assert %{"error" => "daily limit exceeded"} == json_response(conn, 422)
+ assert %{"error" => "daily limit exceeded"} == json_response_and_validate_schema(conn, 422)
end
test "returns error when total user limit is exceeded", %{user: user, conn: conn} do
NaiveDateTime.utc_now()
|> NaiveDateTime.add(:timer.minutes(6), :millisecond)
|> NaiveDateTime.to_iso8601()
+ |> Kernel.<>("Z")
tomorrow =
NaiveDateTime.utc_now()
|> NaiveDateTime.add(:timer.hours(36), :millisecond)
|> NaiveDateTime.to_iso8601()
+ |> Kernel.<>("Z")
attrs = %{params: %{}, scheduled_at: today}
{:ok, _} = ScheduledActivity.create(user, attrs)
{:ok, _} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: tomorrow})
conn =
- post(conn, "/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => tomorrow})
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => tomorrow})
- assert %{"error" => "total limit exceeded"} == json_response(conn, 422)
+ assert %{"error" => "total limit exceeded"} == json_response_and_validate_schema(conn, 422)
end
end
time = NaiveDateTime.utc_now()
conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"status" => "Who is the #bestgrill?",
- "poll" => %{"options" => ["Rei", "Asuka", "Misato"], "expires_in" => 420}
+ "poll" => %{
+ "options" => ["Rei", "Asuka", "Misato"],
+ "expires_in" => 420
+ }
})
- response = json_response(conn, 200)
+ response = json_response_and_validate_schema(conn, 200)
assert Enum.all?(response["poll"]["options"], fn %{"title" => title} ->
title in ["Rei", "Asuka", "Misato"]
limit = Config.get([:instance, :poll_limits, :max_options])
conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"status" => "desu~",
"poll" => %{"options" => Enum.map(0..limit, fn _ -> "desu" end), "expires_in" => 1}
})
- %{"error" => error} = json_response(conn, 422)
+ %{"error" => error} = json_response_and_validate_schema(conn, 422)
assert error == "Poll can't contain more than #{limit} options"
end
limit = Config.get([:instance, :poll_limits, :max_option_chars])
conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"status" => "...",
"poll" => %{
"options" => [Enum.reduce(0..limit, "", fn _, acc -> acc <> "." end)],
}
})
- %{"error" => error} = json_response(conn, 422)
+ %{"error" => error} = json_response_and_validate_schema(conn, 422)
assert error == "Poll options cannot be longer than #{limit} characters each"
end
limit = Config.get([:instance, :poll_limits, :min_expiration])
conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"status" => "imagine arbitrary limits",
"poll" => %{
"options" => ["this post was made by pleroma gang"],
}
})
- %{"error" => error} = json_response(conn, 422)
+ %{"error" => error} = json_response_and_validate_schema(conn, 422)
assert error == "Expiration date is too soon"
end
limit = Config.get([:instance, :poll_limits, :max_expiration])
conn =
- post(conn, "/api/v1/statuses", %{
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
"status" => "imagine arbitrary limits",
"poll" => %{
"options" => ["this post was made by pleroma gang"],
}
})
- %{"error" => error} = json_response(conn, 422)
+ %{"error" => error} = json_response_and_validate_schema(conn, 422)
assert error == "Expiration date is too far in the future"
end
end
conn = get(conn, "/api/v1/statuses/#{activity.id}")
- assert %{"id" => id} = json_response(conn, 200)
+ assert %{"id" => id} = json_response_and_validate_schema(conn, 200)
assert id == to_string(activity.id)
end
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
- assert json_response(res_conn, :not_found) == %{
+ assert json_response_and_validate_schema(res_conn, :not_found) == %{
"error" => "Record not found"
}
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
- assert json_response(res_conn, :not_found) == %{
+ assert json_response_and_validate_schema(res_conn, :not_found) == %{
"error" => "Record not found"
}
end
test "if user is authenticated", %{local: local, remote: remote} do
%{conn: conn} = oauth_access(["read"])
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
- assert %{"id" => _} = json_response(res_conn, 200)
+ assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
- assert %{"id" => _} = json_response(res_conn, 200)
+ assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
end
end
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
- assert json_response(res_conn, :not_found) == %{
+ assert json_response_and_validate_schema(res_conn, :not_found) == %{
"error" => "Record not found"
}
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
- assert %{"id" => _} = json_response(res_conn, 200)
+ assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
end
test "if user is authenticated", %{local: local, remote: remote} do
%{conn: conn} = oauth_access(["read"])
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
- assert %{"id" => _} = json_response(res_conn, 200)
+ assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
- assert %{"id" => _} = json_response(res_conn, 200)
+ assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
end
end
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
- assert %{"id" => _} = json_response(res_conn, 200)
+ assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
- assert json_response(res_conn, :not_found) == %{
+ assert json_response_and_validate_schema(res_conn, :not_found) == %{
"error" => "Record not found"
}
end
test "if user is authenticated", %{local: local, remote: remote} do
%{conn: conn} = oauth_access(["read"])
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
- assert %{"id" => _} = json_response(res_conn, 200)
+ assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
- assert %{"id" => _} = json_response(res_conn, 200)
+ assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
end
end
conn = get(conn, "/api/v1/statuses/#{String.downcase(activity.id)}")
- assert json_response(conn, 404) == %{"error" => "Record not found"}
+ assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}
end
test "get a direct status" do
other_user = insert(:user)
{:ok, activity} =
- CommonAPI.post(user, %{"status" => "@#{other_user.nickname}", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "@#{other_user.nickname}", visibility: "direct"})
conn =
conn
[participation] = Participation.for_user(user)
- res = json_response(conn, 200)
+ res = json_response_and_validate_schema(conn, 200)
assert res["pleroma"]["direct_conversation_id"] == participation.id
end
query_string = "ids[]=#{id1}&ids[]=#{id2}"
conn = get(conn, "/api/v1/statuses/?#{query_string}")
- assert [%{"id" => ^id1}, %{"id" => ^id2}] = Enum.sort_by(json_response(conn, :ok), & &1["id"])
+ assert [%{"id" => ^id1}, %{"id" => ^id2}] =
+ Enum.sort_by(json_response_and_validate_schema(conn, :ok), & &1["id"])
end
describe "getting statuses by ids with restricted unauthenticated for local and remote" do
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
- res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
+ res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
- assert json_response(res_conn, 200) == []
+ assert json_response_and_validate_schema(res_conn, 200) == []
end
test "if user is authenticated", %{local: local, remote: remote} do
%{conn: conn} = oauth_access(["read"])
- res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
+ res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
- assert length(json_response(res_conn, 200)) == 2
+ assert length(json_response_and_validate_schema(res_conn, 200)) == 2
end
end
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
- res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
+ res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
remote_id = remote.id
- assert [%{"id" => ^remote_id}] = json_response(res_conn, 200)
+ assert [%{"id" => ^remote_id}] = json_response_and_validate_schema(res_conn, 200)
end
test "if user is authenticated", %{local: local, remote: remote} do
%{conn: conn} = oauth_access(["read"])
- res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
+ res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
- assert length(json_response(res_conn, 200)) == 2
+ assert length(json_response_and_validate_schema(res_conn, 200)) == 2
end
end
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
- res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
+ res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
local_id = local.id
- assert [%{"id" => ^local_id}] = json_response(res_conn, 200)
+ assert [%{"id" => ^local_id}] = json_response_and_validate_schema(res_conn, 200)
end
test "if user is authenticated", %{local: local, remote: remote} do
%{conn: conn} = oauth_access(["read"])
- res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
+ res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
- assert length(json_response(res_conn, 200)) == 2
+ assert length(json_response_and_validate_schema(res_conn, 200)) == 2
end
end
|> assign(:user, author)
|> delete("/api/v1/statuses/#{activity.id}")
- assert %{} = json_response(conn, 200)
+ assert %{} = json_response_and_validate_schema(conn, 200)
refute Activity.get_by_id(activity.id)
end
|> assign(:user, author)
|> delete("/api/v1/statuses/#{String.downcase(activity.id)}")
- assert %{"error" => "Record not found"} == json_response(conn, 404)
+ assert %{"error" => "Record not found"} == json_response_and_validate_schema(conn, 404)
end
test "when you didn't create it" do
conn = delete(conn, "/api/v1/statuses/#{activity.id}")
- assert %{"error" => _} = json_response(conn, 403)
+ assert %{"error" => _} = json_response_and_validate_schema(conn, 403)
assert Activity.get_by_id(activity.id) == activity
end
|> assign(:token, insert(:oauth_token, user: admin, scopes: ["write:statuses"]))
|> delete("/api/v1/statuses/#{activity1.id}")
- assert %{} = json_response(res_conn, 200)
+ assert %{} = json_response_and_validate_schema(res_conn, 200)
res_conn =
conn
|> assign(:token, insert(:oauth_token, user: moderator, scopes: ["write:statuses"]))
|> delete("/api/v1/statuses/#{activity2.id}")
- assert %{} = json_response(res_conn, 200)
+ assert %{} = json_response_and_validate_schema(res_conn, 200)
refute Activity.get_by_id(activity1.id)
refute Activity.get_by_id(activity2.id)
test "reblogs and returns the reblogged status", %{conn: conn} do
activity = insert(:note_activity)
- conn = post(conn, "/api/v1/statuses/#{activity.id}/reblog")
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity.id}/reblog")
assert %{
"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
"reblogged" => true
- } = json_response(conn, 200)
+ } = json_response_and_validate_schema(conn, 200)
assert to_string(activity.id) == id
end
test "returns 404 if the reblogged status doesn't exist", %{conn: conn} do
activity = insert(:note_activity)
- conn = post(conn, "/api/v1/statuses/#{String.downcase(activity.id)}/reblog")
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{String.downcase(activity.id)}/reblog")
- assert %{"error" => "Record not found"} = json_response(conn, 404)
+ assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn, 404)
end
test "reblogs privately and returns the reblogged status", %{conn: conn} do
activity = insert(:note_activity)
- conn = post(conn, "/api/v1/statuses/#{activity.id}/reblog", %{"visibility" => "private"})
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post(
+ "/api/v1/statuses/#{activity.id}/reblog",
+ %{"visibility" => "private"}
+ )
assert %{
"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
"reblogged" => true,
"visibility" => "private"
- } = json_response(conn, 200)
+ } = json_response_and_validate_schema(conn, 200)
assert to_string(activity.id) == id
end
"reblogged" => false,
"favourited" => false,
"bookmarked" => false
- } = json_response(conn_res, 200)
+ } = json_response_and_validate_schema(conn_res, 200)
conn_res =
build_conn()
"reblogged" => true,
"favourited" => true,
"bookmarked" => true
- } = json_response(conn_res, 200)
+ } = json_response_and_validate_schema(conn_res, 200)
assert to_string(activity.id) == id
end
{:ok, _, _} = CommonAPI.repeat(activity.id, user)
- conn = post(conn, "/api/v1/statuses/#{activity.id}/unreblog")
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity.id}/unreblog")
- assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} = json_response(conn, 200)
+ assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} =
+ json_response_and_validate_schema(conn, 200)
assert to_string(activity.id) == id
end
test "returns 404 error when activity does not exist", %{conn: conn} do
- conn = post(conn, "/api/v1/statuses/foo/unreblog")
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/foo/unreblog")
- assert json_response(conn, 404) == %{"error" => "Record not found"}
+ assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}
end
end
test "favs a status and returns it", %{conn: conn} do
activity = insert(:note_activity)
- conn = post(conn, "/api/v1/statuses/#{activity.id}/favourite")
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity.id}/favourite")
assert %{"id" => id, "favourites_count" => 1, "favourited" => true} =
- json_response(conn, 200)
+ json_response_and_validate_schema(conn, 200)
assert to_string(activity.id) == id
end
test "favoriting twice will just return 200", %{conn: conn} do
activity = insert(:note_activity)
- post(conn, "/api/v1/statuses/#{activity.id}/favourite")
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity.id}/favourite")
- assert post(conn, "/api/v1/statuses/#{activity.id}/favourite")
- |> json_response(200)
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity.id}/favourite")
+ |> json_response_and_validate_schema(200)
end
test "returns 404 error for a wrong id", %{conn: conn} do
conn =
conn
+ |> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses/1/favourite")
- assert json_response(conn, 404) == %{"error" => "Record not found"}
+ assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}
end
end
{:ok, _} = CommonAPI.favorite(user, activity.id)
- conn = post(conn, "/api/v1/statuses/#{activity.id}/unfavourite")
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity.id}/unfavourite")
assert %{"id" => id, "favourites_count" => 0, "favourited" => false} =
- json_response(conn, 200)
+ json_response_and_validate_schema(conn, 200)
assert to_string(activity.id) == id
end
test "returns 404 error for a wrong id", %{conn: conn} do
- conn = post(conn, "/api/v1/statuses/1/unfavourite")
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/1/unfavourite")
- assert json_response(conn, 404) == %{"error" => "Record not found"}
+ assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}
end
end
setup do: oauth_access(["write:accounts"])
setup %{user: user} do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
%{activity: activity}
end
assert %{"id" => ^id_str, "pinned" => true} =
conn
+ |> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses/#{activity.id}/pin")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert [%{"id" => ^id_str, "pinned" => true}] =
conn
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
end
test "/pin: returns 400 error when activity is not public", %{conn: conn, user: user} do
- {:ok, dm} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"})
+ {:ok, dm} = CommonAPI.post(user, %{status: "test", visibility: "direct"})
- conn = post(conn, "/api/v1/statuses/#{dm.id}/pin")
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{dm.id}/pin")
- assert json_response(conn, 400) == %{"error" => "Could not pin"}
+ assert json_response_and_validate_schema(conn, 400) == %{"error" => "Could not pin"}
end
test "unpin status", %{conn: conn, user: user, activity: activity} do
conn
|> assign(:user, user)
|> post("/api/v1/statuses/#{activity.id}/unpin")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert [] =
conn
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
end
test "/unpin: returns 400 error when activity is not exist", %{conn: conn} do
- conn = post(conn, "/api/v1/statuses/1/unpin")
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/1/unpin")
- assert json_response(conn, 400) == %{"error" => "Could not unpin"}
+ assert json_response_and_validate_schema(conn, 400) == %{"error" => "Could not unpin"}
end
test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
- {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity_two} = CommonAPI.post(user, %{status: "HI!!!"})
id_str_one = to_string(activity_one.id)
assert %{"id" => ^id_str_one, "pinned" => true} =
conn
+ |> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses/#{id_str_one}/pin")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
user = refresh_record(user)
conn
|> assign(:user, user)
|> post("/api/v1/statuses/#{activity_two.id}/pin")
- |> json_response(400)
+ |> json_response_and_validate_schema(400)
end
end
test "returns rich-media card", %{conn: conn, user: user} do
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "https://example.com/ogp"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "https://example.com/ogp"})
card_data = %{
"image" => "http://ia.media-imdb.com/images/rock.jpg",
response =
conn
|> get("/api/v1/statuses/#{activity.id}/card")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert response == card_data
# works with private posts
{:ok, activity} =
- CommonAPI.post(user, %{"status" => "https://example.com/ogp", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "https://example.com/ogp", visibility: "direct"})
response_two =
conn
|> get("/api/v1/statuses/#{activity.id}/card")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert response_two == card_data
end
test "replaces missing description with an empty string", %{conn: conn, user: user} do
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "https://example.com/ogp-missing-data"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "https://example.com/ogp-missing-data"})
response =
conn
|> get("/api/v1/statuses/#{activity.id}/card")
- |> json_response(:ok)
+ |> json_response_and_validate_schema(:ok)
assert response == %{
"type" => "link",
%{conn: conn} = oauth_access(["write:bookmarks", "read:bookmarks"])
author = insert(:user)
- {:ok, activity1} =
- CommonAPI.post(author, %{
- "status" => "heweoo?"
- })
+ {:ok, activity1} = CommonAPI.post(author, %{status: "heweoo?"})
+ {:ok, activity2} = CommonAPI.post(author, %{status: "heweoo!"})
- {:ok, activity2} =
- CommonAPI.post(author, %{
- "status" => "heweoo!"
- })
-
- response1 = post(conn, "/api/v1/statuses/#{activity1.id}/bookmark")
+ response1 =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity1.id}/bookmark")
- assert json_response(response1, 200)["bookmarked"] == true
+ assert json_response_and_validate_schema(response1, 200)["bookmarked"] == true
- response2 = post(conn, "/api/v1/statuses/#{activity2.id}/bookmark")
+ response2 =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity2.id}/bookmark")
- assert json_response(response2, 200)["bookmarked"] == true
+ assert json_response_and_validate_schema(response2, 200)["bookmarked"] == true
bookmarks = get(conn, bookmarks_uri)
- assert [json_response(response2, 200), json_response(response1, 200)] ==
- json_response(bookmarks, 200)
+ assert [
+ json_response_and_validate_schema(response2, 200),
+ json_response_and_validate_schema(response1, 200)
+ ] ==
+ json_response_and_validate_schema(bookmarks, 200)
- response1 = post(conn, "/api/v1/statuses/#{activity1.id}/unbookmark")
+ response1 =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity1.id}/unbookmark")
- assert json_response(response1, 200)["bookmarked"] == false
+ assert json_response_and_validate_schema(response1, 200)["bookmarked"] == false
bookmarks = get(conn, bookmarks_uri)
- assert [json_response(response2, 200)] == json_response(bookmarks, 200)
+ assert [json_response_and_validate_schema(response2, 200)] ==
+ json_response_and_validate_schema(bookmarks, 200)
end
describe "conversation muting" do
setup do
post_user = insert(:user)
- {:ok, activity} = CommonAPI.post(post_user, %{"status" => "HIE"})
+ {:ok, activity} = CommonAPI.post(post_user, %{status: "HIE"})
%{activity: activity}
end
assert %{"id" => ^id_str, "muted" => true} =
conn
+ |> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses/#{activity.id}/mute")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
end
test "cannot mute already muted conversation", %{conn: conn, user: user, activity: activity} do
{:ok, _} = CommonAPI.add_mute(user, activity)
- conn = post(conn, "/api/v1/statuses/#{activity.id}/mute")
+ conn =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses/#{activity.id}/mute")
- assert json_response(conn, 400) == %{"error" => "conversation is already muted"}
+ assert json_response_and_validate_schema(conn, 400) == %{
+ "error" => "conversation is already muted"
+ }
end
test "unmute conversation", %{conn: conn, user: user, activity: activity} do
conn
# |> assign(:user, user)
|> post("/api/v1/statuses/#{activity.id}/unmute")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
end
end
user2 = insert(:user)
user3 = insert(:user)
- {:ok, replied_to} = CommonAPI.post(user1, %{"status" => "cofe"})
+ {:ok, replied_to} = CommonAPI.post(user1, %{status: "cofe"})
# Reply to status from another user
conn1 =
conn
|> assign(:user, user2)
|> assign(:token, insert(:oauth_token, user: user2, scopes: ["write:statuses"]))
+ |> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
- assert %{"content" => "xD", "id" => id} = json_response(conn1, 200)
+ assert %{"content" => "xD", "id" => id} = json_response_and_validate_schema(conn1, 200)
activity = Activity.get_by_id_with_object(id)
conn
|> assign(:user, user3)
|> assign(:token, insert(:oauth_token, user: user3, scopes: ["write:statuses"]))
+ |> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses/#{activity.id}/reblog")
assert %{"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1}} =
- json_response(conn2, 200)
+ json_response_and_validate_schema(conn2, 200)
assert to_string(activity.id) == id
setup do: oauth_access(["read:accounts"])
setup %{user: user} do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test"})
%{activity: activity}
end
response =
conn
|> get("/api/v1/statuses/#{activity.id}/favourited_by")
- |> json_response(:ok)
+ |> json_response_and_validate_schema(:ok)
[%{"id" => id}] = response
response =
conn
|> get("/api/v1/statuses/#{activity.id}/favourited_by")
- |> json_response(:ok)
+ |> json_response_and_validate_schema(:ok)
assert Enum.empty?(response)
end
response =
conn
|> get("/api/v1/statuses/#{activity.id}/favourited_by")
- |> json_response(:ok)
+ |> json_response_and_validate_schema(:ok)
assert Enum.empty?(response)
end
response =
build_conn()
|> get("/api/v1/statuses/#{activity.id}/favourited_by")
- |> json_response(:ok)
+ |> json_response_and_validate_schema(:ok)
[%{"id" => id}] = response
assert id == other_user.id
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "@#{other_user.nickname} wanna get some #cofe together?",
- "visibility" => "direct"
+ status: "@#{other_user.nickname} wanna get some #cofe together?",
+ visibility: "direct"
})
{:ok, _} = CommonAPI.favorite(other_user, activity.id)
build_conn()
|> get(favourited_by_url)
- |> json_response(404)
+ |> json_response_and_validate_schema(404)
conn =
build_conn()
conn
|> assign(:token, nil)
|> get(favourited_by_url)
- |> json_response(404)
+ |> json_response_and_validate_schema(404)
response =
conn
|> get(favourited_by_url)
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
[%{"id" => id}] = response
assert id == other_user.id
setup do: oauth_access(["read:accounts"])
setup %{user: user} do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test"})
%{activity: activity}
end
response =
conn
|> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(:ok)
+ |> json_response_and_validate_schema(:ok)
[%{"id" => id}] = response
response =
conn
|> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(:ok)
+ |> json_response_and_validate_schema(:ok)
assert Enum.empty?(response)
end
response =
conn
|> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(:ok)
+ |> json_response_and_validate_schema(:ok)
assert Enum.empty?(response)
end
} do
other_user = insert(:user)
- {:ok, _, _} = CommonAPI.repeat(activity.id, other_user, %{"visibility" => "private"})
+ {:ok, _, _} = CommonAPI.repeat(activity.id, other_user, %{visibility: "private"})
response =
conn
|> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(:ok)
+ |> json_response_and_validate_schema(:ok)
assert Enum.empty?(response)
end
response =
build_conn()
|> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(:ok)
+ |> json_response_and_validate_schema(:ok)
[%{"id" => id}] = response
assert id == other_user.id
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "@#{other_user.nickname} wanna get some #cofe together?",
- "visibility" => "direct"
+ status: "@#{other_user.nickname} wanna get some #cofe together?",
+ visibility: "direct"
})
build_conn()
|> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(404)
+ |> json_response_and_validate_schema(404)
response =
build_conn()
|> assign(:user, other_user)
|> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:accounts"]))
|> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(200)
+ |> json_response_and_validate_schema(200)
assert [] == response
end
test "context" do
user = insert(:user)
- {:ok, %{id: id1}} = CommonAPI.post(user, %{"status" => "1"})
- {:ok, %{id: id2}} = CommonAPI.post(user, %{"status" => "2", "in_reply_to_status_id" => id1})
- {:ok, %{id: id3}} = CommonAPI.post(user, %{"status" => "3", "in_reply_to_status_id" => id2})
- {:ok, %{id: id4}} = CommonAPI.post(user, %{"status" => "4", "in_reply_to_status_id" => id3})
- {:ok, %{id: id5}} = CommonAPI.post(user, %{"status" => "5", "in_reply_to_status_id" => id4})
+ {:ok, %{id: id1}} = CommonAPI.post(user, %{status: "1"})
+ {:ok, %{id: id2}} = CommonAPI.post(user, %{status: "2", in_reply_to_status_id: id1})
+ {:ok, %{id: id3}} = CommonAPI.post(user, %{status: "3", in_reply_to_status_id: id2})
+ {:ok, %{id: id4}} = CommonAPI.post(user, %{status: "4", in_reply_to_status_id: id3})
+ {:ok, %{id: id5}} = CommonAPI.post(user, %{status: "5", in_reply_to_status_id: id4})
response =
build_conn()
|> get("/api/v1/statuses/#{id3}/context")
- |> json_response(:ok)
+ |> json_response_and_validate_schema(:ok)
assert %{
"ancestors" => [%{"id" => ^id1}, %{"id" => ^id2}],
%{user: user, conn: conn} = oauth_access(["read:favourites"])
other_user = insert(:user)
- {:ok, _} = CommonAPI.post(other_user, %{"status" => "bla"})
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "traps are happy"})
+ {:ok, _} = CommonAPI.post(other_user, %{status: "bla"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "traps are happy"})
{:ok, _} = CommonAPI.favorite(user, activity.id)
first_conn = get(conn, "/api/v1/favourites")
- assert [status] = json_response(first_conn, 200)
+ assert [status] = json_response_and_validate_schema(first_conn, 200)
assert status["id"] == to_string(activity.id)
assert [{"link", _link_header}] =
# Honours query params
{:ok, second_activity} =
CommonAPI.post(other_user, %{
- "status" =>
- "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."
+ status: "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."
})
{:ok, _} = CommonAPI.favorite(user, second_activity.id)
second_conn = get(conn, "/api/v1/favourites?since_id=#{last_like}")
- assert [second_status] = json_response(second_conn, 200)
+ assert [second_status] = json_response_and_validate_schema(second_conn, 200)
assert second_status["id"] == to_string(second_activity.id)
third_conn = get(conn, "/api/v1/favourites?limit=0")
- assert [] = json_response(third_conn, 200)
+ assert [] = json_response_and_validate_schema(third_conn, 200)
end
test "expires_at is nil for another user" do
%{conn: conn, user: user} = oauth_access(["read:statuses"])
- {:ok, activity} = CommonAPI.post(user, %{"status" => "foobar", "expires_in" => 1_000_000})
+ {:ok, activity} = CommonAPI.post(user, %{status: "foobar", expires_in: 1_000_000})
expires_at =
activity.id
|> NaiveDateTime.to_iso8601()
assert %{"pleroma" => %{"expires_at" => ^expires_at}} =
- conn |> get("/api/v1/statuses/#{activity.id}") |> json_response(:ok)
+ conn
+ |> get("/api/v1/statuses/#{activity.id}")
+ |> json_response_and_validate_schema(:ok)
%{conn: conn} = oauth_access(["read:statuses"])
assert %{"pleroma" => %{"expires_at" => nil}} =
- conn |> get("/api/v1/statuses/#{activity.id}") |> json_response(:ok)
+ conn
+ |> get("/api/v1/statuses/#{activity.id}")
+ |> json_response_and_validate_schema(:ok)
end
end
other_user = insert(:user)
- {:ok, _} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, _} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
response =
conn
following = insert(:user, nickname: "followed")
third_user = insert(:user, nickname: "repeated")
- {:ok, _activity} = CommonAPI.post(following, %{"status" => "post"})
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "repeated post"})
+ {:ok, _activity} = CommonAPI.post(following, %{status: "post"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "repeated post"})
{:ok, _, _} = CommonAPI.repeat(activity.id, following)
ret_conn = get(conn, uri)
end
test "the home timeline when the direct messages are excluded", %{user: user, conn: conn} do
- {:ok, public_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
- {:ok, direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ {:ok, public_activity} = CommonAPI.post(user, %{status: ".", visibility: "public"})
+ {:ok, direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
- {:ok, unlisted_activity} =
- CommonAPI.post(user, %{"status" => ".", "visibility" => "unlisted"})
+ {:ok, unlisted_activity} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"})
- {:ok, private_activity} =
- CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
+ {:ok, private_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
conn = get(conn, "/api/v1/timelines/home", %{"exclude_visibilities" => ["direct"]})
test "the public timeline", %{conn: conn} do
following = insert(:user)
- {:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
+ {:ok, _activity} = CommonAPI.post(following, %{status: "test"})
_activity = insert(:note_activity, local: false)
test "the public timeline includes only public statuses for an authenticated user" do
%{user: user, conn: conn} = oauth_access(["read:statuses"])
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "test"})
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "private"})
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "unlisted"})
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"})
+ {:ok, _activity} = CommonAPI.post(user, %{status: "test"})
+ {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "private"})
+ {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "unlisted"})
+ {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "direct"})
res_conn = get(conn, "/api/v1/timelines/public")
assert length(json_response(res_conn, 200)) == 1
{:ok, direct} =
CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{user_two.nickname}!",
+ visibility: "direct"
})
{:ok, _follower_only} =
CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
- "visibility" => "private"
+ status: "Hi @#{user_two.nickname}!",
+ visibility: "private"
})
conn_user_two =
Enum.each(1..20, fn _ ->
{:ok, _} =
CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{user_two.nickname}!",
+ visibility: "direct"
})
end)
{:ok, _blocked_direct} =
CommonAPI.post(blocked, %{
- "status" => "Hi @#{blocker.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}!",
+ visibility: "direct"
})
{:ok, direct} =
CommonAPI.post(other_user, %{
- "status" => "Hi @#{blocker.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}!",
+ visibility: "direct"
})
res_conn = get(conn, "api/v1/timelines/direct")
test "list timeline", %{user: user, conn: conn} do
other_user = insert(:user)
- {:ok, _activity_one} = CommonAPI.post(user, %{"status" => "Marisa is cute."})
- {:ok, activity_two} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
+ {:ok, _activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
+ {:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
{:ok, list} = Pleroma.List.create("name", user)
{:ok, list} = Pleroma.List.follow(list, other_user)
conn: conn
} do
other_user = insert(:user)
- {:ok, activity_one} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
+ {:ok, activity_one} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
{:ok, _activity_two} =
CommonAPI.post(other_user, %{
- "status" => "Marisa is cute.",
- "visibility" => "private"
+ status: "Marisa is cute.",
+ visibility: "private"
})
{:ok, list} = Pleroma.List.create("name", user)
test "hashtag timeline", %{conn: conn} do
following = insert(:user)
- {:ok, activity} = CommonAPI.post(following, %{"status" => "test #2hu"})
+ {:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})
nconn = get(conn, "/api/v1/timelines/tag/2hu")
test "multi-hashtag timeline", %{conn: conn} do
user = insert(:user)
- {:ok, activity_test} = CommonAPI.post(user, %{"status" => "#test"})
- {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test #test1"})
- {:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"})
+ {:ok, activity_test} = CommonAPI.post(user, %{status: "#test"})
+ {:ok, activity_test1} = CommonAPI.post(user, %{status: "#test #test1"})
+ {:ok, activity_none} = CommonAPI.post(user, %{status: "#test #none"})
any_test = get(conn, "/api/v1/timelines/tag/test", %{"any" => ["test1"]})
User.subscribe(subscriber, user)
- {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
+ {:ok, status} = CommonAPI.post(user, %{status: "Akariiiin"})
- {:ok, status1} = CommonAPI.post(user, %{"status" => "Magi"})
+ {:ok, status1} = CommonAPI.post(user, %{status: "Magi"})
{:ok, [notification]} = Notification.create_notifications(status)
{:ok, [notification1]} = Notification.create_notifications(status1)
res = MastodonAPI.get_notifications(subscriber)
test "Represent the user account for the account owner" do
user = insert(:user)
- notification_settings = %Pleroma.User.NotificationSetting{}
+ notification_settings = %{
+ followers: true,
+ follows: true,
+ non_followers: true,
+ non_follows: true,
+ privacy_option: false
+ }
+
privacy = user.default_scope
assert %{
{:ok, _activity} =
CommonAPI.post(other_user, %{
- "status" => "Hey @#{user.nickname}.",
- "visibility" => "direct"
+ status: "Hey @#{user.nickname}.",
+ visibility: "direct"
})
user = User.get_cached_by_ap_id(user.ap_id)
other_user = insert(:user)
{:ok, activity} =
- CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "hey @#{other_user.nickname}", visibility: "direct"})
[participation] = Participation.for_user_with_last_activity_id(user)
test "Mention notification" do
user = insert(:user)
mentioned_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{mentioned_user.nickname}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{mentioned_user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
user = User.get_cached_by_id(user.id)
test "Favourite notification" do
user = insert(:user)
another_user = insert(:user)
- {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, favorite_activity} = CommonAPI.favorite(another_user, create_activity.id)
{:ok, [notification]} = Notification.create_notifications(favorite_activity)
create_activity = Activity.get_by_id(create_activity.id)
test "Reblog notification" do
user = insert(:user)
another_user = insert(:user)
- {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, reblog_activity, _object} = CommonAPI.repeat(create_activity.id, another_user)
{:ok, [notification]} = Notification.create_notifications(reblog_activity)
reblog_activity = Activity.get_by_id(create_activity.id)
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "#cofe"})
{:ok, _activity} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
activity = Repo.get(Activity, activity.id)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "Is Tenshi eating a corndog cute?",
- "poll" => %{
- "options" => ["absolutely!", "sure", "yes", "why are you even asking?"],
- "expires_in" => 20
+ status: "Is Tenshi eating a corndog cute?",
+ poll: %{
+ options: ["absolutely!", "sure", "yes", "why are you even asking?"],
+ expires_in: 20
}
})
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "Which Mastodon developer is your favourite?",
- "poll" => %{
- "options" => ["Gargron", "Eugen"],
- "expires_in" => 20,
- "multiple" => true
+ status: "Which Mastodon developer is your favourite?",
+ poll: %{
+ options: ["Gargron", "Eugen"],
+ expires_in: 20,
+ multiple: true
}
})
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "What's with the smug face?",
- "poll" => %{
- "options" => [":blank: sip", ":blank::blank: sip", ":blank::blank::blank: sip"],
- "expires_in" => 20
+ status: "What's with the smug face?",
+ poll: %{
+ options: [":blank: sip", ":blank::blank: sip", ":blank::blank::blank: sip"],
+ expires_in: 20
}
})
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "Which input devices do you use?",
- "poll" => %{
- "options" => ["mouse", "trackball", "trackpoint"],
- "multiple" => true,
- "expires_in" => 20
+ status: "Which input devices do you use?",
+ poll: %{
+ options: ["mouse", "trackball", "trackpoint"],
+ multiple: true,
+ expires_in: 20
}
})
test "A scheduled activity with a media attachment" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hi"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hi"})
scheduled_at =
NaiveDateTime.utc_now()
expected = %{
id: to_string(scheduled_activity.id),
media_attachments:
- %{"media_ids" => [upload.id]}
+ %{media_ids: [upload.id]}
|> Utils.attachments_from_ids()
|> Enum.map(&StatusView.render("attachment.json", %{attachment: &1})),
params: %{
import Pleroma.Factory
import Tesla.Mock
+ import OpenApiSpex.TestAssertions
setup do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
user = insert(:user)
other_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "dae cofe??"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "dae cofe??"})
{:ok, _} = CommonAPI.react_with_emoji(activity.id, user, "☕")
{:ok, _} = CommonAPI.react_with_emoji(activity.id, third_user, "🍵")
activity = Repo.get(Activity, activity.id)
status = StatusView.render("show.json", activity: activity)
+ assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
+
assert status[:pleroma][:emoji_reactions] == [
%{name: "☕", count: 2, me: false},
%{name: "🍵", count: 1, me: false}
status = StatusView.render("show.json", activity: activity, for: user)
+ assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
+
assert status[:pleroma][:emoji_reactions] == [
%{name: "☕", count: 2, me: true},
%{name: "🍵", count: 1, me: false}
test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})
[participation] = Participation.for_user(user)
status =
status = StatusView.render("show.json", activity: activity, for: user)
assert status[:pleroma][:direct_conversation_id] == nil
+ assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
end
test "returns the direct conversation id when given the `direct_conversation_id` option" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})
[participation] = Participation.for_user(user)
status =
)
assert status[:pleroma][:direct_conversation_id] == participation.id
+ assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
end
test "returns a temporary ap_id based user for activities missing db users" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})
Repo.delete(user)
Cachex.clear(:user_cache)
test "tries to get a user by nickname if fetching by ap_id doesn't work" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})
{:ok, user} =
user
result = StatusView.render("show.json", activity: activity)
assert result[:account][:id] == to_string(user.id)
+ assert_schema(result, "Status", Pleroma.Web.ApiSpec.spec())
end
test "a note with null content" do
status = StatusView.render("show.json", %{activity: note})
assert status.content == ""
+ assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
end
test "a note activity" do
}
assert status == expected
+ assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
end
test "tells if the message is muted for some reason" do
{:ok, _user_relationships} = User.mute(user, other_user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "test"})
relationships_opt = UserRelationship.view_relationships_option(user, [other_user])
opts = %{activity: activity}
status = StatusView.render("show.json", opts)
assert status.muted == false
+ assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
status = StatusView.render("show.json", Map.put(opts, :relationships, relationships_opt))
assert status.muted == false
status = StatusView.render("show.json", Map.put(for_opts, :relationships, relationships_opt))
assert status.muted == true
+ assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
end
test "tells if the message is thread muted" do
{:ok, _user_relationships} = User.mute(user, other_user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "test"})
status = StatusView.render("show.json", %{activity: activity, for: user})
assert status.pleroma.thread_muted == false
test "tells if the status is bookmarked" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Cute girls doing cute things"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "Cute girls doing cute things"})
status = StatusView.render("show.json", %{activity: activity})
assert status.bookmarked == false
note = insert(:note_activity)
user = insert(:user)
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
+ {:ok, activity} = CommonAPI.post(user, %{status: "he", in_reply_to_status_id: note.id})
status = StatusView.render("show.json", %{activity: activity})
user = insert(:user)
mentioned = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hi @#{mentioned.nickname}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hi @#{mentioned.nickname}"})
status = StatusView.render("show.json", %{activity: activity})
assert status.mentions ==
Enum.map([mentioned], fn u -> AccountView.render("mention.json", %{user: u}) end)
+
+ assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
end
test "create mentions from the 'to' field" do
api_spec = Pleroma.Web.ApiSpec.spec()
assert expected == StatusView.render("attachment.json", %{attachment: object})
- OpenApiSpex.TestAssertions.assert_schema(expected, "Attachment", api_spec)
+ assert_schema(expected, "Attachment", api_spec)
# If theres a "id", use that instead of the generated one
object = Map.put(object, "id", 2)
result = StatusView.render("attachment.json", %{attachment: object})
assert %{id: "2"} = result
- OpenApiSpex.TestAssertions.assert_schema(result, "Attachment", api_spec)
+ assert_schema(result, "Attachment", api_spec)
end
test "put the url advertised in the Activity in to the url attribute" do
assert represented[:id] == to_string(reblog.id)
assert represented[:reblog][:id] == to_string(activity.id)
assert represented[:emojis] == []
+ assert_schema(represented, "Status", Pleroma.Web.ApiSpec.spec())
end
test "a peertube video" do
assert represented[:id] == to_string(activity.id)
assert length(represented[:media_attachments]) == 1
+ assert_schema(represented, "Status", Pleroma.Web.ApiSpec.spec())
end
test "funkwhale audio" do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "drink more water"
+ status: "drink more water"
})
result = StatusView.render("show.json", %{activity: activity, for: other_user})
assert result[:account][:pleroma][:relationship] ==
AccountView.render("relationship.json", %{user: other_user, target: user})
+
+ assert_schema(result, "Status", Pleroma.Web.ApiSpec.spec())
end
test "embeds a relationship in the account in reposts" do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "˙˙ɐʎns"
+ status: "˙˙ɐʎns"
})
{:ok, activity, _object} = CommonAPI.repeat(activity.id, other_user)
assert result[:reblog][:account][:pleroma][:relationship] ==
AccountView.render("relationship.json", %{user: user, target: user})
+
+ assert_schema(result, "Status", Pleroma.Web.ApiSpec.spec())
end
test "visibility/list" do
{:ok, list} = Pleroma.List.create("foo", user)
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})
status = StatusView.render("show.json", activity: activity)
assert status.length == listen_activity.data["object"]["length"]
assert status.title == listen_activity.data["object"]["title"]
+ assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
end
end
test "it uses summary twittercard if post has no attachment" do
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
note =
insert(:note, %{
test "it renders avatar not attachment if post is nsfw and unfurl_nsfw is disabled" do
Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
note =
insert(:note, %{
test "it renders supported types of attachments and skips unknown types" do
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
note =
insert(:note, %{
} do
{:ok, direct} =
CommonAPI.post(current_user, %{
- "status" => "Hi @#{user.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{user.nickname}!",
+ visibility: "direct"
})
CommonAPI.favorite(user, direct.id)
{:ok, direct} =
CommonAPI.post(user_two, %{
- "status" => "Hi @#{user.nickname}!",
- "visibility" => "direct"
+ status: "Hi @#{user.nickname}!",
+ visibility: "direct"
})
CommonAPI.favorite(user, direct.id)
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "#cofe"})
result =
conn
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "#cofe"})
{:ok, _reaction_activity} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
ObanHelpers.perform_all()
other_user = insert(:user)
doomed_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "#cofe"})
result =
conn
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "#cofe"})
result =
conn
%{user: other_user, conn: conn} = oauth_access(["read:statuses"])
{:ok, _activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "Hi @#{other_user.nickname}!", visibility: "direct"})
[participation] = Participation.for_user(other_user)
third_user = insert(:user)
{:ok, _activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{third_user.nickname}!", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "Hi @#{third_user.nickname}!", visibility: "direct"})
{:ok, activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "Hi @#{other_user.nickname}!", visibility: "direct"})
[participation] = Participation.for_user(other_user)
{:ok, activity_two} =
CommonAPI.post(other_user, %{
- "status" => "Hi!",
- "in_reply_to_status_id" => activity.id,
- "in_reply_to_conversation_id" => participation.id
+ status: "Hi!",
+ in_reply_to_status_id: activity.id,
+ in_reply_to_conversation_id: participation.id
})
result =
{:ok, %{id: id_three}} =
CommonAPI.post(other_user, %{
- "status" => "Bye!",
- "in_reply_to_status_id" => activity.id,
- "in_reply_to_conversation_id" => participation.id
+ status: "Bye!",
+ in_reply_to_status_id: activity.id,
+ in_reply_to_conversation_id: participation.id
})
assert [%{"id" => ^id_two}, %{"id" => ^id_three}] =
%{user: user, conn: conn} = oauth_access(["write:conversations"])
other_user = insert(:user)
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "Hi", "visibility" => "direct"})
+ {:ok, _activity} = CommonAPI.post(user, %{status: "Hi", visibility: "direct"})
[participation] = Participation.for_user(user)
%{user: other_user, conn: conn} = oauth_access(["write:conversations"])
{:ok, _activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "Hi @#{other_user.nickname}", visibility: "direct"})
{:ok, _activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "Hi @#{other_user.nickname}", visibility: "direct"})
[participation2, participation1] = Participation.for_user(other_user)
assert Participation.get(participation2.id).read == false
test "it marks a single notification as read", %{user: user1, conn: conn} do
user2 = insert(:user)
- {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, activity1} = CommonAPI.post(user2, %{status: "hi @#{user1.nickname}"})
+ {:ok, activity2} = CommonAPI.post(user2, %{status: "hi @#{user1.nickname}"})
{:ok, [notification1]} = Notification.create_notifications(activity1)
{:ok, [notification2]} = Notification.create_notifications(activity2)
test "it marks multiple notifications as read", %{user: user1, conn: conn} do
user2 = insert(:user)
- {:ok, _activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, _activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, _activity3} = CommonAPI.post(user2, %{"status" => "HIE @#{user1.nickname}"})
+ {:ok, _activity1} = CommonAPI.post(user2, %{status: "hi @#{user1.nickname}"})
+ {:ok, _activity2} = CommonAPI.post(user2, %{status: "hi @#{user1.nickname}"})
+ {:ok, _activity3} = CommonAPI.post(user2, %{status: "HIE @#{user1.nickname}"})
[notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
data: %{alerts: %{"follow" => true, "mention" => false}}
)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "<Lorem ipsum dolor sit amet."})
+ {:ok, activity} = CommonAPI.post(user, %{status: "<Lorem ipsum dolor sit amet."})
notif =
insert(:notification,
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
+ status:
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
+ status:
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
+ status:
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
{:ok, activity} =
CommonAPI.post(user, %{
- "visibility" => "direct",
- "status" => "This is just between you and me, pal"
+ visibility: "direct",
+ status: "This is just between you and me, pal"
})
assert Impl.format_title(%{activity: activity}) ==
{:ok, activity} =
CommonAPI.post(user, %{
- "visibility" => "direct",
- "status" => "<Lorem ipsum dolor sit amet."
+ visibility: "direct",
+ status: "<Lorem ipsum dolor sit amet."
})
notif = insert(:notification, user: user2, activity: activity)
{:ok, activity} =
CommonAPI.post(user, %{
- "visibility" => "public",
- "status" => "<Lorem ipsum dolor sit amet."
+ visibility: "public",
+ status: "<Lorem ipsum dolor sit amet."
})
notif = insert(:notification, user: user2, activity: activity)
{:ok, activity} =
CommonAPI.post(user, %{
- "visibility" => "direct",
- "status" =>
+ visibility: "direct",
+ status:
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
{:ok, activity} =
CommonAPI.post(user, %{
- "visibility" => "public",
- "status" =>
+ visibility: "public",
+ status:
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "[test](example.com/ogp)",
- "content_type" => "text/markdown"
+ status: "[test](example.com/ogp)",
+ content_type: "text/markdown"
})
Config.put([:rich_media, :enabled], true)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "[test](example.com[]/ogp)",
- "content_type" => "text/markdown"
+ status: "[test](example.com[]/ogp)",
+ content_type: "text/markdown"
})
Config.put([:rich_media, :enabled], true)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "[test](https://example.com/ogp)",
- "content_type" => "text/markdown"
+ status: "[test](https://example.com/ogp)",
+ content_type: "text/markdown"
})
Config.put([:rich_media, :enabled], true)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "http://example.com/ogp",
- "sensitive" => true
+ status: "http://example.com/ogp",
+ sensitive: true
})
%Object{} = object = Object.normalize(activity)
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "http://example.com/ogp #nsfw"
+ status: "http://example.com/ogp #nsfw"
})
%Object{} = object = Object.normalize(activity)
user = insert(:user)
{:ok, activity} =
- CommonAPI.post(user, %{"status" => "http://127.0.0.1:4000/notice/9kCP7VNyPJXFOXDrgO"})
+ CommonAPI.post(user, %{status: "http://127.0.0.1:4000/notice/9kCP7VNyPJXFOXDrgO"})
- {:ok, activity2} = CommonAPI.post(user, %{"status" => "https://10.111.10.1/notice/9kCP7V"})
- {:ok, activity3} = CommonAPI.post(user, %{"status" => "https://172.16.32.40/notice/9kCP7V"})
- {:ok, activity4} = CommonAPI.post(user, %{"status" => "https://192.168.10.40/notice/9kCP7V"})
- {:ok, activity5} = CommonAPI.post(user, %{"status" => "https://pleroma.local/notice/9kCP7V"})
+ {:ok, activity2} = CommonAPI.post(user, %{status: "https://10.111.10.1/notice/9kCP7V"})
+ {:ok, activity3} = CommonAPI.post(user, %{status: "https://172.16.32.40/notice/9kCP7V"})
+ {:ok, activity4} = CommonAPI.post(user, %{status: "https://192.168.10.40/notice/9kCP7V"})
+ {:ok, activity5} = CommonAPI.post(user, %{status: "https://pleroma.local/notice/9kCP7V"})
Config.put([:rich_media, :enabled], true)
end
test "profile does not include private messages", %{conn: conn, user: user} do
- CommonAPI.post(user, %{"status" => "public"})
- CommonAPI.post(user, %{"status" => "private", "visibility" => "private"})
+ CommonAPI.post(user, %{status: "public"})
+ CommonAPI.post(user, %{status: "private", visibility: "private"})
conn = get(conn, "/users/#{user.nickname}")
end
test "pagination", %{conn: conn, user: user} do
- Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
+ Enum.map(1..30, fn i -> CommonAPI.post(user, %{status: "test#{i}"}) end)
conn = get(conn, "/users/#{user.nickname}")
end
test "pagination, page 2", %{conn: conn, user: user} do
- activities = Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
+ activities = Enum.map(1..30, fn i -> CommonAPI.post(user, %{status: "test#{i}"}) end)
{:ok, a11} = Enum.at(activities, 11)
conn = get(conn, "/users/#{user.nickname}?max_id=#{a11.id}")
describe "notice html" do
test "single notice page", %{conn: conn, user: user} do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
conn = get(conn, "/notice/#{activity.id}")
test "filters HTML tags", %{conn: conn} do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "<script>alert('xss')</script>"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "<script>alert('xss')</script>"})
conn =
conn
end
test "shows the whole thread", %{conn: conn, user: user} do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "space: the final frontier"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "space: the final frontier"})
CommonAPI.post(user, %{
- "status" => "these are the voyages or something",
- "in_reply_to_status_id" => activity.id
+ status: "these are the voyages or something",
+ in_reply_to_status_id: activity.id
})
conn = get(conn, "/notice/#{activity.id}")
test "redirect by AP object ID", %{conn: conn, user: user} do
{:ok, %Activity{data: %{"object" => object_url}}} =
- CommonAPI.post(user, %{"status" => "beam me up"})
+ CommonAPI.post(user, %{status: "beam me up"})
conn = get(conn, URI.parse(object_url).path)
test "redirect by activity ID", %{conn: conn, user: user} do
{:ok, %Activity{data: %{"id" => id}}} =
- CommonAPI.post(user, %{"status" => "I'm a doctor, not a devops!"})
+ CommonAPI.post(user, %{status: "I'm a doctor, not a devops!"})
conn = get(conn, URI.parse(id).path)
end
test "404 for private status", %{conn: conn, user: user} do
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "don't show me!", "visibility" => "private"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "don't show me!", visibility: "private"})
conn = get(conn, "/notice/#{activity.id}")
end
test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)
end
test "it streams the user's post in the 'user' stream", %{user: user} do
Streamer.get_topic_and_add_socket("user", user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
assert_receive {:render_with_user, _, _, ^activity}
refute Streamer.filtered_by_user?(user, activity)
end
Streamer.get_topic_and_add_socket("user", user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
{:ok, announce, _} = CommonAPI.repeat(activity.id, user)
assert_receive {:render_with_user, Pleroma.Web.StreamerView, "update.json", ^announce}
Streamer.get_topic_and_add_socket("user:notification", user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => ":("})
+ {:ok, activity} = CommonAPI.post(user, %{status: ":("})
{:ok, _} = CommonAPI.favorite(blocked, activity.id)
refute_receive _
} do
user2 = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
{:ok, _} = CommonAPI.add_mute(user, activity)
Streamer.get_topic_and_add_socket("user:notification", user)
} do
user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
Streamer.get_topic_and_add_socket("user:notification", user)
{:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id)
user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
{:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
Streamer.get_topic_and_add_socket("user:notification", user)
{:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id)
Streamer.get_topic_and_add_socket("public", other_user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Test"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "Test"})
assert_receive {:render_with_user, _, _, ^activity}
refute Streamer.filtered_by_user?(user, activity)
end
test "works for deletions" do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "Test"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "Test"})
Streamer.get_topic_and_add_socket("public", user)
Streamer.get_topic_and_add_socket("public", nil)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Test"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "Test"})
activity_id = activity.id
assert_receive {:text, event}
assert %{"event" => "update", "payload" => payload} = Jason.decode!(event)
{:ok, _user_relationship} = User.block(user, blocked_user)
Streamer.get_topic_and_add_socket("public", user)
- {:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"})
+ {:ok, activity} = CommonAPI.post(blocked_user, %{status: "Test"})
assert_receive {:render_with_user, _, _, ^activity}
assert Streamer.filtered_by_user?(user, activity)
end
{:ok, _user_relationship} = User.block(blocker, blockee)
- {:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey! @#{blockee.nickname}"})
+ {:ok, activity_one} = CommonAPI.post(friend, %{status: "hey! @#{blockee.nickname}"})
assert_receive {:render_with_user, _, _, ^activity_one}
assert Streamer.filtered_by_user?(blocker, activity_one)
- {:ok, activity_two} = CommonAPI.post(blockee, %{"status" => "hey! @#{friend.nickname}"})
+ {:ok, activity_two} = CommonAPI.post(blockee, %{status: "hey! @#{friend.nickname}"})
assert_receive {:render_with_user, _, _, ^activity_two}
assert Streamer.filtered_by_user?(blocker, activity_two)
- {:ok, activity_three} = CommonAPI.post(blockee, %{"status" => "hey! @#{blocker.nickname}"})
+ {:ok, activity_three} = CommonAPI.post(blockee, %{status: "hey! @#{blocker.nickname}"})
assert_receive {:render_with_user, _, _, ^activity_three}
assert Streamer.filtered_by_user?(blocker, activity_three)
{:ok, _activity} =
CommonAPI.post(user_b, %{
- "status" => "@#{user_c.nickname} Test",
- "visibility" => "direct"
+ status: "@#{user_c.nickname} Test",
+ visibility: "direct"
})
refute_receive _
{:ok, _activity} =
CommonAPI.post(user_b, %{
- "status" => "Test",
- "visibility" => "private"
+ status: "Test",
+ visibility: "private"
})
refute_receive _
{:ok, activity} =
CommonAPI.post(user_b, %{
- "status" => "Test",
- "visibility" => "private"
+ status: "Test",
+ visibility: "private"
})
assert_receive {:render_with_user, _, _, ^activity}
CommonAPI.follow(user1, user2)
CommonAPI.hide_reblogs(user1, user2)
- {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"})
+ {:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"})
Streamer.get_topic_and_add_socket("user", user1)
{:ok, announce_activity, _} = CommonAPI.repeat(create_activity.id, user2)
CommonAPI.follow(user1, user2)
CommonAPI.hide_reblogs(user1, user2)
- {:ok, create_activity} = CommonAPI.post(user1, %{"status" => "I'm kawen"})
+ {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
Streamer.get_topic_and_add_socket("user", user1)
{:ok, _favorite_activity, _} = CommonAPI.repeat(create_activity.id, user2)
CommonAPI.follow(user1, user2)
CommonAPI.hide_reblogs(user1, user2)
- {:ok, create_activity} = CommonAPI.post(user1, %{"status" => "I'm kawen"})
+ {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
Streamer.get_topic_and_add_socket("user", user1)
{:ok, _favorite_activity} = CommonAPI.favorite(user2, create_activity.id)
user2 = insert(:user)
Streamer.get_topic_and_add_socket("user", user2)
{:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
{:ok, _} = CommonAPI.add_mute(user2, activity)
assert_receive {:render_with_user, _, _, ^activity}
assert Streamer.filtered_by_user?(user2, activity)
{:ok, _create_activity} =
CommonAPI.post(another_user, %{
- "status" => "hey @#{user.nickname}",
- "visibility" => "direct"
+ status: "hey @#{user.nickname}",
+ visibility: "direct"
})
assert_receive {:text, received_event}
{:ok, create_activity} =
CommonAPI.post(another_user, %{
- "status" => "hi @#{user.nickname}",
- "visibility" => "direct"
+ status: "hi @#{user.nickname}",
+ visibility: "direct"
})
create_activity_id = create_activity.id
{:ok, create_activity} =
CommonAPI.post(another_user, %{
- "status" => "hi @#{user.nickname}",
- "visibility" => "direct"
+ status: "hi @#{user.nickname}",
+ visibility: "direct"
})
{:ok, create_activity2} =
CommonAPI.post(another_user, %{
- "status" => "hi @#{user.nickname} 2",
- "in_reply_to_status_id" => create_activity.id,
- "visibility" => "direct"
+ status: "hi @#{user.nickname} 2",
+ in_reply_to_status_id: create_activity.id,
+ visibility: "direct"
})
assert_receive {:render_with_user, _, _, ^create_activity}
user2 = insert(:user, last_digest_emailed_at: date)
{:ok, _} = User.switch_email_notifications(user2, "digest", true)
- CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
+ CommonAPI.post(user, %{status: "hey @#{user2.nickname}!"})
{:ok, user2: user2}
end
admin = insert(:user, %{is_admin: true})
user = insert(:user, %{inserted_at: yesterday})
user2 = insert(:user, %{inserted_at: yesterday})
- CommonAPI.post(user, %{"status" => "cofe"})
+ CommonAPI.post(user, %{status: "cofe"})
NewUsersDigestWorker.perform(nil, nil)
ObanHelpers.perform_all()
insert(:user, %{inserted_at: yesterday})
user = insert(:user, %{inserted_at: yesterday})
- CommonAPI.post(user, %{"status" => "cofe"})
+ CommonAPI.post(user, %{status: "cofe"})
NewUsersDigestWorker.perform(nil, nil)
ObanHelpers.perform_all()