forked from AkkomaGang/akkoma
Merge remote-tracking branch 'origin/develop' into reactions
This commit is contained in:
commit
a7f31bf06c
102 changed files with 4562 additions and 6086 deletions
22
CHANGELOG.md
22
CHANGELOG.md
|
@ -8,19 +8,30 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- OStatus: eliminate the possibility of a protocol downgrade attack.
|
- OStatus: eliminate the possibility of a protocol downgrade attack.
|
||||||
- OStatus: prevent following locked accounts, bypassing the approval process.
|
- OStatus: prevent following locked accounts, bypassing the approval process.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- **Breaking:** GNU Social API with Qvitter extensions support
|
||||||
|
- **Breaking:** ActivityPub: The `accept_blocks` configuration setting.
|
||||||
|
- Emoji: Remove longfox emojis.
|
||||||
|
- Remove `Reply-To` header from report emails for admins.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- **Breaking:** Configuration: A setting to explicitly disable the mailer was added, defaulting to true, if you are using a mailer add `config :pleroma, Pleroma.Emails.Mailer, enabled: true` to your config
|
- **Breaking:** Configuration: A setting to explicitly disable the mailer was added, defaulting to true, if you are using a mailer add `config :pleroma, Pleroma.Emails.Mailer, enabled: true` to your config
|
||||||
- **Breaking:** Configuration: `/media/` is now removed when `base_url` is configured, append `/media/` to your `base_url` config to keep the old behaviour if desired
|
- **Breaking:** Configuration: `/media/` is now removed when `base_url` is configured, append `/media/` to your `base_url` config to keep the old behaviour if desired
|
||||||
|
- **Breaking:** `/api/pleroma/notifications/read` is moved to `/api/v1/pleroma/notifications/read` and now supports `max_id` and responds with Mastodon API entities.
|
||||||
- Configuration: OpenGraph and TwitterCard providers enabled by default
|
- Configuration: OpenGraph and TwitterCard providers enabled by default
|
||||||
- Configuration: Filter.AnonymizeFilename added ability to retain file extension with custom text
|
- Configuration: Filter.AnonymizeFilename added ability to retain file extension with custom text
|
||||||
|
- Configuration: added `config/description.exs`, from which `docs/config.md` is generated
|
||||||
- Federation: Return 403 errors when trying to request pages from a user's follower/following collections if they have `hide_followers`/`hide_follows` set
|
- Federation: Return 403 errors when trying to request pages from a user's follower/following collections if they have `hide_followers`/`hide_follows` set
|
||||||
- NodeInfo: Return `skipThreadContainment` in `metadata` for the `skip_thread_containment` option
|
- NodeInfo: Return `skipThreadContainment` in `metadata` for the `skip_thread_containment` option
|
||||||
- NodeInfo: Return `mailerEnabled` in `metadata`
|
- NodeInfo: Return `mailerEnabled` in `metadata`
|
||||||
- Mastodon API: Unsubscribe followers when they unfollow a user
|
- Mastodon API: Unsubscribe followers when they unfollow a user
|
||||||
|
- Mastodon API: `pleroma.thread_muted` key in the Status entity
|
||||||
- AdminAPI: Add "godmode" while fetching user statuses (i.e. admin can see private statuses)
|
- AdminAPI: Add "godmode" while fetching user statuses (i.e. admin can see private statuses)
|
||||||
- Improve digest email template
|
- Improve digest email template
|
||||||
|
– Pagination: (optional) return `total` alongside with `items` when paginating
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
- Following from Osada
|
||||||
- Not being able to pin unlisted posts
|
- Not being able to pin unlisted posts
|
||||||
- Objects being re-embedded to activities after being updated (e.g faved/reposted). Running 'mix pleroma.database prune_objects' again is advised.
|
- Objects being re-embedded to activities after being updated (e.g faved/reposted). Running 'mix pleroma.database prune_objects' again is advised.
|
||||||
- Favorites timeline doing database-intensive queries
|
- Favorites timeline doing database-intensive queries
|
||||||
|
@ -28,7 +39,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- `federation_incoming_replies_max_depth` option being ignored in certain cases
|
- `federation_incoming_replies_max_depth` option being ignored in certain cases
|
||||||
- Federation/MediaProxy not working with instances that have wrong certificate order
|
- Federation/MediaProxy not working with instances that have wrong certificate order
|
||||||
- Mastodon API: Handling of search timeouts (`/api/v1/search` and `/api/v2/search`)
|
- Mastodon API: Handling of search timeouts (`/api/v1/search` and `/api/v2/search`)
|
||||||
|
- Mastodon API: Misskey's endless polls being unable to render
|
||||||
- Mastodon API: Embedded relationships not being properly rendered in the Account entity of Status entity
|
- Mastodon API: Embedded relationships not being properly rendered in the Account entity of Status entity
|
||||||
|
- Mastodon API: Notifications endpoint crashing if one notification failed to render
|
||||||
- Mastodon API: follower/following counters not being nullified, when `hide_follows`/`hide_followers` is set
|
- Mastodon API: follower/following counters not being nullified, when `hide_follows`/`hide_followers` is set
|
||||||
- Mastodon API: `muted` in the Status entity, using author's account to determine if the tread was muted
|
- Mastodon API: `muted` in the Status entity, using author's account to determine if the tread was muted
|
||||||
- Mastodon API: Add `account_id`, `type`, `offset`, and `limit` to search API (`/api/v1/search` and `/api/v2/search`)
|
- Mastodon API: Add `account_id`, `type`, `offset`, and `limit` to search API (`/api/v1/search` and `/api/v2/search`)
|
||||||
|
@ -48,6 +61,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Reverse Proxy limiting `max_body_length` was incorrectly defined and only checked `Content-Length` headers which may not be sufficient in some circumstances
|
- Reverse Proxy limiting `max_body_length` was incorrectly defined and only checked `Content-Length` headers which may not be sufficient in some circumstances
|
||||||
- MRF: fix use of unserializable keyword lists in describe() implementations
|
- MRF: fix use of unserializable keyword lists in describe() implementations
|
||||||
- ActivityPub: Deactivated user deletion
|
- ActivityPub: Deactivated user deletion
|
||||||
|
- ActivityPub: Fix `/users/:nickname/inbox` crashing without an authenticated user
|
||||||
|
- MRF: fix ability to follow a relay when AntiFollowbotPolicy was enabled
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- Expiring/ephemeral activites. All activities can have expires_at value set, which controls when they should be deleted automatically.
|
- Expiring/ephemeral activites. All activities can have expires_at value set, which controls when they should be deleted automatically.
|
||||||
|
@ -91,10 +106,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- ActivityPub: Optional signing of ActivityPub object fetches.
|
- ActivityPub: Optional signing of ActivityPub object fetches.
|
||||||
- Admin API: Endpoint for fetching latest user's statuses
|
- Admin API: Endpoint for fetching latest user's statuses
|
||||||
- Pleroma API: Add `/api/v1/pleroma/accounts/confirmation_resend?email=<email>` for resending account confirmation.
|
- Pleroma API: Add `/api/v1/pleroma/accounts/confirmation_resend?email=<email>` for resending account confirmation.
|
||||||
|
- Pleroma API: Email change endpoint.
|
||||||
- Relays: Added a task to list relay subscriptions.
|
- Relays: Added a task to list relay subscriptions.
|
||||||
- Mix Tasks: `mix pleroma.database fix_likes_collections`
|
- Mix Tasks: `mix pleroma.database fix_likes_collections`
|
||||||
- Federation: Remove `likes` from objects.
|
- Federation: Remove `likes` from objects.
|
||||||
- Admin API: Added moderation log
|
- Admin API: Added moderation log
|
||||||
|
- Web response cache (currently, enabled for ActivityPub)
|
||||||
|
- Mastodon API: Added an endpoint to get multiple statuses by IDs (`GET /api/v1/statuses/?ids[]=1&ids[]=2`)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Configuration: Filter.AnonymizeFilename added ability to retain file extension with custom text
|
- Configuration: Filter.AnonymizeFilename added ability to retain file extension with custom text
|
||||||
|
@ -102,10 +120,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- RichMedia: parsers and their order are configured in `rich_media` config.
|
- RichMedia: parsers and their order are configured in `rich_media` config.
|
||||||
- RichMedia: add the rich media ttl based on image expiration time.
|
- RichMedia: add the rich media ttl based on image expiration time.
|
||||||
|
|
||||||
### Removed
|
|
||||||
- Emoji: Remove longfox emojis.
|
|
||||||
- Remove `Reply-To` header from report emails for admins.
|
|
||||||
- ActivityPub: The `accept_blocks` configuration setting.
|
|
||||||
|
|
||||||
## [1.0.1] - 2019-07-14
|
## [1.0.1] - 2019-07-14
|
||||||
### Security
|
### Security
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM rinpatch/elixir:1.9.0-rc.0-alpine as build
|
FROM elixir:1.9-alpine as build
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ RUN apk add git gcc g++ musl-dev make &&\
|
||||||
mkdir release &&\
|
mkdir release &&\
|
||||||
mix release --path release
|
mix release --path release
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:3.9
|
||||||
|
|
||||||
ARG HOME=/opt/pleroma
|
ARG HOME=/opt/pleroma
|
||||||
ARG DATA=/var/lib/pleroma
|
ARG DATA=/var/lib/pleroma
|
||||||
|
|
|
@ -8,7 +8,7 @@ Pleroma is a microblogging server software that can federate (= exchange message
|
||||||
|
|
||||||
Pleroma is written in Elixir, high-performance and can run on small devices like a Raspberry Pi.
|
Pleroma is written in Elixir, high-performance and can run on small devices like a Raspberry Pi.
|
||||||
|
|
||||||
For clients it supports both the [GNU Social API with Qvitter extensions](https://twitter-api.readthedocs.io/en/latest/index.html) and the [Mastodon client API](https://docs.joinmastodon.org/api/guidelines/).
|
For clients it supports the [Mastodon client API](https://docs.joinmastodon.org/api/guidelines/) with Pleroma extensions (see "Pleroma's APIs and Mastodon API extensions" section on <https://docs-develop.pleroma.social>).
|
||||||
|
|
||||||
- [Client Applications for Pleroma](https://docs-develop.pleroma.social/clients.html)
|
- [Client Applications for Pleroma](https://docs-develop.pleroma.social/clients.html)
|
||||||
|
|
||||||
|
|
|
@ -373,6 +373,8 @@
|
||||||
|
|
||||||
config :phoenix, :format_encoders, json: Jason
|
config :phoenix, :format_encoders, json: Jason
|
||||||
|
|
||||||
|
config :phoenix, :json_library, Jason
|
||||||
|
|
||||||
config :pleroma, :gopher,
|
config :pleroma, :gopher,
|
||||||
enabled: false,
|
enabled: false,
|
||||||
ip: {0, 0, 0, 0},
|
ip: {0, 0, 0, 0},
|
||||||
|
@ -560,6 +562,10 @@
|
||||||
|
|
||||||
config :pleroma, Pleroma.ActivityExpiration, enabled: true
|
config :pleroma, Pleroma.ActivityExpiration, enabled: true
|
||||||
|
|
||||||
|
config :pleroma, :web_cache_ttl,
|
||||||
|
activity_pub: nil,
|
||||||
|
activity_pub_question: 30_000
|
||||||
|
|
||||||
# Import environment specific config. This must remain at the bottom
|
# Import environment specific config. This must remain at the bottom
|
||||||
# of this file so it overrides the configuration defined above.
|
# of this file so it overrides the configuration defined above.
|
||||||
import_config "#{Mix.env()}.exs"
|
import_config "#{Mix.env()}.exs"
|
||||||
|
|
2837
config/description.exs
Normal file
2837
config/description.exs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -10,7 +10,7 @@
|
||||||
notify_email: System.get_env("NOTIFY_EMAIL"),
|
notify_email: System.get_env("NOTIFY_EMAIL"),
|
||||||
limit: 5000,
|
limit: 5000,
|
||||||
registrations_open: false,
|
registrations_open: false,
|
||||||
dynamic_configuration: true
|
healthcheck: true
|
||||||
|
|
||||||
config :pleroma, Pleroma.Repo,
|
config :pleroma, Pleroma.Repo,
|
||||||
adapter: Ecto.Adapters.Postgres,
|
adapter: Ecto.Adapters.Postgres,
|
||||||
|
|
|
@ -60,9 +60,13 @@ Authentication is required and the user must be an admin.
|
||||||
|
|
||||||
- Method: `POST`
|
- Method: `POST`
|
||||||
- Params:
|
- Params:
|
||||||
- `nickname`
|
`users`: [
|
||||||
- `email`
|
{
|
||||||
- `password`
|
`nickname`,
|
||||||
|
`email`,
|
||||||
|
`password`
|
||||||
|
}
|
||||||
|
]
|
||||||
- Response: User’s nickname
|
- Response: User’s nickname
|
||||||
|
|
||||||
## `/api/pleroma/admin/users/follow`
|
## `/api/pleroma/admin/users/follow`
|
||||||
|
|
|
@ -26,6 +26,7 @@ Has these additional fields under the `pleroma` object:
|
||||||
- `content`: a map consisting of alternate representations of the `content` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`
|
- `content`: a map consisting of alternate representations of the `content` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`
|
||||||
- `spoiler_text`: a map consisting of alternate representations of the `spoiler_text` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`
|
- `spoiler_text`: a map consisting of alternate representations of the `spoiler_text` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`
|
||||||
- `expires_at`: a datetime (iso8601) that states when the post will expire (be deleted automatically), or empty if the post won't expire
|
- `expires_at`: a datetime (iso8601) that states when the post will expire (be deleted automatically), or empty if the post won't expire
|
||||||
|
- `thread_muted`: true if the thread the post belongs to is muted
|
||||||
|
|
||||||
## Attachments
|
## Attachments
|
||||||
|
|
||||||
|
@ -90,6 +91,20 @@ Additional parameters can be added to the JSON body/Form data:
|
||||||
- `expires_in`: The number of seconds the posted activity should expire in. When a posted activity expires it will be deleted from the server, and a delete request for it will be federated. This needs to be longer than an hour.
|
- `expires_in`: The number of seconds the posted activity should expire in. When a posted activity expires it will be deleted from the server, and a delete request for it will be federated. This needs to be longer than an hour.
|
||||||
- `in_reply_to_conversation_id`: Will reply to a given conversation, addressing only the people who are part of the recipient set of that conversation. Sets the visibility to `direct`.
|
- `in_reply_to_conversation_id`: Will reply to a given conversation, addressing only the people who are part of the recipient set of that conversation. Sets the visibility to `direct`.
|
||||||
|
|
||||||
|
## GET `/api/v1/statuses`
|
||||||
|
|
||||||
|
An endpoint to get multiple statuses by IDs.
|
||||||
|
|
||||||
|
Required parameters:
|
||||||
|
|
||||||
|
- `ids`: array of activity ids
|
||||||
|
|
||||||
|
Usage example: `GET /api/v1/statuses/?ids[]=1&ids[]=2`.
|
||||||
|
|
||||||
|
Returns: array of Status.
|
||||||
|
|
||||||
|
The maximum number of statuses is limited to 100 per request.
|
||||||
|
|
||||||
## PATCH `/api/v1/update_credentials`
|
## PATCH `/api/v1/update_credentials`
|
||||||
|
|
||||||
Additional parameters can be added to the JSON body/Form data:
|
Additional parameters can be added to the JSON body/Form data:
|
||||||
|
|
|
@ -126,13 +126,14 @@ Request parameters can be passed via [query strings](https://en.wikipedia.org/wi
|
||||||
## `/api/pleroma/admin/`…
|
## `/api/pleroma/admin/`…
|
||||||
See [Admin-API](Admin-API.md)
|
See [Admin-API](Admin-API.md)
|
||||||
|
|
||||||
## `/api/pleroma/notifications/read`
|
## `/api/v1/pleroma/notifications/read`
|
||||||
### Mark a single notification as read
|
### Mark notifications as read
|
||||||
* Method `POST`
|
* Method `POST`
|
||||||
* Authentication: required
|
* Authentication: required
|
||||||
* Params:
|
* Params (mutually exclusive):
|
||||||
* `id`: notification's id
|
* `id`: a single notification id to read
|
||||||
* Response: JSON. Returns `{"status": "success"}` if the reading was successful, otherwise returns `{"error": "error_msg"}`
|
* `max_id`: read all notifications up to this id
|
||||||
|
* Response: Notification entity/Array of Notification entities that were read. In case of `max_id`, only the first 80 read notifications will be returned.
|
||||||
|
|
||||||
## `/api/v1/pleroma/accounts/:id/subscribe`
|
## `/api/v1/pleroma/accounts/:id/subscribe`
|
||||||
### Subscribe to receive notifications for all statuses posted by a user
|
### Subscribe to receive notifications for all statuses posted by a user
|
||||||
|
@ -251,7 +252,7 @@ See [Admin-API](Admin-API.md)
|
||||||
* Params:
|
* Params:
|
||||||
* `email`: email of that needs to be verified
|
* `email`: email of that needs to be verified
|
||||||
* Authentication: not required
|
* Authentication: not required
|
||||||
* Response: 204 No Content
|
* Response: 204 No Content
|
||||||
|
|
||||||
## `/api/v1/pleroma/mascot`
|
## `/api/v1/pleroma/mascot`
|
||||||
### Gets user mascot image
|
### Gets user mascot image
|
||||||
|
@ -320,11 +321,21 @@ See [Admin-API](Admin-API.md)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## `/api/pleroma/change_email`
|
||||||
|
### Change account email
|
||||||
|
* Method `POST`
|
||||||
|
* Authentication: required
|
||||||
|
* Params:
|
||||||
|
* `password`: user's password
|
||||||
|
* `email`: new email
|
||||||
|
* Response: JSON. Returns `{"status": "success"}` if the change was successful, `{"error": "[error message]"}` otherwise
|
||||||
|
* Note: Currently, Mastodon has no API for changing email. If they add it in future it might be incompatible with Pleroma.
|
||||||
|
|
||||||
# Pleroma Conversations
|
# Pleroma Conversations
|
||||||
|
|
||||||
Pleroma Conversations have the same general structure that Mastodon Conversations have. The behavior differs in the following ways when using these endpoints:
|
Pleroma Conversations have the same general structure that Mastodon Conversations have. The behavior differs in the following ways when using these endpoints:
|
||||||
|
|
||||||
1. Pleroma Conversations never add or remove recipients, unless explicitly changed by the user.
|
1. Pleroma Conversations never add or remove recipients, unless explicitly changed by the user.
|
||||||
2. Pleroma Conversations statuses can be requested by Conversation id.
|
2. Pleroma Conversations statuses can be requested by Conversation id.
|
||||||
3. Pleroma Conversations can be replied to.
|
3. Pleroma Conversations can be replied to.
|
||||||
|
|
||||||
|
|
693
docs/config.md
693
docs/config.md
|
@ -1,692 +1 @@
|
||||||
# Configuration
|
This file is a placeholder, please run mix pleroma.docs to generate it.
|
||||||
|
|
||||||
This file describe the configuration, it is recommended to edit the relevant *.secret.exs file instead of the others founds in the ``config`` directory.
|
|
||||||
If you run Pleroma with ``MIX_ENV=prod`` the file is ``prod.secret.exs``, otherwise it is ``dev.secret.exs``.
|
|
||||||
|
|
||||||
## Pleroma.Upload
|
|
||||||
* `uploader`: Select which `Pleroma.Uploaders` to use
|
|
||||||
* `filters`: List of `Pleroma.Upload.Filter` to use.
|
|
||||||
* `link_name`: When enabled Pleroma will add a `name` parameter to the url of the upload, for example `https://instance.tld/media/corndog.png?name=corndog.png`. This is needed to provide the correct filename in Content-Disposition headers when using filters like `Pleroma.Upload.Filter.Dedupe`
|
|
||||||
* `base_url`: The base URL to access a user-uploaded file. Useful when you want to proxy the media files via another host.
|
|
||||||
* `proxy_remote`: If you're using a remote uploader, Pleroma will proxy media requests instead of redirecting to it.
|
|
||||||
* `proxy_opts`: Proxy options, see `Pleroma.ReverseProxy` documentation.
|
|
||||||
|
|
||||||
Note: `strip_exif` has been replaced by `Pleroma.Upload.Filter.Mogrify`.
|
|
||||||
|
|
||||||
## Pleroma.Uploaders.Local
|
|
||||||
* `uploads`: Which directory to store the user-uploads in, relative to pleroma’s working directory
|
|
||||||
|
|
||||||
## Pleroma.Uploaders.S3
|
|
||||||
* `bucket`: S3 bucket name
|
|
||||||
* `bucket_namespace`: S3 bucket namespace
|
|
||||||
* `public_endpoint`: S3 endpoint that the user finally accesses(ex. "https://s3.dualstack.ap-northeast-1.amazonaws.com")
|
|
||||||
* `truncated_namespace`: If you use S3 compatible service such as Digital Ocean Spaces or CDN, set folder name or "" etc.
|
|
||||||
For example, when using CDN to S3 virtual host format, set "".
|
|
||||||
At this time, write CNAME to CDN in public_endpoint.
|
|
||||||
|
|
||||||
## Pleroma.Upload.Filter.Mogrify
|
|
||||||
|
|
||||||
* `args`: List of actions for the `mogrify` command like `"strip"` or `["strip", "auto-orient", {"implode", "1"}]`.
|
|
||||||
|
|
||||||
## Pleroma.Upload.Filter.Dedupe
|
|
||||||
|
|
||||||
No specific configuration.
|
|
||||||
|
|
||||||
## Pleroma.Upload.Filter.AnonymizeFilename
|
|
||||||
|
|
||||||
This filter replaces the filename (not the path) of an upload. For complete obfuscation, add
|
|
||||||
`Pleroma.Upload.Filter.Dedupe` before AnonymizeFilename.
|
|
||||||
|
|
||||||
* `text`: Text to replace filenames in links. If empty, `{random}.extension` will be used. You can get the original filename extension by using `{extension}`, for example `custom-file-name.{extension}`.
|
|
||||||
|
|
||||||
## Pleroma.Emails.Mailer
|
|
||||||
* `adapter`: one of the mail adapters listed in [Swoosh readme](https://github.com/swoosh/swoosh#adapters), or `Swoosh.Adapters.Local` for in-memory mailbox.
|
|
||||||
* `api_key` / `password` and / or other adapter-specific settings, per the above documentation.
|
|
||||||
* `enabled`: Allows enable/disable send emails. Default: `false`.
|
|
||||||
|
|
||||||
An example for Sendgrid adapter:
|
|
||||||
|
|
||||||
```elixir
|
|
||||||
config :pleroma, Pleroma.Emails.Mailer,
|
|
||||||
adapter: Swoosh.Adapters.Sendgrid,
|
|
||||||
api_key: "YOUR_API_KEY"
|
|
||||||
```
|
|
||||||
|
|
||||||
An example for SMTP adapter:
|
|
||||||
|
|
||||||
```elixir
|
|
||||||
config :pleroma, Pleroma.Emails.Mailer,
|
|
||||||
adapter: Swoosh.Adapters.SMTP,
|
|
||||||
relay: "smtp.gmail.com",
|
|
||||||
username: "YOUR_USERNAME@gmail.com",
|
|
||||||
password: "YOUR_SMTP_PASSWORD",
|
|
||||||
port: 465,
|
|
||||||
ssl: true,
|
|
||||||
tls: :always,
|
|
||||||
auth: :always
|
|
||||||
```
|
|
||||||
|
|
||||||
## :uri_schemes
|
|
||||||
* `valid_schemes`: List of the scheme part that is considered valid to be an URL
|
|
||||||
|
|
||||||
## :instance
|
|
||||||
* `name`: The instance’s name
|
|
||||||
* `email`: Email used to reach an Administrator/Moderator of the instance
|
|
||||||
* `notify_email`: Email used for notifications.
|
|
||||||
* `description`: The instance’s description, can be seen in nodeinfo and ``/api/v1/instance``
|
|
||||||
* `limit`: Posts character limit (CW/Subject included in the counter)
|
|
||||||
* `remote_limit`: Hard character limit beyond which remote posts will be dropped.
|
|
||||||
* `upload_limit`: File size limit of uploads (except for avatar, background, banner)
|
|
||||||
* `avatar_upload_limit`: File size limit of user’s profile avatars
|
|
||||||
* `background_upload_limit`: File size limit of user’s profile backgrounds
|
|
||||||
* `banner_upload_limit`: File size limit of user’s profile banners
|
|
||||||
* `poll_limits`: A map with poll limits for **local** polls
|
|
||||||
* `max_options`: Maximum number of options
|
|
||||||
* `max_option_chars`: Maximum number of characters per option
|
|
||||||
* `min_expiration`: Minimum expiration time (in seconds)
|
|
||||||
* `max_expiration`: Maximum expiration time (in seconds)
|
|
||||||
* `registrations_open`: Enable registrations for anyone, invitations can be enabled when false.
|
|
||||||
* `invites_enabled`: Enable user invitations for admins (depends on `registrations_open: false`).
|
|
||||||
* `account_activation_required`: Require users to confirm their emails before signing in.
|
|
||||||
* `federating`: Enable federation with other instances
|
|
||||||
* `federation_incoming_replies_max_depth`: Max. depth of reply-to activities fetching on incoming federation, to prevent out-of-memory situations while fetching very long threads. If set to `nil`, threads of any depth will be fetched. Lower this value if you experience out-of-memory crashes.
|
|
||||||
* `federation_reachability_timeout_days`: Timeout (in days) of each external federation target being unreachable prior to pausing federating to it.
|
|
||||||
* `allow_relay`: Enable Pleroma’s Relay, which makes it possible to follow a whole instance
|
|
||||||
* `rewrite_policy`: Message Rewrite Policy, either one or a list. Here are the ones available by default:
|
|
||||||
* `Pleroma.Web.ActivityPub.MRF.NoOpPolicy`: Doesn’t modify activities (default)
|
|
||||||
* `Pleroma.Web.ActivityPub.MRF.DropPolicy`: Drops all activities. It generally doesn’t makes sense to use in production
|
|
||||||
* `Pleroma.Web.ActivityPub.MRF.SimplePolicy`: Restrict the visibility of activities from certains instances (See ``:mrf_simple`` section)
|
|
||||||
* `Pleroma.Web.ActivityPub.MRF.TagPolicy`: Applies policies to individual users based on tags, which can be set using pleroma-fe/admin-fe/any other app that supports Pleroma Admin API. For example it allows marking posts from individual users nsfw (sensitive)
|
|
||||||
* `Pleroma.Web.ActivityPub.MRF.SubchainPolicy`: Selectively runs other MRF policies when messages match (see ``:mrf_subchain`` section)
|
|
||||||
* `Pleroma.Web.ActivityPub.MRF.RejectNonPublic`: Drops posts with non-public visibility settings (See ``:mrf_rejectnonpublic`` section)
|
|
||||||
* `Pleroma.Web.ActivityPub.MRF.EnsureRePrepended`: Rewrites posts to ensure that replies to posts with subjects do not have an identical subject and instead begin with re:.
|
|
||||||
* `Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy`: Rejects posts from likely spambots by rejecting posts from new users that contain links.
|
|
||||||
* `Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy`: Crawls attachments using their MediaProxy URLs so that the MediaProxy cache is primed.
|
|
||||||
* `Pleroma.Web.ActivityPub.MRF.MentionPolicy`: Drops posts mentioning configurable users. (see `:mrf_mention` section)
|
|
||||||
* `Pleroma.Web.ActivityPub.MRF.VocabularyPolicy`: Restricts activities to a configured set of vocabulary. (see `:mrf_vocabulary` section)
|
|
||||||
* `public`: Makes the client API in authentificated mode-only except for user-profiles. Useful for disabling the Local Timeline and The Whole Known Network.
|
|
||||||
* `quarantined_instances`: List of ActivityPub instances where private(DMs, followers-only) activities will not be send.
|
|
||||||
* `managed_config`: Whenether the config for pleroma-fe is configured in this config or in ``static/config.json``
|
|
||||||
* `allowed_post_formats`: MIME-type list of formats allowed to be posted (transformed into HTML)
|
|
||||||
* `mrf_transparency`: Make the content of your Message Rewrite Facility settings public (via nodeinfo).
|
|
||||||
* `mrf_transparency_exclusions`: Exclude specific instance names from MRF transparency. The use of the exclusions feature will be disclosed in nodeinfo as a boolean value.
|
|
||||||
* `scope_copy`: Copy the scope (private/unlisted/public) in replies to posts by default.
|
|
||||||
* `subject_line_behavior`: Allows changing the default behaviour of subject lines in replies. Valid values:
|
|
||||||
* "email": Copy and preprend re:, as in email.
|
|
||||||
* "masto": Copy verbatim, as in Mastodon.
|
|
||||||
* "noop": Don't copy the subject.
|
|
||||||
* `always_show_subject_input`: When set to false, auto-hide the subject field when it's empty.
|
|
||||||
* `extended_nickname_format`: Set to `true` to use extended local nicknames format (allows underscores/dashes). This will break federation with
|
|
||||||
older software for theses nicknames.
|
|
||||||
* `max_pinned_statuses`: The maximum number of pinned statuses. `0` will disable the feature.
|
|
||||||
* `autofollowed_nicknames`: Set to nicknames of (local) users that every new user should automatically follow.
|
|
||||||
* `no_attachment_links`: Set to true to disable automatically adding attachment link text to statuses
|
|
||||||
* `welcome_message`: A message that will be send to a newly registered users as a direct message.
|
|
||||||
* `welcome_user_nickname`: The nickname of the local user that sends the welcome message.
|
|
||||||
* `max_report_comment_size`: The maximum size of the report comment (Default: `1000`)
|
|
||||||
* `safe_dm_mentions`: If set to true, only mentions at the beginning of a post will be used to address people in direct messages. This is to prevent accidental mentioning of people when talking about them (e.g. "@friend hey i really don't like @enemy"). Default: `false`.
|
|
||||||
* `healthcheck`: If set to true, system data will be shown on ``/api/pleroma/healthcheck``.
|
|
||||||
* `remote_post_retention_days`: The default amount of days to retain remote posts when pruning the database.
|
|
||||||
* `user_bio_length`: A user bio maximum length (default: `5000`)
|
|
||||||
* `user_name_length`: A user name maximum length (default: `100`)
|
|
||||||
* `skip_thread_containment`: Skip filter out broken threads. The default is `false`.
|
|
||||||
* `limit_to_local_content`: Limit unauthenticated users to search for local statutes and users only. Possible values: `:unauthenticated`, `:all` and `false`. The default is `:unauthenticated`.
|
|
||||||
* `dynamic_configuration`: Allow transferring configuration to DB with the subsequent customization from Admin api.
|
|
||||||
* `max_account_fields`: The maximum number of custom fields in the user profile (default: `10`)
|
|
||||||
* `max_remote_account_fields`: The maximum number of custom fields in the remote user profile (default: `20`)
|
|
||||||
* `account_field_name_length`: An account field name maximum length (default: `512`)
|
|
||||||
* `account_field_value_length`: An account field value maximum length (default: `512`)
|
|
||||||
* `external_user_synchronization`: Enabling following/followers counters synchronization for external users.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## :logger
|
|
||||||
* `backends`: `:console` is used to send logs to stdout, `{ExSyslogger, :ex_syslogger}` to log to syslog, and `Quack.Logger` to log to Slack
|
|
||||||
|
|
||||||
An example to enable ONLY ExSyslogger (f/ex in ``prod.secret.exs``) with info and debug suppressed:
|
|
||||||
```elixir
|
|
||||||
config :logger,
|
|
||||||
backends: [{ExSyslogger, :ex_syslogger}]
|
|
||||||
|
|
||||||
config :logger, :ex_syslogger,
|
|
||||||
level: :warn
|
|
||||||
```
|
|
||||||
|
|
||||||
Another example, keeping console output and adding the pid to syslog output:
|
|
||||||
```elixir
|
|
||||||
config :logger,
|
|
||||||
backends: [:console, {ExSyslogger, :ex_syslogger}]
|
|
||||||
|
|
||||||
config :logger, :ex_syslogger,
|
|
||||||
level: :warn,
|
|
||||||
option: [:pid, :ndelay]
|
|
||||||
```
|
|
||||||
|
|
||||||
See: [logger’s documentation](https://hexdocs.pm/logger/Logger.html) and [ex_syslogger’s documentation](https://hexdocs.pm/ex_syslogger/)
|
|
||||||
|
|
||||||
An example of logging info to local syslog, but warn to a Slack channel:
|
|
||||||
```elixir
|
|
||||||
config :logger,
|
|
||||||
backends: [ {ExSyslogger, :ex_syslogger}, Quack.Logger ],
|
|
||||||
level: :info
|
|
||||||
|
|
||||||
config :logger, :ex_syslogger,
|
|
||||||
level: :info,
|
|
||||||
ident: "pleroma",
|
|
||||||
format: "$metadata[$level] $message"
|
|
||||||
|
|
||||||
config :quack,
|
|
||||||
level: :warn,
|
|
||||||
meta: [:all],
|
|
||||||
webhook_url: "https://hooks.slack.com/services/YOUR-API-KEY-HERE"
|
|
||||||
```
|
|
||||||
|
|
||||||
See the [Quack Github](https://github.com/azohra/quack) for more details
|
|
||||||
|
|
||||||
## :frontend_configurations
|
|
||||||
|
|
||||||
This can be used to configure a keyword list that keeps the configuration data for any kind of frontend. By default, settings for `pleroma_fe` and `masto_fe` are configured.
|
|
||||||
|
|
||||||
Frontends can access these settings at `/api/pleroma/frontend_configurations`
|
|
||||||
|
|
||||||
To add your own configuration for PleromaFE, use it like this:
|
|
||||||
|
|
||||||
```elixir
|
|
||||||
config :pleroma, :frontend_configurations,
|
|
||||||
pleroma_fe: %{
|
|
||||||
theme: "pleroma-dark",
|
|
||||||
# ... see /priv/static/static/config.json for the available keys.
|
|
||||||
},
|
|
||||||
masto_fe: %{
|
|
||||||
showInstanceSpecificPanel: true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
These settings **need to be complete**, they will override the defaults.
|
|
||||||
|
|
||||||
NOTE: for versions < 1.0, you need to set [`:fe`](#fe) to false, as shown a few lines below.
|
|
||||||
|
|
||||||
## :fe
|
|
||||||
__THIS IS DEPRECATED__
|
|
||||||
|
|
||||||
If you are using this method, please change it to the [`frontend_configurations`](#frontend_configurations) method.
|
|
||||||
Please **set this option to false** in your config like this:
|
|
||||||
|
|
||||||
```elixir
|
|
||||||
config :pleroma, :fe, false
|
|
||||||
```
|
|
||||||
|
|
||||||
This section is used to configure Pleroma-FE, unless ``:managed_config`` in ``:instance`` is set to false.
|
|
||||||
|
|
||||||
* `theme`: Which theme to use, they are defined in ``styles.json``
|
|
||||||
* `logo`: URL of the logo, defaults to Pleroma’s logo
|
|
||||||
* `logo_mask`: Whether to use only the logo's shape as a mask (true) or as a regular image (false)
|
|
||||||
* `logo_margin`: What margin to use around the logo
|
|
||||||
* `background`: URL of the background, unless viewing a user profile with a background that is set
|
|
||||||
* `redirect_root_no_login`: relative URL which indicates where to redirect when a user isn’t logged in.
|
|
||||||
* `redirect_root_login`: relative URL which indicates where to redirect when a user is logged in.
|
|
||||||
* `show_instance_panel`: Whenether to show the instance’s specific panel.
|
|
||||||
* `scope_options_enabled`: Enable setting an notice visibility and subject/CW when posting
|
|
||||||
* `formatting_options_enabled`: Enable setting a formatting different than plain-text (ie. HTML, Markdown) when posting, relates to ``:instance, allowed_post_formats``
|
|
||||||
* `collapse_message_with_subjects`: When a message has a subject(aka Content Warning), collapse it by default
|
|
||||||
* `hide_post_stats`: Hide notices statistics(repeats, favorites, …)
|
|
||||||
* `hide_user_stats`: Hide profile statistics(posts, posts per day, followers, followings, …)
|
|
||||||
|
|
||||||
## :assets
|
|
||||||
|
|
||||||
This section configures assets to be used with various frontends. Currently the only option
|
|
||||||
relates to mascots on the mastodon frontend
|
|
||||||
|
|
||||||
* `mascots`: KeywordList of mascots, each element __MUST__ contain both a `url` and a
|
|
||||||
`mime_type` key.
|
|
||||||
* `default_mascot`: An element from `mascots` - This will be used as the default mascot
|
|
||||||
on MastoFE (default: `:pleroma_fox_tan`)
|
|
||||||
|
|
||||||
## :mrf_simple
|
|
||||||
* `media_removal`: List of instances to remove medias from
|
|
||||||
* `media_nsfw`: List of instances to put medias as NSFW(sensitive) from
|
|
||||||
* `federated_timeline_removal`: List of instances to remove from Federated (aka The Whole Known Network) Timeline
|
|
||||||
* `reject`: List of instances to reject any activities from
|
|
||||||
* `accept`: List of instances to accept any activities from
|
|
||||||
* `report_removal`: List of instances to reject reports from
|
|
||||||
* `avatar_removal`: List of instances to strip avatars from
|
|
||||||
* `banner_removal`: List of instances to strip banners from
|
|
||||||
|
|
||||||
## :mrf_subchain
|
|
||||||
This policy processes messages through an alternate pipeline when a given message matches certain criteria.
|
|
||||||
All criteria are configured as a map of regular expressions to lists of policy modules.
|
|
||||||
|
|
||||||
* `match_actor`: Matches a series of regular expressions against the actor field.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```
|
|
||||||
config :pleroma, :mrf_subchain,
|
|
||||||
match_actor: %{
|
|
||||||
~r/https:\/\/example.com/s => [Pleroma.Web.ActivityPub.MRF.DropPolicy]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## :mrf_rejectnonpublic
|
|
||||||
* `allow_followersonly`: whether to allow followers-only posts
|
|
||||||
* `allow_direct`: whether to allow direct messages
|
|
||||||
|
|
||||||
## :mrf_hellthread
|
|
||||||
* `delist_threshold`: Number of mentioned users after which the message gets delisted (the message can still be seen, but it will not show up in public timelines and mentioned users won't get notifications about it). Set to 0 to disable.
|
|
||||||
* `reject_threshold`: Number of mentioned users after which the messaged gets rejected. Set to 0 to disable.
|
|
||||||
|
|
||||||
## :mrf_keyword
|
|
||||||
* `reject`: A list of patterns which result in message being rejected, each pattern can be a string or a [regular expression](https://hexdocs.pm/elixir/Regex.html)
|
|
||||||
* `federated_timeline_removal`: A list of patterns which result in message being removed from federated timelines (a.k.a unlisted), each pattern can be a string or a [regular expression](https://hexdocs.pm/elixir/Regex.html)
|
|
||||||
* `replace`: A list of tuples containing `{pattern, replacement}`, `pattern` can be a string or a [regular expression](https://hexdocs.pm/elixir/Regex.html)
|
|
||||||
|
|
||||||
## :mrf_mention
|
|
||||||
* `actors`: A list of actors, for which to drop any posts mentioning.
|
|
||||||
|
|
||||||
## :mrf_vocabulary
|
|
||||||
* `accept`: A list of ActivityStreams terms to accept. If empty, all supported messages are accepted.
|
|
||||||
* `reject`: A list of ActivityStreams terms to reject. If empty, no messages are rejected.
|
|
||||||
|
|
||||||
## :media_proxy
|
|
||||||
* `enabled`: Enables proxying of remote media to the instance’s proxy
|
|
||||||
* `base_url`: The base URL to access a user-uploaded file. Useful when you want to proxy the media files via another host/CDN fronts.
|
|
||||||
* `proxy_opts`: All options defined in `Pleroma.ReverseProxy` documentation, defaults to `[max_body_length: (25*1_048_576)]`.
|
|
||||||
* `whitelist`: List of domains to bypass the mediaproxy
|
|
||||||
|
|
||||||
## :gopher
|
|
||||||
* `enabled`: Enables the gopher interface
|
|
||||||
* `ip`: IP address to bind to
|
|
||||||
* `port`: Port to bind to
|
|
||||||
* `dstport`: Port advertised in urls (optional, defaults to `port`)
|
|
||||||
|
|
||||||
## Pleroma.Web.Endpoint
|
|
||||||
`Phoenix` endpoint configuration, all configuration options can be viewed [here](https://hexdocs.pm/phoenix/Phoenix.Endpoint.html#module-dynamic-configuration), only common options are listed here
|
|
||||||
* `http` - a list containing http protocol configuration, all configuration options can be viewed [here](https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html#module-options), only common options are listed here. For deployment using docker, you need to set this to `[ip: {0,0,0,0}, port: 4000]` to make pleroma accessible from other containers (such as your nginx server).
|
|
||||||
- `ip` - a tuple consisting of 4 integers
|
|
||||||
- `port`
|
|
||||||
* `url` - a list containing the configuration for generating urls, accepts
|
|
||||||
- `host` - the host without the scheme and a post (e.g `example.com`, not `https://example.com:2020`)
|
|
||||||
- `scheme` - e.g `http`, `https`
|
|
||||||
- `port`
|
|
||||||
- `path`
|
|
||||||
* `extra_cookie_attrs` - a list of `Key=Value` strings to be added as non-standard cookie attributes. Defaults to `["SameSite=Lax"]`. See the [SameSite article](https://www.owasp.org/index.php/SameSite) on OWASP for more info.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
**Important note**: if you modify anything inside these lists, default `config.exs` values will be overwritten, which may result in breakage, to make sure this does not happen please copy the default value for the list from `config.exs` and modify/add only what you need
|
|
||||||
|
|
||||||
Example:
|
|
||||||
```elixir
|
|
||||||
config :pleroma, Pleroma.Web.Endpoint,
|
|
||||||
url: [host: "example.com", port: 2020, scheme: "https"],
|
|
||||||
http: [
|
|
||||||
# start copied from config.exs
|
|
||||||
dispatch: [
|
|
||||||
{:_,
|
|
||||||
[
|
|
||||||
{"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
|
|
||||||
{"/websocket", Phoenix.Endpoint.CowboyWebSocket,
|
|
||||||
{Phoenix.Transports.WebSocket,
|
|
||||||
{Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, websocket_config}}},
|
|
||||||
{:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
|
|
||||||
]}
|
|
||||||
# end copied from config.exs
|
|
||||||
],
|
|
||||||
port: 8080,
|
|
||||||
ip: {127, 0, 0, 1}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
This will make Pleroma listen on `127.0.0.1` port `8080` and generate urls starting with `https://example.com:2020`
|
|
||||||
|
|
||||||
## :activitypub
|
|
||||||
* ``unfollow_blocked``: Whether blocks result in people getting unfollowed
|
|
||||||
* ``outgoing_blocks``: Whether to federate blocks to other instances
|
|
||||||
* ``deny_follow_blocked``: Whether to disallow following an account that has blocked the user in question
|
|
||||||
* ``sign_object_fetches``: Sign object fetches with HTTP signatures
|
|
||||||
|
|
||||||
## :http_security
|
|
||||||
* ``enabled``: Whether the managed content security policy is enabled
|
|
||||||
* ``sts``: Whether to additionally send a `Strict-Transport-Security` header
|
|
||||||
* ``sts_max_age``: The maximum age for the `Strict-Transport-Security` header if sent
|
|
||||||
* ``ct_max_age``: The maximum age for the `Expect-CT` header if sent
|
|
||||||
* ``referrer_policy``: The referrer policy to use, either `"same-origin"` or `"no-referrer"`
|
|
||||||
* ``report_uri``: Adds the specified url to `report-uri` and `report-to` group in CSP header.
|
|
||||||
|
|
||||||
## :mrf_user_allowlist
|
|
||||||
|
|
||||||
The keys in this section are the domain names that the policy should apply to.
|
|
||||||
Each key should be assigned a list of users that should be allowed through by
|
|
||||||
their ActivityPub ID.
|
|
||||||
|
|
||||||
An example:
|
|
||||||
|
|
||||||
```elixir
|
|
||||||
config :pleroma, :mrf_user_allowlist,
|
|
||||||
"example.org": ["https://example.org/users/admin"]
|
|
||||||
```
|
|
||||||
|
|
||||||
## :web_push_encryption, :vapid_details
|
|
||||||
|
|
||||||
Web Push Notifications configuration. You can use the mix task `mix web_push.gen.keypair` to generate it.
|
|
||||||
|
|
||||||
* ``subject``: a mailto link for the administrative contact. It’s best if this email is not a personal email address, but rather a group email so that if a person leaves an organization, is unavailable for an extended period, or otherwise can’t respond, someone else on the list can.
|
|
||||||
* ``public_key``: VAPID public key
|
|
||||||
* ``private_key``: VAPID private key
|
|
||||||
|
|
||||||
## Pleroma.Captcha
|
|
||||||
* `enabled`: Whether the captcha should be shown on registration
|
|
||||||
* `method`: The method/service to use for captcha
|
|
||||||
* `seconds_valid`: The time in seconds for which the captcha is valid
|
|
||||||
|
|
||||||
### Pleroma.Captcha.Kocaptcha
|
|
||||||
Kocaptcha is a very simple captcha service with a single API endpoint,
|
|
||||||
the source code is here: https://github.com/koto-bank/kocaptcha. The default endpoint
|
|
||||||
`https://captcha.kotobank.ch` is hosted by the developer.
|
|
||||||
|
|
||||||
* `endpoint`: the kocaptcha endpoint to use
|
|
||||||
|
|
||||||
## :admin_token
|
|
||||||
|
|
||||||
Allows to set a token that can be used to authenticate with the admin api without using an actual user by giving it as the 'admin_token' parameter. Example:
|
|
||||||
|
|
||||||
```elixir
|
|
||||||
config :pleroma, :admin_token, "somerandomtoken"
|
|
||||||
```
|
|
||||||
|
|
||||||
You can then do
|
|
||||||
|
|
||||||
```sh
|
|
||||||
curl "http://localhost:4000/api/pleroma/admin/invite_token?admin_token=somerandomtoken"
|
|
||||||
```
|
|
||||||
|
|
||||||
## :pleroma_job_queue
|
|
||||||
|
|
||||||
[Pleroma Job Queue](https://git.pleroma.social/pleroma/pleroma_job_queue) configuration: a list of queues with maximum concurrent jobs.
|
|
||||||
|
|
||||||
Pleroma has the following queues:
|
|
||||||
|
|
||||||
* `federator_outgoing` - Outgoing federation
|
|
||||||
* `federator_incoming` - Incoming federation
|
|
||||||
* `mailer` - Email sender, see [`Pleroma.Emails.Mailer`](#pleroma-emails-mailer)
|
|
||||||
* `transmogrifier` - Transmogrifier
|
|
||||||
* `web_push` - Web push notifications
|
|
||||||
* `scheduled_activities` - Scheduled activities, see [`Pleroma.ScheduledActivities`](#pleromascheduledactivity)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```elixir
|
|
||||||
config :pleroma_job_queue, :queues,
|
|
||||||
federator_incoming: 50,
|
|
||||||
federator_outgoing: 50
|
|
||||||
```
|
|
||||||
|
|
||||||
This config contains two queues: `federator_incoming` and `federator_outgoing`. Both have the `max_jobs` set to `50`.
|
|
||||||
|
|
||||||
## Pleroma.Web.Federator.RetryQueue
|
|
||||||
|
|
||||||
* `enabled`: If set to `true`, failed federation jobs will be retried
|
|
||||||
* `max_jobs`: The maximum amount of parallel federation jobs running at the same time.
|
|
||||||
* `initial_timeout`: The initial timeout in seconds
|
|
||||||
* `max_retries`: The maximum number of times a federation job is retried
|
|
||||||
|
|
||||||
## Pleroma.Web.Metadata
|
|
||||||
* `providers`: a list of metadata providers to enable. Providers available:
|
|
||||||
* Pleroma.Web.Metadata.Providers.OpenGraph
|
|
||||||
* Pleroma.Web.Metadata.Providers.TwitterCard
|
|
||||||
* Pleroma.Web.Metadata.Providers.RelMe - add links from user bio with rel=me into the `<header>` as `<link rel=me>`
|
|
||||||
* `unfurl_nsfw`: If set to `true` nsfw attachments will be shown in previews
|
|
||||||
|
|
||||||
## :rich_media
|
|
||||||
* `enabled`: if enabled the instance will parse metadata from attached links to generate link previews
|
|
||||||
* `ignore_hosts`: list of hosts which will be ignored by the metadata parser. For example `["accounts.google.com", "xss.website"]`, defaults to `[]`.
|
|
||||||
* `ignore_tld`: list TLDs (top-level domains) which will ignore for parse metadata. default is ["local", "localdomain", "lan"]
|
|
||||||
* `parsers`: list of Rich Media parsers
|
|
||||||
|
|
||||||
## :fetch_initial_posts
|
|
||||||
* `enabled`: if enabled, when a new user is federated with, fetch some of their latest posts
|
|
||||||
* `pages`: the amount of pages to fetch
|
|
||||||
|
|
||||||
## :hackney_pools
|
|
||||||
|
|
||||||
Advanced. Tweaks Hackney (http client) connections pools.
|
|
||||||
|
|
||||||
There's three pools used:
|
|
||||||
|
|
||||||
* `:federation` for the federation jobs.
|
|
||||||
You may want this pool max_connections to be at least equal to the number of federator jobs + retry queue jobs.
|
|
||||||
* `:media` for rich media, media proxy
|
|
||||||
* `:upload` for uploaded media (if using a remote uploader and `proxy_remote: true`)
|
|
||||||
|
|
||||||
For each pool, the options are:
|
|
||||||
|
|
||||||
* `max_connections` - how much connections a pool can hold
|
|
||||||
* `timeout` - retention duration for connections
|
|
||||||
|
|
||||||
## :auto_linker
|
|
||||||
|
|
||||||
Configuration for the `auto_linker` library:
|
|
||||||
|
|
||||||
* `class: "auto-linker"` - specify the class to be added to the generated link. false to clear
|
|
||||||
* `rel: "noopener noreferrer"` - override the rel attribute. false to clear
|
|
||||||
* `new_window: true` - set to false to remove `target='_blank'` attribute
|
|
||||||
* `scheme: false` - Set to true to link urls with schema `http://google.com`
|
|
||||||
* `truncate: false` - Set to a number to truncate urls longer then the number. Truncated urls will end in `..`
|
|
||||||
* `strip_prefix: true` - Strip the scheme prefix
|
|
||||||
* `extra: false` - link urls with rarely used schemes (magnet, ipfs, irc, etc.)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```elixir
|
|
||||||
config :auto_linker,
|
|
||||||
opts: [
|
|
||||||
scheme: true,
|
|
||||||
extra: true,
|
|
||||||
class: false,
|
|
||||||
strip_prefix: false,
|
|
||||||
new_window: false,
|
|
||||||
rel: false
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
## Pleroma.ScheduledActivity
|
|
||||||
|
|
||||||
* `daily_user_limit`: the number of scheduled activities a user is allowed to create in a single day (Default: `25`)
|
|
||||||
* `total_user_limit`: the number of scheduled activities a user is allowed to create in total (Default: `300`)
|
|
||||||
* `enabled`: whether scheduled activities are sent to the job queue to be executed
|
|
||||||
|
|
||||||
## Pleroma.ActivityExpiration
|
|
||||||
|
|
||||||
# `enabled`: whether expired activities will be sent to the job queue to be deleted
|
|
||||||
|
|
||||||
## Pleroma.Web.Auth.Authenticator
|
|
||||||
|
|
||||||
* `Pleroma.Web.Auth.PleromaAuthenticator`: default database authenticator
|
|
||||||
* `Pleroma.Web.Auth.LDAPAuthenticator`: LDAP authentication
|
|
||||||
|
|
||||||
## :ldap
|
|
||||||
|
|
||||||
Use LDAP for user authentication. When a user logs in to the Pleroma
|
|
||||||
instance, the name and password will be verified by trying to authenticate
|
|
||||||
(bind) to an LDAP server. If a user exists in the LDAP directory but there
|
|
||||||
is no account with the same name yet on the Pleroma instance then a new
|
|
||||||
Pleroma account will be created with the same name as the LDAP user name.
|
|
||||||
|
|
||||||
* `enabled`: enables LDAP authentication
|
|
||||||
* `host`: LDAP server hostname
|
|
||||||
* `port`: LDAP port, e.g. 389 or 636
|
|
||||||
* `ssl`: true to use SSL, usually implies the port 636
|
|
||||||
* `sslopts`: additional SSL options
|
|
||||||
* `tls`: true to start TLS, usually implies the port 389
|
|
||||||
* `tlsopts`: additional TLS options
|
|
||||||
* `base`: LDAP base, e.g. "dc=example,dc=com"
|
|
||||||
* `uid`: LDAP attribute name to authenticate the user, e.g. when "cn", the filter will be "cn=username,base"
|
|
||||||
|
|
||||||
## BBS / SSH access
|
|
||||||
|
|
||||||
To enable simple command line interface accessible over ssh, add a setting like this to your configuration file:
|
|
||||||
|
|
||||||
```exs
|
|
||||||
app_dir = File.cwd!
|
|
||||||
priv_dir = Path.join([app_dir, "priv/ssh_keys"])
|
|
||||||
|
|
||||||
config :esshd,
|
|
||||||
enabled: true,
|
|
||||||
priv_dir: priv_dir,
|
|
||||||
handler: "Pleroma.BBS.Handler",
|
|
||||||
port: 10_022,
|
|
||||||
password_authenticator: "Pleroma.BBS.Authenticator"
|
|
||||||
```
|
|
||||||
|
|
||||||
Feel free to adjust the priv_dir and port number. Then you will have to create the key for the keys (in the example `priv/ssh_keys`) and create the host keys with `ssh-keygen -m PEM -N "" -b 2048 -t rsa -f ssh_host_rsa_key`. After restarting, you should be able to connect to your Pleroma instance with `ssh username@server -p $PORT`
|
|
||||||
|
|
||||||
## :auth
|
|
||||||
|
|
||||||
* `Pleroma.Web.Auth.PleromaAuthenticator`: default database authenticator
|
|
||||||
* `Pleroma.Web.Auth.LDAPAuthenticator`: LDAP authentication
|
|
||||||
|
|
||||||
Authentication / authorization settings.
|
|
||||||
|
|
||||||
* `auth_template`: authentication form template. By default it's `show.html` which corresponds to `lib/pleroma/web/templates/o_auth/o_auth/show.html.eex`.
|
|
||||||
* `oauth_consumer_template`: OAuth consumer mode authentication form template. By default it's `consumer.html` which corresponds to `lib/pleroma/web/templates/o_auth/o_auth/consumer.html.eex`.
|
|
||||||
* `oauth_consumer_strategies`: the list of enabled OAuth consumer strategies; by default it's set by `OAUTH_CONSUMER_STRATEGIES` environment variable. Each entry in this space-delimited string should be of format `<strategy>` or `<strategy>:<dependency>` (e.g. `twitter` or `keycloak:ueberauth_keycloak_strategy` in case dependency is named differently than `ueberauth_<strategy>`).
|
|
||||||
|
|
||||||
## :email_notifications
|
|
||||||
|
|
||||||
Email notifications settings.
|
|
||||||
|
|
||||||
- digest - emails of "what you've missed" for users who have been
|
|
||||||
inactive for a while.
|
|
||||||
- active: globally enable or disable digest emails
|
|
||||||
- schedule: When to send digest email, in [crontab format](https://en.wikipedia.org/wiki/Cron).
|
|
||||||
"0 0 * * 0" is the default, meaning "once a week at midnight on Sunday morning"
|
|
||||||
- interval: Minimum interval between digest emails to one user
|
|
||||||
- inactivity_threshold: Minimum user inactivity threshold
|
|
||||||
|
|
||||||
## Pleroma.Emails.UserEmail
|
|
||||||
|
|
||||||
- `:logo` - a path to a custom logo. Set it to `nil` to use the default Pleroma logo.
|
|
||||||
- `:styling` - a map with color settings for email templates.
|
|
||||||
|
|
||||||
## OAuth consumer mode
|
|
||||||
|
|
||||||
OAuth consumer mode allows sign in / sign up via external OAuth providers (e.g. Twitter, Facebook, Google, Microsoft, etc.).
|
|
||||||
Implementation is based on Ueberauth; see the list of [available strategies](https://github.com/ueberauth/ueberauth/wiki/List-of-Strategies).
|
|
||||||
|
|
||||||
Note: each strategy is shipped as a separate dependency; in order to get the strategies, run `OAUTH_CONSUMER_STRATEGIES="..." mix deps.get`,
|
|
||||||
e.g. `OAUTH_CONSUMER_STRATEGIES="twitter facebook google microsoft" mix deps.get`.
|
|
||||||
The server should also be started with `OAUTH_CONSUMER_STRATEGIES="..." mix phx.server` in case you enable any strategies.
|
|
||||||
|
|
||||||
Note: each strategy requires separate setup (on external provider side and Pleroma side). Below are the guidelines on setting up most popular strategies.
|
|
||||||
|
|
||||||
Note: make sure that `"SameSite=Lax"` is set in `extra_cookie_attrs` when you have this feature enabled. OAuth consumer mode will not work with `"SameSite=Strict"`
|
|
||||||
|
|
||||||
* For Twitter, [register an app](https://developer.twitter.com/en/apps), configure callback URL to https://<your_host>/oauth/twitter/callback
|
|
||||||
|
|
||||||
* For Facebook, [register an app](https://developers.facebook.com/apps), configure callback URL to https://<your_host>/oauth/facebook/callback, enable Facebook Login service at https://developers.facebook.com/apps/<app_id>/fb-login/settings/
|
|
||||||
|
|
||||||
* For Google, [register an app](https://console.developers.google.com), configure callback URL to https://<your_host>/oauth/google/callback
|
|
||||||
|
|
||||||
* For Microsoft, [register an app](https://portal.azure.com), configure callback URL to https://<your_host>/oauth/microsoft/callback
|
|
||||||
|
|
||||||
Once the app is configured on external OAuth provider side, add app's credentials and strategy-specific settings (if any — e.g. see Microsoft below) to `config/prod.secret.exs`,
|
|
||||||
per strategy's documentation (e.g. [ueberauth_twitter](https://github.com/ueberauth/ueberauth_twitter)). Example config basing on environment variables:
|
|
||||||
|
|
||||||
```elixir
|
|
||||||
# Twitter
|
|
||||||
config :ueberauth, Ueberauth.Strategy.Twitter.OAuth,
|
|
||||||
consumer_key: System.get_env("TWITTER_CONSUMER_KEY"),
|
|
||||||
consumer_secret: System.get_env("TWITTER_CONSUMER_SECRET")
|
|
||||||
|
|
||||||
# Facebook
|
|
||||||
config :ueberauth, Ueberauth.Strategy.Facebook.OAuth,
|
|
||||||
client_id: System.get_env("FACEBOOK_APP_ID"),
|
|
||||||
client_secret: System.get_env("FACEBOOK_APP_SECRET"),
|
|
||||||
redirect_uri: System.get_env("FACEBOOK_REDIRECT_URI")
|
|
||||||
|
|
||||||
# Google
|
|
||||||
config :ueberauth, Ueberauth.Strategy.Google.OAuth,
|
|
||||||
client_id: System.get_env("GOOGLE_CLIENT_ID"),
|
|
||||||
client_secret: System.get_env("GOOGLE_CLIENT_SECRET"),
|
|
||||||
redirect_uri: System.get_env("GOOGLE_REDIRECT_URI")
|
|
||||||
|
|
||||||
# Microsoft
|
|
||||||
config :ueberauth, Ueberauth.Strategy.Microsoft.OAuth,
|
|
||||||
client_id: System.get_env("MICROSOFT_CLIENT_ID"),
|
|
||||||
client_secret: System.get_env("MICROSOFT_CLIENT_SECRET")
|
|
||||||
|
|
||||||
config :ueberauth, Ueberauth,
|
|
||||||
providers: [
|
|
||||||
microsoft: {Ueberauth.Strategy.Microsoft, [callback_params: []]}
|
|
||||||
]
|
|
||||||
|
|
||||||
# Keycloak
|
|
||||||
# Note: make sure to add `keycloak:ueberauth_keycloak_strategy` entry to `OAUTH_CONSUMER_STRATEGIES` environment variable
|
|
||||||
keycloak_url = "https://publicly-reachable-keycloak-instance.org:8080"
|
|
||||||
|
|
||||||
config :ueberauth, Ueberauth.Strategy.Keycloak.OAuth,
|
|
||||||
client_id: System.get_env("KEYCLOAK_CLIENT_ID"),
|
|
||||||
client_secret: System.get_env("KEYCLOAK_CLIENT_SECRET"),
|
|
||||||
site: keycloak_url,
|
|
||||||
authorize_url: "#{keycloak_url}/auth/realms/master/protocol/openid-connect/auth",
|
|
||||||
token_url: "#{keycloak_url}/auth/realms/master/protocol/openid-connect/token",
|
|
||||||
userinfo_url: "#{keycloak_url}/auth/realms/master/protocol/openid-connect/userinfo",
|
|
||||||
token_method: :post
|
|
||||||
|
|
||||||
config :ueberauth, Ueberauth,
|
|
||||||
providers: [
|
|
||||||
keycloak: {Ueberauth.Strategy.Keycloak, [uid_field: :email]}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
## OAuth 2.0 provider - :oauth2
|
|
||||||
|
|
||||||
Configure OAuth 2 provider capabilities:
|
|
||||||
|
|
||||||
* `token_expires_in` - The lifetime in seconds of the access token.
|
|
||||||
* `issue_new_refresh_token` - Keeps old refresh token or generate new refresh token when to obtain an access token.
|
|
||||||
* `clean_expired_tokens` - Enable a background job to clean expired oauth tokens. Defaults to `false`.
|
|
||||||
* `clean_expired_tokens_interval` - Interval to run the job to clean expired tokens. Defaults to `86_400_000` (24 hours).
|
|
||||||
|
|
||||||
## :emoji
|
|
||||||
* `shortcode_globs`: Location of custom emoji files. `*` can be used as a wildcard. Example `["/emoji/custom/**/*.png"]`
|
|
||||||
* `pack_extensions`: A list of file extensions for emojis, when no emoji.txt for a pack is present. Example `[".png", ".gif"]`
|
|
||||||
* `groups`: Emojis are ordered in groups (tags). This is an array of key-value pairs where the key is the groupname and the value the location or array of locations. `*` can be used as a wildcard. Example `[Custom: ["/emoji/*.png", "/emoji/custom/*.png"]]`
|
|
||||||
* `default_manifest`: Location of the JSON-manifest. This manifest contains information about the emoji-packs you can download. Currently only one manifest can be added (no arrays).
|
|
||||||
|
|
||||||
## Database options
|
|
||||||
|
|
||||||
### RUM indexing for full text search
|
|
||||||
* `rum_enabled`: If RUM indexes should be used. Defaults to `false`.
|
|
||||||
|
|
||||||
RUM indexes are an alternative indexing scheme that is not included in PostgreSQL by default. While they may eventually be mainlined, for now they have to be installed as a PostgreSQL extension from https://github.com/postgrespro/rum.
|
|
||||||
|
|
||||||
Their advantage over the standard GIN indexes is that they allow efficient ordering of search results by timestamp, which makes search queries a lot faster on larger servers, by one or two orders of magnitude. They take up around 3 times as much space as GIN indexes.
|
|
||||||
|
|
||||||
To enable them, both the `rum_enabled` flag has to be set and the following special migration has to be run:
|
|
||||||
|
|
||||||
`mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/`
|
|
||||||
|
|
||||||
This will probably take a long time.
|
|
||||||
|
|
||||||
## :rate_limit
|
|
||||||
|
|
||||||
This is an advanced feature and disabled by default.
|
|
||||||
|
|
||||||
A keyword list of rate limiters where a key is a limiter name and value is the limiter configuration. The basic configuration is a tuple where:
|
|
||||||
|
|
||||||
* The first element: `scale` (Integer). The time scale in milliseconds.
|
|
||||||
* The second element: `limit` (Integer). How many requests to limit in the time scale provided.
|
|
||||||
|
|
||||||
It is also possible to have different limits for unauthenticated and authenticated users: the keyword value must be a list of two tuples where the first one is a config for unauthenticated users and the second one is for authenticated.
|
|
||||||
|
|
||||||
See [`Pleroma.Plugs.RateLimiter`](Pleroma.Plugs.RateLimiter.html) documentation for examples.
|
|
||||||
|
|
||||||
Supported rate limiters:
|
|
||||||
|
|
||||||
* `:search` for the search requests (account & status search etc.)
|
|
||||||
* `:app_account_creation` for registering user accounts from the same IP address
|
|
||||||
* `:relations_actions` for actions on relations with all users (follow, unfollow)
|
|
||||||
* `:relation_id_action` for actions on relation with a specific user (follow, unfollow)
|
|
||||||
* `:statuses_actions` for create / delete / fav / unfav / reblog / unreblog actions on any statuses
|
|
||||||
* `:status_id_action` for fav / unfav or reblog / unreblog actions on the same status by the same user
|
|
||||||
|
|
|
@ -71,26 +71,26 @@ server {
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
proxy_set_header Host $http_host;
|
proxy_set_header Host $http_host;
|
||||||
|
|
||||||
# this is explicitly IPv4 since Pleroma.Web.Endpoint binds on IPv4 only
|
# this is explicitly IPv4 since Pleroma.Web.Endpoint binds on IPv4 only
|
||||||
# and `localhost.` resolves to [::0] on some systems: see issue #930
|
# and `localhost.` resolves to [::0] on some systems: see issue #930
|
||||||
proxy_pass http://127.0.0.1:4000;
|
proxy_pass http://127.0.0.1:4000;
|
||||||
|
|
||||||
client_max_body_size 16m;
|
client_max_body_size 16m;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~ ^/(media|proxy) {
|
location ~ ^/(media|proxy) {
|
||||||
proxy_cache pleroma_media_cache;
|
proxy_cache pleroma_media_cache;
|
||||||
slice 1m;
|
slice 1m;
|
||||||
proxy_cache_key $host$uri$is_args$args$slice_range;
|
proxy_cache_key $host$uri$is_args$args$slice_range;
|
||||||
proxy_set_header Range $slice_range;
|
proxy_set_header Range $slice_range;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_cache_valid 200 206 301 304 1h;
|
proxy_cache_valid 200 206 301 304 1h;
|
||||||
proxy_cache_lock on;
|
proxy_cache_lock on;
|
||||||
proxy_ignore_client_abort on;
|
proxy_ignore_client_abort on;
|
||||||
proxy_buffering on;
|
proxy_buffering on;
|
||||||
chunked_transfer_encoding on;
|
chunked_transfer_encoding on;
|
||||||
proxy_ignore_headers Cache-Control;
|
proxy_ignore_headers Cache-Control;
|
||||||
proxy_hide_header Cache-Control;
|
proxy_hide_header Cache-Control;
|
||||||
proxy_pass http://localhost:4000;
|
proxy_pass http://127.0.0.1:4000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ def run(["tag"]) do
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["render_timeline", nickname]) do
|
def run(["render_timeline", nickname | _] = args) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
user = Pleroma.User.get_by_nickname(nickname)
|
user = Pleroma.User.get_by_nickname(nickname)
|
||||||
|
|
||||||
|
@ -37,33 +37,37 @@ def run(["render_timeline", nickname]) do
|
||||||
|> Map.put("blocking_user", user)
|
|> Map.put("blocking_user", user)
|
||||||
|> Map.put("muting_user", user)
|
|> Map.put("muting_user", user)
|
||||||
|> Map.put("user", user)
|
|> Map.put("user", user)
|
||||||
|> Map.put("limit", 80)
|
|> Map.put("limit", 4096)
|
||||||
|> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
|
|> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
|
||||||
|> Enum.reverse()
|
|> Enum.reverse()
|
||||||
|
|
||||||
inputs = %{
|
inputs = %{
|
||||||
"One activity" => Enum.take_random(activities, 1),
|
"1 activity" => Enum.take_random(activities, 1),
|
||||||
"Ten activities" => Enum.take_random(activities, 10),
|
"10 activities" => Enum.take_random(activities, 10),
|
||||||
"Twenty activities" => Enum.take_random(activities, 20),
|
"20 activities" => Enum.take_random(activities, 20),
|
||||||
"Forty activities" => Enum.take_random(activities, 40),
|
"40 activities" => Enum.take_random(activities, 40),
|
||||||
"Eighty activities" => Enum.take_random(activities, 80)
|
"80 activities" => Enum.take_random(activities, 80)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inputs =
|
||||||
|
if Enum.at(args, 2) == "extended" do
|
||||||
|
Map.merge(inputs, %{
|
||||||
|
"200 activities" => Enum.take_random(activities, 200),
|
||||||
|
"500 activities" => Enum.take_random(activities, 500),
|
||||||
|
"2000 activities" => Enum.take_random(activities, 2000),
|
||||||
|
"4096 activities" => Enum.take_random(activities, 4096)
|
||||||
|
})
|
||||||
|
else
|
||||||
|
inputs
|
||||||
|
end
|
||||||
|
|
||||||
Benchee.run(
|
Benchee.run(
|
||||||
%{
|
%{
|
||||||
"Parallel rendering" => fn activities ->
|
|
||||||
Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
|
|
||||||
activities: activities,
|
|
||||||
for: user,
|
|
||||||
as: :activity
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
"Standart rendering" => fn activities ->
|
"Standart rendering" => fn activities ->
|
||||||
Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
|
Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
|
||||||
activities: activities,
|
activities: activities,
|
||||||
for: user,
|
for: user,
|
||||||
as: :activity,
|
as: :activity
|
||||||
parallel: false
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|
42
lib/mix/tasks/pleroma/docs.ex
Normal file
42
lib/mix/tasks/pleroma/docs.ex
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
defmodule Mix.Tasks.Pleroma.Docs do
|
||||||
|
use Mix.Task
|
||||||
|
import Mix.Pleroma
|
||||||
|
|
||||||
|
@shortdoc "Generates docs from descriptions.exs"
|
||||||
|
@moduledoc """
|
||||||
|
Generates docs from `descriptions.exs`.
|
||||||
|
|
||||||
|
Supports two formats: `markdown` and `json`.
|
||||||
|
|
||||||
|
## Generate Markdown docs
|
||||||
|
|
||||||
|
`mix pleroma.docs`
|
||||||
|
|
||||||
|
## Generate JSON docs
|
||||||
|
|
||||||
|
`mix pleroma.docs json`
|
||||||
|
"""
|
||||||
|
|
||||||
|
def run(["json"]) do
|
||||||
|
do_run(Pleroma.Docs.JSON)
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(_) do
|
||||||
|
do_run(Pleroma.Docs.Markdown)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp do_run(implementation) do
|
||||||
|
start_pleroma()
|
||||||
|
|
||||||
|
with {descriptions, _paths} <- Mix.Config.eval!("config/description.exs"),
|
||||||
|
{:ok, file_path} <-
|
||||||
|
Pleroma.Docs.Generator.process(
|
||||||
|
implementation,
|
||||||
|
descriptions[:pleroma][:config_description]
|
||||||
|
) do
|
||||||
|
type = if implementation == Pleroma.Docs.Markdown, do: "Markdown", else: "JSON"
|
||||||
|
|
||||||
|
Mix.shell().info([:green, "#{type} docs successfully generated to #{file_path}."])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -173,6 +173,13 @@ def get_by_id_with_object(id) do
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def all_by_ids_with_object(ids) do
|
||||||
|
Activity
|
||||||
|
|> where([a], a.id in ^ids)
|
||||||
|
|> with_preloaded_object()
|
||||||
|
|> Repo.all()
|
||||||
|
end
|
||||||
|
|
||||||
def by_object_ap_id(ap_id) do
|
def by_object_ap_id(ap_id) do
|
||||||
from(
|
from(
|
||||||
activity in Activity,
|
activity in Activity,
|
||||||
|
@ -308,10 +315,19 @@ def delete_by_ap_id(id) when is_binary(id) do
|
||||||
%{data: %{"type" => "Create", "object" => %{"id" => ap_id}}} -> ap_id == id
|
%{data: %{"type" => "Create", "object" => %{"id" => ap_id}}} -> ap_id == id
|
||||||
_ -> nil
|
_ -> nil
|
||||||
end)
|
end)
|
||||||
|
|> purge_web_resp_cache()
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_by_ap_id(_), do: nil
|
def delete_by_ap_id(_), do: nil
|
||||||
|
|
||||||
|
defp purge_web_resp_cache(%Activity{} = activity) do
|
||||||
|
%{path: path} = URI.parse(activity.data["id"])
|
||||||
|
Cachex.del(:web_resp_cache, path)
|
||||||
|
activity
|
||||||
|
end
|
||||||
|
|
||||||
|
defp purge_web_resp_cache(nil), do: nil
|
||||||
|
|
||||||
for {ap_type, type} <- @mastodon_notification_types do
|
for {ap_type, type} <- @mastodon_notification_types do
|
||||||
def mastodon_notification_type(%Activity{data: %{"type" => unquote(ap_type)}}),
|
def mastodon_notification_type(%Activity{data: %{"type" => unquote(ap_type)}}),
|
||||||
do: unquote(type)
|
do: unquote(type)
|
||||||
|
@ -362,12 +378,12 @@ def query_by_actor(actor) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def restrict_deactivated_users(query) do
|
def restrict_deactivated_users(query) do
|
||||||
|
deactivated_users =
|
||||||
|
from(u in User.Query.build(deactivated: true), select: u.ap_id)
|
||||||
|
|> Repo.all()
|
||||||
|
|
||||||
from(activity in query,
|
from(activity in query,
|
||||||
where:
|
where: activity.actor not in ^deactivated_users
|
||||||
fragment(
|
|
||||||
"? not in (SELECT ap_id FROM users WHERE info->'deactivated' @> 'true')",
|
|
||||||
activity.actor
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,8 @@ defp cachex_children do
|
||||||
build_cachex("object", default_ttl: 25_000, ttl_interval: 1000, limit: 2500),
|
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("rich_media", default_ttl: :timer.minutes(120), limit: 5000),
|
||||||
build_cachex("scrubber", limit: 2500),
|
build_cachex("scrubber", limit: 2500),
|
||||||
build_cachex("idempotency", expiration: idempotency_expiration(), limit: 2500)
|
build_cachex("idempotency", expiration: idempotency_expiration(), limit: 2500),
|
||||||
|
build_cachex("web_resp", limit: 2500)
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
73
lib/pleroma/docs/generator.ex
Normal file
73
lib/pleroma/docs/generator.ex
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
defmodule Pleroma.Docs.Generator do
|
||||||
|
@callback process(keyword()) :: {:ok, String.t()}
|
||||||
|
|
||||||
|
@spec process(module(), keyword()) :: {:ok, String.t()}
|
||||||
|
def process(implementation, descriptions) do
|
||||||
|
implementation.process(descriptions)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec uploaders_list() :: [module()]
|
||||||
|
def uploaders_list do
|
||||||
|
{:ok, modules} = :application.get_key(:pleroma, :modules)
|
||||||
|
|
||||||
|
Enum.filter(modules, fn module ->
|
||||||
|
name_as_list = Module.split(module)
|
||||||
|
|
||||||
|
List.starts_with?(name_as_list, ["Pleroma", "Uploaders"]) and
|
||||||
|
List.last(name_as_list) != "Uploader"
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec filters_list() :: [module()]
|
||||||
|
def filters_list do
|
||||||
|
{:ok, modules} = :application.get_key(:pleroma, :modules)
|
||||||
|
|
||||||
|
Enum.filter(modules, fn module ->
|
||||||
|
name_as_list = Module.split(module)
|
||||||
|
|
||||||
|
List.starts_with?(name_as_list, ["Pleroma", "Upload", "Filter"])
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec mrf_list() :: [module()]
|
||||||
|
def mrf_list do
|
||||||
|
{:ok, modules} = :application.get_key(:pleroma, :modules)
|
||||||
|
|
||||||
|
Enum.filter(modules, fn module ->
|
||||||
|
name_as_list = Module.split(module)
|
||||||
|
|
||||||
|
List.starts_with?(name_as_list, ["Pleroma", "Web", "ActivityPub", "MRF"]) and
|
||||||
|
length(name_as_list) > 4
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec richmedia_parsers() :: [module()]
|
||||||
|
def richmedia_parsers do
|
||||||
|
{:ok, modules} = :application.get_key(:pleroma, :modules)
|
||||||
|
|
||||||
|
Enum.filter(modules, fn module ->
|
||||||
|
name_as_list = Module.split(module)
|
||||||
|
|
||||||
|
List.starts_with?(name_as_list, ["Pleroma", "Web", "RichMedia", "Parsers"]) and
|
||||||
|
length(name_as_list) == 5
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defimpl Jason.Encoder, for: Tuple do
|
||||||
|
def encode(tuple, opts) do
|
||||||
|
Jason.Encode.list(Tuple.to_list(tuple), opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defimpl Jason.Encoder, for: [Regex, Function] do
|
||||||
|
def encode(term, opts) do
|
||||||
|
Jason.Encode.string(inspect(term), opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defimpl String.Chars, for: Regex do
|
||||||
|
def to_string(term) do
|
||||||
|
inspect(term)
|
||||||
|
end
|
||||||
|
end
|
20
lib/pleroma/docs/json.ex
Normal file
20
lib/pleroma/docs/json.ex
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
defmodule Pleroma.Docs.JSON do
|
||||||
|
@behaviour Pleroma.Docs.Generator
|
||||||
|
|
||||||
|
@spec process(keyword()) :: {:ok, String.t()}
|
||||||
|
def process(descriptions) do
|
||||||
|
config_path = "docs/generate_config.json"
|
||||||
|
|
||||||
|
with {:ok, file} <- File.open(config_path, [:write]),
|
||||||
|
json <- generate_json(descriptions),
|
||||||
|
:ok <- IO.write(file, json),
|
||||||
|
:ok <- File.close(file) do
|
||||||
|
{:ok, config_path}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec generate_json([keyword()]) :: String.t()
|
||||||
|
def generate_json(descriptions) do
|
||||||
|
Jason.encode!(descriptions)
|
||||||
|
end
|
||||||
|
end
|
78
lib/pleroma/docs/markdown.ex
Normal file
78
lib/pleroma/docs/markdown.ex
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
defmodule Pleroma.Docs.Markdown do
|
||||||
|
@behaviour Pleroma.Docs.Generator
|
||||||
|
|
||||||
|
@spec process(keyword()) :: {:ok, String.t()}
|
||||||
|
def process(descriptions) do
|
||||||
|
config_path = "docs/config.md"
|
||||||
|
{:ok, file} = File.open(config_path, [:utf8, :write])
|
||||||
|
IO.write(file, "# Configuration\n")
|
||||||
|
IO.write(file, "Date of generation: #{Date.utc_today()}\n\n")
|
||||||
|
|
||||||
|
IO.write(
|
||||||
|
file,
|
||||||
|
"This file describe the configuration, it is recommended to edit the relevant `*.secret.exs` file instead of the others founds in the ``config`` directory.\n\n" <>
|
||||||
|
"If you run Pleroma with ``MIX_ENV=prod`` the file is ``prod.secret.exs``, otherwise it is ``dev.secret.exs``.\n\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
for group <- descriptions do
|
||||||
|
if is_nil(group[:key]) do
|
||||||
|
IO.write(file, "## #{inspect(group[:group])}\n")
|
||||||
|
else
|
||||||
|
IO.write(file, "## #{inspect(group[:key])}\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
IO.write(file, "#{group[:description]}\n")
|
||||||
|
|
||||||
|
for child <- group[:children] do
|
||||||
|
print_child_header(file, child)
|
||||||
|
|
||||||
|
print_suggestions(file, child[:suggestions])
|
||||||
|
|
||||||
|
if child[:children] do
|
||||||
|
for subchild <- child[:children] do
|
||||||
|
print_child_header(file, subchild)
|
||||||
|
|
||||||
|
print_suggestions(file, subchild[:suggestions])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
IO.write(file, "\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
:ok = File.close(file)
|
||||||
|
{:ok, config_path}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp print_suggestion(file, suggestion) when is_list(suggestion) do
|
||||||
|
IO.write(file, " `#{inspect(suggestion)}`\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
defp print_suggestion(file, suggestion) when is_function(suggestion) do
|
||||||
|
IO.write(file, " `#{inspect(suggestion.())}`\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
defp print_suggestion(file, suggestion, as_list \\ false) do
|
||||||
|
list_mark = if as_list, do: "- ", else: ""
|
||||||
|
IO.write(file, " #{list_mark}`#{inspect(suggestion)}`\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
defp print_suggestions(_file, nil), do: nil
|
||||||
|
|
||||||
|
defp print_suggestions(file, suggestions) do
|
||||||
|
IO.write(file, "Suggestions:\n")
|
||||||
|
|
||||||
|
if length(suggestions) > 1 do
|
||||||
|
for suggestion <- suggestions do
|
||||||
|
print_suggestion(file, suggestion, true)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print_suggestion(file, List.first(suggestions))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp print_child_header(file, child) do
|
||||||
|
IO.write(file, "- `#{inspect(child[:key])}` -`#{inspect(child[:type])}` \n")
|
||||||
|
IO.write(file, "#{child[:description]} \n")
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Healthcheck do
|
||||||
alias Pleroma.Healthcheck
|
alias Pleroma.Healthcheck
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
|
||||||
|
@derive Jason.Encoder
|
||||||
defstruct pool_size: 0,
|
defstruct pool_size: 0,
|
||||||
active: 0,
|
active: 0,
|
||||||
idle: 0,
|
idle: 0,
|
|
@ -102,15 +102,33 @@ def set_read_up_to(%{id: user_id} = _user, id) do
|
||||||
n in Notification,
|
n in Notification,
|
||||||
where: n.user_id == ^user_id,
|
where: n.user_id == ^user_id,
|
||||||
where: n.id <= ^id,
|
where: n.id <= ^id,
|
||||||
|
where: n.seen == false,
|
||||||
update: [
|
update: [
|
||||||
set: [
|
set: [
|
||||||
seen: true,
|
seen: true,
|
||||||
updated_at: ^NaiveDateTime.utc_now()
|
updated_at: ^NaiveDateTime.utc_now()
|
||||||
]
|
]
|
||||||
]
|
],
|
||||||
|
# Ideally we would preload object and activities here
|
||||||
|
# but Ecto does not support preloads in update_all
|
||||||
|
select: n.id
|
||||||
)
|
)
|
||||||
|
|
||||||
Repo.update_all(query, [])
|
{_, notification_ids} = Repo.update_all(query, [])
|
||||||
|
|
||||||
|
Notification
|
||||||
|
|> where([n], n.id in ^notification_ids)
|
||||||
|
|> join(:inner, [n], activity in assoc(n, :activity))
|
||||||
|
|> join(:left, [n, a], object in Object,
|
||||||
|
on:
|
||||||
|
fragment(
|
||||||
|
"(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)",
|
||||||
|
object.data,
|
||||||
|
a.data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|> preload([n, a, o], activity: {a, object: o})
|
||||||
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_one(%User{} = user, notification_id) do
|
def read_one(%User{} = user, notification_id) do
|
||||||
|
|
|
@ -130,14 +130,16 @@ def swap_object_with_tombstone(object) do
|
||||||
def delete(%Object{data: %{"id" => id}} = object) do
|
def delete(%Object{data: %{"id" => id}} = object) do
|
||||||
with {:ok, _obj} = swap_object_with_tombstone(object),
|
with {:ok, _obj} = swap_object_with_tombstone(object),
|
||||||
deleted_activity = Activity.delete_by_ap_id(id),
|
deleted_activity = Activity.delete_by_ap_id(id),
|
||||||
{:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do
|
{:ok, true} <- Cachex.del(:object_cache, "object:#{id}"),
|
||||||
|
{:ok, _} <- Cachex.del(:web_resp_cache, URI.parse(id).path) do
|
||||||
{:ok, object, deleted_activity}
|
{:ok, object, deleted_activity}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def prune(%Object{data: %{"id" => id}} = object) do
|
def prune(%Object{data: %{"id" => id}} = object) do
|
||||||
with {:ok, object} <- Repo.delete(object),
|
with {:ok, object} <- Repo.delete(object),
|
||||||
{:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do
|
{:ok, true} <- Cachex.del(:object_cache, "object:#{id}"),
|
||||||
|
{:ok, _} <- Cachex.del(:web_resp_cache, URI.parse(id).path) do
|
||||||
{:ok, object}
|
{:ok, object}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,15 @@ defmodule Pleroma.Pagination do
|
||||||
|
|
||||||
def fetch_paginated(query, params, type \\ :keyset)
|
def fetch_paginated(query, params, type \\ :keyset)
|
||||||
|
|
||||||
|
def fetch_paginated(query, %{"total" => true} = params, :keyset) do
|
||||||
|
total = Repo.aggregate(query, :count, :id)
|
||||||
|
|
||||||
|
%{
|
||||||
|
total: total,
|
||||||
|
items: fetch_paginated(query, Map.drop(params, ["total"]), :keyset)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_paginated(query, params, :keyset) do
|
def fetch_paginated(query, params, :keyset) do
|
||||||
options = cast_params(params)
|
options = cast_params(params)
|
||||||
|
|
||||||
|
@ -25,6 +34,15 @@ def fetch_paginated(query, params, :keyset) do
|
||||||
|> enforce_order(options)
|
|> enforce_order(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fetch_paginated(query, %{"total" => true} = params, :offset) do
|
||||||
|
total = Repo.aggregate(query, :count, :id)
|
||||||
|
|
||||||
|
%{
|
||||||
|
total: total,
|
||||||
|
items: fetch_paginated(query, Map.drop(params, ["total"]), :offset)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_paginated(query, params, :offset) do
|
def fetch_paginated(query, params, :offset) do
|
||||||
options = cast_params(params)
|
options = cast_params(params)
|
||||||
|
|
||||||
|
|
122
lib/pleroma/plugs/cache.ex
Normal file
122
lib/pleroma/plugs/cache.ex
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Plugs.Cache do
|
||||||
|
@moduledoc """
|
||||||
|
Caches successful GET responses.
|
||||||
|
|
||||||
|
To enable the cache add the plug to a router pipeline or controller:
|
||||||
|
|
||||||
|
plug(Pleroma.Plugs.Cache)
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
To configure the plug you need to pass settings as the second argument to the `plug/2` macro:
|
||||||
|
|
||||||
|
plug(Pleroma.Plugs.Cache, [ttl: nil, query_params: true])
|
||||||
|
|
||||||
|
Available options:
|
||||||
|
|
||||||
|
- `ttl`: An expiration time (time-to-live). This value should be in milliseconds or `nil` to disable expiration. Defaults to `nil`.
|
||||||
|
- `query_params`: Take URL query string into account (`true`), ignore it (`false`) or limit to specific params only (list). Defaults to `true`.
|
||||||
|
|
||||||
|
Additionally, you can overwrite the TTL inside a controller action by assigning `cache_ttl` to the connection struct:
|
||||||
|
|
||||||
|
def index(conn, _params) do
|
||||||
|
ttl = 60_000 # one minute
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> assign(:cache_ttl, ttl)
|
||||||
|
|> render("index.html")
|
||||||
|
end
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import Phoenix.Controller, only: [current_path: 1, json: 2]
|
||||||
|
import Plug.Conn
|
||||||
|
|
||||||
|
@behaviour Plug
|
||||||
|
|
||||||
|
@defaults %{ttl: nil, query_params: true}
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def init([]), do: @defaults
|
||||||
|
|
||||||
|
def init(opts) do
|
||||||
|
opts = Map.new(opts)
|
||||||
|
Map.merge(@defaults, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def call(%{method: "GET"} = conn, opts) do
|
||||||
|
key = cache_key(conn, opts)
|
||||||
|
|
||||||
|
case Cachex.get(:web_resp_cache, key) do
|
||||||
|
{:ok, nil} ->
|
||||||
|
cache_resp(conn, opts)
|
||||||
|
|
||||||
|
{:ok, record} ->
|
||||||
|
send_cached(conn, record)
|
||||||
|
|
||||||
|
{atom, message} when atom in [:ignore, :error] ->
|
||||||
|
render_error(conn, message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(conn, _), do: conn
|
||||||
|
|
||||||
|
# full path including query params
|
||||||
|
defp cache_key(conn, %{query_params: true}), do: current_path(conn)
|
||||||
|
|
||||||
|
# request path without query params
|
||||||
|
defp cache_key(conn, %{query_params: false}), do: conn.request_path
|
||||||
|
|
||||||
|
# request path with specific query params
|
||||||
|
defp cache_key(conn, %{query_params: query_params}) when is_list(query_params) do
|
||||||
|
query_string =
|
||||||
|
conn.params
|
||||||
|
|> Map.take(query_params)
|
||||||
|
|> URI.encode_query()
|
||||||
|
|
||||||
|
conn.request_path <> "?" <> query_string
|
||||||
|
end
|
||||||
|
|
||||||
|
defp cache_resp(conn, opts) do
|
||||||
|
register_before_send(conn, fn
|
||||||
|
%{status: 200, resp_body: body} = conn ->
|
||||||
|
ttl = Map.get(conn.assigns, :cache_ttl, opts.ttl)
|
||||||
|
key = cache_key(conn, opts)
|
||||||
|
content_type = content_type(conn)
|
||||||
|
record = {content_type, body}
|
||||||
|
|
||||||
|
Cachex.put(:web_resp_cache, key, record, ttl: ttl)
|
||||||
|
|
||||||
|
put_resp_header(conn, "x-cache", "MISS from Pleroma")
|
||||||
|
|
||||||
|
conn ->
|
||||||
|
conn
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp content_type(conn) do
|
||||||
|
conn
|
||||||
|
|> Plug.Conn.get_resp_header("content-type")
|
||||||
|
|> hd()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp send_cached(conn, {content_type, body}) do
|
||||||
|
conn
|
||||||
|
|> put_resp_content_type(content_type, nil)
|
||||||
|
|> put_resp_header("x-cache", "HIT from Pleroma")
|
||||||
|
|> send_resp(:ok, body)
|
||||||
|
|> halt()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp render_error(conn, message) do
|
||||||
|
conn
|
||||||
|
|> put_status(:internal_server_error)
|
||||||
|
|> json(%{error: message})
|
||||||
|
|> halt()
|
||||||
|
end
|
||||||
|
end
|
41
lib/pleroma/plugs/trailing_format_plug.ex
Normal file
41
lib/pleroma/plugs/trailing_format_plug.ex
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Plugs.TrailingFormatPlug do
|
||||||
|
@moduledoc "Calls TrailingFormatPlug for specific paths. Ideally we would just do this in the router, but TrailingFormatPlug needs to be called before Plug.Parsers."
|
||||||
|
|
||||||
|
@behaviour Plug
|
||||||
|
@paths [
|
||||||
|
"/api/statusnet",
|
||||||
|
"/api/statuses",
|
||||||
|
"/api/qvitter",
|
||||||
|
"/api/search",
|
||||||
|
"/api/account",
|
||||||
|
"/api/friends",
|
||||||
|
"/api/mutes",
|
||||||
|
"/api/media",
|
||||||
|
"/api/favorites",
|
||||||
|
"/api/blocks",
|
||||||
|
"/api/friendships",
|
||||||
|
"/api/users",
|
||||||
|
"/users",
|
||||||
|
"/nodeinfo",
|
||||||
|
"/api/help",
|
||||||
|
"/api/externalprofile",
|
||||||
|
"/notice",
|
||||||
|
"/api/pleroma/emoji"
|
||||||
|
]
|
||||||
|
|
||||||
|
def init(opts) do
|
||||||
|
TrailingFormatPlug.init(opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
for path <- @paths do
|
||||||
|
def call(%{request_path: unquote(path) <> _} = conn, opts) do
|
||||||
|
TrailingFormatPlug.call(conn, opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(conn, _opts), do: conn
|
||||||
|
end
|
|
@ -569,8 +569,22 @@ def get_cached_by_nickname(nickname) do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_cached_by_nickname_or_id(nickname_or_id) do
|
def get_cached_by_nickname_or_id(nickname_or_id, opts \\ []) do
|
||||||
get_cached_by_id(nickname_or_id) || get_cached_by_nickname(nickname_or_id)
|
restrict_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
|
||||||
|
|
||||||
|
cond do
|
||||||
|
is_integer(nickname_or_id) or Pleroma.FlakeId.is_flake_id?(nickname_or_id) ->
|
||||||
|
get_cached_by_id(nickname_or_id) || get_cached_by_nickname(nickname_or_id)
|
||||||
|
|
||||||
|
restrict_to_local == false ->
|
||||||
|
get_cached_by_nickname(nickname_or_id)
|
||||||
|
|
||||||
|
restrict_to_local == :unauthenticated and match?(%User{}, opts[:for]) ->
|
||||||
|
get_cached_by_nickname(nickname_or_id)
|
||||||
|
|
||||||
|
true ->
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_by_nickname(nickname) do
|
def get_by_nickname(nickname) do
|
||||||
|
@ -1610,4 +1624,13 @@ defp put_password_hash(changeset), do: changeset
|
||||||
def is_internal_user?(%User{nickname: nil}), do: true
|
def is_internal_user?(%User{nickname: nil}), do: true
|
||||||
def is_internal_user?(%User{local: true, nickname: "internal." <> _}), do: true
|
def is_internal_user?(%User{local: true, nickname: "internal." <> _}), do: true
|
||||||
def is_internal_user?(_), do: false
|
def is_internal_user?(_), do: false
|
||||||
|
|
||||||
|
def change_email(user, email) do
|
||||||
|
user
|
||||||
|
|> cast(%{email: email}, [:email])
|
||||||
|
|> validate_required([:email])
|
||||||
|
|> unique_constraint(:email)
|
||||||
|
|> validate_format(:email, @email_regex)
|
||||||
|
|> update_and_set_cache()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -807,7 +807,7 @@ defp restrict_muted(query, %{"muting_user" => %User{info: info}} = opts) do
|
||||||
)
|
)
|
||||||
|
|
||||||
unless opts["skip_preload"] do
|
unless opts["skip_preload"] do
|
||||||
from([thread_mute: tm] in query, where: is_nil(tm))
|
from([thread_mute: tm] in query, where: is_nil(tm.user_id))
|
||||||
else
|
else
|
||||||
query
|
query
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,6 +23,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|
||||||
|
|
||||||
action_fallback(:errors)
|
action_fallback(:errors)
|
||||||
|
|
||||||
|
plug(Pleroma.Plugs.Cache, [query_params: false] when action in [:activity, :object])
|
||||||
plug(Pleroma.Web.FederatingPlug when action in [:inbox, :relay])
|
plug(Pleroma.Web.FederatingPlug when action in [:inbox, :relay])
|
||||||
plug(:set_requester_reachable when action in [:inbox])
|
plug(:set_requester_reachable when action in [:inbox])
|
||||||
plug(:relay_active? when action in [:relay])
|
plug(:relay_active? when action in [:relay])
|
||||||
|
@ -53,8 +54,10 @@ def object(conn, %{"uuid" => uuid}) do
|
||||||
%Object{} = object <- Object.get_cached_by_ap_id(ap_id),
|
%Object{} = object <- Object.get_cached_by_ap_id(ap_id),
|
||||||
{_, true} <- {:public?, Visibility.is_public?(object)} do
|
{_, true} <- {:public?, Visibility.is_public?(object)} do
|
||||||
conn
|
conn
|
||||||
|
|> set_cache_ttl_for(object)
|
||||||
|> put_resp_content_type("application/activity+json")
|
|> put_resp_content_type("application/activity+json")
|
||||||
|> json(ObjectView.render("object.json", %{object: object}))
|
|> put_view(ObjectView)
|
||||||
|
|> render("object.json", object: object)
|
||||||
else
|
else
|
||||||
{:public?, false} ->
|
{:public?, false} ->
|
||||||
{:error, :not_found}
|
{:error, :not_found}
|
||||||
|
@ -96,14 +99,36 @@ def activity(conn, %{"uuid" => uuid}) do
|
||||||
%Activity{} = activity <- Activity.normalize(ap_id),
|
%Activity{} = activity <- Activity.normalize(ap_id),
|
||||||
{_, true} <- {:public?, Visibility.is_public?(activity)} do
|
{_, true} <- {:public?, Visibility.is_public?(activity)} do
|
||||||
conn
|
conn
|
||||||
|
|> set_cache_ttl_for(activity)
|
||||||
|> put_resp_content_type("application/activity+json")
|
|> put_resp_content_type("application/activity+json")
|
||||||
|> json(ObjectView.render("object.json", %{object: activity}))
|
|> put_view(ObjectView)
|
||||||
|
|> render("object.json", object: activity)
|
||||||
else
|
else
|
||||||
{:public?, false} ->
|
{:public?, false} -> {:error, :not_found}
|
||||||
{:error, :not_found}
|
nil -> {:error, :not_found}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp set_cache_ttl_for(conn, %Activity{object: object}) do
|
||||||
|
set_cache_ttl_for(conn, object)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp set_cache_ttl_for(conn, entity) do
|
||||||
|
ttl =
|
||||||
|
case entity do
|
||||||
|
%Object{data: %{"type" => "Question"}} ->
|
||||||
|
Pleroma.Config.get([:web_cache_ttl, :activity_pub_question])
|
||||||
|
|
||||||
|
%Object{} ->
|
||||||
|
Pleroma.Config.get([:web_cache_ttl, :activity_pub])
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
assign(conn, :cache_ttl, ttl)
|
||||||
|
end
|
||||||
|
|
||||||
# GET /relay/following
|
# GET /relay/following
|
||||||
def following(%{assigns: %{relay: true}} = conn, _params) do
|
def following(%{assigns: %{relay: true}} = conn, _params) do
|
||||||
conn
|
conn
|
||||||
|
@ -251,22 +276,36 @@ def whoami(%{assigns: %{user: %User{} = user}} = conn, _params) do
|
||||||
|
|
||||||
def whoami(_conn, _params), do: {:error, :not_found}
|
def whoami(_conn, _params), do: {:error, :not_found}
|
||||||
|
|
||||||
def read_inbox(%{assigns: %{user: user}} = conn, %{"nickname" => nickname} = params) do
|
def read_inbox(
|
||||||
if nickname == user.nickname do
|
%{assigns: %{user: %{nickname: nickname} = user}} = conn,
|
||||||
conn
|
%{"nickname" => nickname} = params
|
||||||
|> put_resp_content_type("application/activity+json")
|
) do
|
||||||
|> json(UserView.render("inbox.json", %{user: user, max_id: params["max_id"]}))
|
conn
|
||||||
else
|
|> put_resp_content_type("application/activity+json")
|
||||||
err =
|
|> put_view(UserView)
|
||||||
dgettext("errors", "can't read inbox of %{nickname} as %{as_nickname}",
|
|> render("inbox.json", user: user, max_id: params["max_id"])
|
||||||
nickname: nickname,
|
end
|
||||||
as_nickname: user.nickname
|
|
||||||
)
|
|
||||||
|
|
||||||
conn
|
def read_inbox(%{assigns: %{user: nil}} = conn, %{"nickname" => nickname}) do
|
||||||
|> put_status(:forbidden)
|
err = dgettext("errors", "can't read inbox of %{nickname}", nickname: nickname)
|
||||||
|> json(err)
|
|
||||||
end
|
conn
|
||||||
|
|> put_status(:forbidden)
|
||||||
|
|> json(err)
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_inbox(%{assigns: %{user: %{nickname: as_nickname}}} = conn, %{
|
||||||
|
"nickname" => nickname
|
||||||
|
}) do
|
||||||
|
err =
|
||||||
|
dgettext("errors", "can't read inbox of %{nickname} as %{as_nickname}",
|
||||||
|
nickname: nickname,
|
||||||
|
as_nickname: as_nickname
|
||||||
|
)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_status(:forbidden)
|
||||||
|
|> json(err)
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_user_activity(user, %{"type" => "Create"} = params) do
|
def handle_user_activity(user, %{"type" => "Create"} = params) do
|
||||||
|
|
|
@ -25,11 +25,15 @@ defp score_displayname("fedibot"), do: 1.0
|
||||||
defp score_displayname(_), do: 0.0
|
defp score_displayname(_), do: 0.0
|
||||||
|
|
||||||
defp determine_if_followbot(%User{nickname: nickname, name: displayname}) do
|
defp determine_if_followbot(%User{nickname: nickname, name: displayname}) do
|
||||||
# nickname will always be a binary string because it's generated by Pleroma.
|
# nickname will be a binary string except when following a relay
|
||||||
nick_score =
|
nick_score =
|
||||||
nickname
|
if is_binary(nickname) do
|
||||||
|> String.downcase()
|
nickname
|
||||||
|> score_nickname()
|
|> String.downcase()
|
||||||
|
|> score_nickname()
|
||||||
|
else
|
||||||
|
0.0
|
||||||
|
end
|
||||||
|
|
||||||
# displayname will either be a binary string or nil, if a displayname isn't set.
|
# displayname will either be a binary string or nil, if a displayname isn't set.
|
||||||
name_score =
|
name_score =
|
||||||
|
|
|
@ -185,12 +185,12 @@ def fix_in_reply_to(%{"inReplyTo" => in_reply_to} = object, options)
|
||||||
|> Map.put("context", replied_object.data["context"] || object["conversation"])
|
|> Map.put("context", replied_object.data["context"] || object["conversation"])
|
||||||
else
|
else
|
||||||
e ->
|
e ->
|
||||||
Logger.error("Couldn't fetch \"#{inspect(in_reply_to_id)}\", error: #{inspect(e)}")
|
Logger.error("Couldn't fetch #{inspect(in_reply_to_id)}, error: #{inspect(e)}")
|
||||||
object
|
object
|
||||||
end
|
end
|
||||||
|
|
||||||
e ->
|
e ->
|
||||||
Logger.error("Couldn't fetch \"#{inspect(in_reply_to_id)}\", error: #{inspect(e)}")
|
Logger.error("Couldn't fetch #{inspect(in_reply_to_id)}, error: #{inspect(e)}")
|
||||||
object
|
object
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -464,8 +464,10 @@ def handle_incoming(
|
||||||
%{"type" => "Follow", "object" => followed, "actor" => follower, "id" => id} = data,
|
%{"type" => "Follow", "object" => followed, "actor" => follower, "id" => id} = data,
|
||||||
_options
|
_options
|
||||||
) do
|
) do
|
||||||
with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
|
with %User{local: true} = followed <-
|
||||||
{:ok, %User{} = follower} <- User.get_or_fetch_by_ap_id(follower),
|
User.get_cached_by_ap_id(Containment.get_actor(%{"actor" => followed})),
|
||||||
|
{:ok, %User{} = follower} <-
|
||||||
|
User.get_or_fetch_by_ap_id(Containment.get_actor(%{"actor" => follower})),
|
||||||
{:ok, activity} <- ActivityPub.follow(follower, followed, id, false) do
|
{:ok, activity} <- ActivityPub.follow(follower, followed, id, false) do
|
||||||
with deny_follow_blocked <- Pleroma.Config.get([:user, :deny_follow_blocked]),
|
with deny_follow_blocked <- Pleroma.Config.get([:user, :deny_follow_blocked]),
|
||||||
{_, false} <- {:user_blocked, User.blocks?(followed, follower) && deny_follow_blocked},
|
{_, false} <- {:user_blocked, User.blocks?(followed, follower) && deny_follow_blocked},
|
||||||
|
|
|
@ -90,6 +90,8 @@ defp do_convert(entity) when is_list(entity) do
|
||||||
for v <- entity, into: [], do: do_convert(v)
|
for v <- entity, into: [], do: do_convert(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp do_convert(%Regex{} = entity), do: inspect(entity)
|
||||||
|
|
||||||
defp do_convert(entity) when is_map(entity) do
|
defp do_convert(entity) when is_map(entity) do
|
||||||
for {k, v} <- entity, into: %{}, do: {do_convert(k), do_convert(v)}
|
for {k, v} <- entity, into: %{}, do: {do_convert(k), do_convert(v)}
|
||||||
end
|
end
|
||||||
|
@ -122,7 +124,7 @@ def transform(entity) when is_binary(entity) or is_map(entity) or is_list(entity
|
||||||
|
|
||||||
def transform(entity), do: :erlang.term_to_binary(entity)
|
def transform(entity), do: :erlang.term_to_binary(entity)
|
||||||
|
|
||||||
defp do_transform(%Regex{} = entity) when is_map(entity), do: entity
|
defp do_transform(%Regex{} = entity), do: entity
|
||||||
|
|
||||||
defp do_transform(%{"tuple" => [":dispatch", [entity]]}) do
|
defp do_transform(%{"tuple" => [":dispatch", [entity]]}) do
|
||||||
{dispatch_settings, []} = do_eval(entity)
|
{dispatch_settings, []} = do_eval(entity)
|
||||||
|
@ -154,8 +156,15 @@ defp do_transform(entity) when is_binary(entity) do
|
||||||
defp do_transform(entity), do: entity
|
defp do_transform(entity), do: entity
|
||||||
|
|
||||||
defp do_transform_string("~r/" <> pattern) do
|
defp do_transform_string("~r/" <> pattern) do
|
||||||
pattern = String.trim_trailing(pattern, "/")
|
modificator = String.split(pattern, "/") |> List.last()
|
||||||
~r/#{pattern}/
|
pattern = String.trim_trailing(pattern, "/" <> modificator)
|
||||||
|
|
||||||
|
case modificator do
|
||||||
|
"" -> ~r/#{pattern}/
|
||||||
|
"i" -> ~r/#{pattern}/i
|
||||||
|
"u" -> ~r/#{pattern}/u
|
||||||
|
"s" -> ~r/#{pattern}/s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp do_transform_string(":" <> atom), do: String.to_atom(atom)
|
defp do_transform_string(":" <> atom), do: String.to_atom(atom)
|
||||||
|
|
|
@ -57,7 +57,7 @@ defmodule Pleroma.Web.Endpoint do
|
||||||
plug(Phoenix.CodeReloader)
|
plug(Phoenix.CodeReloader)
|
||||||
end
|
end
|
||||||
|
|
||||||
plug(TrailingFormatPlug)
|
plug(Pleroma.Plugs.TrailingFormatPlug)
|
||||||
plug(Plug.RequestId)
|
plug(Plug.RequestId)
|
||||||
plug(Plug.Logger)
|
plug(Plug.Logger)
|
||||||
|
|
||||||
|
|
|
@ -290,7 +290,7 @@ def verify_app_credentials(%{assigns: %{user: _user, token: token}} = conn, _) d
|
||||||
end
|
end
|
||||||
|
|
||||||
def user(%{assigns: %{user: for_user}} = conn, %{"id" => nickname_or_id}) do
|
def user(%{assigns: %{user: for_user}} = conn, %{"id" => nickname_or_id}) do
|
||||||
with %User{} = user <- User.get_cached_by_nickname_or_id(nickname_or_id),
|
with %User{} = user <- User.get_cached_by_nickname_or_id(nickname_or_id, for: for_user),
|
||||||
true <- User.auth_active?(user) || user.id == for_user.id || User.superuser?(for_user) do
|
true <- User.auth_active?(user) || user.id == for_user.id || User.superuser?(for_user) do
|
||||||
account = AccountView.render("account.json", %{user: user, for: for_user})
|
account = AccountView.render("account.json", %{user: user, for: for_user})
|
||||||
json(conn, account)
|
json(conn, account)
|
||||||
|
@ -390,7 +390,7 @@ def public_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do
|
def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do
|
||||||
with %User{} = user <- User.get_cached_by_nickname_or_id(params["id"]) do
|
with %User{} = user <- User.get_cached_by_nickname_or_id(params["id"], for: reading_user) do
|
||||||
params =
|
params =
|
||||||
params
|
params
|
||||||
|> Map.put("tag", params["tagged"])
|
|> Map.put("tag", params["tagged"])
|
||||||
|
@ -427,6 +427,20 @@ def dm_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
|> render("index.json", %{activities: activities, for: user, as: :activity})
|
|> render("index.json", %{activities: activities, for: user, as: :activity})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_statuses(%{assigns: %{user: user}} = conn, %{"ids" => ids}) do
|
||||||
|
limit = 100
|
||||||
|
|
||||||
|
activities =
|
||||||
|
ids
|
||||||
|
|> Enum.take(limit)
|
||||||
|
|> Activity.all_by_ids_with_object()
|
||||||
|
|> Enum.filter(&Visibility.visible_for_user?(&1, user))
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_view(StatusView)
|
||||||
|
|> render("index.json", activities: activities, for: user, as: :activity)
|
||||||
|
end
|
||||||
|
|
||||||
def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
|
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
|
||||||
true <- Visibility.visible_for_user?(activity, user) do
|
true <- Visibility.visible_for_user?(activity, user) do
|
||||||
|
|
|
@ -14,7 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
|
||||||
alias Pleroma.Web.MastodonAPI.StatusView
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
|
|
||||||
def render("index.json", %{notifications: notifications, for: user}) do
|
def render("index.json", %{notifications: notifications, for: user}) do
|
||||||
render_many(notifications, NotificationView, "show.json", %{for: user})
|
safe_render_many(notifications, NotificationView, "show.json", %{for: user})
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("show.json", %{
|
def render("show.json", %{
|
||||||
|
|
|
@ -73,14 +73,12 @@ defp reblogged?(activity, user) do
|
||||||
|
|
||||||
def render("index.json", opts) do
|
def render("index.json", opts) do
|
||||||
replied_to_activities = get_replied_to_activities(opts.activities)
|
replied_to_activities = get_replied_to_activities(opts.activities)
|
||||||
parallel = unless is_nil(opts[:parallel]), do: opts[:parallel], else: true
|
|
||||||
|
|
||||||
opts.activities
|
opts.activities
|
||||||
|> safe_render_many(
|
|> safe_render_many(
|
||||||
StatusView,
|
StatusView,
|
||||||
"status.json",
|
"status.json",
|
||||||
Map.put(opts, :replied_to_activities, replied_to_activities),
|
Map.put(opts, :replied_to_activities, replied_to_activities)
|
||||||
parallel
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -299,7 +297,8 @@ def render("status.json", %{activity: %{data: %{"object" => _object}} = activity
|
||||||
content: %{"text/plain" => content_plaintext},
|
content: %{"text/plain" => content_plaintext},
|
||||||
spoiler_text: %{"text/plain" => summary_plaintext},
|
spoiler_text: %{"text/plain" => summary_plaintext},
|
||||||
expires_at: expires_at,
|
expires_at: expires_at,
|
||||||
direct_conversation_id: direct_conversation_id
|
direct_conversation_id: direct_conversation_id,
|
||||||
|
thread_muted: thread_muted?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -384,16 +383,27 @@ def render("poll.json", %{object: object} = opts) do
|
||||||
end
|
end
|
||||||
|
|
||||||
if options do
|
if options do
|
||||||
end_time =
|
{end_time, expired} =
|
||||||
(object.data["closed"] || object.data["endTime"])
|
case object.data["closed"] || object.data["endTime"] do
|
||||||
|> NaiveDateTime.from_iso8601!()
|
end_time when is_binary(end_time) ->
|
||||||
|
end_time =
|
||||||
|
(object.data["closed"] || object.data["endTime"])
|
||||||
|
|> NaiveDateTime.from_iso8601!()
|
||||||
|
|
||||||
expired =
|
expired =
|
||||||
end_time
|
end_time
|
||||||
|> NaiveDateTime.compare(NaiveDateTime.utc_now())
|
|> NaiveDateTime.compare(NaiveDateTime.utc_now())
|
||||||
|> case do
|
|> case do
|
||||||
:lt -> true
|
:lt -> true
|
||||||
_ -> false
|
_ -> false
|
||||||
|
end
|
||||||
|
|
||||||
|
end_time = Utils.to_masto_date(end_time)
|
||||||
|
|
||||||
|
{end_time, expired}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
{nil, false}
|
||||||
end
|
end
|
||||||
|
|
||||||
voted =
|
voted =
|
||||||
|
@ -420,7 +430,7 @@ def render("poll.json", %{object: object} = opts) do
|
||||||
# Mastodon uses separate ids for polls, but an object can't have
|
# Mastodon uses separate ids for polls, but an object can't have
|
||||||
# more than one poll embedded so object id is fine
|
# more than one poll embedded so object id is fine
|
||||||
id: to_string(object.id),
|
id: to_string(object.id),
|
||||||
expires_at: Utils.to_masto_date(end_time),
|
expires_at: end_time,
|
||||||
expired: expired,
|
expired: expired,
|
||||||
multiple: multiple,
|
multiple: multiple,
|
||||||
votes_count: votes_count,
|
votes_count: votes_count,
|
||||||
|
@ -487,7 +497,7 @@ def build_tags(object_tags) when is_list(object_tags) do
|
||||||
object_tags = for tag when is_binary(tag) <- object_tags, do: tag
|
object_tags = for tag when is_binary(tag) <- object_tags, do: tag
|
||||||
|
|
||||||
Enum.reduce(object_tags, [], fn tag, tags ->
|
Enum.reduce(object_tags, [], fn tag, tags ->
|
||||||
tags ++ [%{name: tag, url: "/tag/#{tag}"}]
|
tags ++ [%{name: tag, url: "/tag/#{URI.encode(tag)}"}]
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,12 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Conversation.Participation
|
alias Pleroma.Conversation.Participation
|
||||||
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.MastodonAPI.AccountView
|
alias Pleroma.Web.MastodonAPI.AccountView
|
||||||
alias Pleroma.Web.MastodonAPI.ConversationView
|
alias Pleroma.Web.MastodonAPI.ConversationView
|
||||||
|
alias Pleroma.Web.MastodonAPI.NotificationView
|
||||||
alias Pleroma.Web.MastodonAPI.StatusView
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
|
|
||||||
def emoji_reactions_by(%{assigns: %{user: user}} = conn, %{"id" => activity_id}) do
|
def emoji_reactions_by(%{assigns: %{user: user}} = conn, %{"id" => activity_id}) do
|
||||||
|
@ -109,4 +111,27 @@ def update_conversation(
|
||||||
|> render("participation.json", %{participation: participation, for: user})
|
|> render("participation.json", %{participation: participation, for: user})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def read_notification(%{assigns: %{user: user}} = conn, %{"id" => notification_id}) do
|
||||||
|
with {:ok, notification} <- Notification.read_one(user, notification_id) do
|
||||||
|
conn
|
||||||
|
|> put_view(NotificationView)
|
||||||
|
|> render("show.json", %{notification: notification, for: user})
|
||||||
|
else
|
||||||
|
{:error, message} ->
|
||||||
|
conn
|
||||||
|
|> put_status(:bad_request)
|
||||||
|
|> json(%{"error" => message})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_notification(%{assigns: %{user: user}} = conn, %{"max_id" => max_id}) do
|
||||||
|
with notifications <- Notification.set_read_up_to(user, max_id) do
|
||||||
|
notifications = Enum.take(notifications, 80)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_view(NotificationView)
|
||||||
|
|> render("index.json", %{notifications: notifications, for: user})
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -224,6 +224,7 @@ defmodule Pleroma.Web.Router do
|
||||||
scope [] do
|
scope [] do
|
||||||
pipe_through(:oauth_write)
|
pipe_through(:oauth_write)
|
||||||
|
|
||||||
|
post("/change_email", UtilController, :change_email)
|
||||||
post("/change_password", UtilController, :change_password)
|
post("/change_password", UtilController, :change_password)
|
||||||
post("/delete_account", UtilController, :delete_account)
|
post("/delete_account", UtilController, :delete_account)
|
||||||
put("/notification_settings", UtilController, :update_notificaton_settings)
|
put("/notification_settings", UtilController, :update_notificaton_settings)
|
||||||
|
@ -236,12 +237,6 @@ defmodule Pleroma.Web.Router do
|
||||||
post("/blocks_import", UtilController, :blocks_import)
|
post("/blocks_import", UtilController, :blocks_import)
|
||||||
post("/follow_import", UtilController, :follow_import)
|
post("/follow_import", UtilController, :follow_import)
|
||||||
end
|
end
|
||||||
|
|
||||||
scope [] do
|
|
||||||
pipe_through(:oauth_read)
|
|
||||||
|
|
||||||
post("/notifications/read", UtilController, :notifications_read)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/oauth", Pleroma.Web.OAuth do
|
scope "/oauth", Pleroma.Web.OAuth do
|
||||||
|
@ -284,6 +279,7 @@ defmodule Pleroma.Web.Router do
|
||||||
pipe_through(:oauth_write)
|
pipe_through(:oauth_write)
|
||||||
patch("/conversations/:id", PleromaAPIController, :update_conversation)
|
patch("/conversations/:id", PleromaAPIController, :update_conversation)
|
||||||
post("/statuses/:id/react_with_emoji", PleromaAPIController, :react_with_emoji)
|
post("/statuses/:id/react_with_emoji", PleromaAPIController, :react_with_emoji)
|
||||||
|
post("/notifications/read", PleromaAPIController, :read_notification)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -455,6 +451,7 @@ defmodule Pleroma.Web.Router do
|
||||||
get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
|
get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
|
||||||
get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
|
get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
|
||||||
|
|
||||||
|
get("/statuses", MastodonAPIController, :get_statuses)
|
||||||
get("/statuses/:id", MastodonAPIController, :get_status)
|
get("/statuses/:id", MastodonAPIController, :get_status)
|
||||||
get("/statuses/:id/context", MastodonAPIController, :get_context)
|
get("/statuses/:id/context", MastodonAPIController, :get_context)
|
||||||
|
|
||||||
|
@ -489,53 +486,12 @@ defmodule Pleroma.Web.Router do
|
||||||
scope "/api", Pleroma.Web do
|
scope "/api", Pleroma.Web do
|
||||||
pipe_through(:api)
|
pipe_through(:api)
|
||||||
|
|
||||||
post("/account/register", TwitterAPI.Controller, :register)
|
|
||||||
post("/account/password_reset", TwitterAPI.Controller, :password_reset)
|
|
||||||
|
|
||||||
post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email)
|
|
||||||
|
|
||||||
get(
|
get(
|
||||||
"/account/confirm_email/:user_id/:token",
|
"/account/confirm_email/:user_id/:token",
|
||||||
TwitterAPI.Controller,
|
TwitterAPI.Controller,
|
||||||
:confirm_email,
|
:confirm_email,
|
||||||
as: :confirm_email
|
as: :confirm_email
|
||||||
)
|
)
|
||||||
|
|
||||||
scope [] do
|
|
||||||
pipe_through(:oauth_read_or_public)
|
|
||||||
|
|
||||||
get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
|
|
||||||
get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
|
|
||||||
get("/users/show", TwitterAPI.Controller, :show_user)
|
|
||||||
|
|
||||||
get("/statuses/followers", TwitterAPI.Controller, :followers)
|
|
||||||
get("/statuses/friends", TwitterAPI.Controller, :friends)
|
|
||||||
get("/statuses/blocks", TwitterAPI.Controller, :blocks)
|
|
||||||
get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
|
|
||||||
get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
|
|
||||||
|
|
||||||
get("/search", TwitterAPI.Controller, :search)
|
|
||||||
get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scope "/api", Pleroma.Web do
|
|
||||||
pipe_through([:api, :oauth_read_or_public])
|
|
||||||
|
|
||||||
get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
|
|
||||||
|
|
||||||
get(
|
|
||||||
"/statuses/public_and_external_timeline",
|
|
||||||
TwitterAPI.Controller,
|
|
||||||
:public_and_external_timeline
|
|
||||||
)
|
|
||||||
|
|
||||||
get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
|
|
||||||
end
|
|
||||||
|
|
||||||
scope "/api", Pleroma.Web, as: :twitter_api_search do
|
|
||||||
pipe_through([:api, :oauth_read_or_public])
|
|
||||||
get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
|
scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
|
||||||
|
@ -547,67 +503,8 @@ defmodule Pleroma.Web.Router do
|
||||||
scope [] do
|
scope [] do
|
||||||
pipe_through(:oauth_read)
|
pipe_through(:oauth_read)
|
||||||
|
|
||||||
get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
|
|
||||||
post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
|
|
||||||
|
|
||||||
get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
|
|
||||||
get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
|
|
||||||
get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
|
|
||||||
get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
|
|
||||||
get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
|
|
||||||
get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
|
|
||||||
|
|
||||||
get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
|
|
||||||
|
|
||||||
get("/friends/ids", TwitterAPI.Controller, :friends_ids)
|
|
||||||
get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
|
|
||||||
|
|
||||||
get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
|
|
||||||
get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
|
|
||||||
|
|
||||||
get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
|
|
||||||
|
|
||||||
post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
|
post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
|
||||||
end
|
end
|
||||||
|
|
||||||
scope [] do
|
|
||||||
pipe_through(:oauth_write)
|
|
||||||
|
|
||||||
post("/account/update_profile", TwitterAPI.Controller, :update_profile)
|
|
||||||
post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
|
|
||||||
post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
|
|
||||||
|
|
||||||
post("/statuses/update", TwitterAPI.Controller, :status_update)
|
|
||||||
post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
|
|
||||||
post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
|
|
||||||
post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
|
|
||||||
|
|
||||||
post("/statuses/pin/:id", TwitterAPI.Controller, :pin)
|
|
||||||
post("/statuses/unpin/:id", TwitterAPI.Controller, :unpin)
|
|
||||||
|
|
||||||
post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
|
|
||||||
post("/media/upload", TwitterAPI.Controller, :upload_json)
|
|
||||||
post("/media/metadata/create", TwitterAPI.Controller, :update_media)
|
|
||||||
|
|
||||||
post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
|
|
||||||
post("/favorites/create", TwitterAPI.Controller, :favorite)
|
|
||||||
post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
|
|
||||||
|
|
||||||
post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
|
|
||||||
end
|
|
||||||
|
|
||||||
scope [] do
|
|
||||||
pipe_through(:oauth_follow)
|
|
||||||
|
|
||||||
post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
|
|
||||||
post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
|
|
||||||
|
|
||||||
post("/friendships/create", TwitterAPI.Controller, :follow)
|
|
||||||
post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
|
|
||||||
|
|
||||||
post("/blocks/create", TwitterAPI.Controller, :block)
|
|
||||||
post("/blocks/destroy", TwitterAPI.Controller, :unblock)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :ap_service_actor do
|
pipeline :ap_service_actor do
|
||||||
|
|
|
@ -314,6 +314,25 @@ def change_password(%{assigns: %{user: user}} = conn, params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def change_email(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
case CommonAPI.Utils.confirm_current_password(user, params["password"]) do
|
||||||
|
{:ok, user} ->
|
||||||
|
with {:ok, _user} <- User.change_email(user, params["email"]) do
|
||||||
|
json(conn, %{status: "success"})
|
||||||
|
else
|
||||||
|
{:error, changeset} ->
|
||||||
|
{_, {error, _}} = Enum.at(changeset.errors, 0)
|
||||||
|
json(conn, %{error: "Email #{error}."})
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
json(conn, %{error: "Unable to change email."})
|
||||||
|
end
|
||||||
|
|
||||||
|
{:error, msg} ->
|
||||||
|
json(conn, %{error: msg})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def delete_account(%{assigns: %{user: user}} = conn, params) do
|
def delete_account(%{assigns: %{user: user}} = conn, params) do
|
||||||
case CommonAPI.Utils.confirm_current_password(user, params["password"]) do
|
case CommonAPI.Utils.confirm_current_password(user, params["password"]) do
|
||||||
{:ok, user} ->
|
{:ok, user} ->
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
# Pleroma: A lightweight social networking server
|
|
||||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
|
|
||||||
defmodule Pleroma.Web.TwitterAPI.Representers.BaseRepresenter do
|
|
||||||
defmacro __using__(_opts) do
|
|
||||||
quote do
|
|
||||||
def to_json(object) do
|
|
||||||
to_json(object, %{})
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_json(object, options) do
|
|
||||||
object
|
|
||||||
|> to_map(options)
|
|
||||||
|> Jason.encode!()
|
|
||||||
end
|
|
||||||
|
|
||||||
def enum_to_list(enum, options) do
|
|
||||||
mapping = fn el -> to_map(el, options) end
|
|
||||||
Enum.map(enum, mapping)
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_map(object) do
|
|
||||||
to_map(object, %{})
|
|
||||||
end
|
|
||||||
|
|
||||||
def enum_to_json(enum) do
|
|
||||||
enum_to_json(enum, %{})
|
|
||||||
end
|
|
||||||
|
|
||||||
def enum_to_json(enum, options) do
|
|
||||||
enum
|
|
||||||
|> enum_to_list(options)
|
|
||||||
|> Jason.encode!()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,39 +0,0 @@
|
||||||
# Pleroma: A lightweight social networking server
|
|
||||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
|
|
||||||
defmodule Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter do
|
|
||||||
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
|
|
||||||
alias Pleroma.Object
|
|
||||||
|
|
||||||
def to_map(%Object{data: %{"url" => [url | _]}} = object, _opts) do
|
|
||||||
data = object.data
|
|
||||||
|
|
||||||
%{
|
|
||||||
url: url["href"] |> Pleroma.Web.MediaProxy.url(),
|
|
||||||
mimetype: url["mediaType"] || url["mimeType"],
|
|
||||||
id: data["uuid"],
|
|
||||||
oembed: false,
|
|
||||||
description: data["name"]
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_map(%Object{data: %{"url" => url} = data}, _opts) when is_binary(url) do
|
|
||||||
%{
|
|
||||||
url: url |> Pleroma.Web.MediaProxy.url(),
|
|
||||||
mimetype: data["mediaType"] || data["mimeType"],
|
|
||||||
id: data["uuid"],
|
|
||||||
oembed: false,
|
|
||||||
description: data["name"]
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_map(%Object{}, _opts) do
|
|
||||||
%{}
|
|
||||||
end
|
|
||||||
|
|
||||||
# If we only get the naked data, wrap in an object
|
|
||||||
def to_map(%{} = data, opts) do
|
|
||||||
to_map(%Object{data: data}, opts)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -3,133 +3,14 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
||||||
alias Pleroma.Activity
|
|
||||||
alias Pleroma.Emails.Mailer
|
alias Pleroma.Emails.Mailer
|
||||||
alias Pleroma.Emails.UserEmail
|
alias Pleroma.Emails.UserEmail
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.UserInviteToken
|
alias Pleroma.UserInviteToken
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
||||||
alias Pleroma.Web.CommonAPI
|
|
||||||
alias Pleroma.Web.TwitterAPI.UserView
|
|
||||||
|
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
def create_status(%User{} = user, %{"status" => _} = data) do
|
|
||||||
CommonAPI.post(user, data)
|
|
||||||
end
|
|
||||||
|
|
||||||
def delete(%User{} = user, id) do
|
|
||||||
with %Activity{data: %{"type" => _type}} <- Activity.get_by_id(id),
|
|
||||||
{:ok, activity} <- CommonAPI.delete(id, user) do
|
|
||||||
{:ok, activity}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def follow(%User{} = follower, params) do
|
|
||||||
with {:ok, %User{} = followed} <- get_user(params) do
|
|
||||||
CommonAPI.follow(follower, followed)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def unfollow(%User{} = follower, params) do
|
|
||||||
with {:ok, %User{} = unfollowed} <- get_user(params),
|
|
||||||
{:ok, follower} <- CommonAPI.unfollow(follower, unfollowed) do
|
|
||||||
{:ok, follower, unfollowed}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def block(%User{} = blocker, params) do
|
|
||||||
with {:ok, %User{} = blocked} <- get_user(params),
|
|
||||||
{:ok, blocker} <- User.block(blocker, blocked),
|
|
||||||
{:ok, _activity} <- ActivityPub.block(blocker, blocked) do
|
|
||||||
{:ok, blocker, blocked}
|
|
||||||
else
|
|
||||||
err -> err
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def unblock(%User{} = blocker, params) do
|
|
||||||
with {:ok, %User{} = blocked} <- get_user(params),
|
|
||||||
{:ok, blocker} <- User.unblock(blocker, blocked),
|
|
||||||
{:ok, _activity} <- ActivityPub.unblock(blocker, blocked) do
|
|
||||||
{:ok, blocker, blocked}
|
|
||||||
else
|
|
||||||
err -> err
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def repeat(%User{} = user, ap_id_or_id) do
|
|
||||||
with {:ok, _announce, %{data: %{"id" => id}}} <- CommonAPI.repeat(ap_id_or_id, user),
|
|
||||||
%Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do
|
|
||||||
{:ok, activity}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def unrepeat(%User{} = user, ap_id_or_id) do
|
|
||||||
with {:ok, _unannounce, %{data: %{"id" => id}}} <- CommonAPI.unrepeat(ap_id_or_id, user),
|
|
||||||
%Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do
|
|
||||||
{:ok, activity}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def pin(%User{} = user, ap_id_or_id) do
|
|
||||||
CommonAPI.pin(ap_id_or_id, user)
|
|
||||||
end
|
|
||||||
|
|
||||||
def unpin(%User{} = user, ap_id_or_id) do
|
|
||||||
CommonAPI.unpin(ap_id_or_id, user)
|
|
||||||
end
|
|
||||||
|
|
||||||
def fav(%User{} = user, ap_id_or_id) do
|
|
||||||
with {:ok, _fav, %{data: %{"id" => id}}} <- CommonAPI.favorite(ap_id_or_id, user),
|
|
||||||
%Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do
|
|
||||||
{:ok, activity}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def unfav(%User{} = user, ap_id_or_id) do
|
|
||||||
with {:ok, _unfav, _fav, %{data: %{"id" => id}}} <- CommonAPI.unfavorite(ap_id_or_id, user),
|
|
||||||
%Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do
|
|
||||||
{:ok, activity}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def upload(%Plug.Upload{} = file, %User{} = user, format \\ "xml") do
|
|
||||||
{:ok, object} = ActivityPub.upload(file, actor: User.ap_id(user))
|
|
||||||
|
|
||||||
url = List.first(object.data["url"])
|
|
||||||
href = url["href"]
|
|
||||||
type = url["mediaType"]
|
|
||||||
|
|
||||||
case format do
|
|
||||||
"xml" ->
|
|
||||||
# Fake this as good as possible...
|
|
||||||
"""
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<rsp stat="ok" xmlns:atom="http://www.w3.org/2005/Atom">
|
|
||||||
<mediaid>#{object.id}</mediaid>
|
|
||||||
<media_id>#{object.id}</media_id>
|
|
||||||
<media_id_string>#{object.id}</media_id_string>
|
|
||||||
<media_url>#{href}</media_url>
|
|
||||||
<mediaurl>#{href}</mediaurl>
|
|
||||||
<atom:link rel="enclosure" href="#{href}" type="#{type}"></atom:link>
|
|
||||||
</rsp>
|
|
||||||
"""
|
|
||||||
|
|
||||||
"json" ->
|
|
||||||
%{
|
|
||||||
media_id: object.id,
|
|
||||||
media_id_string: "#{object.id}}",
|
|
||||||
media_url: href,
|
|
||||||
size: 0
|
|
||||||
}
|
|
||||||
|> Jason.encode!()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def register_user(params, opts \\ []) do
|
def register_user(params, opts \\ []) do
|
||||||
token = params["token"]
|
token = params["token"]
|
||||||
|
|
||||||
|
@ -236,80 +117,4 @@ def password_reset(nickname_or_email) do
|
||||||
{:error, "unknown user"}
|
{:error, "unknown user"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_user(user \\ nil, params) do
|
|
||||||
case params do
|
|
||||||
%{"user_id" => user_id} ->
|
|
||||||
case User.get_cached_by_nickname_or_id(user_id) do
|
|
||||||
nil ->
|
|
||||||
{:error, "No user with such user_id"}
|
|
||||||
|
|
||||||
%User{info: %{deactivated: true}} ->
|
|
||||||
{:error, "User has been disabled"}
|
|
||||||
|
|
||||||
user ->
|
|
||||||
{:ok, user}
|
|
||||||
end
|
|
||||||
|
|
||||||
%{"screen_name" => nickname} ->
|
|
||||||
case User.get_cached_by_nickname(nickname) do
|
|
||||||
nil -> {:error, "No user with such screen_name"}
|
|
||||||
target -> {:ok, target}
|
|
||||||
end
|
|
||||||
|
|
||||||
_ ->
|
|
||||||
if user do
|
|
||||||
{:ok, user}
|
|
||||||
else
|
|
||||||
{:error, "You need to specify screen_name or user_id"}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp parse_int(string, default)
|
|
||||||
|
|
||||||
defp parse_int(string, default) when is_binary(string) do
|
|
||||||
with {n, _} <- Integer.parse(string) do
|
|
||||||
n
|
|
||||||
else
|
|
||||||
_e -> default
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp parse_int(_, default), do: default
|
|
||||||
|
|
||||||
# TODO: unify the search query with MastoAPI one and do only pagination here
|
|
||||||
def search(_user, %{"q" => query} = params) do
|
|
||||||
limit = parse_int(params["rpp"], 20)
|
|
||||||
page = parse_int(params["page"], 1)
|
|
||||||
offset = (page - 1) * limit
|
|
||||||
|
|
||||||
q =
|
|
||||||
from(
|
|
||||||
[a, o] in Activity.with_preloaded_object(Activity),
|
|
||||||
where: fragment("?->>'type' = 'Create'", a.data),
|
|
||||||
where: ^Pleroma.Constants.as_public() in a.recipients,
|
|
||||||
where:
|
|
||||||
fragment(
|
|
||||||
"to_tsvector('english', ?->>'content') @@ plainto_tsquery('english', ?)",
|
|
||||||
o.data,
|
|
||||||
^query
|
|
||||||
),
|
|
||||||
limit: ^limit,
|
|
||||||
offset: ^offset,
|
|
||||||
# this one isn't indexed so psql won't take the wrong index.
|
|
||||||
order_by: [desc: :inserted_at]
|
|
||||||
)
|
|
||||||
|
|
||||||
_activities = Repo.all(q)
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_external_profile(for_user, uri) do
|
|
||||||
with {:ok, %User{} = user} <- User.get_or_fetch(uri) do
|
|
||||||
{:ok, UserView.render("show.json", %{user: user, for: for_user})}
|
|
||||||
else
|
|
||||||
_e ->
|
|
||||||
{:error, "Couldn't find user"}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,448 +5,16 @@
|
||||||
defmodule Pleroma.Web.TwitterAPI.Controller do
|
defmodule Pleroma.Web.TwitterAPI.Controller do
|
||||||
use Pleroma.Web, :controller
|
use Pleroma.Web, :controller
|
||||||
|
|
||||||
import Pleroma.Web.ControllerHelper, only: [json_response: 3]
|
|
||||||
|
|
||||||
alias Ecto.Changeset
|
alias Ecto.Changeset
|
||||||
alias Pleroma.Activity
|
|
||||||
alias Pleroma.Formatter
|
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
|
||||||
alias Pleroma.Repo
|
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
|
||||||
alias Pleroma.Web.CommonAPI
|
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
|
||||||
alias Pleroma.Web.OAuth.Token
|
alias Pleroma.Web.OAuth.Token
|
||||||
alias Pleroma.Web.TwitterAPI.ActivityView
|
|
||||||
alias Pleroma.Web.TwitterAPI.NotificationView
|
|
||||||
alias Pleroma.Web.TwitterAPI.TokenView
|
alias Pleroma.Web.TwitterAPI.TokenView
|
||||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
|
||||||
alias Pleroma.Web.TwitterAPI.UserView
|
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
plug(Pleroma.Plugs.RateLimiter, :password_reset when action == :password_reset)
|
|
||||||
plug(:only_if_public_instance when action in [:public_timeline, :public_and_external_timeline])
|
|
||||||
action_fallback(:errors)
|
action_fallback(:errors)
|
||||||
|
|
||||||
def verify_credentials(%{assigns: %{user: user}} = conn, _params) do
|
|
||||||
token = Phoenix.Token.sign(conn, "user socket", user.id)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("show.json", %{user: user, token: token, for: user})
|
|
||||||
end
|
|
||||||
|
|
||||||
def status_update(%{assigns: %{user: user}} = conn, %{"status" => _} = status_data) do
|
|
||||||
with media_ids <- extract_media_ids(status_data),
|
|
||||||
{:ok, activity} <-
|
|
||||||
TwitterAPI.create_status(user, Map.put(status_data, "media_ids", media_ids)) do
|
|
||||||
conn
|
|
||||||
|> json(ActivityView.render("activity.json", activity: activity, for: user))
|
|
||||||
else
|
|
||||||
_ -> empty_status_reply(conn)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def status_update(conn, _status_data) do
|
|
||||||
empty_status_reply(conn)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp empty_status_reply(conn) do
|
|
||||||
bad_request_reply(conn, "Client must provide a 'status' parameter with a value.")
|
|
||||||
end
|
|
||||||
|
|
||||||
defp extract_media_ids(status_data) do
|
|
||||||
with media_ids when not is_nil(media_ids) <- status_data["media_ids"],
|
|
||||||
split_ids <- String.split(media_ids, ","),
|
|
||||||
clean_ids <- Enum.reject(split_ids, fn id -> String.length(id) == 0 end) do
|
|
||||||
clean_ids
|
|
||||||
else
|
|
||||||
_e -> []
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def public_and_external_timeline(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
params =
|
|
||||||
params
|
|
||||||
|> Map.put("type", ["Create", "Announce"])
|
|
||||||
|> Map.put("blocking_user", user)
|
|
||||||
|
|
||||||
activities = ActivityPub.fetch_public_activities(params)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("index.json", %{activities: activities, for: user})
|
|
||||||
end
|
|
||||||
|
|
||||||
def public_timeline(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
params =
|
|
||||||
params
|
|
||||||
|> Map.put("type", ["Create", "Announce"])
|
|
||||||
|> Map.put("local_only", true)
|
|
||||||
|> Map.put("blocking_user", user)
|
|
||||||
|
|
||||||
activities = ActivityPub.fetch_public_activities(params)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("index.json", %{activities: activities, for: user})
|
|
||||||
end
|
|
||||||
|
|
||||||
def friends_timeline(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
params =
|
|
||||||
params
|
|
||||||
|> Map.put("type", ["Create", "Announce", "Follow", "Like"])
|
|
||||||
|> Map.put("blocking_user", user)
|
|
||||||
|> Map.put("user", user)
|
|
||||||
|
|
||||||
activities = ActivityPub.fetch_activities([user.ap_id | user.following], params)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("index.json", %{activities: activities, for: user})
|
|
||||||
end
|
|
||||||
|
|
||||||
def show_user(conn, params) do
|
|
||||||
for_user = conn.assigns.user
|
|
||||||
|
|
||||||
with {:ok, shown} <- TwitterAPI.get_user(params),
|
|
||||||
true <-
|
|
||||||
User.auth_active?(shown) ||
|
|
||||||
(for_user && (for_user.id == shown.id || User.superuser?(for_user))) do
|
|
||||||
params =
|
|
||||||
if for_user do
|
|
||||||
%{user: shown, for: for_user}
|
|
||||||
else
|
|
||||||
%{user: shown}
|
|
||||||
end
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("show.json", params)
|
|
||||||
else
|
|
||||||
{:error, msg} ->
|
|
||||||
bad_request_reply(conn, msg)
|
|
||||||
|
|
||||||
false ->
|
|
||||||
conn
|
|
||||||
|> put_status(404)
|
|
||||||
|> json(%{error: "Unconfirmed user"})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def user_timeline(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
case TwitterAPI.get_user(user, params) do
|
|
||||||
{:ok, target_user} ->
|
|
||||||
# Twitter and ActivityPub use a different name and sense for this parameter.
|
|
||||||
{include_rts, params} = Map.pop(params, "include_rts")
|
|
||||||
|
|
||||||
params =
|
|
||||||
case include_rts do
|
|
||||||
x when x == "false" or x == "0" -> Map.put(params, "exclude_reblogs", "true")
|
|
||||||
_ -> params
|
|
||||||
end
|
|
||||||
|
|
||||||
activities = ActivityPub.fetch_user_activities(target_user, user, params)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("index.json", %{activities: activities, for: user})
|
|
||||||
|
|
||||||
{:error, msg} ->
|
|
||||||
bad_request_reply(conn, msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def mentions_timeline(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
params =
|
|
||||||
params
|
|
||||||
|> Map.put("type", ["Create", "Announce", "Follow", "Like"])
|
|
||||||
|> Map.put("blocking_user", user)
|
|
||||||
|> Map.put(:visibility, ~w[unlisted public private])
|
|
||||||
|
|
||||||
activities = ActivityPub.fetch_activities([user.ap_id], params)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("index.json", %{activities: activities, for: user})
|
|
||||||
end
|
|
||||||
|
|
||||||
def dm_timeline(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
params =
|
|
||||||
params
|
|
||||||
|> Map.put("type", "Create")
|
|
||||||
|> Map.put("blocking_user", user)
|
|
||||||
|> Map.put("user", user)
|
|
||||||
|> Map.put(:visibility, "direct")
|
|
||||||
|> Map.put(:order, :desc)
|
|
||||||
|
|
||||||
activities =
|
|
||||||
ActivityPub.fetch_activities_query([user.ap_id], params)
|
|
||||||
|> Repo.all()
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("index.json", %{activities: activities, for: user})
|
|
||||||
end
|
|
||||||
|
|
||||||
def notifications(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
params =
|
|
||||||
if Map.has_key?(params, "with_muted") do
|
|
||||||
Map.put(params, :with_muted, params["with_muted"] in [true, "True", "true", "1"])
|
|
||||||
else
|
|
||||||
params
|
|
||||||
end
|
|
||||||
|
|
||||||
notifications = Notification.for_user(user, params)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(NotificationView)
|
|
||||||
|> render("notification.json", %{notifications: notifications, for: user})
|
|
||||||
end
|
|
||||||
|
|
||||||
def notifications_read(%{assigns: %{user: user}} = conn, %{"latest_id" => latest_id} = params) do
|
|
||||||
Notification.set_read_up_to(user, latest_id)
|
|
||||||
|
|
||||||
notifications = Notification.for_user(user, params)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(NotificationView)
|
|
||||||
|> render("notification.json", %{notifications: notifications, for: user})
|
|
||||||
end
|
|
||||||
|
|
||||||
def notifications_read(%{assigns: %{user: _user}} = conn, _) do
|
|
||||||
bad_request_reply(conn, "You need to specify latest_id")
|
|
||||||
end
|
|
||||||
|
|
||||||
def follow(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
case TwitterAPI.follow(user, params) do
|
|
||||||
{:ok, user, followed, _activity} ->
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("show.json", %{user: followed, for: user})
|
|
||||||
|
|
||||||
{:error, msg} ->
|
|
||||||
forbidden_json_reply(conn, msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def block(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
case TwitterAPI.block(user, params) do
|
|
||||||
{:ok, user, blocked} ->
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("show.json", %{user: blocked, for: user})
|
|
||||||
|
|
||||||
{:error, msg} ->
|
|
||||||
forbidden_json_reply(conn, msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def unblock(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
case TwitterAPI.unblock(user, params) do
|
|
||||||
{:ok, user, blocked} ->
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("show.json", %{user: blocked, for: user})
|
|
||||||
|
|
||||||
{:error, msg} ->
|
|
||||||
forbidden_json_reply(conn, msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def delete_post(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
|
||||||
with {:ok, activity} <- TwitterAPI.delete(user, id) do
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("activity.json", %{activity: activity, for: user})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def unfollow(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
case TwitterAPI.unfollow(user, params) do
|
|
||||||
{:ok, user, unfollowed} ->
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("show.json", %{user: unfollowed, for: user})
|
|
||||||
|
|
||||||
{:error, msg} ->
|
|
||||||
forbidden_json_reply(conn, msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def fetch_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
|
||||||
with %Activity{} = activity <- Activity.get_by_id(id),
|
|
||||||
true <- Visibility.visible_for_user?(activity, user) do
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("activity.json", %{activity: activity, for: user})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def fetch_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
|
||||||
with context when is_binary(context) <- Utils.conversation_id_to_context(id),
|
|
||||||
activities <-
|
|
||||||
ActivityPub.fetch_activities_for_context(context, %{
|
|
||||||
"blocking_user" => user,
|
|
||||||
"user" => user
|
|
||||||
}) do
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("index.json", %{activities: activities, for: user})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
|
||||||
Updates metadata of uploaded media object.
|
|
||||||
Derived from [Twitter API endpoint](https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-create).
|
|
||||||
"""
|
|
||||||
def update_media(%{assigns: %{user: user}} = conn, %{"media_id" => id} = data) do
|
|
||||||
object = Repo.get(Object, id)
|
|
||||||
description = get_in(data, ["alt_text", "text"]) || data["name"] || data["description"]
|
|
||||||
|
|
||||||
{conn, status, response_body} =
|
|
||||||
cond do
|
|
||||||
!object ->
|
|
||||||
{halt(conn), :not_found, ""}
|
|
||||||
|
|
||||||
!Object.authorize_mutation(object, user) ->
|
|
||||||
{halt(conn), :forbidden, "You can only update your own uploads."}
|
|
||||||
|
|
||||||
!is_binary(description) ->
|
|
||||||
{conn, :not_modified, ""}
|
|
||||||
|
|
||||||
true ->
|
|
||||||
new_data = Map.put(object.data, "name", description)
|
|
||||||
|
|
||||||
{:ok, _} =
|
|
||||||
object
|
|
||||||
|> Object.change(%{data: new_data})
|
|
||||||
|> Repo.update()
|
|
||||||
|
|
||||||
{conn, :no_content, ""}
|
|
||||||
end
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_status(status)
|
|
||||||
|> json(response_body)
|
|
||||||
end
|
|
||||||
|
|
||||||
def upload(%{assigns: %{user: user}} = conn, %{"media" => media}) do
|
|
||||||
response = TwitterAPI.upload(media, user)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_resp_content_type("application/atom+xml")
|
|
||||||
|> send_resp(200, response)
|
|
||||||
end
|
|
||||||
|
|
||||||
def upload_json(%{assigns: %{user: user}} = conn, %{"media" => media}) do
|
|
||||||
response = TwitterAPI.upload(media, user, "json")
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> json_reply(200, response)
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_by_id_or_ap_id(id) do
|
|
||||||
activity = Activity.get_by_id(id) || Activity.get_create_by_object_ap_id(id)
|
|
||||||
|
|
||||||
if activity.data["type"] == "Create" do
|
|
||||||
activity
|
|
||||||
else
|
|
||||||
Activity.get_create_by_object_ap_id(activity.data["object"])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def favorite(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
|
||||||
with {:ok, activity} <- TwitterAPI.fav(user, id) do
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("activity.json", %{activity: activity, for: user})
|
|
||||||
else
|
|
||||||
_ -> json_reply(conn, 400, Jason.encode!(%{}))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def unfavorite(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
|
||||||
with {:ok, activity} <- TwitterAPI.unfav(user, id) do
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("activity.json", %{activity: activity, for: user})
|
|
||||||
else
|
|
||||||
_ -> json_reply(conn, 400, Jason.encode!(%{}))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def retweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
|
||||||
with {:ok, activity} <- TwitterAPI.repeat(user, id) do
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("activity.json", %{activity: activity, for: user})
|
|
||||||
else
|
|
||||||
_ -> json_reply(conn, 400, Jason.encode!(%{}))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def unretweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
|
||||||
with {:ok, activity} <- TwitterAPI.unrepeat(user, id) do
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("activity.json", %{activity: activity, for: user})
|
|
||||||
else
|
|
||||||
_ -> json_reply(conn, 400, Jason.encode!(%{}))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def pin(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
|
||||||
with {:ok, activity} <- TwitterAPI.pin(user, id) do
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("activity.json", %{activity: activity, for: user})
|
|
||||||
else
|
|
||||||
{:error, message} -> bad_request_reply(conn, message)
|
|
||||||
err -> err
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def unpin(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
|
||||||
with {:ok, activity} <- TwitterAPI.unpin(user, id) do
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("activity.json", %{activity: activity, for: user})
|
|
||||||
else
|
|
||||||
{:error, message} -> bad_request_reply(conn, message)
|
|
||||||
err -> err
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def register(conn, params) do
|
|
||||||
with {:ok, user} <- TwitterAPI.register_user(params) do
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("show.json", %{user: user})
|
|
||||||
else
|
|
||||||
{:error, errors} ->
|
|
||||||
conn
|
|
||||||
|> json_reply(400, Jason.encode!(errors))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def password_reset(conn, params) do
|
|
||||||
nickname_or_email = params["email"] || params["nickname"]
|
|
||||||
|
|
||||||
with {:ok, _} <- TwitterAPI.password_reset(nickname_or_email) do
|
|
||||||
json_response(conn, :no_content, "")
|
|
||||||
else
|
|
||||||
{:error, "unknown user"} ->
|
|
||||||
send_resp(conn, :not_found, "")
|
|
||||||
|
|
||||||
{:error, _} ->
|
|
||||||
send_resp(conn, :bad_request, "")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def confirm_email(conn, %{"user_id" => uid, "token" => token}) do
|
def confirm_email(conn, %{"user_id" => uid, "token" => token}) do
|
||||||
with %User{} = user <- User.get_cached_by_id(uid),
|
with %User{} = user <- User.get_cached_by_id(uid),
|
||||||
true <- user.local,
|
true <- user.local,
|
||||||
|
@ -460,147 +28,6 @@ def confirm_email(conn, %{"user_id" => uid, "token" => token}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def resend_confirmation_email(conn, params) do
|
|
||||||
nickname_or_email = params["email"] || params["nickname"]
|
|
||||||
|
|
||||||
with %User{} = user <- User.get_by_nickname_or_email(nickname_or_email),
|
|
||||||
{:ok, _} <- User.try_send_confirmation_email(user) do
|
|
||||||
conn
|
|
||||||
|> json_response(:no_content, "")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_avatar(%{assigns: %{user: user}} = conn, %{"img" => ""}) do
|
|
||||||
change = Changeset.change(user, %{avatar: nil})
|
|
||||||
{:ok, user} = User.update_and_set_cache(change)
|
|
||||||
CommonAPI.update(user)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("show.json", %{user: user, for: user})
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_avatar(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
{:ok, object} = ActivityPub.upload(params, type: :avatar)
|
|
||||||
change = Changeset.change(user, %{avatar: object.data})
|
|
||||||
{:ok, user} = User.update_and_set_cache(change)
|
|
||||||
CommonAPI.update(user)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("show.json", %{user: user, for: user})
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_banner(%{assigns: %{user: user}} = conn, %{"banner" => ""}) do
|
|
||||||
with new_info <- %{"banner" => %{}},
|
|
||||||
info_cng <- User.Info.profile_update(user.info, new_info),
|
|
||||||
changeset <- Ecto.Changeset.change(user) |> Ecto.Changeset.put_embed(:info, info_cng),
|
|
||||||
{:ok, user} <- User.update_and_set_cache(changeset) do
|
|
||||||
CommonAPI.update(user)
|
|
||||||
response = %{url: nil} |> Jason.encode!()
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> json_reply(200, response)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_banner(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}, type: :banner),
|
|
||||||
new_info <- %{"banner" => object.data},
|
|
||||||
info_cng <- User.Info.profile_update(user.info, new_info),
|
|
||||||
changeset <- Ecto.Changeset.change(user) |> Ecto.Changeset.put_embed(:info, info_cng),
|
|
||||||
{:ok, user} <- User.update_and_set_cache(changeset) do
|
|
||||||
CommonAPI.update(user)
|
|
||||||
%{"url" => [%{"href" => href} | _]} = object.data
|
|
||||||
response = %{url: href} |> Jason.encode!()
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> json_reply(200, response)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_background(%{assigns: %{user: user}} = conn, %{"img" => ""}) do
|
|
||||||
with new_info <- %{"background" => %{}},
|
|
||||||
info_cng <- User.Info.profile_update(user.info, new_info),
|
|
||||||
changeset <- Ecto.Changeset.change(user) |> Ecto.Changeset.put_embed(:info, info_cng),
|
|
||||||
{:ok, _user} <- User.update_and_set_cache(changeset) do
|
|
||||||
response = %{url: nil} |> Jason.encode!()
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> json_reply(200, response)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_background(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
with {:ok, object} <- ActivityPub.upload(params, type: :background),
|
|
||||||
new_info <- %{"background" => object.data},
|
|
||||||
info_cng <- User.Info.profile_update(user.info, new_info),
|
|
||||||
changeset <- Ecto.Changeset.change(user) |> Ecto.Changeset.put_embed(:info, info_cng),
|
|
||||||
{:ok, _user} <- User.update_and_set_cache(changeset) do
|
|
||||||
%{"url" => [%{"href" => href} | _]} = object.data
|
|
||||||
response = %{url: href} |> Jason.encode!()
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> json_reply(200, response)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def external_profile(%{assigns: %{user: current_user}} = conn, %{"profileurl" => uri}) do
|
|
||||||
with {:ok, user_map} <- TwitterAPI.get_external_profile(current_user, uri),
|
|
||||||
response <- Jason.encode!(user_map) do
|
|
||||||
conn
|
|
||||||
|> json_reply(200, response)
|
|
||||||
else
|
|
||||||
_e ->
|
|
||||||
conn
|
|
||||||
|> put_status(404)
|
|
||||||
|> json(%{error: "Can't find user"})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def followers(%{assigns: %{user: for_user}} = conn, params) do
|
|
||||||
{:ok, page} = Ecto.Type.cast(:integer, params["page"] || 1)
|
|
||||||
|
|
||||||
with {:ok, user} <- TwitterAPI.get_user(for_user, params),
|
|
||||||
{:ok, followers} <- User.get_followers(user, page) do
|
|
||||||
followers =
|
|
||||||
cond do
|
|
||||||
for_user && user.id == for_user.id -> followers
|
|
||||||
user.info.hide_followers -> []
|
|
||||||
true -> followers
|
|
||||||
end
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("index.json", %{users: followers, for: conn.assigns[:user]})
|
|
||||||
else
|
|
||||||
_e -> bad_request_reply(conn, "Can't get followers")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def friends(%{assigns: %{user: for_user}} = conn, params) do
|
|
||||||
{:ok, page} = Ecto.Type.cast(:integer, params["page"] || 1)
|
|
||||||
{:ok, export} = Ecto.Type.cast(:boolean, params["all"] || false)
|
|
||||||
|
|
||||||
page = if export, do: nil, else: page
|
|
||||||
|
|
||||||
with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params),
|
|
||||||
{:ok, friends} <- User.get_friends(user, page) do
|
|
||||||
friends =
|
|
||||||
cond do
|
|
||||||
for_user && user.id == for_user.id -> friends
|
|
||||||
user.info.hide_follows -> []
|
|
||||||
true -> friends
|
|
||||||
end
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("index.json", %{users: friends, for: conn.assigns[:user]})
|
|
||||||
else
|
|
||||||
_e -> bad_request_reply(conn, "Can't get friends")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def oauth_tokens(%{assigns: %{user: user}} = conn, _params) do
|
def oauth_tokens(%{assigns: %{user: user}} = conn, _params) do
|
||||||
with oauth_tokens <- Token.get_user_tokens(user) do
|
with oauth_tokens <- Token.get_user_tokens(user) do
|
||||||
conn
|
conn
|
||||||
|
@ -615,189 +42,6 @@ def revoke_token(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
|
||||||
json_reply(conn, 201, "")
|
json_reply(conn, 201, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
def blocks(%{assigns: %{user: user}} = conn, _params) do
|
|
||||||
with blocked_users <- User.blocked_users(user) do
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("index.json", %{users: blocked_users, for: user})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def friend_requests(conn, params) do
|
|
||||||
with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params),
|
|
||||||
{:ok, friend_requests} <- User.get_follow_requests(user) do
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("index.json", %{users: friend_requests, for: conn.assigns[:user]})
|
|
||||||
else
|
|
||||||
_e -> bad_request_reply(conn, "Can't get friend requests")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def approve_friend_request(conn, %{"user_id" => uid} = _params) do
|
|
||||||
with followed <- conn.assigns[:user],
|
|
||||||
%User{} = follower <- User.get_cached_by_id(uid),
|
|
||||||
{:ok, follower} <- CommonAPI.accept_follow_request(follower, followed) do
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("show.json", %{user: follower, for: followed})
|
|
||||||
else
|
|
||||||
e -> bad_request_reply(conn, "Can't approve user: #{inspect(e)}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def deny_friend_request(conn, %{"user_id" => uid} = _params) do
|
|
||||||
with followed <- conn.assigns[:user],
|
|
||||||
%User{} = follower <- User.get_cached_by_id(uid),
|
|
||||||
{:ok, follower} <- CommonAPI.reject_follow_request(follower, followed) do
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("show.json", %{user: follower, for: followed})
|
|
||||||
else
|
|
||||||
e -> bad_request_reply(conn, "Can't deny user: #{inspect(e)}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def friends_ids(%{assigns: %{user: user}} = conn, _params) do
|
|
||||||
with {:ok, friends} <- User.get_friends(user) do
|
|
||||||
ids =
|
|
||||||
friends
|
|
||||||
|> Enum.map(fn x -> x.id end)
|
|
||||||
|> Jason.encode!()
|
|
||||||
|
|
||||||
json(conn, ids)
|
|
||||||
else
|
|
||||||
_e -> bad_request_reply(conn, "Can't get friends")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def empty_array(conn, _params) do
|
|
||||||
json(conn, Jason.encode!([]))
|
|
||||||
end
|
|
||||||
|
|
||||||
def raw_empty_array(conn, _params) do
|
|
||||||
json(conn, [])
|
|
||||||
end
|
|
||||||
|
|
||||||
defp build_info_cng(user, params) do
|
|
||||||
info_params =
|
|
||||||
[
|
|
||||||
"no_rich_text",
|
|
||||||
"locked",
|
|
||||||
"hide_followers",
|
|
||||||
"hide_follows",
|
|
||||||
"hide_favorites",
|
|
||||||
"show_role",
|
|
||||||
"skip_thread_containment"
|
|
||||||
]
|
|
||||||
|> Enum.reduce(%{}, fn key, res ->
|
|
||||||
if value = params[key] do
|
|
||||||
Map.put(res, key, value == "true")
|
|
||||||
else
|
|
||||||
res
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
info_params =
|
|
||||||
if value = params["default_scope"] do
|
|
||||||
Map.put(info_params, "default_scope", value)
|
|
||||||
else
|
|
||||||
info_params
|
|
||||||
end
|
|
||||||
|
|
||||||
User.Info.profile_update(user.info, info_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp parse_profile_bio(user, params) do
|
|
||||||
if bio = params["description"] do
|
|
||||||
emojis_text = (params["description"] || "") <> " " <> (params["name"] || "")
|
|
||||||
|
|
||||||
emojis =
|
|
||||||
((user.info.emoji || []) ++ Formatter.get_emoji_map(emojis_text))
|
|
||||||
|> Enum.dedup()
|
|
||||||
|
|
||||||
user_info =
|
|
||||||
user.info
|
|
||||||
|> Map.put(
|
|
||||||
"emoji",
|
|
||||||
emojis
|
|
||||||
)
|
|
||||||
|
|
||||||
params
|
|
||||||
|> Map.put("bio", User.parse_bio(bio, user))
|
|
||||||
|> Map.put("info", user_info)
|
|
||||||
else
|
|
||||||
params
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_profile(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
params = parse_profile_bio(user, params)
|
|
||||||
info_cng = build_info_cng(user, params)
|
|
||||||
|
|
||||||
with changeset <- User.update_changeset(user, params),
|
|
||||||
changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng),
|
|
||||||
{:ok, user} <- User.update_and_set_cache(changeset) do
|
|
||||||
CommonAPI.update(user)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("user.json", %{user: user, for: user})
|
|
||||||
else
|
|
||||||
error ->
|
|
||||||
Logger.debug("Can't update user: #{inspect(error)}")
|
|
||||||
bad_request_reply(conn, "Can't update user")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def search(%{assigns: %{user: user}} = conn, %{"q" => _query} = params) do
|
|
||||||
activities = TwitterAPI.search(user, params)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(ActivityView)
|
|
||||||
|> render("index.json", %{activities: activities, for: user})
|
|
||||||
end
|
|
||||||
|
|
||||||
def search_user(%{assigns: %{user: user}} = conn, %{"query" => query}) do
|
|
||||||
users = User.search(query, resolve: true, for_user: user)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_view(UserView)
|
|
||||||
|> render("index.json", %{users: users, for: user})
|
|
||||||
end
|
|
||||||
|
|
||||||
defp bad_request_reply(conn, error_message) do
|
|
||||||
json = error_json(conn, error_message)
|
|
||||||
json_reply(conn, 400, json)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp json_reply(conn, status, json) do
|
|
||||||
conn
|
|
||||||
|> put_resp_content_type("application/json")
|
|
||||||
|> send_resp(status, json)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp forbidden_json_reply(conn, error_message) do
|
|
||||||
json = error_json(conn, error_message)
|
|
||||||
json_reply(conn, 403, json)
|
|
||||||
end
|
|
||||||
|
|
||||||
def only_if_public_instance(%{assigns: %{user: %User{}}} = conn, _), do: conn
|
|
||||||
|
|
||||||
def only_if_public_instance(conn, _) do
|
|
||||||
if Pleroma.Config.get([:instance, :public]) do
|
|
||||||
conn
|
|
||||||
else
|
|
||||||
conn
|
|
||||||
|> forbidden_json_reply("Invalid credentials.")
|
|
||||||
|> halt()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp error_json(conn, error_message) do
|
|
||||||
%{"error" => error_message, "request" => conn.request_path} |> Jason.encode!()
|
|
||||||
end
|
|
||||||
|
|
||||||
def errors(conn, {:param_cast, _}) do
|
def errors(conn, {:param_cast, _}) do
|
||||||
conn
|
conn
|
||||||
|> put_status(400)
|
|> put_status(400)
|
||||||
|
@ -809,4 +53,34 @@ def errors(conn, _) do
|
||||||
|> put_status(500)
|
|> put_status(500)
|
||||||
|> json("Something went wrong")
|
|> json("Something went wrong")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp json_reply(conn, status, json) do
|
||||||
|
conn
|
||||||
|
|> put_resp_content_type("application/json")
|
||||||
|
|> send_resp(status, json)
|
||||||
|
end
|
||||||
|
|
||||||
|
def notifications_read(%{assigns: %{user: user}} = conn, %{"latest_id" => latest_id} = params) do
|
||||||
|
Notification.set_read_up_to(user, latest_id)
|
||||||
|
|
||||||
|
notifications = Notification.for_user(user, params)
|
||||||
|
|
||||||
|
conn
|
||||||
|
# XXX: This is a hack because pleroma-fe still uses that API.
|
||||||
|
|> put_view(Pleroma.Web.MastodonAPI.NotificationView)
|
||||||
|
|> render("index.json", %{notifications: notifications, for: user})
|
||||||
|
end
|
||||||
|
|
||||||
|
def notifications_read(%{assigns: %{user: _user}} = conn, _) do
|
||||||
|
bad_request_reply(conn, "You need to specify latest_id")
|
||||||
|
end
|
||||||
|
|
||||||
|
defp bad_request_reply(conn, error_message) do
|
||||||
|
json = error_json(conn, error_message)
|
||||||
|
json_reply(conn, 400, json)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp error_json(conn, error_message) do
|
||||||
|
%{"error" => error_message, "request" => conn.request_path} |> Jason.encode!()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,366 +0,0 @@
|
||||||
# Pleroma: A lightweight social networking server
|
|
||||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
|
|
||||||
defmodule Pleroma.Web.TwitterAPI.ActivityView do
|
|
||||||
use Pleroma.Web, :view
|
|
||||||
alias Pleroma.Activity
|
|
||||||
alias Pleroma.Formatter
|
|
||||||
alias Pleroma.HTML
|
|
||||||
alias Pleroma.Object
|
|
||||||
alias Pleroma.Repo
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Web.CommonAPI
|
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
|
||||||
alias Pleroma.Web.MastodonAPI.StatusView
|
|
||||||
alias Pleroma.Web.TwitterAPI.ActivityView
|
|
||||||
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
|
|
||||||
alias Pleroma.Web.TwitterAPI.UserView
|
|
||||||
|
|
||||||
import Ecto.Query
|
|
||||||
require Logger
|
|
||||||
require Pleroma.Constants
|
|
||||||
|
|
||||||
defp query_context_ids([]), do: []
|
|
||||||
|
|
||||||
defp query_context_ids(contexts) do
|
|
||||||
query = from(o in Object, where: fragment("(?)->>'id' = ANY(?)", o.data, ^contexts))
|
|
||||||
|
|
||||||
Repo.all(query)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp query_users([]), do: []
|
|
||||||
|
|
||||||
defp query_users(user_ids) do
|
|
||||||
query = from(user in User, where: user.ap_id in ^user_ids)
|
|
||||||
|
|
||||||
Repo.all(query)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp collect_context_ids(activities) do
|
|
||||||
_contexts =
|
|
||||||
activities
|
|
||||||
|> Enum.reject(& &1.data["context_id"])
|
|
||||||
|> Enum.map(fn %{data: data} ->
|
|
||||||
data["context"]
|
|
||||||
end)
|
|
||||||
|> Enum.filter(& &1)
|
|
||||||
|> query_context_ids()
|
|
||||||
|> Enum.reduce(%{}, fn %{data: %{"id" => ap_id}, id: id}, acc ->
|
|
||||||
Map.put(acc, ap_id, id)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp collect_users(activities) do
|
|
||||||
activities
|
|
||||||
|> Enum.map(fn activity ->
|
|
||||||
case activity.data do
|
|
||||||
data = %{"type" => "Follow"} ->
|
|
||||||
[data["actor"], data["object"]]
|
|
||||||
|
|
||||||
data ->
|
|
||||||
[data["actor"]]
|
|
||||||
end ++ activity.recipients
|
|
||||||
end)
|
|
||||||
|> List.flatten()
|
|
||||||
|> Enum.uniq()
|
|
||||||
|> query_users()
|
|
||||||
|> Enum.reduce(%{}, fn user, acc ->
|
|
||||||
Map.put(acc, user.ap_id, user)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp get_context_id(%{data: %{"context_id" => context_id}}, _) when not is_nil(context_id),
|
|
||||||
do: context_id
|
|
||||||
|
|
||||||
defp get_context_id(%{data: %{"context" => nil}}, _), do: nil
|
|
||||||
|
|
||||||
defp get_context_id(%{data: %{"context" => context}}, options) do
|
|
||||||
cond do
|
|
||||||
id = options[:context_ids][context] -> id
|
|
||||||
true -> Utils.context_to_conversation_id(context)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp get_context_id(_, _), do: nil
|
|
||||||
|
|
||||||
defp get_user(ap_id, opts) do
|
|
||||||
cond do
|
|
||||||
user = opts[:users][ap_id] ->
|
|
||||||
user
|
|
||||||
|
|
||||||
String.ends_with?(ap_id, "/followers") ->
|
|
||||||
nil
|
|
||||||
|
|
||||||
ap_id == Pleroma.Constants.as_public() ->
|
|
||||||
nil
|
|
||||||
|
|
||||||
user = User.get_cached_by_ap_id(ap_id) ->
|
|
||||||
user
|
|
||||||
|
|
||||||
user = User.get_by_guessed_nickname(ap_id) ->
|
|
||||||
user
|
|
||||||
|
|
||||||
true ->
|
|
||||||
User.error_user(ap_id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def render("index.json", opts) do
|
|
||||||
context_ids = collect_context_ids(opts.activities)
|
|
||||||
users = collect_users(opts.activities)
|
|
||||||
|
|
||||||
opts =
|
|
||||||
opts
|
|
||||||
|> Map.put(:context_ids, context_ids)
|
|
||||||
|> Map.put(:users, users)
|
|
||||||
|
|
||||||
safe_render_many(
|
|
||||||
opts.activities,
|
|
||||||
ActivityView,
|
|
||||||
"activity.json",
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def render("activity.json", %{activity: %{data: %{"type" => "Delete"}} = activity} = opts) do
|
|
||||||
user = get_user(activity.data["actor"], opts)
|
|
||||||
created_at = activity.data["published"] |> Utils.date_to_asctime()
|
|
||||||
|
|
||||||
%{
|
|
||||||
"id" => activity.id,
|
|
||||||
"uri" => activity.data["object"],
|
|
||||||
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
|
|
||||||
"attentions" => [],
|
|
||||||
"statusnet_html" => "deleted notice {{tag",
|
|
||||||
"text" => "deleted notice {{tag",
|
|
||||||
"is_local" => activity.local,
|
|
||||||
"is_post_verb" => false,
|
|
||||||
"created_at" => created_at,
|
|
||||||
"in_reply_to_status_id" => nil,
|
|
||||||
"external_url" => activity.data["id"],
|
|
||||||
"activity_type" => "delete"
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def render("activity.json", %{activity: %{data: %{"type" => "Follow"}} = activity} = opts) do
|
|
||||||
user = get_user(activity.data["actor"], opts)
|
|
||||||
created_at = activity.data["published"] || DateTime.to_iso8601(activity.inserted_at)
|
|
||||||
created_at = created_at |> Utils.date_to_asctime()
|
|
||||||
|
|
||||||
followed = get_user(activity.data["object"], opts)
|
|
||||||
text = "#{user.nickname} started following #{followed.nickname}"
|
|
||||||
|
|
||||||
%{
|
|
||||||
"id" => activity.id,
|
|
||||||
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
|
|
||||||
"attentions" => [],
|
|
||||||
"statusnet_html" => text,
|
|
||||||
"text" => text,
|
|
||||||
"is_local" => activity.local,
|
|
||||||
"is_post_verb" => false,
|
|
||||||
"created_at" => created_at,
|
|
||||||
"in_reply_to_status_id" => nil,
|
|
||||||
"external_url" => activity.data["id"],
|
|
||||||
"activity_type" => "follow"
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def render("activity.json", %{activity: %{data: %{"type" => "Announce"}} = activity} = opts) do
|
|
||||||
user = get_user(activity.data["actor"], opts)
|
|
||||||
created_at = activity.data["published"] |> Utils.date_to_asctime()
|
|
||||||
announced_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
|
|
||||||
|
|
||||||
text = "#{user.nickname} repeated a status."
|
|
||||||
|
|
||||||
retweeted_status = render("activity.json", Map.merge(opts, %{activity: announced_activity}))
|
|
||||||
|
|
||||||
%{
|
|
||||||
"id" => activity.id,
|
|
||||||
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
|
|
||||||
"statusnet_html" => text,
|
|
||||||
"text" => text,
|
|
||||||
"is_local" => activity.local,
|
|
||||||
"is_post_verb" => false,
|
|
||||||
"uri" => "tag:#{activity.data["id"]}:objectType=note",
|
|
||||||
"created_at" => created_at,
|
|
||||||
"retweeted_status" => retweeted_status,
|
|
||||||
"statusnet_conversation_id" => get_context_id(announced_activity, opts),
|
|
||||||
"external_url" => activity.data["id"],
|
|
||||||
"activity_type" => "repeat"
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def render("activity.json", %{activity: %{data: %{"type" => "Like"}} = activity} = opts) do
|
|
||||||
user = get_user(activity.data["actor"], opts)
|
|
||||||
liked_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
|
|
||||||
liked_activity_id = if liked_activity, do: liked_activity.id, else: nil
|
|
||||||
|
|
||||||
created_at =
|
|
||||||
activity.data["published"]
|
|
||||||
|> Utils.date_to_asctime()
|
|
||||||
|
|
||||||
text = "#{user.nickname} favorited a status."
|
|
||||||
|
|
||||||
favorited_status =
|
|
||||||
if liked_activity,
|
|
||||||
do: render("activity.json", Map.merge(opts, %{activity: liked_activity})),
|
|
||||||
else: nil
|
|
||||||
|
|
||||||
%{
|
|
||||||
"id" => activity.id,
|
|
||||||
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
|
|
||||||
"statusnet_html" => text,
|
|
||||||
"text" => text,
|
|
||||||
"is_local" => activity.local,
|
|
||||||
"is_post_verb" => false,
|
|
||||||
"uri" => "tag:#{activity.data["id"]}:objectType=Favourite",
|
|
||||||
"created_at" => created_at,
|
|
||||||
"favorited_status" => favorited_status,
|
|
||||||
"in_reply_to_status_id" => liked_activity_id,
|
|
||||||
"external_url" => activity.data["id"],
|
|
||||||
"activity_type" => "like"
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def render(
|
|
||||||
"activity.json",
|
|
||||||
%{activity: %{data: %{"type" => "Create", "object" => object_id}} = activity} = opts
|
|
||||||
) do
|
|
||||||
user = get_user(activity.data["actor"], opts)
|
|
||||||
|
|
||||||
object = Object.normalize(object_id)
|
|
||||||
|
|
||||||
created_at = object.data["published"] |> Utils.date_to_asctime()
|
|
||||||
like_count = object.data["like_count"] || 0
|
|
||||||
announcement_count = object.data["announcement_count"] || 0
|
|
||||||
favorited = opts[:for] && opts[:for].ap_id in (object.data["likes"] || [])
|
|
||||||
repeated = opts[:for] && opts[:for].ap_id in (object.data["announcements"] || [])
|
|
||||||
pinned = activity.id in user.info.pinned_activities
|
|
||||||
|
|
||||||
attentions =
|
|
||||||
[]
|
|
||||||
|> Utils.maybe_notify_to_recipients(activity)
|
|
||||||
|> Utils.maybe_notify_mentioned_recipients(activity)
|
|
||||||
|> Enum.map(fn ap_id -> get_user(ap_id, opts) end)
|
|
||||||
|> Enum.filter(& &1)
|
|
||||||
|> Enum.map(fn user -> UserView.render("show.json", %{user: user, for: opts[:for]}) end)
|
|
||||||
|
|
||||||
conversation_id = get_context_id(activity, opts)
|
|
||||||
|
|
||||||
tags = object.data["tag"] || []
|
|
||||||
possibly_sensitive = object.data["sensitive"] || Enum.member?(tags, "nsfw")
|
|
||||||
|
|
||||||
tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
|
|
||||||
|
|
||||||
{summary, content} = render_content(object.data)
|
|
||||||
|
|
||||||
html =
|
|
||||||
content
|
|
||||||
|> HTML.get_cached_scrubbed_html_for_activity(
|
|
||||||
User.html_filter_policy(opts[:for]),
|
|
||||||
activity,
|
|
||||||
"twitterapi:content"
|
|
||||||
)
|
|
||||||
|> Formatter.emojify(object.data["emoji"])
|
|
||||||
|
|
||||||
text =
|
|
||||||
if content do
|
|
||||||
content
|
|
||||||
|> String.replace(~r/<br\s?\/?>/, "\n")
|
|
||||||
|> HTML.get_cached_stripped_html_for_activity(activity, "twitterapi:content")
|
|
||||||
else
|
|
||||||
""
|
|
||||||
end
|
|
||||||
|
|
||||||
reply_parent = Activity.get_in_reply_to_activity(activity)
|
|
||||||
|
|
||||||
reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor)
|
|
||||||
|
|
||||||
summary = HTML.strip_tags(summary)
|
|
||||||
|
|
||||||
card =
|
|
||||||
StatusView.render(
|
|
||||||
"card.json",
|
|
||||||
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
|
||||||
)
|
|
||||||
|
|
||||||
thread_muted? =
|
|
||||||
case activity.thread_muted? do
|
|
||||||
thread_muted? when is_boolean(thread_muted?) -> thread_muted?
|
|
||||||
nil -> CommonAPI.thread_muted?(user, activity)
|
|
||||||
end
|
|
||||||
|
|
||||||
%{
|
|
||||||
"id" => activity.id,
|
|
||||||
"uri" => object.data["id"],
|
|
||||||
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
|
|
||||||
"statusnet_html" => html,
|
|
||||||
"text" => text,
|
|
||||||
"is_local" => activity.local,
|
|
||||||
"is_post_verb" => true,
|
|
||||||
"created_at" => created_at,
|
|
||||||
"in_reply_to_status_id" => reply_parent && reply_parent.id,
|
|
||||||
"in_reply_to_screen_name" => reply_user && reply_user.nickname,
|
|
||||||
"in_reply_to_profileurl" => User.profile_url(reply_user),
|
|
||||||
"in_reply_to_ostatus_uri" => reply_user && reply_user.ap_id,
|
|
||||||
"in_reply_to_user_id" => reply_user && reply_user.id,
|
|
||||||
"statusnet_conversation_id" => conversation_id,
|
|
||||||
"attachments" => (object.data["attachment"] || []) |> ObjectRepresenter.enum_to_list(opts),
|
|
||||||
"attentions" => attentions,
|
|
||||||
"fave_num" => like_count,
|
|
||||||
"repeat_num" => announcement_count,
|
|
||||||
"favorited" => !!favorited,
|
|
||||||
"repeated" => !!repeated,
|
|
||||||
"pinned" => pinned,
|
|
||||||
"external_url" => object.data["external_url"] || object.data["id"],
|
|
||||||
"tags" => tags,
|
|
||||||
"activity_type" => "post",
|
|
||||||
"possibly_sensitive" => possibly_sensitive,
|
|
||||||
"visibility" => Pleroma.Web.ActivityPub.Visibility.get_visibility(object),
|
|
||||||
"summary" => summary,
|
|
||||||
"summary_html" => summary |> Formatter.emojify(object.data["emoji"]),
|
|
||||||
"card" => card,
|
|
||||||
"muted" => thread_muted? || User.mutes?(opts[:for], user)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def render("activity.json", %{activity: unhandled_activity}) do
|
|
||||||
Logger.warn("#{__MODULE__} unhandled activity: #{inspect(unhandled_activity)}")
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_content(%{"type" => "Note"} = object) do
|
|
||||||
summary = object["summary"]
|
|
||||||
|
|
||||||
content =
|
|
||||||
if !!summary and summary != "" do
|
|
||||||
"<p>#{summary}</p>#{object["content"]}"
|
|
||||||
else
|
|
||||||
object["content"]
|
|
||||||
end
|
|
||||||
|
|
||||||
{summary, content}
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_content(%{"type" => object_type} = object)
|
|
||||||
when object_type in ["Article", "Page", "Video"] do
|
|
||||||
summary = object["name"] || object["summary"]
|
|
||||||
|
|
||||||
content =
|
|
||||||
if !!summary and summary != "" and is_bitstring(object["url"]) do
|
|
||||||
"<p><a href=\"#{object["url"]}\">#{summary}</a></p>#{object["content"]}"
|
|
||||||
else
|
|
||||||
object["content"]
|
|
||||||
end
|
|
||||||
|
|
||||||
{summary, content}
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_content(object) do
|
|
||||||
summary = object["summary"] || "Unhandled activity type: #{object["type"]}"
|
|
||||||
content = "<p>#{summary}</p>#{object["content"]}"
|
|
||||||
|
|
||||||
{summary, content}
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,71 +0,0 @@
|
||||||
# Pleroma: A lightweight social networking server
|
|
||||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
|
|
||||||
defmodule Pleroma.Web.TwitterAPI.NotificationView do
|
|
||||||
use Pleroma.Web, :view
|
|
||||||
alias Pleroma.Notification
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
|
||||||
alias Pleroma.Web.TwitterAPI.ActivityView
|
|
||||||
alias Pleroma.Web.TwitterAPI.UserView
|
|
||||||
|
|
||||||
require Pleroma.Constants
|
|
||||||
|
|
||||||
defp get_user(ap_id, opts) do
|
|
||||||
cond do
|
|
||||||
user = opts[:users][ap_id] ->
|
|
||||||
user
|
|
||||||
|
|
||||||
String.ends_with?(ap_id, "/followers") ->
|
|
||||||
nil
|
|
||||||
|
|
||||||
ap_id == Pleroma.Constants.as_public() ->
|
|
||||||
nil
|
|
||||||
|
|
||||||
true ->
|
|
||||||
User.get_cached_by_ap_id(ap_id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def render("notification.json", %{notifications: notifications, for: user}) do
|
|
||||||
render_many(
|
|
||||||
notifications,
|
|
||||||
Pleroma.Web.TwitterAPI.NotificationView,
|
|
||||||
"notification.json",
|
|
||||||
for: user
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def render(
|
|
||||||
"notification.json",
|
|
||||||
%{
|
|
||||||
notification: %Notification{
|
|
||||||
id: id,
|
|
||||||
seen: seen,
|
|
||||||
activity: activity,
|
|
||||||
inserted_at: created_at
|
|
||||||
},
|
|
||||||
for: user
|
|
||||||
} = opts
|
|
||||||
) do
|
|
||||||
ntype =
|
|
||||||
case activity.data["type"] do
|
|
||||||
"Create" -> "mention"
|
|
||||||
"Like" -> "like"
|
|
||||||
"Announce" -> "repeat"
|
|
||||||
"Follow" -> "follow"
|
|
||||||
end
|
|
||||||
|
|
||||||
from = get_user(activity.data["actor"], opts)
|
|
||||||
|
|
||||||
%{
|
|
||||||
"id" => id,
|
|
||||||
"ntype" => ntype,
|
|
||||||
"notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
|
|
||||||
"from_profile" => UserView.render("show.json", %{user: from, for: user}),
|
|
||||||
"is_seen" => if(seen, do: 1, else: 0),
|
|
||||||
"created_at" => created_at |> Utils.format_naive_asctime()
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,191 +0,0 @@
|
||||||
# Pleroma: A lightweight social networking server
|
|
||||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
|
|
||||||
defmodule Pleroma.Web.TwitterAPI.UserView do
|
|
||||||
use Pleroma.Web, :view
|
|
||||||
alias Pleroma.Formatter
|
|
||||||
alias Pleroma.HTML
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
|
||||||
alias Pleroma.Web.MediaProxy
|
|
||||||
|
|
||||||
def render("show.json", %{user: user = %User{}} = assigns) do
|
|
||||||
render_one(user, Pleroma.Web.TwitterAPI.UserView, "user.json", assigns)
|
|
||||||
end
|
|
||||||
|
|
||||||
def render("index.json", %{users: users, for: user}) do
|
|
||||||
users
|
|
||||||
|> render_many(Pleroma.Web.TwitterAPI.UserView, "user.json", for: user)
|
|
||||||
|> Enum.filter(&Enum.any?/1)
|
|
||||||
end
|
|
||||||
|
|
||||||
def render("user.json", %{user: user = %User{}} = assigns) do
|
|
||||||
if User.visible_for?(user, assigns[:for]),
|
|
||||||
do: do_render("user.json", assigns),
|
|
||||||
else: %{}
|
|
||||||
end
|
|
||||||
|
|
||||||
def render("short.json", %{
|
|
||||||
user: %User{
|
|
||||||
nickname: nickname,
|
|
||||||
id: id,
|
|
||||||
ap_id: ap_id,
|
|
||||||
name: name
|
|
||||||
}
|
|
||||||
}) do
|
|
||||||
%{
|
|
||||||
"fullname" => name,
|
|
||||||
"id" => id,
|
|
||||||
"ostatus_uri" => ap_id,
|
|
||||||
"profile_url" => ap_id,
|
|
||||||
"screen_name" => nickname
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
defp do_render("user.json", %{user: user = %User{}} = assigns) do
|
|
||||||
for_user = assigns[:for]
|
|
||||||
image = User.avatar_url(user) |> MediaProxy.url()
|
|
||||||
|
|
||||||
{following, follows_you, statusnet_blocking} =
|
|
||||||
if for_user do
|
|
||||||
{
|
|
||||||
User.following?(for_user, user),
|
|
||||||
User.following?(user, for_user),
|
|
||||||
User.blocks?(for_user, user)
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{false, false, false}
|
|
||||||
end
|
|
||||||
|
|
||||||
user_info = User.get_cached_user_info(user)
|
|
||||||
|
|
||||||
emoji =
|
|
||||||
(user.info.source_data["tag"] || [])
|
|
||||||
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
|
|
||||||
|> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
|
|
||||||
{String.trim(name, ":"), url}
|
|
||||||
end)
|
|
||||||
|
|
||||||
emoji = Enum.dedup(emoji ++ user.info.emoji)
|
|
||||||
|
|
||||||
description_html =
|
|
||||||
(user.bio || "")
|
|
||||||
|> HTML.filter_tags(User.html_filter_policy(for_user))
|
|
||||||
|> Formatter.emojify(emoji)
|
|
||||||
|
|
||||||
fields =
|
|
||||||
user.info
|
|
||||||
|> User.Info.fields()
|
|
||||||
|> Enum.map(fn %{"name" => name, "value" => value} ->
|
|
||||||
%{
|
|
||||||
"name" => Pleroma.HTML.strip_tags(name),
|
|
||||||
"value" => Pleroma.HTML.filter_tags(value, Pleroma.HTML.Scrubber.LinksOnly)
|
|
||||||
}
|
|
||||||
end)
|
|
||||||
|
|
||||||
data =
|
|
||||||
%{
|
|
||||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
|
||||||
"description" => HTML.strip_tags((user.bio || "") |> String.replace("<br>", "\n")),
|
|
||||||
"description_html" => description_html,
|
|
||||||
"favourites_count" => 0,
|
|
||||||
"followers_count" => user_info[:follower_count],
|
|
||||||
"following" => following,
|
|
||||||
"follows_you" => follows_you,
|
|
||||||
"statusnet_blocking" => statusnet_blocking,
|
|
||||||
"friends_count" => user_info[:following_count],
|
|
||||||
"id" => user.id,
|
|
||||||
"name" => user.name || user.nickname,
|
|
||||||
"name_html" =>
|
|
||||||
if(user.name,
|
|
||||||
do: HTML.strip_tags(user.name) |> Formatter.emojify(emoji),
|
|
||||||
else: user.nickname
|
|
||||||
),
|
|
||||||
"profile_image_url" => image,
|
|
||||||
"profile_image_url_https" => image,
|
|
||||||
"profile_image_url_profile_size" => image,
|
|
||||||
"profile_image_url_original" => image,
|
|
||||||
"screen_name" => user.nickname,
|
|
||||||
"statuses_count" => user_info[:note_count],
|
|
||||||
"statusnet_profile_url" => user.ap_id,
|
|
||||||
"cover_photo" => User.banner_url(user) |> MediaProxy.url(),
|
|
||||||
"background_image" => image_url(user.info.background) |> MediaProxy.url(),
|
|
||||||
"is_local" => user.local,
|
|
||||||
"locked" => user.info.locked,
|
|
||||||
"hide_followers" => user.info.hide_followers,
|
|
||||||
"hide_follows" => user.info.hide_follows,
|
|
||||||
"fields" => fields,
|
|
||||||
|
|
||||||
# Pleroma extension
|
|
||||||
"pleroma" =>
|
|
||||||
%{
|
|
||||||
"confirmation_pending" => user_info.confirmation_pending,
|
|
||||||
"tags" => user.tags,
|
|
||||||
"skip_thread_containment" => user.info.skip_thread_containment
|
|
||||||
}
|
|
||||||
|> maybe_with_activation_status(user, for_user)
|
|
||||||
|> with_notification_settings(user, for_user)
|
|
||||||
}
|
|
||||||
|> maybe_with_user_settings(user, for_user)
|
|
||||||
|> maybe_with_role(user, for_user)
|
|
||||||
|
|
||||||
if assigns[:token] do
|
|
||||||
Map.put(data, "token", token_string(assigns[:token]))
|
|
||||||
else
|
|
||||||
data
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp with_notification_settings(data, %User{id: user_id} = user, %User{id: user_id}) do
|
|
||||||
Map.put(data, "notification_settings", user.info.notification_settings)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp with_notification_settings(data, _, _), do: data
|
|
||||||
|
|
||||||
defp maybe_with_activation_status(data, user, %User{info: %{is_admin: true}}) do
|
|
||||||
Map.put(data, "deactivated", user.info.deactivated)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp maybe_with_activation_status(data, _, _), do: data
|
|
||||||
|
|
||||||
defp maybe_with_role(data, %User{id: id} = user, %User{id: id}) do
|
|
||||||
Map.merge(data, %{
|
|
||||||
"role" => role(user),
|
|
||||||
"show_role" => user.info.show_role,
|
|
||||||
"rights" => %{
|
|
||||||
"delete_others_notice" => !!user.info.is_moderator,
|
|
||||||
"admin" => !!user.info.is_admin
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
defp maybe_with_role(data, %User{info: %{show_role: true}} = user, _user) do
|
|
||||||
Map.merge(data, %{
|
|
||||||
"role" => role(user),
|
|
||||||
"rights" => %{
|
|
||||||
"delete_others_notice" => !!user.info.is_moderator,
|
|
||||||
"admin" => !!user.info.is_admin
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
defp maybe_with_role(data, _, _), do: data
|
|
||||||
|
|
||||||
defp maybe_with_user_settings(data, %User{info: info, id: id} = _user, %User{id: id}) do
|
|
||||||
data
|
|
||||||
|> Kernel.put_in(["default_scope"], info.default_scope)
|
|
||||||
|> Kernel.put_in(["no_rich_text"], info.no_rich_text)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp maybe_with_user_settings(data, _, _), do: data
|
|
||||||
defp role(%User{info: %{:is_admin => true}}), do: "admin"
|
|
||||||
defp role(%User{info: %{:is_moderator => true}}), do: "moderator"
|
|
||||||
defp role(_), do: "member"
|
|
||||||
|
|
||||||
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
|
|
||||||
defp image_url(_), do: nil
|
|
||||||
|
|
||||||
defp token_string(%Pleroma.Web.OAuth.Token{token: token_str}), do: token_str
|
|
||||||
defp token_string(token), do: token
|
|
||||||
end
|
|
|
@ -66,23 +66,9 @@ def safe_render(view, template, assigns \\ %{}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Same as `render_many/4` but wrapped in rescue block and parallelized (unless disabled by passing false as a fifth argument).
|
Same as `render_many/4` but wrapped in rescue block.
|
||||||
"""
|
"""
|
||||||
def safe_render_many(collection, view, template, assigns \\ %{}, parallel \\ true)
|
def safe_render_many(collection, view, template, assigns \\ %{}) do
|
||||||
|
|
||||||
def safe_render_many(collection, view, template, assigns, true) do
|
|
||||||
Enum.map(collection, fn resource ->
|
|
||||||
Task.async(fn ->
|
|
||||||
as = Map.get(assigns, :as) || view.__resource__
|
|
||||||
assigns = Map.put(assigns, as, resource)
|
|
||||||
safe_render(view, template, assigns)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|> Enum.map(&Task.await(&1, :infinity))
|
|
||||||
|> Enum.filter(& &1)
|
|
||||||
end
|
|
||||||
|
|
||||||
def safe_render_many(collection, view, template, assigns, false) do
|
|
||||||
Enum.map(collection, fn resource ->
|
Enum.map(collection, fn resource ->
|
||||||
as = Map.get(assigns, :as) || view.__resource__
|
as = Map.get(assigns, :as) || view.__resource__
|
||||||
assigns = Map.put(assigns, as, resource)
|
assigns = Map.put(assigns, as, resource)
|
||||||
|
|
5
mix.exs
5
mix.exs
|
@ -125,7 +125,7 @@ defp deps do
|
||||||
{:crypt,
|
{:crypt,
|
||||||
git: "https://github.com/msantos/crypt", ref: "1f2b58927ab57e72910191a7ebaeff984382a1d3"},
|
git: "https://github.com/msantos/crypt", ref: "1f2b58927ab57e72910191a7ebaeff984382a1d3"},
|
||||||
{:cors_plug, "~> 1.5"},
|
{:cors_plug, "~> 1.5"},
|
||||||
{:ex_doc, "~> 0.20.2", only: :dev, runtime: false},
|
{:ex_doc, "~> 0.21", only: :dev, runtime: false},
|
||||||
{:web_push_encryption, "~> 0.2.1"},
|
{:web_push_encryption, "~> 0.2.1"},
|
||||||
{:swoosh, "~> 0.23.2"},
|
{:swoosh, "~> 0.23.2"},
|
||||||
{:phoenix_swoosh, "~> 0.2"},
|
{:phoenix_swoosh, "~> 0.2"},
|
||||||
|
@ -172,7 +172,8 @@ defp aliases do
|
||||||
"ecto.rollback": ["pleroma.ecto.rollback"],
|
"ecto.rollback": ["pleroma.ecto.rollback"],
|
||||||
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
|
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
|
||||||
"ecto.reset": ["ecto.drop", "ecto.setup"],
|
"ecto.reset": ["ecto.drop", "ecto.setup"],
|
||||||
test: ["ecto.create --quiet", "ecto.migrate", "test"]
|
test: ["ecto.create --quiet", "ecto.migrate", "test"],
|
||||||
|
docs: ["pleroma.docs", "docs"]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
10
mix.lock
10
mix.lock
|
@ -20,7 +20,7 @@
|
||||||
"db_connection": {:hex, :db_connection, "2.0.6", "bde2f85d047969c5b5800cb8f4b3ed6316c8cb11487afedac4aa5f93fd39abfa", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
|
"db_connection": {:hex, :db_connection, "2.0.6", "bde2f85d047969c5b5800cb8f4b3ed6316c8cb11487afedac4aa5f93fd39abfa", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"},
|
"decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"},
|
||||||
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm"},
|
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm"},
|
||||||
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"},
|
"earmark": {:hex, :earmark, "1.3.6", "ce1d0675e10a5bb46b007549362bd3f5f08908843957687d8484fe7f37466b19", [:mix], [], "hexpm"},
|
||||||
"ecto": {:hex, :ecto, "3.1.4", "69d852da7a9f04ede725855a35ede48d158ca11a404fe94f8b2fb3b2162cd3c9", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
|
"ecto": {:hex, :ecto, "3.1.4", "69d852da7a9f04ede725855a35ede48d158ca11a404fe94f8b2fb3b2162cd3c9", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
"ecto_sql": {:hex, :ecto_sql, "3.1.3", "2c536139190492d9de33c5fefac7323c5eaaa82e1b9bf93482a14649042f7cd9", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:myxql, "~> 0.2.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
|
"ecto_sql": {:hex, :ecto_sql, "3.1.3", "2c536139190492d9de33c5fefac7323c5eaaa82e1b9bf93482a14649042f7cd9", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:myxql, "~> 0.2.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"esshd": {:hex, :esshd, "0.1.0", "6f93a2062adb43637edad0ea7357db2702a4b80dd9683482fe00f5134e97f4c1", [:mix], [], "hexpm"},
|
"esshd": {:hex, :esshd, "0.1.0", "6f93a2062adb43637edad0ea7357db2702a4b80dd9683482fe00f5134e97f4c1", [:mix], [], "hexpm"},
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
"ex_aws": {:hex, :ex_aws, "2.1.0", "b92651527d6c09c479f9013caa9c7331f19cba38a650590d82ebf2c6c16a1d8a", [:mix], [{:configparser_ex, "~> 2.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "1.6.3 or 1.6.5 or 1.7.1 or 1.8.6 or ~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:poison, ">= 1.2.0", [hex: :poison, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:xml_builder, "~> 0.1.0", [hex: :xml_builder, repo: "hexpm", optional: true]}], "hexpm"},
|
"ex_aws": {:hex, :ex_aws, "2.1.0", "b92651527d6c09c479f9013caa9c7331f19cba38a650590d82ebf2c6c16a1d8a", [:mix], [{:configparser_ex, "~> 2.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "1.6.3 or 1.6.5 or 1.7.1 or 1.8.6 or ~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:poison, ">= 1.2.0", [hex: :poison, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:xml_builder, "~> 0.1.0", [hex: :xml_builder, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
"ex_aws_s3": {:hex, :ex_aws_s3, "2.0.1", "9e09366e77f25d3d88c5393824e613344631be8db0d1839faca49686e99b6704", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm"},
|
"ex_aws_s3": {:hex, :ex_aws_s3, "2.0.1", "9e09366e77f25d3d88c5393824e613344631be8db0d1839faca49686e99b6704", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
"ex_const": {:hex, :ex_const, "0.2.4", "d06e540c9d834865b012a17407761455efa71d0ce91e5831e86881b9c9d82448", [:mix], [], "hexpm"},
|
"ex_const": {:hex, :ex_const, "0.2.4", "d06e540c9d834865b012a17407761455efa71d0ce91e5831e86881b9c9d82448", [:mix], [], "hexpm"},
|
||||||
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
|
"ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"ex_machina": {:hex, :ex_machina, "2.3.0", "92a5ad0a8b10ea6314b876a99c8c9e3f25f4dde71a2a835845b136b9adaf199a", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm"},
|
"ex_machina": {:hex, :ex_machina, "2.3.0", "92a5ad0a8b10ea6314b876a99c8c9e3f25f4dde71a2a835845b136b9adaf199a", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
"ex_rated": {:hex, :ex_rated, "1.3.3", "30ecbdabe91f7eaa9d37fa4e81c85ba420f371babeb9d1910adbcd79ec798d27", [:mix], [{:ex2ms, "~> 1.5", [hex: :ex2ms, repo: "hexpm", optional: false]}], "hexpm"},
|
"ex_rated": {:hex, :ex_rated, "1.3.3", "30ecbdabe91f7eaa9d37fa4e81c85ba420f371babeb9d1910adbcd79ec798d27", [:mix], [{:ex2ms, "~> 1.5", [hex: :ex2ms, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"ex_syslogger": {:git, "https://github.com/slashmili/ex_syslogger.git", "f3963399047af17e038897c69e20d552e6899e1d", [tag: "1.4.0"]},
|
"ex_syslogger": {:git, "https://github.com/slashmili/ex_syslogger.git", "f3963399047af17e038897c69e20d552e6899e1d", [tag: "1.4.0"]},
|
||||||
|
@ -46,8 +46,8 @@
|
||||||
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
|
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
"joken": {:hex, :joken, "2.0.1", "ec9ab31bf660f343380da033b3316855197c8d4c6ef597fa3fcb451b326beb14", [:mix], [{:jose, "~> 1.9", [hex: :jose, repo: "hexpm", optional: false]}], "hexpm"},
|
"joken": {:hex, :joken, "2.0.1", "ec9ab31bf660f343380da033b3316855197c8d4c6ef597fa3fcb451b326beb14", [:mix], [{:jose, "~> 1.9", [hex: :jose, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"jose": {:hex, :jose, "1.9.0", "4167c5f6d06ffaebffd15cdb8da61a108445ef5e85ab8f5a7ad926fdf3ada154", [:mix, :rebar3], [{:base64url, "~> 0.0.1", [hex: :base64url, repo: "hexpm", optional: false]}], "hexpm"},
|
"jose": {:hex, :jose, "1.9.0", "4167c5f6d06ffaebffd15cdb8da61a108445ef5e85ab8f5a7ad926fdf3ada154", [:mix, :rebar3], [{:base64url, "~> 0.0.1", [hex: :base64url, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
|
"makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
|
"makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"meck": {:hex, :meck, "0.8.13", "ffedb39f99b0b99703b8601c6f17c7f76313ee12de6b646e671e3188401f7866", [:rebar3], [], "hexpm"},
|
"meck": {:hex, :meck, "0.8.13", "ffedb39f99b0b99703b8601c6f17c7f76313ee12de6b646e671e3188401f7866", [:rebar3], [], "hexpm"},
|
||||||
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
|
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
|
||||||
"mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"},
|
"mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"},
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
"mock": {:hex, :mock, "0.3.3", "42a433794b1291a9cf1525c6d26b38e039e0d3a360732b5e467bfc77ef26c914", [:mix], [{:meck, "~> 0.8.13", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
|
"mock": {:hex, :mock, "0.3.3", "42a433794b1291a9cf1525c6d26b38e039e0d3a360732b5e467bfc77ef26c914", [:mix], [{:meck, "~> 0.8.13", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"mogrify": {:hex, :mogrify, "0.6.1", "de1b527514f2d95a7bbe9642eb556061afb337e220cf97adbf3a4e6438ed70af", [:mix], [], "hexpm"},
|
"mogrify": {:hex, :mogrify, "0.6.1", "de1b527514f2d95a7bbe9642eb556061afb337e220cf97adbf3a4e6438ed70af", [:mix], [], "hexpm"},
|
||||||
"mox": {:hex, :mox, "0.5.1", "f86bb36026aac1e6f924a4b6d024b05e9adbed5c63e8daa069bd66fb3292165b", [:mix], [], "hexpm"},
|
"mox": {:hex, :mox, "0.5.1", "f86bb36026aac1e6f924a4b6d024b05e9adbed5c63e8daa069bd66fb3292165b", [:mix], [], "hexpm"},
|
||||||
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
|
"nimble_parsec": {:hex, :nimble_parsec, "0.5.1", "c90796ecee0289dbb5ad16d3ad06f957b0cd1199769641c961cfe0b97db190e0", [:mix], [], "hexpm"},
|
||||||
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
|
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
|
||||||
"pbkdf2_elixir": {:hex, :pbkdf2_elixir, "0.12.3", "6706a148809a29c306062862c803406e88f048277f6e85b68faf73291e820b84", [:mix], [], "hexpm"},
|
"pbkdf2_elixir": {:hex, :pbkdf2_elixir, "0.12.3", "6706a148809a29c306062862c803406e88f048277f6e85b68faf73291e820b84", [:mix], [], "hexpm"},
|
||||||
"phoenix": {:hex, :phoenix, "1.4.9", "746d098e10741c334d88143d3c94cab1756435f94387a63441792e66ec0ee974", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.8.1 or ~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
|
"phoenix": {:hex, :phoenix, "1.4.9", "746d098e10741c334d88143d3c94cab1756435f94387a63441792e66ec0ee974", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.8.1 or ~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1,user-scalable=no"><title>Pleroma</title><!--server-generated-meta--><link rel=icon type=image/png href=/favicon.png><link rel=stylesheet href=/static/font/css/fontello.css><link rel=stylesheet href=/static/font/css/animation.css><link href=/static/css/vendors~app.b2603a50868c68a1c192.css rel=stylesheet><link href=/static/css/app.db80066bde2c96ea6198.css rel=stylesheet></head><body style="display: none"><div id=app></div><script type=text/javascript src=/static/js/vendors~app.4b7be53256fba5c365c9.js></script><script type=text/javascript src=/static/js/app.670c36c0acc42fadb4fe.js></script></body></html>
|
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1,user-scalable=no"><title>Pleroma</title><!--server-generated-meta--><link rel=icon type=image/png href=/favicon.png><link rel=stylesheet href=/static/font/css/fontello.css><link rel=stylesheet href=/static/font/css/animation.css><link href=/static/css/vendors~app.b2603a50868c68a1c192.css rel=stylesheet><link href=/static/css/app.cb3673e4b661fd9526ea.css rel=stylesheet></head><body><noscript>To use Pleroma, please enable JavaScript.</noscript><div id=app></div><script type=text/javascript src=/static/js/vendors~app.4cedffe4993b111c7421.js></script><script type=text/javascript src=/static/js/app.8098503330c7dd14a415.js></script></body></html>
|
|
@ -6,7 +6,6 @@
|
||||||
"logoMargin": ".1em",
|
"logoMargin": ".1em",
|
||||||
"redirectRootNoLogin": "/main/all",
|
"redirectRootNoLogin": "/main/all",
|
||||||
"redirectRootLogin": "/main/friends",
|
"redirectRootLogin": "/main/friends",
|
||||||
"chatDisabled": false,
|
|
||||||
"showInstanceSpecificPanel": false,
|
"showInstanceSpecificPanel": false,
|
||||||
"collapseMessageWithSubject": false,
|
"collapseMessageWithSubject": false,
|
||||||
"scopeCopy": true,
|
"scopeCopy": true,
|
||||||
|
|
|
@ -1,17 +1,8 @@
|
||||||
.with-load-more-footer {
|
|
||||||
padding: 10px;
|
|
||||||
text-align: center;
|
|
||||||
border-top: 1px solid;
|
|
||||||
border-top-color: #222;
|
|
||||||
border-top-color: var(--border, #222);
|
|
||||||
}
|
|
||||||
.with-load-more-footer .error {
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
.tab-switcher .contents .hidden {
|
.tab-switcher .contents .hidden {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.tab-switcher .tabs {
|
.tab-switcher .tabs {
|
||||||
|
display: -ms-flexbox;
|
||||||
display: flex;
|
display: flex;
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
@ -23,7 +14,8 @@ .tab-switcher .tabs {
|
||||||
.tab-switcher .tabs::after, .tab-switcher .tabs::before {
|
.tab-switcher .tabs::after, .tab-switcher .tabs::before {
|
||||||
display: block;
|
display: block;
|
||||||
content: "";
|
content: "";
|
||||||
flex: 1 1 auto;
|
-ms-flex: 1 1 auto;
|
||||||
|
flex: 1 1 auto;
|
||||||
border-bottom: 1px solid;
|
border-bottom: 1px solid;
|
||||||
border-bottom-color: #222;
|
border-bottom-color: #222;
|
||||||
border-bottom-color: var(--border, #222);
|
border-bottom-color: var(--border, #222);
|
||||||
|
@ -31,8 +23,10 @@ .tab-switcher .tabs::after, .tab-switcher .tabs::before {
|
||||||
.tab-switcher .tabs .tab-wrapper {
|
.tab-switcher .tabs .tab-wrapper {
|
||||||
height: 28px;
|
height: 28px;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
display: -ms-flexbox;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex: 0 0 auto;
|
-ms-flex: 0 0 auto;
|
||||||
|
flex: 0 0 auto;
|
||||||
}
|
}
|
||||||
.tab-switcher .tabs .tab-wrapper .tab {
|
.tab-switcher .tabs .tab-wrapper .tab {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
@ -55,6 +49,11 @@ .tab-switcher .tabs .tab-wrapper .tab.active {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
z-index: 5;
|
z-index: 5;
|
||||||
}
|
}
|
||||||
|
.tab-switcher .tabs .tab-wrapper .tab img {
|
||||||
|
max-height: 26px;
|
||||||
|
vertical-align: top;
|
||||||
|
margin-top: -5px;
|
||||||
|
}
|
||||||
.tab-switcher .tabs .tab-wrapper:not(.active)::after {
|
.tab-switcher .tabs .tab-wrapper:not(.active)::after {
|
||||||
content: "";
|
content: "";
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@ -66,6 +65,16 @@ .tab-switcher .tabs .tab-wrapper:not(.active)::after {
|
||||||
border-bottom-color: #222;
|
border-bottom-color: #222;
|
||||||
border-bottom-color: var(--border, #222);
|
border-bottom-color: var(--border, #222);
|
||||||
}
|
}
|
||||||
|
.with-load-more-footer {
|
||||||
|
padding: 10px;
|
||||||
|
text-align: center;
|
||||||
|
border-top: 1px solid;
|
||||||
|
border-top-color: #222;
|
||||||
|
border-top-color: var(--border, #222);
|
||||||
|
}
|
||||||
|
.with-load-more-footer .error {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
.with-subscription-loading {
|
.with-subscription-loading {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
@ -74,4 +83,4 @@ .with-subscription-loading .error {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*# sourceMappingURL=app.db80066bde2c96ea6198.css.map*/
|
/*# sourceMappingURL=app.cb3673e4b661fd9526ea.css.map*/
|
1
priv/static/static/css/app.cb3673e4b661fd9526ea.css.map
Normal file
1
priv/static/static/css/app.cb3673e4b661fd9526ea.css.map
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"sources":["webpack:///./src/components/tab_switcher/tab_switcher.scss","webpack:///./src/hocs/with_load_more/with_load_more.scss","webpack:///./src/hocs/with_subscription/with_subscription.scss"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,C;AClEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,C;ACTA;AACA;AACA;AACA;AACA;AACA;AACA,C","file":"static/css/app.cb3673e4b661fd9526ea.css","sourcesContent":[".tab-switcher .contents .hidden {\n display: none;\n}\n.tab-switcher .tabs {\n display: -ms-flexbox;\n display: flex;\n position: relative;\n width: 100%;\n overflow-y: hidden;\n overflow-x: auto;\n padding-top: 5px;\n box-sizing: border-box;\n}\n.tab-switcher .tabs::after, .tab-switcher .tabs::before {\n display: block;\n content: \"\";\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n border-bottom: 1px solid;\n border-bottom-color: #222;\n border-bottom-color: var(--border, #222);\n}\n.tab-switcher .tabs .tab-wrapper {\n height: 28px;\n position: relative;\n display: -ms-flexbox;\n display: flex;\n -ms-flex: 0 0 auto;\n flex: 0 0 auto;\n}\n.tab-switcher .tabs .tab-wrapper .tab {\n width: 100%;\n min-width: 1px;\n position: relative;\n border-bottom-left-radius: 0;\n border-bottom-right-radius: 0;\n padding: 6px 1em;\n padding-bottom: 99px;\n margin-bottom: -93px;\n white-space: nowrap;\n}\n.tab-switcher .tabs .tab-wrapper .tab:not(.active) {\n z-index: 4;\n}\n.tab-switcher .tabs .tab-wrapper .tab:not(.active):hover {\n z-index: 6;\n}\n.tab-switcher .tabs .tab-wrapper .tab.active {\n background: transparent;\n z-index: 5;\n}\n.tab-switcher .tabs .tab-wrapper .tab img {\n max-height: 26px;\n vertical-align: top;\n margin-top: -5px;\n}\n.tab-switcher .tabs .tab-wrapper:not(.active)::after {\n content: \"\";\n position: absolute;\n left: 0;\n right: 0;\n bottom: 0;\n z-index: 7;\n border-bottom: 1px solid;\n border-bottom-color: #222;\n border-bottom-color: var(--border, #222);\n}",".with-load-more-footer {\n padding: 10px;\n text-align: center;\n border-top: 1px solid;\n border-top-color: #222;\n border-top-color: var(--border, #222);\n}\n.with-load-more-footer .error {\n font-size: 14px;\n}",".with-subscription-loading {\n padding: 10px;\n text-align: center;\n}\n.with-subscription-loading .error {\n font-size: 14px;\n}"],"sourceRoot":""}
|
|
@ -1 +0,0 @@
|
||||||
{"version":3,"sources":["webpack:///./src/hocs/with_load_more/with_load_more.scss","webpack:///./src/components/tab_switcher/tab_switcher.scss","webpack:///./src/hocs/with_subscription/with_subscription.scss"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,C;ACTA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,C;ACzDA;AACA;AACA;AACA;AACA;AACA;AACA,C","file":"static/css/app.db80066bde2c96ea6198.css","sourcesContent":[".with-load-more-footer {\n padding: 10px;\n text-align: center;\n border-top: 1px solid;\n border-top-color: #222;\n border-top-color: var(--border, #222);\n}\n.with-load-more-footer .error {\n font-size: 14px;\n}",".tab-switcher .contents .hidden {\n display: none;\n}\n.tab-switcher .tabs {\n display: flex;\n position: relative;\n width: 100%;\n overflow-y: hidden;\n overflow-x: auto;\n padding-top: 5px;\n box-sizing: border-box;\n}\n.tab-switcher .tabs::after, .tab-switcher .tabs::before {\n display: block;\n content: \"\";\n flex: 1 1 auto;\n border-bottom: 1px solid;\n border-bottom-color: #222;\n border-bottom-color: var(--border, #222);\n}\n.tab-switcher .tabs .tab-wrapper {\n height: 28px;\n position: relative;\n display: flex;\n flex: 0 0 auto;\n}\n.tab-switcher .tabs .tab-wrapper .tab {\n width: 100%;\n min-width: 1px;\n position: relative;\n border-bottom-left-radius: 0;\n border-bottom-right-radius: 0;\n padding: 6px 1em;\n padding-bottom: 99px;\n margin-bottom: -93px;\n white-space: nowrap;\n}\n.tab-switcher .tabs .tab-wrapper .tab:not(.active) {\n z-index: 4;\n}\n.tab-switcher .tabs .tab-wrapper .tab:not(.active):hover {\n z-index: 6;\n}\n.tab-switcher .tabs .tab-wrapper .tab.active {\n background: transparent;\n z-index: 5;\n}\n.tab-switcher .tabs .tab-wrapper:not(.active)::after {\n content: \"\";\n position: absolute;\n left: 0;\n right: 0;\n bottom: 0;\n z-index: 7;\n border-bottom: 1px solid;\n border-bottom-color: #222;\n border-bottom-color: var(--border, #222);\n}",".with-subscription-loading {\n padding: 10px;\n text-align: center;\n}\n.with-subscription-loading .error {\n font-size: 14px;\n}"],"sourceRoot":""}
|
|
0
priv/static/static/font/LICENSE.txt
Normal file → Executable file
0
priv/static/static/font/LICENSE.txt
Normal file → Executable file
0
priv/static/static/font/README.txt
Normal file → Executable file
0
priv/static/static/font/README.txt
Normal file → Executable file
26
priv/static/static/font/config.json
Normal file → Executable file
26
priv/static/static/font/config.json
Normal file → Executable file
|
@ -150,12 +150,6 @@
|
||||||
"code": 61669,
|
"code": 61669,
|
||||||
"src": "fontawesome"
|
"src": "fontawesome"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"uid": "cd21cbfb28ad4d903cede582157f65dc",
|
|
||||||
"css": "bell",
|
|
||||||
"code": 59408,
|
|
||||||
"src": "fontawesome"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"uid": "ccc2329632396dc096bb638d4b46fb98",
|
"uid": "ccc2329632396dc096bb638d4b46fb98",
|
||||||
"css": "mail-alt",
|
"css": "mail-alt",
|
||||||
|
@ -277,6 +271,26 @@
|
||||||
"search": [
|
"search": [
|
||||||
"ellipsis"
|
"ellipsis"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uid": "0bef873af785ead27781fdf98b3ae740",
|
||||||
|
"css": "bell-ringing-o",
|
||||||
|
"code": 59408,
|
||||||
|
"src": "custom_icons",
|
||||||
|
"selected": true,
|
||||||
|
"svg": {
|
||||||
|
"path": "M497.8 0C468.3 0 444.4 23.9 444.4 53.3 444.4 61.1 446.1 68.3 448.9 75 301.7 96.7 213.3 213.3 213.3 320 213.3 588.3 117.8 712.8 35.6 782.2 35.6 821.1 67.8 853.3 106.7 853.3H355.6C355.6 931.7 419.4 995.6 497.8 995.6S640 931.7 640 853.3H888.9C927.8 853.3 960 821.1 960 782.2 877.8 712.8 782.2 588.3 782.2 320 782.2 213.3 693.9 96.7 546.7 75 549.4 68.3 551.1 61.1 551.1 53.3 551.1 23.9 527.2 0 497.8 0ZM189.4 44.8C108.4 118.6 70.5 215.1 71.1 320.2L142.2 319.8C141.7 231.2 170.4 158.3 237.3 97.4L189.4 44.8ZM806.2 44.8L758.3 97.4C825.2 158.3 853.9 231.2 853.3 319.8L924.4 320.2C925.1 215.1 887.2 118.6 806.2 44.8ZM408.9 844.4C413.9 844.4 417.8 848.3 417.8 853.3 417.8 897.2 453.9 933.3 497.8 933.3 502.8 933.3 506.7 937.2 506.7 942.2S502.8 951.1 497.8 951.1C443.9 951.1 400 907.2 400 853.3 400 848.3 403.9 844.4 408.9 844.4Z",
|
||||||
|
"width": 1000
|
||||||
|
},
|
||||||
|
"search": [
|
||||||
|
"bell-ringing-o"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uid": "0b2b66e526028a6972d51a6f10281b4b",
|
||||||
|
"css": "zoom-in",
|
||||||
|
"code": 59420,
|
||||||
|
"src": "fontawesome"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -15,7 +15,7 @@ .icon-video:before { content: '\e80c'; } /* '' */
|
||||||
.icon-right-open:before { content: '\e80d'; } /* '' */
|
.icon-right-open:before { content: '\e80d'; } /* '' */
|
||||||
.icon-left-open:before { content: '\e80e'; } /* '' */
|
.icon-left-open:before { content: '\e80e'; } /* '' */
|
||||||
.icon-up-open:before { content: '\e80f'; } /* '' */
|
.icon-up-open:before { content: '\e80f'; } /* '' */
|
||||||
.icon-bell:before { content: '\e810'; } /* '' */
|
.icon-bell-ringing-o:before { content: '\e810'; } /* '' */
|
||||||
.icon-lock:before { content: '\e811'; } /* '' */
|
.icon-lock:before { content: '\e811'; } /* '' */
|
||||||
.icon-globe:before { content: '\e812'; } /* '' */
|
.icon-globe:before { content: '\e812'; } /* '' */
|
||||||
.icon-brush:before { content: '\e813'; } /* '' */
|
.icon-brush:before { content: '\e813'; } /* '' */
|
||||||
|
@ -27,6 +27,7 @@ .icon-pencil:before { content: '\e818'; } /* '' */
|
||||||
.icon-pin:before { content: '\e819'; } /* '' */
|
.icon-pin:before { content: '\e819'; } /* '' */
|
||||||
.icon-wrench:before { content: '\e81a'; } /* '' */
|
.icon-wrench:before { content: '\e81a'; } /* '' */
|
||||||
.icon-chart-bar:before { content: '\e81b'; } /* '' */
|
.icon-chart-bar:before { content: '\e81b'; } /* '' */
|
||||||
|
.icon-zoom-in:before { content: '\e81c'; } /* '' */
|
||||||
.icon-spin3:before { content: '\e832'; } /* '' */
|
.icon-spin3:before { content: '\e832'; } /* '' */
|
||||||
.icon-spin4:before { content: '\e834'; } /* '' */
|
.icon-spin4:before { content: '\e834'; } /* '' */
|
||||||
.icon-link-ext:before { content: '\f08e'; } /* '' */
|
.icon-link-ext:before { content: '\f08e'; } /* '' */
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -15,7 +15,7 @@ .icon-video { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML
|
||||||
.icon-right-open { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-right-open { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-left-open { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-left-open { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-up-open { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-up-open { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-bell { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-bell-ringing-o { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-lock { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-lock { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-globe { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-globe { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-brush { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-brush { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
|
@ -27,6 +27,7 @@ .icon-pencil { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTM
|
||||||
.icon-pin { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-pin { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-wrench { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-wrench { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-chart-bar { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-chart-bar { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
|
.icon-zoom-in { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-spin3 { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-spin3 { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-spin4 { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-spin4 { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-link-ext { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-link-ext { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
|
|
3
priv/static/static/font/css/fontello-ie7.css
vendored
3
priv/static/static/font/css/fontello-ie7.css
vendored
|
@ -26,7 +26,7 @@ .icon-video { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML
|
||||||
.icon-right-open { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-right-open { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-left-open { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-left-open { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-up-open { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-up-open { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-bell { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-bell-ringing-o { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-lock { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-lock { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-globe { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-globe { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-brush { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-brush { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
|
@ -38,6 +38,7 @@ .icon-pencil { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTM
|
||||||
.icon-pin { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-pin { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-wrench { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-wrench { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-chart-bar { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-chart-bar { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
|
.icon-zoom-in { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-spin3 { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-spin3 { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-spin4 { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-spin4 { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
.icon-link-ext { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
.icon-link-ext { *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = ' '); }
|
||||||
|
|
17
priv/static/static/font/css/fontello.css
vendored
17
priv/static/static/font/css/fontello.css
vendored
|
@ -1,11 +1,11 @@
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'fontello';
|
font-family: 'fontello';
|
||||||
src: url('../font/fontello.eot?3304725');
|
src: url('../font/fontello.eot?4060331');
|
||||||
src: url('../font/fontello.eot?3304725#iefix') format('embedded-opentype'),
|
src: url('../font/fontello.eot?4060331#iefix') format('embedded-opentype'),
|
||||||
url('../font/fontello.woff2?3304725') format('woff2'),
|
url('../font/fontello.woff2?4060331') format('woff2'),
|
||||||
url('../font/fontello.woff?3304725') format('woff'),
|
url('../font/fontello.woff?4060331') format('woff'),
|
||||||
url('../font/fontello.ttf?3304725') format('truetype'),
|
url('../font/fontello.ttf?4060331') format('truetype'),
|
||||||
url('../font/fontello.svg?3304725#fontello') format('svg');
|
url('../font/fontello.svg?4060331#fontello') format('svg');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ @font-face {
|
||||||
@media screen and (-webkit-min-device-pixel-ratio:0) {
|
@media screen and (-webkit-min-device-pixel-ratio:0) {
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'fontello';
|
font-family: 'fontello';
|
||||||
src: url('../font/fontello.svg?3304725#fontello') format('svg');
|
src: url('../font/fontello.svg?4060331#fontello') format('svg');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -71,7 +71,7 @@ .icon-video:before { content: '\e80c'; } /* '' */
|
||||||
.icon-right-open:before { content: '\e80d'; } /* '' */
|
.icon-right-open:before { content: '\e80d'; } /* '' */
|
||||||
.icon-left-open:before { content: '\e80e'; } /* '' */
|
.icon-left-open:before { content: '\e80e'; } /* '' */
|
||||||
.icon-up-open:before { content: '\e80f'; } /* '' */
|
.icon-up-open:before { content: '\e80f'; } /* '' */
|
||||||
.icon-bell:before { content: '\e810'; } /* '' */
|
.icon-bell-ringing-o:before { content: '\e810'; } /* '' */
|
||||||
.icon-lock:before { content: '\e811'; } /* '' */
|
.icon-lock:before { content: '\e811'; } /* '' */
|
||||||
.icon-globe:before { content: '\e812'; } /* '' */
|
.icon-globe:before { content: '\e812'; } /* '' */
|
||||||
.icon-brush:before { content: '\e813'; } /* '' */
|
.icon-brush:before { content: '\e813'; } /* '' */
|
||||||
|
@ -83,6 +83,7 @@ .icon-pencil:before { content: '\e818'; } /* '' */
|
||||||
.icon-pin:before { content: '\e819'; } /* '' */
|
.icon-pin:before { content: '\e819'; } /* '' */
|
||||||
.icon-wrench:before { content: '\e81a'; } /* '' */
|
.icon-wrench:before { content: '\e81a'; } /* '' */
|
||||||
.icon-chart-bar:before { content: '\e81b'; } /* '' */
|
.icon-chart-bar:before { content: '\e81b'; } /* '' */
|
||||||
|
.icon-zoom-in:before { content: '\e81c'; } /* '' */
|
||||||
.icon-spin3:before { content: '\e832'; } /* '' */
|
.icon-spin3:before { content: '\e832'; } /* '' */
|
||||||
.icon-spin4:before { content: '\e834'; } /* '' */
|
.icon-spin4:before { content: '\e834'; } /* '' */
|
||||||
.icon-link-ext:before { content: '\f08e'; } /* '' */
|
.icon-link-ext:before { content: '\f08e'; } /* '' */
|
||||||
|
|
21
priv/static/static/font/demo.html
Normal file → Executable file
21
priv/static/static/font/demo.html
Normal file → Executable file
|
@ -229,11 +229,11 @@ body {
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'fontello';
|
font-family: 'fontello';
|
||||||
src: url('./font/fontello.eot?14310629');
|
src: url('./font/fontello.eot?25455785');
|
||||||
src: url('./font/fontello.eot?14310629#iefix') format('embedded-opentype'),
|
src: url('./font/fontello.eot?25455785#iefix') format('embedded-opentype'),
|
||||||
url('./font/fontello.woff?14310629') format('woff'),
|
url('./font/fontello.woff?25455785') format('woff'),
|
||||||
url('./font/fontello.ttf?14310629') format('truetype'),
|
url('./font/fontello.ttf?25455785') format('truetype'),
|
||||||
url('./font/fontello.svg?14310629#fontello') format('svg');
|
url('./font/fontello.svg?25455785#fontello') format('svg');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ body {
|
||||||
<div class="the-icons span3" title="Code: 0xe80f"><i class="demo-icon icon-up-open"></i> <span class="i-name">icon-up-open</span><span class="i-code">0xe80f</span></div>
|
<div class="the-icons span3" title="Code: 0xe80f"><i class="demo-icon icon-up-open"></i> <span class="i-name">icon-up-open</span><span class="i-code">0xe80f</span></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="the-icons span3" title="Code: 0xe810"><i class="demo-icon icon-bell"></i> <span class="i-name">icon-bell</span><span class="i-code">0xe810</span></div>
|
<div class="the-icons span3" title="Code: 0xe810"><i class="demo-icon icon-bell-ringing-o"></i> <span class="i-name">icon-bell-ringing-o</span><span class="i-code">0xe810</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xe811"><i class="demo-icon icon-lock"></i> <span class="i-name">icon-lock</span><span class="i-code">0xe811</span></div>
|
<div class="the-icons span3" title="Code: 0xe811"><i class="demo-icon icon-lock"></i> <span class="i-name">icon-lock</span><span class="i-code">0xe811</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xe812"><i class="demo-icon icon-globe"></i> <span class="i-name">icon-globe</span><span class="i-code">0xe812</span></div>
|
<div class="the-icons span3" title="Code: 0xe812"><i class="demo-icon icon-globe"></i> <span class="i-name">icon-globe</span><span class="i-code">0xe812</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xe813"><i class="demo-icon icon-brush"></i> <span class="i-name">icon-brush</span><span class="i-code">0xe813</span></div>
|
<div class="the-icons span3" title="Code: 0xe813"><i class="demo-icon icon-brush"></i> <span class="i-name">icon-brush</span><span class="i-code">0xe813</span></div>
|
||||||
|
@ -340,27 +340,30 @@ body {
|
||||||
<div class="the-icons span3" title="Code: 0xe81b"><i class="demo-icon icon-chart-bar"></i> <span class="i-name">icon-chart-bar</span><span class="i-code">0xe81b</span></div>
|
<div class="the-icons span3" title="Code: 0xe81b"><i class="demo-icon icon-chart-bar"></i> <span class="i-name">icon-chart-bar</span><span class="i-code">0xe81b</span></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<div class="the-icons span3" title="Code: 0xe81c"><i class="demo-icon icon-zoom-in"></i> <span class="i-name">icon-zoom-in</span><span class="i-code">0xe81c</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xe832"><i class="demo-icon icon-spin3 animate-spin"></i> <span class="i-name">icon-spin3</span><span class="i-code">0xe832</span></div>
|
<div class="the-icons span3" title="Code: 0xe832"><i class="demo-icon icon-spin3 animate-spin"></i> <span class="i-name">icon-spin3</span><span class="i-code">0xe832</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xe834"><i class="demo-icon icon-spin4 animate-spin"></i> <span class="i-name">icon-spin4</span><span class="i-code">0xe834</span></div>
|
<div class="the-icons span3" title="Code: 0xe834"><i class="demo-icon icon-spin4 animate-spin"></i> <span class="i-name">icon-spin4</span><span class="i-code">0xe834</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf08e"><i class="demo-icon icon-link-ext"></i> <span class="i-name">icon-link-ext</span><span class="i-code">0xf08e</span></div>
|
<div class="the-icons span3" title="Code: 0xf08e"><i class="demo-icon icon-link-ext"></i> <span class="i-name">icon-link-ext</span><span class="i-code">0xf08e</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf08f"><i class="demo-icon icon-link-ext-alt"></i> <span class="i-name">icon-link-ext-alt</span><span class="i-code">0xf08f</span></div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<div class="the-icons span3" title="Code: 0xf08f"><i class="demo-icon icon-link-ext-alt"></i> <span class="i-name">icon-link-ext-alt</span><span class="i-code">0xf08f</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf0c9"><i class="demo-icon icon-menu"></i> <span class="i-name">icon-menu</span><span class="i-code">0xf0c9</span></div>
|
<div class="the-icons span3" title="Code: 0xf0c9"><i class="demo-icon icon-menu"></i> <span class="i-name">icon-menu</span><span class="i-code">0xf0c9</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf0e0"><i class="demo-icon icon-mail-alt"></i> <span class="i-name">icon-mail-alt</span><span class="i-code">0xf0e0</span></div>
|
<div class="the-icons span3" title="Code: 0xf0e0"><i class="demo-icon icon-mail-alt"></i> <span class="i-name">icon-mail-alt</span><span class="i-code">0xf0e0</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf0e5"><i class="demo-icon icon-comment-empty"></i> <span class="i-name">icon-comment-empty</span><span class="i-code">0xf0e5</span></div>
|
<div class="the-icons span3" title="Code: 0xf0e5"><i class="demo-icon icon-comment-empty"></i> <span class="i-name">icon-comment-empty</span><span class="i-code">0xf0e5</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf0f3"><i class="demo-icon icon-bell-alt"></i> <span class="i-name">icon-bell-alt</span><span class="i-code">0xf0f3</span></div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<div class="the-icons span3" title="Code: 0xf0f3"><i class="demo-icon icon-bell-alt"></i> <span class="i-name">icon-bell-alt</span><span class="i-code">0xf0f3</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf0fe"><i class="demo-icon icon-plus-squared"></i> <span class="i-name">icon-plus-squared</span><span class="i-code">0xf0fe</span></div>
|
<div class="the-icons span3" title="Code: 0xf0fe"><i class="demo-icon icon-plus-squared"></i> <span class="i-name">icon-plus-squared</span><span class="i-code">0xf0fe</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf112"><i class="demo-icon icon-reply"></i> <span class="i-name">icon-reply</span><span class="i-code">0xf112</span></div>
|
<div class="the-icons span3" title="Code: 0xf112"><i class="demo-icon icon-reply"></i> <span class="i-name">icon-reply</span><span class="i-code">0xf112</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf13e"><i class="demo-icon icon-lock-open-alt"></i> <span class="i-name">icon-lock-open-alt</span><span class="i-code">0xf13e</span></div>
|
<div class="the-icons span3" title="Code: 0xf13e"><i class="demo-icon icon-lock-open-alt"></i> <span class="i-name">icon-lock-open-alt</span><span class="i-code">0xf13e</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf141"><i class="demo-icon icon-ellipsis"></i> <span class="i-name">icon-ellipsis</span><span class="i-code">0xf141</span></div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<div class="the-icons span3" title="Code: 0xf141"><i class="demo-icon icon-ellipsis"></i> <span class="i-name">icon-ellipsis</span><span class="i-code">0xf141</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf144"><i class="demo-icon icon-play-circled"></i> <span class="i-name">icon-play-circled</span><span class="i-code">0xf144</span></div>
|
<div class="the-icons span3" title="Code: 0xf144"><i class="demo-icon icon-play-circled"></i> <span class="i-name">icon-play-circled</span><span class="i-code">0xf144</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf164"><i class="demo-icon icon-thumbs-up-alt"></i> <span class="i-name">icon-thumbs-up-alt</span><span class="i-code">0xf164</span></div>
|
<div class="the-icons span3" title="Code: 0xf164"><i class="demo-icon icon-thumbs-up-alt"></i> <span class="i-name">icon-thumbs-up-alt</span><span class="i-code">0xf164</span></div>
|
||||||
<div class="the-icons span3" title="Code: 0xf1e5"><i class="demo-icon icon-binoculars"></i> <span class="i-name">icon-binoculars</span><span class="i-code">0xf1e5</span></div>
|
<div class="the-icons span3" title="Code: 0xf1e5"><i class="demo-icon icon-binoculars"></i> <span class="i-name">icon-binoculars</span><span class="i-code">0xf1e5</span></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
<div class="the-icons span3" title="Code: 0xf234"><i class="demo-icon icon-user-plus"></i> <span class="i-name">icon-user-plus</span><span class="i-code">0xf234</span></div>
|
<div class="the-icons span3" title="Code: 0xf234"><i class="demo-icon icon-user-plus"></i> <span class="i-name">icon-user-plus</span><span class="i-code">0xf234</span></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Binary file not shown.
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
<glyph glyph-name="up-open" unicode="" d="M939 114l-92-92q-11-10-26-10t-25 10l-296 297-296-297q-11-10-25-10t-25 10l-93 92q-11 11-11 26t11 25l414 414q11 10 25 10t25-10l414-414q11-11 11-25t-11-26z" horiz-adv-x="1000" />
|
<glyph glyph-name="up-open" unicode="" d="M939 114l-92-92q-11-10-26-10t-25 10l-296 297-296-297q-11-10-25-10t-25 10l-93 92q-11 11-11 26t11 25l414 414q11 10 25 10t25-10l414-414q11-11 11-25t-11-26z" horiz-adv-x="1000" />
|
||||||
|
|
||||||
<glyph glyph-name="bell" unicode="" d="M509-89q0 8-9 8-33 0-57 24t-23 57q0 9-9 9t-9-9q0-41 29-70t69-28q9 0 9 9z m-372 160h726q-149 168-149 465 0 28-13 58t-39 58-67 45-95 17-95-17-67-45-39-58-13-58q0-297-149-465z m827 0q0-29-21-50t-50-21h-250q0-59-42-101t-101-42-101 42-42 101h-250q-29 0-50 21t-21 50q28 24 51 49t47 67 42 89 27 115 11 145q0 84 66 157t171 89q-5 10-5 21 0 23 16 38t38 16 38-16 16-38q0-11-5-21 106-16 171-89t66-157q0-78 11-145t28-115 41-89 48-67 50-49z" horiz-adv-x="1000" />
|
<glyph glyph-name="bell-ringing-o" unicode="" d="M498 857c-30 0-54-24-54-53 0-8 2-15 5-22-147-22-236-138-236-245 0-268-95-393-177-462 0-39 32-71 71-71h249c0-79 63-143 142-143s142 64 142 143h249c39 0 71 32 71 71-82 69-178 194-178 462 0 107-88 223-235 245 2 7 4 14 4 22 0 29-24 53-53 53z m-309-45c-81-74-118-170-118-275l71 0c0 89 28 162 95 223l-48 52z m617 0l-48-52c67-61 96-134 95-223l71 0c1 105-37 201-118 275z m-397-799c5 0 9-4 9-9 0-44 36-80 80-80 5 0 9-4 9-9s-4-9-9-9c-54 0-98 44-98 98 0 5 4 9 9 9z" horiz-adv-x="1000" />
|
||||||
|
|
||||||
<glyph glyph-name="lock" unicode="" d="M179 428h285v108q0 59-42 101t-101 41-101-41-41-101v-108z m464-53v-322q0-22-16-37t-38-16h-535q-23 0-38 16t-16 37v322q0 22 16 38t38 15h17v108q0 102 74 176t176 74 177-74 73-176v-108h18q23 0 38-15t16-38z" horiz-adv-x="642.9" />
|
<glyph glyph-name="lock" unicode="" d="M179 428h285v108q0 59-42 101t-101 41-101-41-41-101v-108z m464-53v-322q0-22-16-37t-38-16h-535q-23 0-38 16t-16 37v322q0 22 16 38t38 15h17v108q0 102 74 176t176 74 177-74 73-176v-108h18q23 0 38-15t16-38z" horiz-adv-x="642.9" />
|
||||||
|
|
||||||
|
@ -62,6 +62,8 @@
|
||||||
|
|
||||||
<glyph glyph-name="chart-bar" unicode="" d="M357 357v-286h-143v286h143z m214 286v-572h-142v572h142z m572-643v-72h-1143v858h71v-786h1072z m-357 500v-429h-143v429h143z m214 214v-643h-143v643h143z" horiz-adv-x="1142.9" />
|
<glyph glyph-name="chart-bar" unicode="" d="M357 357v-286h-143v286h143z m214 286v-572h-142v572h142z m572-643v-72h-1143v858h71v-786h1072z m-357 500v-429h-143v429h143z m214 214v-643h-143v643h143z" horiz-adv-x="1142.9" />
|
||||||
|
|
||||||
|
<glyph glyph-name="zoom-in" unicode="" d="M571 411v-36q0-7-5-13t-12-5h-125v-125q0-7-6-13t-12-5h-36q-7 0-13 5t-5 13v125h-125q-7 0-12 5t-6 13v36q0 7 6 12t12 5h125v125q0 8 5 13t13 5h36q7 0 12-5t6-13v-125h125q7 0 12-5t5-12z m72-18q0 103-73 176t-177 74-177-74-73-176 73-177 177-73 177 73 73 177z m286-465q0-29-21-50t-51-21q-30 0-50 21l-191 191q-100-69-223-69-80 0-153 31t-125 84-84 125-31 153 31 152 84 126 125 84 153 31 153-31 125-84 84-126 31-152q0-123-69-223l191-191q21-21 21-51z" horiz-adv-x="928.6" />
|
||||||
|
|
||||||
<glyph glyph-name="spin3" unicode="" d="M494 857c-266 0-483-210-494-472-1-19 13-20 13-20l84 0c16 0 19 10 19 18 10 199 176 358 378 358 107 0 205-45 273-118l-58-57c-11-12-11-27 5-31l247-50c21-5 46 11 37 44l-58 227c-2 9-16 22-29 13l-65-60c-89 91-214 148-352 148z m409-508c-16 0-19-10-19-18-10-199-176-358-377-358-108 0-205 45-274 118l59 57c10 12 10 27-5 31l-248 50c-21 5-46-11-37-44l58-227c2-9 16-22 30-13l64 60c89-91 214-148 353-148 265 0 482 210 493 473 1 18-13 19-13 19l-84 0z" horiz-adv-x="1000" />
|
<glyph glyph-name="spin3" unicode="" d="M494 857c-266 0-483-210-494-472-1-19 13-20 13-20l84 0c16 0 19 10 19 18 10 199 176 358 378 358 107 0 205-45 273-118l-58-57c-11-12-11-27 5-31l247-50c21-5 46 11 37 44l-58 227c-2 9-16 22-29 13l-65-60c-89 91-214 148-352 148z m409-508c-16 0-19-10-19-18-10-199-176-358-377-358-108 0-205 45-274 118l59 57c10 12 10 27-5 31l-248 50c-21 5-46-11-37-44l58-227c2-9 16-22 30-13l64 60c89-91 214-148 353-148 265 0 482 210 493 473 1 18-13 19-13 19l-84 0z" horiz-adv-x="1000" />
|
||||||
|
|
||||||
<glyph glyph-name="spin4" unicode="" d="M498 857c-114 0-228-39-320-116l0 0c173 140 428 130 588-31 134-134 164-332 89-495-10-29-5-50 12-68 21-20 61-23 84 0 3 3 12 15 15 24 71 180 33 393-112 539-99 98-228 147-356 147z m-409-274c-14 0-29-5-39-16-3-3-13-15-15-24-71-180-34-393 112-539 185-185 479-195 676-31l0 0c-173-140-428-130-589 31-134 134-163 333-89 495 11 29 6 50-12 68-11 11-27 17-44 16z" horiz-adv-x="1001" />
|
<glyph glyph-name="spin4" unicode="" d="M498 857c-114 0-228-39-320-116l0 0c173 140 428 130 588-31 134-134 164-332 89-495-10-29-5-50 12-68 21-20 61-23 84 0 3 3 12 15 15 24 71 180 33 393-112 539-99 98-228 147-356 147z m-409-274c-14 0-29-5-39-16-3-3-13-15-15-24-71-180-34-393 112-539 185-185 479-195 676-31l0 0c-173-140-428-130-589 31-134 134-163 333-89 495 11 29 6 50-12 68-11 11-27 17-44 16z" horiz-adv-x="1001" />
|
||||||
|
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
priv/static/static/js/app.8098503330c7dd14a415.js
Normal file
BIN
priv/static/static/js/app.8098503330c7dd14a415.js
Normal file
Binary file not shown.
BIN
priv/static/static/js/app.8098503330c7dd14a415.js.map
Normal file
BIN
priv/static/static/js/app.8098503330c7dd14a415.js.map
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
priv/static/static/js/vendors~app.4cedffe4993b111c7421.js
Normal file
BIN
priv/static/static/js/vendors~app.4cedffe4993b111c7421.js
Normal file
Binary file not shown.
BIN
priv/static/static/js/vendors~app.4cedffe4993b111c7421.js.map
Normal file
BIN
priv/static/static/js/vendors~app.4cedffe4993b111c7421.js.map
Normal file
Binary file not shown.
Binary file not shown.
|
@ -173,4 +173,16 @@ test "add an activity with an expiration" do
|
||||||
|> where([a], a.activity_id == ^activity.id)
|
|> where([a], a.activity_id == ^activity.id)
|
||||||
|> Repo.one!()
|
|> Repo.one!()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "all_by_ids_with_object/1" do
|
||||||
|
%{id: id1} = insert(:note_activity)
|
||||||
|
%{id: id2} = insert(:note_activity)
|
||||||
|
|
||||||
|
activities =
|
||||||
|
[id1, id2]
|
||||||
|
|> Activity.all_by_ids_with_object()
|
||||||
|
|> Enum.sort(&(&1.id < &2.id))
|
||||||
|
|
||||||
|
assert [%{id: ^id1, object: %Object{}}, %{id: ^id2, object: %Object{}}] = activities
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
56
test/fixtures/osada-follow-activity.json
vendored
Normal file
56
test/fixtures/osada-follow-activity.json
vendored
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
{
|
||||||
|
"@context":[
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
"https://apfed.club/apschema/v1.4"
|
||||||
|
],
|
||||||
|
"id":"https://apfed.club/follow/9",
|
||||||
|
"type":"Follow",
|
||||||
|
"actor":{
|
||||||
|
"type":"Person",
|
||||||
|
"id":"https://apfed.club/channel/indio",
|
||||||
|
"preferredUsername":"indio",
|
||||||
|
"name":"Indio",
|
||||||
|
"updated":"2019-08-20T23:52:34Z",
|
||||||
|
"icon":{
|
||||||
|
"type":"Image",
|
||||||
|
"mediaType":"image/jpeg",
|
||||||
|
"updated":"2019-08-20T23:53:37Z",
|
||||||
|
"url":"https://apfed.club/photo/profile/l/2",
|
||||||
|
"height":300,
|
||||||
|
"width":300
|
||||||
|
},
|
||||||
|
"url":"https://apfed.club/channel/indio",
|
||||||
|
"inbox":"https://apfed.club/inbox/indio",
|
||||||
|
"outbox":"https://apfed.club/outbox/indio",
|
||||||
|
"followers":"https://apfed.club/followers/indio",
|
||||||
|
"following":"https://apfed.club/following/indio",
|
||||||
|
"endpoints":{
|
||||||
|
"sharedInbox":"https://apfed.club/inbox"
|
||||||
|
},
|
||||||
|
"publicKey":{
|
||||||
|
"id":"https://apfed.club/channel/indio",
|
||||||
|
"owner":"https://apfed.club/channel/indio",
|
||||||
|
"publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA77TIR1VuSYFnmDRFGHHb\n4vaGdx9ranzRX4bfOKAqa++Ch5L4EqJpPy08RuM+NrYCYiYl4QQFDSSDXAEgb5g9\nC1TgWTfI7q/E0UBX2Vr0mU6X4i1ztv0tuQvegRjcSJ7l1AvoBs8Ip4MEJ3OPEQhB\ngJqAACB3Gnps4zi2I0yavkxUfGVKr6zKT3BxWh5hTpKC7Do+ChIrVZC2EwxND9K6
|
||||||
|
\nsAnQHThcb5EQuvuzUQZKeS7IEOsd0JpZDmJjbfMGrAWE81pLIfEeeA2joCJiBBTO\nglDsW+juvZ+lWqJpMr2hMWpvfrFjJeUawNJCIzsLdVIZR+aKj5yy6yqoS8hkN9Ha\n1MljZpsXl+EmwcwAIqim1YeLwERCEAQ/JWbSt8pQTQbzZ6ibwQ4mchCxacrRbIVR
|
||||||
|
\nnL59fWMBassJcbY0VwrTugm2SBsYbDjESd55UZV03Rwr8qseGTyi+hH8O7w2SIaY\nzjN6AdZiPmsh00YflzlCk8MSLOHMol1vqIUzXxU8CdXn9+KsuQdZGrTz0YKN/db4\naVwUGJatz2Tsvf7R1tJBjJfeQWOWbbn3pycLVH86LjZ83qngp9ZVnAveUnUqz0yS
|
||||||
|
\nhe+buZ6UMsfGzbIYon2bKNlz6gYTH0YPcr+cLe+29drtt0GZiXha1agbpo4RB8zE
|
||||||
|
\naNL2fucF5YT0yNpbd/5WoV0CAwEAAQ==\n-----END PUBLIC KEY-----\n"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"object":"https://pleroma.site/users/kaniini",
|
||||||
|
"to":[
|
||||||
|
"https://pleroma.site/users/kaniini"
|
||||||
|
],
|
||||||
|
"signature":{
|
||||||
|
"@context":[
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1"
|
||||||
|
],
|
||||||
|
"type":"RsaSignature2017",
|
||||||
|
"nonce":"52c035e0a9e81dce8b486159204e97c22637e91f75cdfad5378de91de68e9117",
|
||||||
|
"creator":"https://apfed.club/channel/indio/public_key_pem",
|
||||||
|
"created":"2019-08-22T03:38:02Z",
|
||||||
|
"signatureValue":"oVliRCIqNIh6yUp851dYrF0y21aHp3Rz6VkIpW1pFMWfXuzExyWSfcELpyLseeRmsw5bUu9zJkH44B4G2LiJQKA9UoEQDjrDMZBmbeUpiQqq3DVUzkrBOI8bHZ7xyJ/CjSZcNHHh0MHhSKxswyxWMGi4zIqzkAZG3vRRgoPVHdjPm00sR3B8jBLw1cjoffv+KKeM/zEUpe13gqX9qHAWHHqZepxgSWmq+EKOkRvHUPBXiEJZfXzc5uW+vZ09F3WBYmaRoy8Y0e1P29fnRLqSy7EEINdrHaGclRqoUZyiawpkgy3lWWlynesV/HiLBR7EXT79eKstxf4wfTDaPKBCfTCsOWuMWHr7Genu37ew2/t7eiBGqCwwW12ylhml/OLHgNK3LOhmRABhtfpaFZSxfDVnlXfaLpY1xekVOj2oC0FpBtnoxVKLpIcyLw6dkfSil5ANd+hl59W/bpPA8KT90ii1fSNCo3+FcwQVx0YsPznJNA60XfFuVsme7zNcOst6393e1WriZxBanFpfB63zVQc9u1fjyfktx/yiUNxIlre+sz9OCc0AACn94iRhBYh4bbzdleUOTnM7lnD4Dj2FP+xeDIP8CA8wXUeq5+9kopSp2kAmlUEyFUdg4no7naIeu1SZnopfUg56PsVCp9JHiUK1SYAyWbdC+FbUECu5CvI="
|
||||||
|
}
|
||||||
|
}
|
1
test/fixtures/tesla_mock/misskey_poll_no_end_date.json
vendored
Normal file
1
test/fixtures/tesla_mock/misskey_poll_no_end_date.json
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"Hashtag":"as:Hashtag"}],"id":"https://skippers-bin.com/notes/7x9tmrp97i","type":"Question","attributedTo":"https://skippers-bin.com/users/7v1w1r8ce6","summary":null,"content":"<p><a href=\"https://marchgenso.me/users/march\" class=\"mention\">@march@marchgenso.me</a><span> How are your notifications now?<br></span><a href=\"https://skippers-bin.com/notes/7x9tmrp97i\"><span>リモートで結果を表示</span></a></p>","_misskey_content":"@march@marchgenso.me How are your notifications now?\n[リモートで結果を表示](https://skippers-bin.com/notes/7x9tmrp97i)","published":"2019-09-05T05:35:32.541Z","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://skippers-bin.com/users/7v1w1r8ce6/followers","https://marchgenso.me/users/march"],"inReplyTo":null,"attachment":[],"sensitive":false,"tag":[{"type":"Mention","href":"https://marchgenso.me/users/march","name":"@march@marchgenso.me"}],"_misskey_fallback_content":"<p><a href=\"https://marchgenso.me/users/march\" class=\"mention\">@march@marchgenso.me</a><span> How are your notifications now?<br></span><a href=\"https://skippers-bin.com/notes/7x9tmrp97i\"><span>リモートで結果を表示</span></a><span><br>----------------------------------------<br>0: Working<br>1: Broken af<br>----------------------------------------<br>番号を返信して投票</span></p>","endTime":null,"oneOf":[{"type":"Note","name":"Working","replies":{"type":"Collection","totalItems":0}},{"type":"Note","name":"Broken af","replies":{"type":"Collection","totalItems":1}}]}
|
1
test/fixtures/tesla_mock/osada-user-indio.json
vendored
Normal file
1
test/fixtures/tesla_mock/osada-user-indio.json
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],"type":"Person","id":"https://apfed.club/channel/indio","preferredUsername":"indio","name":"Indio","updated":"2019-08-20T23:52:34Z","icon":{"type":"Image","mediaType":"image/jpeg","updated":"2019-08-20T23:53:37Z","url":"https://apfed.club/photo/profile/l/2","height":300,"width":300},"url":"https://apfed.club/channel/indio","inbox":"https://apfed.club/inbox/indio","outbox":"https://apfed.club/outbox/indio","followers":"https://apfed.club/followers/indio","following":"https://apfed.club/following/indio","endpoints":{"sharedInbox":"https://apfed.club/inbox"},"publicKey":{"id":"https://apfed.club/channel/indio","owner":"https://apfed.club/channel/indio","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA77TIR1VuSYFnmDRFGHHb\n4vaGdx9ranzRX4bfOKAqa++Ch5L4EqJpPy08RuM+NrYCYiYl4QQFDSSDXAEgb5g9\nC1TgWTfI7q/E0UBX2Vr0mU6X4i1ztv0tuQvegRjcSJ7l1AvoBs8Ip4MEJ3OPEQhB\ngJqAACB3Gnps4zi2I0yavkxUfGVKr6zKT3BxWh5hTpKC7Do+ChIrVZC2EwxND9K6\nsAnQHThcb5EQuvuzUQZKeS7IEOsd0JpZDmJjbfMGrAWE81pLIfEeeA2joCJiBBTO\nglDsW+juvZ+lWqJpMr2hMWpvfrFjJeUawNJCIzsLdVIZR+aKj5yy6yqoS8hkN9Ha\n1MljZpsXl+EmwcwAIqim1YeLwERCEAQ/JWbSt8pQTQbzZ6ibwQ4mchCxacrRbIVR\nnL59fWMBassJcbY0VwrTugm2SBsYbDjESd55UZV03Rwr8qseGTyi+hH8O7w2SIaY\nzjN6AdZiPmsh00YflzlCk8MSLOHMol1vqIUzXxU8CdXn9+KsuQdZGrTz0YKN/db4\naVwUGJatz2Tsvf7R1tJBjJfeQWOWbbn3pycLVH86LjZ83qngp9ZVnAveUnUqz0yS\nhe+buZ6UMsfGzbIYon2bKNlz6gYTH0YPcr+cLe+29drtt0GZiXha1agbpo4RB8zE\naNL2fucF5YT0yNpbd/5WoV0CAwEAAQ==\n-----END PUBLIC KEY-----\n"},"signature":{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],"type":"RsaSignature2017","nonce":"c672a408d2e88b322b36a61bf0c25f586be9245d30293c55b8d653dcc867aaf7","creator":"https://apfed.club/channel/indio/public_key_pem","created":"2019-08-26T07:24:03Z","signatureValue":"MyAv5gnedu6L/DYFaE1TUYvp4LjI9ZUU0axwGYOhgD7qsjivMgwbOrjX/iH32xlcfF8nWOMh/ogu3+Qwr5sqLHkS2AimWmw1+Ubf2KccE58b8vI8zWfyu8QJnMuE92jtBPv8UTQUHw8ZebbExk3L99oXaeyVihKiMBmd63NpVTpGXZTg6m+H+KfWchVajPoyNKZtKMd3nH99x5j54Cqkz0BN5CSTwCSG0wP95G0VtZHtmhX+tsAPM3oAj0d+gtCZSCd8Nu8fvFAwCyTg1oKSfRqKb27EKHlskqK9X57x0jURH77CTAIQSejgGcKJ5GGLtvofubJkafadjagqrtqz6Mz6BZ642ssJ2KGkRAn79Q4F08goI6cfU5lLk2Tooe5A55XERnmE3SkYGyTvLpacZplxJdU0sa+deX9D7+alSGFJZSziaxpCxzrO6lEApe4b9kHXAzn9VaZt9trijkHq/kkq0i3NRcP7n8JG9q+Vv8jY9ddY6HcH89RNCBIA6MKLtAqc+vSc5G24qeZlw2MzlQWBp0KGuVG8DQR00AL6cXLBzF1WY8JZeEg6zqm+DMznbuNzgiS34BP+AehBSHlQ4MZebwDnK3ZPPqGSwioIWMxIFfZDaVDX9Pp1pXAARQMw0c/y4sDcf9FMzsr8jteEa7ZQcoqq5kXQTSCP56TEHnI="}}
|
1
test/fixtures/tesla_mock/sjw.json
vendored
Normal file
1
test/fixtures/tesla_mock/sjw.json
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"Hashtag":"as:Hashtag"}],"type":"Person","id":"https://skippers-bin.com/users/7v1w1r8ce6","inbox":"https://skippers-bin.com/users/7v1w1r8ce6/inbox","outbox":"https://skippers-bin.com/users/7v1w1r8ce6/outbox","followers":"https://skippers-bin.com/users/7v1w1r8ce6/followers","following":"https://skippers-bin.com/users/7v1w1r8ce6/following","featured":"https://skippers-bin.com/users/7v1w1r8ce6/collections/featured","sharedInbox":"https://skippers-bin.com/inbox","endpoints":{"sharedInbox":"https://skippers-bin.com/inbox"},"url":"https://skippers-bin.com/@sjw","preferredUsername":"sjw","name":"It's ya boi sjw :verified:","summary":"<p><span>Admin of skippers-bin.com and neckbeard.xyz<br>For the most part I'm just a normal user. I mostly post animu, lewds, may-mays, and shitposts.<br><br>Not an alt of </span><a href=\"https://skippers-bin.com/@sjw@neckbeard.xyz\" class=\"mention\">@sjw@neckbeard.xyz</a><span> but another main.<br><br>Email/XMPP: neckbeard@rape.lol<br>PGP: d016 b622 75ba bcbc 5b3a fced a7d9 4824 0eb3 9c4e</span></p>","icon":{"type":"Image","url":"https://skippers-bin.com/files/webpublic-21b17f5b-3a83-4f50-8d4f-eda92066aa26","sensitive":false},"image":{"type":"Image","url":"https://skippers-bin.com/files/webpublic-1cd7f961-421e-4c31-aa03-74fb82584308","sensitive":false},"tag":[{"id":"https://skippers-bin.com/emojis/verified","type":"Emoji","name":":verified:","updated":"2019-07-12T02:16:12.088Z","icon":{"type":"Image","mediaType":"image/png","url":"https://skippers-bin.com/files/webpublic-dd10b435-6dad-4602-938b-f69ec0a19f2c"}}],"manuallyApprovesFollowers":false,"publicKey":{"id":"https://skippers-bin.com/users/7v1w1r8ce6/publickey","type":"Key","owner":"https://skippers-bin.com/users/7v1w1r8ce6","publicKeyPem":"-----BEGIN RSA PUBLIC KEY-----\nMIICCgKCAgEAvmp71/A6Oxe1UW/44HK0juAJhrjv9gYhaoslaS9K1FB+BHfIjaE9\n9+W2SKRLnVNYNFSN4JJrSGhX5RUjAsf4tcdRDVcmHl7tp2sgOAZeZz5geULm2sJQ\nwElnGk34jT/xCfX+w/O+7DuX31sU7ZK0B2P7ulNGDQXhrzVO0RMx7HhNcsFcusno\n3kmPyyPT1l+PbM2UNWms599/3yicKtuOzMgzxNeXvuHYtAO19txyPiOeYckQOMmT\nwEVIxypgCgNQ0MNtPLPKQTwOgVbvnN7MN+h3esKeKDcPcGQySkbkjZPaVnA6xCQf\nj58c19wqdCfAS4Effo5/bxVmhLpe0l9HYpV7IMasv2LhFntmSmAxBQzhdz0oTYb1\naNqiyfZdClnzutOiKcrFppADo4rZH9Z1WlPHapahrKbF0GRPN8DjSUsoBxfY9wZs\ntlL056hT4o+EFHYrRGo7KP6X/6aQ9sSsmpE08aVpVuXdwuaoaDlW1KrJ0oOk4lZw\nUNXvjEaN3c+VQAw2CNvkAqLuwrjnw7MdcxEGodEXb6s8VvoSOaiDqT7cexSaZe0R\nliCe/3dqFXpX1UrgRiryI4yc1BrEJIGTanchmP2aUJ2R2pccFsREp23C3vMN3M5b\nHw7fvKbUQHyf6lhRoLCOSCz1xaPutaMJmpwLuJo4wPCHGg9QFBYsqxcCAwEAAQ==\n-----END RSA PUBLIC KEY-----\n"},"isCat":true}
|
|
@ -12,7 +12,6 @@ defmodule Pleroma.NotificationTest do
|
||||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.Streamer
|
alias Pleroma.Web.Streamer
|
||||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
|
||||||
|
|
||||||
describe "create_notifications" do
|
describe "create_notifications" do
|
||||||
test "notifies someone when they are directly addressed" do
|
test "notifies someone when they are directly addressed" do
|
||||||
|
@ -21,7 +20,7 @@ test "notifies someone when they are directly addressed" do
|
||||||
third_user = insert(:user)
|
third_user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, activity} =
|
||||||
TwitterAPI.create_status(user, %{
|
CommonAPI.post(user, %{
|
||||||
"status" => "hey @#{other_user.nickname} and @#{third_user.nickname}"
|
"status" => "hey @#{other_user.nickname} and @#{third_user.nickname}"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -39,7 +38,7 @@ test "it creates a notification for subscribed users" do
|
||||||
|
|
||||||
User.subscribe(subscriber, user)
|
User.subscribe(subscriber, user)
|
||||||
|
|
||||||
{:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
|
{:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
|
||||||
{:ok, [notification]} = Notification.create_notifications(status)
|
{:ok, [notification]} = Notification.create_notifications(status)
|
||||||
|
|
||||||
assert notification.user_id == subscriber.id
|
assert notification.user_id == subscriber.id
|
||||||
|
@ -184,47 +183,20 @@ test "it doesn't create a notification for user if he is the activity author" do
|
||||||
test "it doesn't create a notification for follow-unfollow-follow chains" do
|
test "it doesn't create a notification for follow-unfollow-follow chains" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
followed_user = insert(:user)
|
followed_user = insert(:user)
|
||||||
{:ok, _, _, activity} = TwitterAPI.follow(user, %{"user_id" => followed_user.id})
|
{:ok, _, _, activity} = CommonAPI.follow(user, followed_user)
|
||||||
Notification.create_notification(activity, followed_user)
|
Notification.create_notification(activity, followed_user)
|
||||||
TwitterAPI.unfollow(user, %{"user_id" => followed_user.id})
|
CommonAPI.unfollow(user, followed_user)
|
||||||
{:ok, _, _, activity_dupe} = TwitterAPI.follow(user, %{"user_id" => followed_user.id})
|
{:ok, _, _, activity_dupe} = CommonAPI.follow(user, followed_user)
|
||||||
refute Notification.create_notification(activity_dupe, followed_user)
|
refute Notification.create_notification(activity_dupe, followed_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it doesn't create a notification for like-unlike-like chains" do
|
|
||||||
user = insert(:user)
|
|
||||||
liked_user = insert(:user)
|
|
||||||
{:ok, status} = TwitterAPI.create_status(liked_user, %{"status" => "Yui is best yuru"})
|
|
||||||
{:ok, fav_status} = TwitterAPI.fav(user, status.id)
|
|
||||||
Notification.create_notification(fav_status, liked_user)
|
|
||||||
TwitterAPI.unfav(user, status.id)
|
|
||||||
{:ok, dupe} = TwitterAPI.fav(user, status.id)
|
|
||||||
refute Notification.create_notification(dupe, liked_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it doesn't create a notification for repeat-unrepeat-repeat chains" do
|
|
||||||
user = insert(:user)
|
|
||||||
retweeted_user = insert(:user)
|
|
||||||
|
|
||||||
{:ok, status} =
|
|
||||||
TwitterAPI.create_status(retweeted_user, %{
|
|
||||||
"status" => "Send dupe notifications to the shadow realm"
|
|
||||||
})
|
|
||||||
|
|
||||||
{:ok, retweeted_activity} = TwitterAPI.repeat(user, status.id)
|
|
||||||
Notification.create_notification(retweeted_activity, retweeted_user)
|
|
||||||
TwitterAPI.unrepeat(user, status.id)
|
|
||||||
{:ok, dupe} = TwitterAPI.repeat(user, status.id)
|
|
||||||
refute Notification.create_notification(dupe, retweeted_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it doesn't create duplicate notifications for follow+subscribed users" do
|
test "it doesn't create duplicate notifications for follow+subscribed users" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
subscriber = insert(:user)
|
subscriber = insert(:user)
|
||||||
|
|
||||||
{:ok, _, _, _} = TwitterAPI.follow(subscriber, %{"user_id" => user.id})
|
{:ok, _, _, _} = CommonAPI.follow(subscriber, user)
|
||||||
User.subscribe(subscriber, user)
|
User.subscribe(subscriber, user)
|
||||||
{:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
|
{:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
|
||||||
{:ok, [_notif]} = Notification.create_notifications(status)
|
{:ok, [_notif]} = Notification.create_notifications(status)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -234,8 +206,7 @@ test "it doesn't create subscription notifications if the recipient cannot see t
|
||||||
|
|
||||||
User.subscribe(subscriber, user)
|
User.subscribe(subscriber, user)
|
||||||
|
|
||||||
{:ok, status} =
|
{:ok, status} = CommonAPI.post(user, %{"status" => "inwisible", "visibility" => "direct"})
|
||||||
TwitterAPI.create_status(user, %{"status" => "inwisible", "visibility" => "direct"})
|
|
||||||
|
|
||||||
assert {:ok, []} == Notification.create_notifications(status)
|
assert {:ok, []} == Notification.create_notifications(status)
|
||||||
end
|
end
|
||||||
|
@ -246,8 +217,7 @@ test "it gets a notification that belongs to the user" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||||
TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
|
|
||||||
|
|
||||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||||
{:ok, notification} = Notification.get(other_user, notification.id)
|
{:ok, notification} = Notification.get(other_user, notification.id)
|
||||||
|
@ -259,8 +229,7 @@ test "it returns error if the notification doesn't belong to the user" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||||
TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
|
|
||||||
|
|
||||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||||
{:error, _notification} = Notification.get(user, notification.id)
|
{:error, _notification} = Notification.get(user, notification.id)
|
||||||
|
@ -272,8 +241,7 @@ test "it dismisses a notification that belongs to the user" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||||
TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
|
|
||||||
|
|
||||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||||
{:ok, notification} = Notification.dismiss(other_user, notification.id)
|
{:ok, notification} = Notification.dismiss(other_user, notification.id)
|
||||||
|
@ -285,8 +253,7 @@ test "it returns error if the notification doesn't belong to the user" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||||
TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
|
|
||||||
|
|
||||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||||
{:error, _notification} = Notification.dismiss(user, notification.id)
|
{:error, _notification} = Notification.dismiss(user, notification.id)
|
||||||
|
@ -300,14 +267,14 @@ test "it clears all notifications belonging to the user" do
|
||||||
third_user = insert(:user)
|
third_user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, activity} =
|
||||||
TwitterAPI.create_status(user, %{
|
CommonAPI.post(user, %{
|
||||||
"status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
|
"status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
|
||||||
})
|
})
|
||||||
|
|
||||||
{:ok, _notifs} = Notification.create_notifications(activity)
|
{:ok, _notifs} = Notification.create_notifications(activity)
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, activity} =
|
||||||
TwitterAPI.create_status(user, %{
|
CommonAPI.post(user, %{
|
||||||
"status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
|
"status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -325,12 +292,12 @@ test "it sets all notifications as read up to a specified notification ID" do
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
||||||
{:ok, _activity} =
|
{:ok, _activity} =
|
||||||
TwitterAPI.create_status(user, %{
|
CommonAPI.post(user, %{
|
||||||
"status" => "hey @#{other_user.nickname}!"
|
"status" => "hey @#{other_user.nickname}!"
|
||||||
})
|
})
|
||||||
|
|
||||||
{:ok, _activity} =
|
{:ok, _activity} =
|
||||||
TwitterAPI.create_status(user, %{
|
CommonAPI.post(user, %{
|
||||||
"status" => "hey again @#{other_user.nickname}!"
|
"status" => "hey again @#{other_user.nickname}!"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -340,7 +307,7 @@ test "it sets all notifications as read up to a specified notification ID" do
|
||||||
assert n2.id > n1.id
|
assert n2.id > n1.id
|
||||||
|
|
||||||
{:ok, _activity} =
|
{:ok, _activity} =
|
||||||
TwitterAPI.create_status(user, %{
|
CommonAPI.post(user, %{
|
||||||
"status" => "hey yet again @#{other_user.nickname}!"
|
"status" => "hey yet again @#{other_user.nickname}!"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -677,7 +644,7 @@ test "it returns notifications for muted user without notifications" do
|
||||||
muted = insert(:user)
|
muted = insert(:user)
|
||||||
{:ok, user} = User.mute(user, muted, false)
|
{:ok, user} = User.mute(user, muted, false)
|
||||||
|
|
||||||
{:ok, _activity} = TwitterAPI.create_status(muted, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
assert length(Notification.for_user(user)) == 1
|
assert length(Notification.for_user(user)) == 1
|
||||||
end
|
end
|
||||||
|
@ -687,7 +654,7 @@ test "it doesn't return notifications for muted user with notifications" do
|
||||||
muted = insert(:user)
|
muted = insert(:user)
|
||||||
{:ok, user} = User.mute(user, muted)
|
{:ok, user} = User.mute(user, muted)
|
||||||
|
|
||||||
{:ok, _activity} = TwitterAPI.create_status(muted, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
assert Notification.for_user(user) == []
|
assert Notification.for_user(user) == []
|
||||||
end
|
end
|
||||||
|
@ -697,7 +664,7 @@ test "it doesn't return notifications for blocked user" do
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
{:ok, user} = User.block(user, blocked)
|
{:ok, user} = User.block(user, blocked)
|
||||||
|
|
||||||
{:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
assert Notification.for_user(user) == []
|
assert Notification.for_user(user) == []
|
||||||
end
|
end
|
||||||
|
@ -707,7 +674,7 @@ test "it doesn't return notificatitons for blocked domain" do
|
||||||
blocked = insert(:user, ap_id: "http://some-domain.com")
|
blocked = insert(:user, ap_id: "http://some-domain.com")
|
||||||
{:ok, user} = User.block_domain(user, "some-domain.com")
|
{:ok, user} = User.block_domain(user, "some-domain.com")
|
||||||
|
|
||||||
{:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
assert Notification.for_user(user) == []
|
assert Notification.for_user(user) == []
|
||||||
end
|
end
|
||||||
|
@ -716,8 +683,7 @@ test "it doesn't return notifications for muted thread" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
another_user = insert(:user)
|
another_user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
|
||||||
TwitterAPI.create_status(another_user, %{"status" => "hey @#{user.nickname}"})
|
|
||||||
|
|
||||||
{:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
|
{:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
|
||||||
assert Notification.for_user(user) == []
|
assert Notification.for_user(user) == []
|
||||||
|
@ -728,7 +694,7 @@ test "it returns notifications for muted user with notifications and with_muted
|
||||||
muted = insert(:user)
|
muted = insert(:user)
|
||||||
{:ok, user} = User.mute(user, muted)
|
{:ok, user} = User.mute(user, muted)
|
||||||
|
|
||||||
{:ok, _activity} = TwitterAPI.create_status(muted, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
||||||
end
|
end
|
||||||
|
@ -738,7 +704,7 @@ test "it returns notifications for blocked user and with_muted parameter" do
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
{:ok, user} = User.block(user, blocked)
|
{:ok, user} = User.block(user, blocked)
|
||||||
|
|
||||||
{:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
||||||
end
|
end
|
||||||
|
@ -748,7 +714,7 @@ test "it returns notificatitons for blocked domain and with_muted parameter" do
|
||||||
blocked = insert(:user, ap_id: "http://some-domain.com")
|
blocked = insert(:user, ap_id: "http://some-domain.com")
|
||||||
{:ok, user} = User.block_domain(user, "some-domain.com")
|
{:ok, user} = User.block_domain(user, "some-domain.com")
|
||||||
|
|
||||||
{:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||||
|
|
||||||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
||||||
end
|
end
|
||||||
|
@ -757,8 +723,7 @@ test "it returns notifications for muted thread with_muted parameter" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
another_user = insert(:user)
|
another_user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} =
|
{:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
|
||||||
TwitterAPI.create_status(another_user, %{"status" => "hey @#{user.nickname}"})
|
|
||||||
|
|
||||||
{:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
|
{:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
|
||||||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
||||||
|
|
|
@ -53,9 +53,12 @@ test "ensures cache is cleared for the object" do
|
||||||
|
|
||||||
assert object == cached_object
|
assert object == cached_object
|
||||||
|
|
||||||
|
Cachex.put(:web_resp_cache, URI.parse(object.data["id"]).path, "cofe")
|
||||||
|
|
||||||
Object.delete(cached_object)
|
Object.delete(cached_object)
|
||||||
|
|
||||||
{:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
|
{:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
|
||||||
|
{:ok, nil} = Cachex.get(:web_resp_cache, URI.parse(object.data["id"]).path)
|
||||||
|
|
||||||
cached_object = Object.get_cached_by_ap_id(object.data["id"])
|
cached_object = Object.get_cached_by_ap_id(object.data["id"])
|
||||||
|
|
||||||
|
|
78
test/pagination_test.exs
Normal file
78
test/pagination_test.exs
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.PaginationTest do
|
||||||
|
use Pleroma.DataCase
|
||||||
|
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.Pagination
|
||||||
|
|
||||||
|
describe "keyset" do
|
||||||
|
setup do
|
||||||
|
notes = insert_list(5, :note)
|
||||||
|
|
||||||
|
%{notes: notes}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "paginates by min_id", %{notes: notes} do
|
||||||
|
id = Enum.at(notes, 2).id |> Integer.to_string()
|
||||||
|
|
||||||
|
%{total: total, items: paginated} =
|
||||||
|
Pagination.fetch_paginated(Object, %{"min_id" => id, "total" => true})
|
||||||
|
|
||||||
|
assert length(paginated) == 2
|
||||||
|
assert total == 5
|
||||||
|
end
|
||||||
|
|
||||||
|
test "paginates by since_id", %{notes: notes} do
|
||||||
|
id = Enum.at(notes, 2).id |> Integer.to_string()
|
||||||
|
|
||||||
|
%{total: total, items: paginated} =
|
||||||
|
Pagination.fetch_paginated(Object, %{"since_id" => id, "total" => true})
|
||||||
|
|
||||||
|
assert length(paginated) == 2
|
||||||
|
assert total == 5
|
||||||
|
end
|
||||||
|
|
||||||
|
test "paginates by max_id", %{notes: notes} do
|
||||||
|
id = Enum.at(notes, 1).id |> Integer.to_string()
|
||||||
|
|
||||||
|
%{total: total, items: paginated} =
|
||||||
|
Pagination.fetch_paginated(Object, %{"max_id" => id, "total" => true})
|
||||||
|
|
||||||
|
assert length(paginated) == 1
|
||||||
|
assert total == 5
|
||||||
|
end
|
||||||
|
|
||||||
|
test "paginates by min_id & limit", %{notes: notes} do
|
||||||
|
id = Enum.at(notes, 2).id |> Integer.to_string()
|
||||||
|
|
||||||
|
paginated = Pagination.fetch_paginated(Object, %{"min_id" => id, "limit" => 1})
|
||||||
|
|
||||||
|
assert length(paginated) == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "offset" do
|
||||||
|
setup do
|
||||||
|
notes = insert_list(5, :note)
|
||||||
|
|
||||||
|
%{notes: notes}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "paginates by limit" do
|
||||||
|
paginated = Pagination.fetch_paginated(Object, %{"limit" => 2}, :offset)
|
||||||
|
|
||||||
|
assert length(paginated) == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
test "paginates by limit & offset" do
|
||||||
|
paginated = Pagination.fetch_paginated(Object, %{"limit" => 2, "offset" => 4}, :offset)
|
||||||
|
|
||||||
|
assert length(paginated) == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
186
test/plugs/cache_test.exs
Normal file
186
test/plugs/cache_test.exs
Normal file
|
@ -0,0 +1,186 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Plugs.CacheTest do
|
||||||
|
use ExUnit.Case, async: true
|
||||||
|
use Plug.Test
|
||||||
|
|
||||||
|
alias Pleroma.Plugs.Cache
|
||||||
|
|
||||||
|
@miss_resp {200,
|
||||||
|
[
|
||||||
|
{"cache-control", "max-age=0, private, must-revalidate"},
|
||||||
|
{"content-type", "cofe/hot; charset=utf-8"},
|
||||||
|
{"x-cache", "MISS from Pleroma"}
|
||||||
|
], "cofe"}
|
||||||
|
|
||||||
|
@hit_resp {200,
|
||||||
|
[
|
||||||
|
{"cache-control", "max-age=0, private, must-revalidate"},
|
||||||
|
{"content-type", "cofe/hot; charset=utf-8"},
|
||||||
|
{"x-cache", "HIT from Pleroma"}
|
||||||
|
], "cofe"}
|
||||||
|
|
||||||
|
@ttl 5
|
||||||
|
|
||||||
|
setup do
|
||||||
|
Cachex.clear(:web_resp_cache)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
test "caches a response" do
|
||||||
|
assert @miss_resp ==
|
||||||
|
conn(:get, "/")
|
||||||
|
|> Cache.call(%{query_params: false, ttl: nil})
|
||||||
|
|> put_resp_content_type("cofe/hot")
|
||||||
|
|> send_resp(:ok, "cofe")
|
||||||
|
|> sent_resp()
|
||||||
|
|
||||||
|
assert_raise(Plug.Conn.AlreadySentError, fn ->
|
||||||
|
conn(:get, "/")
|
||||||
|
|> Cache.call(%{query_params: false, ttl: nil})
|
||||||
|
|> put_resp_content_type("cofe/hot")
|
||||||
|
|> send_resp(:ok, "cofe")
|
||||||
|
|> sent_resp()
|
||||||
|
end)
|
||||||
|
|
||||||
|
assert @hit_resp ==
|
||||||
|
conn(:get, "/")
|
||||||
|
|> Cache.call(%{query_params: false, ttl: nil})
|
||||||
|
|> sent_resp()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "ttl is set" do
|
||||||
|
assert @miss_resp ==
|
||||||
|
conn(:get, "/")
|
||||||
|
|> Cache.call(%{query_params: false, ttl: @ttl})
|
||||||
|
|> put_resp_content_type("cofe/hot")
|
||||||
|
|> send_resp(:ok, "cofe")
|
||||||
|
|> sent_resp()
|
||||||
|
|
||||||
|
assert @hit_resp ==
|
||||||
|
conn(:get, "/")
|
||||||
|
|> Cache.call(%{query_params: false, ttl: @ttl})
|
||||||
|
|> sent_resp()
|
||||||
|
|
||||||
|
:timer.sleep(@ttl + 1)
|
||||||
|
|
||||||
|
assert @miss_resp ==
|
||||||
|
conn(:get, "/")
|
||||||
|
|> Cache.call(%{query_params: false, ttl: @ttl})
|
||||||
|
|> put_resp_content_type("cofe/hot")
|
||||||
|
|> send_resp(:ok, "cofe")
|
||||||
|
|> sent_resp()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "set ttl via conn.assigns" do
|
||||||
|
assert @miss_resp ==
|
||||||
|
conn(:get, "/")
|
||||||
|
|> Cache.call(%{query_params: false, ttl: nil})
|
||||||
|
|> put_resp_content_type("cofe/hot")
|
||||||
|
|> assign(:cache_ttl, @ttl)
|
||||||
|
|> send_resp(:ok, "cofe")
|
||||||
|
|> sent_resp()
|
||||||
|
|
||||||
|
assert @hit_resp ==
|
||||||
|
conn(:get, "/")
|
||||||
|
|> Cache.call(%{query_params: false, ttl: nil})
|
||||||
|
|> sent_resp()
|
||||||
|
|
||||||
|
:timer.sleep(@ttl + 1)
|
||||||
|
|
||||||
|
assert @miss_resp ==
|
||||||
|
conn(:get, "/")
|
||||||
|
|> Cache.call(%{query_params: false, ttl: nil})
|
||||||
|
|> put_resp_content_type("cofe/hot")
|
||||||
|
|> send_resp(:ok, "cofe")
|
||||||
|
|> sent_resp()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "ignore query string when `query_params` is false" do
|
||||||
|
assert @miss_resp ==
|
||||||
|
conn(:get, "/?cofe")
|
||||||
|
|> Cache.call(%{query_params: false, ttl: nil})
|
||||||
|
|> put_resp_content_type("cofe/hot")
|
||||||
|
|> send_resp(:ok, "cofe")
|
||||||
|
|> sent_resp()
|
||||||
|
|
||||||
|
assert @hit_resp ==
|
||||||
|
conn(:get, "/?cofefe")
|
||||||
|
|> Cache.call(%{query_params: false, ttl: nil})
|
||||||
|
|> sent_resp()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "take query string into account when `query_params` is true" do
|
||||||
|
assert @miss_resp ==
|
||||||
|
conn(:get, "/?cofe")
|
||||||
|
|> Cache.call(%{query_params: true, ttl: nil})
|
||||||
|
|> put_resp_content_type("cofe/hot")
|
||||||
|
|> send_resp(:ok, "cofe")
|
||||||
|
|> sent_resp()
|
||||||
|
|
||||||
|
assert @miss_resp ==
|
||||||
|
conn(:get, "/?cofefe")
|
||||||
|
|> Cache.call(%{query_params: true, ttl: nil})
|
||||||
|
|> put_resp_content_type("cofe/hot")
|
||||||
|
|> send_resp(:ok, "cofe")
|
||||||
|
|> sent_resp()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "take specific query params into account when `query_params` is list" do
|
||||||
|
assert @miss_resp ==
|
||||||
|
conn(:get, "/?a=1&b=2&c=3&foo=bar")
|
||||||
|
|> fetch_query_params()
|
||||||
|
|> Cache.call(%{query_params: ["a", "b", "c"], ttl: nil})
|
||||||
|
|> put_resp_content_type("cofe/hot")
|
||||||
|
|> send_resp(:ok, "cofe")
|
||||||
|
|> sent_resp()
|
||||||
|
|
||||||
|
assert @hit_resp ==
|
||||||
|
conn(:get, "/?bar=foo&c=3&b=2&a=1")
|
||||||
|
|> fetch_query_params()
|
||||||
|
|> Cache.call(%{query_params: ["a", "b", "c"], ttl: nil})
|
||||||
|
|> sent_resp()
|
||||||
|
|
||||||
|
assert @miss_resp ==
|
||||||
|
conn(:get, "/?bar=foo&c=3&b=2&a=2")
|
||||||
|
|> fetch_query_params()
|
||||||
|
|> Cache.call(%{query_params: ["a", "b", "c"], ttl: nil})
|
||||||
|
|> put_resp_content_type("cofe/hot")
|
||||||
|
|> send_resp(:ok, "cofe")
|
||||||
|
|> sent_resp()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "ignore not GET requests" do
|
||||||
|
expected =
|
||||||
|
{200,
|
||||||
|
[
|
||||||
|
{"cache-control", "max-age=0, private, must-revalidate"},
|
||||||
|
{"content-type", "cofe/hot; charset=utf-8"}
|
||||||
|
], "cofe"}
|
||||||
|
|
||||||
|
assert expected ==
|
||||||
|
conn(:post, "/")
|
||||||
|
|> Cache.call(%{query_params: true, ttl: nil})
|
||||||
|
|> put_resp_content_type("cofe/hot")
|
||||||
|
|> send_resp(:ok, "cofe")
|
||||||
|
|> sent_resp()
|
||||||
|
end
|
||||||
|
|
||||||
|
test "ignore non-successful responses" do
|
||||||
|
expected =
|
||||||
|
{418,
|
||||||
|
[
|
||||||
|
{"cache-control", "max-age=0, private, must-revalidate"},
|
||||||
|
{"content-type", "tea/iced; charset=utf-8"}
|
||||||
|
], "🥤"}
|
||||||
|
|
||||||
|
assert expected ==
|
||||||
|
conn(:get, "/cofe")
|
||||||
|
|> Cache.call(%{query_params: true, ttl: nil})
|
||||||
|
|> put_resp_content_type("tea/iced")
|
||||||
|
|> send_resp(:im_a_teapot, "🥤")
|
||||||
|
|> sent_resp()
|
||||||
|
end
|
||||||
|
end
|
|
@ -775,6 +775,11 @@ def get("https://mastodon.social/users/lambadalambda", _, _, _) do
|
||||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
|
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get("https://apfed.club/channel/indio", _, _, _) do
|
||||||
|
{:ok,
|
||||||
|
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json")}}
|
||||||
|
end
|
||||||
|
|
||||||
def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
|
def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
|
||||||
{:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
|
{:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
|
||||||
end
|
end
|
||||||
|
@ -987,6 +992,18 @@ def get("http://example.com/rel_me/null", _, _, _) do
|
||||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
|
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get("https://skippers-bin.com/notes/7x9tmrp97i", _, _, _) do
|
||||||
|
{:ok,
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200,
|
||||||
|
body: File.read!("test/fixtures/tesla_mock/misskey_poll_no_end_date.json")
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
|
def get("https://skippers-bin.com/users/7v1w1r8ce6", _, _, _) do
|
||||||
|
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sjw.json")}}
|
||||||
|
end
|
||||||
|
|
||||||
def get(url, query, body, headers) do
|
def get(url, query, body, headers) do
|
||||||
{:error,
|
{:error,
|
||||||
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||||
|
|
|
@ -69,8 +69,8 @@ test "returns all pending follow requests" do
|
||||||
locked = insert(:user, %{info: %{locked: true}})
|
locked = insert(:user, %{info: %{locked: true}})
|
||||||
follower = insert(:user)
|
follower = insert(:user)
|
||||||
|
|
||||||
Pleroma.Web.TwitterAPI.TwitterAPI.follow(follower, %{"user_id" => unlocked.id})
|
CommonAPI.follow(follower, unlocked)
|
||||||
Pleroma.Web.TwitterAPI.TwitterAPI.follow(follower, %{"user_id" => locked.id})
|
CommonAPI.follow(follower, locked)
|
||||||
|
|
||||||
assert {:ok, []} = User.get_follow_requests(unlocked)
|
assert {:ok, []} = User.get_follow_requests(unlocked)
|
||||||
assert {:ok, [activity]} = User.get_follow_requests(locked)
|
assert {:ok, [activity]} = User.get_follow_requests(locked)
|
||||||
|
@ -83,9 +83,9 @@ test "doesn't return already accepted or duplicate follow requests" do
|
||||||
pending_follower = insert(:user)
|
pending_follower = insert(:user)
|
||||||
accepted_follower = insert(:user)
|
accepted_follower = insert(:user)
|
||||||
|
|
||||||
Pleroma.Web.TwitterAPI.TwitterAPI.follow(pending_follower, %{"user_id" => locked.id})
|
CommonAPI.follow(pending_follower, locked)
|
||||||
Pleroma.Web.TwitterAPI.TwitterAPI.follow(pending_follower, %{"user_id" => locked.id})
|
CommonAPI.follow(pending_follower, locked)
|
||||||
Pleroma.Web.TwitterAPI.TwitterAPI.follow(accepted_follower, %{"user_id" => locked.id})
|
CommonAPI.follow(accepted_follower, locked)
|
||||||
User.follow(accepted_follower, locked)
|
User.follow(accepted_follower, locked)
|
||||||
|
|
||||||
assert {:ok, [activity]} = User.get_follow_requests(locked)
|
assert {:ok, [activity]} = User.get_follow_requests(locked)
|
||||||
|
@ -1279,11 +1279,9 @@ test "follower count is updated when a follower is blocked" do
|
||||||
{:ok, _follower2} = User.follow(follower2, user)
|
{:ok, _follower2} = User.follow(follower2, user)
|
||||||
{:ok, _follower3} = User.follow(follower3, user)
|
{:ok, _follower3} = User.follow(follower3, user)
|
||||||
|
|
||||||
{:ok, _} = User.block(user, follower)
|
{:ok, user} = User.block(user, follower)
|
||||||
|
|
||||||
user_show = Pleroma.Web.TwitterAPI.UserView.render("show.json", %{user: user})
|
assert User.user_info(user).follower_count == 2
|
||||||
|
|
||||||
assert Map.get(user_show, "followers_count") == 2
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "list_inactive_users_query/1" do
|
describe "list_inactive_users_query/1" do
|
||||||
|
@ -1327,7 +1325,7 @@ test "Only includes users who has no recent activity" do
|
||||||
to = Enum.random(users -- [user])
|
to = Enum.random(users -- [user])
|
||||||
|
|
||||||
{:ok, _} =
|
{:ok, _} =
|
||||||
Pleroma.Web.TwitterAPI.TwitterAPI.create_status(user, %{
|
CommonAPI.post(user, %{
|
||||||
"status" => "hey @#{to.nickname}"
|
"status" => "hey @#{to.nickname}"
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|
@ -1359,12 +1357,12 @@ test "Only includes users with no read notifications" do
|
||||||
|
|
||||||
Enum.each(recipients, fn to ->
|
Enum.each(recipients, fn to ->
|
||||||
{:ok, _} =
|
{:ok, _} =
|
||||||
Pleroma.Web.TwitterAPI.TwitterAPI.create_status(sender, %{
|
CommonAPI.post(sender, %{
|
||||||
"status" => "hey @#{to.nickname}"
|
"status" => "hey @#{to.nickname}"
|
||||||
})
|
})
|
||||||
|
|
||||||
{:ok, _} =
|
{:ok, _} =
|
||||||
Pleroma.Web.TwitterAPI.TwitterAPI.create_status(sender, %{
|
CommonAPI.post(sender, %{
|
||||||
"status" => "hey again @#{to.nickname}"
|
"status" => "hey again @#{to.nickname}"
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|
@ -1616,4 +1614,31 @@ test "syncronizes the counters with the remote instance for the follower when en
|
||||||
assert User.user_info(other_user).following_count == 152
|
assert User.user_info(other_user).following_count == 152
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "change_email/2" do
|
||||||
|
setup do
|
||||||
|
[user: insert(:user)]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "blank email returns error", %{user: user} do
|
||||||
|
assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, "")
|
||||||
|
assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "non unique email returns error", %{user: user} do
|
||||||
|
%{email: email} = insert(:user)
|
||||||
|
|
||||||
|
assert {:error, %{errors: [email: {"has already been taken", _}]}} =
|
||||||
|
User.change_email(user, email)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "invalid email returns error", %{user: user} do
|
||||||
|
assert {:error, %{errors: [email: {"has invalid format", _}]}} =
|
||||||
|
User.change_email(user, "cofe")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "changes email", %{user: user} do
|
||||||
|
assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -175,6 +175,49 @@ test "it returns 404 for tombstone objects", %{conn: conn} do
|
||||||
|
|
||||||
assert json_response(conn, 404)
|
assert json_response(conn, 404)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it caches a response", %{conn: conn} do
|
||||||
|
note = insert(:note)
|
||||||
|
uuid = String.split(note.data["id"], "/") |> List.last()
|
||||||
|
|
||||||
|
conn1 =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|
|> get("/objects/#{uuid}")
|
||||||
|
|
||||||
|
assert json_response(conn1, :ok)
|
||||||
|
assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
|
||||||
|
|
||||||
|
conn2 =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|
|> get("/objects/#{uuid}")
|
||||||
|
|
||||||
|
assert json_response(conn1, :ok) == json_response(conn2, :ok)
|
||||||
|
assert Enum.any?(conn2.resp_headers, &(&1 == {"x-cache", "HIT from Pleroma"}))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "cached purged after object deletion", %{conn: conn} do
|
||||||
|
note = insert(:note)
|
||||||
|
uuid = String.split(note.data["id"], "/") |> List.last()
|
||||||
|
|
||||||
|
conn1 =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|
|> get("/objects/#{uuid}")
|
||||||
|
|
||||||
|
assert json_response(conn1, :ok)
|
||||||
|
assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
|
||||||
|
|
||||||
|
Object.delete(note)
|
||||||
|
|
||||||
|
conn2 =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|
|> get("/objects/#{uuid}")
|
||||||
|
|
||||||
|
assert "Not found" == json_response(conn2, :not_found)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "/object/:uuid/likes" do
|
describe "/object/:uuid/likes" do
|
||||||
|
@ -264,6 +307,51 @@ test "it returns 404 for non-public activities", %{conn: conn} do
|
||||||
|
|
||||||
assert json_response(conn, 404)
|
assert json_response(conn, 404)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it caches a response", %{conn: conn} do
|
||||||
|
activity = insert(:note_activity)
|
||||||
|
uuid = String.split(activity.data["id"], "/") |> List.last()
|
||||||
|
|
||||||
|
conn1 =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|
|> get("/activities/#{uuid}")
|
||||||
|
|
||||||
|
assert json_response(conn1, :ok)
|
||||||
|
assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
|
||||||
|
|
||||||
|
conn2 =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|
|> get("/activities/#{uuid}")
|
||||||
|
|
||||||
|
assert json_response(conn1, :ok) == json_response(conn2, :ok)
|
||||||
|
assert Enum.any?(conn2.resp_headers, &(&1 == {"x-cache", "HIT from Pleroma"}))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "cached purged after activity deletion", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "cofe"})
|
||||||
|
|
||||||
|
uuid = String.split(activity.data["id"], "/") |> List.last()
|
||||||
|
|
||||||
|
conn1 =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|
|> get("/activities/#{uuid}")
|
||||||
|
|
||||||
|
assert json_response(conn1, :ok)
|
||||||
|
assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
|
||||||
|
|
||||||
|
Activity.delete_by_ap_id(activity.object.data["id"])
|
||||||
|
|
||||||
|
conn2 =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|
|> get("/activities/#{uuid}")
|
||||||
|
|
||||||
|
assert "Not found" == json_response(conn2, :not_found)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "/inbox" do
|
describe "/inbox" do
|
||||||
|
@ -365,6 +453,17 @@ test "it rejects reads from other users", %{conn: conn} do
|
||||||
assert json_response(conn, 403)
|
assert json_response(conn, 403)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it doesn't crash without an authenticated user", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|
|> get("/users/#{user.nickname}/inbox")
|
||||||
|
|
||||||
|
assert json_response(conn, 403)
|
||||||
|
end
|
||||||
|
|
||||||
test "it returns a note activity in a collection", %{conn: conn} do
|
test "it returns a note activity in a collection", %{conn: conn} do
|
||||||
note_activity = insert(:direct_note_activity)
|
note_activity = insert(:direct_note_activity)
|
||||||
note_object = Object.normalize(note_activity)
|
note_object = Object.normalize(note_activity)
|
||||||
|
|
|
@ -19,6 +19,25 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "handle_incoming" do
|
describe "handle_incoming" do
|
||||||
|
test "it works for osada follow request" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
data =
|
||||||
|
File.read!("test/fixtures/osada-follow-activity.json")
|
||||||
|
|> Poison.decode!()
|
||||||
|
|> Map.put("object", user.ap_id)
|
||||||
|
|
||||||
|
{:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||||
|
|
||||||
|
assert data["actor"] == "https://apfed.club/channel/indio"
|
||||||
|
assert data["type"] == "Follow"
|
||||||
|
assert data["id"] == "https://apfed.club/follow/9"
|
||||||
|
|
||||||
|
activity = Repo.get(Activity, activity.id)
|
||||||
|
assert activity.data["state"] == "accept"
|
||||||
|
assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
|
||||||
|
end
|
||||||
|
|
||||||
test "it works for incoming follow requests" do
|
test "it works for incoming follow requests" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ test "it does not crash if the object in inReplyTo can't be fetched" do
|
||||||
|
|
||||||
assert capture_log(fn ->
|
assert capture_log(fn ->
|
||||||
{:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
|
{:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
|
||||||
end) =~ "[error] Couldn't fetch \"\"https://404.site/whatever\"\", error: nil"
|
end) =~ "[error] Couldn't fetch \"https://404.site/whatever\", error: nil"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it works for incoming notices" do
|
test "it works for incoming notices" do
|
||||||
|
|
|
@ -1779,7 +1779,11 @@ test "common config example", %{conn: conn} do
|
||||||
%{"tuple" => [":seconds_valid", 60]},
|
%{"tuple" => [":seconds_valid", 60]},
|
||||||
%{"tuple" => [":path", ""]},
|
%{"tuple" => [":path", ""]},
|
||||||
%{"tuple" => [":key1", nil]},
|
%{"tuple" => [":key1", nil]},
|
||||||
%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}
|
%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
|
||||||
|
%{"tuple" => [":regex1", "~r/https:\/\/example.com/"]},
|
||||||
|
%{"tuple" => [":regex2", "~r/https:\/\/example.com/u"]},
|
||||||
|
%{"tuple" => [":regex3", "~r/https:\/\/example.com/i"]},
|
||||||
|
%{"tuple" => [":regex4", "~r/https:\/\/example.com/s"]}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -1796,7 +1800,11 @@ test "common config example", %{conn: conn} do
|
||||||
%{"tuple" => [":seconds_valid", 60]},
|
%{"tuple" => [":seconds_valid", 60]},
|
||||||
%{"tuple" => [":path", ""]},
|
%{"tuple" => [":path", ""]},
|
||||||
%{"tuple" => [":key1", nil]},
|
%{"tuple" => [":key1", nil]},
|
||||||
%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}
|
%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
|
||||||
|
%{"tuple" => [":regex1", "~r/https:\\/\\/example.com/"]},
|
||||||
|
%{"tuple" => [":regex2", "~r/https:\\/\\/example.com/u"]},
|
||||||
|
%{"tuple" => [":regex3", "~r/https:\\/\\/example.com/i"]},
|
||||||
|
%{"tuple" => [":regex4", "~r/https:\\/\\/example.com/s"]}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -103,6 +103,30 @@ test "sigil" do
|
||||||
assert Config.from_binary(binary) == ~r/comp[lL][aA][iI][nN]er/
|
assert Config.from_binary(binary) == ~r/comp[lL][aA][iI][nN]er/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "link sigil" do
|
||||||
|
binary = Config.transform("~r/https:\/\/example.com/")
|
||||||
|
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/)
|
||||||
|
assert Config.from_binary(binary) == ~r/https:\/\/example.com/
|
||||||
|
end
|
||||||
|
|
||||||
|
test "link sigil with u modifier" do
|
||||||
|
binary = Config.transform("~r/https:\/\/example.com/u")
|
||||||
|
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/u)
|
||||||
|
assert Config.from_binary(binary) == ~r/https:\/\/example.com/u
|
||||||
|
end
|
||||||
|
|
||||||
|
test "link sigil with i modifier" do
|
||||||
|
binary = Config.transform("~r/https:\/\/example.com/i")
|
||||||
|
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/i)
|
||||||
|
assert Config.from_binary(binary) == ~r/https:\/\/example.com/i
|
||||||
|
end
|
||||||
|
|
||||||
|
test "link sigil with s modifier" do
|
||||||
|
binary = Config.transform("~r/https:\/\/example.com/s")
|
||||||
|
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/s)
|
||||||
|
assert Config.from_binary(binary) == ~r/https:\/\/example.com/s
|
||||||
|
end
|
||||||
|
|
||||||
test "2 child tuple" do
|
test "2 child tuple" do
|
||||||
binary = Config.transform(%{"tuple" => ["v1", ":v2"]})
|
binary = Config.transform(%{"tuple" => ["v1", ":v2"]})
|
||||||
assert binary == :erlang.term_to_binary({"v1", :v2})
|
assert binary == :erlang.term_to_binary({"v1", :v2})
|
||||||
|
|
|
@ -21,7 +21,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||||
alias Pleroma.Web.OAuth.Token
|
alias Pleroma.Web.OAuth.Token
|
||||||
alias Pleroma.Web.OStatus
|
alias Pleroma.Web.OStatus
|
||||||
alias Pleroma.Web.Push
|
alias Pleroma.Web.Push
|
||||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import ExUnit.CaptureLog
|
import ExUnit.CaptureLog
|
||||||
import Tesla.Mock
|
import Tesla.Mock
|
||||||
|
@ -745,6 +744,16 @@ test "get a status", %{conn: conn} do
|
||||||
assert id == to_string(activity.id)
|
assert id == to_string(activity.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "get statuses by IDs", %{conn: conn} do
|
||||||
|
%{id: id1} = insert(:note_activity)
|
||||||
|
%{id: id2} = insert(:note_activity)
|
||||||
|
|
||||||
|
query_string = "ids[]=#{id1}&ids[]=#{id2}"
|
||||||
|
conn = get(conn, "/api/v1/statuses/?#{query_string}")
|
||||||
|
|
||||||
|
assert [%{"id" => ^id1}, %{"id" => ^id2}] = json_response(conn, :ok)
|
||||||
|
end
|
||||||
|
|
||||||
describe "deleting a status" do
|
describe "deleting a status" do
|
||||||
test "when you created it", %{conn: conn} do
|
test "when you created it", %{conn: conn} do
|
||||||
activity = insert(:note_activity)
|
activity = insert(:note_activity)
|
||||||
|
@ -1484,12 +1493,9 @@ test "gets an users media", %{conn: conn} do
|
||||||
filename: "an_image.jpg"
|
filename: "an_image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
media =
|
{:ok, %{id: media_id}} = ActivityPub.upload(file, actor: user.ap_id)
|
||||||
TwitterAPI.upload(file, user, "json")
|
|
||||||
|> Jason.decode!()
|
|
||||||
|
|
||||||
{:ok, image_post} =
|
{:ok, image_post} = CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media_id]})
|
||||||
CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]})
|
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|
@ -1675,32 +1681,85 @@ test "/api/v1/follow_requests/:id/reject works" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "account fetching", %{conn: conn} do
|
describe "account fetching" do
|
||||||
user = insert(:user)
|
test "works by id" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
build_conn()
|
||||||
|> get("/api/v1/accounts/#{user.id}")
|
|> get("/api/v1/accounts/#{user.id}")
|
||||||
|
|
||||||
assert %{"id" => id} = json_response(conn, 200)
|
assert %{"id" => id} = json_response(conn, 200)
|
||||||
assert id == to_string(user.id)
|
assert id == to_string(user.id)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
build_conn()
|
build_conn()
|
||||||
|> get("/api/v1/accounts/-1")
|
|> get("/api/v1/accounts/-1")
|
||||||
|
|
||||||
assert %{"error" => "Can't find user"} = json_response(conn, 404)
|
assert %{"error" => "Can't find user"} = json_response(conn, 404)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "account fetching also works nickname", %{conn: conn} do
|
test "works by nickname" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
build_conn()
|
||||||
|> get("/api/v1/accounts/#{user.nickname}")
|
|> get("/api/v1/accounts/#{user.nickname}")
|
||||||
|
|
||||||
assert %{"id" => id} = json_response(conn, 200)
|
assert %{"id" => id} = json_response(conn, 200)
|
||||||
assert id == user.id
|
assert id == user.id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "works by nickname for remote users" do
|
||||||
|
limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
|
||||||
|
Pleroma.Config.put([:instance, :limit_to_local_content], false)
|
||||||
|
user = insert(:user, nickname: "user@example.com", local: false)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
build_conn()
|
||||||
|
|> get("/api/v1/accounts/#{user.nickname}")
|
||||||
|
|
||||||
|
Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
|
||||||
|
assert %{"id" => id} = json_response(conn, 200)
|
||||||
|
assert id == user.id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "respects limit_to_local_content == :all for remote user nicknames" do
|
||||||
|
limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
|
||||||
|
Pleroma.Config.put([:instance, :limit_to_local_content], :all)
|
||||||
|
|
||||||
|
user = insert(:user, nickname: "user@example.com", local: false)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
build_conn()
|
||||||
|
|> get("/api/v1/accounts/#{user.nickname}")
|
||||||
|
|
||||||
|
Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
|
||||||
|
assert json_response(conn, 404)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do
|
||||||
|
limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
|
||||||
|
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||||
|
|
||||||
|
user = insert(:user, nickname: "user@example.com", local: false)
|
||||||
|
reading_user = insert(:user)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
build_conn()
|
||||||
|
|> get("/api/v1/accounts/#{user.nickname}")
|
||||||
|
|
||||||
|
assert json_response(conn, 404)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
build_conn()
|
||||||
|
|> assign(:user, reading_user)
|
||||||
|
|> get("/api/v1/accounts/#{user.nickname}")
|
||||||
|
|
||||||
|
Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
|
||||||
|
assert %{"id" => id} = json_response(conn, 200)
|
||||||
|
assert id == user.id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "mascot upload", %{conn: conn} do
|
test "mascot upload", %{conn: conn} do
|
||||||
|
|
|
@ -8,8 +8,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.ScheduledActivity
|
alias Pleroma.ScheduledActivity
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
||||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
@ -75,8 +75,9 @@ test "returns notifications for user" do
|
||||||
|
|
||||||
User.subscribe(subscriber, user)
|
User.subscribe(subscriber, user)
|
||||||
|
|
||||||
{:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
|
{:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
|
||||||
{:ok, status1} = TwitterAPI.create_status(user, %{"status" => "Magi"})
|
|
||||||
|
{:ok, status1} = CommonAPI.post(user, %{"status" => "Magi"})
|
||||||
{:ok, [notification]} = Notification.create_notifications(status)
|
{:ok, [notification]} = Notification.create_notifications(status)
|
||||||
{:ok, [notification1]} = Notification.create_notifications(status1)
|
{:ok, [notification1]} = Notification.create_notifications(status1)
|
||||||
res = MastodonAPI.get_notifications(subscriber)
|
res = MastodonAPI.get_notifications(subscriber)
|
||||||
|
|
|
@ -150,7 +150,8 @@ test "a note activity" do
|
||||||
content: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["content"])},
|
content: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["content"])},
|
||||||
spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])},
|
spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])},
|
||||||
expires_at: nil,
|
expires_at: nil,
|
||||||
direct_conversation_id: nil
|
direct_conversation_id: nil,
|
||||||
|
thread_muted: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +174,24 @@ test "tells if the message is muted for some reason" do
|
||||||
assert status.muted == true
|
assert status.muted == true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "tells if the message is thread muted" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, user} = User.mute(user, other_user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
|
||||||
|
status = StatusView.render("status.json", %{activity: activity, for: user})
|
||||||
|
|
||||||
|
assert status.pleroma.thread_muted == false
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.add_mute(user, activity)
|
||||||
|
|
||||||
|
status = StatusView.render("status.json", %{activity: activity, for: user})
|
||||||
|
|
||||||
|
assert status.pleroma.thread_muted == true
|
||||||
|
end
|
||||||
|
|
||||||
test "tells if the status is bookmarked" do
|
test "tells if the status is bookmarked" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
@ -532,6 +551,14 @@ test "detects vote status" do
|
||||||
assert Enum.at(result[:options], 1)[:votes_count] == 1
|
assert Enum.at(result[:options], 1)[:votes_count] == 1
|
||||||
assert Enum.at(result[:options], 2)[:votes_count] == 1
|
assert Enum.at(result[:options], 2)[:votes_count] == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "does not crash on polls with no end date" do
|
||||||
|
object = Object.normalize("https://skippers-bin.com/notes/7x9tmrp97i")
|
||||||
|
result = StatusView.render("poll.json", %{object: object})
|
||||||
|
|
||||||
|
assert result[:expires_at] == nil
|
||||||
|
assert result[:expired] == false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "embeds a relationship in the account" do
|
test "embeds a relationship in the account" do
|
||||||
|
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
alias Pleroma.Conversation.Participation
|
alias Pleroma.Conversation.Participation
|
||||||
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
|
@ -130,4 +131,59 @@ test "PATCH /api/v1/pleroma/conversations/:id", %{conn: conn} do
|
||||||
assert user in participation.recipients
|
assert user in participation.recipients
|
||||||
assert other_user in participation.recipients
|
assert other_user in participation.recipients
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "POST /api/v1/pleroma/notifications/read" do
|
||||||
|
test "it marks a single notification as read", %{conn: conn} do
|
||||||
|
user1 = insert(:user)
|
||||||
|
user2 = insert(:user)
|
||||||
|
{:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
|
||||||
|
{:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
|
||||||
|
{:ok, [notification1]} = Notification.create_notifications(activity1)
|
||||||
|
{:ok, [notification2]} = Notification.create_notifications(activity2)
|
||||||
|
|
||||||
|
response =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user1)
|
||||||
|
|> post("/api/v1/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
|
||||||
|
|> json_response(:ok)
|
||||||
|
|
||||||
|
assert %{"pleroma" => %{"is_seen" => true}} = response
|
||||||
|
assert Repo.get(Notification, notification1.id).seen
|
||||||
|
refute Repo.get(Notification, notification2.id).seen
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it marks multiple notifications as read", %{conn: conn} do
|
||||||
|
user1 = insert(:user)
|
||||||
|
user2 = insert(:user)
|
||||||
|
{:ok, _activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
|
||||||
|
{:ok, _activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
|
||||||
|
{:ok, _activity3} = CommonAPI.post(user2, %{"status" => "HIE @#{user1.nickname}"})
|
||||||
|
|
||||||
|
[notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
|
||||||
|
|
||||||
|
[response1, response2] =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user1)
|
||||||
|
|> post("/api/v1/pleroma/notifications/read", %{"max_id" => "#{notification2.id}"})
|
||||||
|
|> json_response(:ok)
|
||||||
|
|
||||||
|
assert %{"pleroma" => %{"is_seen" => true}} = response1
|
||||||
|
assert %{"pleroma" => %{"is_seen" => true}} = response2
|
||||||
|
assert Repo.get(Notification, notification1.id).seen
|
||||||
|
assert Repo.get(Notification, notification2.id).seen
|
||||||
|
refute Repo.get(Notification, notification3.id).seen
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it returns error when notification not found", %{conn: conn} do
|
||||||
|
user1 = insert(:user)
|
||||||
|
|
||||||
|
response =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user1)
|
||||||
|
|> post("/api/v1/pleroma/notifications/read", %{"id" => "22222222222222"})
|
||||||
|
|> json_response(:bad_request)
|
||||||
|
|
||||||
|
assert response == %{"error" => "Cannot get notification"}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
# Pleroma: A lightweight social networking server
|
|
||||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
|
|
||||||
defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do
|
|
||||||
use Pleroma.DataCase
|
|
||||||
|
|
||||||
alias Pleroma.Object
|
|
||||||
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
|
|
||||||
|
|
||||||
test "represent an image attachment" do
|
|
||||||
object = %Object{
|
|
||||||
id: 5,
|
|
||||||
data: %{
|
|
||||||
"type" => "Image",
|
|
||||||
"url" => [
|
|
||||||
%{
|
|
||||||
"mediaType" => "sometype",
|
|
||||||
"href" => "someurl"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"uuid" => 6
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
expected_object = %{
|
|
||||||
id: 6,
|
|
||||||
url: "someurl",
|
|
||||||
mimetype: "sometype",
|
|
||||||
oembed: false,
|
|
||||||
description: nil
|
|
||||||
}
|
|
||||||
|
|
||||||
assert expected_object == ObjectRepresenter.to_map(object)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "represents mastodon-style attachments" do
|
|
||||||
object = %Object{
|
|
||||||
id: nil,
|
|
||||||
data: %{
|
|
||||||
"mediaType" => "image/png",
|
|
||||||
"name" => "blabla",
|
|
||||||
"type" => "Document",
|
|
||||||
"url" =>
|
|
||||||
"http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
expected_object = %{
|
|
||||||
url:
|
|
||||||
"http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png",
|
|
||||||
mimetype: "image/png",
|
|
||||||
oembed: false,
|
|
||||||
id: nil,
|
|
||||||
description: "blabla"
|
|
||||||
}
|
|
||||||
|
|
||||||
assert expected_object == ObjectRepresenter.to_map(object)
|
|
||||||
end
|
|
||||||
end
|
|
File diff suppressed because it is too large
Load diff
|
@ -4,270 +4,17 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
alias Pleroma.Activity
|
|
||||||
alias Pleroma.Object
|
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.UserInviteToken
|
alias Pleroma.UserInviteToken
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.MastodonAPI.AccountView
|
||||||
alias Pleroma.Web.TwitterAPI.ActivityView
|
|
||||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||||
alias Pleroma.Web.TwitterAPI.UserView
|
|
||||||
|
|
||||||
import Pleroma.Factory
|
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
test "create a status" do
|
|
||||||
user = insert(:user)
|
|
||||||
mentioned_user = insert(:user, %{nickname: "shp", ap_id: "shp"})
|
|
||||||
|
|
||||||
object_data = %{
|
|
||||||
"type" => "Image",
|
|
||||||
"url" => [
|
|
||||||
%{
|
|
||||||
"type" => "Link",
|
|
||||||
"mediaType" => "image/jpg",
|
|
||||||
"href" => "http://example.org/image.jpg"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"uuid" => 1
|
|
||||||
}
|
|
||||||
|
|
||||||
object = Repo.insert!(%Object{data: object_data})
|
|
||||||
|
|
||||||
input = %{
|
|
||||||
"status" =>
|
|
||||||
"Hello again, @shp.<script></script>\nThis is on another :firefox: line. #2hu #epic #phantasmagoric",
|
|
||||||
"media_ids" => [object.id]
|
|
||||||
}
|
|
||||||
|
|
||||||
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
|
|
||||||
object = Object.normalize(activity)
|
|
||||||
|
|
||||||
expected_text =
|
|
||||||
"Hello again, <span class='h-card'><a data-user='#{mentioned_user.id}' class='u-url mention' href='shp'>@<span>shp</span></a></span>.<script></script><br>This is on another :firefox: line. <a class='hashtag' data-tag='2hu' href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a class='hashtag' data-tag='epic' href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a class='hashtag' data-tag='phantasmagoric' href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
|
|
||||||
|
|
||||||
assert get_in(object.data, ["content"]) == expected_text
|
|
||||||
assert get_in(object.data, ["type"]) == "Note"
|
|
||||||
assert get_in(object.data, ["actor"]) == user.ap_id
|
|
||||||
assert get_in(activity.data, ["actor"]) == user.ap_id
|
|
||||||
assert Enum.member?(get_in(activity.data, ["cc"]), User.ap_followers(user))
|
|
||||||
|
|
||||||
assert Enum.member?(
|
|
||||||
get_in(activity.data, ["to"]),
|
|
||||||
"https://www.w3.org/ns/activitystreams#Public"
|
|
||||||
)
|
|
||||||
|
|
||||||
assert Enum.member?(get_in(activity.data, ["to"]), "shp")
|
|
||||||
assert activity.local == true
|
|
||||||
|
|
||||||
assert %{"firefox" => "http://localhost:4001/emoji/Firefox.gif"} = object.data["emoji"]
|
|
||||||
|
|
||||||
# hashtags
|
|
||||||
assert object.data["tag"] == ["2hu", "epic", "phantasmagoric"]
|
|
||||||
|
|
||||||
# Add a context
|
|
||||||
assert is_binary(get_in(activity.data, ["context"]))
|
|
||||||
assert is_binary(get_in(object.data, ["context"]))
|
|
||||||
|
|
||||||
assert is_list(object.data["attachment"])
|
|
||||||
|
|
||||||
assert activity.data["object"] == object.data["id"]
|
|
||||||
|
|
||||||
user = User.get_cached_by_ap_id(user.ap_id)
|
|
||||||
|
|
||||||
assert user.info.note_count == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
test "create a status that is a reply" do
|
|
||||||
user = insert(:user)
|
|
||||||
|
|
||||||
input = %{
|
|
||||||
"status" => "Hello again."
|
|
||||||
}
|
|
||||||
|
|
||||||
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
|
|
||||||
object = Object.normalize(activity)
|
|
||||||
|
|
||||||
input = %{
|
|
||||||
"status" => "Here's your (you).",
|
|
||||||
"in_reply_to_status_id" => activity.id
|
|
||||||
}
|
|
||||||
|
|
||||||
{:ok, reply = %Activity{}} = TwitterAPI.create_status(user, input)
|
|
||||||
reply_object = Object.normalize(reply)
|
|
||||||
|
|
||||||
assert get_in(reply.data, ["context"]) == get_in(activity.data, ["context"])
|
|
||||||
|
|
||||||
assert get_in(reply_object.data, ["context"]) == get_in(object.data, ["context"])
|
|
||||||
|
|
||||||
assert get_in(reply_object.data, ["inReplyTo"]) == get_in(activity.data, ["object"])
|
|
||||||
assert Activity.get_in_reply_to_activity(reply).id == activity.id
|
|
||||||
end
|
|
||||||
|
|
||||||
test "Follow another user using user_id" do
|
|
||||||
user = insert(:user)
|
|
||||||
followed = insert(:user)
|
|
||||||
|
|
||||||
{:ok, user, followed, _activity} = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
|
||||||
assert User.ap_followers(followed) in user.following
|
|
||||||
|
|
||||||
{:ok, _, _, _} = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
|
||||||
end
|
|
||||||
|
|
||||||
test "Follow another user using screen_name" do
|
|
||||||
user = insert(:user)
|
|
||||||
followed = insert(:user)
|
|
||||||
|
|
||||||
{:ok, user, followed, _activity} =
|
|
||||||
TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
|
||||||
|
|
||||||
assert User.ap_followers(followed) in user.following
|
|
||||||
|
|
||||||
followed = User.get_cached_by_ap_id(followed.ap_id)
|
|
||||||
assert followed.info.follower_count == 1
|
|
||||||
|
|
||||||
{:ok, _, _, _} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
|
||||||
end
|
|
||||||
|
|
||||||
test "Unfollow another user using user_id" do
|
|
||||||
unfollowed = insert(:user)
|
|
||||||
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
|
|
||||||
ActivityPub.follow(user, unfollowed)
|
|
||||||
|
|
||||||
{:ok, user, unfollowed} = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
|
||||||
assert user.following == []
|
|
||||||
|
|
||||||
{:error, msg} = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
|
||||||
assert msg == "Not subscribed!"
|
|
||||||
end
|
|
||||||
|
|
||||||
test "Unfollow another user using screen_name" do
|
|
||||||
unfollowed = insert(:user)
|
|
||||||
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
|
|
||||||
|
|
||||||
ActivityPub.follow(user, unfollowed)
|
|
||||||
|
|
||||||
{:ok, user, unfollowed} = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
|
||||||
assert user.following == []
|
|
||||||
|
|
||||||
{:error, msg} = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
|
||||||
assert msg == "Not subscribed!"
|
|
||||||
end
|
|
||||||
|
|
||||||
test "Block another user using user_id" do
|
|
||||||
user = insert(:user)
|
|
||||||
blocked = insert(:user)
|
|
||||||
|
|
||||||
{:ok, user, blocked} = TwitterAPI.block(user, %{"user_id" => blocked.id})
|
|
||||||
assert User.blocks?(user, blocked)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "Block another user using screen_name" do
|
|
||||||
user = insert(:user)
|
|
||||||
blocked = insert(:user)
|
|
||||||
|
|
||||||
{:ok, user, blocked} = TwitterAPI.block(user, %{"screen_name" => blocked.nickname})
|
|
||||||
assert User.blocks?(user, blocked)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "Unblock another user using user_id" do
|
|
||||||
unblocked = insert(:user)
|
|
||||||
user = insert(:user)
|
|
||||||
{:ok, user, _unblocked} = TwitterAPI.block(user, %{"user_id" => unblocked.id})
|
|
||||||
|
|
||||||
{:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"user_id" => unblocked.id})
|
|
||||||
assert user.info.blocks == []
|
|
||||||
end
|
|
||||||
|
|
||||||
test "Unblock another user using screen_name" do
|
|
||||||
unblocked = insert(:user)
|
|
||||||
user = insert(:user)
|
|
||||||
{:ok, user, _unblocked} = TwitterAPI.block(user, %{"screen_name" => unblocked.nickname})
|
|
||||||
|
|
||||||
{:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"screen_name" => unblocked.nickname})
|
|
||||||
assert user.info.blocks == []
|
|
||||||
end
|
|
||||||
|
|
||||||
test "upload a file" do
|
|
||||||
user = insert(:user)
|
|
||||||
|
|
||||||
file = %Plug.Upload{
|
|
||||||
content_type: "image/jpg",
|
|
||||||
path: Path.absname("test/fixtures/image.jpg"),
|
|
||||||
filename: "an_image.jpg"
|
|
||||||
}
|
|
||||||
|
|
||||||
response = TwitterAPI.upload(file, user)
|
|
||||||
|
|
||||||
assert is_binary(response)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it favorites a status, returns the updated activity" do
|
|
||||||
user = insert(:user)
|
|
||||||
other_user = insert(:user)
|
|
||||||
note_activity = insert(:note_activity)
|
|
||||||
|
|
||||||
{:ok, status} = TwitterAPI.fav(user, note_activity.id)
|
|
||||||
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
|
|
||||||
assert ActivityView.render("activity.json", %{activity: updated_activity})["fave_num"] == 1
|
|
||||||
|
|
||||||
object = Object.normalize(note_activity)
|
|
||||||
|
|
||||||
assert object.data["like_count"] == 1
|
|
||||||
|
|
||||||
assert status == updated_activity
|
|
||||||
|
|
||||||
{:ok, _status} = TwitterAPI.fav(other_user, note_activity.id)
|
|
||||||
|
|
||||||
object = Object.normalize(note_activity)
|
|
||||||
|
|
||||||
assert object.data["like_count"] == 2
|
|
||||||
|
|
||||||
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
|
|
||||||
assert ActivityView.render("activity.json", %{activity: updated_activity})["fave_num"] == 2
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it unfavorites a status, returns the updated activity" do
|
|
||||||
user = insert(:user)
|
|
||||||
note_activity = insert(:note_activity)
|
|
||||||
object = Object.normalize(note_activity)
|
|
||||||
|
|
||||||
{:ok, _like_activity, _object} = ActivityPub.like(user, object)
|
|
||||||
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
|
|
||||||
|
|
||||||
assert ActivityView.render("activity.json", activity: updated_activity)["fave_num"] == 1
|
|
||||||
|
|
||||||
{:ok, activity} = TwitterAPI.unfav(user, note_activity.id)
|
|
||||||
|
|
||||||
assert ActivityView.render("activity.json", activity: activity)["fave_num"] == 0
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it retweets a status and returns the retweet" do
|
|
||||||
user = insert(:user)
|
|
||||||
note_activity = insert(:note_activity)
|
|
||||||
|
|
||||||
{:ok, status} = TwitterAPI.repeat(user, note_activity.id)
|
|
||||||
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
|
|
||||||
|
|
||||||
assert status == updated_activity
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it unretweets an already retweeted status" do
|
|
||||||
user = insert(:user)
|
|
||||||
note_activity = insert(:note_activity)
|
|
||||||
|
|
||||||
{:ok, _status} = TwitterAPI.repeat(user, note_activity.id)
|
|
||||||
{:ok, status} = TwitterAPI.unrepeat(user, note_activity.id)
|
|
||||||
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
|
|
||||||
|
|
||||||
assert status == updated_activity
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it registers a new user and returns the user." do
|
test "it registers a new user and returns the user." do
|
||||||
data = %{
|
data = %{
|
||||||
"nickname" => "lain",
|
"nickname" => "lain",
|
||||||
|
@ -281,8 +28,8 @@ test "it registers a new user and returns the user." do
|
||||||
|
|
||||||
fetched_user = User.get_cached_by_nickname("lain")
|
fetched_user = User.get_cached_by_nickname("lain")
|
||||||
|
|
||||||
assert UserView.render("show.json", %{user: user}) ==
|
assert AccountView.render("account.json", %{user: user}) ==
|
||||||
UserView.render("show.json", %{user: fetched_user})
|
AccountView.render("account.json", %{user: fetched_user})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it registers a new user with empty string in bio and returns the user." do
|
test "it registers a new user with empty string in bio and returns the user." do
|
||||||
|
@ -299,8 +46,8 @@ test "it registers a new user with empty string in bio and returns the user." do
|
||||||
|
|
||||||
fetched_user = User.get_cached_by_nickname("lain")
|
fetched_user = User.get_cached_by_nickname("lain")
|
||||||
|
|
||||||
assert UserView.render("show.json", %{user: user}) ==
|
assert AccountView.render("account.json", %{user: user}) ==
|
||||||
UserView.render("show.json", %{user: fetched_user})
|
AccountView.render("account.json", %{user: fetched_user})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it sends confirmation email if :account_activation_required is specified in instance config" do
|
test "it sends confirmation email if :account_activation_required is specified in instance config" do
|
||||||
|
@ -397,8 +144,8 @@ test "returns user on success" do
|
||||||
|
|
||||||
assert invite.used == true
|
assert invite.used == true
|
||||||
|
|
||||||
assert UserView.render("show.json", %{user: user}) ==
|
assert AccountView.render("account.json", %{user: user}) ==
|
||||||
UserView.render("show.json", %{user: fetched_user})
|
AccountView.render("account.json", %{user: fetched_user})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns error on invalid token" do
|
test "returns error on invalid token" do
|
||||||
|
@ -462,8 +209,8 @@ test "returns error on expired token" do
|
||||||
{:ok, user} = TwitterAPI.register_user(data)
|
{:ok, user} = TwitterAPI.register_user(data)
|
||||||
fetched_user = User.get_cached_by_nickname("vinny")
|
fetched_user = User.get_cached_by_nickname("vinny")
|
||||||
|
|
||||||
assert UserView.render("show.json", %{user: user}) ==
|
assert AccountView.render("account.json", %{user: user}) ==
|
||||||
UserView.render("show.json", %{user: fetched_user})
|
AccountView.render("account.json", %{user: fetched_user})
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok, data: data, check_fn: check_fn}
|
{:ok, data: data, check_fn: check_fn}
|
||||||
|
@ -537,8 +284,8 @@ test "returns user on success, after him registration fails" do
|
||||||
|
|
||||||
assert invite.used == true
|
assert invite.used == true
|
||||||
|
|
||||||
assert UserView.render("show.json", %{user: user}) ==
|
assert AccountView.render("account.json", %{user: user}) ==
|
||||||
UserView.render("show.json", %{user: fetched_user})
|
AccountView.render("account.json", %{user: fetched_user})
|
||||||
|
|
||||||
data = %{
|
data = %{
|
||||||
"nickname" => "GrimReaper",
|
"nickname" => "GrimReaper",
|
||||||
|
@ -588,8 +335,8 @@ test "returns user on success" do
|
||||||
|
|
||||||
refute invite.used
|
refute invite.used
|
||||||
|
|
||||||
assert UserView.render("show.json", %{user: user}) ==
|
assert AccountView.render("account.json", %{user: user}) ==
|
||||||
UserView.render("show.json", %{user: fetched_user})
|
AccountView.render("account.json", %{user: fetched_user})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "error after max uses" do
|
test "error after max uses" do
|
||||||
|
@ -612,8 +359,8 @@ test "error after max uses" do
|
||||||
invite = Repo.get_by(UserInviteToken, token: invite.token)
|
invite = Repo.get_by(UserInviteToken, token: invite.token)
|
||||||
assert invite.used == true
|
assert invite.used == true
|
||||||
|
|
||||||
assert UserView.render("show.json", %{user: user}) ==
|
assert AccountView.render("account.json", %{user: user}) ==
|
||||||
UserView.render("show.json", %{user: fetched_user})
|
AccountView.render("account.json", %{user: fetched_user})
|
||||||
|
|
||||||
data = %{
|
data = %{
|
||||||
"nickname" => "GrimReaper",
|
"nickname" => "GrimReaper",
|
||||||
|
@ -689,31 +436,9 @@ test "it returns the error on registration problems" do
|
||||||
refute User.get_cached_by_nickname("lain")
|
refute User.get_cached_by_nickname("lain")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it assigns an integer conversation_id" do
|
|
||||||
note_activity = insert(:note_activity)
|
|
||||||
status = ActivityView.render("activity.json", activity: note_activity)
|
|
||||||
|
|
||||||
assert is_number(status["statusnet_conversation_id"])
|
|
||||||
end
|
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
Supervisor.terminate_child(Pleroma.Supervisor, Cachex)
|
Supervisor.terminate_child(Pleroma.Supervisor, Cachex)
|
||||||
Supervisor.restart_child(Pleroma.Supervisor, Cachex)
|
Supervisor.restart_child(Pleroma.Supervisor, Cachex)
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "fetching a user by uri" do
|
|
||||||
test "fetches a user by uri" do
|
|
||||||
id = "https://mastodon.social/users/lambadalambda"
|
|
||||||
user = insert(:user)
|
|
||||||
{:ok, represented} = TwitterAPI.get_external_profile(user, id)
|
|
||||||
remote = User.get_cached_by_ap_id(id)
|
|
||||||
|
|
||||||
assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"]
|
|
||||||
|
|
||||||
# Also fetches the feed.
|
|
||||||
# assert Activity.get_create_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status")
|
|
||||||
# credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
alias Pleroma.Notification
|
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
@ -141,37 +140,6 @@ test "it imports blocks users from file", %{conn: conn} do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "POST /api/pleroma/notifications/read" do
|
|
||||||
test "it marks a single notification as read", %{conn: conn} do
|
|
||||||
user1 = insert(:user)
|
|
||||||
user2 = insert(:user)
|
|
||||||
{:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
|
|
||||||
{:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
|
|
||||||
{:ok, [notification1]} = Notification.create_notifications(activity1)
|
|
||||||
{:ok, [notification2]} = Notification.create_notifications(activity2)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> assign(:user, user1)
|
|
||||||
|> post("/api/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
|
|
||||||
|> json_response(:ok)
|
|
||||||
|
|
||||||
assert Repo.get(Notification, notification1.id).seen
|
|
||||||
refute Repo.get(Notification, notification2.id).seen
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it returns error when notification not found", %{conn: conn} do
|
|
||||||
user1 = insert(:user)
|
|
||||||
|
|
||||||
response =
|
|
||||||
conn
|
|
||||||
|> assign(:user, user1)
|
|
||||||
|> post("/api/pleroma/notifications/read", %{"id" => "22222222222222"})
|
|
||||||
|> json_response(403)
|
|
||||||
|
|
||||||
assert response == %{"error" => "Cannot get notification"}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "PUT /api/pleroma/notification_settings" do
|
describe "PUT /api/pleroma/notification_settings" do
|
||||||
test "it updates notification settings", %{conn: conn} do
|
test "it updates notification settings", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
@ -694,4 +662,111 @@ test "it returns new captcha", %{conn: conn} do
|
||||||
assert called(Pleroma.Captcha.new())
|
assert called(Pleroma.Captcha.new())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp with_credentials(conn, username, password) do
|
||||||
|
header_content = "Basic " <> Base.encode64("#{username}:#{password}")
|
||||||
|
put_req_header(conn, "authorization", header_content)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp valid_user(_context) do
|
||||||
|
user = insert(:user)
|
||||||
|
[user: user]
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "POST /api/pleroma/change_email" do
|
||||||
|
setup [:valid_user]
|
||||||
|
|
||||||
|
test "without credentials", %{conn: conn} do
|
||||||
|
conn = post(conn, "/api/pleroma/change_email")
|
||||||
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with credentials and invalid password", %{conn: conn, user: current_user} do
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> with_credentials(current_user.nickname, "test")
|
||||||
|
|> post("/api/pleroma/change_email", %{
|
||||||
|
"password" => "hi",
|
||||||
|
"email" => "test@test.com"
|
||||||
|
})
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == %{"error" => "Invalid password."}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with credentials, valid password and invalid email", %{
|
||||||
|
conn: conn,
|
||||||
|
user: current_user
|
||||||
|
} do
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> with_credentials(current_user.nickname, "test")
|
||||||
|
|> post("/api/pleroma/change_email", %{
|
||||||
|
"password" => "test",
|
||||||
|
"email" => "foobar"
|
||||||
|
})
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == %{"error" => "Email has invalid format."}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with credentials, valid password and no email", %{
|
||||||
|
conn: conn,
|
||||||
|
user: current_user
|
||||||
|
} do
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> with_credentials(current_user.nickname, "test")
|
||||||
|
|> post("/api/pleroma/change_email", %{
|
||||||
|
"password" => "test"
|
||||||
|
})
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == %{"error" => "Email can't be blank."}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with credentials, valid password and blank email", %{
|
||||||
|
conn: conn,
|
||||||
|
user: current_user
|
||||||
|
} do
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> with_credentials(current_user.nickname, "test")
|
||||||
|
|> post("/api/pleroma/change_email", %{
|
||||||
|
"password" => "test",
|
||||||
|
"email" => ""
|
||||||
|
})
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == %{"error" => "Email can't be blank."}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with credentials, valid password and non unique email", %{
|
||||||
|
conn: conn,
|
||||||
|
user: current_user
|
||||||
|
} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> with_credentials(current_user.nickname, "test")
|
||||||
|
|> post("/api/pleroma/change_email", %{
|
||||||
|
"password" => "test",
|
||||||
|
"email" => user.email
|
||||||
|
})
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == %{"error" => "Email has already been taken."}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with credentials, valid password and valid email", %{
|
||||||
|
conn: conn,
|
||||||
|
user: current_user
|
||||||
|
} do
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> with_credentials(current_user.nickname, "test")
|
||||||
|
|> post("/api/pleroma/change_email", %{
|
||||||
|
"password" => "test",
|
||||||
|
"email" => "cofe@foobar.com"
|
||||||
|
})
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == %{"status" => "success"}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,384 +0,0 @@
|
||||||
# Pleroma: A lightweight social networking server
|
|
||||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
|
|
||||||
defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
|
|
||||||
use Pleroma.DataCase
|
|
||||||
|
|
||||||
alias Pleroma.Activity
|
|
||||||
alias Pleroma.Object
|
|
||||||
alias Pleroma.Repo
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
||||||
alias Pleroma.Web.CommonAPI
|
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
|
||||||
alias Pleroma.Web.TwitterAPI.ActivityView
|
|
||||||
alias Pleroma.Web.TwitterAPI.UserView
|
|
||||||
|
|
||||||
import Pleroma.Factory
|
|
||||||
import Tesla.Mock
|
|
||||||
|
|
||||||
setup do
|
|
||||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
import Mock
|
|
||||||
|
|
||||||
test "returns a temporary ap_id based user for activities missing db users" do
|
|
||||||
user = insert(:user)
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
|
|
||||||
|
|
||||||
Repo.delete(user)
|
|
||||||
Cachex.clear(:user_cache)
|
|
||||||
|
|
||||||
%{"user" => tw_user} = ActivityView.render("activity.json", activity: activity)
|
|
||||||
|
|
||||||
assert tw_user["screen_name"] == "erroruser@example.com"
|
|
||||||
assert tw_user["name"] == user.ap_id
|
|
||||||
assert tw_user["statusnet_profile_url"] == user.ap_id
|
|
||||||
end
|
|
||||||
|
|
||||||
test "tries to get a user by nickname if fetching by ap_id doesn't work" do
|
|
||||||
user = insert(:user)
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
|
|
||||||
|
|
||||||
{:ok, user} =
|
|
||||||
user
|
|
||||||
|> Ecto.Changeset.change(%{ap_id: "#{user.ap_id}/extension/#{user.nickname}"})
|
|
||||||
|> Repo.update()
|
|
||||||
|
|
||||||
Cachex.clear(:user_cache)
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", activity: activity)
|
|
||||||
assert result["user"]["id"] == user.id
|
|
||||||
end
|
|
||||||
|
|
||||||
test "tells if the message is muted for some reason" do
|
|
||||||
user = insert(:user)
|
|
||||||
other_user = insert(:user)
|
|
||||||
|
|
||||||
{:ok, user} = User.mute(user, other_user)
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
|
|
||||||
status = ActivityView.render("activity.json", %{activity: activity})
|
|
||||||
|
|
||||||
assert status["muted"] == false
|
|
||||||
|
|
||||||
status = ActivityView.render("activity.json", %{activity: activity, for: user})
|
|
||||||
|
|
||||||
assert status["muted"] == true
|
|
||||||
end
|
|
||||||
|
|
||||||
test "a create activity with a html status" do
|
|
||||||
text = """
|
|
||||||
#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg
|
|
||||||
"""
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(insert(:user), %{"status" => text})
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", activity: activity)
|
|
||||||
|
|
||||||
assert result["statusnet_html"] ==
|
|
||||||
"<a class=\"hashtag\" data-tag=\"bike\" href=\"http://localhost:4001/tag/bike\" rel=\"tag\">#Bike</a> log - Commute Tuesday<br /><a href=\"https://pla.bike/posts/20181211/\">https://pla.bike/posts/20181211/</a><br /><a class=\"hashtag\" data-tag=\"cycling\" href=\"http://localhost:4001/tag/cycling\" rel=\"tag\">#cycling</a> <a class=\"hashtag\" data-tag=\"chscycling\" href=\"http://localhost:4001/tag/chscycling\" rel=\"tag\">#CHScycling</a> <a class=\"hashtag\" data-tag=\"commute\" href=\"http://localhost:4001/tag/commute\" rel=\"tag\">#commute</a><br />MVIMG_20181211_054020.jpg"
|
|
||||||
|
|
||||||
assert result["text"] ==
|
|
||||||
"#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg"
|
|
||||||
end
|
|
||||||
|
|
||||||
test "a create activity with a summary containing emoji" do
|
|
||||||
{:ok, activity} =
|
|
||||||
CommonAPI.post(insert(:user), %{
|
|
||||||
"spoiler_text" => ":firefox: meow",
|
|
||||||
"status" => "."
|
|
||||||
})
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", activity: activity)
|
|
||||||
|
|
||||||
expected = ":firefox: meow"
|
|
||||||
|
|
||||||
expected_html =
|
|
||||||
"<img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"http://localhost:4001/emoji/Firefox.gif\" /> meow"
|
|
||||||
|
|
||||||
assert result["summary"] == expected
|
|
||||||
assert result["summary_html"] == expected_html
|
|
||||||
end
|
|
||||||
|
|
||||||
test "a create activity with a summary containing invalid HTML" do
|
|
||||||
{:ok, activity} =
|
|
||||||
CommonAPI.post(insert(:user), %{
|
|
||||||
"spoiler_text" => "<span style=\"color: magenta; font-size: 32px;\">meow</span>",
|
|
||||||
"status" => "."
|
|
||||||
})
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", activity: activity)
|
|
||||||
|
|
||||||
expected = "meow"
|
|
||||||
|
|
||||||
assert result["summary"] == expected
|
|
||||||
assert result["summary_html"] == expected
|
|
||||||
end
|
|
||||||
|
|
||||||
test "a create activity with a note" do
|
|
||||||
user = insert(:user)
|
|
||||||
other_user = insert(:user, %{nickname: "shp"})
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
|
|
||||||
object = Object.normalize(activity)
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", activity: activity)
|
|
||||||
|
|
||||||
convo_id = Utils.context_to_conversation_id(object.data["context"])
|
|
||||||
|
|
||||||
expected = %{
|
|
||||||
"activity_type" => "post",
|
|
||||||
"attachments" => [],
|
|
||||||
"attentions" => [
|
|
||||||
UserView.render("show.json", %{user: other_user})
|
|
||||||
],
|
|
||||||
"created_at" => object.data["published"] |> Utils.date_to_asctime(),
|
|
||||||
"external_url" => object.data["id"],
|
|
||||||
"fave_num" => 0,
|
|
||||||
"favorited" => false,
|
|
||||||
"id" => activity.id,
|
|
||||||
"in_reply_to_status_id" => nil,
|
|
||||||
"in_reply_to_screen_name" => nil,
|
|
||||||
"in_reply_to_user_id" => nil,
|
|
||||||
"in_reply_to_profileurl" => nil,
|
|
||||||
"in_reply_to_ostatus_uri" => nil,
|
|
||||||
"is_local" => true,
|
|
||||||
"is_post_verb" => true,
|
|
||||||
"possibly_sensitive" => false,
|
|
||||||
"repeat_num" => 0,
|
|
||||||
"repeated" => false,
|
|
||||||
"pinned" => false,
|
|
||||||
"statusnet_conversation_id" => convo_id,
|
|
||||||
"summary" => "",
|
|
||||||
"summary_html" => "",
|
|
||||||
"statusnet_html" =>
|
|
||||||
"Hey <span class=\"h-card\"><a data-user=\"#{other_user.id}\" class=\"u-url mention\" href=\"#{
|
|
||||||
other_user.ap_id
|
|
||||||
}\">@<span>shp</span></a></span>!",
|
|
||||||
"tags" => [],
|
|
||||||
"text" => "Hey @shp!",
|
|
||||||
"uri" => object.data["id"],
|
|
||||||
"user" => UserView.render("show.json", %{user: user}),
|
|
||||||
"visibility" => "direct",
|
|
||||||
"card" => nil,
|
|
||||||
"muted" => false
|
|
||||||
}
|
|
||||||
|
|
||||||
assert result == expected
|
|
||||||
end
|
|
||||||
|
|
||||||
test "a list of activities" do
|
|
||||||
user = insert(:user)
|
|
||||||
other_user = insert(:user, %{nickname: "shp"})
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
|
||||||
object = Object.normalize(activity)
|
|
||||||
|
|
||||||
convo_id = Utils.context_to_conversation_id(object.data["context"])
|
|
||||||
|
|
||||||
mocks = [
|
|
||||||
{
|
|
||||||
Utils,
|
|
||||||
[:passthrough],
|
|
||||||
[context_to_conversation_id: fn _ -> false end]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
User,
|
|
||||||
[:passthrough],
|
|
||||||
[get_cached_by_ap_id: fn _ -> nil end]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
with_mocks mocks do
|
|
||||||
[result] = ActivityView.render("index.json", activities: [activity])
|
|
||||||
|
|
||||||
assert result["statusnet_conversation_id"] == convo_id
|
|
||||||
assert result["user"]
|
|
||||||
refute called(Utils.context_to_conversation_id(:_))
|
|
||||||
refute called(User.get_cached_by_ap_id(user.ap_id))
|
|
||||||
refute called(User.get_cached_by_ap_id(other_user.ap_id))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "an activity that is a reply" do
|
|
||||||
user = insert(:user)
|
|
||||||
other_user = insert(:user, %{nickname: "shp"})
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
|
||||||
|
|
||||||
{:ok, answer} =
|
|
||||||
CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", %{activity: answer})
|
|
||||||
|
|
||||||
assert result["in_reply_to_status_id"] == activity.id
|
|
||||||
end
|
|
||||||
|
|
||||||
test "a like activity" do
|
|
||||||
user = insert(:user)
|
|
||||||
other_user = insert(:user, %{nickname: "shp"})
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
|
||||||
{:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", activity: like)
|
|
||||||
activity = Pleroma.Activity.get_by_ap_id(activity.data["id"])
|
|
||||||
|
|
||||||
expected = %{
|
|
||||||
"activity_type" => "like",
|
|
||||||
"created_at" => like.data["published"] |> Utils.date_to_asctime(),
|
|
||||||
"external_url" => like.data["id"],
|
|
||||||
"id" => like.id,
|
|
||||||
"in_reply_to_status_id" => activity.id,
|
|
||||||
"is_local" => true,
|
|
||||||
"is_post_verb" => false,
|
|
||||||
"favorited_status" => ActivityView.render("activity.json", activity: activity),
|
|
||||||
"statusnet_html" => "shp favorited a status.",
|
|
||||||
"text" => "shp favorited a status.",
|
|
||||||
"uri" => "tag:#{like.data["id"]}:objectType=Favourite",
|
|
||||||
"user" => UserView.render("show.json", user: other_user)
|
|
||||||
}
|
|
||||||
|
|
||||||
assert result == expected
|
|
||||||
end
|
|
||||||
|
|
||||||
test "a like activity for deleted post" do
|
|
||||||
user = insert(:user)
|
|
||||||
other_user = insert(:user, %{nickname: "shp"})
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
|
||||||
{:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
|
|
||||||
CommonAPI.delete(activity.id, user)
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", activity: like)
|
|
||||||
|
|
||||||
expected = %{
|
|
||||||
"activity_type" => "like",
|
|
||||||
"created_at" => like.data["published"] |> Utils.date_to_asctime(),
|
|
||||||
"external_url" => like.data["id"],
|
|
||||||
"id" => like.id,
|
|
||||||
"in_reply_to_status_id" => nil,
|
|
||||||
"is_local" => true,
|
|
||||||
"is_post_verb" => false,
|
|
||||||
"favorited_status" => nil,
|
|
||||||
"statusnet_html" => "shp favorited a status.",
|
|
||||||
"text" => "shp favorited a status.",
|
|
||||||
"uri" => "tag:#{like.data["id"]}:objectType=Favourite",
|
|
||||||
"user" => UserView.render("show.json", user: other_user)
|
|
||||||
}
|
|
||||||
|
|
||||||
assert result == expected
|
|
||||||
end
|
|
||||||
|
|
||||||
test "an announce activity" do
|
|
||||||
user = insert(:user)
|
|
||||||
other_user = insert(:user, %{nickname: "shp"})
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
|
||||||
{:ok, announce, object} = CommonAPI.repeat(activity.id, other_user)
|
|
||||||
|
|
||||||
convo_id = Utils.context_to_conversation_id(object.data["context"])
|
|
||||||
|
|
||||||
activity = Activity.get_by_id(activity.id)
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", activity: announce)
|
|
||||||
|
|
||||||
expected = %{
|
|
||||||
"activity_type" => "repeat",
|
|
||||||
"created_at" => announce.data["published"] |> Utils.date_to_asctime(),
|
|
||||||
"external_url" => announce.data["id"],
|
|
||||||
"id" => announce.id,
|
|
||||||
"is_local" => true,
|
|
||||||
"is_post_verb" => false,
|
|
||||||
"statusnet_html" => "shp repeated a status.",
|
|
||||||
"text" => "shp repeated a status.",
|
|
||||||
"uri" => "tag:#{announce.data["id"]}:objectType=note",
|
|
||||||
"user" => UserView.render("show.json", user: other_user),
|
|
||||||
"retweeted_status" => ActivityView.render("activity.json", activity: activity),
|
|
||||||
"statusnet_conversation_id" => convo_id
|
|
||||||
}
|
|
||||||
|
|
||||||
assert result == expected
|
|
||||||
end
|
|
||||||
|
|
||||||
test "A follow activity" do
|
|
||||||
user = insert(:user)
|
|
||||||
other_user = insert(:user, %{nickname: "shp"})
|
|
||||||
|
|
||||||
{:ok, follower} = User.follow(user, other_user)
|
|
||||||
{:ok, follow} = ActivityPub.follow(follower, other_user)
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", activity: follow)
|
|
||||||
|
|
||||||
expected = %{
|
|
||||||
"activity_type" => "follow",
|
|
||||||
"attentions" => [],
|
|
||||||
"created_at" => follow.data["published"] |> Utils.date_to_asctime(),
|
|
||||||
"external_url" => follow.data["id"],
|
|
||||||
"id" => follow.id,
|
|
||||||
"in_reply_to_status_id" => nil,
|
|
||||||
"is_local" => true,
|
|
||||||
"is_post_verb" => false,
|
|
||||||
"statusnet_html" => "#{user.nickname} started following shp",
|
|
||||||
"text" => "#{user.nickname} started following shp",
|
|
||||||
"user" => UserView.render("show.json", user: user)
|
|
||||||
}
|
|
||||||
|
|
||||||
assert result == expected
|
|
||||||
end
|
|
||||||
|
|
||||||
test "a delete activity" do
|
|
||||||
user = insert(:user)
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
|
||||||
{:ok, delete} = CommonAPI.delete(activity.id, user)
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", activity: delete)
|
|
||||||
|
|
||||||
expected = %{
|
|
||||||
"activity_type" => "delete",
|
|
||||||
"attentions" => [],
|
|
||||||
"created_at" => delete.data["published"] |> Utils.date_to_asctime(),
|
|
||||||
"external_url" => delete.data["id"],
|
|
||||||
"id" => delete.id,
|
|
||||||
"in_reply_to_status_id" => nil,
|
|
||||||
"is_local" => true,
|
|
||||||
"is_post_verb" => false,
|
|
||||||
"statusnet_html" => "deleted notice {{tag",
|
|
||||||
"text" => "deleted notice {{tag",
|
|
||||||
"uri" => Object.normalize(delete).data["id"],
|
|
||||||
"user" => UserView.render("show.json", user: user)
|
|
||||||
}
|
|
||||||
|
|
||||||
assert result == expected
|
|
||||||
end
|
|
||||||
|
|
||||||
test "a peertube video" do
|
|
||||||
{:ok, object} =
|
|
||||||
Pleroma.Object.Fetcher.fetch_object_from_id(
|
|
||||||
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
|
|
||||||
)
|
|
||||||
|
|
||||||
%Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"])
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", activity: activity)
|
|
||||||
|
|
||||||
assert length(result["attachments"]) == 1
|
|
||||||
assert result["summary"] == "Friday Night"
|
|
||||||
end
|
|
||||||
|
|
||||||
test "special characters are not escaped in text field for status created" do
|
|
||||||
text = "<3 is on the way"
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(insert(:user), %{"status" => text})
|
|
||||||
|
|
||||||
result = ActivityView.render("activity.json", activity: activity)
|
|
||||||
|
|
||||||
assert result["text"] == text
|
|
||||||
end
|
|
||||||
end
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue