forked from AkkomaGang/akkoma
Merge branch 'develop' of http://akkoma.dev/AkkomaGang/akkoma into develop
This commit is contained in:
commit
6a20f59a42
204 changed files with 6601 additions and 990 deletions
|
@ -1,18 +0,0 @@
|
|||
<!--
|
||||
### Precheck
|
||||
|
||||
* For support use https://git.pleroma.social/pleroma/pleroma-support or [community channels](https://git.pleroma.social/pleroma/pleroma#community-channels).
|
||||
* Please do a quick search to ensure no similar bug has been reported before. If the bug has not been addressed after 2 weeks, it's fine to bump it.
|
||||
* Try to ensure that the bug is actually related to the Pleroma backend. For example, if a bug happens in Pleroma-FE but not in Mastodon-FE or mobile clients, it's likely that the bug should be filed in [Pleroma-FE](https://git.pleroma.social/pleroma/pleroma-fe/issues/new) repository.
|
||||
-->
|
||||
|
||||
### Environment
|
||||
|
||||
* Installation type (OTP or From Source):
|
||||
* Pleroma version (could be found in the "Version" tab of settings in Pleroma-FE):
|
||||
* Elixir version (`elixir -v` for from source installations, N/A for OTP):
|
||||
* Operating system:
|
||||
* PostgreSQL version (`psql -V`):
|
||||
|
||||
|
||||
### Bug description
|
|
@ -1,6 +0,0 @@
|
|||
### Release checklist
|
||||
* [ ] Bump version in `mix.exs`
|
||||
* [ ] Compile a changelog
|
||||
* [ ] Create an MR with an announcement to pleroma.social
|
||||
* [ ] Tag the release
|
||||
* [ ] Merge `stable` into `develop` (in case the fixes are already in develop, use `git merge -s ours --no-commit` and manually merge the changelogs)
|
|
@ -14,6 +14,14 @@ variables:
|
|||
- stable
|
||||
- refs/tags/v*
|
||||
- refs/tags/stable-*
|
||||
- &on-stable
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
- tag
|
||||
branch:
|
||||
- stable
|
||||
- refs/tags/stable-*
|
||||
- &on-point-release
|
||||
when:
|
||||
event:
|
||||
|
@ -87,13 +95,12 @@ pipeline:
|
|||
|
||||
# Canonical amd64
|
||||
ubuntu22:
|
||||
image: hexpm/elixir:1.13.4-erlang-25.0.2-ubuntu-jammy-20220428
|
||||
image: hexpm/elixir:1.13.4-erlang-24.3.4.5-ubuntu-jammy-20220428
|
||||
<<: *on-release
|
||||
environment:
|
||||
MIX_ENV: prod
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
commands:
|
||||
- rm config/emoji.txt
|
||||
- apt-get update && apt-get install -y cmake libmagic-dev rclone zip imagemagick libmagic-dev git build-essential g++ wget
|
||||
- *clean
|
||||
- echo "import Config" > config/prod.secret.exs
|
||||
|
@ -111,9 +118,11 @@ pipeline:
|
|||
- export SOURCE=akkoma-ubuntu-jammy.zip
|
||||
- export DEST=scaleway:akkoma-updates/$${CI_COMMIT_TAG:-"$CI_COMMIT_BRANCH"}/akkoma-ubuntu-jammy.zip
|
||||
- /bin/sh /entrypoint.sh
|
||||
- export DEST=scaleway:akkoma-updates/$${CI_COMMIT_TAG:-"$CI_COMMIT_BRANCH"}/akkoma-amd64-ubuntu-jammy.zip
|
||||
- /bin/sh /entrypoint.sh
|
||||
|
||||
debian-bullseye:
|
||||
image: elixir:1.13.4
|
||||
image: hexpm/elixir:1.13.4-erlang-24.3.4.5-debian-bullseye-20220801
|
||||
<<: *on-release
|
||||
environment:
|
||||
MIX_ENV: prod
|
||||
|
@ -142,8 +151,8 @@ pipeline:
|
|||
|
||||
# Canonical amd64-musl
|
||||
musl:
|
||||
image: elixir:1.13.4-alpine
|
||||
<<: *on-release
|
||||
image: hexpm/elixir:1.13.4-erlang-24.3.4.5-alpine-3.15.6
|
||||
<<: *on-stable
|
||||
environment:
|
||||
MIX_ENV: prod
|
||||
commands:
|
||||
|
@ -158,7 +167,7 @@ pipeline:
|
|||
|
||||
release-musl:
|
||||
image: akkoma/releaser
|
||||
<<: *on-release
|
||||
<<: *on-stable
|
||||
secrets: *scw-secrets
|
||||
commands:
|
||||
- export SOURCE=akkoma-amd64-musl.zip
|
||||
|
|
37
CHANGELOG.md
37
CHANGELOG.md
|
@ -4,7 +4,42 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
## [Unreleased]
|
||||
## Unreleased
|
||||
|
||||
### Changed
|
||||
- **Breaking**: `/api/v1/pleroma/backups` endpoints now requires `read:backups` scope instead of `read:accounts`
|
||||
|
||||
### Fixed
|
||||
- prevent false-errors from meilisearch
|
||||
|
||||
## 2022.09
|
||||
|
||||
### Added
|
||||
- support for fedibird-fe, and non-breaking API parity for it to function
|
||||
- support for setting instance languages in metadata
|
||||
- support for reusing oauth tokens, and not requiring new authorizations
|
||||
- the ability to obfuscate domains in your MRF descriptions
|
||||
- automatic translation of statuses via DeepL or LibreTranslate
|
||||
- ability to edit posts
|
||||
- ability to react with remote emoji
|
||||
|
||||
### Changed
|
||||
- MFM parsing is now done on the backend by a modified version of ilja's parser -> https://akkoma.dev/AkkomaGang/mfm-parser
|
||||
- InlineQuotePolicy is now on by default
|
||||
- Enable remote users to interact with posts
|
||||
|
||||
### Fixed
|
||||
- Compatibility with latest meilisearch
|
||||
- Resolution of nested mix tasks (i.e search.meilisearch) in OTP releases
|
||||
- Elasticsearch returning likes and repeats, displaying as posts
|
||||
- Ensure key generation happens at registration-time to prevent potential race-conditions
|
||||
- Ensured websockets get closed on logout
|
||||
- Allowed GoToSocial-style `?query_string` signatures
|
||||
|
||||
### Removed
|
||||
- Non-finch HTTP adapters. `:tesla, :adapter` is now highly recommended to be set to the default.
|
||||
|
||||
## 2022.08
|
||||
|
||||
### Added
|
||||
- extended runtime module support, see config cheatsheet
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
*a smallish microblogging platform, aka the cooler pleroma*
|
||||
|
||||
![English OK](https://img.shields.io/badge/English-OK-blueviolet) ![日本語OK](https://img.shields.io/badge/%E6%97%A5%E6%9C%AC%E8%AA%9E-OK-blueviolet)
|
||||
|
||||
## About
|
||||
|
||||
This is a fork of Pleroma, which is a microblogging server software that can federate (= exchange messages with) other servers that support ActivityPub. What that means is that you can host a server for yourself or your friends and stay in control of your online identity, but still exchange messages with people on larger servers. Akkoma will federate with all servers that implement ActivityPub, like Friendica, GNU Social, Hubzilla, Mastodon, Misskey, Peertube, and Pixelfed.
|
||||
|
|
2
SIGNING_KEY.pub
Normal file
2
SIGNING_KEY.pub
Normal file
|
@ -0,0 +1,2 @@
|
|||
untrusted comment: Akkoma Signing Key public key
|
||||
RWQRlw8Ex/uTbvo1wB1yK75tQ5nXKilB/vrKdkL41bgZHL9aKP+7fSS5
|
|
@ -48,6 +48,7 @@
|
|||
|
||||
config :pleroma, Pleroma.Repo,
|
||||
telemetry_event: [Pleroma.Repo.Instrumenter],
|
||||
queue_target: 20_000,
|
||||
migration_lock: nil
|
||||
|
||||
config :pleroma, Pleroma.Captcha,
|
||||
|
@ -197,6 +198,7 @@
|
|||
avatar_upload_limit: 2_000_000,
|
||||
background_upload_limit: 4_000_000,
|
||||
banner_upload_limit: 4_000_000,
|
||||
languages: ["en"],
|
||||
poll_limits: %{
|
||||
max_options: 20,
|
||||
max_option_chars: 200,
|
||||
|
@ -734,6 +736,14 @@
|
|||
"build_dir" => "distribution",
|
||||
"ref" => "akkoma"
|
||||
},
|
||||
"fedibird-fe" => %{
|
||||
"name" => "fedibird-fe",
|
||||
"git" => "https://akkoma.dev/AkkomaGang/fedibird-fe",
|
||||
"build_url" =>
|
||||
"https://akkoma-updates.s3-website.fr-par.scw.cloud/frontend/${ref}/fedibird-fe.zip",
|
||||
"build_dir" => "distribution",
|
||||
"ref" => "akkoma"
|
||||
},
|
||||
"admin-fe" => %{
|
||||
"name" => "admin-fe",
|
||||
"git" => "https://akkoma.dev/AkkomaGang/admin-fe",
|
||||
|
@ -743,9 +753,9 @@
|
|||
},
|
||||
"soapbox-fe" => %{
|
||||
"name" => "soapbox-fe",
|
||||
"git" => "https://gitlab.com/soapbox-pub/soapbox-fe",
|
||||
"git" => "https://gitlab.com/soapbox-pub/soapbox",
|
||||
"build_url" =>
|
||||
"https://gitlab.com/soapbox-pub/soapbox-fe/-/jobs/artifacts/${ref}/download?job=build-production",
|
||||
"https://gitlab.com/soapbox-pub/soapbox/-/jobs/artifacts/${ref}/download?job=build-production",
|
||||
"ref" => "v2.0.0",
|
||||
"build_dir" => "static"
|
||||
},
|
||||
|
@ -785,7 +795,8 @@
|
|||
config :pleroma, :mrf,
|
||||
policies: [Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy, Pleroma.Web.ActivityPub.MRF.TagPolicy],
|
||||
transparency: true,
|
||||
transparency_exclusions: []
|
||||
transparency_exclusions: [],
|
||||
transparency_obfuscate_domains: []
|
||||
|
||||
config :ex_aws, http_client: Pleroma.HTTP.ExAws
|
||||
|
||||
|
@ -833,6 +844,19 @@
|
|||
}
|
||||
}
|
||||
|
||||
config :pleroma, :translator,
|
||||
enabled: false,
|
||||
module: Pleroma.Akkoma.Translators.DeepL
|
||||
|
||||
config :pleroma, :deepl,
|
||||
# either :free or :pro
|
||||
tier: :free,
|
||||
api_key: ""
|
||||
|
||||
config :pleroma, :libre_translate,
|
||||
url: "http://127.0.0.1:5000",
|
||||
api_key: nil
|
||||
|
||||
# Import environment specific config. This must remain at the bottom
|
||||
# of this file so it overrides the configuration defined above.
|
||||
import_config "#{Mix.env()}.exs"
|
||||
|
|
|
@ -509,6 +509,16 @@
|
|||
"Pleroma"
|
||||
]
|
||||
},
|
||||
%{
|
||||
key: :languages,
|
||||
type: {:list, :string},
|
||||
description: "Languages the instance uses",
|
||||
suggestions: [
|
||||
"en",
|
||||
"ja",
|
||||
"fr"
|
||||
]
|
||||
},
|
||||
%{
|
||||
key: :email,
|
||||
label: "Admin Email Address",
|
||||
|
@ -1169,7 +1179,6 @@
|
|||
hideFilteredStatuses: false,
|
||||
hideMutedPosts: false,
|
||||
hidePostStats: false,
|
||||
hideSitename: false,
|
||||
hideUserStats: false,
|
||||
loginMethod: "password",
|
||||
logo: "/static/logo.svg",
|
||||
|
@ -1235,12 +1244,6 @@
|
|||
type: :boolean,
|
||||
description: "Hide notices statistics (repeats, favorites, ...)"
|
||||
},
|
||||
%{
|
||||
key: :hideSitename,
|
||||
label: "Hide Sitename",
|
||||
type: :boolean,
|
||||
description: "Hides instance name from PleromaFE banner"
|
||||
},
|
||||
%{
|
||||
key: :hideUserStats,
|
||||
label: "Hide user stats",
|
||||
|
@ -1350,6 +1353,42 @@
|
|||
type: :string,
|
||||
description: "Which theme to use. Available themes are defined in styles.json",
|
||||
suggestions: ["pleroma-dark"]
|
||||
},
|
||||
%{
|
||||
key: :showPanelNavShortcuts,
|
||||
label: "Show timeline panel nav shortcuts",
|
||||
type: :boolean,
|
||||
description: "Whether to put timeline nav tabs on the top of the panel"
|
||||
},
|
||||
%{
|
||||
key: :showNavShortcuts,
|
||||
label: "Show navbar shortcuts",
|
||||
type: :boolean,
|
||||
description: "Whether to put extra navigation options on the navbar"
|
||||
},
|
||||
%{
|
||||
key: :showWiderShortcuts,
|
||||
label: "Increase navbar shortcut spacing",
|
||||
type: :boolean,
|
||||
description: "Whether to add extra space between navbar icons"
|
||||
},
|
||||
%{
|
||||
key: :hideSiteFavicon,
|
||||
label: "Hide site favicon",
|
||||
type: :boolean,
|
||||
description: "Whether to hide the instance favicon from the navbar"
|
||||
},
|
||||
%{
|
||||
key: :hideSiteName,
|
||||
label: "Hide site name",
|
||||
type: :boolean,
|
||||
description: "Whether to hide the site name from the navbar"
|
||||
},
|
||||
%{
|
||||
key: :renderMisskeyMarkdown,
|
||||
label: "Render misskey markdown",
|
||||
type: :boolean,
|
||||
description: "Whether to render Misskey-flavoured markdown"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1448,7 +1487,8 @@
|
|||
%{
|
||||
key: :background_color,
|
||||
type: :string,
|
||||
description: "Describe the background color of the app - this is only used for mastodon-fe",
|
||||
description:
|
||||
"Describe the background color of the app - this is only used for mastodon-fe",
|
||||
suggestions: ["#191b22", "aliceblue"]
|
||||
}
|
||||
]
|
||||
|
@ -2597,9 +2637,10 @@
|
|||
%{
|
||||
key: :proxy_url,
|
||||
label: "Proxy URL",
|
||||
type: [:string, :tuple],
|
||||
description: "Proxy URL",
|
||||
suggestions: ["localhost:9020", {:socks5, :localhost, 3090}]
|
||||
type: :string,
|
||||
description:
|
||||
"Proxy URL - of the format http://host:port. Advise setting in .exs instead of admin-fe due to this being set at boot-time.",
|
||||
suggestions: ["http://localhost:3128"]
|
||||
},
|
||||
%{
|
||||
key: :user_agent,
|
||||
|
@ -3185,13 +3226,14 @@
|
|||
group: :pleroma,
|
||||
key: Pleroma.Search,
|
||||
type: :group,
|
||||
label: "Search",
|
||||
description: "General search settings.",
|
||||
children: [
|
||||
%{
|
||||
key: :module,
|
||||
type: :keyword,
|
||||
type: :module,
|
||||
description: "Selected search module.",
|
||||
suggestion: [Pleroma.Search.DatabaseSearch, Pleroma.Search.Meilisearch]
|
||||
suggestions: {:list_behaviour_implementations, Pleroma.Search.SearchBackend}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -3216,7 +3258,7 @@
|
|||
},
|
||||
%{
|
||||
key: :initial_indexing_chunk_size,
|
||||
type: :int,
|
||||
type: :integer,
|
||||
description:
|
||||
"Amount of posts in a batch when running the initial indexing operation. Should probably not be more than 100000" <>
|
||||
" since there's a limit on maximum insert size",
|
||||
|
@ -3227,6 +3269,7 @@
|
|||
%{
|
||||
group: :pleroma,
|
||||
key: Pleroma.Search.Elasticsearch.Cluster,
|
||||
label: "Elasticsearch",
|
||||
type: :group,
|
||||
description: "Elasticsearch settings.",
|
||||
children: [
|
||||
|
@ -3293,13 +3336,13 @@
|
|||
},
|
||||
%{
|
||||
key: :bulk_page_size,
|
||||
type: :int,
|
||||
type: :integer,
|
||||
description: "Size for bulk put requests, mostly used on building the index",
|
||||
suggestion: [5000]
|
||||
},
|
||||
%{
|
||||
key: :bulk_wait_interval,
|
||||
type: :int,
|
||||
type: :integer,
|
||||
description: "Time to wait between bulk put requests (in ms)",
|
||||
suggestion: [15_000]
|
||||
}
|
||||
|
@ -3308,5 +3351,66 @@
|
|||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
group: :pleroma,
|
||||
key: :translator,
|
||||
type: :group,
|
||||
description: "Translation Settings",
|
||||
children: [
|
||||
%{
|
||||
key: :enabled,
|
||||
type: :boolean,
|
||||
description: "Is translation enabled?",
|
||||
suggestion: [true, false]
|
||||
},
|
||||
%{
|
||||
key: :module,
|
||||
type: :module,
|
||||
description: "Translation module.",
|
||||
suggestions: {:list_behaviour_implementations, Pleroma.Akkoma.Translator}
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
group: :pleroma,
|
||||
key: :deepl,
|
||||
label: "DeepL",
|
||||
type: :group,
|
||||
description: "DeepL Settings.",
|
||||
children: [
|
||||
%{
|
||||
key: :tier,
|
||||
type: {:dropdown, :atom},
|
||||
description: "API Tier",
|
||||
suggestions: [:free, :pro]
|
||||
},
|
||||
%{
|
||||
key: :api_key,
|
||||
type: :string,
|
||||
description: "API key for DeepL",
|
||||
suggestions: [nil]
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
group: :pleroma,
|
||||
key: :libre_translate,
|
||||
type: :group,
|
||||
description: "LibreTranslate Settings.",
|
||||
children: [
|
||||
%{
|
||||
key: :url,
|
||||
type: :string,
|
||||
description: "URL for libretranslate",
|
||||
suggestion: [nil]
|
||||
},
|
||||
%{
|
||||
key: :api_key,
|
||||
type: :string,
|
||||
description: "API key for libretranslate",
|
||||
suggestion: [nil]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
firefox, /emoji/Firefox.gif, Gif,Fun
|
||||
blank, /emoji/blank.png, Fun
|
||||
dinosaur, /emoji/dino walking.gif, Gif
|
||||
100a, /emoji/100a.png, Fun
|
|
@ -14,6 +14,10 @@ su akkoma -s $SHELL -lc "./bin/pleroma_ctl update"
|
|||
su akkoma -s $SHELL -lc "./bin/pleroma_ctl migrate"
|
||||
```
|
||||
|
||||
If you selected an alternate flavour on installation,
|
||||
you _may_ need to specify `--flavour`, in the same way as
|
||||
[when installing](../../installation/otp_en#detecting-flavour).
|
||||
|
||||
## For from source installations (using git)
|
||||
|
||||
1. Go to the working directory of Akkoma (default is `/opt/akkoma`)
|
||||
|
|
|
@ -120,6 +120,7 @@ To add configuration to your config file, you can copy it from the base config.
|
|||
* `Pleroma.Web.ActivityPub.MRF.KeywordPolicy`: Rejects or removes from the federated timeline or replaces keywords. (See [`:mrf_keyword`](#mrf_keyword)).
|
||||
* `transparency`: Make the content of your Message Rewrite Facility settings public (via nodeinfo).
|
||||
* `transparency_exclusions`: Exclude specific instance names from MRF transparency. The use of the exclusions feature will be disclosed in nodeinfo as a boolean value.
|
||||
* `transparency_obfuscate_domains`: Show domains with `*` in the middle, to censor them if needed. For example, `ridingho.me` will show as `rid*****.me`
|
||||
|
||||
## Federation
|
||||
### MRF policies
|
||||
|
@ -283,14 +284,19 @@ config :pleroma, :frontends,
|
|||
"name" => "swagger-ui",
|
||||
"ref" => "stable",
|
||||
"enabled" => true
|
||||
},
|
||||
mastodon: %{
|
||||
"name" => "mastodon-fe",
|
||||
"ref" => "akkoma"
|
||||
}
|
||||
```
|
||||
|
||||
* `:primary` - The frontend that will be served at `/`
|
||||
* `:admin` - The frontend that will be served at `/pleroma/admin`
|
||||
* `:swagger` - Config for developers to act as an API reference to be served at `/akkoma/swaggerui/` (trailing slash _needed_). Disabled by default.
|
||||
* `:mastodon` - The mastodon-fe configuration. This shouldn't need to be changed. This is served at `/web` when installed.
|
||||
|
||||
### :static_fe
|
||||
### :static\_fe
|
||||
|
||||
Render profiles and posts using server-generated HTML that is viewable without using JavaScript.
|
||||
|
||||
|
@ -516,7 +522,7 @@ Available caches:
|
|||
|
||||
### :http
|
||||
|
||||
* `proxy_url`: an upstream proxy to fetch posts and/or media with, (default: `nil`)
|
||||
* `proxy_url`: an upstream proxy to fetch posts and/or media with, (default: `nil`); for example `http://127.0.0.1:3192`. Does not support SOCKS5 proxy, only http(s).
|
||||
* `send_user_agent`: should we include a user agent with HTTP requests? (default: `true`)
|
||||
* `user_agent`: what user agent should we use? (default: `:default`), must be string or `:default`
|
||||
* `adapter`: array of adapter options
|
||||
|
@ -1153,3 +1159,28 @@ Each job has these settings:
|
|||
|
||||
* `:max_running` - max concurrently runnings jobs
|
||||
* `:max_waiting` - max waiting jobs
|
||||
|
||||
### Translation Settings
|
||||
|
||||
Settings to automatically translate statuses for end users. Currently supported
|
||||
translation services are DeepL and LibreTranslate.
|
||||
|
||||
Translations are available at `/api/v1/statuses/:id/translations/:language`, where
|
||||
`language` is the target language code (e.g `en`)
|
||||
|
||||
### `:translator`
|
||||
|
||||
- `:enabled` - enables translation
|
||||
- `:module` - Sets module to be used
|
||||
- Either `Pleroma.Akkoma.Translators.DeepL` or `Pleroma.Akkoma.Translators.LibreTranslate`
|
||||
|
||||
### `:deepl`
|
||||
|
||||
- `:api_key` - API key for DeepL
|
||||
- `:tier` - API tier
|
||||
- either `:free` or `:pro`
|
||||
|
||||
### `:libre_translate`
|
||||
|
||||
- `:url` - URL of LibreTranslate instance
|
||||
- `:api_key` - API key for LibreTranslate
|
||||
|
|
|
@ -19,6 +19,10 @@ config :pleroma, :frontends,
|
|||
admin: %{
|
||||
"name" => "admin-fe",
|
||||
"ref" => "stable"
|
||||
},
|
||||
mastodon: %{
|
||||
"name" => "mastodon-fe",
|
||||
"ref" => "akkoma"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -26,12 +30,18 @@ This would serve the frontend from the the folder at `$instance_static/frontends
|
|||
|
||||
Refer to [the frontend CLI task](../../administration/CLI_tasks/frontend) for how to install the frontend's files
|
||||
|
||||
If you wish masto-fe to also be enabled, you will also need to run the install task for `mastodon-fe`. Not doing this will lead to the frontend not working.
|
||||
|
||||
If you choose not to install a frontend for whatever reason, it is recommended that you enable [`:static_fe`](#static_fe) to allow remote users to click "view remote source". Don't bother with this if you've got no unauthenticated access though.
|
||||
|
||||
You can also replace the default "no frontend" page by placing an `index.html` file under your `instance/static/` directory.
|
||||
|
||||
## Mastodon-FE
|
||||
|
||||
Akkoma supports both [glitchsoc](https://github.com/glitch-soc/mastodon)'s more "vanilla" mastodon frontend,
|
||||
as well as [fedibird](https://github.com/fedibird/mastodon)'s extended frontend which has near-feature-parity with akkoma (with quoting and reactions).
|
||||
|
||||
To enable either one, you must run the `frontend.install` task for either `mastodon-fe` or `fedibird-fe` (both `--ref akkoma`), then make sure
|
||||
`:pleroma, :frontends, :mastodon` references the one you want.
|
||||
|
||||
## Swagger (openAPI) documentation viewer
|
||||
|
||||
If you're a developer and you'd like a human-readable rendering of the
|
||||
|
|
|
@ -21,7 +21,7 @@ This will only save the theme for you personally. To make it available to the wh
|
|||
|
||||
### Upload the theme to the server
|
||||
|
||||
Themes can be found in the [static directory](static_dir.md). Create `STATIC-DIR/static/themes/` if needed and copy your theme there. Next you need to add an entry for your theme to `STATIC-DIR/static/styles.json`. If you use a from source installation, you'll first need to copy the file from `priv/static/static/styles.json`.
|
||||
Themes can be found in the [static directory](static_dir.md). Create `STATIC-DIR/static/themes/` if needed and copy your theme there. Next you need to add an entry for your theme to `STATIC-DIR/static/styles.json`. If you use a from source installation, you'll first need to copy the file from `STATIC-DIR/frontends/pleroma-fe/REF/static/styles.json` (where `REF` is `stable` or `develop` depending on which ref you decided to install).
|
||||
|
||||
Example of `styles.json` where we add our own `my-awesome-theme.json`
|
||||
```json
|
||||
|
|
|
@ -14,11 +14,12 @@ apt -yq install tor
|
|||
|
||||
**WARNING:** Onion instances not using a Tor version supporting V3 addresses will not be able to federate with you.
|
||||
|
||||
Create the hidden service for your Akkoma instance in `/etc/tor/torrc`:
|
||||
Create the hidden service for your Akkoma instance in `/etc/tor/torrc`, with an HTTP tunnel:
|
||||
```
|
||||
HiddenServiceDir /var/lib/tor/akkoma_hidden_service/
|
||||
HiddenServicePort 80 127.0.0.1:8099
|
||||
HiddenServiceVersion 3 # Remove if Tor version is below 0.3 ( tor --version )
|
||||
HTTPTunnelPort 9080
|
||||
```
|
||||
Restart Tor to generate an adress:
|
||||
```
|
||||
|
@ -35,7 +36,7 @@ Next, edit your Akkoma config.
|
|||
If running in prod, navigate to your Akkoma directory, edit `config/prod.secret.exs`
|
||||
and append this line:
|
||||
```
|
||||
config :pleroma, :http, proxy_url: {:socks5, :localhost, 9050}
|
||||
config :pleroma, :http, proxy_url: "http://localhost:9080"
|
||||
```
|
||||
In your Akkoma directory, assuming you're running prod,
|
||||
run the following:
|
||||
|
|
|
@ -141,8 +141,7 @@ You then need to set the URL and authentication credentials if relevant.
|
|||
|
||||
### Initial indexing
|
||||
|
||||
After setting up the configuration, you'll want to index all of your already existsing posts. Only public posts are indexed. You'll only
|
||||
have to do it one time, but it might take a while, depending on the amount of posts your instance has seen.
|
||||
After setting up the configuration, you'll want to index all of your already existsing posts. You'll only have to do it one time, but it might take a while, depending on the amount of posts your instance has seen.
|
||||
|
||||
The sequence of actions is as follows:
|
||||
|
||||
|
|
|
@ -40,6 +40,10 @@ Has these additional fields under the `pleroma` object:
|
|||
- `parent_visible`: If the parent of this post is visible to the user or not.
|
||||
- `pinned_at`: a datetime (iso8601) when status was pinned, `null` otherwise.
|
||||
|
||||
The `GET /api/v1/statuses/:id/source` endpoint additionally has the following attributes:
|
||||
|
||||
- `content_type`: The content type of the status source.
|
||||
|
||||
## Scheduled statuses
|
||||
|
||||
Has these additional fields in `params`:
|
||||
|
|
|
@ -7,6 +7,20 @@ It actually consists of two components: a backend, named simply Akkoma, and a us
|
|||
It's part of what we call the fediverse, a federated network of instances which speak common protocols and can communicate with each other.
|
||||
One account on an instance is enough to talk to the entire fediverse!
|
||||
|
||||
## Community Channels
|
||||
|
||||
### IRC
|
||||
|
||||
For support or general questions, pop over to #akkoma and #akkoma-dev at [irc.akkoma.dev](https://irc.akkoma.dev) (port 6697, SSL)
|
||||
|
||||
### Discourse
|
||||
|
||||
For more general meta-discussion, for example discussion of potential future features, head on over to [meta.akkoma.dev](https://meta.akkoma.dev)
|
||||
|
||||
### Dev diaries and release notifications
|
||||
|
||||
will be posted via [@akkoma@ihba](https://ihatebeinga.live/users/akkoma)
|
||||
|
||||
## How can I use it?
|
||||
|
||||
Akkoma instances are already widely deployed, a list can be found at <https://the-federation.info/pleroma> and <https://fediverse.network/pleroma>.
|
||||
|
@ -26,3 +40,4 @@ Just add a "/web" after your instance url (e.g. <https://pleroma.soykaf.com/web>
|
|||
The Mastodon interface is from the Glitch-soc fork. For more information on the Mastodon interface you can check the [Mastodon](https://docs.joinmastodon.org/) and [Glitch-soc](https://glitch-soc.github.io/docs/) documentation.
|
||||
|
||||
Remember, what you see is only the frontend part of Mastodon, the backend is still Akkoma.
|
||||
|
||||
|
|
|
@ -221,6 +221,8 @@ If your instance is up and running, you can create your first user with administ
|
|||
doas -u akkoma env MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
|
||||
```
|
||||
|
||||
{! installation/frontends.include !}
|
||||
|
||||
#### Further reading
|
||||
|
||||
{! installation/further_reading.include !}
|
||||
|
|
|
@ -212,6 +212,8 @@ If your instance is up and running, you can create your first user with administ
|
|||
sudo -Hu akkoma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
|
||||
```
|
||||
|
||||
{! installation/frontends.include !}
|
||||
|
||||
#### Further reading
|
||||
|
||||
{! installation/further_reading.include !}
|
||||
|
|
|
@ -175,6 +175,8 @@ If your instance is up and running, you can create your first user with administ
|
|||
sudo -Hu akkoma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
|
||||
```
|
||||
|
||||
{! installation/frontends.include !}
|
||||
|
||||
#### Further reading
|
||||
|
||||
{! installation/further_reading.include !}
|
||||
|
|
|
@ -199,6 +199,8 @@ If your instance is up and running, you can create your first user with administ
|
|||
sudo -Hu akkoma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
|
||||
```
|
||||
|
||||
{! installation/frontends.include !}
|
||||
|
||||
#### Further reading
|
||||
|
||||
{! installation/further_reading.include !}
|
||||
|
|
|
@ -206,6 +206,9 @@ If your instance is up and running, you can create your first user with administ
|
|||
```shell
|
||||
sudo -Hu akkoma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
|
||||
```
|
||||
|
||||
{! installation/frontends.include !}
|
||||
|
||||
## Conclusion
|
||||
|
||||
Restart nginx with `# service nginx restart` and you should be up and running.
|
||||
|
|
25
docs/docs/installation/frontends.include
Normal file
25
docs/docs/installation/frontends.include
Normal file
|
@ -0,0 +1,25 @@
|
|||
#### Installing Frontends
|
||||
|
||||
Once your backend server is functional, you'll also want to
|
||||
probably install frontends.
|
||||
|
||||
These are no longer bundled with the distribution and need an extra
|
||||
command to install.
|
||||
|
||||
For most installations, the following will suffice:
|
||||
|
||||
=== "OTP"
|
||||
```sh
|
||||
./bin/pleroma_ctl frontend install pleroma-fe --ref stable
|
||||
# and also, if desired
|
||||
./bin/pleroma_ctl frontend install admin-fe --ref stable
|
||||
```
|
||||
|
||||
=== "From Source"
|
||||
```sh
|
||||
mix pleroma.frontend install pleroma-fe --ref stable
|
||||
mix pleroma.frontend install admin-fe --ref stable
|
||||
```
|
||||
|
||||
For more customised installations, refer to [Frontend Management](../../configuration/frontend_management)
|
||||
|
|
@ -293,6 +293,8 @@ akkoma$ MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
|
|||
|
||||
If you opted to allow sudo for the `akkoma` user but would like to remove the ability for greater security, now might be a good time to edit `/etc/sudoers` and/or change the groups the `akkoma` user belongs to. Be sure to restart the akkoma service afterwards to ensure it picks up on the changes.
|
||||
|
||||
{! installation/frontends.include !}
|
||||
|
||||
#### Further reading
|
||||
|
||||
{! installation/further_reading.include !}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
# Migrating to Akkoma
|
||||
|
||||
**Akkoma does not currently have a stable release, until 3.0, all builds should be considered "develop"**
|
||||
|
||||
## Why should you migrate?
|
||||
|
||||
aside from actually responsive maintainer(s)? let's lookie here, we've got:
|
||||
|
@ -11,6 +9,8 @@ aside from actually responsive maintainer(s)? let's lookie here, we've got:
|
|||
- elasticsearch support (because pleroma search is GARBAGE)
|
||||
- latest develop pleroma-fe additions
|
||||
- local-only posting
|
||||
- automatic post translation
|
||||
- the mastodon frontend back in all its glory
|
||||
- probably more, this is like 3.5 years of IHBA additions finally compiled
|
||||
|
||||
## Actually migrating
|
||||
|
@ -43,14 +43,14 @@ This will just be setting the update URL - find your flavour from the [mapping o
|
|||
```bash
|
||||
export FLAVOUR=[the flavour you found above]
|
||||
|
||||
./bin/pleroma_ctl update --zip-url https://akkoma-updates.s3-website.fr-par.scw.cloud/develop/akkoma-$FLAVOUR.zip
|
||||
./bin/pleroma_ctl update --zip-url https://akkoma-updates.s3-website.fr-par.scw.cloud/stable/akkoma-$FLAVOUR.zip
|
||||
./bin/pleroma_ctl migrate
|
||||
```
|
||||
|
||||
Then restart. When updating in the future, you canjust use
|
||||
|
||||
```bash
|
||||
./bin/pleroma_ctl update --branch develop
|
||||
./bin/pleroma_ctl update --branch stable
|
||||
```
|
||||
|
||||
## Frontend changes
|
||||
|
@ -62,17 +62,18 @@ your upgrade path here depends on your setup
|
|||
|
||||
You'll need to run a couple of commands,
|
||||
|
||||
```bash
|
||||
# From source
|
||||
mix pleroma.frontend install pleroma-fe
|
||||
# you'll probably want this too
|
||||
mix pleroma.frontend install admin-fe
|
||||
=== "OTP"
|
||||
```sh
|
||||
./bin/pleroma_ctl frontend install pleroma-fe --ref stable
|
||||
# and also, if desired
|
||||
./bin/pleroma_ctl frontend install admin-fe --ref stable
|
||||
```
|
||||
|
||||
# OTP
|
||||
./bin/pleroma_ctl frontend install pleroma-fe
|
||||
# you'll probably want this too
|
||||
./bin/pleroma_ctl frontend install admin-fe
|
||||
```
|
||||
=== "From Source"
|
||||
```sh
|
||||
mix pleroma.frontend install pleroma-fe --ref stable
|
||||
mix pleroma.frontend install admin-fe --ref stable
|
||||
```
|
||||
|
||||
### I've run the mix task to install a frontend
|
||||
|
||||
|
|
|
@ -202,6 +202,8 @@ incorrect timestamps. You should have ntpd running.
|
|||
|
||||
* <https://catgirl.science>
|
||||
|
||||
{! installation/frontends.include !}
|
||||
|
||||
#### Further reading
|
||||
|
||||
{! installation/further_reading.include !}
|
||||
|
|
|
@ -250,6 +250,8 @@ If your instance is up and running, you can create your first user with administ
|
|||
LC_ALL=en_US.UTF-8 MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
|
||||
```
|
||||
|
||||
{! installation/frontends.include !}
|
||||
|
||||
#### Further reading
|
||||
|
||||
{! installation/further_reading.include !}
|
||||
|
|
|
@ -19,12 +19,12 @@ This is a little more complex than it used to be (thanks ubuntu)
|
|||
|
||||
Use the following mapping to figure out your flavour:
|
||||
|
||||
| distribution | flavour |
|
||||
| ------------- | ------------ |
|
||||
| debian stable | amd64 |
|
||||
| ubuntu focal | amd64 |
|
||||
| ubuntu jammy | ubuntu-jammy |
|
||||
| alpine | amd64-musl |
|
||||
| distribution | flavour | available branches |
|
||||
| ------------- | ------------------ | ------------------- |
|
||||
| debian stable | amd64 | develop, stable |
|
||||
| ubuntu focal | amd64 | develop, stable |
|
||||
| ubuntu jammy | amd64-ubuntu-jammy | develop, stable |
|
||||
| alpine | amd64-musl | stable |
|
||||
|
||||
Other similar distributions will _probably_ work, but if it is not listed above, there is no official
|
||||
support.
|
||||
|
@ -306,6 +306,8 @@ su akkoma -s $SHELL -lc "./bin/pleroma_ctl user new joeuser joeuser@sld.tld --ad
|
|||
```
|
||||
This will create an account withe the username of 'joeuser' with the email address of joeuser@sld.tld, and set that user's account as an admin. This will result in a link that you can paste into the browser, which logs you in and enables you to set the password.
|
||||
|
||||
{! installation/frontends.include !}
|
||||
|
||||
## Further reading
|
||||
|
||||
{! installation/further_reading.include !}
|
||||
|
|
|
@ -279,6 +279,7 @@ After that, run the `pleroma_ctl migrate` command as usual to perform database m
|
|||
|
||||
As it currently stands, your OTP build will only be compatible for the specific RedHat distribution you've built it on. Fedora builds only work on Fedora, Centos builds only on Centos, RedHat builds only on RedHat. Secondly, for Fedora, they will also be bound to the specific Fedora release. This is because different releases of Fedora may have significant changes made in some of the required packages and libraries.
|
||||
|
||||
{! installation/frontends.include !}
|
||||
|
||||
{! installation/further_reading.include !}
|
||||
|
||||
|
|
66
docs/docs/installation/verifying_otp_releases.md
Normal file
66
docs/docs/installation/verifying_otp_releases.md
Normal file
|
@ -0,0 +1,66 @@
|
|||
# Verifying OTP release integrity
|
||||
|
||||
All stable OTP releases are cryptographically signed, to allow
|
||||
you to verify the integrity if you choose to.
|
||||
|
||||
Releases are signed with [Signify](https://man.openbsd.org/signify.1),
|
||||
with [the public key in the main repository](https://akkoma.dev/AkkomaGang/akkoma/src/branch/develop/SIGNING_KEY.pub)
|
||||
|
||||
Release URLs will always be of the form
|
||||
|
||||
```
|
||||
https://akkoma-updates.s3-website.fr-par.scw.cloud/{branch}/akkoma-{flavour}.zip
|
||||
```
|
||||
|
||||
Where branch is usually `stable` or `develop`, and `flavour` is
|
||||
the one [that you detect on install](../otp_en/#detecting-flavour).
|
||||
|
||||
So, for an AMD64 stable install, your update URL will be
|
||||
|
||||
```
|
||||
https://akkoma-updates.s3-website.fr-par.scw.cloud/stable/akkoma-amd64.zip
|
||||
```
|
||||
|
||||
To verify the integrity of this file, we have two helper files
|
||||
|
||||
```
|
||||
# Checksums
|
||||
https://akkoma-updates.s3-website.fr-par.scw.cloud/{branch}/akkoma-{flavour}.zip.sha256
|
||||
|
||||
# Signify signature of the hashes
|
||||
https://akkoma-updates.s3-website.fr-par.scw.cloud/{branch}/akkoma-{flavour}.zip.sha256.sig
|
||||
```
|
||||
|
||||
Thus, to upgrade manually, with integrity checking, consider the following script:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
set -eo pipefail
|
||||
|
||||
export FLAVOUR=amd64
|
||||
export BRANCH=stable
|
||||
|
||||
# Fetch signing key
|
||||
curl --silent https://akkoma.dev/AkkomaGang/akkoma/raw/branch/$BRANCH/SIGNING_KEY.pub -o AKKOMA_SIGNING_KEY.pub
|
||||
|
||||
# Download zip file and sig files
|
||||
wget -q https://akkoma-updates.s3-website.fr-par.scw.cloud/$BRANCH/akkoma-$FLAVOUR{.zip,.zip.sha256,.zip.sha256.sig}
|
||||
|
||||
# Verify zip file's sha256 integrity
|
||||
sha256sum --check akkoma-$FLAVOUR.zip.sha256
|
||||
|
||||
# Verify hash file's integrity
|
||||
# Signify might be under the `signify` command, depending on your distribution
|
||||
signify-openbsd -V -p AKKOMA_SIGNING_KEY.pub -m akkoma-$FLAVOUR.zip.sha256
|
||||
|
||||
# We're good, use that URL
|
||||
echo "Update URL contents verified"
|
||||
echo "use"
|
||||
echo "./bin/pleroma_ctl update --zip-url https://akkoma-updates.s3-website.fr-par.scw.cloud/$BRANCH/akkoma-$FLAVOUR"
|
||||
echo "to update your instance"
|
||||
|
||||
# Clean up
|
||||
rm akkoma-$FLAVOUR.zip
|
||||
rm akkoma-$FLAVOUR.zip.sha256
|
||||
rm akkoma-$FLAVOUR.zip.sha256.sig
|
||||
```
|
|
@ -23,7 +23,15 @@ def start_pleroma do
|
|||
Pleroma.Config.Oban.warn()
|
||||
Pleroma.Application.limiters_setup()
|
||||
Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
|
||||
Finch.start_link(name: MyFinch)
|
||||
|
||||
proxy_url = Pleroma.Config.get([:http, :proxy_url])
|
||||
proxy = Pleroma.HTTP.AdapterHelper.format_proxy(proxy_url)
|
||||
|
||||
finch_config =
|
||||
[:http, :adapter]
|
||||
|> Pleroma.Config.get([])
|
||||
|> Pleroma.HTTP.AdapterHelper.maybe_add_proxy_pool(proxy)
|
||||
|> Keyword.put(:name, MyFinch)
|
||||
|
||||
unless System.get_env("DEBUG") do
|
||||
Logger.remove_backend(:console)
|
||||
|
@ -45,6 +53,7 @@ def start_pleroma do
|
|||
Pleroma.Emoji,
|
||||
{Pleroma.Config.TransferTask, false},
|
||||
Pleroma.Web.Endpoint,
|
||||
{Finch, finch_config},
|
||||
{Oban, oban_config},
|
||||
{Majic.Pool,
|
||||
[name: Pleroma.MajicPool, pool_size: Pleroma.Config.get([:majic_pool, :size], 2)]}
|
||||
|
|
|
@ -9,7 +9,7 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
|
|||
import Ecto.Query
|
||||
|
||||
import Pleroma.Search.Meilisearch,
|
||||
only: [meili_post: 2, meili_put: 2, meili_get: 1, meili_delete!: 1]
|
||||
only: [meili_put: 2, meili_get: 1, meili_delete!: 1]
|
||||
|
||||
def run(["index"]) do
|
||||
start_pleroma()
|
||||
|
@ -27,7 +27,7 @@ def run(["index"]) do
|
|||
end
|
||||
|
||||
{:ok, _} =
|
||||
meili_post(
|
||||
meili_put(
|
||||
"/indexes/objects/settings/ranking-rules",
|
||||
[
|
||||
"published:desc",
|
||||
|
@ -41,7 +41,7 @@ def run(["index"]) do
|
|||
)
|
||||
|
||||
{:ok, _} =
|
||||
meili_post(
|
||||
meili_put(
|
||||
"/indexes/objects/settings/searchable-attributes",
|
||||
[
|
||||
"content"
|
||||
|
@ -91,7 +91,7 @@ def run(["index"]) do
|
|||
)
|
||||
|
||||
with {:ok, res} <- result do
|
||||
if not Map.has_key?(res, "uid") do
|
||||
if not Map.has_key?(res, "indexUid") do
|
||||
IO.puts("\nFailed to index: #{inspect(result)}")
|
||||
end
|
||||
else
|
||||
|
|
|
@ -258,6 +258,25 @@ def run(["untag", nickname | tags]) do
|
|||
end
|
||||
end
|
||||
|
||||
def run(["refetch_public_keys"]) do
|
||||
start_pleroma()
|
||||
|
||||
Pleroma.User.Query.build(%{
|
||||
external: true,
|
||||
is_active: true
|
||||
})
|
||||
|> refetch_public_keys()
|
||||
end
|
||||
|
||||
def run(["refetch_public_keys" | rest]) do
|
||||
start_pleroma()
|
||||
|
||||
Pleroma.User.Query.build(%{
|
||||
ap_id: rest
|
||||
})
|
||||
|> refetch_public_keys()
|
||||
end
|
||||
|
||||
def run(["invite" | rest]) do
|
||||
{options, [], []} =
|
||||
OptionParser.parse(rest,
|
||||
|
@ -519,6 +538,26 @@ def run(["fix_follow_state", local_user, remote_user]) do
|
|||
end
|
||||
end
|
||||
|
||||
defp refetch_public_keys(query) do
|
||||
query
|
||||
|> Pleroma.Repo.chunk_stream(50, :batches)
|
||||
|> Stream.each(fn users ->
|
||||
users
|
||||
|> Enum.each(fn user ->
|
||||
IO.puts("Re-Resolving: #{user.ap_id}")
|
||||
|
||||
with {:ok, user} <- Pleroma.User.fetch_by_ap_id(user.ap_id),
|
||||
changeset <- Pleroma.User.update_changeset(user),
|
||||
{:ok, _user} <- Pleroma.User.update_and_set_cache(changeset) do
|
||||
:ok
|
||||
else
|
||||
error -> IO.puts("Could not resolve: #{user.ap_id}, #{inspect(error)}")
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|> Stream.run()
|
||||
end
|
||||
|
||||
defp set_moderator(user, value) do
|
||||
{:ok, user} =
|
||||
user
|
||||
|
|
|
@ -8,6 +8,40 @@ defmodule Pleroma.Activity.HTML do
|
|||
|
||||
@cachex Pleroma.Config.get([:cachex, :provider], Cachex)
|
||||
|
||||
# We store a list of cache keys related to an activity in a
|
||||
# separate cache, scrubber_management_cache. It has the same
|
||||
# size as scrubber_cache (see application.ex). Every time we add
|
||||
# a cache to scrubber_cache, we update scrubber_management_cache.
|
||||
#
|
||||
# The most recent write of a certain key in the management cache
|
||||
# is the same as the most recent write of any record related to that
|
||||
# key in the main cache.
|
||||
# Assuming LRW ( https://hexdocs.pm/cachex/Cachex.Policy.LRW.html ),
|
||||
# this means when the management cache is evicted by cachex, all
|
||||
# related records in the main cache will also have been evicted.
|
||||
|
||||
defp get_cache_keys_for(activity_id) do
|
||||
with {:ok, list} when is_list(list) <- @cachex.get(:scrubber_management_cache, activity_id) do
|
||||
list
|
||||
else
|
||||
_ -> []
|
||||
end
|
||||
end
|
||||
|
||||
defp add_cache_key_for(activity_id, additional_key) do
|
||||
current = get_cache_keys_for(activity_id)
|
||||
|
||||
unless additional_key in current do
|
||||
@cachex.put(:scrubber_management_cache, activity_id, [additional_key | current])
|
||||
end
|
||||
end
|
||||
|
||||
def invalidate_cache_for(activity_id) do
|
||||
keys = get_cache_keys_for(activity_id)
|
||||
Enum.map(keys, &@cachex.del(:scrubber_cache, &1))
|
||||
@cachex.del(:scrubber_management_cache, activity_id)
|
||||
end
|
||||
|
||||
def get_cached_scrubbed_html_for_activity(
|
||||
content,
|
||||
scrubbers,
|
||||
|
@ -19,6 +53,8 @@ def get_cached_scrubbed_html_for_activity(
|
|||
|
||||
@cachex.fetch!(:scrubber_cache, key, fn _key ->
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
add_cache_key_for(activity.id, key)
|
||||
HTML.ensure_scrubbed_html(content, scrubbers, object.data["fake"] || false, callback)
|
||||
end)
|
||||
end
|
||||
|
|
100
lib/pleroma/akkoma/translators/deepl.ex
Normal file
100
lib/pleroma/akkoma/translators/deepl.ex
Normal file
|
@ -0,0 +1,100 @@
|
|||
defmodule Pleroma.Akkoma.Translators.DeepL do
|
||||
@behaviour Pleroma.Akkoma.Translator
|
||||
|
||||
alias Pleroma.HTTP
|
||||
alias Pleroma.Config
|
||||
require Logger
|
||||
|
||||
defp base_url(:free) do
|
||||
"https://api-free.deepl.com/v2/"
|
||||
end
|
||||
|
||||
defp base_url(:pro) do
|
||||
"https://api.deepl.com/v2/"
|
||||
end
|
||||
|
||||
defp api_key do
|
||||
Config.get([:deepl, :api_key])
|
||||
end
|
||||
|
||||
defp tier do
|
||||
Config.get([:deepl, :tier])
|
||||
end
|
||||
|
||||
@impl Pleroma.Akkoma.Translator
|
||||
def languages do
|
||||
with {:ok, %{status: 200} = source_response} <- do_languages("source"),
|
||||
{:ok, %{status: 200} = dest_response} <- do_languages("target"),
|
||||
{:ok, source_body} <- Jason.decode(source_response.body),
|
||||
{:ok, dest_body} <- Jason.decode(dest_response.body) do
|
||||
source_resp =
|
||||
Enum.map(source_body, fn %{"language" => code, "name" => name} ->
|
||||
%{code: code, name: name}
|
||||
end)
|
||||
|
||||
dest_resp =
|
||||
Enum.map(dest_body, fn %{"language" => code, "name" => name} ->
|
||||
%{code: code, name: name}
|
||||
end)
|
||||
|
||||
{:ok, source_resp, dest_resp}
|
||||
else
|
||||
{:ok, %{status: status} = response} ->
|
||||
Logger.warning("DeepL: Request rejected: #{inspect(response)}")
|
||||
{:error, "DeepL request failed (code #{status})"}
|
||||
|
||||
{:error, reason} ->
|
||||
{:error, reason}
|
||||
end
|
||||
end
|
||||
|
||||
@impl Pleroma.Akkoma.Translator
|
||||
def translate(string, from_language, to_language) do
|
||||
with {:ok, %{status: 200} = response} <-
|
||||
do_request(api_key(), tier(), string, from_language, to_language),
|
||||
{:ok, body} <- Jason.decode(response.body) do
|
||||
%{"translations" => [%{"text" => translated, "detected_source_language" => detected}]} =
|
||||
body
|
||||
|
||||
{:ok, detected, translated}
|
||||
else
|
||||
{:ok, %{status: status} = response} ->
|
||||
Logger.warning("DeepL: Request rejected: #{inspect(response)}")
|
||||
{:error, "DeepL request failed (code #{status})"}
|
||||
|
||||
{:error, reason} ->
|
||||
{:error, reason}
|
||||
end
|
||||
end
|
||||
|
||||
defp do_request(api_key, tier, string, from_language, to_language) do
|
||||
HTTP.post(
|
||||
base_url(tier) <> "translate",
|
||||
URI.encode_query(
|
||||
%{
|
||||
text: string,
|
||||
target_lang: to_language,
|
||||
tag_handling: "html"
|
||||
}
|
||||
|> maybe_add_source(from_language),
|
||||
:rfc3986
|
||||
),
|
||||
[
|
||||
{"authorization", "DeepL-Auth-Key #{api_key}"},
|
||||
{"content-type", "application/x-www-form-urlencoded"}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
defp maybe_add_source(opts, nil), do: opts
|
||||
defp maybe_add_source(opts, lang), do: Map.put(opts, :source_lang, lang)
|
||||
|
||||
defp do_languages(type) do
|
||||
HTTP.get(
|
||||
base_url(tier()) <> "languages?type=#{type}",
|
||||
[
|
||||
{"authorization", "DeepL-Auth-Key #{api_key()}"}
|
||||
]
|
||||
)
|
||||
end
|
||||
end
|
82
lib/pleroma/akkoma/translators/libre_translate.ex
Normal file
82
lib/pleroma/akkoma/translators/libre_translate.ex
Normal file
|
@ -0,0 +1,82 @@
|
|||
defmodule Pleroma.Akkoma.Translators.LibreTranslate do
|
||||
@behaviour Pleroma.Akkoma.Translator
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.HTTP
|
||||
require Logger
|
||||
|
||||
defp api_key do
|
||||
Config.get([:libre_translate, :api_key])
|
||||
end
|
||||
|
||||
defp url do
|
||||
Config.get([:libre_translate, :url])
|
||||
end
|
||||
|
||||
@impl Pleroma.Akkoma.Translator
|
||||
def languages do
|
||||
with {:ok, %{status: 200} = response} <- do_languages(),
|
||||
{:ok, body} <- Jason.decode(response.body) do
|
||||
resp = Enum.map(body, fn %{"code" => code, "name" => name} -> %{code: code, name: name} end)
|
||||
# No separate source/dest
|
||||
{:ok, resp, resp}
|
||||
else
|
||||
{:ok, %{status: status} = response} ->
|
||||
Logger.warning("LibreTranslate: Request rejected: #{inspect(response)}")
|
||||
{:error, "LibreTranslate request failed (code #{status})"}
|
||||
|
||||
{:error, reason} ->
|
||||
{:error, reason}
|
||||
end
|
||||
end
|
||||
|
||||
@impl Pleroma.Akkoma.Translator
|
||||
def translate(string, from_language, to_language) do
|
||||
with {:ok, %{status: 200} = response} <- do_request(string, from_language, to_language),
|
||||
{:ok, body} <- Jason.decode(response.body) do
|
||||
%{"translatedText" => translated} = body
|
||||
|
||||
detected =
|
||||
if Map.has_key?(body, "detectedLanguage") do
|
||||
get_in(body, ["detectedLanguage", "language"])
|
||||
else
|
||||
from_language
|
||||
end
|
||||
|
||||
{:ok, detected, translated}
|
||||
else
|
||||
{:ok, %{status: status} = response} ->
|
||||
Logger.warning("libre_translate: request failed, #{inspect(response)}")
|
||||
{:error, "libre_translate: request failed (code #{status})"}
|
||||
|
||||
{:error, reason} ->
|
||||
{:error, reason}
|
||||
end
|
||||
end
|
||||
|
||||
defp do_request(string, from_language, to_language) do
|
||||
url = URI.parse(url())
|
||||
url = %{url | path: "/translate"}
|
||||
|
||||
HTTP.post(
|
||||
to_string(url),
|
||||
Jason.encode!(%{
|
||||
q: string,
|
||||
source: if(is_nil(from_language), do: "auto", else: from_language),
|
||||
target: to_language,
|
||||
format: "html",
|
||||
api_key: api_key()
|
||||
}),
|
||||
[
|
||||
{"content-type", "application/json"}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
defp do_languages() do
|
||||
url = URI.parse(url())
|
||||
url = %{url | path: "/languages"}
|
||||
|
||||
HTTP.get(to_string(url))
|
||||
end
|
||||
end
|
8
lib/pleroma/akkoma/translators/translator.ex
Normal file
8
lib/pleroma/akkoma/translators/translator.ex
Normal file
|
@ -0,0 +1,8 @@
|
|||
defmodule Pleroma.Akkoma.Translator do
|
||||
@callback translate(String.t(), String.t() | nil, String.t()) ::
|
||||
{:ok, String.t(), String.t()} | {:error, any()}
|
||||
@callback languages() ::
|
||||
{:ok, [%{name: String.t(), code: String.t()}],
|
||||
[%{name: String.t(), code: String.t()}]}
|
||||
| {:error, any()}
|
||||
end
|
|
@ -63,7 +63,8 @@ def start(_type, _args) do
|
|||
Pleroma.Repo,
|
||||
Config.TransferTask,
|
||||
Pleroma.Emoji,
|
||||
Pleroma.Web.Plugs.RateLimiter.Supervisor
|
||||
Pleroma.Web.Plugs.RateLimiter.Supervisor,
|
||||
{Task.Supervisor, name: Pleroma.TaskSupervisor}
|
||||
] ++
|
||||
cachex_children() ++
|
||||
http_children() ++
|
||||
|
@ -149,11 +150,13 @@ defp cachex_children do
|
|||
build_cachex("object", default_ttl: 25_000, ttl_interval: 1000, limit: 2500),
|
||||
build_cachex("rich_media", default_ttl: :timer.minutes(120), limit: 5000),
|
||||
build_cachex("scrubber", limit: 2500),
|
||||
build_cachex("scrubber_management", limit: 2500),
|
||||
build_cachex("idempotency", expiration: idempotency_expiration(), limit: 2500),
|
||||
build_cachex("web_resp", limit: 2500),
|
||||
build_cachex("emoji_packs", expiration: emoji_packs_expiration(), limit: 10),
|
||||
build_cachex("failed_proxy_url", limit: 2500),
|
||||
build_cachex("banned_urls", default_ttl: :timer.hours(24 * 30), limit: 5_000)
|
||||
build_cachex("banned_urls", default_ttl: :timer.hours(24 * 30), limit: 5_000),
|
||||
build_cachex("translations", default_ttl: :timer.hours(24 * 30), limit: 2500)
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -248,9 +251,13 @@ def limiters_setup do
|
|||
end
|
||||
|
||||
defp http_children do
|
||||
proxy_url = Config.get([:http, :proxy_url])
|
||||
proxy = Pleroma.HTTP.AdapterHelper.format_proxy(proxy_url)
|
||||
|
||||
config =
|
||||
[:http, :adapter]
|
||||
|> Config.get([])
|
||||
|> Pleroma.HTTP.AdapterHelper.maybe_add_proxy_pool(proxy)
|
||||
|> Keyword.put(:name, MyFinch)
|
||||
|
||||
[{Finch, config}]
|
||||
|
|
|
@ -11,10 +11,7 @@ defmodule Akkoma.Collections.Fetcher do
|
|||
alias Pleroma.Config
|
||||
require Logger
|
||||
|
||||
def fetch_collection_by_ap_id(ap_id) when is_binary(ap_id) do
|
||||
fetch_collection(ap_id)
|
||||
end
|
||||
|
||||
@spec fetch_collection(String.t() | map()) :: {:ok, [Pleroma.Object.t()]} | {:error, any()}
|
||||
def fetch_collection(ap_id) when is_binary(ap_id) do
|
||||
with {:ok, page} <- Fetcher.fetch_and_contain_remote_object_from_id(ap_id) do
|
||||
{:ok, objects_from_collection(page)}
|
||||
|
@ -26,7 +23,7 @@ def fetch_collection(ap_id) when is_binary(ap_id) do
|
|||
end
|
||||
|
||||
def fetch_collection(%{"type" => type} = page)
|
||||
when type in ["Collection", "OrderedCollection"] do
|
||||
when type in ["Collection", "OrderedCollection", "CollectionPage", "OrderedCollectionPage"] do
|
||||
{:ok, objects_from_collection(page)}
|
||||
end
|
||||
|
||||
|
@ -38,12 +35,13 @@ defp items_in_page(%{"type" => type, "items" => items})
|
|||
when is_list(items) and type in ["Collection", "CollectionPage"],
|
||||
do: items
|
||||
|
||||
defp objects_from_collection(%{"type" => "OrderedCollection", "orderedItems" => items})
|
||||
when is_list(items),
|
||||
do: items
|
||||
defp objects_from_collection(%{"type" => type, "orderedItems" => items} = page)
|
||||
when is_list(items) and type in ["OrderedCollection", "OrderedCollectionPage"],
|
||||
do: maybe_next_page(page, items)
|
||||
|
||||
defp objects_from_collection(%{"type" => "Collection", "items" => items}) when is_list(items),
|
||||
do: items
|
||||
defp objects_from_collection(%{"type" => type, "items" => items} = page)
|
||||
when is_list(items) and type in ["Collection", "CollectionPage"],
|
||||
do: maybe_next_page(page, items)
|
||||
|
||||
defp objects_from_collection(%{"type" => type, "first" => first})
|
||||
when is_binary(first) and type in ["Collection", "OrderedCollection"] do
|
||||
|
@ -55,11 +53,13 @@ defp objects_from_collection(%{"type" => type, "first" => %{"id" => id}})
|
|||
fetch_page_items(id)
|
||||
end
|
||||
|
||||
defp objects_from_collection(_page), do: []
|
||||
|
||||
defp fetch_page_items(id, items \\ []) do
|
||||
if Enum.count(items) >= Config.get([:activitypub, :max_collection_objects]) do
|
||||
items
|
||||
else
|
||||
{:ok, page} = Fetcher.fetch_and_contain_remote_object_from_id(id)
|
||||
with {:ok, page} <- Fetcher.fetch_and_contain_remote_object_from_id(id) do
|
||||
objects = items_in_page(page)
|
||||
|
||||
if Enum.count(objects) > 0 do
|
||||
|
@ -67,6 +67,14 @@ defp fetch_page_items(id, items \\ []) do
|
|||
else
|
||||
items
|
||||
end
|
||||
else
|
||||
{:error, "Object has been deleted"} ->
|
||||
items
|
||||
|
||||
{:error, error} ->
|
||||
Logger.error("Could not fetch page #{id} - #{inspect(error)}")
|
||||
{:error, error}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ def start_link(restart_pleroma? \\ true) do
|
|||
def load_and_update_env(deleted_settings \\ [], restart_pleroma? \\ true) do
|
||||
with {_, true} <- {:configurable, Config.get(:configurable_from_database)} do
|
||||
# We need to restart applications for loaded settings take effect
|
||||
|
||||
{logger, other} =
|
||||
(Repo.all(ConfigDB) ++ deleted_settings)
|
||||
|> Enum.map(&merge_with_default/1)
|
||||
|
@ -85,7 +84,12 @@ defp maybe_set_pleroma_last(apps) do
|
|||
end
|
||||
|
||||
defp merge_with_default(%{group: group, key: key, value: value} = setting) do
|
||||
default = Config.Holder.default_config(group, key)
|
||||
default =
|
||||
if group == :pleroma do
|
||||
Config.get([key], Config.Holder.default_config(group, key))
|
||||
else
|
||||
Config.Holder.default_config(group, key)
|
||||
end
|
||||
|
||||
merged =
|
||||
cond do
|
||||
|
|
|
@ -27,4 +27,40 @@ defmodule Pleroma.Constants do
|
|||
do:
|
||||
~w(index.html robots.txt static static-fe finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc embed.js embed.css)
|
||||
)
|
||||
|
||||
const(status_updatable_fields,
|
||||
do: [
|
||||
"source",
|
||||
"tag",
|
||||
"updated",
|
||||
"emoji",
|
||||
"content",
|
||||
"summary",
|
||||
"sensitive",
|
||||
"attachment",
|
||||
"generator"
|
||||
]
|
||||
)
|
||||
|
||||
const(updatable_object_types,
|
||||
do: [
|
||||
"Note",
|
||||
"Question",
|
||||
"Audio",
|
||||
"Video",
|
||||
"Event",
|
||||
"Article",
|
||||
"Page"
|
||||
]
|
||||
)
|
||||
|
||||
const(actor_types,
|
||||
do: [
|
||||
"Application",
|
||||
"Group",
|
||||
"Organization",
|
||||
"Person",
|
||||
"Service"
|
||||
]
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
# emoji-test.txt
|
||||
# Date: 2021-08-26, 17:22:23 GMT
|
||||
# © 2021 Unicode®, Inc.
|
||||
# Date: 2022-08-12, 20:24:39 GMT
|
||||
# © 2022 Unicode®, Inc.
|
||||
# Unicode and the Unicode Logo are registered trademarks of Unicode, Inc. in the U.S. and other countries.
|
||||
# For terms of use, see http://www.unicode.org/terms_of_use.html
|
||||
# For terms of use, see https://www.unicode.org/terms_of_use.html
|
||||
#
|
||||
# Emoji Keyboard/Display Test Data for UTS #51
|
||||
# Version: 14.0
|
||||
# Version: 15.0
|
||||
#
|
||||
# For documentation and usage, see http://www.unicode.org/reports/tr51
|
||||
# For documentation and usage, see https://www.unicode.org/reports/tr51
|
||||
#
|
||||
# This file provides data for testing which emoji forms should be in keyboards and which should also be displayed/processed.
|
||||
# Format: code points; status # emoji name
|
||||
|
@ -92,6 +92,7 @@
|
|||
1F62C ; fully-qualified # 😬 E1.0 grimacing face
|
||||
1F62E 200D 1F4A8 ; fully-qualified # 😮💨 E13.1 face exhaling
|
||||
1F925 ; fully-qualified # 🤥 E3.0 lying face
|
||||
1FAE8 ; fully-qualified # 🫨 E15.0 shaking face
|
||||
|
||||
# subgroup: face-sleepy
|
||||
1F60C ; fully-qualified # 😌 E0.6 relieved face
|
||||
|
@ -155,7 +156,7 @@
|
|||
|
||||
# subgroup: face-negative
|
||||
1F624 ; fully-qualified # 😤 E0.6 face with steam from nose
|
||||
1F621 ; fully-qualified # 😡 E0.6 pouting face
|
||||
1F621 ; fully-qualified # 😡 E0.6 enraged face
|
||||
1F620 ; fully-qualified # 😠 E0.6 angry face
|
||||
1F92C ; fully-qualified # 🤬 E5.0 face with symbols on mouth
|
||||
1F608 ; fully-qualified # 😈 E1.0 smiling face with horns
|
||||
|
@ -190,8 +191,7 @@
|
|||
1F649 ; fully-qualified # 🙉 E0.6 hear-no-evil monkey
|
||||
1F64A ; fully-qualified # 🙊 E0.6 speak-no-evil monkey
|
||||
|
||||
# subgroup: emotion
|
||||
1F48B ; fully-qualified # 💋 E0.6 kiss mark
|
||||
# subgroup: heart
|
||||
1F48C ; fully-qualified # 💌 E0.6 love letter
|
||||
1F498 ; fully-qualified # 💘 E0.6 heart with arrow
|
||||
1F49D ; fully-qualified # 💝 E0.6 heart with ribbon
|
||||
|
@ -210,14 +210,20 @@
|
|||
2764 200D 1FA79 ; unqualified # ❤🩹 E13.1 mending heart
|
||||
2764 FE0F ; fully-qualified # ❤️ E0.6 red heart
|
||||
2764 ; unqualified # ❤ E0.6 red heart
|
||||
1FA77 ; fully-qualified # 🩷 E15.0 pink heart
|
||||
1F9E1 ; fully-qualified # 🧡 E5.0 orange heart
|
||||
1F49B ; fully-qualified # 💛 E0.6 yellow heart
|
||||
1F49A ; fully-qualified # 💚 E0.6 green heart
|
||||
1F499 ; fully-qualified # 💙 E0.6 blue heart
|
||||
1FA75 ; fully-qualified # 🩵 E15.0 light blue heart
|
||||
1F49C ; fully-qualified # 💜 E0.6 purple heart
|
||||
1F90E ; fully-qualified # 🤎 E12.0 brown heart
|
||||
1F5A4 ; fully-qualified # 🖤 E3.0 black heart
|
||||
1FA76 ; fully-qualified # 🩶 E15.0 grey heart
|
||||
1F90D ; fully-qualified # 🤍 E12.0 white heart
|
||||
|
||||
# subgroup: emotion
|
||||
1F48B ; fully-qualified # 💋 E0.6 kiss mark
|
||||
1F4AF ; fully-qualified # 💯 E0.6 hundred points
|
||||
1F4A2 ; fully-qualified # 💢 E0.6 anger symbol
|
||||
1F4A5 ; fully-qualified # 💥 E0.6 collision
|
||||
|
@ -226,21 +232,20 @@
|
|||
1F4A8 ; fully-qualified # 💨 E0.6 dashing away
|
||||
1F573 FE0F ; fully-qualified # 🕳️ E0.7 hole
|
||||
1F573 ; unqualified # 🕳 E0.7 hole
|
||||
1F4A3 ; fully-qualified # 💣 E0.6 bomb
|
||||
1F4AC ; fully-qualified # 💬 E0.6 speech balloon
|
||||
1F441 FE0F 200D 1F5E8 FE0F ; fully-qualified # 👁️🗨️ E2.0 eye in speech bubble
|
||||
1F441 200D 1F5E8 FE0F ; unqualified # 👁🗨️ E2.0 eye in speech bubble
|
||||
1F441 FE0F 200D 1F5E8 ; unqualified # 👁️🗨 E2.0 eye in speech bubble
|
||||
1F441 FE0F 200D 1F5E8 ; minimally-qualified # 👁️🗨 E2.0 eye in speech bubble
|
||||
1F441 200D 1F5E8 ; unqualified # 👁🗨 E2.0 eye in speech bubble
|
||||
1F5E8 FE0F ; fully-qualified # 🗨️ E2.0 left speech bubble
|
||||
1F5E8 ; unqualified # 🗨 E2.0 left speech bubble
|
||||
1F5EF FE0F ; fully-qualified # 🗯️ E0.7 right anger bubble
|
||||
1F5EF ; unqualified # 🗯 E0.7 right anger bubble
|
||||
1F4AD ; fully-qualified # 💭 E1.0 thought balloon
|
||||
1F4A4 ; fully-qualified # 💤 E0.6 zzz
|
||||
1F4A4 ; fully-qualified # 💤 E0.6 ZZZ
|
||||
|
||||
# Smileys & Emotion subtotal: 177
|
||||
# Smileys & Emotion subtotal: 177 w/o modifiers
|
||||
# Smileys & Emotion subtotal: 180
|
||||
# Smileys & Emotion subtotal: 180 w/o modifiers
|
||||
|
||||
# group: People & Body
|
||||
|
||||
|
@ -300,6 +305,18 @@
|
|||
1FAF4 1F3FD ; fully-qualified # 🫴🏽 E14.0 palm up hand: medium skin tone
|
||||
1FAF4 1F3FE ; fully-qualified # 🫴🏾 E14.0 palm up hand: medium-dark skin tone
|
||||
1FAF4 1F3FF ; fully-qualified # 🫴🏿 E14.0 palm up hand: dark skin tone
|
||||
1FAF7 ; fully-qualified # 🫷 E15.0 leftwards pushing hand
|
||||
1FAF7 1F3FB ; fully-qualified # 🫷🏻 E15.0 leftwards pushing hand: light skin tone
|
||||
1FAF7 1F3FC ; fully-qualified # 🫷🏼 E15.0 leftwards pushing hand: medium-light skin tone
|
||||
1FAF7 1F3FD ; fully-qualified # 🫷🏽 E15.0 leftwards pushing hand: medium skin tone
|
||||
1FAF7 1F3FE ; fully-qualified # 🫷🏾 E15.0 leftwards pushing hand: medium-dark skin tone
|
||||
1FAF7 1F3FF ; fully-qualified # 🫷🏿 E15.0 leftwards pushing hand: dark skin tone
|
||||
1FAF8 ; fully-qualified # 🫸 E15.0 rightwards pushing hand
|
||||
1FAF8 1F3FB ; fully-qualified # 🫸🏻 E15.0 rightwards pushing hand: light skin tone
|
||||
1FAF8 1F3FC ; fully-qualified # 🫸🏼 E15.0 rightwards pushing hand: medium-light skin tone
|
||||
1FAF8 1F3FD ; fully-qualified # 🫸🏽 E15.0 rightwards pushing hand: medium skin tone
|
||||
1FAF8 1F3FE ; fully-qualified # 🫸🏾 E15.0 rightwards pushing hand: medium-dark skin tone
|
||||
1FAF8 1F3FF ; fully-qualified # 🫸🏿 E15.0 rightwards pushing hand: dark skin tone
|
||||
|
||||
# subgroup: hand-fingers-partial
|
||||
1F44C ; fully-qualified # 👌 E0.6 OK hand
|
||||
|
@ -473,11 +490,11 @@
|
|||
1F932 1F3FE ; fully-qualified # 🤲🏾 E5.0 palms up together: medium-dark skin tone
|
||||
1F932 1F3FF ; fully-qualified # 🤲🏿 E5.0 palms up together: dark skin tone
|
||||
1F91D ; fully-qualified # 🤝 E3.0 handshake
|
||||
1F91D 1F3FB ; fully-qualified # 🤝🏻 E3.0 handshake: light skin tone
|
||||
1F91D 1F3FC ; fully-qualified # 🤝🏼 E3.0 handshake: medium-light skin tone
|
||||
1F91D 1F3FD ; fully-qualified # 🤝🏽 E3.0 handshake: medium skin tone
|
||||
1F91D 1F3FE ; fully-qualified # 🤝🏾 E3.0 handshake: medium-dark skin tone
|
||||
1F91D 1F3FF ; fully-qualified # 🤝🏿 E3.0 handshake: dark skin tone
|
||||
1F91D 1F3FB ; fully-qualified # 🤝🏻 E14.0 handshake: light skin tone
|
||||
1F91D 1F3FC ; fully-qualified # 🤝🏼 E14.0 handshake: medium-light skin tone
|
||||
1F91D 1F3FD ; fully-qualified # 🤝🏽 E14.0 handshake: medium skin tone
|
||||
1F91D 1F3FE ; fully-qualified # 🤝🏾 E14.0 handshake: medium-dark skin tone
|
||||
1F91D 1F3FF ; fully-qualified # 🤝🏿 E14.0 handshake: dark skin tone
|
||||
1FAF1 1F3FB 200D 1FAF2 1F3FC ; fully-qualified # 🫱🏻🫲🏼 E14.0 handshake: light skin tone, medium-light skin tone
|
||||
1FAF1 1F3FB 200D 1FAF2 1F3FD ; fully-qualified # 🫱🏻🫲🏽 E14.0 handshake: light skin tone, medium skin tone
|
||||
1FAF1 1F3FB 200D 1FAF2 1F3FE ; fully-qualified # 🫱🏻🫲🏾 E14.0 handshake: light skin tone, medium-dark skin tone
|
||||
|
@ -1455,7 +1472,7 @@
|
|||
1F575 1F3FF ; fully-qualified # 🕵🏿 E2.0 detective: dark skin tone
|
||||
1F575 FE0F 200D 2642 FE0F ; fully-qualified # 🕵️♂️ E4.0 man detective
|
||||
1F575 200D 2642 FE0F ; unqualified # 🕵♂️ E4.0 man detective
|
||||
1F575 FE0F 200D 2642 ; unqualified # 🕵️♂ E4.0 man detective
|
||||
1F575 FE0F 200D 2642 ; minimally-qualified # 🕵️♂ E4.0 man detective
|
||||
1F575 200D 2642 ; unqualified # 🕵♂ E4.0 man detective
|
||||
1F575 1F3FB 200D 2642 FE0F ; fully-qualified # 🕵🏻♂️ E4.0 man detective: light skin tone
|
||||
1F575 1F3FB 200D 2642 ; minimally-qualified # 🕵🏻♂ E4.0 man detective: light skin tone
|
||||
|
@ -1469,7 +1486,7 @@
|
|||
1F575 1F3FF 200D 2642 ; minimally-qualified # 🕵🏿♂ E4.0 man detective: dark skin tone
|
||||
1F575 FE0F 200D 2640 FE0F ; fully-qualified # 🕵️♀️ E4.0 woman detective
|
||||
1F575 200D 2640 FE0F ; unqualified # 🕵♀️ E4.0 woman detective
|
||||
1F575 FE0F 200D 2640 ; unqualified # 🕵️♀ E4.0 woman detective
|
||||
1F575 FE0F 200D 2640 ; minimally-qualified # 🕵️♀ E4.0 woman detective
|
||||
1F575 200D 2640 ; unqualified # 🕵♀ E4.0 woman detective
|
||||
1F575 1F3FB 200D 2640 FE0F ; fully-qualified # 🕵🏻♀️ E4.0 woman detective: light skin tone
|
||||
1F575 1F3FB 200D 2640 ; minimally-qualified # 🕵🏻♀ E4.0 woman detective: light skin tone
|
||||
|
@ -2302,7 +2319,7 @@
|
|||
1F3CC 1F3FF ; fully-qualified # 🏌🏿 E4.0 person golfing: dark skin tone
|
||||
1F3CC FE0F 200D 2642 FE0F ; fully-qualified # 🏌️♂️ E4.0 man golfing
|
||||
1F3CC 200D 2642 FE0F ; unqualified # 🏌♂️ E4.0 man golfing
|
||||
1F3CC FE0F 200D 2642 ; unqualified # 🏌️♂ E4.0 man golfing
|
||||
1F3CC FE0F 200D 2642 ; minimally-qualified # 🏌️♂ E4.0 man golfing
|
||||
1F3CC 200D 2642 ; unqualified # 🏌♂ E4.0 man golfing
|
||||
1F3CC 1F3FB 200D 2642 FE0F ; fully-qualified # 🏌🏻♂️ E4.0 man golfing: light skin tone
|
||||
1F3CC 1F3FB 200D 2642 ; minimally-qualified # 🏌🏻♂ E4.0 man golfing: light skin tone
|
||||
|
@ -2316,7 +2333,7 @@
|
|||
1F3CC 1F3FF 200D 2642 ; minimally-qualified # 🏌🏿♂ E4.0 man golfing: dark skin tone
|
||||
1F3CC FE0F 200D 2640 FE0F ; fully-qualified # 🏌️♀️ E4.0 woman golfing
|
||||
1F3CC 200D 2640 FE0F ; unqualified # 🏌♀️ E4.0 woman golfing
|
||||
1F3CC FE0F 200D 2640 ; unqualified # 🏌️♀ E4.0 woman golfing
|
||||
1F3CC FE0F 200D 2640 ; minimally-qualified # 🏌️♀ E4.0 woman golfing
|
||||
1F3CC 200D 2640 ; unqualified # 🏌♀ E4.0 woman golfing
|
||||
1F3CC 1F3FB 200D 2640 FE0F ; fully-qualified # 🏌🏻♀️ E4.0 woman golfing: light skin tone
|
||||
1F3CC 1F3FB 200D 2640 ; minimally-qualified # 🏌🏻♀ E4.0 woman golfing: light skin tone
|
||||
|
@ -2427,7 +2444,7 @@
|
|||
26F9 1F3FF ; fully-qualified # ⛹🏿 E2.0 person bouncing ball: dark skin tone
|
||||
26F9 FE0F 200D 2642 FE0F ; fully-qualified # ⛹️♂️ E4.0 man bouncing ball
|
||||
26F9 200D 2642 FE0F ; unqualified # ⛹♂️ E4.0 man bouncing ball
|
||||
26F9 FE0F 200D 2642 ; unqualified # ⛹️♂ E4.0 man bouncing ball
|
||||
26F9 FE0F 200D 2642 ; minimally-qualified # ⛹️♂ E4.0 man bouncing ball
|
||||
26F9 200D 2642 ; unqualified # ⛹♂ E4.0 man bouncing ball
|
||||
26F9 1F3FB 200D 2642 FE0F ; fully-qualified # ⛹🏻♂️ E4.0 man bouncing ball: light skin tone
|
||||
26F9 1F3FB 200D 2642 ; minimally-qualified # ⛹🏻♂ E4.0 man bouncing ball: light skin tone
|
||||
|
@ -2441,7 +2458,7 @@
|
|||
26F9 1F3FF 200D 2642 ; minimally-qualified # ⛹🏿♂ E4.0 man bouncing ball: dark skin tone
|
||||
26F9 FE0F 200D 2640 FE0F ; fully-qualified # ⛹️♀️ E4.0 woman bouncing ball
|
||||
26F9 200D 2640 FE0F ; unqualified # ⛹♀️ E4.0 woman bouncing ball
|
||||
26F9 FE0F 200D 2640 ; unqualified # ⛹️♀ E4.0 woman bouncing ball
|
||||
26F9 FE0F 200D 2640 ; minimally-qualified # ⛹️♀ E4.0 woman bouncing ball
|
||||
26F9 200D 2640 ; unqualified # ⛹♀ E4.0 woman bouncing ball
|
||||
26F9 1F3FB 200D 2640 FE0F ; fully-qualified # ⛹🏻♀️ E4.0 woman bouncing ball: light skin tone
|
||||
26F9 1F3FB 200D 2640 ; minimally-qualified # ⛹🏻♀ E4.0 woman bouncing ball: light skin tone
|
||||
|
@ -2462,7 +2479,7 @@
|
|||
1F3CB 1F3FF ; fully-qualified # 🏋🏿 E2.0 person lifting weights: dark skin tone
|
||||
1F3CB FE0F 200D 2642 FE0F ; fully-qualified # 🏋️♂️ E4.0 man lifting weights
|
||||
1F3CB 200D 2642 FE0F ; unqualified # 🏋♂️ E4.0 man lifting weights
|
||||
1F3CB FE0F 200D 2642 ; unqualified # 🏋️♂ E4.0 man lifting weights
|
||||
1F3CB FE0F 200D 2642 ; minimally-qualified # 🏋️♂ E4.0 man lifting weights
|
||||
1F3CB 200D 2642 ; unqualified # 🏋♂ E4.0 man lifting weights
|
||||
1F3CB 1F3FB 200D 2642 FE0F ; fully-qualified # 🏋🏻♂️ E4.0 man lifting weights: light skin tone
|
||||
1F3CB 1F3FB 200D 2642 ; minimally-qualified # 🏋🏻♂ E4.0 man lifting weights: light skin tone
|
||||
|
@ -2476,7 +2493,7 @@
|
|||
1F3CB 1F3FF 200D 2642 ; minimally-qualified # 🏋🏿♂ E4.0 man lifting weights: dark skin tone
|
||||
1F3CB FE0F 200D 2640 FE0F ; fully-qualified # 🏋️♀️ E4.0 woman lifting weights
|
||||
1F3CB 200D 2640 FE0F ; unqualified # 🏋♀️ E4.0 woman lifting weights
|
||||
1F3CB FE0F 200D 2640 ; unqualified # 🏋️♀ E4.0 woman lifting weights
|
||||
1F3CB FE0F 200D 2640 ; minimally-qualified # 🏋️♀ E4.0 woman lifting weights
|
||||
1F3CB 200D 2640 ; unqualified # 🏋♀ E4.0 woman lifting weights
|
||||
1F3CB 1F3FB 200D 2640 FE0F ; fully-qualified # 🏋🏻♀️ E4.0 woman lifting weights: light skin tone
|
||||
1F3CB 1F3FB 200D 2640 ; minimally-qualified # 🏋🏻♀ E4.0 woman lifting weights: light skin tone
|
||||
|
@ -3262,8 +3279,8 @@
|
|||
1FAC2 ; fully-qualified # 🫂 E13.0 people hugging
|
||||
1F463 ; fully-qualified # 👣 E0.6 footprints
|
||||
|
||||
# People & Body subtotal: 2986
|
||||
# People & Body subtotal: 506 w/o modifiers
|
||||
# People & Body subtotal: 2998
|
||||
# People & Body subtotal: 508 w/o modifiers
|
||||
|
||||
# group: Component
|
||||
|
||||
|
@ -3306,6 +3323,8 @@
|
|||
1F405 ; fully-qualified # 🐅 E1.0 tiger
|
||||
1F406 ; fully-qualified # 🐆 E1.0 leopard
|
||||
1F434 ; fully-qualified # 🐴 E0.6 horse face
|
||||
1FACE ; fully-qualified # 🫎 E15.0 moose
|
||||
1FACF ; fully-qualified # 🫏 E15.0 donkey
|
||||
1F40E ; fully-qualified # 🐎 E0.6 horse
|
||||
1F984 ; fully-qualified # 🦄 E1.0 unicorn
|
||||
1F993 ; fully-qualified # 🦓 E5.0 zebra
|
||||
|
@ -3373,6 +3392,9 @@
|
|||
1F9A9 ; fully-qualified # 🦩 E12.0 flamingo
|
||||
1F99A ; fully-qualified # 🦚 E11.0 peacock
|
||||
1F99C ; fully-qualified # 🦜 E11.0 parrot
|
||||
1FABD ; fully-qualified # 🪽 E15.0 wing
|
||||
1F426 200D 2B1B ; fully-qualified # 🐦⬛ E15.0 black bird
|
||||
1FABF ; fully-qualified # 🪿 E15.0 goose
|
||||
|
||||
# subgroup: animal-amphibian
|
||||
1F438 ; fully-qualified # 🐸 E0.6 frog
|
||||
|
@ -3399,6 +3421,7 @@
|
|||
1F419 ; fully-qualified # 🐙 E0.6 octopus
|
||||
1F41A ; fully-qualified # 🐚 E0.6 spiral shell
|
||||
1FAB8 ; fully-qualified # 🪸 E14.0 coral
|
||||
1FABC ; fully-qualified # 🪼 E15.0 jellyfish
|
||||
|
||||
# subgroup: animal-bug
|
||||
1F40C ; fully-qualified # 🐌 E0.6 snail
|
||||
|
@ -3433,6 +3456,7 @@
|
|||
1F33B ; fully-qualified # 🌻 E0.6 sunflower
|
||||
1F33C ; fully-qualified # 🌼 E0.6 blossom
|
||||
1F337 ; fully-qualified # 🌷 E0.6 tulip
|
||||
1FABB ; fully-qualified # 🪻 E15.0 hyacinth
|
||||
|
||||
# subgroup: plant-other
|
||||
1F331 ; fully-qualified # 🌱 E0.6 seedling
|
||||
|
@ -3451,9 +3475,10 @@
|
|||
1F343 ; fully-qualified # 🍃 E0.6 leaf fluttering in wind
|
||||
1FAB9 ; fully-qualified # 🪹 E14.0 empty nest
|
||||
1FABA ; fully-qualified # 🪺 E14.0 nest with eggs
|
||||
1F344 ; fully-qualified # 🍄 E0.6 mushroom
|
||||
|
||||
# Animals & Nature subtotal: 151
|
||||
# Animals & Nature subtotal: 151 w/o modifiers
|
||||
# Animals & Nature subtotal: 159
|
||||
# Animals & Nature subtotal: 159 w/o modifiers
|
||||
|
||||
# group: Food & Drink
|
||||
|
||||
|
@ -3492,10 +3517,11 @@
|
|||
1F966 ; fully-qualified # 🥦 E5.0 broccoli
|
||||
1F9C4 ; fully-qualified # 🧄 E12.0 garlic
|
||||
1F9C5 ; fully-qualified # 🧅 E12.0 onion
|
||||
1F344 ; fully-qualified # 🍄 E0.6 mushroom
|
||||
1F95C ; fully-qualified # 🥜 E3.0 peanuts
|
||||
1FAD8 ; fully-qualified # 🫘 E14.0 beans
|
||||
1F330 ; fully-qualified # 🌰 E0.6 chestnut
|
||||
1FADA ; fully-qualified # 🫚 E15.0 ginger root
|
||||
1FADB ; fully-qualified # 🫛 E15.0 pea pod
|
||||
|
||||
# subgroup: food-prepared
|
||||
1F35E ; fully-qualified # 🍞 E0.6 bread
|
||||
|
@ -3607,8 +3633,8 @@
|
|||
1FAD9 ; fully-qualified # 🫙 E14.0 jar
|
||||
1F3FA ; fully-qualified # 🏺 E1.0 amphora
|
||||
|
||||
# Food & Drink subtotal: 134
|
||||
# Food & Drink subtotal: 134 w/o modifiers
|
||||
# Food & Drink subtotal: 135
|
||||
# Food & Drink subtotal: 135 w/o modifiers
|
||||
|
||||
# group: Travel & Places
|
||||
|
||||
|
@ -3974,11 +4000,10 @@
|
|||
1F3AF ; fully-qualified # 🎯 E0.6 bullseye
|
||||
1FA80 ; fully-qualified # 🪀 E12.0 yo-yo
|
||||
1FA81 ; fully-qualified # 🪁 E12.0 kite
|
||||
1F52B ; fully-qualified # 🔫 E0.6 water pistol
|
||||
1F3B1 ; fully-qualified # 🎱 E0.6 pool 8 ball
|
||||
1F52E ; fully-qualified # 🔮 E0.6 crystal ball
|
||||
1FA84 ; fully-qualified # 🪄 E13.0 magic wand
|
||||
1F9FF ; fully-qualified # 🧿 E11.0 nazar amulet
|
||||
1FAAC ; fully-qualified # 🪬 E14.0 hamsa
|
||||
1F3AE ; fully-qualified # 🎮 E0.6 video game
|
||||
1F579 FE0F ; fully-qualified # 🕹️ E0.7 joystick
|
||||
1F579 ; unqualified # 🕹 E0.7 joystick
|
||||
|
@ -4013,8 +4038,8 @@
|
|||
1F9F6 ; fully-qualified # 🧶 E11.0 yarn
|
||||
1FAA2 ; fully-qualified # 🪢 E13.0 knot
|
||||
|
||||
# Activities subtotal: 97
|
||||
# Activities subtotal: 97 w/o modifiers
|
||||
# Activities subtotal: 96
|
||||
# Activities subtotal: 96 w/o modifiers
|
||||
|
||||
# group: Objects
|
||||
|
||||
|
@ -4040,6 +4065,7 @@
|
|||
1FA73 ; fully-qualified # 🩳 E12.0 shorts
|
||||
1F459 ; fully-qualified # 👙 E0.6 bikini
|
||||
1F45A ; fully-qualified # 👚 E0.6 woman’s clothes
|
||||
1FAAD ; fully-qualified # 🪭 E15.0 folding hand fan
|
||||
1F45B ; fully-qualified # 👛 E0.6 purse
|
||||
1F45C ; fully-qualified # 👜 E0.6 handbag
|
||||
1F45D ; fully-qualified # 👝 E0.6 clutch bag
|
||||
|
@ -4055,6 +4081,7 @@
|
|||
1F461 ; fully-qualified # 👡 E0.6 woman’s sandal
|
||||
1FA70 ; fully-qualified # 🩰 E12.0 ballet shoes
|
||||
1F462 ; fully-qualified # 👢 E0.6 woman’s boot
|
||||
1FAAE ; fully-qualified # 🪮 E15.0 hair pick
|
||||
1F451 ; fully-qualified # 👑 E0.6 crown
|
||||
1F452 ; fully-qualified # 👒 E0.6 woman’s hat
|
||||
1F3A9 ; fully-qualified # 🎩 E0.6 top hat
|
||||
|
@ -4103,6 +4130,8 @@
|
|||
1FA95 ; fully-qualified # 🪕 E12.0 banjo
|
||||
1F941 ; fully-qualified # 🥁 E3.0 drum
|
||||
1FA98 ; fully-qualified # 🪘 E13.0 long drum
|
||||
1FA87 ; fully-qualified # 🪇 E15.0 maracas
|
||||
1FA88 ; fully-qualified # 🪈 E15.0 flute
|
||||
|
||||
# subgroup: phone
|
||||
1F4F1 ; fully-qualified # 📱 E0.6 mobile phone
|
||||
|
@ -4275,7 +4304,7 @@
|
|||
1F5E1 ; unqualified # 🗡 E0.7 dagger
|
||||
2694 FE0F ; fully-qualified # ⚔️ E1.0 crossed swords
|
||||
2694 ; unqualified # ⚔ E1.0 crossed swords
|
||||
1F52B ; fully-qualified # 🔫 E0.6 water pistol
|
||||
1F4A3 ; fully-qualified # 💣 E0.6 bomb
|
||||
1FA83 ; fully-qualified # 🪃 E13.0 boomerang
|
||||
1F3F9 ; fully-qualified # 🏹 E1.0 bow and arrow
|
||||
1F6E1 FE0F ; fully-qualified # 🛡️ E0.7 shield
|
||||
|
@ -4354,12 +4383,14 @@
|
|||
1FAA6 ; fully-qualified # 🪦 E13.0 headstone
|
||||
26B1 FE0F ; fully-qualified # ⚱️ E1.0 funeral urn
|
||||
26B1 ; unqualified # ⚱ E1.0 funeral urn
|
||||
1F9FF ; fully-qualified # 🧿 E11.0 nazar amulet
|
||||
1FAAC ; fully-qualified # 🪬 E14.0 hamsa
|
||||
1F5FF ; fully-qualified # 🗿 E0.6 moai
|
||||
1FAA7 ; fully-qualified # 🪧 E13.0 placard
|
||||
1FAAA ; fully-qualified # 🪪 E14.0 identification card
|
||||
|
||||
# Objects subtotal: 304
|
||||
# Objects subtotal: 304 w/o modifiers
|
||||
# Objects subtotal: 310
|
||||
# Objects subtotal: 310 w/o modifiers
|
||||
|
||||
# group: Symbols
|
||||
|
||||
|
@ -4455,6 +4486,7 @@
|
|||
262E ; unqualified # ☮ E1.0 peace symbol
|
||||
1F54E ; fully-qualified # 🕎 E1.0 menorah
|
||||
1F52F ; fully-qualified # 🔯 E0.6 dotted six-pointed star
|
||||
1FAAF ; fully-qualified # 🪯 E15.0 khanda
|
||||
|
||||
# subgroup: zodiac
|
||||
2648 ; fully-qualified # ♈ E0.6 Aries
|
||||
|
@ -4503,6 +4535,7 @@
|
|||
1F505 ; fully-qualified # 🔅 E1.0 dim button
|
||||
1F506 ; fully-qualified # 🔆 E1.0 bright button
|
||||
1F4F6 ; fully-qualified # 📶 E0.6 antenna bars
|
||||
1F6DC ; fully-qualified # 🛜 E15.0 wireless
|
||||
1F4F3 ; fully-qualified # 📳 E0.6 vibration mode
|
||||
1F4F4 ; fully-qualified # 📴 E0.6 mobile phone off
|
||||
|
||||
|
@ -4693,8 +4726,8 @@
|
|||
1F533 ; fully-qualified # 🔳 E0.6 white square button
|
||||
1F532 ; fully-qualified # 🔲 E0.6 black square button
|
||||
|
||||
# Symbols subtotal: 302
|
||||
# Symbols subtotal: 302 w/o modifiers
|
||||
# Symbols subtotal: 304
|
||||
# Symbols subtotal: 304 w/o modifiers
|
||||
|
||||
# group: Flags
|
||||
|
||||
|
@ -4709,7 +4742,7 @@
|
|||
1F3F3 200D 1F308 ; unqualified # 🏳🌈 E4.0 rainbow flag
|
||||
1F3F3 FE0F 200D 26A7 FE0F ; fully-qualified # 🏳️⚧️ E13.0 transgender flag
|
||||
1F3F3 200D 26A7 FE0F ; unqualified # 🏳⚧️ E13.0 transgender flag
|
||||
1F3F3 FE0F 200D 26A7 ; unqualified # 🏳️⚧ E13.0 transgender flag
|
||||
1F3F3 FE0F 200D 26A7 ; minimally-qualified # 🏳️⚧ E13.0 transgender flag
|
||||
1F3F3 200D 26A7 ; unqualified # 🏳⚧ E13.0 transgender flag
|
||||
1F3F4 200D 2620 FE0F ; fully-qualified # 🏴☠️ E11.0 pirate flag
|
||||
1F3F4 200D 2620 ; minimally-qualified # 🏴☠ E11.0 pirate flag
|
||||
|
@ -4983,9 +5016,9 @@
|
|||
# Flags subtotal: 275 w/o modifiers
|
||||
|
||||
# Status Counts
|
||||
# fully-qualified : 3624
|
||||
# minimally-qualified : 817
|
||||
# unqualified : 252
|
||||
# fully-qualified : 3655
|
||||
# minimally-qualified : 827
|
||||
# unqualified : 242
|
||||
# component : 9
|
||||
|
||||
#EOF
|
||||
|
|
|
@ -188,6 +188,11 @@ def emoji_url(%{"type" => "EmojiReact", "content" => emoji, "tag" => tags}) do
|
|||
|
||||
def emoji_url(_), do: nil
|
||||
|
||||
def emoji_name_with_instance(name, url) do
|
||||
url = url |> URI.parse() |> Map.get(:host)
|
||||
"#{name}@#{url}"
|
||||
end
|
||||
|
||||
emoji_qualification_map =
|
||||
emojis
|
||||
|> Enum.filter(&String.contains?(&1, "\uFE0F"))
|
||||
|
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Helpers.AuthHelper do
|
|||
import Plug.Conn
|
||||
|
||||
@oauth_token_session_key :oauth_token
|
||||
@oauth_user_session_key :oauth_user
|
||||
|
||||
@doc """
|
||||
Skips OAuth permissions (scopes) checks, assigns nil `:token`.
|
||||
|
@ -43,4 +44,16 @@ def put_session_token(%Conn{} = conn, token) when is_binary(token) do
|
|||
def delete_session_token(%Conn{} = conn) do
|
||||
delete_session(conn, @oauth_token_session_key)
|
||||
end
|
||||
|
||||
def put_session_user(%Conn{} = conn, user) do
|
||||
put_session(conn, @oauth_user_session_key, user)
|
||||
end
|
||||
|
||||
def delete_session_user(%Conn{} = conn) do
|
||||
delete_session(conn, @oauth_user_session_key)
|
||||
end
|
||||
|
||||
def get_session_user(%Conn{} = conn) do
|
||||
get_session(conn, @oauth_user_session_key)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ defmodule Pleroma.HTTP.AdapterHelper do
|
|||
@moduledoc """
|
||||
Configure Tesla.Client with default and customized adapter options.
|
||||
"""
|
||||
@defaults [name: MyFinch, connect_timeout: 5_000, recv_timeout: 5_000]
|
||||
@defaults [name: MyFinch, pool_timeout: 5_000, receive_timeout: 5_000]
|
||||
|
||||
@type proxy_type() :: :socks4 | :socks5
|
||||
@type host() :: charlist() | :inet.ip_address()
|
||||
|
@ -25,15 +25,58 @@ def format_proxy(nil), do: nil
|
|||
|
||||
def format_proxy(proxy_url) do
|
||||
case parse_proxy(proxy_url) do
|
||||
{:ok, host, port} -> {host, port}
|
||||
{:ok, type, host, port} -> {type, host, port}
|
||||
{:ok, host, port} -> {:http, host, port, []}
|
||||
{:ok, type, host, port} -> {type, host, port, []}
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
@spec maybe_add_proxy(keyword(), proxy() | nil) :: keyword()
|
||||
def maybe_add_proxy(opts, nil), do: opts
|
||||
def maybe_add_proxy(opts, proxy), do: Keyword.put_new(opts, :proxy, proxy)
|
||||
|
||||
def maybe_add_proxy(opts, proxy) do
|
||||
Keyword.put(opts, :proxy, proxy)
|
||||
end
|
||||
|
||||
def maybe_add_proxy_pool(opts, nil), do: opts
|
||||
|
||||
def maybe_add_proxy_pool(opts, proxy) do
|
||||
Logger.info("Using HTTP Proxy: #{inspect(proxy)}")
|
||||
|
||||
opts
|
||||
|> maybe_add_pools()
|
||||
|> maybe_add_default_pool()
|
||||
|> maybe_add_conn_opts()
|
||||
|> put_in([:pools, :default, :conn_opts, :proxy], proxy)
|
||||
end
|
||||
|
||||
defp maybe_add_pools(opts) do
|
||||
if Keyword.has_key?(opts, :pools) do
|
||||
opts
|
||||
else
|
||||
Keyword.put(opts, :pools, %{})
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_add_default_pool(opts) do
|
||||
pools = Keyword.get(opts, :pools)
|
||||
|
||||
if Map.has_key?(pools, :default) do
|
||||
opts
|
||||
else
|
||||
put_in(opts, [:pools, :default], [])
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_add_conn_opts(opts) do
|
||||
conn_opts = get_in(opts, [:pools, :default, :conn_opts])
|
||||
|
||||
unless is_nil(conn_opts) do
|
||||
opts
|
||||
else
|
||||
put_in(opts, [:pools, :default, :conn_opts], [])
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Merge default connection & adapter options with received ones.
|
||||
|
@ -46,36 +89,31 @@ def options(%URI{} = uri, opts \\ []) do
|
|||
|> AdapterHelper.Default.options(uri)
|
||||
end
|
||||
|
||||
defp proxy_type("http"), do: {:ok, :http}
|
||||
defp proxy_type("https"), do: {:ok, :https}
|
||||
defp proxy_type(_), do: {:error, :unknown}
|
||||
|
||||
@spec parse_proxy(String.t() | tuple() | nil) ::
|
||||
{:ok, host(), pos_integer()}
|
||||
| {:ok, proxy_type(), host(), pos_integer()}
|
||||
| {:error, atom()}
|
||||
| nil
|
||||
|
||||
def parse_proxy(nil), do: nil
|
||||
|
||||
def parse_proxy(proxy) when is_binary(proxy) do
|
||||
with [host, port] <- String.split(proxy, ":"),
|
||||
{port, ""} <- Integer.parse(port) do
|
||||
{:ok, parse_host(host), port}
|
||||
with %URI{} = uri <- URI.parse(proxy),
|
||||
{:ok, type} <- proxy_type(uri.scheme) do
|
||||
{:ok, type, uri.host, uri.port}
|
||||
else
|
||||
{_, _} ->
|
||||
Logger.warn("Parsing port failed #{inspect(proxy)}")
|
||||
{:error, :invalid_proxy_port}
|
||||
|
||||
:error ->
|
||||
Logger.warn("Parsing port failed #{inspect(proxy)}")
|
||||
{:error, :invalid_proxy_port}
|
||||
|
||||
_ ->
|
||||
Logger.warn("Parsing proxy failed #{inspect(proxy)}")
|
||||
e ->
|
||||
Logger.warn("Parsing proxy failed #{inspect(proxy)}, #{inspect(e)}")
|
||||
{:error, :invalid_proxy}
|
||||
end
|
||||
end
|
||||
|
||||
def parse_proxy(proxy) when is_tuple(proxy) do
|
||||
with {type, host, port} <- proxy do
|
||||
{:ok, type, parse_host(host), port}
|
||||
{:ok, type, host, port}
|
||||
else
|
||||
_ ->
|
||||
Logger.warn("Parsing proxy failed #{inspect(proxy)}")
|
||||
|
|
|
@ -9,7 +9,7 @@ defmodule Pleroma.HTTP.AdapterHelper.Default do
|
|||
|
||||
@spec options(keyword(), URI.t()) :: keyword()
|
||||
def options(opts, _uri) do
|
||||
proxy = Pleroma.Config.get([:http, :proxy_url], nil)
|
||||
proxy = Pleroma.Config.get([:http, :proxy_url])
|
||||
AdapterHelper.maybe_add_proxy(opts, AdapterHelper.format_proxy(proxy))
|
||||
end
|
||||
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.HTTP.AdapterHelper.Gun do
|
||||
@behaviour Pleroma.HTTP.AdapterHelper
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.HTTP.AdapterHelper
|
||||
|
||||
require Logger
|
||||
|
||||
@defaults [
|
||||
retry: 1,
|
||||
retry_timeout: 1_000
|
||||
]
|
||||
|
||||
@type pool() :: :federation | :upload | :media | :default
|
||||
|
||||
@spec options(keyword(), URI.t()) :: keyword()
|
||||
def options(incoming_opts \\ [], %URI{} = uri) do
|
||||
proxy =
|
||||
[:http, :proxy_url]
|
||||
|> Config.get()
|
||||
|> AdapterHelper.format_proxy()
|
||||
|
||||
config_opts = Config.get([:http, :adapter], [])
|
||||
|
||||
@defaults
|
||||
|> Keyword.merge(config_opts)
|
||||
|> add_scheme_opts(uri)
|
||||
|> AdapterHelper.maybe_add_proxy(proxy)
|
||||
|> Keyword.merge(incoming_opts)
|
||||
|> put_timeout()
|
||||
end
|
||||
|
||||
defp add_scheme_opts(opts, %{scheme: "http"}), do: opts
|
||||
|
||||
defp add_scheme_opts(opts, %{scheme: "https"}) do
|
||||
Keyword.put(opts, :certificates_verification, true)
|
||||
end
|
||||
|
||||
defp put_timeout(opts) do
|
||||
{recv_timeout, opts} = Keyword.pop(opts, :recv_timeout, pool_timeout(opts[:pool]))
|
||||
# this is the timeout to receive a message from Gun
|
||||
# `:timeout` key is used in Tesla
|
||||
Keyword.put(opts, :timeout, recv_timeout)
|
||||
end
|
||||
|
||||
@spec pool_timeout(pool()) :: non_neg_integer()
|
||||
def pool_timeout(pool) do
|
||||
default = Config.get([:pools, :default, :recv_timeout], 5_000)
|
||||
|
||||
Config.get([:pools, pool, :recv_timeout], default)
|
||||
end
|
||||
|
||||
def limiter_setup do
|
||||
prefix = Pleroma.Gun.ConnectionPool
|
||||
wait = Config.get([:connections_pool, :connection_acquisition_wait])
|
||||
retries = Config.get([:connections_pool, :connection_acquisition_retries])
|
||||
|
||||
:pools
|
||||
|> Config.get([])
|
||||
|> Enum.each(fn {name, opts} ->
|
||||
max_running = Keyword.get(opts, :size, 50)
|
||||
max_waiting = Keyword.get(opts, :max_waiting, 10)
|
||||
|
||||
result =
|
||||
ConcurrentLimiter.new(:"#{prefix}.#{name}", max_running, max_waiting,
|
||||
wait: wait,
|
||||
max_retries: retries
|
||||
)
|
||||
|
||||
case result do
|
||||
:ok -> :ok
|
||||
{:error, :existing} -> :ok
|
||||
end
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.HTTP.AdapterHelper.Hackney do
|
||||
@behaviour Pleroma.HTTP.AdapterHelper
|
||||
|
||||
@defaults [
|
||||
follow_redirect: true,
|
||||
force_redirect: true
|
||||
]
|
||||
|
||||
@spec options(keyword(), URI.t()) :: keyword()
|
||||
def options(connection_opts \\ [], %URI{} = uri) do
|
||||
proxy = Pleroma.Config.get([:http, :proxy_url])
|
||||
|
||||
config_opts = Pleroma.Config.get([:http, :adapter], [])
|
||||
|
||||
@defaults
|
||||
|> Keyword.merge(config_opts)
|
||||
|> Keyword.merge(connection_opts)
|
||||
|> add_scheme_opts(uri)
|
||||
|> maybe_add_with_body()
|
||||
|> Pleroma.HTTP.AdapterHelper.maybe_add_proxy(proxy)
|
||||
end
|
||||
|
||||
defp add_scheme_opts(opts, %URI{scheme: "https"}) do
|
||||
Keyword.put(opts, :ssl_options, versions: [:"tlsv1.3", :"tlsv1.2", :"tlsv1.1", :tlsv1])
|
||||
end
|
||||
|
||||
defp add_scheme_opts(opts, _), do: opts
|
||||
|
||||
defp maybe_add_with_body(opts) do
|
||||
if opts[:max_body] do
|
||||
Keyword.put(opts, :with_body, true)
|
||||
else
|
||||
opts
|
||||
end
|
||||
end
|
||||
end
|
|
@ -384,7 +384,7 @@ def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = act
|
|||
end
|
||||
|
||||
def create_notifications(%Activity{data: %{"type" => type}} = activity, options)
|
||||
when type in ["Follow", "Like", "Announce", "Move", "EmojiReact", "Flag"] do
|
||||
when type in ["Follow", "Like", "Announce", "Move", "EmojiReact", "Flag", "Update"] do
|
||||
do_create_notifications(activity, options)
|
||||
end
|
||||
|
||||
|
@ -438,6 +438,9 @@ defp type_from_activity(%{data: %{"type" => type}} = activity) do
|
|||
activity
|
||||
|> type_from_activity_object()
|
||||
|
||||
"Update" ->
|
||||
"update"
|
||||
|
||||
t ->
|
||||
raise "No notification type for activity type #{t}"
|
||||
end
|
||||
|
@ -503,7 +506,16 @@ def create_poll_notifications(%Activity{} = activity) do
|
|||
def get_notified_from_activity(activity, local_only \\ true)
|
||||
|
||||
def get_notified_from_activity(%Activity{data: %{"type" => type}} = activity, local_only)
|
||||
when type in ["Create", "Like", "Announce", "Follow", "Move", "EmojiReact", "Flag"] do
|
||||
when type in [
|
||||
"Create",
|
||||
"Like",
|
||||
"Announce",
|
||||
"Follow",
|
||||
"Move",
|
||||
"EmojiReact",
|
||||
"Flag",
|
||||
"Update"
|
||||
] do
|
||||
potential_receiver_ap_ids = get_potential_receiver_ap_ids(activity)
|
||||
|
||||
potential_receivers =
|
||||
|
@ -543,6 +555,21 @@ def get_potential_receiver_ap_ids(%{data: %{"type" => "Flag", "actor" => actor}}
|
|||
(User.all_superusers() |> Enum.map(fn user -> user.ap_id end)) -- [actor]
|
||||
end
|
||||
|
||||
# Update activity: notify all who repeated this
|
||||
def get_potential_receiver_ap_ids(%{data: %{"type" => "Update", "actor" => actor}} = activity) do
|
||||
with %Object{data: %{"id" => object_id}} <- Object.normalize(activity, fetch: false) do
|
||||
repeaters =
|
||||
Activity.Queries.by_type("Announce")
|
||||
|> Activity.Queries.by_object_id(object_id)
|
||||
|> Activity.with_joined_user_actor()
|
||||
|> where([a, u], u.local)
|
||||
|> select([a, u], u.ap_id)
|
||||
|> Repo.all()
|
||||
|
||||
repeaters -- [actor]
|
||||
end
|
||||
end
|
||||
|
||||
def get_potential_receiver_ap_ids(activity) do
|
||||
[]
|
||||
|> Utils.maybe_notify_to_recipients(activity)
|
||||
|
|
|
@ -145,7 +145,7 @@ defp warn_on_no_object_preloaded(ap_id) do
|
|||
Logger.debug("Backtrace: #{inspect(Process.info(:erlang.self(), :current_stacktrace))}")
|
||||
end
|
||||
|
||||
def normalize(_, options \\ [fetch: false])
|
||||
def normalize(_, options \\ [fetch: false, id_only: false])
|
||||
|
||||
# If we pass an Activity to Object.normalize(), we can try to use the preloaded object.
|
||||
# Use this whenever possible, especially when walking graphs in an O(N) loop!
|
||||
|
@ -173,9 +173,14 @@ def normalize(%Activity{data: %{"object" => ap_id}}, options) do
|
|||
def normalize(%{"id" => ap_id}, options), do: normalize(ap_id, options)
|
||||
|
||||
def normalize(ap_id, options) when is_binary(ap_id) do
|
||||
if Keyword.get(options, :fetch) do
|
||||
cond do
|
||||
Keyword.get(options, :id_only) ->
|
||||
ap_id
|
||||
|
||||
Keyword.get(options, :fetch) ->
|
||||
Fetcher.fetch_object_from_id!(ap_id, options)
|
||||
else
|
||||
|
||||
true ->
|
||||
get_cached_by_ap_id(ap_id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,8 +26,42 @@ defp touch_changeset(changeset) do
|
|||
end
|
||||
|
||||
defp maybe_reinject_internal_fields(%{data: %{} = old_data}, new_data) do
|
||||
has_history? = fn
|
||||
%{"formerRepresentations" => %{"orderedItems" => list}} when is_list(list) -> true
|
||||
_ -> false
|
||||
end
|
||||
|
||||
internal_fields = Map.take(old_data, Pleroma.Constants.object_internal_fields())
|
||||
|
||||
remote_history_exists? = has_history?.(new_data)
|
||||
|
||||
# If the remote history exists, we treat that as the only source of truth.
|
||||
new_data =
|
||||
if has_history?.(old_data) and not remote_history_exists? do
|
||||
Map.put(new_data, "formerRepresentations", old_data["formerRepresentations"])
|
||||
else
|
||||
new_data
|
||||
end
|
||||
|
||||
# If the remote does not have history information, we need to manage it ourselves
|
||||
new_data =
|
||||
if not remote_history_exists? do
|
||||
changed? =
|
||||
Pleroma.Constants.status_updatable_fields()
|
||||
|> Enum.any?(fn field -> Map.get(old_data, field) != Map.get(new_data, field) end)
|
||||
|
||||
%{updated_object: updated_object} =
|
||||
new_data
|
||||
|> Object.Updater.maybe_update_history(old_data,
|
||||
updated: changed?,
|
||||
use_history_in_new_object?: false
|
||||
)
|
||||
|
||||
updated_object
|
||||
else
|
||||
new_data
|
||||
end
|
||||
|
||||
Map.merge(new_data, internal_fields)
|
||||
end
|
||||
|
||||
|
|
240
lib/pleroma/object/updater.ex
Normal file
240
lib/pleroma/object/updater.ex
Normal file
|
@ -0,0 +1,240 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Object.Updater do
|
||||
require Pleroma.Constants
|
||||
|
||||
def update_content_fields(orig_object_data, updated_object) do
|
||||
Pleroma.Constants.status_updatable_fields()
|
||||
|> Enum.reduce(
|
||||
%{data: orig_object_data, updated: false},
|
||||
fn field, %{data: data, updated: updated} ->
|
||||
updated =
|
||||
updated or
|
||||
(field != "updated" and
|
||||
Map.get(updated_object, field) != Map.get(orig_object_data, field))
|
||||
|
||||
data =
|
||||
if Map.has_key?(updated_object, field) do
|
||||
Map.put(data, field, updated_object[field])
|
||||
else
|
||||
Map.drop(data, [field])
|
||||
end
|
||||
|
||||
%{data: data, updated: updated}
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
def maybe_history(object) do
|
||||
with history <- Map.get(object, "formerRepresentations"),
|
||||
true <- is_map(history),
|
||||
"OrderedCollection" <- Map.get(history, "type"),
|
||||
true <- is_list(Map.get(history, "orderedItems")),
|
||||
true <- is_integer(Map.get(history, "totalItems")) do
|
||||
history
|
||||
else
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
def history_for(object) do
|
||||
with history when not is_nil(history) <- maybe_history(object) do
|
||||
history
|
||||
else
|
||||
_ -> history_skeleton()
|
||||
end
|
||||
end
|
||||
|
||||
defp history_skeleton do
|
||||
%{
|
||||
"type" => "OrderedCollection",
|
||||
"totalItems" => 0,
|
||||
"orderedItems" => []
|
||||
}
|
||||
end
|
||||
|
||||
def maybe_update_history(
|
||||
updated_object,
|
||||
orig_object_data,
|
||||
opts
|
||||
) do
|
||||
updated = opts[:updated]
|
||||
use_history_in_new_object? = opts[:use_history_in_new_object?]
|
||||
|
||||
if not updated do
|
||||
%{updated_object: updated_object, used_history_in_new_object?: false}
|
||||
else
|
||||
# Put edit history
|
||||
# Note that we may have got the edit history by first fetching the object
|
||||
{new_history, used_history_in_new_object?} =
|
||||
with true <- use_history_in_new_object?,
|
||||
updated_history when not is_nil(updated_history) <- maybe_history(opts[:new_data]) do
|
||||
{updated_history, true}
|
||||
else
|
||||
_ ->
|
||||
history = history_for(orig_object_data)
|
||||
|
||||
latest_history_item =
|
||||
orig_object_data
|
||||
|> Map.drop(["id", "formerRepresentations"])
|
||||
|
||||
updated_history =
|
||||
history
|
||||
|> Map.put("orderedItems", [latest_history_item | history["orderedItems"]])
|
||||
|> Map.put("totalItems", history["totalItems"] + 1)
|
||||
|
||||
{updated_history, false}
|
||||
end
|
||||
|
||||
updated_object =
|
||||
updated_object
|
||||
|> Map.put("formerRepresentations", new_history)
|
||||
|
||||
%{updated_object: updated_object, used_history_in_new_object?: used_history_in_new_object?}
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_update_poll(to_be_updated, updated_object) do
|
||||
choice_key = fn data ->
|
||||
if Map.has_key?(data, "anyOf"), do: "anyOf", else: "oneOf"
|
||||
end
|
||||
|
||||
with true <- to_be_updated["type"] == "Question",
|
||||
key <- choice_key.(updated_object),
|
||||
true <- key == choice_key.(to_be_updated),
|
||||
orig_choices <- to_be_updated[key] |> Enum.map(&Map.drop(&1, ["replies"])),
|
||||
new_choices <- updated_object[key] |> Enum.map(&Map.drop(&1, ["replies"])),
|
||||
true <- orig_choices == new_choices do
|
||||
# Choices are the same, but counts are different
|
||||
to_be_updated
|
||||
|> Map.put(key, updated_object[key])
|
||||
else
|
||||
# Choices (or vote type) have changed, do not allow this
|
||||
_ -> to_be_updated
|
||||
end
|
||||
end
|
||||
|
||||
# This calculates the data to be sent as the object of an Update.
|
||||
# new_data's formerRepresentations is not considered.
|
||||
# formerRepresentations is added to the returned data.
|
||||
def make_update_object_data(original_data, new_data, date) do
|
||||
%{data: updated_data, updated: updated} =
|
||||
original_data
|
||||
|> update_content_fields(new_data)
|
||||
|
||||
if not updated do
|
||||
updated_data
|
||||
else
|
||||
%{updated_object: updated_data} =
|
||||
updated_data
|
||||
|> maybe_update_history(original_data, updated: updated, use_history_in_new_object?: false)
|
||||
|
||||
updated_data
|
||||
|> Map.put("updated", date)
|
||||
end
|
||||
end
|
||||
|
||||
# This calculates the data of the new Object from an Update.
|
||||
# new_data's formerRepresentations is considered.
|
||||
def make_new_object_data_from_update_object(original_data, new_data) do
|
||||
update_is_reasonable =
|
||||
with {_, updated} when not is_nil(updated) <- {:cur_updated, new_data["updated"]},
|
||||
{_, {:ok, updated_time, _}} <- {:cur_updated, DateTime.from_iso8601(updated)},
|
||||
{_, last_updated} when not is_nil(last_updated) <-
|
||||
{:last_updated, original_data["updated"] || original_data["published"]},
|
||||
{_, {:ok, last_updated_time, _}} <-
|
||||
{:last_updated, DateTime.from_iso8601(last_updated)},
|
||||
:gt <- DateTime.compare(updated_time, last_updated_time) do
|
||||
:update_everything
|
||||
else
|
||||
# only allow poll updates
|
||||
{:cur_updated, _} -> :no_content_update
|
||||
:eq -> :no_content_update
|
||||
# allow all updates
|
||||
{:last_updated, _} -> :update_everything
|
||||
# allow no updates
|
||||
_ -> false
|
||||
end
|
||||
|
||||
%{
|
||||
updated_object: updated_data,
|
||||
used_history_in_new_object?: used_history_in_new_object?,
|
||||
updated: updated
|
||||
} =
|
||||
if update_is_reasonable == :update_everything do
|
||||
%{data: updated_data, updated: updated} =
|
||||
original_data
|
||||
|> update_content_fields(new_data)
|
||||
|
||||
updated_data
|
||||
|> maybe_update_history(original_data,
|
||||
updated: updated,
|
||||
use_history_in_new_object?: true,
|
||||
new_data: new_data
|
||||
)
|
||||
|> Map.put(:updated, updated)
|
||||
else
|
||||
%{
|
||||
updated_object: original_data,
|
||||
used_history_in_new_object?: false,
|
||||
updated: false
|
||||
}
|
||||
end
|
||||
|
||||
updated_data =
|
||||
if update_is_reasonable != false do
|
||||
updated_data
|
||||
|> maybe_update_poll(new_data)
|
||||
else
|
||||
updated_data
|
||||
end
|
||||
|
||||
%{
|
||||
updated_data: updated_data,
|
||||
updated: updated,
|
||||
used_history_in_new_object?: used_history_in_new_object?
|
||||
}
|
||||
end
|
||||
|
||||
def for_each_history_item(%{"orderedItems" => items} = history, _object, fun) do
|
||||
new_items =
|
||||
Enum.map(items, fun)
|
||||
|> Enum.reduce_while(
|
||||
{:ok, []},
|
||||
fn
|
||||
{:ok, item}, {:ok, acc} -> {:cont, {:ok, acc ++ [item]}}
|
||||
e, _acc -> {:halt, e}
|
||||
end
|
||||
)
|
||||
|
||||
case new_items do
|
||||
{:ok, items} -> {:ok, Map.put(history, "orderedItems", items)}
|
||||
e -> e
|
||||
end
|
||||
end
|
||||
|
||||
def for_each_history_item(history, _, _) do
|
||||
{:ok, history}
|
||||
end
|
||||
|
||||
def do_with_history(object, fun) do
|
||||
with history <- object["formerRepresentations"],
|
||||
object <- Map.drop(object, ["formerRepresentations"]),
|
||||
{_, {:ok, object}} <- {:main_body, fun.(object)},
|
||||
{_, {:ok, history}} <- {:history_items, for_each_history_item(history, object, fun)} do
|
||||
object =
|
||||
if history do
|
||||
Map.put(object, "formerRepresentations", history)
|
||||
else
|
||||
object
|
||||
end
|
||||
|
||||
{:ok, object}
|
||||
else
|
||||
{:main_body, e} -> e
|
||||
{:history_items, e} -> e
|
||||
end
|
||||
end
|
||||
end
|
|
@ -25,7 +25,7 @@ defp mix_task(task, args) do
|
|||
module = Module.split(module)
|
||||
|
||||
match?(["Mix", "Tasks", "Pleroma" | _], module) and
|
||||
String.downcase(List.last(module)) == task
|
||||
task_match?(module, task)
|
||||
end)
|
||||
|
||||
if module do
|
||||
|
@ -35,6 +35,13 @@ defp mix_task(task, args) do
|
|||
end
|
||||
end
|
||||
|
||||
defp task_match?(["Mix", "Tasks", "Pleroma" | module_path], task) do
|
||||
module_path
|
||||
|> Enum.join(".")
|
||||
|> String.downcase()
|
||||
|> String.equivalent?(String.downcase(task))
|
||||
end
|
||||
|
||||
def migrate(args) do
|
||||
Mix.Tasks.Pleroma.Ecto.Migrate.run(args)
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ def es_query(:activity, query, offset, limit) do
|
|||
timeout: "5s",
|
||||
sort: [
|
||||
"_score",
|
||||
%{_timestamp: %{order: "desc", format: "basic_date_time"}}
|
||||
%{"_timestamp" => %{order: "desc", format: "basic_date_time"}}
|
||||
],
|
||||
query: %{
|
||||
bool: %{
|
||||
|
@ -62,8 +62,12 @@ def search(user, query, options) do
|
|||
Task.async(fn ->
|
||||
q = es_query(:activity, parsed_query, offset, limit)
|
||||
|
||||
Pleroma.Search.Elasticsearch.Store.search(:activities, q)
|
||||
|> Enum.filter(fn x -> Visibility.visible_for_user?(x, user) end)
|
||||
:activities
|
||||
|> Pleroma.Search.Elasticsearch.Store.search(q)
|
||||
|> Enum.filter(fn x ->
|
||||
x.data["type"] == "Create" && x.object.data["type"] == "Note" &&
|
||||
Visibility.visible_for_user?(x, user)
|
||||
end)
|
||||
end)
|
||||
|
||||
activity_results = Task.await(activity_task)
|
||||
|
|
|
@ -42,7 +42,6 @@ def search(:activities, q) do
|
|||
results
|
||||
|> Enum.map(fn result -> result["_id"] end)
|
||||
|> Pleroma.Activity.all_by_ids_with_object()
|
||||
|> Enum.sort(&(&1.inserted_at >= &2.inserted_at))
|
||||
else
|
||||
e ->
|
||||
Logger.error(e)
|
||||
|
|
|
@ -153,7 +153,7 @@ def add_to_index(activity) do
|
|||
)
|
||||
|
||||
with {:ok, res} <- result,
|
||||
true <- Map.has_key?(res, "uid") do
|
||||
true <- Map.has_key?(res, "taskUid") do
|
||||
# Do nothing
|
||||
else
|
||||
_ ->
|
||||
|
|
|
@ -66,9 +66,8 @@ def refetch_public_key(conn) do
|
|||
end
|
||||
end
|
||||
|
||||
def sign(%User{} = user, headers) do
|
||||
with {:ok, %{keys: keys}} <- User.ensure_keys_present(user),
|
||||
{:ok, private_key, _} <- Keys.keys_from_pem(keys) do
|
||||
def sign(%User{keys: keys} = user, headers) do
|
||||
with {:ok, private_key, _} <- Keys.keys_from_pem(keys) do
|
||||
HTTPSignatures.sign(private_key, user.ap_id <> "#main-key", headers)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,6 +36,7 @@ defmodule Pleroma.Upload do
|
|||
alias Ecto.UUID
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Maps
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
require Logger
|
||||
|
||||
@type source ::
|
||||
|
@ -88,6 +89,7 @@ def store(upload, opts \\ []) do
|
|||
{:ok, url_spec} <- Pleroma.Uploaders.Uploader.put_file(opts.uploader, upload) do
|
||||
{:ok,
|
||||
%{
|
||||
"id" => Utils.generate_object_id(),
|
||||
"type" => opts.activity_type,
|
||||
"mediaType" => upload.content_type,
|
||||
"url" => [
|
||||
|
|
|
@ -683,6 +683,7 @@ def register_changeset_ldap(struct, params = %{password: password})
|
|||
|> put_ap_id()
|
||||
|> unique_constraint(:ap_id)
|
||||
|> put_following_and_follower_and_featured_address()
|
||||
|> put_private_key()
|
||||
end
|
||||
|
||||
def register_changeset(struct, params \\ %{}, opts \\ []) do
|
||||
|
@ -743,6 +744,7 @@ def register_changeset(struct, params \\ %{}, opts \\ []) do
|
|||
|> put_ap_id()
|
||||
|> unique_constraint(:ap_id)
|
||||
|> put_following_and_follower_and_featured_address()
|
||||
|> put_private_key()
|
||||
end
|
||||
|
||||
def maybe_validate_required_email(changeset, true), do: changeset
|
||||
|
@ -772,6 +774,11 @@ def put_following_and_follower_and_featured_address(changeset) do
|
|||
|> put_change(:featured_address, featured)
|
||||
end
|
||||
|
||||
defp put_private_key(changeset) do
|
||||
{:ok, pem} = Keys.generate_rsa_pem()
|
||||
put_change(changeset, :keys, pem)
|
||||
end
|
||||
|
||||
defp autofollow_users(user) do
|
||||
candidates = Config.get([:instance, :autofollowed_nicknames])
|
||||
|
||||
|
@ -1948,6 +1955,7 @@ defp create_service_actor(uri, nickname) do
|
|||
follower_address: uri <> "/followers"
|
||||
}
|
||||
|> change
|
||||
|> put_private_key()
|
||||
|> unique_constraint(:nickname)
|
||||
|> Repo.insert()
|
||||
|> set_cache()
|
||||
|
@ -1980,7 +1988,8 @@ def ap_enabled?(_), do: false
|
|||
|
||||
@doc "Gets or fetch a user by uri or nickname."
|
||||
@spec get_or_fetch(String.t()) :: {:ok, User.t()} | {:error, String.t()}
|
||||
def get_or_fetch("http" <> _host = uri), do: get_or_fetch_by_ap_id(uri)
|
||||
def get_or_fetch("http://" <> _host = uri), do: get_or_fetch_by_ap_id(uri)
|
||||
def get_or_fetch("https://" <> _host = uri), do: get_or_fetch_by_ap_id(uri)
|
||||
def get_or_fetch(nickname), do: get_or_fetch_by_nickname(nickname)
|
||||
|
||||
# wait a period of time and return newest version of the User structs
|
||||
|
@ -2213,17 +2222,6 @@ def get_mascot(%{mascot: mascot}) when is_nil(mascot) do
|
|||
}
|
||||
end
|
||||
|
||||
def ensure_keys_present(%{keys: keys} = user) when not is_nil(keys), do: {:ok, user}
|
||||
|
||||
def ensure_keys_present(%User{} = user) do
|
||||
with {:ok, pem} <- Keys.generate_rsa_pem() do
|
||||
user
|
||||
|> cast(%{keys: pem}, [:keys])
|
||||
|> validate_required([:keys])
|
||||
|> update_and_set_cache()
|
||||
end
|
||||
end
|
||||
|
||||
def get_ap_ids_by_nicknames(nicknames) do
|
||||
from(u in User,
|
||||
where: u.nickname in ^nicknames,
|
||||
|
|
|
@ -94,6 +94,7 @@ defp search_query(query_string, for_user, following, top_user_ids) do
|
|||
|> subquery()
|
||||
|> order_by(desc: :search_rank)
|
||||
|> maybe_restrict_local(for_user)
|
||||
|> filter_deactivated_users()
|
||||
end
|
||||
|
||||
defp select_top_users(query, top_user_ids) do
|
||||
|
@ -166,6 +167,10 @@ defp filter_internal_users(query) do
|
|||
from(q in query, where: q.actor_type != "Application")
|
||||
end
|
||||
|
||||
defp filter_deactivated_users(query) do
|
||||
from(q in query, where: q.is_active == true)
|
||||
end
|
||||
|
||||
defp filter_blocked_user(query, %User{} = blocker) do
|
||||
query
|
||||
|> join(:left, [u], b in Pleroma.UserRelationship,
|
||||
|
|
|
@ -194,7 +194,16 @@ defp insert_activity_with_expiration(data, local, recipients) do
|
|||
def notify_and_stream(activity) do
|
||||
Notification.create_notifications(activity)
|
||||
|
||||
conversation = create_or_bump_conversation(activity, activity.actor)
|
||||
original_activity =
|
||||
case activity do
|
||||
%{data: %{"type" => "Update"}, object: %{data: %{"id" => id}}} ->
|
||||
Activity.get_create_by_object_ap_id_with_object(id)
|
||||
|
||||
_ ->
|
||||
activity
|
||||
end
|
||||
|
||||
conversation = create_or_bump_conversation(original_activity, original_activity.actor)
|
||||
participations = get_participations(conversation)
|
||||
stream_out(activity)
|
||||
stream_out_participations(participations)
|
||||
|
@ -260,7 +269,7 @@ def stream_out_participations(_, _), do: :noop
|
|||
|
||||
@impl true
|
||||
def stream_out(%Activity{data: %{"type" => data_type}} = activity)
|
||||
when data_type in ["Create", "Announce", "Delete"] do
|
||||
when data_type in ["Create", "Announce", "Delete", "Update"] do
|
||||
activity
|
||||
|> Topics.get_activity_topics()
|
||||
|> Streamer.stream(activity)
|
||||
|
@ -331,9 +340,9 @@ defp do_unfollow(follower, followed, activity_id, local)
|
|||
|
||||
defp do_unfollow(follower, followed, activity_id, local) when local == true do
|
||||
with %Activity{} = follow_activity <- fetch_latest_follow(follower, followed),
|
||||
{:ok, follow_activity} <- update_follow_state(follow_activity, "cancelled"),
|
||||
unfollow_data <- make_unfollow_data(follower, followed, follow_activity, activity_id),
|
||||
{:ok, activity} <- insert(unfollow_data, local),
|
||||
{:ok, _activity} <- Repo.delete(follow_activity),
|
||||
_ <- notify_and_stream(activity),
|
||||
:ok <- maybe_federate(activity) do
|
||||
{:ok, activity}
|
||||
|
@ -349,7 +358,7 @@ defp do_unfollow(follower, followed, activity_id, false) do
|
|||
with %Activity{} = follow_activity <- fetch_latest_follow(follower, followed),
|
||||
{:ok, _activity} <- Repo.delete(follow_activity),
|
||||
unfollow_data <- make_unfollow_data(follower, followed, follow_activity, activity_id),
|
||||
unfollow_activity <- remote_unfollow_data(unfollow_data),
|
||||
unfollow_activity <- make_unfollow_activity(unfollow_data, false),
|
||||
_ <- notify_and_stream(unfollow_activity) do
|
||||
{:ok, unfollow_activity}
|
||||
else
|
||||
|
@ -358,12 +367,12 @@ defp do_unfollow(follower, followed, activity_id, false) do
|
|||
end
|
||||
end
|
||||
|
||||
defp remote_unfollow_data(data) do
|
||||
defp make_unfollow_activity(data, local) do
|
||||
{recipients, _, _} = get_recipients(data)
|
||||
|
||||
%Activity{
|
||||
data: data,
|
||||
local: false,
|
||||
local: local,
|
||||
actor: data["actor"],
|
||||
recipients: recipients
|
||||
}
|
||||
|
|
|
@ -66,8 +66,7 @@ defp relay_active?(conn, _) do
|
|||
end
|
||||
|
||||
def user(conn, %{"nickname" => nickname}) do
|
||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname),
|
||||
{:ok, user} <- User.ensure_keys_present(user) do
|
||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> put_view(UserView)
|
||||
|
@ -174,7 +173,6 @@ def relay_following(conn, _params) do
|
|||
|
||||
def following(%{assigns: %{user: for_user}} = conn, %{"nickname" => nickname, "page" => page}) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||
{user, for_user} <- ensure_user_keys_present_and_maybe_refresh_for_user(user, for_user),
|
||||
{:show_follows, true} <-
|
||||
{:show_follows, (for_user && for_user == user) || !user.hide_follows} do
|
||||
{page, _} = Integer.parse(page)
|
||||
|
@ -192,8 +190,7 @@ def following(%{assigns: %{user: for_user}} = conn, %{"nickname" => nickname, "p
|
|||
end
|
||||
|
||||
def following(%{assigns: %{user: for_user}} = conn, %{"nickname" => nickname}) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||
{user, for_user} <- ensure_user_keys_present_and_maybe_refresh_for_user(user, for_user) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> put_view(UserView)
|
||||
|
@ -213,7 +210,6 @@ def relay_followers(conn, _params) do
|
|||
|
||||
def followers(%{assigns: %{user: for_user}} = conn, %{"nickname" => nickname, "page" => page}) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||
{user, for_user} <- ensure_user_keys_present_and_maybe_refresh_for_user(user, for_user),
|
||||
{:show_followers, true} <-
|
||||
{:show_followers, (for_user && for_user == user) || !user.hide_followers} do
|
||||
{page, _} = Integer.parse(page)
|
||||
|
@ -231,8 +227,7 @@ def followers(%{assigns: %{user: for_user}} = conn, %{"nickname" => nickname, "p
|
|||
end
|
||||
|
||||
def followers(%{assigns: %{user: for_user}} = conn, %{"nickname" => nickname}) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||
{user, for_user} <- ensure_user_keys_present_and_maybe_refresh_for_user(user, for_user) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> put_view(UserView)
|
||||
|
@ -245,8 +240,7 @@ def outbox(
|
|||
%{"nickname" => nickname, "page" => page?} = params
|
||||
)
|
||||
when page? in [true, "true"] do
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||
{:ok, user} <- User.ensure_keys_present(user) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||
# "include_poll_votes" is a hack because postgres generates inefficient
|
||||
# queries when filtering by 'Answer', poll votes will be hidden by the
|
||||
# visibility filter in this case anyway
|
||||
|
@ -270,8 +264,7 @@ def outbox(
|
|||
end
|
||||
|
||||
def outbox(conn, %{"nickname" => nickname}) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||
{:ok, user} <- User.ensure_keys_present(user) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> put_view(UserView)
|
||||
|
@ -328,14 +321,10 @@ defp post_inbox_relayed_create(conn, params) do
|
|||
end
|
||||
|
||||
defp represent_service_actor(%User{} = user, conn) do
|
||||
with {:ok, user} <- User.ensure_keys_present(user) do
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> put_view(UserView)
|
||||
|> render("user.json", %{user: user})
|
||||
else
|
||||
nil -> {:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
defp represent_service_actor(nil, _), do: {:error, :not_found}
|
||||
|
@ -388,13 +377,11 @@ def read_inbox(
|
|||
def read_inbox(%{assigns: %{user: %User{nickname: nickname} = user}} = conn, %{
|
||||
"nickname" => nickname
|
||||
}) do
|
||||
with {:ok, user} <- User.ensure_keys_present(user) do
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> put_view(UserView)
|
||||
|> render("activity_collection.json", %{iri: "#{user.ap_id}/inbox"})
|
||||
end
|
||||
end
|
||||
|
||||
def read_inbox(%{assigns: %{user: %User{nickname: as_nickname}}} = conn, %{
|
||||
"nickname" => nickname
|
||||
|
@ -530,19 +517,6 @@ defp set_requester_reachable(%Plug.Conn{} = conn, _) do
|
|||
conn
|
||||
end
|
||||
|
||||
defp ensure_user_keys_present_and_maybe_refresh_for_user(user, for_user) do
|
||||
{:ok, new_user} = User.ensure_keys_present(user)
|
||||
|
||||
for_user =
|
||||
if new_user != user and match?(%User{}, for_user) do
|
||||
User.get_cached_by_nickname(for_user.nickname)
|
||||
else
|
||||
for_user
|
||||
end
|
||||
|
||||
{new_user, for_user}
|
||||
end
|
||||
|
||||
def upload_media(%{assigns: %{user: %User{} = user}} = conn, %{"file" => file} = data) do
|
||||
with {:ok, object} <-
|
||||
ActivityPub.upload(
|
||||
|
|
|
@ -55,27 +55,21 @@ def follow(follower, followed) do
|
|||
{:ok, data, []}
|
||||
end
|
||||
|
||||
@spec emoji_react(User.t(), Object.t(), String.t()) :: {:ok, map(), keyword()}
|
||||
def emoji_react(actor, object, emoji) do
|
||||
with {:ok, data, meta} <- object_action(actor, object) do
|
||||
data =
|
||||
if Emoji.is_unicode_emoji?(emoji) do
|
||||
defp unicode_emoji_react(_object, data, emoji) do
|
||||
data
|
||||
|> Map.put("content", emoji)
|
||||
|> Map.put("type", "EmojiReact")
|
||||
else
|
||||
with %{} = emojo <- Emoji.get(emoji) do
|
||||
path = emojo |> Map.get(:file)
|
||||
url = "#{Endpoint.url()}#{path}"
|
||||
end
|
||||
|
||||
defp add_emoji_content(data, emoji, url) do
|
||||
data
|
||||
|> Map.put("content", emoji)
|
||||
|> Map.put("content", Emoji.maybe_quote(emoji))
|
||||
|> Map.put("type", "EmojiReact")
|
||||
|> Map.put("tag", [
|
||||
%{}
|
||||
|> Map.put("id", url)
|
||||
|> Map.put("type", "Emoji")
|
||||
|> Map.put("name", emojo.code)
|
||||
|> Map.put("name", Emoji.maybe_quote(emoji))
|
||||
|> Map.put(
|
||||
"icon",
|
||||
%{}
|
||||
|
@ -83,11 +77,64 @@ def emoji_react(actor, object, emoji) do
|
|||
|> Map.put("url", url)
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
defp remote_custom_emoji_react(
|
||||
%{data: %{"reactions" => existing_reactions}},
|
||||
data,
|
||||
emoji
|
||||
) do
|
||||
[emoji_code, instance] = String.split(Emoji.stripped_name(emoji), "@")
|
||||
|
||||
matching_reaction =
|
||||
Enum.find(
|
||||
existing_reactions,
|
||||
fn [name, _, url] ->
|
||||
url = URI.parse(url)
|
||||
url.host == instance && name == emoji_code
|
||||
end
|
||||
)
|
||||
|
||||
if matching_reaction do
|
||||
[name, _, url] = matching_reaction
|
||||
add_emoji_content(data, name, url)
|
||||
else
|
||||
{:error, "Could not react"}
|
||||
end
|
||||
end
|
||||
|
||||
defp remote_custom_emoji_react(_object, _data, _emoji) do
|
||||
{:error, "Could not react"}
|
||||
end
|
||||
|
||||
defp local_custom_emoji_react(data, emoji) do
|
||||
with %{} = emojo <- Emoji.get(emoji) do
|
||||
path = emojo |> Map.get(:file)
|
||||
url = "#{Endpoint.url()}#{path}"
|
||||
add_emoji_content(data, emojo.code, url)
|
||||
else
|
||||
_ -> {:error, "Emoji does not exist"}
|
||||
end
|
||||
end
|
||||
|
||||
defp custom_emoji_react(object, data, emoji) do
|
||||
if String.contains?(emoji, "@") do
|
||||
remote_custom_emoji_react(object, data, emoji)
|
||||
else
|
||||
local_custom_emoji_react(data, emoji)
|
||||
end
|
||||
end
|
||||
|
||||
@spec emoji_react(User.t(), Object.t(), String.t()) :: {:ok, map(), keyword()}
|
||||
def emoji_react(actor, object, emoji) do
|
||||
with {:ok, data, meta} <- object_action(actor, object) do
|
||||
data =
|
||||
if Emoji.is_unicode_emoji?(emoji) do
|
||||
unicode_emoji_react(object, data, emoji)
|
||||
else
|
||||
custom_emoji_react(object, data, emoji)
|
||||
end
|
||||
|
||||
{:ok, data, meta}
|
||||
end
|
||||
end
|
||||
|
@ -231,10 +278,16 @@ def like(actor, object) do
|
|||
end
|
||||
end
|
||||
|
||||
# Retricted to user updates for now, always public
|
||||
@spec update(User.t(), Object.t()) :: {:ok, map(), keyword()}
|
||||
def update(actor, object) do
|
||||
to = [Pleroma.Constants.as_public(), actor.follower_address]
|
||||
{to, cc} =
|
||||
if object["type"] in Pleroma.Constants.actor_types() do
|
||||
# User updates, always public
|
||||
{[Pleroma.Constants.as_public(), actor.follower_address], []}
|
||||
else
|
||||
# Status updates, follow the recipients in the object
|
||||
{object["to"] || [], object["cc"] || []}
|
||||
end
|
||||
|
||||
{:ok,
|
||||
%{
|
||||
|
@ -242,7 +295,8 @@ def update(actor, object) do
|
|||
"type" => "Update",
|
||||
"actor" => actor.ap_id,
|
||||
"object" => object,
|
||||
"to" => to
|
||||
"to" => to,
|
||||
"cc" => cc
|
||||
}, []}
|
||||
end
|
||||
|
||||
|
|
|
@ -41,6 +41,16 @@ defmodule Pleroma.Web.ActivityPub.MRF do
|
|||
suggestions: [
|
||||
"exclusion.com"
|
||||
]
|
||||
},
|
||||
%{
|
||||
key: :transparency_obfuscate_domains,
|
||||
label: "MRF domain obfuscation",
|
||||
type: {:list, :string},
|
||||
description:
|
||||
"Obfuscate domains in MRF transparency. This is useful if the domain you're blocking contains words you don't want displayed, but still want to disclose the MRF settings.",
|
||||
suggestions: [
|
||||
"badword.com"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -53,10 +63,53 @@ defmodule Pleroma.Web.ActivityPub.MRF do
|
|||
|
||||
@required_description_keys [:key, :related_policy]
|
||||
|
||||
def filter_one(policy, message) do
|
||||
should_plug_history? =
|
||||
if function_exported?(policy, :history_awareness, 0) do
|
||||
policy.history_awareness()
|
||||
else
|
||||
:manual
|
||||
end
|
||||
|> Kernel.==(:auto)
|
||||
|
||||
if not should_plug_history? do
|
||||
policy.filter(message)
|
||||
else
|
||||
main_result = policy.filter(message)
|
||||
|
||||
with {_, {:ok, main_message}} <- {:main, main_result},
|
||||
{_,
|
||||
%{
|
||||
"formerRepresentations" => %{
|
||||
"orderedItems" => [_ | _]
|
||||
}
|
||||
}} = {_, object} <- {:object, message["object"]},
|
||||
{_, {:ok, new_history}} <-
|
||||
{:history,
|
||||
Pleroma.Object.Updater.for_each_history_item(
|
||||
object["formerRepresentations"],
|
||||
object,
|
||||
fn item ->
|
||||
with {:ok, filtered} <- policy.filter(Map.put(message, "object", item)) do
|
||||
{:ok, filtered["object"]}
|
||||
else
|
||||
e -> e
|
||||
end
|
||||
end
|
||||
)} do
|
||||
{:ok, put_in(main_message, ["object", "formerRepresentations"], new_history)}
|
||||
else
|
||||
{:main, _} -> main_result
|
||||
{:object, _} -> main_result
|
||||
{:history, e} -> e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def filter(policies, %{} = message) do
|
||||
policies
|
||||
|> Enum.reduce({:ok, message}, fn
|
||||
policy, {:ok, message} -> policy.filter(message)
|
||||
policy, {:ok, message} -> filter_one(policy, message)
|
||||
_, error -> error
|
||||
end)
|
||||
end
|
||||
|
@ -85,7 +138,11 @@ def pipeline_filter(%{} = message, meta) do
|
|||
def get_policies do
|
||||
Pleroma.Config.get([:mrf, :policies], [])
|
||||
|> get_policies()
|
||||
|> Enum.concat([Pleroma.Web.ActivityPub.MRF.HashtagPolicy])
|
||||
|> Enum.concat([
|
||||
Pleroma.Web.ActivityPub.MRF.HashtagPolicy,
|
||||
Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy
|
||||
])
|
||||
|> Enum.uniq()
|
||||
end
|
||||
|
||||
defp get_policies(policy) when is_atom(policy), do: [policy]
|
||||
|
|
|
@ -9,6 +9,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy do
|
|||
|
||||
require Logger
|
||||
|
||||
@impl true
|
||||
def history_awareness, do: :auto
|
||||
|
||||
# has the user successfully posted before?
|
||||
defp old_user?(%User{} = u) do
|
||||
u.note_count > 0 || u.follower_count > 0
|
||||
|
|
|
@ -10,6 +10,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
|
|||
|
||||
@reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless])
|
||||
|
||||
def history_awareness, do: :auto
|
||||
|
||||
def filter_by_summary(
|
||||
%{data: %{"summary" => parent_summary}} = _in_reply_to,
|
||||
%{"summary" => child_summary} = child
|
||||
|
@ -27,8 +29,8 @@ def filter_by_summary(
|
|||
|
||||
def filter_by_summary(_in_reply_to, child), do: child
|
||||
|
||||
def filter(%{"type" => "Create", "object" => child_object} = object)
|
||||
when is_map(child_object) do
|
||||
def filter(%{"type" => type, "object" => child_object} = object)
|
||||
when type in ["Create", "Update"] and is_map(child_object) do
|
||||
child =
|
||||
child_object["inReplyTo"]
|
||||
|> Object.normalize(fetch: false)
|
||||
|
|
|
@ -16,6 +16,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.HashtagPolicy do
|
|||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def history_awareness, do: :manual
|
||||
|
||||
defp check_reject(message, hashtags) do
|
||||
if Enum.any?(Config.get([:mrf_hashtag, :reject]), fn match -> match in hashtags end) do
|
||||
{:reject, "[HashtagPolicy] Matches with rejected keyword"}
|
||||
|
@ -47,22 +50,46 @@ defp check_ftl_removal(%{"to" => to} = message, hashtags) do
|
|||
|
||||
defp check_ftl_removal(message, _hashtags), do: {:ok, message}
|
||||
|
||||
defp check_sensitive(message, hashtags) do
|
||||
defp check_sensitive(message) do
|
||||
{:ok, new_object} =
|
||||
Object.Updater.do_with_history(message["object"], fn object ->
|
||||
hashtags = Object.hashtags(%Object{data: object})
|
||||
|
||||
if Enum.any?(Config.get([:mrf_hashtag, :sensitive]), fn match -> match in hashtags end) do
|
||||
{:ok, Kernel.put_in(message, ["object", "sensitive"], true)}
|
||||
{:ok, Map.put(object, "sensitive", true)}
|
||||
else
|
||||
{:ok, message}
|
||||
{:ok, object}
|
||||
end
|
||||
end)
|
||||
|
||||
{:ok, Map.put(message, "object", new_object)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def filter(%{"type" => "Create", "object" => object} = message) do
|
||||
hashtags = Object.hashtags(%Object{data: object})
|
||||
def filter(%{"type" => type, "object" => object} = message) when type in ["Create", "Update"] do
|
||||
history_items =
|
||||
with %{"formerRepresentations" => %{"orderedItems" => items}} <- object do
|
||||
items
|
||||
else
|
||||
_ -> []
|
||||
end
|
||||
|
||||
historical_hashtags =
|
||||
Enum.reduce(history_items, [], fn item, acc ->
|
||||
acc ++ Object.hashtags(%Object{data: item})
|
||||
end)
|
||||
|
||||
hashtags = Object.hashtags(%Object{data: object}) ++ historical_hashtags
|
||||
|
||||
if hashtags != [] do
|
||||
with {:ok, message} <- check_reject(message, hashtags),
|
||||
{:ok, message} <- check_ftl_removal(message, hashtags),
|
||||
{:ok, message} <- check_sensitive(message, hashtags) do
|
||||
{:ok, message} <-
|
||||
(if "type" == "Create" do
|
||||
check_ftl_removal(message, hashtags)
|
||||
else
|
||||
{:ok, message}
|
||||
end),
|
||||
{:ok, message} <- check_sensitive(message) do
|
||||
{:ok, message}
|
||||
end
|
||||
else
|
||||
|
|
|
@ -27,6 +27,8 @@ defp object_payload(%{} = object) do
|
|||
end
|
||||
|
||||
defp check_reject(%{"object" => %{} = object} = message) do
|
||||
with {:ok, _new_object} <-
|
||||
Pleroma.Object.Updater.do_with_history(object, fn object ->
|
||||
payload = object_payload(object)
|
||||
|
||||
if Enum.any?(Pleroma.Config.get([:mrf_keyword, :reject]), fn pattern ->
|
||||
|
@ -36,15 +38,35 @@ defp check_reject(%{"object" => %{} = object} = message) do
|
|||
else
|
||||
{:ok, message}
|
||||
end
|
||||
end) do
|
||||
{:ok, message}
|
||||
else
|
||||
e -> e
|
||||
end
|
||||
end
|
||||
|
||||
defp check_ftl_removal(%{"to" => to, "object" => %{} = object} = message) do
|
||||
defp check_ftl_removal(%{"type" => "Create", "to" => to, "object" => %{} = object} = message) do
|
||||
check_keyword = fn object ->
|
||||
payload = object_payload(object)
|
||||
|
||||
if Pleroma.Constants.as_public() in to and
|
||||
Enum.any?(Pleroma.Config.get([:mrf_keyword, :federated_timeline_removal]), fn pattern ->
|
||||
if Enum.any?(Pleroma.Config.get([:mrf_keyword, :federated_timeline_removal]), fn pattern ->
|
||||
string_matches?(payload, pattern)
|
||||
end) do
|
||||
{:should_delist, nil}
|
||||
else
|
||||
{:ok, %{}}
|
||||
end
|
||||
end
|
||||
|
||||
should_delist? = fn object ->
|
||||
with {:ok, _} <- Pleroma.Object.Updater.do_with_history(object, check_keyword) do
|
||||
false
|
||||
else
|
||||
_ -> true
|
||||
end
|
||||
end
|
||||
|
||||
if Pleroma.Constants.as_public() in to and should_delist?.(object) do
|
||||
to = List.delete(to, Pleroma.Constants.as_public())
|
||||
cc = [Pleroma.Constants.as_public() | message["cc"] || []]
|
||||
|
||||
|
@ -59,8 +81,12 @@ defp check_ftl_removal(%{"to" => to, "object" => %{} = object} = message) do
|
|||
end
|
||||
end
|
||||
|
||||
defp check_ftl_removal(message) do
|
||||
{:ok, message}
|
||||
end
|
||||
|
||||
defp check_replace(%{"object" => %{} = object} = message) do
|
||||
object =
|
||||
replace_kw = fn object ->
|
||||
["content", "name", "summary"]
|
||||
|> Enum.filter(fn field -> Map.has_key?(object, field) && object[field] end)
|
||||
|> Enum.reduce(object, fn field, object ->
|
||||
|
@ -73,6 +99,10 @@ defp check_replace(%{"object" => %{} = object} = message) do
|
|||
|
||||
Map.put(object, field, data)
|
||||
end)
|
||||
|> (fn object -> {:ok, object} end).()
|
||||
end
|
||||
|
||||
{:ok, object} = Pleroma.Object.Updater.do_with_history(object, replace_kw)
|
||||
|
||||
message = Map.put(message, "object", object)
|
||||
|
||||
|
@ -80,7 +110,8 @@ defp check_replace(%{"object" => %{} = object} = message) do
|
|||
end
|
||||
|
||||
@impl true
|
||||
def filter(%{"type" => "Create", "object" => %{"content" => _content}} = message) do
|
||||
def filter(%{"type" => type, "object" => %{"content" => _content}} = message)
|
||||
when type in ["Create", "Update"] do
|
||||
with {:ok, message} <- check_reject(message),
|
||||
{:ok, message} <- check_ftl_removal(message),
|
||||
{:ok, message} <- check_replace(message) do
|
||||
|
|
|
@ -15,6 +15,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy do
|
|||
recv_timeout: 10_000
|
||||
]
|
||||
|
||||
@impl true
|
||||
def history_awareness, do: :auto
|
||||
|
||||
defp prefetch(url) do
|
||||
# Fetching only proxiable resources
|
||||
if MediaProxy.enabled?() and MediaProxy.url_proxiable?(url) do
|
||||
|
@ -53,10 +56,8 @@ defp preload(%{"object" => %{"attachment" => attachments}} = _message) do
|
|||
end
|
||||
|
||||
@impl true
|
||||
def filter(
|
||||
%{"type" => "Create", "object" => %{"attachment" => attachments} = _object} = message
|
||||
)
|
||||
when is_list(attachments) and length(attachments) > 0 do
|
||||
def filter(%{"type" => type, "object" => %{"attachment" => attachments} = _object} = message)
|
||||
when type in ["Create", "Update"] and is_list(attachments) and length(attachments) > 0 do
|
||||
preload(message)
|
||||
|
||||
{:ok, message}
|
||||
|
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy do
|
|||
@impl true
|
||||
def filter(%{"actor" => actor} = object) do
|
||||
with true <- is_local?(actor),
|
||||
true <- is_eligible_type?(object),
|
||||
true <- is_note?(object),
|
||||
false <- has_attachment?(object),
|
||||
true <- only_mentions?(object) do
|
||||
|
@ -32,7 +33,6 @@ defp is_local?(actor) do
|
|||
end
|
||||
|
||||
defp has_attachment?(%{
|
||||
"type" => "Create",
|
||||
"object" => %{"type" => "Note", "attachment" => attachments}
|
||||
})
|
||||
when length(attachments) > 0,
|
||||
|
@ -40,23 +40,13 @@ defp has_attachment?(%{
|
|||
|
||||
defp has_attachment?(_), do: false
|
||||
|
||||
defp only_mentions?(%{"type" => "Create", "object" => %{"type" => "Note", "source" => source}})
|
||||
when is_binary(source) do
|
||||
non_mentions =
|
||||
source |> String.split() |> Enum.filter(&(not String.starts_with?(&1, "@"))) |> length
|
||||
|
||||
if non_mentions > 0 do
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
defp only_mentions?(%{"object" => %{"type" => "Note", "source" => source}}) do
|
||||
source =
|
||||
case source do
|
||||
%{"content" => text} -> text
|
||||
_ -> source
|
||||
end
|
||||
|
||||
defp only_mentions?(%{
|
||||
"type" => "Create",
|
||||
"object" => %{"type" => "Note", "source" => %{"content" => source}}
|
||||
})
|
||||
when is_binary(source) do
|
||||
non_mentions =
|
||||
source |> String.split() |> Enum.filter(&(not String.starts_with?(&1, "@"))) |> length
|
||||
|
||||
|
@ -69,9 +59,12 @@ defp only_mentions?(%{
|
|||
|
||||
defp only_mentions?(_), do: false
|
||||
|
||||
defp is_note?(%{"type" => "Create", "object" => %{"type" => "Note"}}), do: true
|
||||
defp is_note?(%{"object" => %{"type" => "Note"}}), do: true
|
||||
defp is_note?(_), do: false
|
||||
|
||||
defp is_eligible_type?(%{"type" => type}) when type in ["Create", "Update"], do: true
|
||||
defp is_eligible_type?(_), do: false
|
||||
|
||||
@impl true
|
||||
def describe, do: {:ok, %{}}
|
||||
end
|
||||
|
|
|
@ -6,14 +6,17 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy do
|
|||
@moduledoc "Ensure no content placeholder is present (such as the dot from mastodon)"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def history_awareness, do: :auto
|
||||
|
||||
@impl true
|
||||
def filter(
|
||||
%{
|
||||
"type" => "Create",
|
||||
"type" => type,
|
||||
"object" => %{"content" => content, "attachment" => _} = _child_object
|
||||
} = object
|
||||
)
|
||||
when content in [".", "<p>.</p>"] do
|
||||
when type in ["Create", "Update"] and content in [".", "<p>.</p>"] do
|
||||
{:ok, put_in(object, ["object", "content"], "")}
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do
|
|||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
@impl true
|
||||
def filter(%{"type" => "Create", "object" => child_object} = object) do
|
||||
def history_awareness, do: :auto
|
||||
|
||||
@impl true
|
||||
def filter(%{"type" => type, "object" => child_object} = object)
|
||||
when type in ["Create", "Update"] do
|
||||
scrub_policy = Pleroma.Config.get([:mrf_normalize_markup, :scrub_policy])
|
||||
|
||||
content =
|
||||
|
|
|
@ -12,5 +12,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.Policy do
|
|||
label: String.t(),
|
||||
description: String.t()
|
||||
}
|
||||
@optional_callbacks config_description: 0
|
||||
@callback history_awareness() :: :auto | :manual
|
||||
@optional_callbacks config_description: 0, history_awareness: 0
|
||||
end
|
||||
|
|
|
@ -256,10 +256,35 @@ def filter(object) when is_binary(object) do
|
|||
|
||||
def filter(object), do: {:ok, object}
|
||||
|
||||
defp obfuscate(string) when is_binary(string) do
|
||||
string
|
||||
|> to_charlist()
|
||||
|> Enum.with_index()
|
||||
|> Enum.map(fn
|
||||
{?., _index} ->
|
||||
?.
|
||||
|
||||
{char, index} ->
|
||||
if 3 <= index && index < String.length(string) - 3, do: ?*, else: char
|
||||
end)
|
||||
|> to_string()
|
||||
end
|
||||
|
||||
defp maybe_obfuscate(host, obfuscations) do
|
||||
if MRF.subdomain_match?(obfuscations, host) do
|
||||
obfuscate(host)
|
||||
else
|
||||
host
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def describe do
|
||||
exclusions = Config.get([:mrf, :transparency_exclusions]) |> MRF.instance_list_from_tuples()
|
||||
|
||||
obfuscations =
|
||||
Config.get([:mrf, :transparency_obfuscate_domains], []) |> MRF.subdomains_regex()
|
||||
|
||||
mrf_simple_excluded =
|
||||
Config.get(:mrf_simple)
|
||||
|> Enum.map(fn {rule, instances} ->
|
||||
|
@ -269,7 +294,7 @@ def describe do
|
|||
mrf_simple =
|
||||
mrf_simple_excluded
|
||||
|> Enum.map(fn {rule, instances} ->
|
||||
{rule, Enum.map(instances, fn {host, _} -> host end)}
|
||||
{rule, Enum.map(instances, fn {host, _} -> maybe_obfuscate(host, obfuscations) end)}
|
||||
end)
|
||||
|> Map.new()
|
||||
|
||||
|
@ -286,7 +311,9 @@ def describe do
|
|||
|> Enum.map(fn {rule, instances} ->
|
||||
instances =
|
||||
instances
|
||||
|> Enum.map(fn {host, reason} -> {host, %{"reason" => reason}} end)
|
||||
|> Enum.map(fn {host, reason} ->
|
||||
{maybe_obfuscate(host, obfuscations), %{"reason" => reason}}
|
||||
end)
|
||||
|> Map.new()
|
||||
|
||||
{rule, instances}
|
||||
|
|
|
@ -86,8 +86,8 @@ def validate(
|
|||
meta
|
||||
)
|
||||
when objtype in ~w[Question Answer Audio Video Event Article Note Page] do
|
||||
with {:ok, object_data} <- cast_and_apply(object),
|
||||
meta = Keyword.put(meta, :object_data, object_data |> stringify_keys),
|
||||
with {:ok, object_data} <- cast_and_apply_and_stringify_with_history(object),
|
||||
meta = Keyword.put(meta, :object_data, object_data),
|
||||
{:ok, create_activity} <-
|
||||
create_activity
|
||||
|> CreateGenericValidator.cast_and_validate(meta)
|
||||
|
@ -110,6 +110,8 @@ def validate(%{"type" => type} = object, meta)
|
|||
"Page" -> ArticleNotePageValidator
|
||||
end
|
||||
|
||||
with {:ok, object} <-
|
||||
do_separate_with_history(object, fn object ->
|
||||
with {:ok, object} <-
|
||||
object
|
||||
|> validator.cast_and_validate()
|
||||
|
@ -120,10 +122,42 @@ def validate(%{"type" => type} = object, meta)
|
|||
tag = (object["tag"] || []) ++ Object.hashtags(%Object{data: object})
|
||||
object = Map.put(object, "tag", tag)
|
||||
|
||||
{:ok, object}
|
||||
end
|
||||
end) do
|
||||
{:ok, object, meta}
|
||||
end
|
||||
end
|
||||
|
||||
def validate(
|
||||
%{"type" => "Update", "object" => %{"type" => objtype} = object} = update_activity,
|
||||
meta
|
||||
)
|
||||
when objtype in ~w[Question Answer Audio Video Event Article Note Page] do
|
||||
with {_, false} <- {:local, Access.get(meta, :local, false)},
|
||||
{_, {:ok, object_data, _}} <- {:object_validation, validate(object, meta)},
|
||||
meta = Keyword.put(meta, :object_data, object_data),
|
||||
{:ok, update_activity} <-
|
||||
update_activity
|
||||
|> UpdateValidator.cast_and_validate()
|
||||
|> Ecto.Changeset.apply_action(:insert) do
|
||||
update_activity = stringify_keys(update_activity)
|
||||
{:ok, update_activity, meta}
|
||||
else
|
||||
{:local, _} ->
|
||||
with {:ok, object} <-
|
||||
update_activity
|
||||
|> UpdateValidator.cast_and_validate()
|
||||
|> Ecto.Changeset.apply_action(:insert) do
|
||||
object = stringify_keys(object)
|
||||
{:ok, object, meta}
|
||||
end
|
||||
|
||||
{:object_validation, e} ->
|
||||
e
|
||||
end
|
||||
end
|
||||
|
||||
def validate(%{"type" => type} = object, meta)
|
||||
when type in ~w[Accept Reject Follow Update Like EmojiReact Announce
|
||||
Answer] do
|
||||
|
@ -160,6 +194,15 @@ def validate(%{"type" => type} = object, meta) when type in ~w(Add Remove) do
|
|||
|
||||
def validate(o, m), do: {:error, {:validator_not_set, {o, m}}}
|
||||
|
||||
def cast_and_apply_and_stringify_with_history(object) do
|
||||
do_separate_with_history(object, fn object ->
|
||||
with {:ok, object_data} <- cast_and_apply(object),
|
||||
object_data <- object_data |> stringify_keys() do
|
||||
{:ok, object_data}
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
def cast_and_apply(%{"type" => "Question"} = object) do
|
||||
QuestionValidator.cast_and_apply(object)
|
||||
end
|
||||
|
@ -214,4 +257,54 @@ def fetch_actor_and_object(object) do
|
|||
Object.normalize(object["object"], fetch: true)
|
||||
:ok
|
||||
end
|
||||
|
||||
defp for_each_history_item(
|
||||
%{"type" => "OrderedCollection", "orderedItems" => items} = history,
|
||||
object,
|
||||
fun
|
||||
) do
|
||||
processed_items =
|
||||
Enum.map(items, fn item ->
|
||||
with item <- Map.put(item, "id", object["id"]),
|
||||
{:ok, item} <- fun.(item) do
|
||||
item
|
||||
else
|
||||
_ -> nil
|
||||
end
|
||||
end)
|
||||
|
||||
if Enum.all?(processed_items, &(not is_nil(&1))) do
|
||||
{:ok, Map.put(history, "orderedItems", processed_items)}
|
||||
else
|
||||
{:error, :invalid_history}
|
||||
end
|
||||
end
|
||||
|
||||
defp for_each_history_item(nil, _object, _fun) do
|
||||
{:ok, nil}
|
||||
end
|
||||
|
||||
defp for_each_history_item(_, _object, _fun) do
|
||||
{:error, :invalid_history}
|
||||
end
|
||||
|
||||
# fun is (object -> {:ok, validated_object_with_string_keys})
|
||||
defp do_separate_with_history(object, fun) do
|
||||
with history <- object["formerRepresentations"],
|
||||
object <- Map.drop(object, ["formerRepresentations"]),
|
||||
{_, {:ok, object}} <- {:main_body, fun.(object)},
|
||||
{_, {:ok, history}} <- {:history_items, for_each_history_item(history, object, fun)} do
|
||||
object =
|
||||
if history do
|
||||
Map.put(object, "formerRepresentations", history)
|
||||
else
|
||||
object
|
||||
end
|
||||
|
||||
{:ok, object}
|
||||
else
|
||||
{:main_body, e} -> e
|
||||
{:history_items, e} -> e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator do
|
|||
use Ecto.Schema
|
||||
alias Pleroma.User
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators
|
||||
alias Pleroma.Object.Fetcher
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
|
||||
|
@ -54,23 +53,17 @@ defp fix_url(%{"url" => url} = data) when is_bitstring(url), do: data
|
|||
defp fix_url(%{"url" => url} = data) when is_map(url), do: Map.put(data, "url", url["href"])
|
||||
defp fix_url(data), do: data
|
||||
|
||||
defp fix_tag(%{"tag" => tag} = data) when is_list(tag), do: data
|
||||
defp fix_tag(%{"tag" => tag} = data) when is_list(tag) do
|
||||
Map.put(data, "tag", Enum.filter(tag, &is_map/1))
|
||||
end
|
||||
|
||||
defp fix_tag(%{"tag" => tag} = data) when is_map(tag), do: Map.put(data, "tag", [tag])
|
||||
defp fix_tag(data), do: Map.drop(data, ["tag"])
|
||||
|
||||
defp fix_replies(%{"replies" => %{"first" => %{"items" => replies}}} = data)
|
||||
when is_list(replies),
|
||||
do: Map.put(data, "replies", replies)
|
||||
|
||||
defp fix_replies(%{"replies" => %{"items" => replies}} = data) when is_list(replies),
|
||||
do: Map.put(data, "replies", replies)
|
||||
|
||||
defp fix_replies(%{"replies" => replies} = data) when is_bitstring(replies),
|
||||
do: Map.drop(data, ["replies"])
|
||||
defp fix_replies(%{"replies" => replies} = data) when is_list(replies), do: data
|
||||
|
||||
defp fix_replies(%{"replies" => %{"first" => first}} = data) do
|
||||
with {:ok, %{"orderedItems" => replies}} <-
|
||||
Fetcher.fetch_and_contain_remote_object_from_id(first) do
|
||||
with {:ok, replies} <- Akkoma.Collections.Fetcher.fetch_collection(first) do
|
||||
Map.put(data, "replies", replies)
|
||||
else
|
||||
{:error, _} ->
|
||||
|
@ -79,7 +72,10 @@ defp fix_replies(%{"replies" => %{"first" => first}} = data) do
|
|||
end
|
||||
end
|
||||
|
||||
defp fix_replies(data), do: data
|
||||
defp fix_replies(%{"replies" => %{"items" => replies}} = data) when is_list(replies),
|
||||
do: Map.put(data, "replies", replies)
|
||||
|
||||
defp fix_replies(data), do: Map.delete(data, "replies")
|
||||
|
||||
defp remote_mention_resolver(
|
||||
%{"id" => ap_id, "tag" => tags},
|
||||
|
@ -108,6 +104,8 @@ defp remote_mention_resolver(
|
|||
end
|
||||
|
||||
# https://github.com/misskey-dev/misskey/pull/8787
|
||||
# Misskey has an awful tendency to drop all custom formatting when it sends remotely
|
||||
# So this basically reprocesses their MFM source
|
||||
defp fix_misskey_content(
|
||||
%{"source" => %{"mediaType" => "text/x.misskeymarkdown", "content" => content}} = object
|
||||
)
|
||||
|
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator do
|
|||
|
||||
@primary_key false
|
||||
embedded_schema do
|
||||
field(:id, :string)
|
||||
field(:type, :string)
|
||||
field(:mediaType, :string, default: "application/octet-stream")
|
||||
field(:name, :string)
|
||||
|
@ -43,7 +44,7 @@ def changeset(struct, data) do
|
|||
|> fix_url()
|
||||
|
||||
struct
|
||||
|> cast(data, [:type, :mediaType, :name, :blurhash])
|
||||
|> cast(data, [:id, :type, :mediaType, :name, :blurhash])
|
||||
|> cast_embed(:url, with: &url_changeset/2, required: true)
|
||||
|> validate_inclusion(:type, ~w[Link Document Audio Image Video])
|
||||
|> validate_required([:type, :mediaType])
|
||||
|
|
|
@ -33,6 +33,7 @@ defmacro object_fields do
|
|||
field(:content, :string)
|
||||
|
||||
field(:published, ObjectValidators.DateTime)
|
||||
field(:updated, ObjectValidators.DateTime)
|
||||
field(:emoji, ObjectValidators.Emoji, default: %{})
|
||||
embeds_many(:attachment, AttachmentValidator)
|
||||
end
|
||||
|
|
|
@ -7,8 +7,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
|
|||
alias Pleroma.Object
|
||||
alias Pleroma.Object.Containment
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
require Pleroma.Constants
|
||||
|
||||
def cast_and_filter_recipients(message, field, follower_collection, field_fallback \\ []) do
|
||||
{:ok, data} = ObjectValidators.Recipients.cast(message[field] || field_fallback)
|
||||
|
@ -32,7 +32,7 @@ def fix_object_defaults(data) do
|
|||
|> cast_and_filter_recipients("cc", follower_collection)
|
||||
|> cast_and_filter_recipients("bto", follower_collection)
|
||||
|> cast_and_filter_recipients("bcc", follower_collection)
|
||||
|> Transmogrifier.fix_implicit_addressing(follower_collection)
|
||||
|> fix_implicit_addressing(follower_collection)
|
||||
end
|
||||
|
||||
def fix_activity_addressing(activity) do
|
||||
|
@ -43,7 +43,7 @@ def fix_activity_addressing(activity) do
|
|||
|> cast_and_filter_recipients("cc", follower_collection)
|
||||
|> cast_and_filter_recipients("bto", follower_collection)
|
||||
|> cast_and_filter_recipients("bcc", follower_collection)
|
||||
|> Transmogrifier.fix_implicit_addressing(follower_collection)
|
||||
|> fix_implicit_addressing(follower_collection)
|
||||
end
|
||||
|
||||
def fix_actor(data) do
|
||||
|
@ -73,4 +73,27 @@ def fix_object_action_recipients(data, %Object{data: %{"actor" => actor}}) do
|
|||
|
||||
Map.put(data, "to", to)
|
||||
end
|
||||
|
||||
# if as:Public is addressed, then make sure the followers collection is also addressed
|
||||
# so that the activities will be delivered to local users.
|
||||
def fix_implicit_addressing(%{"to" => to, "cc" => cc} = object, followers_collection) do
|
||||
recipients = to ++ cc
|
||||
|
||||
if followers_collection not in recipients do
|
||||
cond do
|
||||
Pleroma.Constants.as_public() in cc ->
|
||||
to = to ++ [followers_collection]
|
||||
Map.put(object, "to", to)
|
||||
|
||||
Pleroma.Constants.as_public() in to ->
|
||||
cc = cc ++ [followers_collection]
|
||||
Map.put(object, "cc", cc)
|
||||
|
||||
true ->
|
||||
object
|
||||
end
|
||||
else
|
||||
object
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
|
@ -67,7 +66,7 @@ defp fix_addressing(data, object) do
|
|||
|> CommonFixes.cast_and_filter_recipients("cc", follower_collection, object["cc"])
|
||||
|> CommonFixes.cast_and_filter_recipients("bto", follower_collection, object["bto"])
|
||||
|> CommonFixes.cast_and_filter_recipients("bcc", follower_collection, object["bcc"])
|
||||
|> Transmogrifier.fix_implicit_addressing(follower_collection)
|
||||
|> CommonFixes.fix_implicit_addressing(follower_collection)
|
||||
end
|
||||
|
||||
def fix(data, meta) do
|
||||
|
|
|
@ -13,7 +13,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator do
|
|||
import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
|
||||
|
||||
@primary_key false
|
||||
@emoji_regex ~r/:[A-Za-z0-9_-]+:/
|
||||
@emoji_regex ~r/:[A-Za-z0-9_-]+(@.+)?:/
|
||||
|
||||
embedded_schema do
|
||||
quote do
|
||||
|
|
|
@ -51,7 +51,9 @@ def validate_updating_rights(cng) do
|
|||
with actor = get_field(cng, :actor),
|
||||
object = get_field(cng, :object),
|
||||
{:ok, object_id} <- ObjectValidators.ObjectID.cast(object),
|
||||
true <- actor == object_id do
|
||||
actor_uri <- URI.parse(actor),
|
||||
object_uri <- URI.parse(object_id),
|
||||
true <- actor_uri.host == object_uri.host do
|
||||
cng
|
||||
else
|
||||
_e ->
|
||||
|
|
|
@ -23,6 +23,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
|||
alias Pleroma.Web.Streamer
|
||||
alias Pleroma.Workers.PollWorker
|
||||
|
||||
require Pleroma.Constants
|
||||
require Logger
|
||||
|
||||
@logger Pleroma.Config.get([:side_effects, :logger], Logger)
|
||||
|
@ -150,24 +151,27 @@ def handle(
|
|||
|
||||
# Tasks this handles:
|
||||
# - Update the user
|
||||
# - Update a non-user object (Note, Question, etc.)
|
||||
#
|
||||
# For a local user, we also get a changeset with the full information, so we
|
||||
# can update non-federating, non-activitypub settings as well.
|
||||
@impl true
|
||||
def handle(%{data: %{"type" => "Update", "object" => updated_object}} = object, meta) do
|
||||
if changeset = Keyword.get(meta, :user_update_changeset) do
|
||||
changeset
|
||||
|> User.update_and_set_cache()
|
||||
updated_object_id = updated_object["id"]
|
||||
|
||||
with {_, true} <- {:has_id, is_binary(updated_object_id)},
|
||||
%{"type" => type} <- updated_object,
|
||||
{_, is_user} <- {:is_user, type in Pleroma.Constants.actor_types()} do
|
||||
if is_user do
|
||||
handle_update_user(object, meta)
|
||||
else
|
||||
{:ok, new_user_data} = ActivityPub.user_data_from_user_object(updated_object)
|
||||
|
||||
User.get_by_ap_id(updated_object["id"])
|
||||
|> User.remote_user_changeset(new_user_data)
|
||||
|> User.update_and_set_cache()
|
||||
handle_update_object(object, meta)
|
||||
end
|
||||
|
||||
else
|
||||
_ ->
|
||||
{:ok, object, meta}
|
||||
end
|
||||
end
|
||||
|
||||
# Tasks this handles:
|
||||
# - Add like to object
|
||||
|
@ -395,6 +399,79 @@ def handle(object, meta) do
|
|||
{:ok, object, meta}
|
||||
end
|
||||
|
||||
defp handle_update_user(
|
||||
%{data: %{"type" => "Update", "object" => updated_object}} = object,
|
||||
meta
|
||||
) do
|
||||
if changeset = Keyword.get(meta, :user_update_changeset) do
|
||||
changeset
|
||||
|> User.update_and_set_cache()
|
||||
else
|
||||
{:ok, new_user_data} = ActivityPub.user_data_from_user_object(updated_object)
|
||||
|
||||
User.get_by_ap_id(updated_object["id"])
|
||||
|> User.remote_user_changeset(new_user_data)
|
||||
|> User.update_and_set_cache()
|
||||
end
|
||||
|
||||
{:ok, object, meta}
|
||||
end
|
||||
|
||||
defp handle_update_object(
|
||||
%{data: %{"type" => "Update", "object" => updated_object}} = object,
|
||||
meta
|
||||
) do
|
||||
orig_object_ap_id = updated_object["id"]
|
||||
orig_object = Object.get_by_ap_id(orig_object_ap_id)
|
||||
orig_object_data = orig_object.data
|
||||
|
||||
updated_object =
|
||||
if meta[:local] do
|
||||
# If this is a local Update, we don't process it by transmogrifier,
|
||||
# so we use the embedded object as-is.
|
||||
updated_object
|
||||
else
|
||||
meta[:object_data]
|
||||
end
|
||||
|
||||
if orig_object_data["type"] in Pleroma.Constants.updatable_object_types() do
|
||||
%{
|
||||
updated_data: updated_object_data,
|
||||
updated: updated,
|
||||
used_history_in_new_object?: used_history_in_new_object?
|
||||
} = Object.Updater.make_new_object_data_from_update_object(orig_object_data, updated_object)
|
||||
|
||||
changeset =
|
||||
orig_object
|
||||
|> Repo.preload(:hashtags)
|
||||
|> Object.change(%{data: updated_object_data})
|
||||
|
||||
with {:ok, new_object} <- Repo.update(changeset),
|
||||
{:ok, _} <- Object.invalid_object_cache(new_object),
|
||||
{:ok, _} <- Object.set_cache(new_object),
|
||||
# The metadata/utils.ex uses the object id for the cache.
|
||||
{:ok, _} <- Pleroma.Activity.HTML.invalidate_cache_for(new_object.id) do
|
||||
if used_history_in_new_object? do
|
||||
with create_activity when not is_nil(create_activity) <-
|
||||
Pleroma.Activity.get_create_by_object_ap_id(orig_object_ap_id),
|
||||
{:ok, _} <- Pleroma.Activity.HTML.invalidate_cache_for(create_activity.id) do
|
||||
nil
|
||||
else
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
if updated do
|
||||
object
|
||||
|> Activity.normalize()
|
||||
|> ActivityPub.notify_and_stream()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
{:ok, object, meta}
|
||||
end
|
||||
|
||||
def handle_object_creation(%{"type" => "Question"} = object, activity, meta) do
|
||||
with {:ok, object, meta} <- Pipeline.common_pipeline(object, meta) do
|
||||
PollWorker.schedule_poll_end(activity)
|
||||
|
|
|
@ -19,6 +19,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
alias Pleroma.Web.ActivityPub.Pipeline
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.ActivityPub.Visibility
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
|
||||
alias Pleroma.Web.Federator
|
||||
alias Pleroma.Workers.TransmogrifierWorker
|
||||
|
||||
|
@ -95,29 +96,6 @@ def fix_explicit_addressing(%{"to" => to, "cc" => cc} = object, follower_collect
|
|||
|> Map.put("cc", final_cc)
|
||||
end
|
||||
|
||||
# if as:Public is addressed, then make sure the followers collection is also addressed
|
||||
# so that the activities will be delivered to local users.
|
||||
def fix_implicit_addressing(%{"to" => to, "cc" => cc} = object, followers_collection) do
|
||||
recipients = to ++ cc
|
||||
|
||||
if followers_collection not in recipients do
|
||||
cond do
|
||||
Pleroma.Constants.as_public() in cc ->
|
||||
to = to ++ [followers_collection]
|
||||
Map.put(object, "to", to)
|
||||
|
||||
Pleroma.Constants.as_public() in to ->
|
||||
cc = cc ++ [followers_collection]
|
||||
Map.put(object, "cc", cc)
|
||||
|
||||
true ->
|
||||
object
|
||||
end
|
||||
else
|
||||
object
|
||||
end
|
||||
end
|
||||
|
||||
def fix_addressing(object) do
|
||||
{:ok, %User{follower_address: follower_collection}} =
|
||||
object
|
||||
|
@ -130,7 +108,7 @@ def fix_addressing(object) do
|
|||
|> fix_addressing_list("bto")
|
||||
|> fix_addressing_list("bcc")
|
||||
|> fix_explicit_addressing(follower_collection)
|
||||
|> fix_implicit_addressing(follower_collection)
|
||||
|> CommonFixes.fix_implicit_addressing(follower_collection)
|
||||
end
|
||||
|
||||
def fix_actor(%{"attributedTo" => actor} = object) do
|
||||
|
@ -721,6 +699,24 @@ def prepare_object(object) do
|
|||
|> strip_internal_fields
|
||||
|> strip_internal_tags
|
||||
|> set_type
|
||||
|> maybe_process_history
|
||||
end
|
||||
|
||||
defp maybe_process_history(%{"formerRepresentations" => %{"orderedItems" => history}} = object) do
|
||||
processed_history =
|
||||
Enum.map(
|
||||
history,
|
||||
fn
|
||||
item when is_map(item) -> prepare_object(item)
|
||||
item -> item
|
||||
end
|
||||
)
|
||||
|
||||
put_in(object, ["formerRepresentations", "orderedItems"], processed_history)
|
||||
end
|
||||
|
||||
defp maybe_process_history(object) do
|
||||
object
|
||||
end
|
||||
|
||||
# @doc
|
||||
|
@ -745,6 +741,21 @@ def prepare_outgoing(%{"type" => activity_type, "object" => object_id} = data)
|
|||
{:ok, data}
|
||||
end
|
||||
|
||||
def prepare_outgoing(%{"type" => "Update", "object" => %{"type" => objtype} = object} = data)
|
||||
when objtype in Pleroma.Constants.updatable_object_types() do
|
||||
object =
|
||||
object
|
||||
|> prepare_object
|
||||
|
||||
data =
|
||||
data
|
||||
|> Map.put("object", object)
|
||||
|> Map.merge(Utils.make_json_ld_header())
|
||||
|> Map.delete("bcc")
|
||||
|
||||
{:ok, data}
|
||||
end
|
||||
|
||||
def prepare_outgoing(%{"type" => "Announce", "actor" => ap_id, "object" => object_id} = data) do
|
||||
object =
|
||||
object_id
|
||||
|
|
|
@ -329,7 +329,7 @@ def add_emoji_reaction_to_object(
|
|||
object
|
||||
) do
|
||||
reactions = get_cached_emoji_reactions(object)
|
||||
emoji = stripped_emoji_name(emoji)
|
||||
emoji = Pleroma.Emoji.stripped_name(emoji)
|
||||
url = emoji_url(emoji, activity)
|
||||
|
||||
new_reactions =
|
||||
|
@ -356,12 +356,6 @@ def add_emoji_reaction_to_object(
|
|||
update_element_in_object("reaction", new_reactions, object, count)
|
||||
end
|
||||
|
||||
defp stripped_emoji_name(name) do
|
||||
name
|
||||
|> String.replace_leading(":", "")
|
||||
|> String.replace_trailing(":", "")
|
||||
end
|
||||
|
||||
defp emoji_url(
|
||||
name,
|
||||
%Activity{
|
||||
|
@ -384,7 +378,7 @@ def remove_emoji_reaction_from_object(
|
|||
%Activity{data: %{"content" => emoji, "actor" => actor}} = activity,
|
||||
object
|
||||
) do
|
||||
emoji = stripped_emoji_name(emoji)
|
||||
emoji = Pleroma.Emoji.stripped_name(emoji)
|
||||
reactions = get_cached_emoji_reactions(object)
|
||||
url = emoji_url(emoji, activity)
|
||||
|
||||
|
@ -472,18 +466,6 @@ def update_follow_state_for_all(
|
|||
{:ok, activity}
|
||||
end
|
||||
|
||||
def update_follow_state(
|
||||
%Activity{} = activity,
|
||||
state
|
||||
) do
|
||||
new_data = Map.put(activity.data, "state", state)
|
||||
changeset = Changeset.change(activity, data: new_data)
|
||||
|
||||
with {:ok, activity} <- Repo.update(changeset) do
|
||||
{:ok, activity}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Makes a follow activity data for the given follower and followed
|
||||
"""
|
||||
|
@ -525,19 +507,37 @@ def fetch_latest_undo(%User{ap_id: ap_id}) do
|
|||
|
||||
def get_latest_reaction(internal_activity_id, %{ap_id: ap_id}, emoji) do
|
||||
%{data: %{"object" => object_ap_id}} = Activity.get_by_id(internal_activity_id)
|
||||
|
||||
emoji = Pleroma.Emoji.maybe_quote(emoji)
|
||||
|
||||
"EmojiReact"
|
||||
|> Activity.Queries.by_type()
|
||||
|> where(actor: ^ap_id)
|
||||
|> where([activity], fragment("?->>'content' = ?", activity.data, ^emoji))
|
||||
|> custom_emoji_discriminator(emoji)
|
||||
|> Activity.Queries.by_object_id(object_ap_id)
|
||||
|> order_by([activity], fragment("? desc nulls last", activity.id))
|
||||
|> limit(1)
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
defp custom_emoji_discriminator(query, emoji) do
|
||||
if String.contains?(emoji, "@") do
|
||||
stripped = Pleroma.Emoji.stripped_name(emoji)
|
||||
[name, domain] = String.split(stripped, "@")
|
||||
domain_pattern = "%" <> domain <> "%"
|
||||
emoji_pattern = Pleroma.Emoji.maybe_quote(name)
|
||||
|
||||
query
|
||||
|> where([activity], fragment("?->>'content' = ?
|
||||
AND EXISTS (
|
||||
SELECT FROM jsonb_array_elements(?->'tag') elem
|
||||
WHERE elem->>'id' ILIKE ?
|
||||
)", activity.data, ^emoji_pattern, activity.data, ^domain_pattern))
|
||||
else
|
||||
query
|
||||
|> where([activity], fragment("?->>'content' = ?", activity.data, ^emoji))
|
||||
end
|
||||
end
|
||||
|
||||
#### Announce-related helpers
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -29,11 +29,11 @@ def render("object.json", %{object: %Activity{data: %{"type" => activity_type}}
|
|||
|
||||
def render("object.json", %{object: %Activity{} = activity}) do
|
||||
base = Pleroma.Web.ActivityPub.Utils.make_json_ld_header()
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
object_id = Object.normalize(activity, id_only: true)
|
||||
|
||||
additional =
|
||||
Transmogrifier.prepare_object(activity.data)
|
||||
|> Map.put("object", object.data["id"])
|
||||
|> Map.put("object", object_id)
|
||||
|
||||
Map.merge(base, additional)
|
||||
end
|
||||
|
|
|
@ -34,7 +34,6 @@ def render("endpoints.json", %{user: %User{local: true} = _user}) do
|
|||
def render("endpoints.json", _), do: %{}
|
||||
|
||||
def render("service.json", %{user: user}) do
|
||||
{:ok, user} = User.ensure_keys_present(user)
|
||||
{:ok, _, public_key} = Keys.keys_from_pem(user.keys)
|
||||
public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key)
|
||||
public_key = :public_key.pem_encode([public_key])
|
||||
|
@ -71,7 +70,6 @@ def render("user.json", %{user: %User{nickname: "internal." <> _} = user}),
|
|||
do: render("service.json", %{user: user}) |> Map.put("preferredUsername", user.nickname)
|
||||
|
||||
def render("user.json", %{user: user}) do
|
||||
{:ok, user} = User.ensure_keys_present(user)
|
||||
{:ok, _, public_key} = Keys.keys_from_pem(user.keys)
|
||||
public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key)
|
||||
public_key = :public_key.pem_encode([public_key])
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
defmodule Pleroma.Web.AkkomaAPI.TranslationController do
|
||||
use Pleroma.Web, :controller
|
||||
|
||||
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
||||
|
||||
@cachex Pleroma.Config.get([:cachex, :provider], Cachex)
|
||||
|
||||
@unauthenticated_access %{fallback: :proceed_unauthenticated, scopes: []}
|
||||
plug(
|
||||
OAuthScopesPlug,
|
||||
%{@unauthenticated_access | scopes: ["read:statuses"]}
|
||||
when action in [
|
||||
:languages
|
||||
]
|
||||
)
|
||||
|
||||
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
||||
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.TranslationOperation
|
||||
|
||||
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
|
||||
|
||||
@doc "GET /api/v1/akkoma/translation/languages"
|
||||
def languages(conn, _params) do
|
||||
with {:ok, source_languages, dest_languages} <- get_languages() do
|
||||
conn
|
||||
|> json(%{source: source_languages, target: dest_languages})
|
||||
else
|
||||
e -> IO.inspect(e)
|
||||
end
|
||||
end
|
||||
|
||||
defp get_languages do
|
||||
module = Pleroma.Config.get([:translator, :module])
|
||||
|
||||
@cachex.fetch!(:translations_cache, "languages:#{module}}", fn _ ->
|
||||
with {:ok, source_languages, dest_languages} <- module.languages() do
|
||||
{:ok, source_languages, dest_languages}
|
||||
else
|
||||
{:error, err} -> {:ignore, {:error, err}}
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
|
@ -16,7 +16,7 @@ def index_operation do
|
|||
%Operation{
|
||||
tags: ["Backups"],
|
||||
summary: "List backups",
|
||||
security: [%{"oAuth" => ["read:account"]}],
|
||||
security: [%{"oAuth" => ["read:backups"]}],
|
||||
operationId: "PleromaAPI.BackupController.index",
|
||||
responses: %{
|
||||
200 =>
|
||||
|
@ -37,7 +37,7 @@ def create_operation do
|
|||
%Operation{
|
||||
tags: ["Backups"],
|
||||
summary: "Create a backup",
|
||||
security: [%{"oAuth" => ["read:account"]}],
|
||||
security: [%{"oAuth" => ["read:backups"]}],
|
||||
operationId: "PleromaAPI.BackupController.create",
|
||||
responses: %{
|
||||
200 =>
|
||||
|
|
|
@ -6,9 +6,13 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
|
|||
alias OpenApiSpex.Operation
|
||||
alias OpenApiSpex.Schema
|
||||
alias Pleroma.Web.ApiSpec.AccountOperation
|
||||
alias Pleroma.Web.ApiSpec.Schemas.Account
|
||||
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
||||
alias Pleroma.Web.ApiSpec.Schemas.Attachment
|
||||
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
|
||||
alias Pleroma.Web.ApiSpec.Schemas.Emoji
|
||||
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
|
||||
alias Pleroma.Web.ApiSpec.Schemas.Poll
|
||||
alias Pleroma.Web.ApiSpec.Schemas.ScheduledStatus
|
||||
alias Pleroma.Web.ApiSpec.Schemas.Status
|
||||
alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
|
||||
|
@ -406,6 +410,75 @@ def bookmarks_operation do
|
|||
}
|
||||
end
|
||||
|
||||
def translate_operation do
|
||||
%Operation{
|
||||
tags: ["Retrieve status translation"],
|
||||
summary: "Translate status",
|
||||
description: "View the translation of a given status",
|
||||
operationId: "StatusController.translation",
|
||||
security: [%{"oAuth" => ["read:statuses"]}],
|
||||
parameters: [id_param(), language_param(), source_language_param()],
|
||||
responses: %{
|
||||
200 => Operation.response("Translation", "application/json", translation()),
|
||||
400 => Operation.response("Error", "application/json", ApiError),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def show_history_operation do
|
||||
%Operation{
|
||||
tags: ["Retrieve status history"],
|
||||
summary: "Status history",
|
||||
description: "View history of a status",
|
||||
operationId: "StatusController.show_history",
|
||||
security: [%{"oAuth" => ["read:statuses"]}],
|
||||
parameters: [
|
||||
id_param()
|
||||
],
|
||||
responses: %{
|
||||
200 => status_history_response(),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def show_source_operation do
|
||||
%Operation{
|
||||
tags: ["Retrieve status source"],
|
||||
summary: "Status source",
|
||||
description: "View source of a status",
|
||||
operationId: "StatusController.show_source",
|
||||
security: [%{"oAuth" => ["read:statuses"]}],
|
||||
parameters: [
|
||||
id_param()
|
||||
],
|
||||
responses: %{
|
||||
200 => status_source_response(),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def update_operation do
|
||||
%Operation{
|
||||
tags: ["Update status"],
|
||||
summary: "Update status",
|
||||
description: "Change the content of a status",
|
||||
operationId: "StatusController.update",
|
||||
security: [%{"oAuth" => ["write:statuses"]}],
|
||||
parameters: [
|
||||
id_param()
|
||||
],
|
||||
requestBody: request_body("Parameters", update_request(), required: true),
|
||||
responses: %{
|
||||
200 => status_response(),
|
||||
403 => Operation.response("Forbidden", "application/json", ApiError),
|
||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def array_of_statuses do
|
||||
%Schema{type: :array, items: Status, example: [Status.schema().example]}
|
||||
end
|
||||
|
@ -514,6 +587,60 @@ defp create_request do
|
|||
}
|
||||
end
|
||||
|
||||
defp update_request do
|
||||
%Schema{
|
||||
title: "StatusUpdateRequest",
|
||||
type: :object,
|
||||
properties: %{
|
||||
status: %Schema{
|
||||
type: :string,
|
||||
nullable: true,
|
||||
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{
|
||||
nullable: true,
|
||||
type: :array,
|
||||
items: %Schema{type: :string},
|
||||
description: "Array of Attachment ids to be attached as media."
|
||||
},
|
||||
poll: poll_params(),
|
||||
sensitive: %Schema{
|
||||
allOf: [BooleanLike],
|
||||
nullable: true,
|
||||
description: "Mark status and attached media as sensitive?"
|
||||
},
|
||||
spoiler_text: %Schema{
|
||||
type: :string,
|
||||
nullable: true,
|
||||
description:
|
||||
"Text to be shown as a warning or subject before the actual content. Statuses are generally collapsed behind this field."
|
||||
},
|
||||
content_type: %Schema{
|
||||
type: :string,
|
||||
nullable: true,
|
||||
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,
|
||||
nullable: true,
|
||||
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"
|
||||
}
|
||||
},
|
||||
example: %{
|
||||
"status" => "What time is it?",
|
||||
"sensitive" => "false",
|
||||
"poll" => %{
|
||||
"options" => ["Cofe", "Adventure"],
|
||||
"expires_in" => 420
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def poll_params do
|
||||
%Schema{
|
||||
nullable: true,
|
||||
|
@ -552,10 +679,99 @@ def id_param do
|
|||
)
|
||||
end
|
||||
|
||||
defp language_param do
|
||||
Operation.parameter(:language, :path, :string, "ISO 639 language code", example: "en")
|
||||
end
|
||||
|
||||
defp source_language_param do
|
||||
Operation.parameter(:from, :query, :string, "ISO 639 language code", example: "en")
|
||||
end
|
||||
|
||||
defp status_response do
|
||||
Operation.response("Status", "application/json", Status)
|
||||
end
|
||||
|
||||
defp status_history_response do
|
||||
Operation.response(
|
||||
"Status History",
|
||||
"application/json",
|
||||
%Schema{
|
||||
title: "Status history",
|
||||
description: "Response schema for history of a status",
|
||||
type: :array,
|
||||
items: %Schema{
|
||||
type: :object,
|
||||
properties: %{
|
||||
account: %Schema{
|
||||
allOf: [Account],
|
||||
description: "The account that authored this status"
|
||||
},
|
||||
content: %Schema{
|
||||
type: :string,
|
||||
format: :html,
|
||||
description: "HTML-encoded status content"
|
||||
},
|
||||
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"
|
||||
},
|
||||
created_at: %Schema{
|
||||
type: :string,
|
||||
format: "date-time",
|
||||
description: "The date when this status was created"
|
||||
},
|
||||
media_attachments: %Schema{
|
||||
type: :array,
|
||||
items: Attachment,
|
||||
description: "Media that is attached to this status"
|
||||
},
|
||||
emojis: %Schema{
|
||||
type: :array,
|
||||
items: Emoji,
|
||||
description: "Custom emoji to be used when rendering status content"
|
||||
},
|
||||
poll: %Schema{
|
||||
allOf: [Poll],
|
||||
nullable: true,
|
||||
description: "The poll attached to the status"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
defp status_source_response do
|
||||
Operation.response(
|
||||
"Status Source",
|
||||
"application/json",
|
||||
%Schema{
|
||||
type: :object,
|
||||
properties: %{
|
||||
id: FlakeID,
|
||||
text: %Schema{
|
||||
type: :string,
|
||||
description: "Raw source of status content"
|
||||
},
|
||||
spoiler_text: %Schema{
|
||||
type: :string,
|
||||
description:
|
||||
"Subject or summary line, below which status content is collapsed until expanded"
|
||||
},
|
||||
content_type: %Schema{
|
||||
type: :string,
|
||||
description: "The content type of the source"
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
defp context do
|
||||
%Schema{
|
||||
title: "StatusContext",
|
||||
|
@ -573,4 +789,20 @@ defp context do
|
|||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp translation do
|
||||
%Schema{
|
||||
title: "StatusTranslation",
|
||||
description: "The translation of a status.",
|
||||
type: :object,
|
||||
required: [:detected_language, :text],
|
||||
properties: %{
|
||||
detected_language: %Schema{
|
||||
type: :string,
|
||||
description: "The detected language of the text"
|
||||
},
|
||||
text: %Schema{type: :string, description: "The translated text"}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
53
lib/pleroma/web/api_spec/operations/translate_operation.ex
Normal file
53
lib/pleroma/web/api_spec/operations/translate_operation.ex
Normal file
|
@ -0,0 +1,53 @@
|
|||
defmodule Pleroma.Web.ApiSpec.TranslationOperation do
|
||||
alias OpenApiSpex.Operation
|
||||
alias OpenApiSpex.Schema
|
||||
|
||||
@spec open_api_operation(atom) :: Operation.t()
|
||||
def open_api_operation(action) do
|
||||
operation = String.to_existing_atom("#{action}_operation")
|
||||
apply(__MODULE__, operation, [])
|
||||
end
|
||||
|
||||
@spec languages_operation() :: Operation.t()
|
||||
def languages_operation() do
|
||||
%Operation{
|
||||
tags: ["Retrieve status translation"],
|
||||
summary: "Translate status",
|
||||
description: "View the translation of a given status",
|
||||
operationId: "AkkomaAPI.TranslationController.languages",
|
||||
security: [%{"oAuth" => ["read:statuses"]}],
|
||||
responses: %{
|
||||
200 =>
|
||||
Operation.response("Translation", "application/json", source_dest_languages_schema())
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp source_dest_languages_schema do
|
||||
%Schema{
|
||||
type: :object,
|
||||
required: [:source, :target],
|
||||
properties: %{
|
||||
source: languages_schema(),
|
||||
target: languages_schema()
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp languages_schema do
|
||||
%Schema{
|
||||
type: :array,
|
||||
items: %Schema{
|
||||
type: :object,
|
||||
properties: %{
|
||||
code: %Schema{
|
||||
type: :string
|
||||
},
|
||||
name: %Schema{
|
||||
type: :string
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
|
@ -405,6 +405,16 @@ defp remote_interaction_request do
|
|||
}
|
||||
end
|
||||
|
||||
def show_subscribe_form_operation do
|
||||
%Operation{
|
||||
tags: ["Accounts"],
|
||||
summary: "Show remote subscribe form",
|
||||
operationId: "UtilController.show_subscribe_form",
|
||||
parameters: [],
|
||||
responses: %{200 => Operation.response("Web Page", "test/html", %Schema{type: :string})}
|
||||
}
|
||||
end
|
||||
|
||||
defp delete_account_request do
|
||||
%Schema{
|
||||
title: "AccountDeleteRequest",
|
||||
|
|
|
@ -73,6 +73,12 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
|
|||
format: "date-time",
|
||||
description: "The date when this status was created"
|
||||
},
|
||||
edited_at: %Schema{
|
||||
type: :string,
|
||||
format: "date-time",
|
||||
nullable: true,
|
||||
description: "The date when this status was last edited"
|
||||
},
|
||||
emojis: %Schema{
|
||||
type: :array,
|
||||
items: Emoji,
|
||||
|
|
|
@ -209,7 +209,8 @@ def react_with_emoji(id, user, emoji) do
|
|||
{:ok, activity, _} <- Pipeline.common_pipeline(emoji_react, local: true) do
|
||||
{:ok, activity}
|
||||
else
|
||||
_ -> {:error, dgettext("errors", "Could not add reaction emoji")}
|
||||
_ ->
|
||||
{:error, dgettext("errors", "Could not add reaction emoji")}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -346,6 +347,41 @@ def post(user, %{status: _} = data) do
|
|||
end
|
||||
end
|
||||
|
||||
def update(user, orig_activity, changes) do
|
||||
with orig_object <- Object.normalize(orig_activity),
|
||||
{:ok, new_object} <- make_update_data(user, orig_object, changes),
|
||||
{:ok, update_data, _} <- Builder.update(user, new_object),
|
||||
{:ok, update, _} <- Pipeline.common_pipeline(update_data, local: true) do
|
||||
{:ok, update}
|
||||
else
|
||||
_ -> {:error, nil}
|
||||
end
|
||||
end
|
||||
|
||||
defp make_update_data(user, orig_object, changes) do
|
||||
kept_params = %{
|
||||
visibility: Visibility.get_visibility(orig_object),
|
||||
in_reply_to_id:
|
||||
with replied_id when is_binary(replied_id) <- orig_object.data["inReplyTo"],
|
||||
%Activity{id: activity_id} <- Activity.get_create_by_object_ap_id(replied_id) do
|
||||
activity_id
|
||||
else
|
||||
_ -> nil
|
||||
end
|
||||
}
|
||||
|
||||
params = Map.merge(changes, kept_params)
|
||||
|
||||
with {:ok, draft} <- ActivityDraft.create(user, params) do
|
||||
change =
|
||||
Object.Updater.make_update_object_data(orig_object.data, draft.object, Utils.make_date())
|
||||
|
||||
{:ok, change}
|
||||
else
|
||||
_ -> {:error, nil}
|
||||
end
|
||||
end
|
||||
|
||||
@spec pin(String.t(), User.t()) :: {:ok, Activity.t()} | {:error, term()}
|
||||
def pin(id, %User{} = user) do
|
||||
with %Activity{} = activity <- create_activity_by_id(id),
|
||||
|
|
|
@ -221,7 +221,7 @@ defp object(draft) do
|
|||
|> Map.put("emoji", emoji)
|
||||
|> Map.put("source", %{
|
||||
"content" => draft.status,
|
||||
"mediaType" => draft.params[:content_type]
|
||||
"mediaType" => Utils.get_content_type(draft.params[:content_type])
|
||||
})
|
||||
|> Map.put("generator", draft.params[:generator])
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ def attachments_from_ids_no_descs([]), do: []
|
|||
|
||||
def attachments_from_ids_no_descs(ids) do
|
||||
Enum.map(ids, fn media_id ->
|
||||
case Repo.get(Object, media_id) do
|
||||
case get_attachment(media_id) do
|
||||
%Object{data: data} -> data
|
||||
_ -> nil
|
||||
end
|
||||
|
@ -51,13 +51,17 @@ def attachments_from_ids_descs(ids, descs_str) do
|
|||
{_, descs} = Jason.decode(descs_str)
|
||||
|
||||
Enum.map(ids, fn media_id ->
|
||||
with %Object{data: data} <- Repo.get(Object, media_id) do
|
||||
with %Object{data: data} <- get_attachment(media_id) do
|
||||
Map.put(data, "name", descs[media_id])
|
||||
end
|
||||
end)
|
||||
|> Enum.reject(&is_nil/1)
|
||||
end
|
||||
|
||||
defp get_attachment(media_id) do
|
||||
Repo.get(Object, media_id)
|
||||
end
|
||||
|
||||
@spec get_to_and_cc(ActivityDraft.t()) :: {list(String.t()), list(String.t())}
|
||||
|
||||
def get_to_and_cc(%{in_reply_to_conversation: %Participation{} = participation}) do
|
||||
|
@ -219,7 +223,7 @@ def make_content_html(%ActivityDraft{} = draft) do
|
|||
|> maybe_add_attachments(draft.attachments, attachment_links)
|
||||
end
|
||||
|
||||
defp get_content_type(content_type) do
|
||||
def get_content_type(content_type) do
|
||||
if Enum.member?(Config.get([:instance, :allowed_post_formats]), content_type) do
|
||||
content_type
|
||||
else
|
||||
|
@ -285,11 +289,11 @@ def format_input(text, "text/html", options) do
|
|||
|
||||
def format_input(text, "text/x.misskeymarkdown", options) do
|
||||
text
|
||||
|> Formatter.markdown_to_html()
|
||||
|> MfmParser.Parser.parse()
|
||||
|> MfmParser.Encoder.to_html()
|
||||
|> Formatter.linkify(options)
|
||||
|> Formatter.html_escape("text/x.misskeymarkdown")
|
||||
|> (fn {text, mentions, tags} ->
|
||||
{String.replace(text, ~r/\r?\n/, "<br>"), mentions, tags}
|
||||
end).()
|
||||
|> Formatter.html_escape("text/html")
|
||||
end
|
||||
|
||||
def format_input(text, "text/markdown", options) do
|
||||
|
|
|
@ -69,11 +69,9 @@ def perform(:publish_one, module, params) do
|
|||
def perform(:publish, activity) do
|
||||
Logger.debug(fn -> "Running publish for #{activity.data["id"]}" end)
|
||||
|
||||
with %User{} = actor <- User.get_cached_by_ap_id(activity.data["actor"]),
|
||||
{:ok, actor} <- User.ensure_keys_present(actor) do
|
||||
%User{} = actor = User.get_cached_by_ap_id(activity.data["actor"])
|
||||
Publisher.publish(actor, activity)
|
||||
end
|
||||
end
|
||||
|
||||
def perform(:incoming_ap_doc, params) do
|
||||
Logger.debug("Handling incoming AP activity")
|
||||
|
|
|
@ -27,9 +27,21 @@ defmodule Pleroma.Web.MastoFEController do
|
|||
def index(conn, _params) do
|
||||
with %{assigns: %{user: %User{} = user, token: %Token{app_id: token_app_id} = token}} <- conn,
|
||||
{:ok, %{id: ^token_app_id}} <- AuthController.local_mastofe_app() do
|
||||
flavour =
|
||||
[:frontends, :mastodon]
|
||||
|> Pleroma.Config.get()
|
||||
|> Map.get("name", "mastodon-fe")
|
||||
|
||||
index =
|
||||
if flavour == "fedibird-fe" do
|
||||
"fedibird.index.html"
|
||||
else
|
||||
"glitchsoc.index.html"
|
||||
end
|
||||
|
||||
conn
|
||||
|> put_layout(false)
|
||||
|> render("index.html",
|
||||
|> render(index,
|
||||
token: token.token,
|
||||
user: user,
|
||||
custom_emojis: Pleroma.Emoji.get_all()
|
||||
|
|
|
@ -27,7 +27,8 @@ defmodule Pleroma.Web.MastodonAPI.AuthController do
|
|||
def login(conn, %{"code" => auth_token} = params) do
|
||||
with {:ok, app} <- local_mastofe_app(),
|
||||
{:ok, auth} <- Authorization.get_by_token(app, auth_token),
|
||||
{:ok, oauth_token} <- Token.exchange_token(app, auth) do
|
||||
%User{} = user <- User.get_cached_by_id(auth.user_id),
|
||||
{:ok, oauth_token} <- Token.get_or_exchange_token(auth, app, user) do
|
||||
redirect_to =
|
||||
conn
|
||||
|> local_mastodon_post_login_path()
|
||||
|
|
|
@ -51,6 +51,7 @@ def index(conn, %{account_id: account_id} = params) do
|
|||
move
|
||||
pleroma:emoji_reaction
|
||||
poll
|
||||
update
|
||||
}
|
||||
def index(%{assigns: %{user: user}} = conn, params) do
|
||||
params =
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue