Merge develop
This commit is contained in:
commit
28d4512fe6
|
@ -79,7 +79,6 @@ unit-testing:
|
|||
- "**/*.ex"
|
||||
- "**/*.exs"
|
||||
- "mix.lock"
|
||||
retry: 2
|
||||
cache: &testing_cache_policy
|
||||
<<: *global_cache_policy
|
||||
policy: pull
|
||||
|
@ -94,19 +93,42 @@ unit-testing:
|
|||
- mix ecto.migrate
|
||||
- mix coveralls --preload-modules
|
||||
|
||||
federated-testing:
|
||||
unit-testing-erratic:
|
||||
stage: test
|
||||
cache: *testing_cache_policy
|
||||
retry: 2
|
||||
only:
|
||||
changes:
|
||||
- "**/*.ex"
|
||||
- "**/*.exs"
|
||||
- "mix.lock"
|
||||
cache: &testing_cache_policy
|
||||
<<: *global_cache_policy
|
||||
policy: pull
|
||||
|
||||
services:
|
||||
- name: minibikini/postgres-with-rum:12
|
||||
- name: postgres:13
|
||||
alias: postgres
|
||||
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
|
||||
script:
|
||||
- mix deps.get
|
||||
- mix ecto.create
|
||||
- mix ecto.migrate
|
||||
- epmd -daemon
|
||||
- mix test --trace --only federated
|
||||
- mix test --only=erratic
|
||||
|
||||
# Removed to fix CI issue. In this early state it wasn't adding much value anyway.
|
||||
# TODO Fix and reinstate federated testing
|
||||
# federated-testing:
|
||||
# stage: test
|
||||
# cache: *testing_cache_policy
|
||||
# services:
|
||||
# - name: minibikini/postgres-with-rum:12
|
||||
# alias: postgres
|
||||
# command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
|
||||
# script:
|
||||
# - mix deps.get
|
||||
# - mix ecto.create
|
||||
# - mix ecto.migrate
|
||||
# - epmd -daemon
|
||||
# - mix test --trace --only federated
|
||||
|
||||
unit-testing-rum:
|
||||
stage: test
|
||||
|
@ -115,7 +137,6 @@ unit-testing-rum:
|
|||
- "**/*.ex"
|
||||
- "**/*.exs"
|
||||
- "mix.lock"
|
||||
retry: 2
|
||||
cache: *testing_cache_policy
|
||||
services:
|
||||
- name: minibikini/postgres-with-rum:12
|
||||
|
|
|
@ -18,6 +18,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
|
||||
### Fixed
|
||||
- Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies
|
||||
- Handle Reject for already-accepted Follows properly
|
||||
- Display OpenGraph data on alternative notice routes.
|
||||
|
||||
### Removed
|
||||
|
||||
|
|
|
@ -254,7 +254,8 @@ config :pleroma, :instance,
|
|||
]
|
||||
],
|
||||
show_reactions: true,
|
||||
password_reset_token_validity: 60 * 60 * 24
|
||||
password_reset_token_validity: 60 * 60 * 24,
|
||||
profile_directory: true
|
||||
|
||||
config :pleroma, :welcome,
|
||||
direct_message: [
|
||||
|
|
|
@ -936,6 +936,11 @@ config :pleroma, :config_description, [
|
|||
key: :show_reactions,
|
||||
type: :boolean,
|
||||
description: "Let favourites and emoji reactions be viewed through the API."
|
||||
},
|
||||
%{
|
||||
key: :profile_directory,
|
||||
type: :boolean,
|
||||
description: "Enable profile directory."
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -383,12 +383,6 @@ Pleroma is generally compatible with the Mastodon 2.7.2 API, but some newer feat
|
|||
|
||||
- `GET /api/v1/endorsements`: Returns an empty array, `[]`
|
||||
|
||||
### Profile directory
|
||||
|
||||
*Added in Mastodon 3.0.0*
|
||||
|
||||
- `GET /api/v1/directory`: Returns HTTP 404
|
||||
|
||||
### Featured tags
|
||||
|
||||
*Added in Mastodon 3.0.0*
|
||||
|
|
|
@ -0,0 +1,347 @@
|
|||
# Nodeinfo
|
||||
|
||||
See also [the Nodeinfo standard](https://nodeinfo.diaspora.software/).
|
||||
|
||||
## `/.well-known/nodeinfo`
|
||||
### The well-known path
|
||||
* Method: `GET`
|
||||
* Authentication: not required
|
||||
* Params: none
|
||||
* Response: JSON
|
||||
* Example response:
|
||||
```json
|
||||
{
|
||||
"links":[
|
||||
{
|
||||
"href":"https://example.com/nodeinfo/2.0.json",
|
||||
"rel":"http://nodeinfo.diaspora.software/ns/schema/2.0"
|
||||
},
|
||||
{
|
||||
"href":"https://example.com/nodeinfo/2.1.json",
|
||||
"rel":"http://nodeinfo.diaspora.software/ns/schema/2.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## `/nodeinfo/2.0.json`
|
||||
### Nodeinfo 2.0
|
||||
* Method: `GET`
|
||||
* Authentication: not required
|
||||
* Params: none
|
||||
* Response: JSON
|
||||
* Example response:
|
||||
```json
|
||||
{
|
||||
"metadata":{
|
||||
"accountActivationRequired":false,
|
||||
"features":[
|
||||
"pleroma_api",
|
||||
"mastodon_api",
|
||||
"mastodon_api_streaming",
|
||||
"polls",
|
||||
"pleroma_explicit_addressing",
|
||||
"shareable_emoji_packs",
|
||||
"multifetch",
|
||||
"pleroma:api/v1/notifications:include_types_filter",
|
||||
"chat",
|
||||
"shout",
|
||||
"relay",
|
||||
"pleroma_emoji_reactions",
|
||||
"pleroma_chat_messages"
|
||||
],
|
||||
"federation":{
|
||||
"enabled":true,
|
||||
"exclusions":false,
|
||||
"mrf_hashtag":{
|
||||
"federated_timeline_removal":[
|
||||
|
||||
],
|
||||
"reject":[
|
||||
|
||||
],
|
||||
"sensitive":[
|
||||
"nsfw"
|
||||
]
|
||||
},
|
||||
"mrf_object_age":{
|
||||
"actions":[
|
||||
"delist",
|
||||
"strip_followers"
|
||||
],
|
||||
"threshold":604800
|
||||
},
|
||||
"mrf_policies":[
|
||||
"ObjectAgePolicy",
|
||||
"TagPolicy",
|
||||
"HashtagPolicy"
|
||||
],
|
||||
"quarantined_instances":[
|
||||
|
||||
]
|
||||
},
|
||||
"fieldsLimits":{
|
||||
"maxFields":10,
|
||||
"maxRemoteFields":20,
|
||||
"nameLength":512,
|
||||
"valueLength":2048
|
||||
},
|
||||
"invitesEnabled":false,
|
||||
"mailerEnabled":false,
|
||||
"nodeDescription":"Pleroma: An efficient and flexible fediverse server",
|
||||
"nodeName":"Example",
|
||||
"pollLimits":{
|
||||
"max_expiration":31536000,
|
||||
"max_option_chars":200,
|
||||
"max_options":20,
|
||||
"min_expiration":0
|
||||
},
|
||||
"postFormats":[
|
||||
"text/plain",
|
||||
"text/html",
|
||||
"text/markdown",
|
||||
"text/bbcode"
|
||||
],
|
||||
"private":false,
|
||||
"restrictedNicknames":[
|
||||
".well-known",
|
||||
"~",
|
||||
"about",
|
||||
"activities",
|
||||
"api",
|
||||
"auth",
|
||||
"check_password",
|
||||
"dev",
|
||||
"friend-requests",
|
||||
"inbox",
|
||||
"internal",
|
||||
"main",
|
||||
"media",
|
||||
"nodeinfo",
|
||||
"notice",
|
||||
"oauth",
|
||||
"objects",
|
||||
"ostatus_subscribe",
|
||||
"pleroma",
|
||||
"proxy",
|
||||
"push",
|
||||
"registration",
|
||||
"relay",
|
||||
"settings",
|
||||
"status",
|
||||
"tag",
|
||||
"user-search",
|
||||
"user_exists",
|
||||
"users",
|
||||
"web",
|
||||
"verify_credentials",
|
||||
"update_credentials",
|
||||
"relationships",
|
||||
"search",
|
||||
"confirmation_resend",
|
||||
"mfa"
|
||||
],
|
||||
"skipThreadContainment":true,
|
||||
"staffAccounts":[
|
||||
"https://example.com/users/admin",
|
||||
"https://example.com/users/staff"
|
||||
],
|
||||
"suggestions":{
|
||||
"enabled":false
|
||||
},
|
||||
"uploadLimits":{
|
||||
"avatar":2000000,
|
||||
"background":4000000,
|
||||
"banner":4000000,
|
||||
"general":16000000
|
||||
}
|
||||
},
|
||||
"openRegistrations":true,
|
||||
"protocols":[
|
||||
"activitypub"
|
||||
],
|
||||
"services":{
|
||||
"inbound":[
|
||||
|
||||
],
|
||||
"outbound":[
|
||||
|
||||
]
|
||||
},
|
||||
"software":{
|
||||
"name":"pleroma",
|
||||
"version":"2.4.1"
|
||||
},
|
||||
"usage":{
|
||||
"localPosts":27,
|
||||
"users":{
|
||||
"activeHalfyear":129,
|
||||
"activeMonth":70,
|
||||
"total":235
|
||||
}
|
||||
},
|
||||
"version":"2.0"
|
||||
}
|
||||
```
|
||||
|
||||
## `/nodeinfo/2.1.json`
|
||||
### Nodeinfo 2.1
|
||||
* Method: `GET`
|
||||
* Authentication: not required
|
||||
* Params: none
|
||||
* Response: JSON
|
||||
* Example response:
|
||||
```json
|
||||
{
|
||||
"metadata":{
|
||||
"accountActivationRequired":false,
|
||||
"features":[
|
||||
"pleroma_api",
|
||||
"mastodon_api",
|
||||
"mastodon_api_streaming",
|
||||
"polls",
|
||||
"pleroma_explicit_addressing",
|
||||
"shareable_emoji_packs",
|
||||
"multifetch",
|
||||
"pleroma:api/v1/notifications:include_types_filter",
|
||||
"chat",
|
||||
"shout",
|
||||
"relay",
|
||||
"pleroma_emoji_reactions",
|
||||
"pleroma_chat_messages"
|
||||
],
|
||||
"federation":{
|
||||
"enabled":true,
|
||||
"exclusions":false,
|
||||
"mrf_hashtag":{
|
||||
"federated_timeline_removal":[
|
||||
|
||||
],
|
||||
"reject":[
|
||||
|
||||
],
|
||||
"sensitive":[
|
||||
"nsfw"
|
||||
]
|
||||
},
|
||||
"mrf_object_age":{
|
||||
"actions":[
|
||||
"delist",
|
||||
"strip_followers"
|
||||
],
|
||||
"threshold":604800
|
||||
},
|
||||
"mrf_policies":[
|
||||
"ObjectAgePolicy",
|
||||
"TagPolicy",
|
||||
"HashtagPolicy"
|
||||
],
|
||||
"quarantined_instances":[
|
||||
|
||||
]
|
||||
},
|
||||
"fieldsLimits":{
|
||||
"maxFields":10,
|
||||
"maxRemoteFields":20,
|
||||
"nameLength":512,
|
||||
"valueLength":2048
|
||||
},
|
||||
"invitesEnabled":false,
|
||||
"mailerEnabled":false,
|
||||
"nodeDescription":"Pleroma: An efficient and flexible fediverse server",
|
||||
"nodeName":"Example",
|
||||
"pollLimits":{
|
||||
"max_expiration":31536000,
|
||||
"max_option_chars":200,
|
||||
"max_options":20,
|
||||
"min_expiration":0
|
||||
},
|
||||
"postFormats":[
|
||||
"text/plain",
|
||||
"text/html",
|
||||
"text/markdown",
|
||||
"text/bbcode"
|
||||
],
|
||||
"private":false,
|
||||
"restrictedNicknames":[
|
||||
".well-known",
|
||||
"~",
|
||||
"about",
|
||||
"activities",
|
||||
"api",
|
||||
"auth",
|
||||
"check_password",
|
||||
"dev",
|
||||
"friend-requests",
|
||||
"inbox",
|
||||
"internal",
|
||||
"main",
|
||||
"media",
|
||||
"nodeinfo",
|
||||
"notice",
|
||||
"oauth",
|
||||
"objects",
|
||||
"ostatus_subscribe",
|
||||
"pleroma",
|
||||
"proxy",
|
||||
"push",
|
||||
"registration",
|
||||
"relay",
|
||||
"settings",
|
||||
"status",
|
||||
"tag",
|
||||
"user-search",
|
||||
"user_exists",
|
||||
"users",
|
||||
"web",
|
||||
"verify_credentials",
|
||||
"update_credentials",
|
||||
"relationships",
|
||||
"search",
|
||||
"confirmation_resend",
|
||||
"mfa"
|
||||
],
|
||||
"skipThreadContainment":true,
|
||||
"staffAccounts":[
|
||||
"https://example.com/users/admin",
|
||||
"https://example.com/users/staff"
|
||||
],
|
||||
"suggestions":{
|
||||
"enabled":false
|
||||
},
|
||||
"uploadLimits":{
|
||||
"avatar":2000000,
|
||||
"background":4000000,
|
||||
"banner":4000000,
|
||||
"general":16000000
|
||||
}
|
||||
},
|
||||
"openRegistrations":true,
|
||||
"protocols":[
|
||||
"activitypub"
|
||||
],
|
||||
"services":{
|
||||
"inbound":[
|
||||
|
||||
],
|
||||
"outbound":[
|
||||
|
||||
]
|
||||
},
|
||||
"software":{
|
||||
"name":"pleroma",
|
||||
"repository":"https://git.pleroma.social/pleroma/pleroma",
|
||||
"version":"2.4.1"
|
||||
},
|
||||
"usage":{
|
||||
"localPosts":27,
|
||||
"users":{
|
||||
"activeHalfyear":129,
|
||||
"activeMonth":70,
|
||||
"total":235
|
||||
}
|
||||
},
|
||||
"version":"2.1"
|
||||
}
|
||||
```
|
||||
|
|
@ -159,10 +159,12 @@ See [Admin-API](admin_api.md)
|
|||
"muting": false,
|
||||
"muting_notifications": false,
|
||||
"subscribing": true,
|
||||
"notifying": true,
|
||||
"requested": false,
|
||||
"domain_blocking": false,
|
||||
"showing_reblogs": true,
|
||||
"endorsed": false
|
||||
"endorsed": false,
|
||||
"note": ""
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -183,10 +185,12 @@ See [Admin-API](admin_api.md)
|
|||
"muting": false,
|
||||
"muting_notifications": false,
|
||||
"subscribing": false,
|
||||
"notifying": false,
|
||||
"requested": false,
|
||||
"domain_blocking": false,
|
||||
"showing_reblogs": true,
|
||||
"endorsed": false
|
||||
"endorsed": false,
|
||||
"note": ""
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -149,6 +149,7 @@ defmodule Pleroma.User do
|
|||
field(:disclose_client, :boolean, default: true)
|
||||
field(:pinned_objects, :map, default: %{})
|
||||
field(:is_suggested, :boolean, default: false)
|
||||
field(:last_status_at, :naive_datetime)
|
||||
|
||||
embeds_one(
|
||||
:notification_settings,
|
||||
|
@ -2499,4 +2500,16 @@ defmodule Pleroma.User do
|
|||
|> where([u], u.local == true)
|
||||
|> Repo.aggregate(:count)
|
||||
end
|
||||
|
||||
def update_last_status_at(user) do
|
||||
User
|
||||
|> where(id: ^user.id)
|
||||
|> update([u], set: [last_status_at: fragment("NOW()")])
|
||||
|> select([u], u)
|
||||
|> Repo.update_all([])
|
||||
|> case do
|
||||
{1, [user]} -> set_cache(user)
|
||||
_ -> {:error, user}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,6 +47,7 @@ defmodule Pleroma.User.Query do
|
|||
is_admin: boolean(),
|
||||
is_moderator: boolean(),
|
||||
is_suggested: boolean(),
|
||||
is_discoverable: boolean(),
|
||||
super_users: boolean(),
|
||||
invisible: boolean(),
|
||||
internal: boolean(),
|
||||
|
@ -172,6 +173,10 @@ defmodule Pleroma.User.Query do
|
|||
where(query, [u], u.is_suggested == ^bool)
|
||||
end
|
||||
|
||||
defp compose_query({:is_discoverable, bool}, query) do
|
||||
where(query, [u], u.is_discoverable == ^bool)
|
||||
end
|
||||
|
||||
defp compose_query({:followers, %User{id: id}}, query) do
|
||||
query
|
||||
|> where([u], u.id != ^id)
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.UserNote do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserNote
|
||||
|
||||
schema "user_notes" do
|
||||
belongs_to(:source, User, type: FlakeId.Ecto.CompatType)
|
||||
belongs_to(:target, User, type: FlakeId.Ecto.CompatType)
|
||||
field(:comment, :string)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(%UserNote{} = user_note, params \\ %{}) do
|
||||
user_note
|
||||
|> cast(params, [:source_id, :target_id, :comment])
|
||||
|> validate_required([:source_id, :target_id])
|
||||
end
|
||||
|
||||
def show(%User{} = source, %User{} = target) do
|
||||
with %UserNote{} = note <-
|
||||
UserNote
|
||||
|> where(source_id: ^source.id, target_id: ^target.id)
|
||||
|> Repo.one() do
|
||||
note.comment
|
||||
else
|
||||
_ -> ""
|
||||
end
|
||||
end
|
||||
|
||||
def create(%User{} = source, %User{} = target, comment) do
|
||||
%UserNote{}
|
||||
|> changeset(%{
|
||||
source_id: source.id,
|
||||
target_id: target.id,
|
||||
comment: comment
|
||||
})
|
||||
|> Repo.insert(
|
||||
on_conflict: {:replace, [:comment]},
|
||||
conflict_target: [:source_id, :target_id]
|
||||
)
|
||||
end
|
||||
end
|
|
@ -81,6 +81,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
if is_public?(object), do: User.decrease_note_count(actor), else: {:ok, actor}
|
||||
end
|
||||
|
||||
def update_last_status_at_if_public(actor, object) do
|
||||
if is_public?(object), do: User.update_last_status_at(actor), else: {:ok, actor}
|
||||
end
|
||||
|
||||
defp increase_replies_count_if_reply(%{
|
||||
"object" => %{"inReplyTo" => reply_ap_id} = object,
|
||||
"type" => "Create"
|
||||
|
@ -288,6 +292,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
_ <- increase_replies_count_if_reply(create_data),
|
||||
{:quick_insert, false, activity} <- {:quick_insert, quick_insert?, activity},
|
||||
{:ok, _actor} <- increase_note_count_if_public(actor, activity),
|
||||
{:ok, _actor} <- update_last_status_at_if_public(actor, activity),
|
||||
_ <- notify_and_stream(activity),
|
||||
:ok <- maybe_schedule_poll_notifications(activity),
|
||||
:ok <- maybe_federate(activity) do
|
||||
|
|
|
@ -199,6 +199,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
|||
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
||||
{:ok, notifications} = Notification.create_notifications(activity, do_send: false)
|
||||
{:ok, _user} = ActivityPub.increase_note_count_if_public(user, object)
|
||||
{:ok, _user} = ActivityPub.update_last_status_at_if_public(user, object)
|
||||
|
||||
if in_reply_to = object.data["type"] != "Answer" && object.data["inReplyTo"] do
|
||||
Object.increase_replies_count(in_reply_to)
|
||||
|
|
|
@ -446,7 +446,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
|> Activity.Queries.by_type()
|
||||
|> Activity.Queries.by_actor(actor)
|
||||
|> Activity.Queries.by_object_id(object)
|
||||
|> where(fragment("data->>'state' = 'pending'"))
|
||||
|> where(fragment("data->>'state' = 'pending'") or fragment("data->>'state' = 'accept'"))
|
||||
|> update(set: [data: fragment("jsonb_set(data, '{state}', ?)", ^state)])
|
||||
|> Repo.update_all([])
|
||||
|
||||
|
|
|
@ -226,6 +226,12 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||
type: :boolean,
|
||||
description: "Receive this account's reblogs in home timeline? Defaults to true.",
|
||||
default: true
|
||||
},
|
||||
notify: %Schema{
|
||||
type: :boolean,
|
||||
description:
|
||||
"Receive notifications for all statuses posted by the account? Defaults to false.",
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -328,6 +334,29 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||
}
|
||||
end
|
||||
|
||||
def note_operation do
|
||||
%Operation{
|
||||
tags: ["Account actions"],
|
||||
summary: "Set a private note about a user.",
|
||||
operationId: "AccountController.note",
|
||||
security: [%{"oAuth" => ["follow", "write:accounts"]}],
|
||||
requestBody: request_body("Parameters", note_request()),
|
||||
description: "Create a note for the given account.",
|
||||
parameters: [
|
||||
%Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
|
||||
Operation.parameter(
|
||||
:comment,
|
||||
:query,
|
||||
%Schema{type: :string},
|
||||
"Account note body"
|
||||
)
|
||||
],
|
||||
responses: %{
|
||||
200 => Operation.response("Relationship", "application/json", AccountRelationship)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def follow_by_uri_operation do
|
||||
%Operation{
|
||||
tags: ["Account actions"],
|
||||
|
@ -685,9 +714,11 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||
"blocked_by" => true,
|
||||
"muting" => false,
|
||||
"muting_notifications" => false,
|
||||
"note" => "",
|
||||
"requested" => false,
|
||||
"domain_blocking" => false,
|
||||
"subscribing" => false,
|
||||
"notifying" => false,
|
||||
"endorsed" => true
|
||||
},
|
||||
%{
|
||||
|
@ -699,9 +730,11 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||
"blocked_by" => true,
|
||||
"muting" => true,
|
||||
"muting_notifications" => false,
|
||||
"note" => "",
|
||||
"requested" => true,
|
||||
"domain_blocking" => false,
|
||||
"subscribing" => false,
|
||||
"notifying" => false,
|
||||
"endorsed" => false
|
||||
},
|
||||
%{
|
||||
|
@ -713,9 +746,11 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||
"blocked_by" => false,
|
||||
"muting" => true,
|
||||
"muting_notifications" => false,
|
||||
"note" => "",
|
||||
"requested" => false,
|
||||
"domain_blocking" => true,
|
||||
"subscribing" => true,
|
||||
"notifying" => true,
|
||||
"endorsed" => false
|
||||
}
|
||||
]
|
||||
|
@ -760,6 +795,23 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||
}
|
||||
end
|
||||
|
||||
defp note_request do
|
||||
%Schema{
|
||||
title: "AccountNoteRequest",
|
||||
description: "POST body for adding a note for an account",
|
||||
type: :object,
|
||||
properties: %{
|
||||
comment: %Schema{
|
||||
type: :string,
|
||||
description: "Account note body"
|
||||
}
|
||||
},
|
||||
example: %{
|
||||
"comment" => "Example note"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp array_of_lists do
|
||||
%Schema{
|
||||
title: "ArrayOfLists",
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ApiSpec.DirectoryOperation do
|
||||
alias OpenApiSpex.Operation
|
||||
alias Pleroma.Web.ApiSpec.AccountOperation
|
||||
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
||||
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
|
||||
|
||||
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: ["Directory"],
|
||||
summary: "Profile directory",
|
||||
operationId: "DirectoryController.index",
|
||||
parameters:
|
||||
[
|
||||
Operation.parameter(
|
||||
:order,
|
||||
:query,
|
||||
:string,
|
||||
"Order by recent activity or account creation",
|
||||
required: nil
|
||||
),
|
||||
Operation.parameter(:local, :query, BooleanLike, "Include local users only")
|
||||
] ++ pagination_params(),
|
||||
responses: %{
|
||||
200 =>
|
||||
Operation.response("Accounts", "application/json", AccountOperation.array_of_accounts()),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
|
@ -239,6 +239,32 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do
|
|||
}
|
||||
end
|
||||
|
||||
def remote_interaction_operation do
|
||||
%Operation{
|
||||
tags: ["Accounts"],
|
||||
summary: "Remote interaction",
|
||||
operationId: "UtilController.remote_interaction",
|
||||
requestBody: request_body("Parameters", remote_interaction_request(), required: true),
|
||||
responses: %{
|
||||
200 =>
|
||||
Operation.response("Remote interaction URL", "application/json", %Schema{type: :object})
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp remote_interaction_request do
|
||||
%Schema{
|
||||
title: "RemoteInteractionRequest",
|
||||
description: "POST body for remote interaction",
|
||||
type: :object,
|
||||
required: [:ap_id, :profile],
|
||||
properties: %{
|
||||
ap_id: %Schema{type: :string, description: "Profile or status ActivityPub ID"},
|
||||
profile: %Schema{type: :string, description: "Remote profile webfinger"}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp delete_account_request do
|
||||
%Schema{
|
||||
title: "AccountDeleteRequest",
|
||||
|
|
|
@ -194,9 +194,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
|
|||
"id" => "9tKi3esbG7OQgZ2920",
|
||||
"muting" => false,
|
||||
"muting_notifications" => false,
|
||||
"note" => "",
|
||||
"requested" => false,
|
||||
"showing_reblogs" => true,
|
||||
"subscribing" => false
|
||||
"subscribing" => false,
|
||||
"notifying" => false
|
||||
},
|
||||
"settings_store" => %{
|
||||
"pleroma-fe" => %{}
|
||||
|
|
|
@ -22,9 +22,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do
|
|||
id: FlakeID,
|
||||
muting: %Schema{type: :boolean},
|
||||
muting_notifications: %Schema{type: :boolean},
|
||||
note: %Schema{type: :string},
|
||||
requested: %Schema{type: :boolean},
|
||||
showing_reblogs: %Schema{type: :boolean},
|
||||
subscribing: %Schema{type: :boolean}
|
||||
subscribing: %Schema{type: :boolean},
|
||||
notifying: %Schema{type: :boolean}
|
||||
},
|
||||
example: %{
|
||||
"blocked_by" => false,
|
||||
|
@ -36,9 +38,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do
|
|||
"id" => "9tKi3esbG7OQgZ2920",
|
||||
"muting" => false,
|
||||
"muting_notifications" => false,
|
||||
"note" => "",
|
||||
"requested" => false,
|
||||
"showing_reblogs" => true,
|
||||
"subscribing" => false
|
||||
"subscribing" => false,
|
||||
"notifying" => false
|
||||
}
|
||||
})
|
||||
end
|
||||
|
|
|
@ -282,9 +282,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
|
|||
"id" => "9toJCsKN7SmSf3aj5c",
|
||||
"muting" => false,
|
||||
"muting_notifications" => false,
|
||||
"note" => "",
|
||||
"requested" => false,
|
||||
"showing_reblogs" => true,
|
||||
"subscribing" => false
|
||||
"subscribing" => false,
|
||||
"notifying" => false
|
||||
},
|
||||
"skip_thread_containment" => false,
|
||||
"tags" => []
|
||||
|
|
|
@ -15,6 +15,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||
|
||||
alias Pleroma.Maps
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserNote
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.Pipeline
|
||||
|
@ -53,7 +54,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||
when action in [:verify_credentials, :endorsements, :identity_proofs]
|
||||
)
|
||||
|
||||
plug(OAuthScopesPlug, %{scopes: ["write:accounts"]} when action == :update_credentials)
|
||||
plug(
|
||||
OAuthScopesPlug,
|
||||
%{scopes: ["write:accounts"]}
|
||||
when action in [:update_credentials, :note]
|
||||
)
|
||||
|
||||
plug(OAuthScopesPlug, %{scopes: ["read:lists"]} when action == :lists)
|
||||
|
||||
|
@ -79,7 +84,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||
plug(OAuthScopesPlug, %{scopes: ["follow", "write:mutes"]} when action in [:mute, :unmute])
|
||||
|
||||
@relationship_actions [:follow, :unfollow]
|
||||
@needs_account ~W(followers following lists follow unfollow mute unmute block unblock)a
|
||||
@needs_account ~W(followers following lists follow unfollow mute unmute block unblock note)a
|
||||
|
||||
plug(
|
||||
RateLimiter,
|
||||
|
@ -435,6 +440,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||
end
|
||||
end
|
||||
|
||||
@doc "POST /api/v1/accounts/:id/note"
|
||||
def note(
|
||||
%{assigns: %{user: noter, account: target}, body_params: %{comment: comment}} = conn,
|
||||
_params
|
||||
) do
|
||||
with {:ok, _user_note} <- UserNote.create(noter, target, comment) do
|
||||
render(conn, "relationship.json", user: noter, target: target)
|
||||
end
|
||||
end
|
||||
|
||||
@doc "POST /api/v1/follows"
|
||||
def follow_by_uri(%{body_params: %{uri: uri}} = conn, _) do
|
||||
case User.get_cached_by_nickname(uri) do
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.DirectoryController do
|
||||
use Pleroma.Web, :controller
|
||||
|
||||
import Ecto.Query
|
||||
alias Pleroma.Pagination
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserRelationship
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
|
||||
require Logger
|
||||
|
||||
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
||||
|
||||
plug(:skip_auth when action == "index")
|
||||
|
||||
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.DirectoryOperation
|
||||
|
||||
@doc "GET /api/v1/directory"
|
||||
def index(%{assigns: %{user: user}} = conn, params) do
|
||||
with true <- Pleroma.Config.get([:instance, :profile_directory]) do
|
||||
limit = Map.get(params, :limit, 20) |> min(80)
|
||||
|
||||
users =
|
||||
User.Query.build(%{is_discoverable: true, invisible: false, limit: limit})
|
||||
|> order_by_creation_date(params)
|
||||
|> exclude_remote(params)
|
||||
|> exclude_user(user)
|
||||
|> exclude_relationships(user, [:block, :mute])
|
||||
|> Pagination.fetch_paginated(params, :offset)
|
||||
|
||||
conn
|
||||
|> put_view(AccountView)
|
||||
|> render("index.json", for: user, users: users, as: :user)
|
||||
else
|
||||
_ -> json(conn, [])
|
||||
end
|
||||
end
|
||||
|
||||
defp order_by_creation_date(query, %{order: "new"}) do
|
||||
query
|
||||
end
|
||||
|
||||
defp order_by_creation_date(query, _params) do
|
||||
query
|
||||
|> order_by([u], desc_nulls_last: u.last_status_at)
|
||||
end
|
||||
|
||||
defp exclude_remote(query, %{local: true}) do
|
||||
where(query, [u], u.local == true)
|
||||
end
|
||||
|
||||
defp exclude_remote(query, _params) do
|
||||
query
|
||||
end
|
||||
|
||||
defp exclude_user(query, %User{id: user_id}) do
|
||||
where(query, [u], u.id != ^user_id)
|
||||
end
|
||||
|
||||
defp exclude_user(query, _user) do
|
||||
query
|
||||
end
|
||||
|
||||
defp exclude_relationships(query, %User{id: user_id}, relationship_types) do
|
||||
query
|
||||
|> join(:left, [u], r in UserRelationship,
|
||||
as: :user_relationships,
|
||||
on:
|
||||
r.target_id == u.id and r.source_id == ^user_id and
|
||||
r.relationship_type in ^relationship_types
|
||||
)
|
||||
|> where([user_relationships: r], is_nil(r.target_id))
|
||||
end
|
||||
|
||||
defp exclude_relationships(query, _user, _relationship_types) do
|
||||
query
|
||||
end
|
||||
end
|
|
@ -24,6 +24,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
with {:ok, follower, _followed, _} <- result do
|
||||
options = cast_params(params)
|
||||
set_reblogs_visibility(options[:reblogs], result)
|
||||
set_subscription(options[:notify], result)
|
||||
{:ok, follower}
|
||||
end
|
||||
end
|
||||
|
@ -36,6 +37,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
CommonAPI.show_reblogs(follower, followed)
|
||||
end
|
||||
|
||||
defp set_subscription(true, {:ok, follower, followed, _}) do
|
||||
User.subscribe(follower, followed)
|
||||
end
|
||||
|
||||
defp set_subscription(false, {:ok, follower, followed, _}) do
|
||||
User.unsubscribe(follower, followed)
|
||||
end
|
||||
|
||||
defp set_subscription(_, _), do: {:ok, nil}
|
||||
|
||||
@spec get_followers(User.t(), map()) :: list(User.t())
|
||||
def get_followers(user, params \\ %{}) do
|
||||
user
|
||||
|
@ -73,7 +84,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
exclude_visibilities: {:array, :string},
|
||||
reblogs: :boolean,
|
||||
with_muted: :boolean,
|
||||
account_ap_id: :string
|
||||
account_ap_id: :string,
|
||||
notify: :boolean
|
||||
}
|
||||
|
||||
changeset = cast({%{}, param_types}, params, Map.keys(param_types))
|
||||
|
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
|
||||
alias Pleroma.FollowingRelationship
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserNote
|
||||
alias Pleroma.UserRelationship
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
|
@ -101,6 +102,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
User.following?(target, reading_user)
|
||||
end
|
||||
|
||||
subscribing =
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
:inverse_subscription,
|
||||
target,
|
||||
reading_user,
|
||||
&User.subscribed_to?(&2, &1)
|
||||
)
|
||||
|
||||
# NOTE: adjust UserRelationship.view_relationships_option/2 on new relation-related flags
|
||||
%{
|
||||
id: to_string(target.id),
|
||||
|
@ -138,14 +148,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
target,
|
||||
&User.muted_notifications?(&1, &2)
|
||||
),
|
||||
subscribing:
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
:inverse_subscription,
|
||||
target,
|
||||
reading_user,
|
||||
&User.subscribed_to?(&2, &1)
|
||||
),
|
||||
subscribing: subscribing,
|
||||
notifying: subscribing,
|
||||
requested: follow_state == :follow_pending,
|
||||
domain_blocking: User.blocks_domain?(reading_user, target),
|
||||
showing_reblogs:
|
||||
|
@ -156,7 +160,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
target,
|
||||
&User.muting_reblogs?(&1, &2)
|
||||
),
|
||||
endorsed: false
|
||||
endorsed: false,
|
||||
note:
|
||||
UserNote.show(
|
||||
reading_user,
|
||||
target
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -261,6 +270,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
actor_type: user.actor_type
|
||||
}
|
||||
},
|
||||
last_status_at: user.last_status_at,
|
||||
|
||||
# Pleroma extensions
|
||||
# Note: it's insecure to output :email but fully-qualified nickname may serve as safe stub
|
||||
|
|
|
@ -87,6 +87,9 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||
"pleroma_chat_messages",
|
||||
if Config.get([:instance, :show_reactions]) do
|
||||
"exposable_reactions"
|
||||
end,
|
||||
if Config.get([:instance, :profile_directory]) do
|
||||
"profile_directory"
|
||||
end
|
||||
]
|
||||
|> Enum.filter(& &1)
|
||||
|
|
|
@ -151,6 +151,7 @@ defmodule Pleroma.Web.Router do
|
|||
get("/emoji", UtilController, :emoji)
|
||||
get("/captcha", UtilController, :captcha)
|
||||
get("/healthcheck", UtilController, :healthcheck)
|
||||
post("/remote_interaction", UtilController, :remote_interaction)
|
||||
end
|
||||
|
||||
scope "/api/v1/pleroma", Pleroma.Web do
|
||||
|
@ -474,6 +475,7 @@ defmodule Pleroma.Web.Router do
|
|||
post("/accounts/:id/unblock", AccountController, :unblock)
|
||||
post("/accounts/:id/mute", AccountController, :mute)
|
||||
post("/accounts/:id/unmute", AccountController, :unmute)
|
||||
post("/accounts/:id/note", AccountController, :note)
|
||||
|
||||
get("/conversations", ConversationController, :index)
|
||||
post("/conversations/:id/read", ConversationController, :mark_as_read)
|
||||
|
@ -598,6 +600,8 @@ defmodule Pleroma.Web.Router do
|
|||
get("/timelines/tag/:tag", TimelineController, :hashtag)
|
||||
|
||||
get("/polls/:id", PollController, :show)
|
||||
|
||||
get("/directory", DirectoryController, :index)
|
||||
end
|
||||
|
||||
scope "/api/v2", Pleroma.Web.MastodonAPI do
|
||||
|
@ -648,6 +652,11 @@ defmodule Pleroma.Web.Router do
|
|||
get("/activities/:uuid", OStatus.OStatusController, :activity)
|
||||
get("/notice/:id", OStatus.OStatusController, :notice)
|
||||
|
||||
# Notice compatibility routes for other frontends
|
||||
get("/@:nickname/:id", OStatus.OStatusController, :notice)
|
||||
get("/@:nickname/posts/:id", OStatus.OStatusController, :notice)
|
||||
get("/:nickname/status/:id", OStatus.OStatusController, :notice)
|
||||
|
||||
# Mastodon compatibility routes
|
||||
get("/users/:nickname/statuses/:id", OStatus.OStatusController, :object)
|
||||
get("/users/:nickname/statuses/:id/activity", OStatus.OStatusController, :activity)
|
||||
|
|
|
@ -167,6 +167,15 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
|
|||
defp assign_id(%{path_info: ["notice", notice_id]} = conn, _opts),
|
||||
do: assign(conn, :notice_id, notice_id)
|
||||
|
||||
defp assign_id(%{path_info: ["@" <> _nickname, notice_id]} = conn, _opts),
|
||||
do: assign(conn, :notice_id, notice_id)
|
||||
|
||||
defp assign_id(%{path_info: ["@" <> _nickname, "posts", notice_id]} = conn, _opts),
|
||||
do: assign(conn, :notice_id, notice_id)
|
||||
|
||||
defp assign_id(%{path_info: [_nickname, "status", notice_id]} = conn, _opts),
|
||||
do: assign(conn, :notice_id, notice_id)
|
||||
|
||||
defp assign_id(%{path_info: ["users", user_id]} = conn, _opts),
|
||||
do: assign(conn, :username_or_id, user_id)
|
||||
|
||||
|
|
|
@ -62,6 +62,15 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
|||
end
|
||||
end
|
||||
|
||||
def remote_interaction(%{body_params: %{ap_id: ap_id, profile: profile}} = conn, _params) do
|
||||
with {:ok, %{"subscribe_address" => template}} <- WebFinger.finger(profile) do
|
||||
conn
|
||||
|> json(%{url: String.replace(template, "{uri}", ap_id)})
|
||||
else
|
||||
_e -> json(conn, %{error: "Couldn't find user"})
|
||||
end
|
||||
end
|
||||
|
||||
def frontend_configurations(conn, _params) do
|
||||
render(conn, "frontend_configurations.json")
|
||||
end
|
||||
|
|
7
mix.exs
7
mix.exs
|
@ -8,7 +8,7 @@ defmodule Pleroma.Mixfile do
|
|||
elixir: "~> 1.9",
|
||||
elixirc_paths: elixirc_paths(Mix.env()),
|
||||
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
|
||||
elixirc_options: [warnings_as_errors: warnings_as_errors(Mix.env())],
|
||||
elixirc_options: [warnings_as_errors: warnings_as_errors()],
|
||||
xref: [exclude: [:eldap]],
|
||||
start_permanent: Mix.env() == :prod,
|
||||
aliases: aliases(),
|
||||
|
@ -91,10 +91,7 @@ defmodule Pleroma.Mixfile do
|
|||
defp elixirc_paths(:test), do: ["lib", "test/support"]
|
||||
defp elixirc_paths(_), do: ["lib"]
|
||||
|
||||
defp warnings_as_errors(:huskyapp), do: false
|
||||
defp warnings_as_errors(:prod), do: false
|
||||
defp warnings_as_errors(:isi), do: false
|
||||
defp warnings_as_errors(_), do: true
|
||||
defp warnings_as_errors, do: System.get_env("CI") == "true"
|
||||
|
||||
# Specifies OAuth dependencies.
|
||||
defp oauth_deps do
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
defmodule Pleroma.Repo.Migrations.CreateUserNotes do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create_if_not_exists table(:user_notes) do
|
||||
add(:source_id, references(:users, type: :uuid, on_delete: :delete_all))
|
||||
add(:target_id, references(:users, type: :uuid, on_delete: :delete_all))
|
||||
add(:comment, :string)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create_if_not_exists(unique_index(:user_notes, [:source_id, :target_id]))
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
defmodule Pleroma.Repo.Migrations.AddLastStatusAtToUsers do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:users) do
|
||||
add(:last_status_at, :naive_datetime)
|
||||
end
|
||||
|
||||
create_if_not_exists(index(:users, [:last_status_at]))
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
defmodule Pleroma.Repo.Migrations.AddIsDiscoverableIndexToUsers do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create(index(:users, [:is_discoverable]))
|
||||
end
|
||||
end
|
|
@ -88,6 +88,16 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
assert User.blocks?(user, blocked)
|
||||
end
|
||||
|
||||
test "it updates following relationship", %{user: user, blocked: blocked, block: block} do
|
||||
{:ok, _, _} = SideEffects.handle(block)
|
||||
|
||||
refute Pleroma.FollowingRelationship.get(user, blocked)
|
||||
assert User.get_follow_state(user, blocked) == nil
|
||||
assert User.get_follow_state(blocked, user) == nil
|
||||
assert User.get_follow_state(user, blocked, nil) == nil
|
||||
assert User.get_follow_state(blocked, user, nil) == nil
|
||||
end
|
||||
|
||||
test "it blocks but does not unfollow if the relevant setting is set", %{
|
||||
user: user,
|
||||
blocked: blocked,
|
||||
|
@ -542,4 +552,74 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "removing a follower" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(user, followed)
|
||||
|
||||
{:ok, reject_data, []} = Builder.reject(followed, follow_activity)
|
||||
{:ok, reject, _meta} = ActivityPub.persist(reject_data, local: true)
|
||||
|
||||
%{user: user, followed: followed, reject: reject}
|
||||
end
|
||||
|
||||
test "", %{user: user, followed: followed, reject: reject} do
|
||||
assert User.following?(user, followed)
|
||||
assert Pleroma.FollowingRelationship.get(user, followed)
|
||||
|
||||
{:ok, _, _} = SideEffects.handle(reject)
|
||||
|
||||
refute User.following?(user, followed)
|
||||
refute Pleroma.FollowingRelationship.get(user, followed)
|
||||
assert User.get_follow_state(user, followed) == nil
|
||||
assert User.get_follow_state(user, followed, nil) == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "removing a follower from remote" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
followed = insert(:user, local: false)
|
||||
|
||||
# Mock a local-to-remote follow
|
||||
{:ok, follow_data, []} = Builder.follow(user, followed)
|
||||
|
||||
follow_data =
|
||||
follow_data
|
||||
|> Map.put("state", "accept")
|
||||
|
||||
{:ok, follow, _meta} = ActivityPub.persist(follow_data, local: true)
|
||||
{:ok, _, _} = SideEffects.handle(follow)
|
||||
|
||||
# Mock a remote-to-local accept
|
||||
{:ok, accept_data, _} = Builder.accept(followed, follow)
|
||||
{:ok, accept, _} = ActivityPub.persist(accept_data, local: false)
|
||||
{:ok, _, _} = SideEffects.handle(accept)
|
||||
|
||||
# Mock a remote-to-local reject
|
||||
{:ok, reject_data, []} = Builder.reject(followed, follow)
|
||||
{:ok, reject, _meta} = ActivityPub.persist(reject_data, local: false)
|
||||
|
||||
%{user: user, followed: followed, reject: reject}
|
||||
end
|
||||
|
||||
test "", %{user: user, followed: followed, reject: reject} do
|
||||
assert User.following?(user, followed)
|
||||
assert Pleroma.FollowingRelationship.get(user, followed)
|
||||
|
||||
{:ok, _, _} = SideEffects.handle(reject)
|
||||
|
||||
refute User.following?(user, followed)
|
||||
refute Pleroma.FollowingRelationship.get(user, followed)
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(user, followed).data["state"] ==
|
||||
"reject"
|
||||
|
||||
assert User.get_follow_state(user, followed) == nil
|
||||
assert User.get_follow_state(user, followed, nil) == nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -213,6 +213,20 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
assert refresh_record(follow_activity).data["state"] == "accept"
|
||||
assert refresh_record(follow_activity_two).data["state"] == "accept"
|
||||
end
|
||||
|
||||
test "also updates the state of accepted follows" do
|
||||
user = insert(:user)
|
||||
follower = insert(:user)
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user)
|
||||
{:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user)
|
||||
|
||||
{:ok, follow_activity_two} =
|
||||
Utils.update_follow_state_for_all(follow_activity_two, "reject")
|
||||
|
||||
assert refresh_record(follow_activity).data["state"] == "reject"
|
||||
assert refresh_record(follow_activity_two).data["state"] == "reject"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update_follow_state/2" do
|
||||
|
|
|
@ -922,6 +922,27 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "following with subscription and unsubscribing" do
|
||||
%{conn: conn} = oauth_access(["follow"])
|
||||
followed = insert(:user)
|
||||
|
||||
ret_conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/accounts/#{followed.id}/follow", %{notify: true})
|
||||
|
||||
assert %{"id" => _id, "subscribing" => true} =
|
||||
json_response_and_validate_schema(ret_conn, 200)
|
||||
|
||||
ret_conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/accounts/#{followed.id}/follow", %{notify: false})
|
||||
|
||||
assert %{"id" => _id, "subscribing" => false} =
|
||||
json_response_and_validate_schema(ret_conn, 200)
|
||||
end
|
||||
|
||||
test "following / unfollowing errors", %{user: user, conn: conn} do
|
||||
# self follow
|
||||
conn_res = post(conn, "/api/v1/accounts/#{user.id}/follow")
|
||||
|
@ -1776,4 +1797,21 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
assert [%{"id" => ^id2}] = result
|
||||
end
|
||||
|
||||
test "create a note on a user" do
|
||||
%{conn: conn} = oauth_access(["write:accounts", "read:follows"])
|
||||
other_user = insert(:user)
|
||||
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/accounts/#{other_user.id}/note", %{
|
||||
"comment" => "Example note"
|
||||
})
|
||||
|
||||
assert [%{"note" => "Example note"}] =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> get("/api/v1/accounts/relationships?id=#{other_user.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.DirectoryControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
alias Pleroma.Web.CommonAPI
|
||||
import Pleroma.Factory
|
||||
|
||||
test "GET /api/v1/directory with :profile_directory disabled returns empty array", %{conn: conn} do
|
||||
clear_config([:instance, :profile_directory], false)
|
||||
|
||||
insert(:user, is_discoverable: true)
|
||||
insert(:user, is_discoverable: true)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/directory")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert result == []
|
||||
end
|
||||
|
||||
test "GET /api/v1/directory returns discoverable users only", %{conn: conn} do
|
||||
%{id: user_id} = insert(:user, is_discoverable: true)
|
||||
insert(:user, is_discoverable: false)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/directory")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^user_id}] = result
|
||||
end
|
||||
|
||||
test "GET /api/v1/directory returns users sorted by most recent statuses", %{conn: conn} do
|
||||
insert(:user, is_discoverable: true)
|
||||
%{id: user_id} = user = insert(:user, is_discoverable: true)
|
||||
insert(:user, is_discoverable: true)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(user, %{status: "yay i'm discoverable"})
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/directory?order=active")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^user_id} | _tail] = result
|
||||
end
|
||||
end
|
|
@ -74,6 +74,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
fields: []
|
||||
},
|
||||
fqn: "shp@shitposter.club",
|
||||
last_status_at: nil,
|
||||
pleroma: %{
|
||||
ap_id: user.ap_id,
|
||||
also_known_as: ["https://shitposter.zone/users/shp"],
|
||||
|
@ -175,6 +176,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
fields: []
|
||||
},
|
||||
fqn: "shp@shitposter.club",
|
||||
last_status_at: nil,
|
||||
pleroma: %{
|
||||
ap_id: user.ap_id,
|
||||
also_known_as: [],
|
||||
|
@ -270,10 +272,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
muting: false,
|
||||
muting_notifications: false,
|
||||
subscribing: false,
|
||||
notifying: false,
|
||||
requested: false,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: true,
|
||||
endorsed: false
|
||||
endorsed: false,
|
||||
note: ""
|
||||
}
|
||||
|
||||
test "represent a relationship for the following and followed user" do
|
||||
|
@ -295,6 +299,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
muting: true,
|
||||
muting_notifications: true,
|
||||
subscribing: true,
|
||||
notifying: true,
|
||||
showing_reblogs: false,
|
||||
id: to_string(other_user.id)
|
||||
}
|
||||
|
|
|
@ -343,4 +343,54 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|> response(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "notice compatibility routes" do
|
||||
test "Soapbox FE", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
note_activity = insert(:note_activity, user: user)
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/@#{user.nickname}/posts/#{note_activity.id}")
|
||||
|> response(200)
|
||||
|
||||
expected =
|
||||
"<meta content=\"#{Endpoint.url()}/notice/#{note_activity.id}\" property=\"og:url\">"
|
||||
|
||||
assert resp =~ expected
|
||||
end
|
||||
|
||||
test "Mastodon", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
note_activity = insert(:note_activity, user: user)
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/@#{user.nickname}/#{note_activity.id}")
|
||||
|> response(200)
|
||||
|
||||
expected =
|
||||
"<meta content=\"#{Endpoint.url()}/notice/#{note_activity.id}\" property=\"og:url\">"
|
||||
|
||||
assert resp =~ expected
|
||||
end
|
||||
|
||||
test "Twitter", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
note_activity = insert(:note_activity, user: user)
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/#{user.nickname}/status/#{note_activity.id}")
|
||||
|> response(200)
|
||||
|
||||
expected =
|
||||
"<meta content=\"#{Endpoint.url()}/notice/#{note_activity.id}\" property=\"og:url\">"
|
||||
|
||||
assert resp =~ expected
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -86,6 +86,8 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
|||
"objects",
|
||||
"activities",
|
||||
"notice",
|
||||
"@:nickname",
|
||||
":nickname",
|
||||
"users",
|
||||
"tags",
|
||||
"mailer",
|
||||
|
|
Loading…
Reference in New Issue