aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md12
-rw-r--r--COPYING7
-rw-r--r--config/config.exs10
-rw-r--r--docs/api/differences_in_mastoapi_responses.md2
-rw-r--r--docs/api/pleroma_api.md75
-rw-r--r--docs/config.md7
-rw-r--r--docs/config/custom_emoji.md25
-rw-r--r--docs/installation/gentoo_en.md296
-rw-r--r--lib/healthcheck.ex60
-rw-r--r--lib/mix/tasks/pleroma/database.ex51
-rw-r--r--lib/mix/tasks/pleroma/emoji.ex293
-rw-r--r--lib/mix/tasks/pleroma/user.ex20
-rw-r--r--lib/pleroma/PasswordResetToken.ex2
-rw-r--r--lib/pleroma/activity.ex79
-rw-r--r--lib/pleroma/emoji.ex165
-rw-r--r--lib/pleroma/gopher/server.ex5
-rw-r--r--lib/pleroma/html.ex3
-rw-r--r--lib/pleroma/list.ex2
-rw-r--r--lib/pleroma/notification.ex2
-rw-r--r--lib/pleroma/object.ex22
-rw-r--r--lib/pleroma/object/containment.ex61
-rw-r--r--lib/pleroma/object/fetcher.ex75
-rw-r--r--lib/pleroma/user.ex41
-rw-r--r--lib/pleroma/user/info.ex2
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex107
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub_controller.ex3
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex97
-rw-r--r--lib/pleroma/web/activity_pub/utils.ex10
-rw-r--r--lib/pleroma/web/activity_pub/visibility.ex23
-rw-r--r--lib/pleroma/web/admin_api/admin_api_controller.ex24
-rw-r--r--lib/pleroma/web/channels/user_socket.ex2
-rw-r--r--lib/pleroma/web/common_api/common_api.ex13
-rw-r--r--lib/pleroma/web/common_api/utils.ex10
-rw-r--r--lib/pleroma/web/federator/federator.ex5
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api.ex28
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex118
-rw-r--r--lib/pleroma/web/mastodon_api/views/account_view.ex2
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex90
-rw-r--r--lib/pleroma/web/mastodon_api/websocket_handler.ex2
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex27
-rw-r--r--lib/pleroma/web/oauth/token.ex2
-rw-r--r--lib/pleroma/web/ostatus/activity_representer.ex42
-rw-r--r--lib/pleroma/web/ostatus/handlers/note_handler.ex5
-rw-r--r--lib/pleroma/web/ostatus/ostatus.ex2
-rw-r--r--lib/pleroma/web/router.ex3
-rw-r--r--lib/pleroma/web/streamer.ex2
-rw-r--r--lib/pleroma/web/twitter_api/controllers/util_controller.ex32
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api.ex9
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api_controller.ex8
-rw-r--r--lib/pleroma/web/twitter_api/views/activity_view.ex30
-rw-r--r--lib/pleroma/web/web_finger/web_finger.ex2
-rw-r--r--priv/static/finmoji/1000px/a_trusted_friend.pngbin73028 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/alandislands.pngbin73719 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/association.pngbin79169 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/auroraborealis.pngbin230107 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/baby_in_a_box.pngbin88975 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/bear.pngbin43219 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/black_gold.pngbin58373 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/christmasparty.pngbin94071 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/crosscountryskiing.pngbin41402 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/cupofcoffee.pngbin44470 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/education.pngbin61859 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/fashionista_finns.pngbin62943 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/finnishlove.pngbin75603 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/flag.pngbin61680 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/forest.pngbin44987 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/four_seasons_of_bbq.pngbin96149 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/girlpower.pngbin47542 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/handshake.pngbin30936 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/happiness.pngbin40144 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/headbanger.pngbin52072 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/icebreaker.pngbin59735 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/iceman.pngbin241786 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/joulutorttu.pngbin38280 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/kaamos.pngbin129659 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/kalsarikannit_f.pngbin77284 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/kalsarikannit_m.pngbin52061 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/karjalanpiirakka.pngbin59854 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/kicksled.pngbin62979 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/kokko.pngbin120955 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/lavatanssit.pngbin127880 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/losthopes_f.pngbin51293 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/losthopes_m.pngbin60920 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/mattinykanen.pngbin106925 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/meanwhileinfinland.pngbin115605 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/moominmamma.pngbin168752 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/nordicfamily.pngbin99681 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/out_of_office.pngbin70661 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/peacemaker.pngbin58963 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/perkele.pngbin52650 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/pesapallo.pngbin40777 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/polarbear.pngbin71010 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/pusa_hispida_saimensis.pngbin45040 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/reindeer.pngbin44210 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/sami.pngbin54417 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/sauna_f.pngbin37303 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/sauna_m.pngbin34653 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/sauna_whisk.pngbin98017 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/sisu.pngbin74499 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/stuck.pngbin45617 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/suomimainittu.pngbin67753 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/superfood.pngbin128635 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/swan.pngbin42163 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/the_cap.pngbin36104 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/the_conductor.pngbin34223 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/the_king.pngbin90901 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/the_voice.pngbin77017 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/theoriginalsanta.pngbin59829 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/tomoffinland.pngbin69815 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/torillatavataan.pngbin137173 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/unbreakable.pngbin77581 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/waiting.pngbin17677 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/white_nights.pngbin50176 -> 0 bytes
-rw-r--r--priv/static/finmoji/1000px/woollysocks.pngbin130906 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/a_trusted_friend-128.pngbin8011 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/alandislands-128.pngbin6348 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/association-128.pngbin8702 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/auroraborealis-128.pngbin10942 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/baby_in_a_box-128.pngbin9156 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/bear-128.pngbin4330 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/black_gold-128.pngbin6370 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/christmasparty-128.pngbin8546 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/crosscountryskiing-128.pngbin4604 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/cupofcoffee-128.pngbin4273 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/education-128.pngbin6309 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/fashionista_finns-128.pngbin7668 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/finnishlove-128.pngbin6002 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/flag-128.pngbin4134 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/forest-128.pngbin4074 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/four_seasons_of_bbq-128.pngbin9531 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/girlpower-128.pngbin4444 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/handshake-128.pngbin2805 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/happiness-128.pngbin4631 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/headbanger-128.pngbin4972 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/icebreaker-128.pngbin7435 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/iceman-128.pngbin12456 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/joulutorttu-128.pngbin3194 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/kaamos-128.pngbin8834 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/kalsarikannit_f-128.pngbin6921 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/kalsarikannit_m-128.pngbin5356 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/karjalanpiirakka-128.pngbin5234 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/kicksled-128.pngbin7302 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/kokko-128.pngbin11435 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/lavatanssit-128.pngbin11916 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/losthopes_f-128.pngbin4886 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/losthopes_m-128.pngbin6336 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/mattinykanen-128.pngbin7411 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/meanwhileinfinland-128.pngbin10995 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/moominmamma-128.pngbin9176 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/nordicfamily-128.pngbin11159 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/out_of_office-128.pngbin7475 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/peacemaker-128.pngbin5250 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/perkele-128.pngbin9884 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/pesapallo-128.pngbin4164 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/polarbear-128.pngbin8390 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/pusa_hispida_saimensis-128.pngbin4455 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/reindeer-128.pngbin3999 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/sami-128.pngbin5205 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/sauna_f-128.pngbin5970 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/sauna_m-128.pngbin5450 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/sauna_whisk-128.pngbin10569 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/sisu-128.pngbin6751 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/stuck-128.pngbin4529 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/suomimainittu-128.pngbin6841 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/superfood-128.pngbin10698 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/swan-128.pngbin4339 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/the_cap-128.pngbin3612 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/the_conductor-128.pngbin4014 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/the_king-128.pngbin8679 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/the_voice-128.pngbin6629 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/theoriginalsanta-128.pngbin5283 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/tomoffinland-128.pngbin7562 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/torillatavataan-128.pngbin13543 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/unbreakable-128.pngbin7393 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/waiting-128.pngbin2732 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/white_nights-128.pngbin6076 -> 0 bytes
-rw-r--r--priv/static/finmoji/128px/woollysocks-128.pngbin9507 -> 0 bytes
-rw-r--r--priv/static/finmoji/LICENSE1
-rw-r--r--test/activity_test.exs14
-rw-r--r--test/emoji_test.exs4
-rw-r--r--test/formatter_test.exs8
-rw-r--r--test/healthcheck_test.exs22
-rw-r--r--test/notification_test.exs4
-rw-r--r--test/object/containment_test.exs58
-rw-r--r--test/object/fetcher_test.exs90
-rw-r--r--test/object_test.exs28
-rw-r--r--test/scheduled_activity_worker_test.exs2
-rw-r--r--test/tasks/relay_test.exs4
-rw-r--r--test/tasks/user_test.exs16
-rw-r--r--test/user_test.exs39
-rw-r--r--test/web/activity_pub/activity_pub_controller_test.exs8
-rw-r--r--test/web/activity_pub/activity_pub_test.exs142
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs164
-rw-r--r--test/web/activity_pub/utils_test.exs5
-rw-r--r--test/web/admin_api/admin_api_controller_test.exs24
-rw-r--r--test/web/common_api/common_api_test.exs25
-rw-r--r--test/web/common_api/common_api_utils_test.exs10
-rw-r--r--test/web/mastodon_api/account_view_test.exs6
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs281
-rw-r--r--test/web/mastodon_api/notification_view_test.exs2
-rw-r--r--test/web/mastodon_api/status_view_test.exs18
-rw-r--r--test/web/oauth/oauth_controller_test.exs21
-rw-r--r--test/web/ostatus/ostatus_controller_test.exs8
-rw-r--r--test/web/ostatus/ostatus_test.exs101
-rw-r--r--test/web/push/impl_test.exs4
-rw-r--r--test/web/salmon/salmon_test.exs2
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs40
-rw-r--r--test/web/twitter_api/twitter_api_test.exs65
-rw-r--r--test/web/twitter_api/util_controller_test.exs6
-rw-r--r--test/web/twitter_api/views/activity_view_test.exs25
-rw-r--r--test/web/twitter_api/views/user_view_test.exs2
211 files changed, 2294 insertions, 970 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c90ff61cd..70381f382 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,19 +10,23 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- A [job queue](https://git.pleroma.social/pleroma/pleroma_job_queue) for federation, emails, web push, etc.
- [Prometheus](https://prometheus.io/) metrics
- Support for Mastodon's remote interaction
+- Mix Tasks: `mix pleroma.database remove_embedded_objects`
- Federation: Support for reports
- Configuration: `safe_dm_mentions` option
- Configuration: `link_name` option
- Configuration: `fetch_initial_posts` option
- Configuration: `notify_email` option
-- Pleroma API: User subscribtions
+- Pleroma API: User subscriptions
+- Pleroma API: Healthcheck endpoint
- Admin API: Endpoints for listing/revoking invite tokens
- Admin API: Endpoints for making users follow/unfollow each other
- Mastodon API: [Scheduled statuses](https://docs.joinmastodon.org/api/rest/scheduled-statuses/)
- Mastodon API: `/api/v1/notifications/destroy_multiple` (glitch-soc extension)
+- Mastodon API: `/api/v1/pleroma/accounts/:id/favourites` (API extension)
- Mastodon API: [Reports](https://docs.joinmastodon.org/api/rest/reports/)
- ActivityPub C2S: OAuth endpoints
- Metadata RelMe provider
+- Emoji packs and emoji pack manager
### Changed
- **Breaking:** Configuration: move from Pleroma.Mailer to Pleroma.Emails.Mailer
@@ -39,7 +43,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Mastodon API: Support for `exclude_types`, `limit` and `min_id` in `/api/v1/notifications`
- Mastodon API: Add `languages` and `registrations` to `/api/v1/instance`
- Mastodon API: Provide plaintext versions of cw/content in the Status entity
-- Mastodon API: Add `pleroma.conversation_id` field to the Status entity
+- Mastodon API: Add `pleroma.conversation_id`, `pleroma.in_reply_to_account_acct` fields to the Status entity
- Mastodon API: Add `pleroma.tags`, `pleroma.relationship{}`, `pleroma.is_moderator`, `pleroma.is_admin`, `pleroma.confirmation_pending` fields to the User entity
- Mastodon API: Add `pleroma.is_seen` to the Notification entity
- Mastodon API: Add `pleroma.local` to the Status entity
@@ -49,6 +53,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Mastodon API: Remove attachment limit in the Status entity
- Deps: Updated Cowboy to 2.6
- Deps: Updated Ecto to 3.0.7
+- Don't ship finmoji by default, they can be installed as an emoji pack
### Fixed
- Followers counter not being updated when a follower is blocked
@@ -66,10 +71,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- MediaProxy: Parse name from content disposition headers even for non-whitelisted types
- MediaProxy: S3 link encoding
- Rich Media: Reject any data which cannot be explicitly encoded into JSON
+- Pleroma API: Importing follows from Mastodon 2.8+
- Mastodon API: `/api/v1/favourites` serving only public activities
- Mastodon API: Reblogs having `in_reply_to_id` - `null` even when they are replies
- Mastodon API: Streaming API broadcasting wrong activity id
- Mastodon API: 500 errors when requesting a card for a private conversation
+- Mastodon API: Handling of `reblogs` in `/api/v1/accounts/:id/follow`
+- Mastodon API: Correct `reblogged`, `favourited`, and `bookmarked` values in the reblog status JSON
## [0.9.9999] - 2019-04-05
### Security
diff --git a/COPYING b/COPYING
index ceec519ae..eceb68efe 100644
--- a/COPYING
+++ b/COPYING
@@ -39,10 +39,3 @@ does not include the right to compile photos from Unsplash to replicate
a similar or competing service.
priv/static/images/city.jpg
-
----
-
-The files present under the priv/static/finmoji directory are copyright
-Finland <https://finland.fi/emoji/>, and are distributed under the Creative
-Commons Attribution-NonCommercial-NoDerivatives 4.0 International license, you
-should have received a copy of the license file as CC-BY-NC-ND-4.0.
diff --git a/config/config.exs b/config/config.exs
index 1114dc84d..b11e4c680 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -100,9 +100,9 @@ config :pleroma, :emoji,
shortcode_globs: ["/emoji/custom/**/*.png"],
groups: [
# Put groups that have higher priority than defaults here. Example in `docs/config/custom_emoji.md`
- Finmoji: "/finmoji/128px/*-128.png",
- Custom: ["/emoji/*.png", "/emoji/custom/*.png"]
- ]
+ Custom: ["/emoji/*.png", "/emoji/**/*.png"]
+ ],
+ default_manifest: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
config :pleroma, :uri_schemes,
valid_schemes: [
@@ -223,7 +223,6 @@ config :pleroma, :instance,
"text/html",
"text/markdown"
],
- finmoji_enabled: true,
mrf_transparency: true,
autofollowed_nicknames: [],
max_pinned_statuses: 1,
@@ -231,7 +230,8 @@ config :pleroma, :instance,
welcome_user_nickname: nil,
welcome_message: nil,
max_report_comment_size: 1000,
- safe_dm_mentions: false
+ safe_dm_mentions: false,
+ healthcheck: false
config :pleroma, :markup,
# XXX - unfortunately, inline images must be enabled by default right now, because
diff --git a/docs/api/differences_in_mastoapi_responses.md b/docs/api/differences_in_mastoapi_responses.md
index ed3fd9b67..3bb1bd41f 100644
--- a/docs/api/differences_in_mastoapi_responses.md
+++ b/docs/api/differences_in_mastoapi_responses.md
@@ -20,6 +20,7 @@ Has these additional fields under the `pleroma` object:
- `local`: true if the post was made on the local instance.
- `conversation_id`: the ID of the conversation the status is associated with (if any)
+- `in_reply_to_account_acct`: the `acct` property of User entity for replied user (if any)
- `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`
@@ -58,3 +59,4 @@ Has these additional fields under the `pleroma` object:
Additional parameters can be added to the JSON body/Form data:
- `preview`: boolean, if set to `true` the post won't be actually posted, but the status entitiy would still be rendered back. This could be useful for previewing rich text/custom emoji, for example.
+- `content_type`: string, contain the MIME type of the status, it is transformed into HTML by the backend. You can get the list of the supported MIME types with the nodeinfo endpoint.
diff --git a/docs/api/pleroma_api.md b/docs/api/pleroma_api.md
index dbe250300..190846de9 100644
--- a/docs/api/pleroma_api.md
+++ b/docs/api/pleroma_api.md
@@ -77,7 +77,7 @@ Request parameters can be passed via [query strings](https://en.wikipedia.org/wi
* `token`: invite token required when the registrations aren't public.
* Response: JSON. Returns a user object on success, otherwise returns `{"error": "error_msg"}`
* Example response:
-```
+```json
{
"background_image": null,
"cover_photo": "https://pleroma.soykaf.com/images/banner.png",
@@ -187,6 +187,62 @@ See [Admin-API](Admin-API.md)
}
```
+## `/api/v1/pleroma/accounts/:id/favourites`
+### Returns favorites timeline of any user
+* Method `GET`
+* Authentication: not required
+* Params:
+ * `id`: the id of the account for whom to return results
+ * `limit`: optional, the number of records to retrieve
+ * `since_id`: optional, returns results that are more recent than the specified id
+ * `max_id`: optional, returns results that are older than the specified id
+* Response: JSON, returns a list of Mastodon Status entities on success, otherwise returns `{"error": "error_msg"}`
+* Example response:
+```json
+[
+ {
+ "account": {
+ "id": "9hptFmUF3ztxYh3Svg",
+ "url": "https://pleroma.example.org/users/nick2",
+ "username": "nick2",
+ ...
+ },
+ "application": {"name": "Web", "website": null},
+ "bookmarked": false,
+ "card": null,
+ "content": "This is :moominmamma: note 0",
+ "created_at": "2019-04-15T15:42:15.000Z",
+ "emojis": [],
+ "favourited": false,
+ "favourites_count": 1,
+ "id": "9hptFmVJ02khbzYJaS",
+ "in_reply_to_account_id": null,
+ "in_reply_to_id": null,
+ "language": null,
+ "media_attachments": [],
+ "mentions": [],
+ "muted": false,
+ "pinned": false,
+ "pleroma": {
+ "content": {"text/plain": "This is :moominmamma: note 0"},
+ "conversation_id": 13679,
+ "local": true,
+ "spoiler_text": {"text/plain": "2hu"}
+ },
+ "reblog": null,
+ "reblogged": false,
+ "reblogs_count": 0,
+ "replies_count": 0,
+ "sensitive": false,
+ "spoiler_text": "2hu",
+ "tags": [{"name": "2hu", "url": "/tag/2hu"}],
+ "uri": "https://pleroma.example.org/objects/198ed2a1-7912-4482-b559-244a0369e984",
+ "url": "https://pleroma.example.org/notice/9hptFmVJ02khbzYJaS",
+ "visibility": "public"
+ }
+]
+```
+
## `/api/pleroma/notification_settings`
### Updates user notification settings
* Method `PUT`
@@ -197,3 +253,20 @@ See [Admin-API](Admin-API.md)
* `remote`: BOOLEAN field, receives notifications from people on remote instances
* `local`: BOOLEAN field, receives notifications from people on the local instance
* Response: JSON. Returns `{"status": "success"}` if the update was successful, otherwise returns `{"error": "error_msg"}`
+
+## `/api/pleroma/healthcheck`
+### Healthcheck endpoint with additional system data.
+* Method `GET`
+* Authentication: not required
+* Params: none
+* Response: JSON, statuses (200 - healthy, 503 unhealthy).
+* Example response:
+```json
+{
+ "pool_size": 0, # database connection pool
+ "active": 0, # active processes
+ "idle": 0, # idle processes
+ "memory_used": 0.00, # Memory used
+ "healthy": true # Instance state
+}
+```
diff --git a/docs/config.md b/docs/config.md
index 5a97033b2..7b6631f9b 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -87,7 +87,6 @@ config :pleroma, Pleroma.Emails.Mailer,
* `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)
-* `finmoji_enabled`: Whenether to enable the finmojis in the custom emojis.
* `mrf_transparency`: Make the content of your Message Rewrite Facility settings public (via nodeinfo).
* `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:
@@ -104,6 +103,7 @@ config :pleroma, Pleroma.Emails.Mailer,
* `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``.
## :logger
* `backends`: `:console` is used to send logs to stdout, `{ExSyslogger, :ex_syslogger}` to log to syslog, and `Quack.Logger` to log to Slack
@@ -487,3 +487,8 @@ config :ueberauth, Ueberauth,
microsoft: {Ueberauth.Strategy.Microsoft, [callback_params: []]}
]
```
+
+## :emoji
+* `shortcode_globs`: Location of custom emoji files. `*` can be used as a wildcard. Example `["/emoji/custom/**/*.png"]`
+* `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).
diff --git a/docs/config/custom_emoji.md b/docs/config/custom_emoji.md
index 5ce9865a2..f72c0edbc 100644
--- a/docs/config/custom_emoji.md
+++ b/docs/config/custom_emoji.md
@@ -1,15 +1,25 @@
# Custom Emoji
+Before you add your own custom emoji, check if they are available in an existing pack.
+See `Mix.Tasks.Pleroma.Emoji` for information about emoji packs.
+
To add custom emoji:
-* Add the image file(s) to `priv/static/emoji/custom`
-* In case of conflicts: add the desired shortcode with the path to `config/custom_emoji.txt`, comma-separated and one per line
-* Force recompilation (``mix clean && mix compile``)
+* Create the `STATIC-DIR/emoji/` directory if it doesn't exist
+ (`STATIC-DIR` is configurable, `instance/static/` by default)
+* Create a directory with whatever name you want (custom is a good name to show the purpose of it).
+ This will create a local emoji pack.
+* Put your `.png` emoji files in that directory. In case of conflicts, you can create an `emoji.txt`
+ file in that directory and specify a custom shortcode using the following format:
+ `shortcode, file-path, tag1, tag2, etc`. One emoji per line. Note that if you do so,
+ you'll have to list all other emojis in the pack too.
+* Either restart pleroma or connect to the iex session pleroma's running and
+ run `Pleroma.Emoji.reload/0` in it.
Example:
-image files (in `/priv/static/emoji/custom`): `happy.png` and `sad.png`
+image files (in `instance/static/emoji/custom`): `happy.png` and `sad.png`
-content of `config/custom_emoji.txt`:
+content of `emoji.txt`:
```
happy, /emoji/custom/happy.png, Tag1,Tag2
sad, /emoji/custom/sad.png, Tag1
@@ -18,6 +28,11 @@ foo, /emoji/custom/foo.png
The files should be PNG (APNG is okay with `.png` for `image/png` Content-type) and under 50kb for compatibility with mastodon.
+Default file extentions and locations for emojis are set in `config.exs`. To use different locations or file-extentions, add the `shortcode_globs` to your secrets file (`prod.secret.exs` or `dev.secret.exs`) and edit it. Note that not all fediverse-software will show emojis with other file extentions:
+```elixir
+config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png", "/emoji/custom/**/*.gif"]
+```
+
## Emoji tags (groups)
Default tags are set in `config.exs`. To set your own tags, copy the structure to your secrets file (`prod.secret.exs` or `dev.secret.exs`) and edit it.
diff --git a/docs/installation/gentoo_en.md b/docs/installation/gentoo_en.md
new file mode 100644
index 000000000..fccaad378
--- /dev/null
+++ b/docs/installation/gentoo_en.md
@@ -0,0 +1,296 @@
+# Installing on Gentoo GNU/Linux
+## Installation
+
+This guide will assume that you have administrative rights, either as root or a user with [sudo permissions](https://wiki.gentoo.org/wiki/Sudo). Lines that begin with `#` indicate that they should be run as the superuser. Lines using `$` should be run as the indicated user, e.g. `pleroma$` should be run as the `pleroma` user.
+
+### Configuring your hostname (optional)
+
+If you would like your prompt to permanently include your host/domain, change `/etc/conf.d/hostname` to your hostname. You can reboot or use the `hostname` command to make immediate changes.
+
+### Your make.conf, package.use, and USE flags
+
+The only specific USE flag you should need is the `uuid` flag for `dev-db/postgresql`. Add the following line to any new file in `/etc/portage/package.use`. If you would like a suggested name for the file, either `postgresql` or `pleroma` would do fine, depending on how you like to arrange your package.use flags.
+
+```text
+dev-db/postgresql uuid
+```
+
+You could opt to add `USE="uuid"` to `/etc/portage/make.conf` if you'd rather set this as a global USE flags, but this flags does unrelated things in other packages, so keep that in mind if you elect to do so.
+
+Double check your compiler flags in `/etc/portage/make.conf`. If you require any special compilation flags or would like to set up remote builds, now is the time to do so. Be sure that your CFLAGS and MAKEOPTS make sense for the platform you are using. It is not recommended to use above `-O2` or risky optimization flags for a production server.
+
+### Installing a cron daemon
+
+Gentoo quite pointedly does not come with a cron daemon installed, and as such it is recommended you install one to automate certbot renewals and to allow other system administration tasks to be run automatically. Gentoo has [a whole wide world of cron options](https://wiki.gentoo.org/wiki/Cron) but if you just want A Cron That Works, `emerge --ask virtual/cron` will install the default cron implementation (probably cronie) which will work just fine. For the purpouses of this guide, we will be doing just that.
+
+### Required ebuilds
+
+* `dev-db/postgresql`
+* `dev-lang/elixir`
+* `dev-vcs/git`
+
+#### Optional ebuilds used in this guide
+
+* `www-servers/nginx` (preferred, example configs for other reverse proxies can be found in the repo)
+* `app-crypt/certbot` (or any other ACME client for Let’s Encrypt certificates)
+* `app-crypt/certbot-nginx` (nginx certbot plugin that allows use of the all-powerful `--nginx` flag on certbot)
+
+### Prepare the system
+
+* First ensure that you have the latest copy of the portage ebuilds if you have not synced them yet:
+
+```shell
+ # emaint sync -a
+```
+
+* Emerge all required the required and suggested software in one go:
+
+```shell
+ # emerge --ask dev-db/postgresql dev-lang/elixir dev-vcs/git www-servers/nginx app-crypt/certbot app-crypt/certbot-nginx
+```
+
+If you would not like to install the optional packages, remove them from this line.
+
+If you're running this from a low-powered virtual machine, it should work though it will take some time. There were no issues on a VPS with a single core and 1GB of RAM; if you are using an even more limited device and run into issues, you can try creating a swapfile or use a more powerful machine running Gentoo to [cross build](https://wiki.gentoo.org/wiki/Cross_build_environment). If you have a wait ahead of you, now would be a good time to take a break, strech a bit, refresh your beverage of choice and/or get a snack, and reply to Arch users' posts with "I use Gentoo btw" as we do.
+
+### Install PostgreSQL
+
+[Gentoo Wiki article](https://wiki.gentoo.org/wiki/PostgreSQL) as well as [PostgreSQL QuickStart](https://wiki.gentoo.org/wiki/PostgreSQL/QuickStart) might be worth a quick glance, as the way Gentoo handles postgres is slightly unusual, with built in capability to have two different databases running for testing and live or whatever other purpouse. While it is still straightforward to install, it does mean that the version numbers used in this guide might change for future updates, so keep an eye out for the output you get from `emerge` to ensure you are using the correct ones.
+
+* Install postgresql if you have not done so already:
+
+```shell
+ # emerge --ask dev-db/postgresql
+```
+
+Ensure that `/etc/conf.d/postgresql-11` has the encoding you want (it defaults to UTF8 which is probably what you want) and make any adjustments to the data directory if you find it necessary. Be sure to adjust the number at the end depending on what version of postgres you actually installed.
+
+* Initialize the database cluster
+
+The output from emerging postgresql should give you a command for initializing the postgres database. The default slot should be indicated in this command, ensure that it matches the command below.
+
+```shell
+ # emerge --config dev-db/postgresql:11
+```
+
+* Start postgres and enable the system service
+
+```shell
+ # /etc/init.d/postgresql-11 start
+ # rc-update add postgresql-11 default
+ ```
+
+### A note on licenses, the AGPL, and deployment procedures
+
+If you do not plan to make any modifications to your Pleroma instance, cloning directly from the main repo will get you what you need. However, if you plan on doing any contributions to upstream development, making changes or modifications to your instance, making custom themes, or want to play around--and let's be honest here, if you're using Gentoo that is most likely you--you will save yourself a lot of headache later if you take the time right now to fork the Pleroma repo and use that in the following section.
+
+Not only does this make it much easier to deploy changes you make, as you can commit and pull from upstream and all that good stuff from the comfort of your local machine then simply `git pull` on your instance server when you're ready to deploy, it also ensures you are compliant with the Affero General Public Licence that Pleroma is licenced under, which stipulates that all network services provided with modified AGPL code must publish their changes on a publicly available internet service and for free. It also makes it much easier to ask for help from and provide help to your fellow Pleroma admins if your public repo always reflects what you are running because it is part of your deployment procedure.
+
+### Install PleromaBE
+
+* Add a new system user for the Pleroma service and set up default directories:
+
+Remove `,wheel` if you do not want this user to be able to use `sudo`, however note that being able to `sudo` as the `pleroma` user will make finishing the insallation and common maintenence tasks somewhat easier:
+
+```shell
+ # useradd -m -G users,wheel -s /bin/bash pleroma
+```
+
+Optional: If you are using sudo, review your sudo setup to ensure it works for you. The `/etc/sudoers` file has a lot of options and examples to help you, and [the Gentoo sudo guide](https://wiki.gentoo.org/wiki/Sudo) has more information. Finishing this installation will be somewhat easier if you have a way to sudo from the `pleroma` user, but it might be best to not allow that user to sudo during normal operation, and as such there will be a reminder at the end of this guide to double check if you would like to lock down the `pleroma` user after initial setup.
+
+**Note**: To execute a single command as the Pleroma system user, use `sudo -Hu pleroma command`. You can also switch to a shell by using `sudo -Hu pleroma $SHELL`. If you don't have or want `sudo` or would like to use the system as the `pleroma` user for instance maintenance tasks, you can simply use `su - pleroma` to switch to the `pleroma` user.
+
+* Git clone the PleromaBE repository and make the Pleroma user the owner of the directory:
+
+It is highly recommended you use your own fork for the `https://path/to/repo` part below, however if you foolishly decide to forego using your own fork, the primary repo `https://git.pleroma.social/pleroma/pleroma` will work here.
+
+```shell
+ pleroma$ cd ~
+ pleroma$ git clone https://path/to/repo
+```
+
+* Change to the new directory:
+
+```shell
+pleroma$ cd ~/pleroma
+```
+
+* Install the dependencies for Pleroma and answer with `yes` if it asks you to install `Hex`:
+
+```shell
+pleroma$ mix deps.get
+```
+
+* Generate the configuration:
+
+```shell
+pleroma$ mix pleroma.instance gen
+```
+
+ * Answer with `yes` if it asks you to install `rebar3`.
+
+ * This part precompiles some parts of Pleroma, so it might take a few moments
+
+ * After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
+
+ * Spend some time with `generated_config.exs` to ensure that everything is in order. If you plan on using an S3-compatible service to store your local media, that can be done here. You will likely mostly be using `prod.secret.exs` for a production instance, however if you would like to set up a development environment, make a copy to `dev.secret.exs` and adjust settings as needed as well.
+
+```shell
+pleroma$ mv config/generated_config.exs config/prod.secret.exs
+```
+
+* The previous command creates also the file `config/setup_db.psql`, with which you can create the database. Ensure that it is using the correct database name on the `CREATE DATABASE` and the `\c` lines, then run the postgres script:
+
+```shell
+pleroma$ sudo -Hu postgres psql -f config/setup_db.psql
+```
+
+* Now run the database migration:
+
+```shell
+pleroma$ MIX_ENV=prod mix ecto.migrate
+```
+
+* Now you can start Pleroma already
+
+```shell
+pleroma$ MIX_ENV=prod mix phx.server
+```
+
+It probably won't work over the public internet quite yet, however, as we still need to set up a web servere to proxy to the pleroma application, as well as configure SSL.
+
+### Finalize installation
+
+Assuming you want to open your newly installed federated social network to, well, the federation, you should run nginx or some other webserver/proxy in front of Pleroma. It is also a good idea to set up Pleroma to run as a system service.
+
+#### Nginx
+
+* Install nginx, if not already done:
+
+```shell
+ # emerge --ask www-servers/nginx
+```
+
+* Create directories for available and enabled sites:
+
+```shell
+ # mkdir -p /etc/nginx/sites-{available,enabled}
+```
+
+* Append the following line at the end of the `http` block in `/etc/nginx/nginx.conf`:
+
+```Nginx
+include sites-enabled/*;
+```
+
+* Setup your SSL cert, using your method of choice or certbot. If using certbot, install it if you haven't already:
+
+```shell
+ # emerge --ask app-crypt/certbot app-crypt/certbot-nginx
+```
+
+and then set it up:
+
+```shell
+ # mkdir -p /var/lib/letsencrypt/
+ # certbot certonly --email <your@emailaddress> -d <yourdomain> --standalone
+```
+
+If that doesn't work the first time, add `--dry-run` to further attempts to avoid being ratelimited as you identify the issue, and do not remove it until the dry run succeeds. If that doesn’t work, make sure, that nginx is not already running. If it still doesn’t work, try setting up nginx first (change ssl “on” to “off” and try again). Often the answer to issues with certbot is to use the `--nginx` flag once you have nginx up and running.
+
+If you are using any additional subdomains, such as for a media proxy, you can re-run the same command with the subdomain in question. When it comes time to renew later, you will not need to run multiple times for each domain, one renew will handle it.
+
+---
+
+* Copy the example nginx configuration and activate it:
+
+```shell
+ # cp /home/pleroma/pleroma/installation/pleroma.nginx /etc/nginx/sites-available/
+ # ln -s /etc/nginx/sites-available/pleroma.nginx /etc/nginx/sites-enabled/pleroma.nginx
+```
+
+* Take some time to ensure that your nginx config is correct
+
+Replace all instances of `example.tld` with your instance's public URL. If for whatever reason you made changes to the port that your pleroma app runs on, be sure that is reflected in your configuration.
+
+Pay special attention to the line that begins with `ssl_ecdh_curve`. It is stongly advised to comment that line out so that OpenSSL will use its full capabilities, and it is also possible you are running OpenSSL 1.0.2 necessitating that you do this.
+
+* Enable and start nginx:
+
+```shell
+ # rc-update add nginx default
+ # /etc/init.d/nginx start
+```
+
+If you are using certbot, it is HIGHLY recommend you set up a cron job that renews your certificate, and that you install the suggested `certbot-nginx` plugin. If you don't do these things, you only have yourself to blame when your instance breaks suddenly because you forgot about it.
+
+First, ensure that the command you will be installing into your crontab works.
+
+```shell
+ # /usr/bin/certbot renew --nginx
+```
+
+Assuming not much time has passed since you got certbot working a few steps ago, you should get a message for all domains you installed certificates for saying `Cert not yet due for renewal`.
+
+Now, run crontab as a superuser with `crontab -e` or `sudo crontab -e` as appropriate, and add the following line to your cron:
+
+```cron
+0 0 1 * * /usr/bin/certbot renew --nginx
+```
+
+This will run certbot on the first of the month at midnight. If you'd rather run more frequently, it's not a bad idea, feel free to go for it.
+
+#### Other webserver/proxies
+
+If you would like to use other webservers or proxies, there are example configurations for some popular alternatives in `/home/pleroma/pleroma/installation/`. You can, of course, check out [the Gentoo wiki](https://wiki.gentoo.org) for more information on installing and configuring said alternatives.
+
+#### Create the uploads folder
+
+Even if you are using S3, Pleroma needs someplace to store media posted on your instance. If you are using the `/home/pleroma/pleroma` root folder suggested by this guide, simply:
+
+```shell
+ pleroma$ mkdir -p ~/pleroma/uploads
+ ```
+
+#### init.d service
+
+* Copy example service file
+
+```shell
+ # cp /home/pleroma/pleroma/installation/init.d/pleroma /etc/init.d/
+```
+
+* Be sure to take a look at this service file and make sure that all paths fit your installation
+
+* Enable and start `pleroma`:
+
+```shell
+ # rc-update add pleroma default
+ # /etc/init.d/pleroma start
+```
+
+#### Create your first user
+
+If your instance is up and running, you can create your first user with administrative rights with the following task:
+
+```shell
+pleroma$ MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
+```
+
+#### Privilege cleanup
+
+If you opted to allow sudo for the `pleroma` user but would like to remove the ability for greater security, now might be a good time to edit `/etc/sudoers` and/or change the groups the `pleroma` user belongs to. Be sure to restart the pleroma service afterwards to ensure it picks up on the changes.
+
+#### Further reading
+
+* [Admin tasks](Admin tasks)
+* [Backup your instance](Backup-your-instance)
+* [Configuration tips](General tips for customizing pleroma fe)
+* [Hardening your instance](Hardening-your-instance)
+* [How to activate mediaproxy](How-to-activate-mediaproxy)
+* [Small Pleroma-FE customizations](Small customizations)
+* [Updating your instance](Updating-your-instance)
+
+## Questions
+
+Questions about the installation or didn’t it work as it should be, ask in [#pleroma:matrix.org](https://matrix.heldscal.la/#/room/#freenode_#pleroma:matrix.org) or IRC Channel **#pleroma** on **Freenode**.
diff --git a/lib/healthcheck.ex b/lib/healthcheck.ex
new file mode 100644
index 000000000..646fb3b9d
--- /dev/null
+++ b/lib/healthcheck.ex
@@ -0,0 +1,60 @@
+defmodule Pleroma.Healthcheck do
+ @moduledoc """
+ Module collects metrics about app and assign healthy status.
+ """
+ alias Pleroma.Healthcheck
+ alias Pleroma.Repo
+
+ defstruct pool_size: 0,
+ active: 0,
+ idle: 0,
+ memory_used: 0,
+ healthy: true
+
+ @type t :: %__MODULE__{
+ pool_size: non_neg_integer(),
+ active: non_neg_integer(),
+ idle: non_neg_integer(),
+ memory_used: number(),
+ healthy: boolean()
+ }
+
+ @spec system_info() :: t()
+ def system_info do
+ %Healthcheck{
+ memory_used: Float.round(:erlang.memory(:total) / 1024 / 1024, 2)
+ }
+ |> assign_db_info()
+ |> check_health()
+ end
+
+ defp assign_db_info(healthcheck) do
+ database = Application.get_env(:pleroma, Repo)[:database]
+
+ query =
+ "select state, count(pid) from pg_stat_activity where datname = '#{database}' group by state;"
+
+ result = Repo.query!(query)
+ pool_size = Application.get_env(:pleroma, Repo)[:pool_size]
+
+ db_info =
+ Enum.reduce(result.rows, %{active: 0, idle: 0}, fn [state, cnt], states ->
+ if state == "active" do
+ Map.put(states, :active, states.active + cnt)
+ else
+ Map.put(states, :idle, states.idle + cnt)
+ end
+ end)
+ |> Map.put(:pool_size, pool_size)
+
+ Map.merge(healthcheck, db_info)
+ end
+
+ @spec check_health(Healthcheck.t()) :: Healthcheck.t()
+ def check_health(%{pool_size: pool_size, active: active} = check)
+ when active >= pool_size do
+ %{check | healthy: false}
+ end
+
+ def check_health(check), do: check
+end
diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex
new file mode 100644
index 000000000..ab9a3a7ff
--- /dev/null
+++ b/lib/mix/tasks/pleroma/database.ex
@@ -0,0 +1,51 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Mix.Tasks.Pleroma.Database do
+ alias Mix.Tasks.Pleroma.Common
+ require Logger
+ use Mix.Task
+
+ @shortdoc "A collection of database related tasks"
+ @moduledoc """
+ A collection of database related tasks
+
+ ## Replace embedded objects with their references
+
+ Replaces embedded objects with references to them in the `objects` table. Only needs to be ran once. The reason why this is not a migration is because it could significantly increase the database size after being ran, however after this `VACUUM FULL` will be able to reclaim about 20% (really depends on what is in the database, your mileage may vary) of the db size before the migration.
+
+ mix pleroma.database remove_embedded_objects
+
+ Options:
+ - `--vacuum` - run `VACUUM FULL` after the embedded objects are replaced with their references
+ """
+ def run(["remove_embedded_objects" | args]) do
+ {options, [], []} =
+ OptionParser.parse(
+ args,
+ strict: [
+ vacuum: :boolean
+ ]
+ )
+
+ Common.start_pleroma()
+ Logger.info("Removing embedded objects")
+
+ Pleroma.Repo.query!(
+ "update activities set data = jsonb_set(data, '{object}'::text[], data->'object'->'id') where data->'object'->>'id' is not null;",
+ [],
+ timeout: :infinity
+ )
+
+ if Keyword.get(options, :vacuum) do
+ Logger.info("Runnning VACUUM FULL")
+
+ Pleroma.Repo.query!(
+ "vacuum full;",
+ [],
+ timeout: :infinity
+ )
+ end
+ end
+end
diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex
new file mode 100644
index 000000000..cced73226
--- /dev/null
+++ b/lib/mix/tasks/pleroma/emoji.ex
@@ -0,0 +1,293 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Mix.Tasks.Pleroma.Emoji do
+ use Mix.Task
+
+ @shortdoc "Manages emoji packs"
+ @moduledoc """
+ Manages emoji packs
+
+ ## ls-packs
+
+ mix pleroma.emoji ls-packs [OPTION...]
+
+ Lists the emoji packs and metadata specified in the manifest.
+
+ ### Options
+
+ - `-m, --manifest PATH/URL` - path to a custom manifest, it can
+ either be an URL starting with `http`, in that case the
+ manifest will be fetched from that address, or a local path
+
+ ## get-packs
+
+ mix pleroma.emoji get-packs [OPTION...] PACKS
+
+ Fetches, verifies and installs the specified PACKS from the
+ manifest into the `STATIC-DIR/emoji/PACK-NAME`
+
+ ### Options
+
+ - `-m, --manifest PATH/URL` - same as ls-packs
+
+ ## gen-pack
+
+ mix pleroma.emoji gen-pack PACK-URL
+
+ Creates a new manifest entry and a file list from the specified
+ remote pack file. Currently, only .zip archives are recognized
+ as remote pack files and packs are therefore assumed to be zip
+ archives. This command is intended to run interactively and will
+ first ask you some basic questions about the pack, then download
+ the remote file and generate an SHA256 checksum for it, then
+ generate an emoji file list for you.
+
+ The manifest entry will either be written to a newly created
+ `index.json` file or appended to the existing one, *replacing*
+ the old pack with the same name if it was in the file previously.
+
+ The file list will be written to the file specified previously,
+ *replacing* that file. You _should_ check that the file list doesn't
+ contain anything you don't need in the pack, that is, anything that is
+ not an emoji (the whole pack is downloaded, but only emoji files
+ are extracted).
+ """
+
+ @default_manifest Pleroma.Config.get!([:emoji, :default_manifest])
+
+ def run(["ls-packs" | args]) do
+ Application.ensure_all_started(:hackney)
+
+ {options, [], []} = parse_global_opts(args)
+
+ manifest =
+ fetch_manifest(if options[:manifest], do: options[:manifest], else: @default_manifest)
+
+ Enum.each(manifest, fn {name, info} ->
+ to_print = [
+ {"Name", name},
+ {"Homepage", info["homepage"]},
+ {"Description", info["description"]},
+ {"License", info["license"]},
+ {"Source", info["src"]}
+ ]
+
+ for {param, value} <- to_print do
+ IO.puts(IO.ANSI.format([:bright, param, :normal, ": ", value]))
+ end
+
+ # A newline
+ IO.puts("")
+ end)
+ end
+
+ def run(["get-packs" | args]) do
+ Application.ensure_all_started(:hackney)
+
+ {options, pack_names, []} = parse_global_opts(args)
+
+ manifest_url = if options[:manifest], do: options[:manifest], else: @default_manifest
+
+ manifest = fetch_manifest(manifest_url)
+
+ for pack_name <- pack_names do
+ if Map.has_key?(manifest, pack_name) do
+ pack = manifest[pack_name]
+ src_url = pack["src"]
+
+ IO.puts(
+ IO.ANSI.format([
+ "Downloading ",
+ :bright,
+ pack_name,
+ :normal,
+ " from ",
+ :underline,
+ src_url
+ ])
+ )
+
+ binary_archive = Tesla.get!(src_url).body
+ archive_sha = :crypto.hash(:sha256, binary_archive) |> Base.encode16()
+
+ sha_status_text = ["SHA256 of ", :bright, pack_name, :normal, " source file is ", :bright]
+
+ if archive_sha == String.upcase(pack["src_sha256"]) do
+ IO.puts(IO.ANSI.format(sha_status_text ++ [:green, "OK"]))
+ else
+ IO.puts(IO.ANSI.format(sha_status_text ++ [:red, "BAD"]))
+
+ raise "Bad SHA256 for #{pack_name}"
+ end
+
+ # The url specified in files should be in the same directory
+ files_url = Path.join(Path.dirname(manifest_url), pack["files"])
+
+ IO.puts(
+ IO.ANSI.format([
+ "Fetching the file list for ",
+ :bright,
+ pack_name,
+ :normal,
+ " from ",
+ :underline,
+ files_url
+ ])
+ )
+
+ files = Tesla.get!(files_url).body |> Poison.decode!()
+
+ IO.puts(IO.ANSI.format(["Unpacking ", :bright, pack_name]))
+
+ pack_path =
+ Path.join([
+ Pleroma.Config.get!([:instance, :static_dir]),
+ "emoji",
+ pack_name
+ ])
+
+ files_to_unzip =
+ Enum.map(
+ files,
+ fn {_, f} -> to_charlist(f) end
+ )
+
+ {:ok, _} =
+ :zip.unzip(binary_archive,
+ cwd: pack_path,
+ file_list: files_to_unzip
+ )
+
+ IO.puts(IO.ANSI.format(["Writing emoji.txt for ", :bright, pack_name]))
+
+ emoji_txt_str =
+ Enum.map(
+ files,
+ fn {shortcode, path} ->
+ emojo_path = Path.join("/emoji/#{pack_name}", path)
+ "#{shortcode}, #{emojo_path}"
+ end
+ )
+ |> Enum.join("\n")
+
+ File.write!(Path.join(pack_path, "emoji.txt"), emoji_txt_str)
+ else
+ IO.puts(IO.ANSI.format([:bright, :red, "No pack named \"#{pack_name}\" found"]))
+ end
+ end
+ end
+
+ def run(["gen-pack", src]) do
+ Application.ensure_all_started(:hackney)
+
+ proposed_name = Path.basename(src) |> Path.rootname()
+ name = String.trim(IO.gets("Pack name [#{proposed_name}]: "))
+ # If there's no name, use the default one
+ name = if String.length(name) > 0, do: name, else: proposed_name
+
+ license = String.trim(IO.gets("License: "))
+ homepage = String.trim(IO.gets("Homepage: "))
+ description = String.trim(IO.gets("Description: "))
+
+ proposed_files_name = "#{name}.json"
+ files_name = String.trim(IO.gets("Save file list to [#{proposed_files_name}]: "))
+ files_name = if String.length(files_name) > 0, do: files_name, else: proposed_files_name
+
+ default_exts = [".png", ".gif"]
+ default_exts_str = Enum.join(default_exts, " ")
+
+ exts =
+ String.trim(
+ IO.gets("Emoji file extensions (separated with spaces) [#{default_exts_str}]: ")
+ )
+
+ exts =
+ if String.length(exts) > 0 do
+ String.split(exts, " ")
+ |> Enum.filter(fn e -> e |> String.trim() |> String.length() > 0 end)
+ else
+ default_exts
+ end
+
+ IO.puts("Downloading the pack and generating SHA256")
+
+ binary_archive = Tesla.get!(src).body
+ archive_sha = :crypto.hash(:sha256, binary_archive) |> Base.encode16()
+
+ IO.puts("SHA256 is #{archive_sha}")
+
+ pack_json = %{
+ name => %{
+ license: license,
+ homepage: homepage,
+ description: description,
+ src: src,
+ src_sha256: archive_sha,
+ files: files_name
+ }
+ }
+
+ tmp_pack_dir = Path.join(System.tmp_dir!(), "emoji-pack-#{name}")
+
+ {:ok, _} =
+ :zip.unzip(
+ binary_archive,
+ cwd: tmp_pack_dir
+ )
+
+ emoji_map = Pleroma.Emoji.make_shortcode_to_file_map(tmp_pack_dir, exts)
+
+ File.write!(files_name, Poison.encode!(emoji_map, pretty: true))
+
+ IO.puts("""
+
+ #{files_name} has been created and contains the list of all found emojis in the pack.
+ Please review the files in the remove those not needed.
+ """)
+
+ if File.exists?("index.json") do
+ existing_data = File.read!("index.json") |> Poison.decode!()
+
+ File.write!(
+ "index.json",
+ Poison.encode!(
+ Map.merge(
+ existing_data,
+ pack_json
+ ),
+ pretty: true
+ )
+ )
+
+ IO.puts("index.json file has been update with the #{name} pack")
+ else
+ File.write!("index.json", Poison.encode!(pack_json, pretty: true))
+
+ IO.puts("index.json has been created with the #{name} pack")
+ end
+ end
+
+ defp fetch_manifest(from) do
+ Poison.decode!(
+ if String.starts_with?(from, "http") do
+ Tesla.get!(from).body
+ else
+ File.read!(from)
+ end
+ )
+ end
+
+ defp parse_global_opts(args) do
+ OptionParser.parse(
+ args,
+ strict: [
+ manifest: :string
+ ],
+ aliases: [
+ m: :manifest
+ ]
+ )
+ end
+end
diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex
index 441168df2..b396ff0de 100644
--- a/lib/mix/tasks/pleroma/user.ex
+++ b/lib/mix/tasks/pleroma/user.ex
@@ -162,7 +162,7 @@ defmodule Mix.Tasks.Pleroma.User do
def run(["rm", nickname]) do
Common.start_pleroma()
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
User.delete(user)
Mix.shell().info("User #{nickname} deleted.")
else
@@ -174,7 +174,7 @@ defmodule Mix.Tasks.Pleroma.User do
def run(["toggle_activated", nickname]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
{:ok, user} = User.deactivate(user, !user.info.deactivated)
Mix.shell().info(
@@ -189,7 +189,7 @@ defmodule Mix.Tasks.Pleroma.User do
def run(["reset_password", nickname]) do
Common.start_pleroma()
- with %User{local: true} = user <- User.get_by_nickname(nickname),
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname),
{:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do
Mix.shell().info("Generated password reset token for #{user.nickname}")
@@ -211,14 +211,14 @@ defmodule Mix.Tasks.Pleroma.User do
def run(["unsubscribe", nickname]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
Mix.shell().info("Deactivating #{user.nickname}")
User.deactivate(user)
{:ok, friends} = User.get_friends(user)
Enum.each(friends, fn friend ->
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}")
User.unfollow(user, friend)
@@ -226,7 +226,7 @@ defmodule Mix.Tasks.Pleroma.User do
:timer.sleep(500)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
if Enum.empty?(user.following) do
Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}")
@@ -250,7 +250,7 @@ defmodule Mix.Tasks.Pleroma.User do
]
)
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
user =
case Keyword.get(options, :moderator) do
nil -> user
@@ -277,7 +277,7 @@ defmodule Mix.Tasks.Pleroma.User do
def run(["tag", nickname | tags]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
user = user |> User.tag(tags)
Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}")
@@ -290,7 +290,7 @@ defmodule Mix.Tasks.Pleroma.User do
def run(["untag", nickname | tags]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
user = user |> User.untag(tags)
Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}")
@@ -379,7 +379,7 @@ defmodule Mix.Tasks.Pleroma.User do
def run(["delete_activities", nickname]) do
Common.start_pleroma()
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
User.delete_user_activities(user)
Mix.shell().info("User #{nickname} statuses deleted.")
else
diff --git a/lib/pleroma/PasswordResetToken.ex b/lib/pleroma/PasswordResetToken.ex
index 7afbc8751..f31ea5bc5 100644
--- a/lib/pleroma/PasswordResetToken.ex
+++ b/lib/pleroma/PasswordResetToken.ex
@@ -39,7 +39,7 @@ defmodule Pleroma.PasswordResetToken do
def reset_password(token, data) do
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
- %User{} = user <- User.get_by_id(token.user_id),
+ %User{} = user <- User.get_cached_by_id(token.user_id),
{:ok, _user} <- User.reset_password(user, data),
{:ok, token} <- Repo.update(used_changeset(token)) do
{:ok, token}
diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex
index e6507e5ca..4a2ded518 100644
--- a/lib/pleroma/activity.ex
+++ b/lib/pleroma/activity.ex
@@ -10,6 +10,7 @@ defmodule Pleroma.Activity do
alias Pleroma.Object
alias Pleroma.Repo
+ import Ecto.Changeset
import Ecto.Query
@type t :: %__MODULE__{}
@@ -79,6 +80,13 @@ defmodule Pleroma.Activity do
)
end
+ def change(struct, params \\ %{}) do
+ struct
+ |> cast(params, [:data])
+ |> validate_required([:data])
+ |> unique_constraint(:ap_id, name: :activities_unique_apid_index)
+ end
+
def get_by_ap_id_with_object(ap_id) do
Repo.one(
from(
@@ -196,21 +204,27 @@ defmodule Pleroma.Activity do
def create_by_object_ap_id_with_object(_), do: nil
- def get_create_by_object_ap_id_with_object(ap_id) do
+ def get_create_by_object_ap_id_with_object(ap_id) when is_binary(ap_id) do
ap_id
|> create_by_object_ap_id_with_object()
|> Repo.one()
end
- def normalize(obj) when is_map(obj), do: get_by_ap_id_with_object(obj["id"])
- def normalize(ap_id) when is_binary(ap_id), do: get_by_ap_id_with_object(ap_id)
- def normalize(_), do: nil
+ def get_create_by_object_ap_id_with_object(_), do: nil
- def get_in_reply_to_activity(%Activity{data: %{"object" => %{"inReplyTo" => ap_id}}}) do
- get_create_by_object_ap_id(ap_id)
+ defp get_in_reply_to_activity_from_object(%Object{data: %{"inReplyTo" => ap_id}}) do
+ get_create_by_object_ap_id_with_object(ap_id)
end
- def get_in_reply_to_activity(_), do: nil
+ defp get_in_reply_to_activity_from_object(_), do: nil
+
+ def get_in_reply_to_activity(%Activity{data: %{"object" => object}}) do
+ get_in_reply_to_activity_from_object(Object.normalize(object))
+ end
+
+ def normalize(obj) when is_map(obj), do: get_by_ap_id_with_object(obj["id"])
+ def normalize(ap_id) when is_binary(ap_id), do: get_by_ap_id_with_object(ap_id)
+ def normalize(_), do: nil
def delete_by_ap_id(id) when is_binary(id) do
by_object_ap_id(id)
@@ -218,6 +232,7 @@ defmodule Pleroma.Activity do
|> Repo.delete_all()
|> elem(1)
|> Enum.find(fn
+ %{data: %{"type" => "Create", "object" => ap_id}} when is_binary(ap_id) -> ap_id == id
%{data: %{"type" => "Create", "object" => %{"id" => ap_id}}} -> ap_id == id
_ -> nil
end)
@@ -245,54 +260,4 @@ defmodule Pleroma.Activity do
|> where([s], s.actor == ^actor)
|> Repo.all()
end
-
- def increase_replies_count(nil), do: nil
-
- def increase_replies_count(object_ap_id) do
- from(a in create_by_object_ap_id(object_ap_id),
- update: [
- set: [
- data:
- fragment(
- """
- jsonb_set(?, '{object, repliesCount}',
- (coalesce((?->'object'->>'repliesCount')::int, 0) + 1)::varchar::jsonb, true)
- """,
- a.data,
- a.data
- )
- ]
- ]
- )
- |> Repo.update_all([])
- |> case do
- {1, [activity]} -> activity
- _ -> {:error, "Not found"}
- end
- end
-
- def decrease_replies_count(nil), do: nil
-
- def decrease_replies_count(object_ap_id) do
- from(a in create_by_object_ap_id(object_ap_id),
- update: [
- set: [
- data:
- fragment(
- """
- jsonb_set(?, '{object, repliesCount}',
- (greatest(0, (?->'object'->>'repliesCount')::int - 1))::varchar::jsonb, true)
- """,
- a.data,
- a.data
- )
- ]
- ]
- )
- |> Repo.update_all([])
- |> case do
- {1, [activity]} -> activity
- _ -> {:error, "Not found"}
- end
- end
end
diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex
index 87c7f2cec..6390cce4c 100644
--- a/lib/pleroma/emoji.ex
+++ b/lib/pleroma/emoji.ex
@@ -6,7 +6,7 @@ defmodule Pleroma.Emoji do
@moduledoc """
The emojis are loaded from:
- * the built-in Finmojis (if enabled in configuration),
+ * emoji packs in INSTANCE-DIR/emoji
* the files: `config/emoji.txt` and `config/custom_emoji.txt`
* glob paths, nested folder is used as tag name for grouping e.g. priv/static/emoji/custom/nested_folder
@@ -14,6 +14,8 @@ defmodule Pleroma.Emoji do
"""
use GenServer
+ require Logger
+
@type pattern :: Regex.t() | module() | String.t()
@type patterns :: pattern() | [pattern()]
@type group_patterns :: keyword(patterns())
@@ -79,95 +81,94 @@ defmodule Pleroma.Emoji do
end
defp load do
- finmoji_enabled = Keyword.get(Application.get_env(:pleroma, :instance), :finmoji_enabled)
+ emoji_dir_path =
+ Path.join(
+ Pleroma.Config.get!([:instance, :static_dir]),
+ "emoji"
+ )
+
+ case File.ls(emoji_dir_path) do
+ {:error, :enoent} ->
+ # The custom emoji directory doesn't exist,
+ # don't do anything
+ nil
+
+ {:error, e} ->
+ # There was some other error
+ Logger.error("Could not access the custom emoji directory #{emoji_dir_path}: #{e}")
+
+ {:ok, packs} ->
+ # Print the packs we've found
+ Logger.info("Found emoji packs: #{Enum.join(packs, ", ")}")
+
+ emojis =
+ Enum.flat_map(
+ packs,
+ fn pack -> load_pack(Path.join(emoji_dir_path, pack)) end
+ )
+
+ true = :ets.insert(@ets, emojis)
+ end
+
+ # Compat thing for old custom emoji handling & default emoji,
+ # it should run even if there are no emoji packs
shortcode_globs = Application.get_env(:pleroma, :emoji)[:shortcode_globs] || []
emojis =
- (load_finmoji(finmoji_enabled) ++
- load_from_file("config/emoji.txt") ++
+ (load_from_file("config/emoji.txt") ++
load_from_file("config/custom_emoji.txt") ++
load_from_globs(shortcode_globs))
|> Enum.reject(fn value -> value == nil end)
true = :ets.insert(@ets, emojis)
+
:ok
end
- @finmoji [
- "a_trusted_friend",
- "alandislands",
- "association",
- "auroraborealis",
- "baby_in_a_box",
- "bear",
- "black_gold",
- "christmasparty",
- "crosscountryskiing",
- "cupofcoffee",
- "education",
- "fashionista_finns",
- "finnishlove",
- "flag",
- "forest",
- "four_seasons_of_bbq",
- "girlpower",
- "handshake",
- "happiness",
- "headbanger",
- "icebreaker",
- "iceman",
- "joulutorttu",
- "kaamos",
- "kalsarikannit_f",
- "kalsarikannit_m",
- "karjalanpiirakka",
- "kicksled",
- "kokko",
- "lavatanssit",
- "losthopes_f",
- "losthopes_m",
- "mattinykanen",
- "meanwhileinfinland",
- "moominmamma",
- "nordicfamily",
- "out_of_office",
- "peacemaker",
- "perkele",
- "pesapallo",
- "polarbear",
- "pusa_hispida_saimensis",
- "reindeer",
- "sami",
- "sauna_f",
- "sauna_m",
- "sauna_whisk",
- "sisu",
- "stuck",
- "suomimainittu",
- "superfood",
- "swan",
- "the_cap",
- "the_conductor",
- "the_king",
- "the_voice",
- "theoriginalsanta",
- "tomoffinland",
- "torillatavataan",
- "unbreakable",
- "waiting",
- "white_nights",
- "woollysocks"
- ]
-
- defp load_finmoji(true) do
- Enum.map(@finmoji, fn finmoji ->
- file_name = "/finmoji/128px/#{finmoji}-128.png"
- group = match_extra(@groups, file_name)
- {finmoji, file_name, to_string(group)}
- end)
+ defp load_pack(pack_dir) do
+ pack_name = Path.basename(pack_dir)
+
+ emoji_txt = Path.join(pack_dir, "emoji.txt")
+
+ if File.exists?(emoji_txt) do
+ load_from_file(emoji_txt)
+ else
+ Logger.info(
+ "No emoji.txt found for pack \"#{pack_name}\", assuming all .png files are emoji"
+ )
+
+ make_shortcode_to_file_map(pack_dir, [".png"])
+ |> Enum.map(fn {shortcode, rel_file} ->
+ filename = Path.join("/emoji/#{pack_name}", rel_file)
+
+ {shortcode, filename, [to_string(match_extra(@groups, filename))]}
+ end)
+ end
+ end
+
+ def make_shortcode_to_file_map(pack_dir, exts) do
+ find_all_emoji(pack_dir, exts)
+ |> Enum.map(&Path.relative_to(&1, pack_dir))
+ |> Enum.map(fn f -> {f |> Path.basename() |> Path.rootname(), f} end)
+ |> Enum.into(%{})
end
- defp load_finmoji(_), do: []
+ def find_all_emoji(dir, exts) do
+ Enum.reduce(
+ File.ls!(dir),
+ [],
+ fn f, acc ->
+ filepath = Path.join(dir, f)
+
+ if File.dir?(filepath) do
+ acc ++ find_all_emoji(filepath, exts)
+ else
+ acc ++ [filepath]
+ end
+ end
+ )
+ |> Enum.filter(fn f -> Path.extname(f) in exts end)
+ end
defp load_from_file(file) do
if File.exists?(file) do
@@ -182,11 +183,11 @@ defmodule Pleroma.Emoji do
|> Stream.map(&String.trim/1)
|> Stream.map(fn line ->
case String.split(line, ~r/,\s*/) do
- [name, file, tags] ->
- {name, file, tags}
-
[name, file] ->
- {name, file, to_string(match_extra(@groups, file))}
+ {name, file, [to_string(match_extra(@groups, file))]}
+
+ [name, file | tags] ->
+ {name, file, tags}
_ ->
nil
@@ -209,7 +210,7 @@ defmodule Pleroma.Emoji do
tag = match_extra(@groups, Path.join("/", Path.relative_to(path, static_path)))
shortcode = Path.basename(path, Path.extname(path))
external_path = Path.join("/", Path.relative_to(path, static_path))
- {shortcode, external_path, to_string(tag)}
+ {shortcode, external_path, [to_string(tag)]}
end)
end
diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex
index 6a56a6f67..1d2e0785c 100644
--- a/lib/pleroma/gopher/server.ex
+++ b/lib/pleroma/gopher/server.ex
@@ -38,6 +38,7 @@ end
defmodule Pleroma.Gopher.Server.ProtocolHandler do
alias Pleroma.Activity
alias Pleroma.HTML
+ alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Visibility
@@ -75,14 +76,14 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do
|> Enum.map(fn activity ->
user = User.get_cached_by_ap_id(activity.data["actor"])
- object = activity.data["object"]
+ object = Object.normalize(activity)
like_count = object["like_count"] || 0
announcement_count = object["announcement_count"] || 0
link("Post ##{activity.id} by #{user.nickname}", "/notices/#{activity.id}") <>
info("#{like_count} likes, #{announcement_count} repeats") <>
"i\tfake\t(NULL)\t0\r\n" <>
- info(HTML.strip_tags(String.replace(activity.data["object"]["content"], "<br>", "\r")))
+ info(HTML.strip_tags(String.replace(object["content"], "<br>", "\r")))
end)
|> Enum.join("i\tfake\t(NULL)\t0\r\n")
end
diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex
index 2c701adb5..cf6c0ee0a 100644
--- a/lib/pleroma/html.ex
+++ b/lib/pleroma/html.ex
@@ -32,7 +32,8 @@ defmodule Pleroma.HTML do
key = "#{key}#{generate_scrubber_signature(scrubbers)}|#{activity.id}"
Cachex.fetch!(:scrubber_cache, key, fn _key ->
- ensure_scrubbed_html(content, scrubbers, activity.data["object"]["fake"] || false)
+ object = Pleroma.Object.normalize(activity)
+ ensure_scrubbed_html(content, scrubbers, object.data["fake"] || false)
end)
end
diff --git a/lib/pleroma/list.ex b/lib/pleroma/list.ex
index 110be8355..a5b1cad68 100644
--- a/lib/pleroma/list.ex
+++ b/lib/pleroma/list.ex
@@ -80,7 +80,7 @@ defmodule Pleroma.List do
# Get lists to which the account belongs.
def get_lists_account_belongs(%User{} = owner, account_id) do
- user = User.get_by_id(account_id)
+ user = User.get_cached_by_id(account_id)
query =
from(
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index b357d5399..dd274cf6b 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -196,7 +196,7 @@ defmodule Pleroma.Notification do
def skip?(:follows, activity, %{info: %{notification_settings: %{"follows" => false}}} = user) do
actor = activity.data["actor"]
- followed = User.get_by_ap_id(actor)
+ followed = User.get_cached_by_ap_id(actor)
User.following?(user, followed)
end
diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex
index 013d62157..740d687a3 100644
--- a/lib/pleroma/object.ex
+++ b/lib/pleroma/object.ex
@@ -7,6 +7,7 @@ defmodule Pleroma.Object do
alias Pleroma.Activity
alias Pleroma.Object
+ alias Pleroma.Object.Fetcher
alias Pleroma.ObjectTombstone
alias Pleroma.Repo
alias Pleroma.User
@@ -40,41 +41,44 @@ defmodule Pleroma.Object do
Repo.one(from(object in Object, where: fragment("(?)->>'id' = ?", object.data, ^ap_id)))
end
+ def normalize(_, fetch_remote \\ true)
# If we pass an Activity to Object.normalize(), we can try to use the preloaded object.
# Use this whenever possible, especially when walking graphs in an O(N) loop!
- def normalize(%Activity{object: %Object{} = object}), do: object
+ def normalize(%Object{} = object, _), do: object
+ def normalize(%Activity{object: %Object{} = object}, _), do: object
# A hack for fake activities
- def normalize(%Activity{data: %{"object" => %{"fake" => true} = data}}) do
+ def normalize(%Activity{data: %{"object" => %{"fake" => true} = data}}, _) do
%Object{id: "pleroma:fake_object_id", data: data}
end
# Catch and log Object.normalize() calls where the Activity's child object is not
# preloaded.
- def normalize(%Activity{data: %{"object" => %{"id" => ap_id}}}) do
+ def normalize(%Activity{data: %{"object" => %{"id" => ap_id}}}, fetch_remote) do
Logger.debug(
"Object.normalize() called without preloaded object (#{ap_id}). Consider preloading the object!"
)
Logger.debug("Backtrace: #{inspect(Process.info(:erlang.self(), :current_stacktrace))}")
- normalize(ap_id)
+ normalize(ap_id, fetch_remote)
end
- def normalize(%Activity{data: %{"object" => ap_id}}) do
+ def normalize(%Activity{data: %{"object" => ap_id}}, fetch_remote) do
Logger.debug(
"Object.normalize() called without preloaded object (#{ap_id}). Consider preloading the object!"
)
Logger.debug("Backtrace: #{inspect(Process.info(:erlang.self(), :current_stacktrace))}")
- normalize(ap_id)
+ normalize(ap_id, fetch_remote)
end
# Old way, try fetching the object through cache.
- def normalize(%{"id" => ap_id}), do: normalize(ap_id)
- def normalize(ap_id) when is_binary(ap_id), do: get_cached_by_ap_id(ap_id)
- def normalize(_), do: nil
+ def normalize(%{"id" => ap_id}, fetch_remote), do: normalize(ap_id, fetch_remote)
+ def normalize(ap_id, false) when is_binary(ap_id), do: get_cached_by_ap_id(ap_id)
+ def normalize(ap_id, true) when is_binary(ap_id), do: Fetcher.fetch_object_from_id!(ap_id)
+ def normalize(_, _), do: nil
# Owned objects can only be mutated by their owner
def authorize_mutation(%Object{data: %{"actor" => actor}}, %User{ap_id: ap_id}),
diff --git a/lib/pleroma/object/containment.ex b/lib/pleroma/object/containment.ex
new file mode 100644
index 000000000..25bd911fb
--- /dev/null
+++ b/lib/pleroma/object/containment.ex
@@ -0,0 +1,61 @@
+defmodule Pleroma.Object.Containment do
+ @moduledoc """
+ # Object Containment
+
+ This module contains some useful functions for containing objects to specific
+ origins and determining those origins. They previously lived in the
+ ActivityPub `Transmogrifier` module.
+
+ Object containment is an important step in validating remote objects to prevent
+ spoofing, therefore removal of object containment functions is NOT recommended.
+ """
+ def get_actor(%{"actor" => actor}) when is_binary(actor) do
+ actor
+ end
+
+ def get_actor(%{"actor" => actor}) when is_list(actor) do
+ if is_binary(Enum.at(actor, 0)) do
+ Enum.at(actor, 0)
+ else
+ Enum.find(actor, fn %{"type" => type} -> type in ["Person", "Service", "Application"] end)
+ |> Map.get("id")
+ end
+ end
+
+ def get_actor(%{"actor" => %{"id" => id}}) when is_bitstring(id) do
+ id
+ end
+
+ def get_actor(%{"actor" => nil, "attributedTo" => actor}) when not is_nil(actor) do
+ get_actor(%{"actor" => actor})
+ end
+
+ @doc """
+ Checks that an imported AP object's actor matches the domain it came from.
+ """
+ def contain_origin(_id, %{"actor" => nil}), do: :error
+
+ def contain_origin(id, %{"actor" => _actor} = params) do
+ id_uri = URI.parse(id)
+ actor_uri = URI.parse(get_actor(params))
+
+ if id_uri.host == actor_uri.host do
+ :ok
+ else
+ :error
+ end
+ end
+
+ def contain_origin_from_id(_id, %{"id" => nil}), do: :error
+
+ def contain_origin_from_id(id, %{"id" => other_id} = _params) do
+ id_uri = URI.parse(id)
+ other_uri = URI.parse(other_id)
+
+ if id_uri.host == other_uri.host do
+ :ok
+ else
+ :error
+ end
+ end
+end
diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex
new file mode 100644
index 000000000..8d4bcc95e
--- /dev/null
+++ b/lib/pleroma/object/fetcher.ex
@@ -0,0 +1,75 @@
+defmodule Pleroma.Object.Fetcher do
+ alias Pleroma.Object
+ alias Pleroma.Object.Containment
+ alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.OStatus
+
+ require Logger
+
+ @httpoison Application.get_env(:pleroma, :httpoison)
+
+ # TODO:
+ # This will create a Create activity, which we need internally at the moment.
+ def fetch_object_from_id(id) do
+ if object = Object.get_cached_by_ap_id(id) do
+ {:ok, object}
+ else
+ Logger.info("Fetching #{id} via AP")
+
+ with {:ok, data} <- fetch_and_contain_remote_object_from_id(id),
+ nil <- Object.normalize(data, false),
+ params <- %{
+ "type" => "Create",
+ "to" => data["to"],
+ "cc" => data["cc"],
+ "actor" => data["actor"] || data["attributedTo"],
+ "object" => data
+ },
+ :ok <- Containment.contain_origin(id, params),
+ {:ok, activity} <- Transmogrifier.handle_incoming(params) do
+ {:ok, Object.normalize(activity, false)}
+ else
+ {:error, {:reject, nil}} ->
+ {:reject, nil}
+
+ object = %Object{} ->
+ {:ok, object}
+
+ _e ->
+ Logger.info("Couldn't get object via AP, trying out OStatus fetching...")
+
+ case OStatus.fetch_activity_from_url(id) do
+ {:ok, [activity | _]} -> {:ok, Object.normalize(activity, false)}
+ e -> e
+ end
+ end
+ end
+ end
+
+ def fetch_object_from_id!(id) do
+ with {:ok, object} <- fetch_object_from_id(id) do
+ object
+ else
+ _e ->
+ nil
+ end
+ end
+
+ def fetch_and_contain_remote_object_from_id(id) do
+ Logger.info("Fetching object #{id} via AP")
+
+ with true <- String.starts_with?(id, "http"),
+ {:ok, %{body: body, status: code}} when code in 200..299 <-
+ @httpoison.get(
+ id,
+ [{:Accept, "application/activity+json"}]
+ ),
+ {:ok, data} <- Jason.decode(body),
+ :ok <- Containment.contain_origin_from_id(id, data) do
+ {:ok, data}
+ else
+ e ->
+ {:error, e}
+ end
+ end
+end
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 78eb29ddd..f1feab279 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -269,6 +269,7 @@ defmodule Pleroma.User do
def register(%Ecto.Changeset{} = changeset) do
with {:ok, user} <- Repo.insert(changeset),
{:ok, user} <- autofollow_users(user),
+ {:ok, user} <- set_cache(user),
{:ok, _} <- Pleroma.User.WelcomeMessage.post_welcome_message_to_user(user),
{:ok, _} <- try_send_confirmation_email(user) do
{:ok, user}
@@ -453,10 +454,13 @@ defmodule Pleroma.User do
name = List.last(String.split(ap_id, "/"))
nickname = "#{name}@#{domain}"
- get_by_nickname(nickname)
+ get_cached_by_nickname(nickname)
end
- def set_cache(user) do
+ def set_cache({:ok, user}), do: set_cache(user)
+ def set_cache({:error, err}), do: {:error, err}
+
+ def set_cache(%User{} = user) do
Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user)
Cachex.put(:user_cache, "nickname:#{user.nickname}", user)
Cachex.put(:user_cache, "user_info:#{user.id}", user_info(user))
@@ -544,6 +548,7 @@ defmodule Pleroma.User do
with [_nick, _domain] <- String.split(nickname, "@"),
{:ok, user} <- fetch_by_nickname(nickname) do
if Pleroma.Config.get([:fetch_initial_posts, :enabled]) do
+ # TODO turn into job
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
end
@@ -1002,7 +1007,7 @@ defmodule Pleroma.User do
# helper to handle the block given only an actor's AP id
def block(blocker, %{ap_id: ap_id}) do
- block(blocker, User.get_by_ap_id(ap_id))
+ block(blocker, get_cached_by_ap_id(ap_id))
end
def unblock(blocker, %{ap_id: ap_id}) do
@@ -1032,7 +1037,7 @@ defmodule Pleroma.User do
end
def subscribed_to?(user, %{ap_id: ap_id}) do
- with %User{} = target <- User.get_by_ap_id(ap_id) do
+ with %User{} = target <- get_cached_by_ap_id(ap_id) do
Enum.member?(target.info.subscribers, user.ap_id)
end
end
@@ -1207,7 +1212,7 @@ defmodule Pleroma.User do
end
def get_or_fetch_by_ap_id(ap_id) do
- user = get_by_ap_id(ap_id)
+ user = get_cached_by_ap_id(ap_id)
if !is_nil(user) and !User.needs_update?(user) do
user
@@ -1230,7 +1235,7 @@ defmodule Pleroma.User do
def get_or_create_instance_user do
relay_uri = "#{Pleroma.Web.Endpoint.url()}/relay"
- if user = get_by_ap_id(relay_uri) do
+ if user = get_cached_by_ap_id(relay_uri) do
user
else
changes =
@@ -1277,13 +1282,11 @@ defmodule Pleroma.User do
defp blank?(n), do: n
def insert_or_update_user(data) do
- data =
- data
- |> Map.put(:name, blank?(data[:name]) || data[:nickname])
-
- cs = User.remote_user_creation(data)
-
- Repo.insert(cs, on_conflict: :replace_all, conflict_target: :nickname)
+ data
+ |> Map.put(:name, blank?(data[:name]) || data[:nickname])
+ |> remote_user_creation()
+ |> Repo.insert(on_conflict: :replace_all, conflict_target: :nickname)
+ |> set_cache()
end
def ap_enabled?(%User{local: true}), do: true
@@ -1299,8 +1302,8 @@ defmodule Pleroma.User do
# this is because we have synchronous follow APIs and need to simulate them
# with an async handshake
def wait_and_refresh(_, %User{local: true} = a, %User{local: true} = b) do
- with %User{} = a <- User.get_by_id(a.id),
- %User{} = b <- User.get_by_id(b.id) do
+ with %User{} = a <- User.get_cached_by_id(a.id),
+ %User{} = b <- User.get_cached_by_id(b.id) do
{:ok, a, b}
else
_e ->
@@ -1310,8 +1313,8 @@ defmodule Pleroma.User do
def wait_and_refresh(timeout, %User{} = a, %User{} = b) do
with :ok <- :timer.sleep(timeout),
- %User{} = a <- User.get_by_id(a.id),
- %User{} = b <- User.get_by_id(b.id) do
+ %User{} = a <- User.get_cached_by_id(a.id),
+ %User{} = b <- User.get_cached_by_id(b.id) do
{:ok, a, b}
else
_e ->
@@ -1350,7 +1353,7 @@ defmodule Pleroma.User do
end
def tag(nickname, tags) when is_binary(nickname),
- do: tag(User.get_by_nickname(nickname), tags)
+ do: tag(get_by_nickname(nickname), tags)
def tag(%User{} = user, tags),
do: update_tags(user, Enum.uniq((user.tags || []) ++ normalize_tags(tags)))
@@ -1362,7 +1365,7 @@ defmodule Pleroma.User do
end
def untag(nickname, tags) when is_binary(nickname),
- do: untag(User.get_by_nickname(nickname), tags)
+ do: untag(get_by_nickname(nickname), tags)
def untag(%User{} = user, tags),
do: update_tags(user, (user.tags || []) -- normalize_tags(tags))
diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex
index 5afa7988c..7f22a45b5 100644
--- a/lib/pleroma/user/info.ex
+++ b/lib/pleroma/user/info.ex
@@ -38,6 +38,7 @@ defmodule Pleroma.User.Info do
field(:salmon, :string, default: nil)
field(:hide_followers, :boolean, default: false)
field(:hide_follows, :boolean, default: false)
+ field(:hide_favorites, :boolean, default: true)
field(:pinned_activities, {:array, :string}, default: [])
field(:flavour, :string, default: nil)
@@ -202,6 +203,7 @@ defmodule Pleroma.User.Info do
:banner,
:hide_follows,
:hide_followers,
+ :hide_favorites,
:background,
:show_role
])
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index cb88ba308..604ffae7b 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
alias Pleroma.Instances
alias Pleroma.Notification
alias Pleroma.Object
+ alias Pleroma.Object.Fetcher
alias Pleroma.Pagination
alias Pleroma.Repo
alias Pleroma.Upload
@@ -14,7 +15,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
alias Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.Federator
- alias Pleroma.Web.OStatus
alias Pleroma.Web.WebFinger
import Ecto.Query
@@ -95,7 +95,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
"type" => "Create"
}) do
if is_public?(object) do
- Activity.increase_replies_count(reply_ap_id)
Object.increase_replies_count(reply_ap_id)
end
end
@@ -106,7 +105,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
data: %{"inReplyTo" => reply_ap_id} = object
}) do
if is_public?(object) do
- Activity.decrease_replies_count(reply_ap_id)
Object.decrease_replies_count(reply_ap_id)
end
end
@@ -121,7 +119,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
{:ok, map} <- MRF.filter(map),
{recipients, _, _} = get_recipients(map),
{:fake, false, map, recipients} <- {:fake, fake, map, recipients},
- {:ok, object} <- insert_full_object(map) do
+ {:ok, map, object} <- insert_full_object(map) do
{:ok, activity} =
Repo.insert(%Activity{
data: map,
@@ -170,6 +168,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
public = "https://www.w3.org/ns/activitystreams#Public"
if activity.data["type"] in ["Create", "Announce", "Delete"] do
+ object = Object.normalize(activity)
Pleroma.Web.Streamer.stream("user", activity)
Pleroma.Web.Streamer.stream("list", activity)
@@ -181,12 +180,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
if activity.data["type"] in ["Create"] do
- activity.data["object"]
+ object.data
|> Map.get("tag", [])
|> Enum.filter(fn tag -> is_bitstring(tag) end)
|> Enum.each(fn tag -> Pleroma.Web.Streamer.stream("hashtag:" <> tag, activity) end)
- if activity.data["object"]["attachment"] != [] do
+ if object.data["attachment"] != [] do
Pleroma.Web.Streamer.stream("public:media", activity)
if activity.local do
@@ -198,7 +197,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
if !Enum.member?(activity.data["cc"] || [], public) &&
!Enum.member?(
activity.data["to"],
- User.get_by_ap_id(activity.data["actor"]).follower_address
+ User.get_cached_by_ap_id(activity.data["actor"]).follower_address
),
do: Pleroma.Web.Streamer.stream("direct", activity)
end
@@ -572,37 +571,49 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_since(query, _), do: query
+ defp restrict_tag_reject(_query, %{"tag_reject" => _tag_reject, "skip_preload" => true}) do
+ raise "Can't use the child object without preloading!"
+ end
+
defp restrict_tag_reject(query, %{"tag_reject" => tag_reject})
when is_list(tag_reject) and tag_reject != [] do
from(
- activity in query,
- where: fragment(~s(\(not \(? #> '{"object","tag"}'\) \\?| ?\)), activity.data, ^tag_reject)
+ [_activity, object] in query,
+ where: fragment("not (?)->'tag' \\?| (?)", object.data, ^tag_reject)
)
end
defp restrict_tag_reject(query, _), do: query
+ defp restrict_tag_all(_query, %{"tag_all" => _tag_all, "skip_preload" => true}) do
+ raise "Can't use the child object without preloading!"
+ end
+
defp restrict_tag_all(query, %{"tag_all" => tag_all})
when is_list(tag_all) and tag_all != [] do
from(
- activity in query,
- where: fragment(~s(\(? #> '{"object","tag"}'\) \\?& ?), activity.data, ^tag_all)
+ [_activity, object] in query,
+ where: fragment("(?)->'tag' \\?& (?)", object.data, ^tag_all)
)
end
defp restrict_tag_all(query, _), do: query
+ defp restrict_tag(_query, %{"tag" => _tag, "skip_preload" => true}) do
+ raise "Can't use the child object without preloading!"
+ end
+
defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do
from(
- activity in query,
- where: fragment(~s(\(? #> '{"object","tag"}'\) \\?| ?), activity.data, ^tag)
+ [_activity, object] in query,
+ where: fragment("(?)->'tag' \\?| (?)", object.data, ^tag)
)
end
defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do
from(
- activity in query,
- where: fragment(~s(? <@ (? #> '{"object","tag"}'\)), ^tag, activity.data)
+ [_activity, object] in query,
+ where: fragment("(?)->'tag' \\? (?)", object.data, ^tag)
)
end
@@ -667,10 +678,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_favorited_by(query, _), do: query
+ defp restrict_media(_query, %{"only_media" => _val, "skip_preload" => true}) do
+ raise "Can't use the child object without preloading!"
+ end
+
defp restrict_media(query, %{"only_media" => val}) when val == "true" or val == "1" do
from(
- activity in query,
- where: fragment(~s(not (? #> '{"object","attachment"}' = ?\)), activity.data, ^[])
+ [_activity, object] in query,
+ where: fragment("not (?)->'attachment' = (?)", object.data, ^[])
)
end
@@ -866,7 +881,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
def fetch_and_prepare_user_from_ap_id(ap_id) do
- with {:ok, data} <- fetch_and_contain_remote_object_from_id(ap_id) do
+ with {:ok, data} <- Fetcher.fetch_and_contain_remote_object_from_id(ap_id) do
user_data_from_user_object(data)
else
e -> Logger.error("Could not decode user at fetch #{ap_id}, #{inspect(e)}")
@@ -874,7 +889,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
def make_user_from_ap_id(ap_id) do
- if _user = User.get_by_ap_id(ap_id) do
+ if _user = User.get_cached_by_ap_id(ap_id) do
Transmogrifier.upgrade_user_from_ap_id(ap_id)
else
with {:ok, data} <- fetch_and_prepare_user_from_ap_id(ap_id) do
@@ -976,60 +991,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
end
- # TODO:
- # This will create a Create activity, which we need internally at the moment.
- def fetch_object_from_id(id) do
- if object = Object.get_cached_by_ap_id(id) do
- {:ok, object}
- else
- with {:ok, data} <- fetch_and_contain_remote_object_from_id(id),
- nil <- Object.normalize(data),
- params <- %{
- "type" => "Create",
- "to" => data["to"],
- "cc" => data["cc"],
- "actor" => data["actor"] || data["attributedTo"],
- "object" => data
- },
- :ok <- Transmogrifier.contain_origin(id, params),
- {:ok, activity} <- Transmogrifier.handle_incoming(params) do
- {:ok, Object.normalize(activity)}
- else
- {:error, {:reject, nil}} ->
- {:reject, nil}
-
- object = %Object{} ->
- {:ok, object}
-
- _e ->
- Logger.info("Couldn't get object via AP, trying out OStatus fetching...")
-
- case OStatus.fetch_activity_from_url(id) do
- {:ok, [activity | _]} -> {:ok, Object.normalize(activity)}
- e -> e
- end
- end
- end
- end
-
- def fetch_and_contain_remote_object_from_id(id) do
- Logger.info("Fetching object #{id} via AP")
-
- with true <- String.starts_with?(id, "http"),
- {:ok, %{body: body, status: code}} when code in 200..299 <-
- @httpoison.get(
- id,
- [{:Accept, "application/activity+json"}]
- ),
- {:ok, data} <- Jason.decode(body),
- :ok <- Transmogrifier.contain_origin_from_id(id, data) do
- {:ok, data}
- else
- e ->
- {:error, e}
- end
- end
-
# filter out broken threads
def contain_broken_threads(%Activity{} = activity, %User{} = user) do
entire_thread_visible_for_user?(activity, user)
diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex
index 3331ebebd..0b80566bf 100644
--- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
alias Pleroma.Activity
alias Pleroma.Object
+ alias Pleroma.Object.Fetcher
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.ObjectView
@@ -173,7 +174,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
"Signature missing or not from author, relayed Create message, fetching object from source"
)
- ActivityPub.fetch_object_from_id(params["object"]["id"])
+ Fetcher.fetch_object_from_id(params["object"]["id"])
json(conn, "ok")
end
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 39cd31921..52666a409 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -8,8 +8,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
"""
alias Pleroma.Activity
alias Pleroma.Object
+ alias Pleroma.Object.Containment
alias Pleroma.Repo
alias Pleroma.User
+ alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.ActivityPub.Visibility
@@ -18,56 +20,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
require Logger
- def get_actor(%{"actor" => actor}) when is_binary(actor) do
- actor
- end
-
- def get_actor(%{"actor" => actor}) when is_list(actor) do
- if is_binary(Enum.at(actor, 0)) do
- Enum.at(actor, 0)
- else
- Enum.find(actor, fn %{"type" => type} -> type in ["Person", "Service", "Application"] end)
- |> Map.get("id")
- end
- end
-
- def get_actor(%{"actor" => %{"id" => id}}) when is_bitstring(id) do
- id
- end
-
- def get_actor(%{"actor" => nil, "attributedTo" => actor}) when not is_nil(actor) do
- get_actor(%{"actor" => actor})
- end
-
- @doc """
- Checks that an imported AP object's actor matches the domain it came from.
- """
- def contain_origin(_id, %{"actor" => nil}), do: :error
-
- def contain_origin(id, %{"actor" => _actor} = params) do
- id_uri = URI.parse(id)
- actor_uri = URI.parse(get_actor(params))
-
- if id_uri.host == actor_uri.host do
- :ok
- else
- :error
- end
- end
-
- def contain_origin_from_id(_id, %{"id" => nil}), do: :error
-
- def contain_origin_from_id(id, %{"id" => other_id} = _params) do
- id_uri = URI.parse(id)
- other_uri = URI.parse(other_id)
-
- if id_uri.host == other_uri.host do
- :ok
- else
- :error
- end
- end
-
@doc """
Modifies an incoming AP object (mastodon format) to our internal format.
"""
@@ -188,7 +140,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def fix_actor(%{"attributedTo" => actor} = object) do
object
- |> Map.put("actor", get_actor(%{"actor" => actor}))
+ |> Map.put("actor", Containment.get_actor(%{"actor" => actor}))
end
# Check for standardisation
@@ -223,7 +175,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
""
end
- case fetch_obj_helper(in_reply_to_id) do
+ case get_obj_helper(in_reply_to_id) do
{:ok, replied_object} ->
with %Activity{} = _activity <-
Activity.get_create_by_object_ap_id(replied_object.data["id"]) do
@@ -448,7 +400,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
# - emoji
def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data)
when objtype in ["Article", "Note", "Video", "Page"] do
- actor = get_actor(data)
+ actor = Containment.get_actor(data)
data =
Map.put(data, "actor", actor)
@@ -506,7 +458,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def handle_incoming(
%{"type" => "Accept", "object" => follow_object, "actor" => _actor, "id" => _id} = data
) do
- with actor <- get_actor(data),
+ with actor <- Containment.get_actor(data),
%User{} = followed <- User.get_or_fetch_by_ap_id(actor),
{:ok, follow_activity} <- get_follow_activity(follow_object, followed),
{:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"),
@@ -532,7 +484,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def handle_incoming(
%{"type" => "Reject", "object" => follow_object, "actor" => _actor, "id" => _id} = data
) do
- with actor <- get_actor(data),
+ with actor <- Containment.get_actor(data),
%User{} = followed <- User.get_or_fetch_by_ap_id(actor),
{:ok, follow_activity} <- get_follow_activity(follow_object, followed),
{:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"),
@@ -556,9 +508,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def handle_incoming(
%{"type" => "Like", "object" => object_id, "actor" => _actor, "id" => id} = data
) do
- with actor <- get_actor(data),
+ with actor <- Containment.get_actor(data),
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
- {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
+ {:ok, object} <- get_obj_helper(object_id),
{:ok, activity, _object} <- ActivityPub.like(actor, object, id, false) do
{:ok, activity}
else
@@ -569,9 +521,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def handle_incoming(
%{"type" => "Announce", "object" => object_id, "actor" => _actor, "id" => id} = data
) do
- with actor <- get_actor(data),
+ with actor <- Containment.get_actor(data),
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
- {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
+ {:ok, object} <- get_obj_helper(object_id),
public <- Visibility.is_public?(data),
{:ok, activity, _object} <- ActivityPub.announce(actor, object, id, false, public) do
{:ok, activity}
@@ -585,7 +537,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
data
)
when object_type in ["Person", "Application", "Service", "Organization"] do
- with %User{ap_id: ^actor_id} = actor <- User.get_by_ap_id(object["id"]) do
+ with %User{ap_id: ^actor_id} = actor <- User.get_cached_by_ap_id(object["id"]) do
{:ok, new_user_data} = ActivityPub.user_data_from_user_object(object)
banner = new_user_data[:info]["banner"]
@@ -624,10 +576,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
) do
object_id = Utils.get_ap_id(object_id)
- with actor <- get_actor(data),
+ with actor <- Containment.get_actor(data),
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
- {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
- :ok <- contain_origin(actor.ap_id, object.data),
+ {:ok, object} <- get_obj_helper(object_id),
+ :ok <- Containment.contain_origin(actor.ap_id, object.data),
{:ok, activity} <- ActivityPub.delete(object, false) do
{:ok, activity}
else
@@ -643,9 +595,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
"id" => id
} = data
) do
- with actor <- get_actor(data),
+ with actor <- Containment.get_actor(data),
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
- {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
+ {:ok, object} <- get_obj_helper(object_id),
{:ok, activity, _} <- ActivityPub.unannounce(actor, object, id, false) do
{:ok, activity}
else
@@ -713,9 +665,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
"id" => id
} = data
) do
- with actor <- get_actor(data),
+ with actor <- Containment.get_actor(data),
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
- {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id),
+ {:ok, object} <- get_obj_helper(object_id),
{:ok, activity, _, _} <- ActivityPub.unlike(actor, object, id, false) do
{:ok, activity}
else
@@ -725,9 +677,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def handle_incoming(_), do: :error
- def fetch_obj_helper(id) when is_bitstring(id), do: ActivityPub.fetch_object_from_id(id)
- def fetch_obj_helper(obj) when is_map(obj), do: ActivityPub.fetch_object_from_id(obj["id"])
-
def get_obj_helper(id) do
if object = Object.normalize(id), do: {:ok, object}, else: nil
end
@@ -764,9 +713,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
# internal -> Mastodon
# """
- def prepare_outgoing(%{"type" => "Create", "object" => object} = data) do
+ def prepare_outgoing(%{"type" => "Create", "object" => object_id} = data) do
object =
- object
+ Object.normalize(object_id).data
|> prepare_object
data =
@@ -827,7 +776,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def maybe_fix_object_url(data) do
if is_binary(data["object"]) and not String.starts_with?(data["object"], "http") do
- case fetch_obj_helper(data["object"]) do
+ case get_obj_helper(data["object"]) do
{:ok, relative_object} ->
if relative_object.data["external_url"] do
_data =
@@ -1015,7 +964,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
def upgrade_user_from_ap_id(ap_id) do
- with %User{local: false} = user <- User.get_by_ap_id(ap_id),
+ with %User{local: false} = user <- User.get_cached_by_ap_id(ap_id),
{:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id),
already_ap <- User.ap_enabled?(user),
{:ok, user} <- user |> User.upgrade_changeset(data) |> User.update_and_set_cache() do
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index ccc9da7c6..581b9d1ab 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -234,14 +234,18 @@ defmodule Pleroma.Web.ActivityPub.Utils do
@doc """
Inserts a full object if it is contained in an activity.
"""
- def insert_full_object(%{"object" => %{"type" => type} = object_data})
+ def insert_full_object(%{"object" => %{"type" => type} = object_data} = map)
when is_map(object_data) and type in @supported_object_types do
with {:ok, object} <- Object.create(object_data) do
- {:ok, object}
+ map =
+ map
+ |> Map.put("object", object.data["id"])
+
+ {:ok, map, object}
end
end
- def insert_full_object(_), do: {:ok, nil}
+ def insert_full_object(map), do: {:ok, map, nil}
def update_object_in_activities(%{data: %{"id" => id}} = object) do
# TODO
diff --git a/lib/pleroma/web/activity_pub/visibility.ex b/lib/pleroma/web/activity_pub/visibility.ex
index db52fe933..6dee61dd6 100644
--- a/lib/pleroma/web/activity_pub/visibility.ex
+++ b/lib/pleroma/web/activity_pub/visibility.ex
@@ -41,16 +41,21 @@ defmodule Pleroma.Web.ActivityPub.Visibility do
# guard
def entire_thread_visible_for_user?(nil, _user), do: false
- # child
+ # XXX: Probably even more inefficient than the previous implementation intended to be a placeholder untill https://git.pleroma.social/pleroma/pleroma/merge_requests/971 is in develop
+ # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
+
def entire_thread_visible_for_user?(
- %Activity{data: %{"object" => %{"inReplyTo" => parent_id}}} = tail,
+ %Activity{} = tail,
+ # %Activity{data: %{"object" => %{"inReplyTo" => parent_id}}} = tail,
user
- )
- when is_binary(parent_id) do
- parent = Activity.get_in_reply_to_activity(tail)
- visible_for_user?(tail, user) && entire_thread_visible_for_user?(parent, user)
+ ) do
+ case Object.normalize(tail) do
+ %{data: %{"inReplyTo" => parent_id}} when is_binary(parent_id) ->
+ parent = Activity.get_in_reply_to_activity(tail)
+ visible_for_user?(tail, user) && entire_thread_visible_for_user?(parent, user)
+
+ _ ->
+ visible_for_user?(tail, user)
+ end
end
-
- # root
- def entire_thread_visible_for_user?(tail, user), do: visible_for_user?(tail, user)
end
diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex
index c436715d5..711f233a6 100644
--- a/lib/pleroma/web/admin_api/admin_api_controller.ex
+++ b/lib/pleroma/web/admin_api/admin_api_controller.ex
@@ -19,7 +19,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
action_fallback(:errors)
def user_delete(conn, %{"nickname" => nickname}) do
- User.get_by_nickname(nickname)
+ User.get_cached_by_nickname(nickname)
|> User.delete()
conn
@@ -27,8 +27,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
end
def user_follow(conn, %{"follower" => follower_nick, "followed" => followed_nick}) do
- with %User{} = follower <- User.get_by_nickname(follower_nick),
- %User{} = followed <- User.get_by_nickname(followed_nick) do
+ with %User{} = follower <- User.get_cached_by_nickname(follower_nick),
+ %User{} = followed <- User.get_cached_by_nickname(followed_nick) do
User.follow(follower, followed)
end
@@ -37,8 +37,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
end
def user_unfollow(conn, %{"follower" => follower_nick, "followed" => followed_nick}) do
- with %User{} = follower <- User.get_by_nickname(follower_nick),
- %User{} = followed <- User.get_by_nickname(followed_nick) do
+ with %User{} = follower <- User.get_cached_by_nickname(follower_nick),
+ %User{} = followed <- User.get_cached_by_nickname(followed_nick) do
User.unfollow(follower, followed)
end
@@ -67,7 +67,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
end
def user_show(conn, %{"nickname" => nickname}) do
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
conn
|> json(AccountView.render("show.json", %{user: user}))
else
@@ -76,7 +76,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
end
def user_toggle_activation(conn, %{"nickname" => nickname}) do
- user = User.get_by_nickname(nickname)
+ user = User.get_cached_by_nickname(nickname)
{:ok, updated_user} = User.deactivate(user, !user.info.deactivated)
@@ -131,7 +131,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
def right_add(conn, %{"permission_group" => permission_group, "nickname" => nickname})
when permission_group in ["moderator", "admin"] do
- user = User.get_by_nickname(nickname)
+ user = User.get_cached_by_nickname(nickname)
info =
%{}
@@ -156,7 +156,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
end
def right_get(conn, %{"nickname" => nickname}) do
- user = User.get_by_nickname(nickname)
+ user = User.get_cached_by_nickname(nickname)
conn
|> json(%{
@@ -178,7 +178,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|> put_status(403)
|> json(%{error: "You can't revoke your own admin status."})
else
- user = User.get_by_nickname(nickname)
+ user = User.get_cached_by_nickname(nickname)
info =
%{}
@@ -204,7 +204,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
def set_activation_status(conn, %{"nickname" => nickname, "status" => status}) do
with {:ok, status} <- Ecto.Type.cast(:boolean, status),
- %User{} = user <- User.get_by_nickname(nickname),
+ %User{} = user <- User.get_cached_by_nickname(nickname),
{:ok, _} <- User.deactivate(user, !status),
do: json_response(conn, :no_content, "")
end
@@ -277,7 +277,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
@doc "Get a password reset token (base64 string) for given nickname"
def get_password_reset(conn, %{"nickname" => nickname}) do
- (%User{local: true} = user) = User.get_by_nickname(nickname)
+ (%User{local: true} = user) = User.get_cached_by_nickname(nickname)
{:ok, token} = Pleroma.PasswordResetToken.create_token(user)
conn
diff --git a/lib/pleroma/web/channels/user_socket.ex b/lib/pleroma/web/channels/user_socket.ex
index 6503979a1..8e2759e3b 100644
--- a/lib/pleroma/web/channels/user_socket.ex
+++ b/lib/pleroma/web/channels/user_socket.ex
@@ -24,7 +24,7 @@ defmodule Pleroma.Web.UserSocket do
def connect(%{"token" => token}, socket) do
with true <- Pleroma.Config.get([:chat, :enabled]),
{:ok, user_id} <- Phoenix.Token.verify(socket, "user socket", token, max_age: 84_600),
- %User{} = user <- Pleroma.User.get_by_id(user_id) do
+ %User{} = user <- Pleroma.User.get_cached_by_id(user_id) do
{:ok, assign(socket, :user_name, user.nickname)}
else
_e -> :error
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index 74babdf14..cfbc5dc10 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -125,7 +125,10 @@ defmodule Pleroma.Web.CommonAPI do
"public"
in_reply_to ->
- Pleroma.Web.MastodonAPI.StatusView.get_visibility(in_reply_to.data["object"])
+ # XXX: these heuristics should be moved out of MastodonAPI.
+ with %Object{} = object <- Object.normalize(in_reply_to) do
+ Pleroma.Web.MastodonAPI.StatusView.get_visibility(object)
+ end
end
end
@@ -214,8 +217,10 @@ defmodule Pleroma.Web.CommonAPI do
with %Activity{
actor: ^user_ap_id,
data: %{
- "type" => "Create",
- "object" => %{
+ "type" => "Create"
+ },
+ object: %Object{
+ data: %{
"to" => object_to,
"type" => "Note"
}
@@ -279,7 +284,7 @@ defmodule Pleroma.Web.CommonAPI do
def report(user, data) do
with {:account_id, %{"account_id" => account_id}} <- {:account_id, data},
- {:account, %User{} = account} <- {:account, User.get_by_id(account_id)},
+ {:account, %User{} = account} <- {:account, User.get_cached_by_id(account_id)},
{:ok, {content_html, _, _}} <- make_report_content_html(data["comment"]),
{:ok, statuses} <- get_report_statuses(account, data),
{:ok, activity} <-
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 185292878..887f878c4 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -208,7 +208,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
context,
content_html,
attachments,
- inReplyTo,
+ in_reply_to,
tags,
cw \\ nil,
cc \\ []
@@ -225,9 +225,11 @@ defmodule Pleroma.Web.CommonAPI.Utils do
"tag" => tags |> Enum.map(fn {_, tag} -> tag end) |> Enum.uniq()
}
- if inReplyTo do
+ if in_reply_to do
+ in_reply_to_object = Object.normalize(in_reply_to)
+
object
- |> Map.put("inReplyTo", inReplyTo.data["object"]["id"])
+ |> Map.put("inReplyTo", in_reply_to_object.data["id"])
else
object
end
@@ -282,7 +284,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
end
def confirm_current_password(user, password) do
- with %User{local: true} = db_user <- User.get_by_id(user.id),
+ with %User{local: true} = db_user <- User.get_cached_by_id(user.id),
true <- Pbkdf2.checkpw(password, db_user.password_hash) do
{:ok, db_user}
else
diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex
index c47328e13..29e178ba9 100644
--- a/lib/pleroma/web/federator/federator.ex
+++ b/lib/pleroma/web/federator/federator.ex
@@ -4,6 +4,7 @@
defmodule Pleroma.Web.Federator do
alias Pleroma.Activity
+ alias Pleroma.Object.Containment
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Relay
@@ -136,7 +137,7 @@ defmodule Pleroma.Web.Federator do
# actor shouldn't be acting on objects outside their own AP server.
with {:ok, _user} <- ap_enabled_actor(params["actor"]),
nil <- Activity.normalize(params["id"]),
- :ok <- Transmogrifier.contain_origin_from_id(params["actor"], params),
+ :ok <- Containment.contain_origin_from_id(params["actor"], params),
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
{:ok, activity}
else
@@ -185,7 +186,7 @@ defmodule Pleroma.Web.Federator do
end
def ap_enabled_actor(id) do
- user = User.get_by_ap_id(id)
+ user = User.get_cached_by_ap_id(id)
if User.ap_enabled?(user) do
{:ok, user}
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api.ex b/lib/pleroma/web/mastodon_api/mastodon_api.ex
index 382f07e6b..3a3ec7c2a 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api.ex
@@ -7,6 +7,31 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
alias Pleroma.Pagination
alias Pleroma.ScheduledActivity
alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+
+ def follow(follower, followed, params \\ %{}) do
+ options = cast_params(params)
+ reblogs = options[:reblogs]
+
+ result =
+ if not User.following?(follower, followed) do
+ CommonAPI.follow(follower, followed)
+ else
+ {:ok, follower, followed, nil}
+ end
+
+ with {:ok, follower, followed, _} <- result do
+ reblogs
+ |> case do
+ false -> CommonAPI.hide_reblogs(follower, followed)
+ _ -> CommonAPI.show_reblogs(follower, followed)
+ end
+ |> case do
+ {:ok, follower} -> {:ok, follower}
+ _ -> {:ok, follower}
+ end
+ end
+ end
def get_followers(user, params \\ %{}) do
user
@@ -37,7 +62,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
defp cast_params(params) do
param_types = %{
- exclude_types: {:array, :string}
+ exclude_types: {:array, :string},
+ reblogs: :boolean
}
changeset = cast({%{}, param_types}, params, Map.keys(param_types))
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 63fadce38..0ba8d9eea 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -4,13 +4,13 @@
defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
use Pleroma.Web, :controller
-
alias Ecto.Changeset
alias Pleroma.Activity
alias Pleroma.Config
alias Pleroma.Filter
alias Pleroma.Notification
alias Pleroma.Object
+ alias Pleroma.Object.Fetcher
alias Pleroma.Pagination
alias Pleroma.Repo
alias Pleroma.ScheduledActivity
@@ -190,7 +190,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
"static_url" => url,
"visible_in_picker" => true,
"url" => url,
- "tags" => String.split(tags, ",")
+ "tags" => tags
}
end)
end
@@ -304,7 +304,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do
- with %User{} = user <- User.get_by_id(params["id"]) do
+ with %User{} = user <- User.get_cached_by_id(params["id"]) do
activities = ActivityPub.fetch_user_activities(user, reading_user, params)
conn
@@ -338,7 +338,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
- with %Activity{} = activity <- Activity.get_by_id(id),
+ with %Activity{} = activity <- Activity.get_by_id_with_object(id),
true <- Visibility.visible_for_user?(activity, user) do
conn
|> put_view(StatusView)
@@ -487,7 +487,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def reblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
- with {:ok, announce, _activity} <- CommonAPI.repeat(ap_id_or_id, user) do
+ with {:ok, announce, _activity} <- CommonAPI.repeat(ap_id_or_id, user),
+ %Activity{} = announce <- Activity.normalize(announce.data) do
conn
|> put_view(StatusView)
|> try_render("status.json", %{activity: announce, for: user, as: :activity})
@@ -496,7 +497,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => 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
+ %Activity{} = activity <- Activity.get_create_by_object_ap_id_with_object(id) do
conn
|> put_view(StatusView)
|> try_render("status.json", %{activity: activity, for: user, as: :activity})
@@ -543,10 +544,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def bookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
- with %Activity{} = activity <- Activity.get_by_id(id),
- %User{} = user <- User.get_by_nickname(user.nickname),
+ with %Activity{} = activity <- Activity.get_by_id_with_object(id),
+ %Object{} = object <- Object.normalize(activity),
+ %User{} = user <- User.get_cached_by_nickname(user.nickname),
true <- Visibility.visible_for_user?(activity, user),
- {:ok, user} <- User.bookmark(user, activity.data["object"]["id"]) do
+ {:ok, user} <- User.bookmark(user, object.data["id"]) do
conn
|> put_view(StatusView)
|> try_render("status.json", %{activity: activity, for: user, as: :activity})
@@ -554,10 +556,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def unbookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
- with %Activity{} = activity <- Activity.get_by_id(id),
- %User{} = user <- User.get_by_nickname(user.nickname),
+ with %Activity{} = activity <- Activity.get_by_id_with_object(id),
+ %Object{} = object <- Object.normalize(activity),
+ %User{} = user <- User.get_cached_by_nickname(user.nickname),
true <- Visibility.visible_for_user?(activity, user),
- {:ok, user} <- User.unbookmark(user, activity.data["object"]["id"]) do
+ {:ok, user} <- User.unbookmark(user, object.data["id"]) do
conn
|> put_view(StatusView)
|> try_render("status.json", %{activity: activity, for: user, as: :activity})
@@ -681,7 +684,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def favourited_by(conn, %{"id" => id}) do
- with %Activity{data: %{"object" => %{"likes" => likes}}} <- Activity.get_by_id(id) do
+ with %Activity{data: %{"object" => object}} <- Repo.get(Activity, id),
+ %Object{data: %{"likes" => likes}} <- Object.normalize(object) do
q = from(u in User, where: u.ap_id in ^likes)
users = Repo.all(q)
@@ -694,7 +698,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def reblogged_by(conn, %{"id" => id}) do
- with %Activity{data: %{"object" => %{"announcements" => announces}}} <- Activity.get_by_id(id) do
+ with %Activity{data: %{"object" => object}} <- Repo.get(Activity, id),
+ %Object{data: %{"announcements" => announces}} <- Object.normalize(object) do
q = from(u in User, where: u.ap_id in ^announces)
users = Repo.all(q)
@@ -745,7 +750,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def followers(%{assigns: %{user: for_user}} = conn, %{"id" => id} = params) do
- with %User{} = user <- User.get_by_id(id),
+ with %User{} = user <- User.get_cached_by_id(id),
followers <- MastodonAPI.get_followers(user, params) do
followers =
cond do
@@ -762,7 +767,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def following(%{assigns: %{user: for_user}} = conn, %{"id" => id} = params) do
- with %User{} = user <- User.get_by_id(id),
+ with %User{} = user <- User.get_cached_by_id(id),
followers <- MastodonAPI.get_friends(user, params) do
followers =
cond do
@@ -787,7 +792,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def authorize_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do
- with %User{} = follower <- User.get_by_id(id),
+ with %User{} = follower <- User.get_cached_by_id(id),
{:ok, follower} <- CommonAPI.accept_follow_request(follower, followed) do
conn
|> put_view(AccountView)
@@ -801,7 +806,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def reject_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do
- with %User{} = follower <- User.get_by_id(id),
+ with %User{} = follower <- User.get_cached_by_id(id),
{:ok, follower} <- CommonAPI.reject_follow_request(follower, followed) do
conn
|> put_view(AccountView)
@@ -817,8 +822,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
with {_, %User{} = followed} <- {:followed, User.get_cached_by_id(id)},
{_, true} <- {:followed, follower.id != followed.id},
- false <- User.following?(follower, followed),
- {:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do
+ {:ok, follower} <- MastodonAPI.follow(follower, followed, conn.params) do
conn
|> put_view(AccountView)
|> render("relationship.json", %{user: follower, target: followed})
@@ -826,19 +830,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
{:followed, _} ->
{:error, :not_found}
- true ->
- followed = User.get_cached_by_id(id)
-
- {:ok, follower} =
- case conn.params["reblogs"] do
- true -> CommonAPI.show_reblogs(follower, followed)
- false -> CommonAPI.hide_reblogs(follower, followed)
- end
-
- conn
- |> put_view(AccountView)
- |> render("relationship.json", %{user: follower, target: followed})
-
{:error, message} ->
conn
|> put_resp_content_type("application/json")
@@ -881,7 +872,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def mute(%{assigns: %{user: muter}} = conn, %{"id" => id}) do
- with %User{} = muted <- User.get_by_id(id),
+ with %User{} = muted <- User.get_cached_by_id(id),
{:ok, muter} <- User.mute(muter, muted) do
conn
|> put_view(AccountView)
@@ -895,7 +886,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def unmute(%{assigns: %{user: muter}} = conn, %{"id" => id}) do
- with %User{} = muted <- User.get_by_id(id),
+ with %User{} = muted <- User.get_cached_by_id(id),
{:ok, muter} <- User.unmute(muter, muted) do
conn
|> put_view(AccountView)
@@ -916,7 +907,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def block(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
- with %User{} = blocked <- User.get_by_id(id),
+ with %User{} = blocked <- User.get_cached_by_id(id),
{:ok, blocker} <- User.block(blocker, blocked),
{:ok, _activity} <- ActivityPub.block(blocker, blocked) do
conn
@@ -931,7 +922,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def unblock(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
- with %User{} = blocked <- User.get_by_id(id),
+ with %User{} = blocked <- User.get_cached_by_id(id),
{:ok, blocker} <- User.unblock(blocker, blocked),
{:ok, _activity} <- ActivityPub.unblock(blocker, blocked) do
conn
@@ -997,7 +988,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
def status_search(user, query) do
fetched =
if Regex.match?(~r/https?:/, query) do
- with {:ok, object} <- ActivityPub.fetch_object_from_id(query),
+ with {:ok, object} <- Fetcher.fetch_object_from_id(query),
%Activity{} = activity <- Activity.get_create_by_object_ap_id(object.data["id"]),
true <- Visibility.visible_for_user?(activity, user) do
[activity]
@@ -1008,13 +999,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
q =
from(
- a in Activity,
+ [a, o] in Activity.with_preloaded_object(Activity),
where: fragment("?->>'type' = 'Create'", a.data),
where: "https://www.w3.org/ns/activitystreams#Public" in a.recipients,
where:
fragment(
- "to_tsvector('english', ?->'object'->>'content') @@ plainto_tsquery('english', ?)",
- a.data,
+ "to_tsvector('english', ?->>'content') @@ plainto_tsquery('english', ?)",
+ o.data,
^query
),
limit: 20,
@@ -1096,8 +1087,45 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|> render("index.json", %{activities: activities, for: user, as: :activity})
end
+ def user_favourites(%{assigns: %{user: for_user}} = conn, %{"id" => id} = params) do
+ with %User{} = user <- User.get_by_id(id),
+ false <- user.info.hide_favorites do
+ params =
+ params
+ |> Map.put("type", "Create")
+ |> Map.put("favorited_by", user.ap_id)
+ |> Map.put("blocking_user", for_user)
+
+ recipients =
+ if for_user do
+ ["https://www.w3.org/ns/activitystreams#Public"] ++
+ [for_user.ap_id | for_user.following]
+ else
+ ["https://www.w3.org/ns/activitystreams#Public"]
+ end
+
+ activities =
+ recipients
+ |> ActivityPub.fetch_activities(params)
+ |> Enum.reverse()
+
+ conn
+ |> add_link_headers(:favourites, activities)
+ |> put_view(StatusView)
+ |> render("index.json", %{activities: activities, for: for_user, as: :activity})
+ else
+ nil ->
+ {:error, :not_found}
+
+ true ->
+ conn
+ |> put_status(403)
+ |> json(%{error: "Can't get favorites"})
+ end
+ end
+
def bookmarks(%{assigns: %{user: user}} = conn, _) do
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
activities =
user.bookmarks
@@ -1154,7 +1182,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
accounts
|> Enum.each(fn account_id ->
with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
- %User{} = followed <- User.get_by_id(account_id) do
+ %User{} = followed <- User.get_cached_by_id(account_id) do
Pleroma.List.follow(list, followed)
end
end)
@@ -1166,7 +1194,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
accounts
|> Enum.each(fn account_id ->
with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
- %User{} = followed <- Pleroma.User.get_by_id(account_id) do
+ %User{} = followed <- Pleroma.User.get_cached_by_id(account_id) do
Pleroma.List.unfollow(list, followed)
end
end)
@@ -1459,7 +1487,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
def relationship_noop(%{assigns: %{user: user}} = conn, %{"id" => id}) do
Logger.debug("Unimplemented, returning unmodified relationship")
- with %User{} = target <- User.get_by_id(id) do
+ with %User{} = target <- User.get_cached_by_id(id) do
conn
|> put_view(AccountView)
|> render("relationship.json", %{user: user, target: target})
diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex
index af56c4149..d87fdb15d 100644
--- a/lib/pleroma/web/mastodon_api/views/account_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/account_view.ex
@@ -68,7 +68,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
defp do_render("account.json", %{user: user} = opts) do
image = User.avatar_url(user) |> MediaProxy.url()
header = User.banner_url(user) |> MediaProxy.url()
- user_info = User.user_info(user)
+ user_info = User.get_cached_user_info(user)
bot = (user.info.source_data["type"] || "Person") in ["Application", "Service"]
emojis =
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index a9f607aa5..7dd80d708 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
alias Pleroma.Activity
alias Pleroma.HTML
+ alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.CommonAPI
@@ -19,8 +20,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
defp get_replied_to_activities(activities) do
activities
|> Enum.map(fn
- %{data: %{"type" => "Create", "object" => %{"inReplyTo" => in_reply_to}}} ->
- in_reply_to != "" && in_reply_to
+ %{data: %{"type" => "Create", "object" => object}} ->
+ object = Object.normalize(object)
+ object.data["inReplyTo"] != "" && object.data["inReplyTo"]
_ ->
nil
@@ -29,7 +31,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|> Activity.create_by_object_ap_id()
|> Repo.all()
|> Enum.reduce(%{}, fn activity, acc ->
- Map.put(acc, activity.data["object"]["id"], activity)
+ object = Object.normalize(activity)
+ Map.put(acc, object.data["id"], activity)
end)
end
@@ -55,8 +58,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
defp get_context_id(_), do: nil
defp reblogged?(activity, user) do
- object = activity.data["object"] || %{}
- present?(user && user.ap_id in (object["announcements"] || []))
+ object = Object.normalize(activity) || %{}
+ present?(user && user.ap_id in (object.data["announcements"] || []))
end
def render("index.json", opts) do
@@ -80,6 +83,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
reblogged_activity = Activity.get_create_by_object_ap_id(object)
reblogged = render("status.json", Map.put(opts, :activity, reblogged_activity))
+ activity_object = Object.normalize(activity)
+ favorited = opts[:for] && opts[:for].ap_id in (activity_object.data["likes"] || [])
+ bookmarked = opts[:for] && activity_object.data["id"] in opts[:for].bookmarks
+
mentions =
activity.recipients
|> Enum.map(fn ap_id -> User.get_cached_by_ap_id(ap_id) end)
@@ -100,8 +107,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
replies_count: 0,
favourites_count: 0,
reblogged: reblogged?(reblogged_activity, opts[:for]),
- favourited: false,
- bookmarked: false,
+ favourited: present?(favorited),
+ bookmarked: present?(bookmarked),
muted: false,
pinned: pinned?(activity, user),
sensitive: false,
@@ -122,14 +129,16 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
}
end
- def render("status.json", %{activity: %{data: %{"object" => object}} = activity} = opts) do
+ def render("status.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
+ object = Object.normalize(activity)
+
user = get_user(activity.data["actor"])
- like_count = object["like_count"] || 0
- announcement_count = object["announcement_count"] || 0
+ like_count = object.data["like_count"] || 0
+ announcement_count = object.data["announcement_count"] || 0
- tags = object["tag"] || []
- sensitive = object["sensitive"] || Enum.member?(tags, "nsfw")
+ tags = object.data["tag"] || []
+ sensitive = object.data["sensitive"] || Enum.member?(tags, "nsfw")
mentions =
activity.recipients
@@ -137,15 +146,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|> Enum.filter(& &1)
|> Enum.map(fn user -> AccountView.render("mention.json", %{user: user}) end)
- favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || [])
- bookmarked = opts[:for] && object["id"] in opts[:for].bookmarks
+ favorited = opts[:for] && opts[:for].ap_id in (object.data["likes"] || [])
- attachment_data = object["attachment"] || []
+ bookmarked = opts[:for] && object.data["id"] in opts[:for].bookmarks
+
+ attachment_data = object.data["attachment"] || []
attachments = render_many(attachment_data, StatusView, "attachment.json", as: :attachment)
- created_at = Utils.to_masto_date(object["published"])
+ created_at = Utils.to_masto_date(object.data["published"])
reply_to = get_reply_to(activity, opts)
+
reply_to_user = reply_to && get_user(reply_to.data["actor"])
content =
@@ -167,7 +178,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
"mastoapi:content"
)
- summary = object["summary"] || ""
+ summary = object.data["summary"] || ""
summary_html =
summary
@@ -190,12 +201,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
if user.local do
Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity)
else
- object["external_url"] || object["id"]
+ object.data["external_url"] || object.data["id"]
end
%{
id: to_string(activity.id),
- uri: object["id"],
+ uri: object.data["id"],
url: url,
account: AccountView.render("account.json", %{user: user}),
in_reply_to_id: reply_to && to_string(reply_to.id),
@@ -205,7 +216,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
content: content_html,
created_at: created_at,
reblogs_count: announcement_count,
- replies_count: object["repliesCount"] || 0,
+ replies_count: object.data["repliesCount"] || 0,
favourites_count: like_count,
reblogged: reblogged?(activity, opts[:for]),
favourited: present?(favorited),
@@ -223,10 +234,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
website: nil
},
language: nil,
- emojis: build_emojis(activity.data["object"]["emoji"]),
+ emojis: build_emojis(object.data["emoji"]),
pleroma: %{
local: activity.local,
conversation_id: get_context_id(activity),
+ in_reply_to_account_acct: reply_to_user && reply_to_user.nickname,
content: %{"text/plain" => content_plaintext},
spoiler_text: %{"text/plain" => summary_plaintext}
}
@@ -305,15 +317,19 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
end
def get_reply_to(activity, %{replied_to_activities: replied_to_activities}) do
- with nil <- replied_to_activities[activity.data["object"]["inReplyTo"]] do
+ object = Object.normalize(activity)
+
+ with nil <- replied_to_activities[object.data["inReplyTo"]] do
# If user didn't participate in the thread
Activity.get_in_reply_to_activity(activity)
end
end
- def get_reply_to(%{data: %{"object" => object}}, _) do
- if object["inReplyTo"] && object["inReplyTo"] != "" do
- Activity.get_create_by_object_ap_id(object["inReplyTo"])
+ def get_reply_to(%{data: %{"object" => _object}} = activity, _) do
+ object = Object.normalize(activity)
+
+ if object.data["inReplyTo"] && object.data["inReplyTo"] != "" do
+ Activity.get_create_by_object_ap_id(object.data["inReplyTo"])
else
nil
end
@@ -321,8 +337,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
def get_visibility(object) do
public = "https://www.w3.org/ns/activitystreams#Public"
- to = object["to"] || []
- cc = object["cc"] || []
+ to = object.data["to"] || []
+ cc = object.data["cc"] || []
cond do
public in to ->
@@ -343,25 +359,25 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
end
end
- def render_content(%{"type" => "Video"} = object) do
- with name when not is_nil(name) and name != "" <- object["name"] do
- "<p><a href=\"#{object["id"]}\">#{name}</a></p>#{object["content"]}"
+ def render_content(%{data: %{"type" => "Video"}} = object) do
+ with name when not is_nil(name) and name != "" <- object.data["name"] do
+ "<p><a href=\"#{object.data["id"]}\">#{name}</a></p>#{object.data["content"]}"
else
- _ -> object["content"] || ""
+ _ -> object.data["content"] || ""
end
end
- def render_content(%{"type" => object_type} = object)
+ def render_content(%{data: %{"type" => object_type}} = object)
when object_type in ["Article", "Page"] do
- with summary when not is_nil(summary) and summary != "" <- object["name"],
- url when is_bitstring(url) <- object["url"] do
- "<p><a href=\"#{url}\">#{summary}</a></p>#{object["content"]}"
+ with summary when not is_nil(summary) and summary != "" <- object.data["name"],
+ url when is_bitstring(url) <- object.data["url"] do
+ "<p><a href=\"#{url}\">#{summary}</a></p>#{object.data["content"]}"
else
- _ -> object["content"] || ""
+ _ -> object.data["content"] || ""
end
end
- def render_content(object), do: object["content"] || ""
+ def render_content(object), do: object.data["content"] || ""
@doc """
Builds a dictionary tags.
diff --git a/lib/pleroma/web/mastodon_api/websocket_handler.ex b/lib/pleroma/web/mastodon_api/websocket_handler.ex
index 1b3721e2b..abfa26754 100644
--- a/lib/pleroma/web/mastodon_api/websocket_handler.ex
+++ b/lib/pleroma/web/mastodon_api/websocket_handler.ex
@@ -90,7 +90,7 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do
# Authenticated streams.
defp allow_request(stream, {"access_token", access_token}) when stream in @streams do
with %Token{user_id: user_id} <- Repo.get_by(Token, token: access_token),
- user = %User{} <- User.get_by_id(user_id) do
+ user = %User{} <- User.get_cached_by_id(user_id) do
{:ok, user}
else
_ -> {:error, 403}
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index 9874bac23..688eaca11 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -23,6 +23,12 @@ defmodule Pleroma.Web.OAuth.OAuthController do
action_fallback(Pleroma.Web.OAuth.FallbackController)
+ # Note: this definition is only called from error-handling methods with `conn.params` as 2nd arg
+ def authorize(conn, %{"authorization" => _} = params) do
+ {auth_attrs, params} = Map.pop(params, "authorization")
+ authorize(conn, Map.merge(params, auth_attrs))
+ end
+
def authorize(%{assigns: %{token: %Token{} = token}} = conn, params) do
if ControllerHelper.truthy_param?(params["force_login"]) do
do_authorize(conn, params)
@@ -44,21 +50,20 @@ defmodule Pleroma.Web.OAuth.OAuthController do
def authorize(conn, params), do: do_authorize(conn, params)
- defp do_authorize(conn, %{"authorization" => auth_attrs}), do: do_authorize(conn, auth_attrs)
-
- defp do_authorize(conn, auth_attrs) do
- app = Repo.get_by(App, client_id: auth_attrs["client_id"])
+ defp do_authorize(conn, params) do
+ app = Repo.get_by(App, client_id: params["client_id"])
available_scopes = (app && app.scopes) || []
- scopes = oauth_scopes(auth_attrs, nil) || available_scopes
+ scopes = oauth_scopes(params, nil) || available_scopes
+ # Note: `params` might differ from `conn.params`; use `@params` not `@conn.params` in template
render(conn, Authenticator.auth_template(), %{
- response_type: auth_attrs["response_type"],
- client_id: auth_attrs["client_id"],
+ response_type: params["response_type"],
+ client_id: params["client_id"],
available_scopes: available_scopes,
scopes: scopes,
- redirect_uri: auth_attrs["redirect_uri"],
- state: auth_attrs["state"],
- params: auth_attrs
+ redirect_uri: params["redirect_uri"],
+ state: params["state"],
+ params: params
})
end
@@ -138,7 +143,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
fixed_token = fix_padding(params["code"]),
%Authorization{} = auth <-
Repo.get_by(Authorization, token: fixed_token, app_id: app.id),
- %User{} = user <- User.get_by_id(auth.user_id),
+ %User{} = user <- User.get_cached_by_id(auth.user_id),
{:ok, token} <- Token.exchange_token(app, auth),
{:ok, inserted_at} <- DateTime.from_naive(token.inserted_at, "Etc/UTC") do
response = %{
diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex
index 2b5ad9b94..399140003 100644
--- a/lib/pleroma/web/oauth/token.ex
+++ b/lib/pleroma/web/oauth/token.ex
@@ -27,7 +27,7 @@ defmodule Pleroma.Web.OAuth.Token do
def exchange_token(app, auth) do
with {:ok, auth} <- Authorization.use_token(auth),
true <- auth.app_id == app.id do
- create_token(app, User.get_by_id(auth.user_id), auth.scopes)
+ create_token(app, User.get_cached_by_id(auth.user_id), auth.scopes)
end
end
diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex
index 1a1b74bb0..166691a09 100644
--- a/lib/pleroma/web/ostatus/activity_representer.ex
+++ b/lib/pleroma/web/ostatus/activity_representer.ex
@@ -54,23 +54,16 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
end)
end
- defp get_links(%{local: true, data: data}) do
+ defp get_links(%{local: true}, %{"id" => object_id}) do
h = fn str -> [to_charlist(str)] end
[
- {:link, [type: ['application/atom+xml'], href: h.(data["object"]["id"]), rel: 'self'], []},
- {:link, [type: ['text/html'], href: h.(data["object"]["id"]), rel: 'alternate'], []}
+ {:link, [type: ['application/atom+xml'], href: h.(object_id), rel: 'self'], []},
+ {:link, [type: ['text/html'], href: h.(object_id), rel: 'alternate'], []}
]
end
- defp get_links(%{
- local: false,
- data: %{
- "object" => %{
- "external_url" => external_url
- }
- }
- }) do
+ defp get_links(%{local: false}, %{"external_url" => external_url}) do
h = fn str -> [to_charlist(str)] end
[
@@ -78,7 +71,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
]
end
- defp get_links(_activity), do: []
+ defp get_links(_activity, _object_data), do: []
defp get_emoji_links(emojis) do
Enum.map(emojis, fn {emoji, file} ->
@@ -88,14 +81,16 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
def to_simple_form(activity, user, with_author \\ false)
- def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user, with_author) do
+ def to_simple_form(%{data: %{"type" => "Create"}} = activity, user, with_author) do
h = fn str -> [to_charlist(str)] end
- updated_at = activity.data["object"]["published"]
- inserted_at = activity.data["object"]["published"]
+ object = Object.normalize(activity)
+
+ updated_at = object.data["published"]
+ inserted_at = object.data["published"]
attachments =
- Enum.map(activity.data["object"]["attachment"] || [], fn attachment ->
+ Enum.map(object.data["attachment"] || [], fn attachment ->
url = hd(attachment["url"])
{:link,
@@ -108,7 +103,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
mentions = activity.recipients |> get_mentions
categories =
- (activity.data["object"]["tag"] || [])
+ (object.data["tag"] || [])
|> Enum.map(fn tag ->
if is_binary(tag) do
{:category, [term: to_charlist(tag)], []}
@@ -118,11 +113,11 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
end)
|> Enum.filter(& &1)
- emoji_links = get_emoji_links(activity.data["object"]["emoji"] || %{})
+ emoji_links = get_emoji_links(object.data["emoji"] || %{})
summary =
- if activity.data["object"]["summary"] do
- [{:summary, [], h.(activity.data["object"]["summary"])}]
+ if object.data["summary"] do
+ [{:summary, [], h.(object.data["summary"])}]
else
[]
end
@@ -131,10 +126,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
{:"activity:object-type", ['http://activitystrea.ms/schema/1.0/note']},
{:"activity:verb", ['http://activitystrea.ms/schema/1.0/post']},
# For notes, federate the object id.
- {:id, h.(activity.data["object"]["id"])},
+ {:id, h.(object.data["id"])},
{:title, ['New note by #{user.nickname}']},
- {:content, [type: 'html'],
- h.(activity.data["object"]["content"] |> String.replace(~r/[\n\r]/, ""))},
+ {:content, [type: 'html'], h.(object.data["content"] |> String.replace(~r/[\n\r]/, ""))},
{:published, h.(inserted_at)},
{:updated, h.(updated_at)},
{:"ostatus:conversation", [ref: h.(activity.data["context"])],
@@ -142,7 +136,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
{:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []}
] ++
summary ++
- get_links(activity) ++
+ get_links(activity, object.data) ++
categories ++ attachments ++ in_reply_to ++ author ++ mentions ++ emoji_links
end
diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex
index db995ec77..ec6e5cfaf 100644
--- a/lib/pleroma/web/ostatus/handlers/note_handler.ex
+++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex
@@ -113,8 +113,9 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
cw <- OStatus.get_cw(entry),
in_reply_to <- XML.string_from_xpath("//thr:in-reply-to[1]/@ref", entry),
in_reply_to_activity <- fetch_replied_to_activity(entry, in_reply_to),
- in_reply_to <-
- (in_reply_to_activity && in_reply_to_activity.data["object"]["id"]) || in_reply_to,
+ in_reply_to_object <-
+ (in_reply_to_activity && Object.normalize(in_reply_to_activity)) || nil,
+ in_reply_to <- (in_reply_to_object && in_reply_to_object.data["id"]) || in_reply_to,
attachments <- OStatus.get_attachments(entry),
context <- get_context(entry, in_reply_to),
tags <- OStatus.get_tags(entry),
diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex
index 9a34d7ad5..4744c6d83 100644
--- a/lib/pleroma/web/ostatus/ostatus.ex
+++ b/lib/pleroma/web/ostatus/ostatus.ex
@@ -294,7 +294,7 @@ defmodule Pleroma.Web.OStatus do
}
with false <- update,
- %User{} = user <- User.get_by_ap_id(data.ap_id) do
+ %User{} = user <- User.get_cached_by_ap_id(data.ap_id) do
{:ok, user}
else
_e -> User.insert_or_update_user(data)
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 8b665d61b..ff4f08af5 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -135,6 +135,7 @@ defmodule Pleroma.Web.Router do
post("/password_reset", UtilController, :password_reset)
get("/emoji", UtilController, :emoji)
get("/captcha", UtilController, :captcha)
+ get("/healthcheck", UtilController, :healthcheck)
end
scope "/api/pleroma", Pleroma.Web do
@@ -394,6 +395,8 @@ defmodule Pleroma.Web.Router do
get("/accounts/:id", MastodonAPIController, :user)
get("/search", MastodonAPIController, :search)
+
+ get("/pleroma/accounts/:id/favourites", MastodonAPIController, :user_favourites)
end
end
diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex
index a82109f92..72eaf2084 100644
--- a/lib/pleroma/web/streamer.ex
+++ b/lib/pleroma/web/streamer.ex
@@ -81,7 +81,7 @@ defmodule Pleroma.Web.Streamer do
_ ->
Pleroma.List.get_lists_from_activity(item)
|> Enum.filter(fn list ->
- owner = User.get_by_id(list.user_id)
+ owner = User.get_cached_by_id(list.user_id)
Visibility.visible_for_user?(item, owner)
end)
diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
index ed45ca735..1122e6c5d 100644
--- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex
+++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
@@ -22,7 +22,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
def show_password_reset(conn, %{"token" => token}) do
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
- %User{} = user <- User.get_by_id(token.user_id) do
+ %User{} = user <- User.get_cached_by_id(token.user_id) do
render(conn, "password_reset.html", %{
token: token,
user: user
@@ -75,7 +75,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do
if is_status?(acct) do
- {:ok, object} = ActivityPub.fetch_object_from_id(acct)
+ {:ok, object} = Pleroma.Object.Fetcher.fetch_object_from_id(acct)
%Activity{id: activity_id} = Activity.get_create_by_object_ap_id(object.data["id"])
redirect(conn, to: "/notice/#{activity_id}")
else
@@ -101,7 +101,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
end
defp is_status?(acct) do
- case ActivityPub.fetch_and_contain_remote_object_from_id(acct) do
+ case Pleroma.Object.Fetcher.fetch_and_contain_remote_object_from_id(acct) do
{:ok, %{"type" => type}} when type in ["Article", "Note", "Video", "Page", "Question"] ->
true
@@ -113,13 +113,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
def do_remote_follow(conn, %{
"authorization" => %{"name" => username, "password" => password, "id" => id}
}) do
- followee = User.get_by_id(id)
+ followee = User.get_cached_by_id(id)
avatar = User.avatar_url(followee)
name = followee.nickname
with %User{} = user <- User.get_cached_by_nickname(username),
true <- Pbkdf2.checkpw(password, user.password_hash),
- %User{} = _followed <- User.get_by_id(id),
+ %User{} = _followed <- User.get_cached_by_id(id),
{:ok, follower} <- User.follow(user, followee),
{:ok, _activity} <- ActivityPub.follow(follower, followee) do
conn
@@ -141,7 +141,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
end
def do_remote_follow(%{assigns: %{user: user}} = conn, %{"user" => %{"id" => id}}) do
- with %User{} = followee <- User.get_by_id(id),
+ with %User{} = followee <- User.get_cached_by_id(id),
{:ok, follower} <- User.follow(user, followee),
{:ok, _activity} <- ActivityPub.follow(follower, followee) do
conn
@@ -286,7 +286,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
emoji =
Emoji.get_all()
|> Enum.map(fn {short_code, path, tags} ->
- {short_code, %{image_url: path, tags: String.split(tags, ",")}}
+ {short_code, %{image_url: path, tags: tags}}
end)
|> Enum.into(%{})
@@ -363,4 +363,22 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
def captcha(conn, _params) do
json(conn, Pleroma.Captcha.new())
end
+
+ def healthcheck(conn, _params) do
+ info =
+ if Pleroma.Config.get([:instance, :healthcheck]) do
+ Pleroma.Healthcheck.system_info()
+ else
+ %{}
+ end
+
+ conn =
+ if info[:healthy] do
+ conn
+ else
+ Plug.Conn.put_status(conn, :service_unavailable)
+ end
+
+ json(conn, info)
+ end
end
diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex
index d6ce0a7c6..adeac6f3c 100644
--- a/lib/pleroma/web/twitter_api/twitter_api.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api.ex
@@ -240,7 +240,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
end
%{"screen_name" => nickname} ->
- case User.get_by_nickname(nickname) do
+ case User.get_cached_by_nickname(nickname) do
nil -> {:error, "No user with such screen_name"}
target -> {:ok, target}
end
@@ -266,6 +266,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
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)
@@ -273,13 +274,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
q =
from(
- a in Activity,
+ [a, o] in Activity.with_preloaded_object(Activity),
where: fragment("?->>'type' = 'Create'", a.data),
where: "https://www.w3.org/ns/activitystreams#Public" in a.recipients,
where:
fragment(
- "to_tsvector('english', ?->'object'->>'content') @@ plainto_tsquery('english', ?)",
- a.data,
+ "to_tsvector('english', ?->>'content') @@ plainto_tsquery('english', ?)",
+ o.data,
^query
),
limit: ^limit,
diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
index a7ec9949c..79ed9dad2 100644
--- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
@@ -434,7 +434,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
end
def confirm_email(conn, %{"user_id" => uid, "token" => token}) do
- with %User{} = user <- User.get_by_id(uid),
+ with %User{} = user <- User.get_cached_by_id(uid),
true <- user.local,
true <- user.info.confirmation_pending,
true <- user.info.confirmation_token == token,
@@ -587,7 +587,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
def approve_friend_request(conn, %{"user_id" => uid} = _params) do
with followed <- conn.assigns[:user],
- %User{} = follower <- User.get_by_id(uid),
+ %User{} = follower <- User.get_cached_by_id(uid),
{:ok, follower} <- CommonAPI.accept_follow_request(follower, followed) do
conn
|> put_view(UserView)
@@ -599,7 +599,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
def deny_friend_request(conn, %{"user_id" => uid} = _params) do
with followed <- conn.assigns[:user],
- %User{} = follower <- User.get_by_id(uid),
+ %User{} = follower <- User.get_cached_by_id(uid),
{:ok, follower} <- CommonAPI.reject_follow_request(follower, followed) do
conn
|> put_view(UserView)
@@ -632,7 +632,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
defp build_info_cng(user, params) do
info_params =
- ["no_rich_text", "locked", "hide_followers", "hide_follows", "show_role"]
+ ["no_rich_text", "locked", "hide_followers", "hide_follows", "hide_favorites", "show_role"]
|> Enum.reduce(%{}, fn key, res ->
if value = params[key] do
Map.put(res, key, value == "true")
diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex
index ecb2b437b..c64152da8 100644
--- a/lib/pleroma/web/twitter_api/views/activity_view.ex
+++ b/lib/pleroma/web/twitter_api/views/activity_view.ex
@@ -224,15 +224,17 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
def render(
"activity.json",
- %{activity: %{data: %{"type" => "Create", "object" => object}} = activity} = opts
+ %{activity: %{data: %{"type" => "Create", "object" => object_id}} = activity} = opts
) do
user = get_user(activity.data["actor"], opts)
- created_at = object["published"] |> Utils.date_to_asctime()
- like_count = object["like_count"] || 0
- announcement_count = object["announcement_count"] || 0
- favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || [])
- repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || [])
+ 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 =
@@ -245,12 +247,12 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
conversation_id = get_context_id(activity, opts)
- tags = activity.data["object"]["tag"] || []
- possibly_sensitive = activity.data["object"]["sensitive"] || Enum.member?(tags, "nsfw")
+ 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)
+ {summary, content} = render_content(object.data)
html =
content
@@ -259,7 +261,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
activity,
"twitterapi:content"
)
- |> Formatter.emojify(object["emoji"])
+ |> Formatter.emojify(object.data["emoji"])
text =
if content do
@@ -284,7 +286,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
%{
"id" => activity.id,
- "uri" => activity.data["object"]["id"],
+ "uri" => object.data["id"],
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
"statusnet_html" => html,
"text" => text,
@@ -297,20 +299,20 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
"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["attachment"] || []) |> ObjectRepresenter.enum_to_list(opts),
+ "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["external_url"] || object["id"],
+ "external_url" => object.data["external_url"] || object.data["id"],
"tags" => tags,
"activity_type" => "post",
"possibly_sensitive" => possibly_sensitive,
"visibility" => StatusView.get_visibility(object),
"summary" => summary,
- "summary_html" => summary |> Formatter.emojify(object["emoji"]),
+ "summary_html" => summary |> Formatter.emojify(object.data["emoji"]),
"card" => card,
"muted" => CommonAPI.thread_muted?(user, activity) || User.mutes?(opts[:for], user)
}
diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex
index 32c3455f5..a3b0bf999 100644
--- a/lib/pleroma/web/web_finger/web_finger.ex
+++ b/lib/pleroma/web/web_finger/web_finger.ex
@@ -37,7 +37,7 @@ defmodule Pleroma.Web.WebFinger do
regex = ~r/(acct:)?(?<username>\w+)@#{host}/
with %{"username" => username} <- Regex.named_captures(regex, resource),
- %User{} = user <- User.get_by_nickname(username) do
+ %User{} = user <- User.get_cached_by_nickname(username) do
{:ok, represent_user(user, fmt)}
else
_e ->
diff --git a/priv/static/finmoji/1000px/a_trusted_friend.png b/priv/static/finmoji/1000px/a_trusted_friend.png
deleted file mode 100644
index 5658d589c..000000000
--- a/priv/static/finmoji/1000px/a_trusted_friend.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/alandislands.png b/priv/static/finmoji/1000px/alandislands.png
deleted file mode 100644
index 094dd3284..000000000
--- a/priv/static/finmoji/1000px/alandislands.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/association.png b/priv/static/finmoji/1000px/association.png
deleted file mode 100644
index dad3b8864..000000000
--- a/priv/static/finmoji/1000px/association.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/auroraborealis.png b/priv/static/finmoji/1000px/auroraborealis.png
deleted file mode 100644
index 5875dc2c4..000000000
--- a/priv/static/finmoji/1000px/auroraborealis.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/baby_in_a_box.png b/priv/static/finmoji/1000px/baby_in_a_box.png
deleted file mode 100644
index 9479aaebb..000000000
--- a/priv/static/finmoji/1000px/baby_in_a_box.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/bear.png b/priv/static/finmoji/1000px/bear.png
deleted file mode 100644
index 5d9fbb320..000000000
--- a/priv/static/finmoji/1000px/bear.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/black_gold.png b/priv/static/finmoji/1000px/black_gold.png
deleted file mode 100644
index 707e949ec..000000000
--- a/priv/static/finmoji/1000px/black_gold.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/christmasparty.png b/priv/static/finmoji/1000px/christmasparty.png
deleted file mode 100644
index 785decb8d..000000000
--- a/priv/static/finmoji/1000px/christmasparty.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/crosscountryskiing.png b/priv/static/finmoji/1000px/crosscountryskiing.png
deleted file mode 100644
index 2a9bddf41..000000000
--- a/priv/static/finmoji/1000px/crosscountryskiing.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/cupofcoffee.png b/priv/static/finmoji/1000px/cupofcoffee.png
deleted file mode 100644
index a12cc867c..000000000
--- a/priv/static/finmoji/1000px/cupofcoffee.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/education.png b/priv/static/finmoji/1000px/education.png
deleted file mode 100644
index af9feee59..000000000
--- a/priv/static/finmoji/1000px/education.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/fashionista_finns.png b/priv/static/finmoji/1000px/fashionista_finns.png
deleted file mode 100644
index d1140250d..000000000
--- a/priv/static/finmoji/1000px/fashionista_finns.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/finnishlove.png b/priv/static/finmoji/1000px/finnishlove.png
deleted file mode 100644
index 00148202f..000000000
--- a/priv/static/finmoji/1000px/finnishlove.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/flag.png b/priv/static/finmoji/1000px/flag.png
deleted file mode 100644
index e709449d7..000000000
--- a/priv/static/finmoji/1000px/flag.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/forest.png b/priv/static/finmoji/1000px/forest.png
deleted file mode 100644
index b2d64ea37..000000000
--- a/priv/static/finmoji/1000px/forest.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/four_seasons_of_bbq.png b/priv/static/finmoji/1000px/four_seasons_of_bbq.png
deleted file mode 100644
index 42f4a7fb7..000000000
--- a/priv/static/finmoji/1000px/four_seasons_of_bbq.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/girlpower.png b/priv/static/finmoji/1000px/girlpower.png
deleted file mode 100644
index 7674f2e26..000000000
--- a/priv/static/finmoji/1000px/girlpower.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/handshake.png b/priv/static/finmoji/1000px/handshake.png
deleted file mode 100644
index d9857d699..000000000
--- a/priv/static/finmoji/1000px/handshake.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/happiness.png b/priv/static/finmoji/1000px/happiness.png
deleted file mode 100644
index fbfc34fe4..000000000
--- a/priv/static/finmoji/1000px/happiness.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/headbanger.png b/priv/static/finmoji/1000px/headbanger.png
deleted file mode 100644
index d9c2f6247..000000000
--- a/priv/static/finmoji/1000px/headbanger.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/icebreaker.png b/priv/static/finmoji/1000px/icebreaker.png
deleted file mode 100644
index aedce3dca..000000000
--- a/priv/static/finmoji/1000px/icebreaker.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/iceman.png b/priv/static/finmoji/1000px/iceman.png
deleted file mode 100644
index c172e60d5..000000000
--- a/priv/static/finmoji/1000px/iceman.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/joulutorttu.png b/priv/static/finmoji/1000px/joulutorttu.png
deleted file mode 100644
index d7b5a7e53..000000000
--- a/priv/static/finmoji/1000px/joulutorttu.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/kaamos.png b/priv/static/finmoji/1000px/kaamos.png
deleted file mode 100644
index 139b21953..000000000
--- a/priv/static/finmoji/1000px/kaamos.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/kalsarikannit_f.png b/priv/static/finmoji/1000px/kalsarikannit_f.png
deleted file mode 100644
index 064c86160..000000000
--- a/priv/static/finmoji/1000px/kalsarikannit_f.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/kalsarikannit_m.png b/priv/static/finmoji/1000px/kalsarikannit_m.png
deleted file mode 100644
index e08bd27af..000000000
--- a/priv/static/finmoji/1000px/kalsarikannit_m.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/karjalanpiirakka.png b/priv/static/finmoji/1000px/karjalanpiirakka.png
deleted file mode 100644
index dbf647df5..000000000
--- a/priv/static/finmoji/1000px/karjalanpiirakka.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/kicksled.png b/priv/static/finmoji/1000px/kicksled.png
deleted file mode 100644
index 305a56f77..000000000
--- a/priv/static/finmoji/1000px/kicksled.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/kokko.png b/priv/static/finmoji/1000px/kokko.png
deleted file mode 100644
index 0a5472c9a..000000000
--- a/priv/static/finmoji/1000px/kokko.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/lavatanssit.png b/priv/static/finmoji/1000px/lavatanssit.png
deleted file mode 100644
index a1f0a69dd..000000000
--- a/priv/static/finmoji/1000px/lavatanssit.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/losthopes_f.png b/priv/static/finmoji/1000px/losthopes_f.png
deleted file mode 100644
index a847df3c5..000000000
--- a/priv/static/finmoji/1000px/losthopes_f.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/losthopes_m.png b/priv/static/finmoji/1000px/losthopes_m.png
deleted file mode 100644
index 93c83b995..000000000
--- a/priv/static/finmoji/1000px/losthopes_m.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/mattinykanen.png b/priv/static/finmoji/1000px/mattinykanen.png
deleted file mode 100644
index 2d9c9d38f..000000000
--- a/priv/static/finmoji/1000px/mattinykanen.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/meanwhileinfinland.png b/priv/static/finmoji/1000px/meanwhileinfinland.png
deleted file mode 100644
index 794db1eed..000000000
--- a/priv/static/finmoji/1000px/meanwhileinfinland.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/moominmamma.png b/priv/static/finmoji/1000px/moominmamma.png
deleted file mode 100644
index d34b1b98b..000000000
--- a/priv/static/finmoji/1000px/moominmamma.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/nordicfamily.png b/priv/static/finmoji/1000px/nordicfamily.png
deleted file mode 100644
index 21292eaff..000000000
--- a/priv/static/finmoji/1000px/nordicfamily.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/out_of_office.png b/priv/static/finmoji/1000px/out_of_office.png
deleted file mode 100644
index b72d6dbd5..000000000
--- a/priv/static/finmoji/1000px/out_of_office.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/peacemaker.png b/priv/static/finmoji/1000px/peacemaker.png
deleted file mode 100644
index 48a51fa6f..000000000
--- a/priv/static/finmoji/1000px/peacemaker.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/perkele.png b/priv/static/finmoji/1000px/perkele.png
deleted file mode 100644
index 16a68d053..000000000
--- a/priv/static/finmoji/1000px/perkele.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/pesapallo.png b/priv/static/finmoji/1000px/pesapallo.png
deleted file mode 100644
index 2f35c8e02..000000000
--- a/priv/static/finmoji/1000px/pesapallo.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/polarbear.png b/priv/static/finmoji/1000px/polarbear.png
deleted file mode 100644
index ce6c65e8b..000000000
--- a/priv/static/finmoji/1000px/polarbear.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/pusa_hispida_saimensis.png b/priv/static/finmoji/1000px/pusa_hispida_saimensis.png
deleted file mode 100644
index 35ec8caed..000000000
--- a/priv/static/finmoji/1000px/pusa_hispida_saimensis.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/reindeer.png b/priv/static/finmoji/1000px/reindeer.png
deleted file mode 100644
index e60f0f0a4..000000000
--- a/priv/static/finmoji/1000px/reindeer.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/sami.png b/priv/static/finmoji/1000px/sami.png
deleted file mode 100644
index e4703dfd2..000000000
--- a/priv/static/finmoji/1000px/sami.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/sauna_f.png b/priv/static/finmoji/1000px/sauna_f.png
deleted file mode 100644
index 9a4ba8629..000000000
--- a/priv/static/finmoji/1000px/sauna_f.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/sauna_m.png b/priv/static/finmoji/1000px/sauna_m.png
deleted file mode 100644
index 4bdd33f7b..000000000
--- a/priv/static/finmoji/1000px/sauna_m.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/sauna_whisk.png b/priv/static/finmoji/1000px/sauna_whisk.png
deleted file mode 100644
index c16928065..000000000
--- a/priv/static/finmoji/1000px/sauna_whisk.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/sisu.png b/priv/static/finmoji/1000px/sisu.png
deleted file mode 100644
index 238453bb5..000000000
--- a/priv/static/finmoji/1000px/sisu.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/stuck.png b/priv/static/finmoji/1000px/stuck.png
deleted file mode 100644
index 4180e3ecd..000000000
--- a/priv/static/finmoji/1000px/stuck.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/suomimainittu.png b/priv/static/finmoji/1000px/suomimainittu.png
deleted file mode 100644
index af46347f5..000000000
--- a/priv/static/finmoji/1000px/suomimainittu.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/superfood.png b/priv/static/finmoji/1000px/superfood.png
deleted file mode 100644
index 8fa033c18..000000000
--- a/priv/static/finmoji/1000px/superfood.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/swan.png b/priv/static/finmoji/1000px/swan.png
deleted file mode 100644
index 5363f861d..000000000
--- a/priv/static/finmoji/1000px/swan.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/the_cap.png b/priv/static/finmoji/1000px/the_cap.png
deleted file mode 100644
index 7f547dc0e..000000000
--- a/priv/static/finmoji/1000px/the_cap.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/the_conductor.png b/priv/static/finmoji/1000px/the_conductor.png
deleted file mode 100644
index ed5ca7f1f..000000000
--- a/priv/static/finmoji/1000px/the_conductor.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/the_king.png b/priv/static/finmoji/1000px/the_king.png
deleted file mode 100644
index 8c3a5c66d..000000000
--- a/priv/static/finmoji/1000px/the_king.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/the_voice.png b/priv/static/finmoji/1000px/the_voice.png
deleted file mode 100644
index 9bfc87b3a..000000000
--- a/priv/static/finmoji/1000px/the_voice.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/theoriginalsanta.png b/priv/static/finmoji/1000px/theoriginalsanta.png
deleted file mode 100644
index b8dc1ef47..000000000
--- a/priv/static/finmoji/1000px/theoriginalsanta.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/tomoffinland.png b/priv/static/finmoji/1000px/tomoffinland.png
deleted file mode 100644
index 97da05a64..000000000
--- a/priv/static/finmoji/1000px/tomoffinland.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/torillatavataan.png b/priv/static/finmoji/1000px/torillatavataan.png
deleted file mode 100644
index ff7a81eda..000000000
--- a/priv/static/finmoji/1000px/torillatavataan.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/unbreakable.png b/priv/static/finmoji/1000px/unbreakable.png
deleted file mode 100644
index 1778fc115..000000000
--- a/priv/static/finmoji/1000px/unbreakable.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/waiting.png b/priv/static/finmoji/1000px/waiting.png
deleted file mode 100644
index 2aa9afa70..000000000
--- a/priv/static/finmoji/1000px/waiting.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/white_nights.png b/priv/static/finmoji/1000px/white_nights.png
deleted file mode 100644
index 8e9cd3fc8..000000000
--- a/priv/static/finmoji/1000px/white_nights.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/1000px/woollysocks.png b/priv/static/finmoji/1000px/woollysocks.png
deleted file mode 100644
index 5ee4e6de1..000000000
--- a/priv/static/finmoji/1000px/woollysocks.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/a_trusted_friend-128.png b/priv/static/finmoji/128px/a_trusted_friend-128.png
deleted file mode 100644
index 16d596bda..000000000
--- a/priv/static/finmoji/128px/a_trusted_friend-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/alandislands-128.png b/priv/static/finmoji/128px/alandislands-128.png
deleted file mode 100644
index 13cdf6e76..000000000
--- a/priv/static/finmoji/128px/alandislands-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/association-128.png b/priv/static/finmoji/128px/association-128.png
deleted file mode 100644
index 5b388d781..000000000
--- a/priv/static/finmoji/128px/association-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/auroraborealis-128.png b/priv/static/finmoji/128px/auroraborealis-128.png
deleted file mode 100644
index 7e2af77b9..000000000
--- a/priv/static/finmoji/128px/auroraborealis-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/baby_in_a_box-128.png b/priv/static/finmoji/128px/baby_in_a_box-128.png
deleted file mode 100644
index 9c495e24a..000000000
--- a/priv/static/finmoji/128px/baby_in_a_box-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/bear-128.png b/priv/static/finmoji/128px/bear-128.png
deleted file mode 100644
index 8bb101bf4..000000000
--- a/priv/static/finmoji/128px/bear-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/black_gold-128.png b/priv/static/finmoji/128px/black_gold-128.png
deleted file mode 100644
index 1833edab4..000000000
--- a/priv/static/finmoji/128px/black_gold-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/christmasparty-128.png b/priv/static/finmoji/128px/christmasparty-128.png
deleted file mode 100644
index 98216830c..000000000
--- a/priv/static/finmoji/128px/christmasparty-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/crosscountryskiing-128.png b/priv/static/finmoji/128px/crosscountryskiing-128.png
deleted file mode 100644
index 67553f398..000000000
--- a/priv/static/finmoji/128px/crosscountryskiing-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/cupofcoffee-128.png b/priv/static/finmoji/128px/cupofcoffee-128.png
deleted file mode 100644
index 20064f218..000000000
--- a/priv/static/finmoji/128px/cupofcoffee-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/education-128.png b/priv/static/finmoji/128px/education-128.png
deleted file mode 100644
index c98083bdd..000000000
--- a/priv/static/finmoji/128px/education-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/fashionista_finns-128.png b/priv/static/finmoji/128px/fashionista_finns-128.png
deleted file mode 100644
index 4248825e0..000000000
--- a/priv/static/finmoji/128px/fashionista_finns-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/finnishlove-128.png b/priv/static/finmoji/128px/finnishlove-128.png
deleted file mode 100644
index 5d4f9476c..000000000
--- a/priv/static/finmoji/128px/finnishlove-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/flag-128.png b/priv/static/finmoji/128px/flag-128.png
deleted file mode 100644
index 0087cc589..000000000
--- a/priv/static/finmoji/128px/flag-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/forest-128.png b/priv/static/finmoji/128px/forest-128.png
deleted file mode 100644
index 142e60b94..000000000
--- a/priv/static/finmoji/128px/forest-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/four_seasons_of_bbq-128.png b/priv/static/finmoji/128px/four_seasons_of_bbq-128.png
deleted file mode 100644
index bb7fe1f51..000000000
--- a/priv/static/finmoji/128px/four_seasons_of_bbq-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/girlpower-128.png b/priv/static/finmoji/128px/girlpower-128.png
deleted file mode 100644
index bc76a51c5..000000000
--- a/priv/static/finmoji/128px/girlpower-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/handshake-128.png b/priv/static/finmoji/128px/handshake-128.png
deleted file mode 100644
index 4ebf196ab..000000000
--- a/priv/static/finmoji/128px/handshake-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/happiness-128.png b/priv/static/finmoji/128px/happiness-128.png
deleted file mode 100644
index e28f99a26..000000000
--- a/priv/static/finmoji/128px/happiness-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/headbanger-128.png b/priv/static/finmoji/128px/headbanger-128.png
deleted file mode 100644
index 0de620efe..000000000
--- a/priv/static/finmoji/128px/headbanger-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/icebreaker-128.png b/priv/static/finmoji/128px/icebreaker-128.png
deleted file mode 100644
index 7fb36a4a3..000000000
--- a/priv/static/finmoji/128px/icebreaker-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/iceman-128.png b/priv/static/finmoji/128px/iceman-128.png
deleted file mode 100644
index eb814e6aa..000000000
--- a/priv/static/finmoji/128px/iceman-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/joulutorttu-128.png b/priv/static/finmoji/128px/joulutorttu-128.png
deleted file mode 100644
index 50448e333..000000000
--- a/priv/static/finmoji/128px/joulutorttu-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/kaamos-128.png b/priv/static/finmoji/128px/kaamos-128.png
deleted file mode 100644
index 8b2df03ef..000000000
--- a/priv/static/finmoji/128px/kaamos-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/kalsarikannit_f-128.png b/priv/static/finmoji/128px/kalsarikannit_f-128.png
deleted file mode 100644
index bcd94141a..000000000
--- a/priv/static/finmoji/128px/kalsarikannit_f-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/kalsarikannit_m-128.png b/priv/static/finmoji/128px/kalsarikannit_m-128.png
deleted file mode 100644
index c6938e677..000000000
--- a/priv/static/finmoji/128px/kalsarikannit_m-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/karjalanpiirakka-128.png b/priv/static/finmoji/128px/karjalanpiirakka-128.png
deleted file mode 100644
index a82a902db..000000000
--- a/priv/static/finmoji/128px/karjalanpiirakka-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/kicksled-128.png b/priv/static/finmoji/128px/kicksled-128.png
deleted file mode 100644
index ff42462db..000000000
--- a/priv/static/finmoji/128px/kicksled-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/kokko-128.png b/priv/static/finmoji/128px/kokko-128.png
deleted file mode 100644
index e0b6e07fa..000000000
--- a/priv/static/finmoji/128px/kokko-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/lavatanssit-128.png b/priv/static/finmoji/128px/lavatanssit-128.png
deleted file mode 100644
index f89dc358c..000000000
--- a/priv/static/finmoji/128px/lavatanssit-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/losthopes_f-128.png b/priv/static/finmoji/128px/losthopes_f-128.png
deleted file mode 100644
index 60f0949c0..000000000
--- a/priv/static/finmoji/128px/losthopes_f-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/losthopes_m-128.png b/priv/static/finmoji/128px/losthopes_m-128.png
deleted file mode 100644
index 9ae6f9e2f..000000000
--- a/priv/static/finmoji/128px/losthopes_m-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/mattinykanen-128.png b/priv/static/finmoji/128px/mattinykanen-128.png
deleted file mode 100644
index 0e81271ca..000000000
--- a/priv/static/finmoji/128px/mattinykanen-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/meanwhileinfinland-128.png b/priv/static/finmoji/128px/meanwhileinfinland-128.png
deleted file mode 100644
index 5a9710a3b..000000000
--- a/priv/static/finmoji/128px/meanwhileinfinland-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/moominmamma-128.png b/priv/static/finmoji/128px/moominmamma-128.png
deleted file mode 100644
index ae37bb94a..000000000
--- a/priv/static/finmoji/128px/moominmamma-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/nordicfamily-128.png b/priv/static/finmoji/128px/nordicfamily-128.png
deleted file mode 100644
index cff41b228..000000000
--- a/priv/static/finmoji/128px/nordicfamily-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/out_of_office-128.png b/priv/static/finmoji/128px/out_of_office-128.png
deleted file mode 100644
index 45cd1c2f5..000000000
--- a/priv/static/finmoji/128px/out_of_office-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/peacemaker-128.png b/priv/static/finmoji/128px/peacemaker-128.png
deleted file mode 100644
index c4e9bd447..000000000
--- a/priv/static/finmoji/128px/peacemaker-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/perkele-128.png b/priv/static/finmoji/128px/perkele-128.png
deleted file mode 100644
index e89e5bf32..000000000
--- a/priv/static/finmoji/128px/perkele-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/pesapallo-128.png b/priv/static/finmoji/128px/pesapallo-128.png
deleted file mode 100644
index 5e06bec50..000000000
--- a/priv/static/finmoji/128px/pesapallo-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/polarbear-128.png b/priv/static/finmoji/128px/polarbear-128.png
deleted file mode 100644
index fd3c3ec30..000000000
--- a/priv/static/finmoji/128px/polarbear-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/pusa_hispida_saimensis-128.png b/priv/static/finmoji/128px/pusa_hispida_saimensis-128.png
deleted file mode 100644
index 60620be5d..000000000
--- a/priv/static/finmoji/128px/pusa_hispida_saimensis-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/reindeer-128.png b/priv/static/finmoji/128px/reindeer-128.png
deleted file mode 100644
index 8cdd05f27..000000000
--- a/priv/static/finmoji/128px/reindeer-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/sami-128.png b/priv/static/finmoji/128px/sami-128.png
deleted file mode 100644
index e9e9f41a7..000000000
--- a/priv/static/finmoji/128px/sami-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/sauna_f-128.png b/priv/static/finmoji/128px/sauna_f-128.png
deleted file mode 100644
index 474f126ff..000000000
--- a/priv/static/finmoji/128px/sauna_f-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/sauna_m-128.png b/priv/static/finmoji/128px/sauna_m-128.png
deleted file mode 100644
index f7f563a9b..000000000
--- a/priv/static/finmoji/128px/sauna_m-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/sauna_whisk-128.png b/priv/static/finmoji/128px/sauna_whisk-128.png
deleted file mode 100644
index 80ebb55e4..000000000
--- a/priv/static/finmoji/128px/sauna_whisk-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/sisu-128.png b/priv/static/finmoji/128px/sisu-128.png
deleted file mode 100644
index 7b9330654..000000000
--- a/priv/static/finmoji/128px/sisu-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/stuck-128.png b/priv/static/finmoji/128px/stuck-128.png
deleted file mode 100644
index c14bc555d..000000000
--- a/priv/static/finmoji/128px/stuck-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/suomimainittu-128.png b/priv/static/finmoji/128px/suomimainittu-128.png
deleted file mode 100644
index 8d35b9be1..000000000
--- a/priv/static/finmoji/128px/suomimainittu-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/superfood-128.png b/priv/static/finmoji/128px/superfood-128.png
deleted file mode 100644
index 2e9d924cc..000000000
--- a/priv/static/finmoji/128px/superfood-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/swan-128.png b/priv/static/finmoji/128px/swan-128.png
deleted file mode 100644
index d1711c70b..000000000
--- a/priv/static/finmoji/128px/swan-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/the_cap-128.png b/priv/static/finmoji/128px/the_cap-128.png
deleted file mode 100644
index 10d83c22e..000000000
--- a/priv/static/finmoji/128px/the_cap-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/the_conductor-128.png b/priv/static/finmoji/128px/the_conductor-128.png
deleted file mode 100644
index 0da7c42e8..000000000
--- a/priv/static/finmoji/128px/the_conductor-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/the_king-128.png b/priv/static/finmoji/128px/the_king-128.png
deleted file mode 100644
index 07dd27ad7..000000000
--- a/priv/static/finmoji/128px/the_king-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/the_voice-128.png b/priv/static/finmoji/128px/the_voice-128.png
deleted file mode 100644
index bb436f95b..000000000
--- a/priv/static/finmoji/128px/the_voice-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/theoriginalsanta-128.png b/priv/static/finmoji/128px/theoriginalsanta-128.png
deleted file mode 100644
index 082d58c28..000000000
--- a/priv/static/finmoji/128px/theoriginalsanta-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/tomoffinland-128.png b/priv/static/finmoji/128px/tomoffinland-128.png
deleted file mode 100644
index 29c68bcba..000000000
--- a/priv/static/finmoji/128px/tomoffinland-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/torillatavataan-128.png b/priv/static/finmoji/128px/torillatavataan-128.png
deleted file mode 100644
index da7b502b4..000000000
--- a/priv/static/finmoji/128px/torillatavataan-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/unbreakable-128.png b/priv/static/finmoji/128px/unbreakable-128.png
deleted file mode 100644
index eb825e14f..000000000
--- a/priv/static/finmoji/128px/unbreakable-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/waiting-128.png b/priv/static/finmoji/128px/waiting-128.png
deleted file mode 100644
index 10b9167f2..000000000
--- a/priv/static/finmoji/128px/waiting-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/white_nights-128.png b/priv/static/finmoji/128px/white_nights-128.png
deleted file mode 100644
index 8eacd11f0..000000000
--- a/priv/static/finmoji/128px/white_nights-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/128px/woollysocks-128.png b/priv/static/finmoji/128px/woollysocks-128.png
deleted file mode 100644
index 856af5b2e..000000000
--- a/priv/static/finmoji/128px/woollysocks-128.png
+++ /dev/null
Binary files differ
diff --git a/priv/static/finmoji/LICENSE b/priv/static/finmoji/LICENSE
deleted file mode 100644
index e3a607aa3..000000000
--- a/priv/static/finmoji/LICENSE
+++ /dev/null
@@ -1 +0,0 @@
-these are under CC-BY-ND, see https://finland.fi/emoji/
diff --git a/test/activity_test.exs b/test/activity_test.exs
index dc9c56a21..ad889f544 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -28,18 +28,4 @@ defmodule Pleroma.ActivityTest do
assert activity == found_activity
end
-
- test "reply count" do
- %{id: id, data: %{"object" => %{"id" => object_ap_id}}} = activity = insert(:note_activity)
-
- replies_count = activity.data["object"]["repliesCount"] || 0
- expected_increase = replies_count + 1
- Activity.increase_replies_count(object_ap_id)
- %{data: %{"object" => %{"repliesCount" => actual_increase}}} = Activity.get_by_id(id)
- assert expected_increase == actual_increase
- expected_decrease = expected_increase - 1
- Activity.decrease_replies_count(object_ap_id)
- %{data: %{"object" => %{"repliesCount" => actual_decrease}}} = Activity.get_by_id(id)
- assert expected_decrease == actual_decrease
- end
end
diff --git a/test/emoji_test.exs b/test/emoji_test.exs
index cb1d62d00..2eaa26be6 100644
--- a/test/emoji_test.exs
+++ b/test/emoji_test.exs
@@ -15,7 +15,7 @@ defmodule Pleroma.EmojiTest do
assert tuple_size(emoji) == 3
assert is_binary(code)
assert is_binary(path)
- assert is_binary(tags)
+ assert is_list(tags)
end
test "random emoji", %{emoji_list: emoji_list} do
@@ -25,7 +25,7 @@ defmodule Pleroma.EmojiTest do
assert tuple_size(emoji) == 3
assert is_binary(code)
assert is_binary(path)
- assert is_binary(tags)
+ assert is_list(tags)
end
end
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index e74985c4e..97eb2f583 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -245,10 +245,10 @@ defmodule Pleroma.FormatterTest do
end
test "it adds cool emoji" do
- text = "I love :moominmamma:"
+ text = "I love :firefox:"
expected_result =
- "I love <img height=\"32px\" width=\"32px\" alt=\"moominmamma\" title=\"moominmamma\" src=\"/finmoji/128px/moominmamma-128.png\" />"
+ "I love <img height=\"32px\" width=\"32px\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\" />"
assert Formatter.emojify(text) == expected_result
end
@@ -269,10 +269,10 @@ defmodule Pleroma.FormatterTest do
end
test "it returns the emoji used in the text" do
- text = "I love :moominmamma:"
+ text = "I love :firefox:"
assert Formatter.get_emoji(text) == [
- {"moominmamma", "/finmoji/128px/moominmamma-128.png", "Finmoji"}
+ {"firefox", "/emoji/Firefox.gif", ["Gif", "Fun"]}
]
end
diff --git a/test/healthcheck_test.exs b/test/healthcheck_test.exs
new file mode 100644
index 000000000..e05061220
--- /dev/null
+++ b/test/healthcheck_test.exs
@@ -0,0 +1,22 @@
+defmodule Pleroma.HealthcheckTest do
+ use Pleroma.DataCase
+ alias Pleroma.Healthcheck
+
+ test "system_info/0" do
+ result = Healthcheck.system_info() |> Map.from_struct()
+
+ assert Map.keys(result) == [:active, :healthy, :idle, :memory_used, :pool_size]
+ end
+
+ describe "check_health/1" do
+ test "pool size equals active connections" do
+ result = Healthcheck.check_health(%Healthcheck{pool_size: 10, active: 10})
+ refute result.healthy
+ end
+
+ test "chech_health/1" do
+ result = Healthcheck.check_health(%Healthcheck{pool_size: 10, active: 9})
+ assert result.healthy
+ end
+ end
+end
diff --git a/test/notification_test.exs b/test/notification_test.exs
index c3db77b6c..581db58a8 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -46,7 +46,7 @@ defmodule Pleroma.NotificationTest do
describe "create_notification" do
test "it doesn't create a notification for user if the user blocks the activity author" do
activity = insert(:note_activity)
- author = User.get_by_ap_id(activity.data["actor"])
+ author = User.get_cached_by_ap_id(activity.data["actor"])
user = insert(:user)
{:ok, user} = User.block(user, author)
@@ -124,7 +124,7 @@ defmodule Pleroma.NotificationTest do
test "it doesn't create a notification for user if he is the activity author" do
activity = insert(:note_activity)
- author = User.get_by_ap_id(activity.data["actor"])
+ author = User.get_cached_by_ap_id(activity.data["actor"])
assert nil == Notification.create_notification(activity, author)
end
diff --git a/test/object/containment_test.exs b/test/object/containment_test.exs
new file mode 100644
index 000000000..452064093
--- /dev/null
+++ b/test/object/containment_test.exs
@@ -0,0 +1,58 @@
+defmodule Pleroma.Object.ContainmentTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Object.Containment
+ alias Pleroma.User
+
+ import Pleroma.Factory
+
+ describe "general origin containment" do
+ test "contain_origin_from_id() catches obvious spoofing attempts" do
+ data = %{
+ "id" => "http://example.com/~alyssa/activities/1234.json"
+ }
+
+ :error =
+ Containment.contain_origin_from_id(
+ "http://example.org/~alyssa/activities/1234.json",
+ data
+ )
+ end
+
+ test "contain_origin_from_id() allows alternate IDs within the same origin domain" do
+ data = %{
+ "id" => "http://example.com/~alyssa/activities/1234.json"
+ }
+
+ :ok =
+ Containment.contain_origin_from_id(
+ "http://example.com/~alyssa/activities/1234",
+ data
+ )
+ end
+
+ test "contain_origin_from_id() allows matching IDs" do
+ data = %{
+ "id" => "http://example.com/~alyssa/activities/1234.json"
+ }
+
+ :ok =
+ Containment.contain_origin_from_id(
+ "http://example.com/~alyssa/activities/1234.json",
+ data
+ )
+ end
+
+ test "users cannot be collided through fake direction spoofing attempts" do
+ _user =
+ insert(:user, %{
+ nickname: "rye@niu.moe",
+ local: false,
+ ap_id: "https://niu.moe/users/rye",
+ follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
+ })
+
+ {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye")
+ end
+ end
+end
diff --git a/test/object/fetcher_test.exs b/test/object/fetcher_test.exs
new file mode 100644
index 000000000..72f616782
--- /dev/null
+++ b/test/object/fetcher_test.exs
@@ -0,0 +1,90 @@
+defmodule Pleroma.Object.FetcherTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Activity
+ alias Pleroma.Object
+ alias Pleroma.Object.Fetcher
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ describe "actor origin containment" do
+ test "it rejects objects with a bogus origin" do
+ {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity.json")
+ end
+
+ test "it rejects objects when attributedTo is wrong (variant 1)" do
+ {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity2.json")
+ end
+
+ test "it rejects objects when attributedTo is wrong (variant 2)" do
+ {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity3.json")
+ end
+ end
+
+ describe "fetching an object" do
+ test "it fetches an object" do
+ {:ok, object} =
+ Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+
+ assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
+ assert activity.data["id"]
+
+ {:ok, object_again} =
+ Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+
+ assert [attachment] = object.data["attachment"]
+ assert is_list(attachment["url"])
+
+ assert object == object_again
+ end
+
+ test "it works with objects only available via Ostatus" do
+ {:ok, object} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
+ assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
+ assert activity.data["id"]
+
+ {:ok, object_again} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
+
+ assert object == object_again
+ end
+
+ test "it correctly stitches up conversations between ostatus and ap" do
+ last = "https://mstdn.io/users/mayuutann/statuses/99568293732299394"
+ {:ok, object} = Fetcher.fetch_object_from_id(last)
+
+ object = Object.get_by_ap_id(object.data["inReplyTo"])
+ assert object
+ end
+ end
+
+ describe "implementation quirks" do
+ test "it can fetch plume articles" do
+ {:ok, object} =
+ Fetcher.fetch_object_from_id(
+ "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
+ )
+
+ assert object
+ end
+
+ test "it can fetch peertube videos" do
+ {:ok, object} =
+ Fetcher.fetch_object_from_id(
+ "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
+ )
+
+ assert object
+ end
+
+ test "all objects with fake directions are rejected by the object fetcher" do
+ {:error, _} =
+ Fetcher.fetch_and_contain_remote_object_from_id(
+ "https://info.pleroma.site/activity4.json"
+ )
+ end
+ end
+end
diff --git a/test/object_test.exs b/test/object_test.exs
index 911757d57..d138ee091 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -5,9 +5,15 @@
defmodule Pleroma.ObjectTest do
use Pleroma.DataCase
import Pleroma.Factory
+ import Tesla.Mock
alias Pleroma.Object
alias Pleroma.Repo
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
test "returns an object by it's AP id" do
object = insert(:note)
found_object = Object.get_by_ap_id(object.data["id"])
@@ -58,4 +64,26 @@ defmodule Pleroma.ObjectTest do
assert cached_object.data["type"] == "Tombstone"
end
end
+
+ describe "normalizer" do
+ test "fetches unknown objects by default" do
+ %Object{} =
+ object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367")
+
+ assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367"
+ end
+
+ test "fetches unknown objects when fetch_remote is explicitly true" do
+ %Object{} =
+ object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367", true)
+
+ assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367"
+ end
+
+ test "does not fetch unknown objects when fetch_remote is false" do
+ assert is_nil(
+ Object.normalize("http://mastodon.example.org/@admin/99541947525187367", false)
+ )
+ end
+ end
end
diff --git a/test/scheduled_activity_worker_test.exs b/test/scheduled_activity_worker_test.exs
index b9c91dda6..e3ad1244e 100644
--- a/test/scheduled_activity_worker_test.exs
+++ b/test/scheduled_activity_worker_test.exs
@@ -14,6 +14,6 @@ defmodule Pleroma.ScheduledActivityWorkerTest do
refute Repo.get(ScheduledActivity, scheduled_activity.id)
activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id))
- assert activity.data["object"]["content"] == "hi"
+ assert Pleroma.Object.normalize(activity).data["content"] == "hi"
end
end
diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs
index 535dc3756..9d260da3e 100644
--- a/test/tasks/relay_test.exs
+++ b/test/tasks/relay_test.exs
@@ -31,7 +31,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
local_user = Relay.get_actor()
assert local_user.ap_id =~ "/relay"
- target_user = User.get_by_ap_id(target_instance)
+ target_user = User.get_cached_by_ap_id(target_instance)
refute target_user.local
activity = Utils.fetch_latest_follow(local_user, target_user)
@@ -48,7 +48,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
%User{ap_id: follower_id} = local_user = Relay.get_actor()
- target_user = User.get_by_ap_id(target_instance)
+ target_user = User.get_cached_by_ap_id(target_instance)
follow_activity = Utils.fetch_latest_follow(local_user, target_user)
Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs
index 242265da5..eaf4ecf84 100644
--- a/test/tasks/user_test.exs
+++ b/test/tasks/user_test.exs
@@ -50,7 +50,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ "created"
- user = User.get_by_nickname(unsaved.nickname)
+ user = User.get_cached_by_nickname(unsaved.nickname)
assert user.name == unsaved.name
assert user.email == unsaved.email
assert user.bio == unsaved.bio
@@ -75,7 +75,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ "will not be created"
- refute User.get_by_nickname(unsaved.nickname)
+ refute User.get_cached_by_nickname(unsaved.nickname)
end
end
@@ -88,7 +88,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert user.info.deactivated
end
@@ -109,7 +109,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " deactivated"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert user.info.deactivated
end
@@ -121,7 +121,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " activated"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
refute user.info.deactivated
end
@@ -150,7 +150,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ "Successfully unsubscribed"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert Enum.empty?(user.following)
assert user.info.deactivated
end
@@ -178,7 +178,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Admin status .* true/
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert user.info.is_moderator
assert user.info.locked
assert user.info.is_admin
@@ -204,7 +204,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Admin status .* false/
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
refute user.info.is_moderator
refute user.info.locked
refute user.info.is_admin
diff --git a/test/user_test.exs b/test/user_test.exs
index d2167a970..42d570c50 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -5,6 +5,7 @@
defmodule Pleroma.UserTest do
alias Pleroma.Activity
alias Pleroma.Builders.UserBuilder
+ alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.CommonAPI
@@ -122,9 +123,9 @@ defmodule Pleroma.UserTest do
{:ok, user} = User.follow(user, followed)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
- followed = User.get_by_ap_id(followed.ap_id)
+ followed = User.get_cached_by_ap_id(followed.ap_id)
assert followed.info.follower_count == 1
assert User.ap_followers(followed) in user.following
@@ -187,7 +188,7 @@ defmodule Pleroma.UserTest do
{:ok, user, _activity} = User.unfollow(user, followed)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.following == []
end
@@ -197,7 +198,7 @@ defmodule Pleroma.UserTest do
{:error, _} = User.unfollow(user, user)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.following == [user.ap_id]
end
@@ -256,7 +257,7 @@ defmodule Pleroma.UserTest do
activity = Repo.one(Pleroma.Activity)
assert registered_user.ap_id in activity.recipients
- assert activity.data["object"]["content"] =~ "cool site"
+ assert Object.normalize(activity).data["content"] =~ "cool site"
assert activity.actor == welcome_user.ap_id
Pleroma.Config.put([:instance, :welcome_user_nickname], nil)
@@ -555,8 +556,8 @@ defmodule Pleroma.UserTest do
{:ok, res} = User.get_friends(user)
- followed_one = User.get_by_ap_id(followed_one.ap_id)
- followed_two = User.get_by_ap_id(followed_two.ap_id)
+ followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
+ followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
assert Enum.member?(res, followed_one)
assert Enum.member?(res, followed_two)
refute Enum.member?(res, not_followed)
@@ -567,7 +568,7 @@ defmodule Pleroma.UserTest do
test "it sets the info->note_count property" do
note = insert(:note)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
assert user.info.note_count == 0
@@ -578,7 +579,7 @@ defmodule Pleroma.UserTest do
test "it increases the info->note_count property" do
note = insert(:note)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
assert user.info.note_count == 0
@@ -593,7 +594,7 @@ defmodule Pleroma.UserTest do
test "it decreases the info->note_count property" do
note = insert(:note)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
assert user.info.note_count == 0
@@ -695,7 +696,7 @@ defmodule Pleroma.UserTest do
assert User.following?(blocked, blocker)
{:ok, blocker} = User.block(blocker, blocked)
- blocked = User.get_by_id(blocked.id)
+ blocked = User.get_cached_by_id(blocked.id)
assert User.blocks?(blocker, blocked)
@@ -713,7 +714,7 @@ defmodule Pleroma.UserTest do
refute User.following?(blocked, blocker)
{:ok, blocker} = User.block(blocker, blocked)
- blocked = User.get_by_id(blocked.id)
+ blocked = User.get_cached_by_id(blocked.id)
assert User.blocks?(blocker, blocked)
@@ -731,7 +732,7 @@ defmodule Pleroma.UserTest do
assert User.following?(blocked, blocker)
{:ok, blocker} = User.block(blocker, blocked)
- blocked = User.get_by_id(blocked.id)
+ blocked = User.get_cached_by_id(blocked.id)
assert User.blocks?(blocker, blocked)
@@ -851,9 +852,9 @@ defmodule Pleroma.UserTest do
{:ok, _} = User.delete(user)
- followed = User.get_by_id(followed.id)
- follower = User.get_by_id(follower.id)
- user = User.get_by_id(user.id)
+ followed = User.get_cached_by_id(followed.id)
+ follower = User.get_cached_by_id(follower.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.deactivated
@@ -1007,7 +1008,7 @@ defmodule Pleroma.UserTest do
results = User.search("http://mastodon.example.org/users/admin", resolve: true)
result = results |> List.first()
- user = User.get_by_ap_id("http://mastodon.example.org/users/admin")
+ user = User.get_cached_by_ap_id("http://mastodon.example.org/users/admin")
assert length(results) == 1
assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
@@ -1132,14 +1133,14 @@ defmodule Pleroma.UserTest do
"status" => "heweoo!"
})
- id1 = activity1.data["object"]["id"]
+ id1 = Object.normalize(activity1).data["id"]
{:ok, activity2} =
CommonAPI.post(user, %{
"status" => "heweoo!"
})
- id2 = activity2.data["object"]["id"]
+ id2 = Object.normalize(activity2).data["id"]
assert {:ok, user_state1} = User.bookmark(user, id1)
assert user_state1.bookmarks == [id1]
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 7b1c60f15..30adfda36 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> put_req_header("accept", "application/json")
|> get("/users/#{user.nickname}")
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
end
@@ -65,7 +65,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> put_req_header("accept", "application/activity+json")
|> get("/users/#{user.nickname}")
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
end
@@ -83,7 +83,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
)
|> get("/users/#{user.nickname}")
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
end
@@ -572,7 +572,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
user = insert(:user)
Enum.each(1..15, fn _ ->
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
other_user = insert(:user)
User.follow(user, other_user)
end)
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 79116824e..f8e987e58 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -84,17 +84,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
{:ok, status_two} = CommonAPI.post(user, %{"status" => ". #essais"})
{:ok, status_three} = CommonAPI.post(user, %{"status" => ". #test #reject"})
- fetch_one = ActivityPub.fetch_activities([], %{"tag" => "test"})
- fetch_two = ActivityPub.fetch_activities([], %{"tag" => ["test", "essais"]})
+ fetch_one = ActivityPub.fetch_activities([], %{"type" => "Create", "tag" => "test"})
+
+ fetch_two =
+ ActivityPub.fetch_activities([], %{"type" => "Create", "tag" => ["test", "essais"]})
fetch_three =
ActivityPub.fetch_activities([], %{
+ "type" => "Create",
"tag" => ["test", "essais"],
"tag_reject" => ["reject"]
})
fetch_four =
ActivityPub.fetch_activities([], %{
+ "type" => "Create",
"tag" => ["test"],
"tag_all" => ["test", "reject"]
})
@@ -192,8 +196,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
}
{:ok, %Activity{} = activity} = ActivityPub.insert(data)
- assert is_binary(activity.data["object"]["id"])
- assert %Object{} = Object.get_by_ap_id(activity.data["object"]["id"])
+ object = Object.normalize(activity.data["object"])
+
+ assert is_binary(object.data["id"])
+ assert %Object{} = Object.get_by_ap_id(activity.data["object"])
end
end
@@ -206,7 +212,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
to: ["user1", "user1", "user2"],
actor: user,
context: "",
- object: %{}
+ object: %{
+ "to" => ["user1", "user1", "user2"],
+ "type" => "Note",
+ "content" => "testing"
+ }
})
assert activity.data["to"] == ["user1", "user2"]
@@ -218,18 +228,30 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
user = insert(:user)
{:ok, _} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "1", "visibility" => "public"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "1",
+ "visibility" => "public"
+ })
{:ok, _} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "2", "visibility" => "unlisted"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "2",
+ "visibility" => "unlisted"
+ })
{:ok, _} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "2", "visibility" => "private"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "2",
+ "visibility" => "private"
+ })
{:ok, _} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "3", "visibility" => "direct"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "3",
+ "visibility" => "direct"
+ })
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.note_count == 2
end
@@ -244,25 +266,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
# public
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "public"))
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
- assert data["object"]["repliesCount"] == 1
assert object.data["repliesCount"] == 1
# unlisted
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "unlisted"))
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
- assert data["object"]["repliesCount"] == 2
assert object.data["repliesCount"] == 2
# private
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "private"))
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
- assert data["object"]["repliesCount"] == 2
assert object.data["repliesCount"] == 2
# direct
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "direct"))
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
- assert data["object"]["repliesCount"] == 2
assert object.data["repliesCount"] == 2
end
end
@@ -680,40 +698,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
end
- describe "fetching an object" do
- test "it fetches an object" do
- {:ok, object} =
- ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
-
- assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
- assert activity.data["id"]
-
- {:ok, object_again} =
- ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
-
- assert [attachment] = object.data["attachment"]
- assert is_list(attachment["url"])
-
- assert object == object_again
- end
-
- test "it works with objects only available via Ostatus" do
- {:ok, object} = ActivityPub.fetch_object_from_id("https://shitposter.club/notice/2827873")
- assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
- assert activity.data["id"]
-
- {:ok, object_again} =
- ActivityPub.fetch_object_from_id("https://shitposter.club/notice/2827873")
+ describe "fetch the latest Follow" do
+ test "fetches the latest Follow activity" do
+ %Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity)
+ follower = Repo.get_by(User, ap_id: activity.data["actor"])
+ followed = Repo.get_by(User, ap_id: activity.data["object"])
- assert object == object_again
- end
-
- test "it correctly stitches up conversations between ostatus and ap" do
- last = "https://mstdn.io/users/mayuutann/statuses/99568293732299394"
- {:ok, object} = ActivityPub.fetch_object_from_id(last)
-
- object = Object.get_by_ap_id(object.data["inReplyTo"])
- assert object
+ assert activity == Utils.fetch_latest_follow(follower, followed)
end
end
@@ -793,23 +784,35 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
user = insert(:user, info: %{note_count: 10})
{:ok, a1} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "public"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "yeah",
+ "visibility" => "public"
+ })
{:ok, a2} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "unlisted"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "yeah",
+ "visibility" => "unlisted"
+ })
{:ok, a3} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "private"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "yeah",
+ "visibility" => "private"
+ })
{:ok, a4} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "direct"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "yeah",
+ "visibility" => "direct"
+ })
- {:ok, _} = a1.data["object"]["id"] |> Object.get_by_ap_id() |> ActivityPub.delete()
- {:ok, _} = a2.data["object"]["id"] |> Object.get_by_ap_id() |> ActivityPub.delete()
- {:ok, _} = a3.data["object"]["id"] |> Object.get_by_ap_id() |> ActivityPub.delete()
- {:ok, _} = a4.data["object"]["id"] |> Object.get_by_ap_id() |> ActivityPub.delete()
+ {:ok, _} = Object.normalize(a1) |> ActivityPub.delete()
+ {:ok, _} = Object.normalize(a2) |> ActivityPub.delete()
+ {:ok, _} = Object.normalize(a3) |> ActivityPub.delete()
+ {:ok, _} = Object.normalize(a4) |> ActivityPub.delete()
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.note_count == 10
end
@@ -849,22 +852,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
_ = CommonAPI.delete(direct_reply.id, user2)
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
- assert data["object"]["repliesCount"] == 2
assert object.data["repliesCount"] == 2
_ = CommonAPI.delete(private_reply.id, user2)
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
- assert data["object"]["repliesCount"] == 2
assert object.data["repliesCount"] == 2
_ = CommonAPI.delete(public_reply.id, user2)
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
- assert data["object"]["repliesCount"] == 1
assert object.data["repliesCount"] == 1
_ = CommonAPI.delete(unlisted_reply.id, user2)
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
- assert data["object"]["repliesCount"] == 0
assert object.data["repliesCount"] == 0
end
end
@@ -906,7 +905,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
activities = ActivityPub.fetch_activities([user1.ap_id | user1.following])
private_activity_1 = Activity.get_by_ap_id_with_object(private_activity_1.data["id"])
- assert [public_activity, private_activity_1, private_activity_3] == activities
+
+ assert [public_activity, private_activity_1, private_activity_3] ==
+ activities
+
assert length(activities) == 3
activities = ActivityPub.contain_timeline(activities, user1)
@@ -916,15 +918,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
end
- test "it can fetch plume articles" do
- {:ok, object} =
- ActivityPub.fetch_object_from_id(
- "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
- )
-
- assert object
- end
-
describe "update" do
test "it creates an update activity with the new user data" do
user = insert(:user)
@@ -946,15 +939,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
end
- test "it can fetch peertube videos" do
- {:ok, object} =
- ActivityPub.fetch_object_from_id(
- "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
- )
-
- assert object
- end
-
test "returned pinned statuses" do
Pleroma.Config.put([:instance, :max_pinned_statuses], 3)
user = insert(:user)
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index c857a7ec1..31e36a987 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
use Pleroma.DataCase
alias Pleroma.Activity
alias Pleroma.Object
+ alias Pleroma.Object.Fetcher
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
@@ -50,14 +51,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|> Map.put("object", object)
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
+ returned_object = Object.normalize(returned_activity.data["object"])
assert activity =
Activity.get_create_by_object_ap_id(
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
)
- assert returned_activity.data["object"]["inReplyToAtomUri"] ==
- "https://shitposter.club/notice/2827873"
+ assert returned_object.data["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
end
test "it works for incoming notices" do
@@ -80,7 +81,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["actor"] == "http://mastodon.example.org/users/admin"
- object = data["object"]
+ object = Object.normalize(data["object"]).data
assert object["id"] == "http://mastodon.example.org/users/admin/statuses/99512778738411822"
assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
@@ -98,7 +99,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert object["sensitive"] == true
- user = User.get_by_ap_id(object["actor"])
+ user = User.get_cached_by_ap_id(object["actor"])
assert user.info.note_count == 1
end
@@ -107,7 +108,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- assert Enum.at(data["object"]["tag"], 2) == "moo"
+ object = Object.normalize(data["object"])
+
+ assert Enum.at(object.data["tag"], 2) == "moo"
end
test "it works for incoming notices with contentMap" do
@@ -115,8 +118,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ object = Object.normalize(data["object"])
- assert data["object"]["content"] ==
+ assert object.data["content"] ==
"<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
end
@@ -124,8 +128,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data = File.read!("test/fixtures/kroeg-post-activity.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ object = Object.normalize(data["object"])
- assert data["object"]["content"] ==
+ assert object.data["content"] ==
"<p>henlo from my Psion netBook</p><p>message sent from my Psion netBook</p>"
end
@@ -141,24 +146,27 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ object = Object.normalize(data["object"])
- assert data["object"]["emoji"] == %{
+ assert object.data["emoji"] == %{
"icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png"
}
data = File.read!("test/fixtures/kroeg-array-less-hashtag.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ object = Object.normalize(data["object"])
- assert "test" in data["object"]["tag"]
+ assert "test" in object.data["tag"]
end
test "it works for incoming notices with url not being a string (prismo)" do
data = File.read!("test/fixtures/prismo-url-map.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ object = Object.normalize(data["object"])
- assert data["object"]["url"] == "https://prismo.news/posts/83"
+ assert object.data["url"] == "https://prismo.news/posts/83"
end
test "it cleans up incoming notices which are not really DMs" do
@@ -180,15 +188,15 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data = Map.put(data, "object", object)
- {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
assert data["to"] == []
assert data["cc"] == to
- object = data["object"]
+ object_data = Object.normalize(activity).data
- assert object["to"] == []
- assert object["cc"] == to
+ assert object_data["to"] == []
+ assert object_data["cc"] == to
end
test "it works for incoming follow requests" do
@@ -204,7 +212,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["actor"] == "http://mastodon.example.org/users/admin"
assert data["type"] == "Follow"
assert data["id"] == "http://mastodon.example.org/users/admin#follows/2"
- assert User.following?(User.get_by_ap_id(data["actor"]), user)
+ assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
end
test "it works for incoming follow requests from hubzilla" do
@@ -221,7 +229,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["actor"] == "https://hubzilla.example.org/channel/kaniini"
assert data["type"] == "Follow"
assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2"
- assert User.following?(User.get_by_ap_id(data["actor"]), user)
+ assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
end
test "it works for incoming likes" do
@@ -231,14 +239,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data =
File.read!("test/fixtures/mastodon-like.json")
|> Poison.decode!()
- |> Map.put("object", activity.data["object"]["id"])
+ |> Map.put("object", activity.data["object"])
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
assert data["actor"] == "http://mastodon.example.org/users/admin"
assert data["type"] == "Like"
assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
- assert data["object"] == activity.data["object"]["id"]
+ assert data["object"] == activity.data["object"]
end
test "it returns an error for incoming unlikes wihout a like activity" do
@@ -248,7 +256,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data =
File.read!("test/fixtures/mastodon-undo-like.json")
|> Poison.decode!()
- |> Map.put("object", activity.data["object"]["id"])
+ |> Map.put("object", activity.data["object"])
assert Transmogrifier.handle_incoming(data) == :error
end
@@ -260,7 +268,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
like_data =
File.read!("test/fixtures/mastodon-like.json")
|> Poison.decode!()
- |> Map.put("object", activity.data["object"]["id"])
+ |> Map.put("object", activity.data["object"])
{:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
@@ -302,7 +310,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data =
File.read!("test/fixtures/mastodon-announce.json")
|> Poison.decode!()
- |> Map.put("object", activity.data["object"]["id"])
+ |> Map.put("object", activity.data["object"])
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
@@ -312,7 +320,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["id"] ==
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
- assert data["object"] == activity.data["object"]["id"]
+ assert data["object"] == activity.data["object"]
assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
end
@@ -324,7 +332,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data =
File.read!("test/fixtures/mastodon-announce.json")
|> Poison.decode!()
- |> Map.put("object", activity.data["object"]["id"])
+ |> Map.put("object", Object.normalize(activity).data["id"])
|> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
|> Map.put("cc", [])
@@ -450,7 +458,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
object =
data["object"]
- |> Map.put("id", activity.data["object"]["id"])
+ |> Map.put("id", activity.data["object"])
data =
data
@@ -471,7 +479,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
object =
data["object"]
- |> Map.put("id", activity.data["object"]["id"])
+ |> Map.put("id", activity.data["object"])
data =
data
@@ -489,7 +497,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
announce_data =
File.read!("test/fixtures/mastodon-announce.json")
|> Poison.decode!()
- |> Map.put("object", activity.data["object"]["id"])
+ |> Map.put("object", activity.data["object"])
{:ok, %Activity{data: announce_data, local: false}} =
Transmogrifier.handle_incoming(announce_data)
@@ -504,7 +512,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["type"] == "Undo"
assert data["object"]["type"] == "Announce"
- assert data["object"]["object"] == activity.data["object"]["id"]
+ assert data["object"]["object"] == activity.data["object"]
assert data["object"]["id"] ==
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
@@ -532,7 +540,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["object"]["object"] == user.ap_id
assert data["actor"] == "http://mastodon.example.org/users/admin"
- refute User.following?(User.get_by_ap_id(data["actor"]), user)
+ refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
end
test "it works for incoming blocks" do
@@ -549,7 +557,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["object"] == user.ap_id
assert data["actor"] == "http://mastodon.example.org/users/admin"
- blocker = User.get_by_ap_id(data["actor"])
+ blocker = User.get_cached_by_ap_id(data["actor"])
assert User.blocks?(blocker, user)
end
@@ -576,8 +584,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["object"] == blocked.ap_id
assert data["actor"] == blocker.ap_id
- blocker = User.get_by_ap_id(data["actor"])
- blocked = User.get_by_ap_id(data["object"])
+ blocker = User.get_cached_by_ap_id(data["actor"])
+ blocked = User.get_cached_by_ap_id(data["object"])
assert User.blocks?(blocker, blocked)
@@ -606,7 +614,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["object"]["object"] == user.ap_id
assert data["actor"] == "http://mastodon.example.org/users/admin"
- blocker = User.get_by_ap_id(data["actor"])
+ blocker = User.get_cached_by_ap_id(data["actor"])
refute User.blocks?(blocker, user)
end
@@ -637,7 +645,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert activity.data["object"] == follow_activity.data["id"]
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == true
end
@@ -659,7 +667,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
assert activity.data["object"] == follow_activity.data["id"]
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == true
end
@@ -679,7 +687,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
assert activity.data["object"] == follow_activity.data["id"]
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == true
end
@@ -698,7 +706,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
:error = Transmogrifier.handle_incoming(accept_data)
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
refute User.following?(follower, followed) == true
end
@@ -717,7 +725,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
:error = Transmogrifier.handle_incoming(accept_data)
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
refute User.following?(follower, followed) == true
end
@@ -742,7 +750,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} = Transmogrifier.handle_incoming(reject_data)
refute activity.local
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == false
end
@@ -764,7 +772,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == false
end
@@ -783,7 +791,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it remaps video URLs as attachments if necessary" do
{:ok, object} =
- ActivityPub.fetch_object_from_id(
+ Fetcher.fetch_object_from_id(
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
)
@@ -938,7 +946,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it strips internal fields" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :moominmamma:"})
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :firefox:"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
@@ -1018,7 +1026,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})
assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.note_count == 1
{:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
@@ -1026,7 +1034,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert user.info.note_count == 1
assert user.follower_address == "https://niu.moe/users/rye/followers"
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.note_count == 1
activity = Activity.get_by_id(activity.id)
@@ -1055,7 +1063,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
unrelated_activity = Activity.get_by_id(unrelated_activity.id)
refute user.follower_address in unrelated_activity.recipients
- user_two = User.get_by_id(user_two.id)
+ user_two = User.get_cached_by_id(user_two.id)
assert user.follower_address in user_two.following
refute "..." in user_two.following
end
@@ -1088,10 +1096,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end
describe "actor origin containment" do
- test "it rejects objects with a bogus origin" do
- {:error, _} = ActivityPub.fetch_object_from_id("https://info.pleroma.site/activity.json")
- end
-
test "it rejects activities which reference objects with bogus origins" do
data = %{
"@context" => "https://www.w3.org/ns/activitystreams",
@@ -1105,10 +1109,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
:error = Transmogrifier.handle_incoming(data)
end
- test "it rejects objects when attributedTo is wrong (variant 1)" do
- {:error, _} = ActivityPub.fetch_object_from_id("https://info.pleroma.site/activity2.json")
- end
-
test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do
data = %{
"@context" => "https://www.w3.org/ns/activitystreams",
@@ -1122,10 +1122,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
:error = Transmogrifier.handle_incoming(data)
end
- test "it rejects objects when attributedTo is wrong (variant 2)" do
- {:error, _} = ActivityPub.fetch_object_from_id("https://info.pleroma.site/activity3.json")
- end
-
test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do
data = %{
"@context" => "https://www.w3.org/ns/activitystreams",
@@ -1140,62 +1136,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end
end
- describe "general origin containment" do
- test "contain_origin_from_id() catches obvious spoofing attempts" do
- data = %{
- "id" => "http://example.com/~alyssa/activities/1234.json"
- }
-
- :error =
- Transmogrifier.contain_origin_from_id(
- "http://example.org/~alyssa/activities/1234.json",
- data
- )
- end
-
- test "contain_origin_from_id() allows alternate IDs within the same origin domain" do
- data = %{
- "id" => "http://example.com/~alyssa/activities/1234.json"
- }
-
- :ok =
- Transmogrifier.contain_origin_from_id(
- "http://example.com/~alyssa/activities/1234",
- data
- )
- end
-
- test "contain_origin_from_id() allows matching IDs" do
- data = %{
- "id" => "http://example.com/~alyssa/activities/1234.json"
- }
-
- :ok =
- Transmogrifier.contain_origin_from_id(
- "http://example.com/~alyssa/activities/1234.json",
- data
- )
- end
-
- test "users cannot be collided through fake direction spoofing attempts" do
- insert(:user, %{
- nickname: "rye@niu.moe",
- local: false,
- ap_id: "https://niu.moe/users/rye",
- follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
- })
-
- {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye")
- end
-
- test "all objects with fake directions are rejected by the object fetcher" do
- {:error, _} =
- ActivityPub.fetch_and_contain_remote_object_from_id(
- "https://info.pleroma.site/activity4.json"
- )
- end
- end
-
describe "reserialization" do
test "successfully reserializes a message with inReplyTo == nil" do
user = insert(:user)
diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs
index 758214e68..c57fae437 100644
--- a/test/web/activity_pub/utils_test.exs
+++ b/test/web/activity_pub/utils_test.exs
@@ -1,7 +1,6 @@
defmodule Pleroma.Web.ActivityPub.UtilsTest do
use Pleroma.DataCase
alias Pleroma.Activity
- alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
@@ -12,8 +11,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
describe "fetch the latest Follow" do
test "fetches the latest Follow activity" do
%Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity)
- follower = Repo.get_by(User, ap_id: activity.data["actor"])
- followed = Repo.get_by(User, ap_id: activity.data["object"])
+ follower = User.get_cached_by_ap_id(activity.data["actor"])
+ followed = User.get_cached_by_ap_id(activity.data["object"])
assert activity == Utils.fetch_latest_follow(follower, followed)
end
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index b3167a861..b89c42327 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -89,8 +89,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"followed" => user.nickname
})
- user = User.get_by_id(user.id)
- follower = User.get_by_id(follower.id)
+ user = User.get_cached_by_id(user.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, user)
end
@@ -112,8 +112,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"followed" => user.nickname
})
- user = User.get_by_id(user.id)
- follower = User.get_by_id(follower.id)
+ user = User.get_cached_by_id(user.id)
+ follower = User.get_cached_by_id(follower.id)
refute User.following?(follower, user)
end
@@ -145,13 +145,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
user2: user2
} do
assert json_response(conn, :no_content)
- assert User.get_by_id(user1.id).tags == ["x", "foo", "bar"]
- assert User.get_by_id(user2.id).tags == ["y", "foo", "bar"]
+ assert User.get_cached_by_id(user1.id).tags == ["x", "foo", "bar"]
+ assert User.get_cached_by_id(user2.id).tags == ["y", "foo", "bar"]
end
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
assert json_response(conn, :no_content)
- assert User.get_by_id(user3.id).tags == ["unchanged"]
+ assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
end
end
@@ -181,13 +181,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
user2: user2
} do
assert json_response(conn, :no_content)
- assert User.get_by_id(user1.id).tags == []
- assert User.get_by_id(user2.id).tags == ["y"]
+ assert User.get_cached_by_id(user1.id).tags == []
+ assert User.get_cached_by_id(user2.id).tags == ["y"]
end
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
assert json_response(conn, :no_content)
- assert User.get_by_id(user3.id).tags == ["unchanged"]
+ assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
end
end
@@ -257,7 +257,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn
|> put("/api/pleroma/admin/activation_status/#{user.nickname}", %{status: false})
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.deactivated == true
assert json_response(conn, :no_content)
end
@@ -269,7 +269,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn
|> put("/api/pleroma/admin/activation_status/#{user.nickname}", %{status: true})
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.deactivated == false
assert json_response(conn, :no_content)
end
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 34aa5bf18..a5b07c446 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -5,6 +5,7 @@
defmodule Pleroma.Web.CommonAPITest do
use Pleroma.DataCase
alias Pleroma.Activity
+ alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.CommonAPI
@@ -32,24 +33,26 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu #2HU"})
- assert activity.data["object"]["tag"] == ["2hu"]
+ object = Object.normalize(activity.data["object"])
+
+ assert object.data["tag"] == ["2hu"]
end
test "it adds emoji in the object" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => ":moominmamma:"})
+ {:ok, activity} = CommonAPI.post(user, %{"status" => ":firefox:"})
- assert activity.data["object"]["emoji"]["moominmamma"]
+ assert Object.normalize(activity).data["emoji"]["firefox"]
end
test "it adds emoji when updating profiles" do
- user = insert(:user, %{name: ":karjalanpiirakka:"})
+ user = insert(:user, %{name: ":firefox:"})
CommonAPI.update(user)
user = User.get_cached_by_ap_id(user.ap_id)
- [karjalanpiirakka] = user.info.source_data["tag"]
+ [firefox] = user.info.source_data["tag"]
- assert karjalanpiirakka["name"] == ":karjalanpiirakka:"
+ assert firefox["name"] == ":firefox:"
end
describe "posting" do
@@ -64,8 +67,9 @@ defmodule Pleroma.Web.CommonAPITest do
"content_type" => "text/html"
})
- content = activity.data["object"]["content"]
- assert content == "<p><b>2hu</b></p>alert('xss')"
+ object = Object.normalize(activity.data["object"])
+
+ assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
end
test "it filters out obviously bad tags when accepting a post as Markdown" do
@@ -79,8 +83,9 @@ defmodule Pleroma.Web.CommonAPITest do
"content_type" => "text/markdown"
})
- content = activity.data["object"]["content"]
- assert content == "<p><b>2hu</b></p>alert('xss')"
+ object = Object.normalize(activity.data["object"])
+
+ assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
end
end
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index f0c59d5c3..837a66063 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -37,21 +37,21 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
end
test "parses emoji from name and bio" do
- {:ok, user} = UserBuilder.insert(%{name: ":karjalanpiirakka:", bio: ":perkele:"})
+ {:ok, user} = UserBuilder.insert(%{name: ":blank:", bio: ":firefox:"})
expected = [
%{
"type" => "Emoji",
- "icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/finmoji/128px/perkele-128.png"},
- "name" => ":perkele:"
+ "icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/emoji/Firefox.gif"},
+ "name" => ":firefox:"
},
%{
"type" => "Emoji",
"icon" => %{
"type" => "Image",
- "url" => "#{Endpoint.url()}/finmoji/128px/karjalanpiirakka-128.png"
+ "url" => "#{Endpoint.url()}/emoji/blank.png"
},
- "name" => ":karjalanpiirakka:"
+ "name" => ":blank:"
}
]
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index d7487bed9..0730201bd 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -169,15 +169,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
test "represent an embedded relationship" do
user =
insert(:user, %{
- info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
+ info: %{note_count: 5, follower_count: 0, source_data: %{"type" => "Service"}},
nickname: "shp@shitposter.club",
inserted_at: ~N[2017-08-15 15:47:06.597036]
})
other_user = insert(:user)
-
{:ok, other_user} = User.follow(other_user, user)
{:ok, other_user} = User.block(other_user, user)
+ {:ok, _} = User.follow(insert(:user), user)
expected = %{
id: to_string(user.id),
@@ -186,7 +186,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
display_name: user.name,
locked: false,
created_at: "2017-08-15T15:47:06.000Z",
- followers_count: 3,
+ followers_count: 1,
following_count: 0,
statuses_count: 5,
note: user.bio,
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index f21cf677d..a22944088 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -445,7 +445,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "deleting a status" do
test "when you created it", %{conn: conn} do
activity = insert(:note_activity)
- author = User.get_by_ap_id(activity.data["actor"])
+ author = User.get_cached_by_ap_id(activity.data["actor"])
conn =
conn
@@ -1021,6 +1021,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user1 = insert(:user)
user2 = insert(:user)
user3 = insert(:user)
+ CommonAPI.favorite(activity.id, user2)
+ {:ok, user2} = User.bookmark(user2, activity.data["object"]["id"])
{:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
{:ok, _, _object} = CommonAPI.repeat(activity.id, user2)
@@ -1031,7 +1033,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{
"reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 2},
- "reblogged" => false
+ "reblogged" => false,
+ "favourited" => false,
+ "bookmarked" => false
} = json_response(conn_res, 200)
conn_res =
@@ -1041,7 +1045,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{
"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 2},
- "reblogged" => true
+ "reblogged" => true,
+ "favourited" => true,
+ "bookmarked" => true
} = json_response(conn_res, 200)
assert to_string(activity.id) == id
@@ -1161,7 +1167,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "unimplemented pinned statuses feature", %{conn: conn} do
note = insert(:note_activity)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
conn =
conn
@@ -1172,7 +1178,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "gets an users media", %{conn: conn} do
note = insert(:note_activity)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
file = %Plug.Upload{
content_type: "image/jpg",
@@ -1247,8 +1253,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
@@ -1267,8 +1273,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
@@ -1280,8 +1286,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert relationship = json_response(conn, 200)
assert to_string(other_user.id) == relationship["id"]
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == true
end
@@ -1304,7 +1310,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
@@ -1314,8 +1320,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert relationship = json_response(conn, 200)
assert to_string(other_user.id) == relationship["id"]
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
end
@@ -1600,7 +1606,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => _id, "following" => true} = json_response(conn, 200)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
@@ -1609,7 +1615,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => _id, "following" => false} = json_response(conn, 200)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
@@ -1620,6 +1626,44 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(other_user.id)
end
+ test "following without reblogs" do
+ follower = insert(:user)
+ followed = insert(:user)
+ other_user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, follower)
+ |> post("/api/v1/accounts/#{followed.id}/follow?reblogs=false")
+
+ assert %{"showing_reblogs" => false} = json_response(conn, 200)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"})
+ {:ok, reblog, _} = CommonAPI.repeat(activity.id, followed)
+
+ conn =
+ build_conn()
+ |> assign(:user, User.get_cached_by_id(follower.id))
+ |> get("/api/v1/timelines/home")
+
+ assert [] == json_response(conn, 200)
+
+ conn =
+ build_conn()
+ |> assign(:user, follower)
+ |> post("/api/v1/accounts/#{followed.id}/follow?reblogs=true")
+
+ assert %{"showing_reblogs" => true} = json_response(conn, 200)
+
+ conn =
+ build_conn()
+ |> assign(:user, User.get_cached_by_id(follower.id))
+ |> get("/api/v1/timelines/home")
+
+ expected_activity_id = reblog.id
+ assert [%{"id" => ^expected_activity_id}] = json_response(conn, 200)
+ end
+
test "following / unfollowing errors" do
user = insert(:user)
@@ -1665,7 +1709,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => _id, "muting" => true} = json_response(conn, 200)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
@@ -1720,7 +1764,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => _id, "blocking" => true} = json_response(conn, 200)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
@@ -1879,7 +1923,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
capture_log(fn ->
conn =
conn
- |> get("/api/v1/search", %{"q" => activity.data["object"]["id"]})
+ |> get("/api/v1/search", %{"q" => Object.normalize(activity).data["id"]})
assert results = json_response(conn, 200)
@@ -1944,6 +1988,199 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] = json_response(third_conn, 200)
end
+ describe "getting favorites timeline of specified user" do
+ setup do
+ [current_user, user] = insert_pair(:user, %{info: %{hide_favorites: false}})
+ [current_user: current_user, user: user]
+ end
+
+ test "returns list of statuses favorited by specified user", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ [activity | _] = insert_pair(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ [like] = response
+
+ assert length(response) == 1
+ assert like["id"] == activity.id
+ end
+
+ test "returns favorites for specified user_id when user is not logged in", %{
+ conn: conn,
+ user: user
+ } do
+ activity = insert(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ response =
+ conn
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert length(response) == 1
+ end
+
+ test "returns favorited DM only when user is logged in and he is one of recipients", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ {:ok, direct} =
+ CommonAPI.post(current_user, %{
+ "status" => "Hi @#{user.nickname}!",
+ "visibility" => "direct"
+ })
+
+ CommonAPI.favorite(direct.id, user)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert length(response) == 1
+
+ anonymous_response =
+ conn
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert length(anonymous_response) == 0
+ end
+
+ test "does not return others' favorited DM when user is not one of recipients", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ user_two = insert(:user)
+
+ {:ok, direct} =
+ CommonAPI.post(user_two, %{
+ "status" => "Hi @#{user.nickname}!",
+ "visibility" => "direct"
+ })
+
+ CommonAPI.favorite(direct.id, user)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert length(response) == 0
+ end
+
+ test "paginates favorites using since_id and max_id", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ activities = insert_list(10, :note_activity)
+
+ Enum.each(activities, fn activity ->
+ CommonAPI.favorite(activity.id, user)
+ end)
+
+ third_activity = Enum.at(activities, 2)
+ seventh_activity = Enum.at(activities, 6)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{
+ since_id: third_activity.id,
+ max_id: seventh_activity.id
+ })
+ |> json_response(:ok)
+
+ assert length(response) == 3
+ refute third_activity in response
+ refute seventh_activity in response
+ end
+
+ test "limits favorites using limit parameter", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ 7
+ |> insert_list(:note_activity)
+ |> Enum.each(fn activity ->
+ CommonAPI.favorite(activity.id, user)
+ end)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{limit: "3"})
+ |> json_response(:ok)
+
+ assert length(response) == 3
+ end
+
+ test "returns empty response when user does not have any favorited statuses", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
+ end
+
+ test "returns 404 error when specified user is not exist", %{conn: conn} do
+ conn = get(conn, "/api/v1/pleroma/accounts/test/favourites")
+
+ assert json_response(conn, 404) == %{"error" => "Record not found"}
+ end
+
+ test "returns 403 error when user has hidden own favorites", %{
+ conn: conn,
+ current_user: current_user
+ } do
+ user = insert(:user, %{info: %{hide_favorites: true}})
+ activity = insert(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ conn =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+
+ assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
+ end
+
+ test "hides favorites for new users by default", %{conn: conn, current_user: current_user} do
+ user = insert(:user)
+ activity = insert(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ conn =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+
+ assert user.info.hide_favorites
+ assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
+ end
+ end
+
describe "updating credentials" do
test "updates the user's bio", %{conn: conn} do
user = insert(:user)
@@ -2080,7 +2317,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"})
# Stats should count users with missing or nil `info.deactivated` value
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
info_change = Changeset.change(user.info, %{deactivated: nil})
{:ok, _user} =
@@ -2791,9 +3028,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"content" => "xD", "id" => id} = json_response(conn1, 200)
- activity = Activity.get_by_id(id)
+ activity = Activity.get_by_id_with_object(id)
- assert activity.data["object"]["inReplyTo"] == replied_to.data["object"]["id"]
+ assert Object.normalize(activity).data["inReplyTo"] == Object.normalize(replied_to).data["id"]
assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
# Reblog from the third user
diff --git a/test/web/mastodon_api/notification_view_test.exs b/test/web/mastodon_api/notification_view_test.exs
index f2c1eb76c..977ea1e87 100644
--- a/test/web/mastodon_api/notification_view_test.exs
+++ b/test/web/mastodon_api/notification_view_test.exs
@@ -21,7 +21,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
mentioned_user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{mentioned_user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
expected = %{
id: to_string(notification.id),
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index db2fdc2f6..f74726212 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -6,8 +6,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest 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.MastodonAPI.AccountView
@@ -53,14 +54,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
test "a note with null content" do
note = insert(:note_activity)
+ note_object = Object.normalize(note.data["object"])
data =
- note.data
- |> put_in(["object", "content"], nil)
+ note_object.data
+ |> Map.put("content", nil)
- note =
- note
- |> Map.put(:data, data)
+ Object.change(note_object, %{data: data})
+ |> Object.update_and_set_cache()
User.get_cached_by_ap_id(note.data["actor"])
@@ -127,6 +128,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
pleroma: %{
local: true,
conversation_id: convo_id,
+ in_reply_to_account_acct: nil,
content: %{"text/plain" => HtmlSanitizeEx.strip_tags(note.data["object"]["content"])},
spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(note.data["object"]["summary"])}
}
@@ -177,7 +179,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status = StatusView.render("status.json", %{activity: activity})
- actor = User.get_by_ap_id(activity.actor)
+ actor = User.get_cached_by_ap_id(activity.actor)
assert status.mentions ==
Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end)
@@ -230,7 +232,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
user = insert(:user)
{:ok, object} =
- ActivityPub.fetch_object_from_id(
+ Pleroma.Object.Fetcher.fetch_object_from_id(
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
)
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index fb505fab3..6e96537ec 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -365,6 +365,27 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
assert html_response(conn, 200) =~ ~s(type="submit")
end
+ test "properly handles internal calls with `authorization`-wrapped params", %{
+ app: app,
+ conn: conn
+ } do
+ conn =
+ get(
+ conn,
+ "/oauth/authorize",
+ %{
+ "authorization" => %{
+ "response_type" => "code",
+ "client_id" => app.client_id,
+ "redirect_uri" => app.redirect_uris,
+ "scope" => "read"
+ }
+ }
+ )
+
+ assert html_response(conn, 200) =~ ~s(type="submit")
+ end
+
test "renders authentication page if user is already authenticated but `force_login` is tru-ish",
%{app: app, conn: conn} do
token = insert(:oauth_token, app_id: app.id)
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 2950f11c0..7441e5fce 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -6,7 +6,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
alias Pleroma.Object
- alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus.ActivityRepresenter
@@ -41,7 +40,8 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
assert response(conn, 200)
# Set a wrong magic-key for a user so it has to refetch
- salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1")
+ salmon_user = User.get_cached_by_ap_id("http://gs.example.org:4040/index.php/user/1")
+
# Wrong key
info_cng =
User.Info.remote_user_creation(salmon_user.info, %{
@@ -52,7 +52,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
salmon_user
|> Ecto.Changeset.change()
|> Ecto.Changeset.put_embed(:info, info_cng)
- |> Repo.update()
+ |> User.update_and_set_cache()
conn =
build_conn()
@@ -86,7 +86,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "gets an object", %{conn: conn} do
note_activity = insert(:note_activity)
- user = User.get_by_ap_id(note_activity.data["actor"])
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
url = "/objects/#{uuid}"
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 9fd100f63..2916caf8d 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -28,34 +28,35 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming note - GS, Salmon" do
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
+ object = Object.normalize(activity.data["object"])
- user = User.get_by_ap_id(activity.data["actor"])
+ user = User.get_cached_by_ap_id(activity.data["actor"])
assert user.info.note_count == 1
assert activity.data["type"] == "Create"
- assert activity.data["object"]["type"] == "Note"
+ assert object.data["type"] == "Note"
- assert activity.data["object"]["id"] ==
- "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
+ assert object.data["id"] == "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
- assert activity.data["object"]["published"] == "2017-04-23T14:51:03+00:00"
+ assert object.data["published"] == "2017-04-23T14:51:03+00:00"
assert activity.data["context"] ==
"tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]
- assert activity.data["object"]["emoji"] == %{"marko" => "marko.png", "reimu" => "reimu.png"}
+ assert object.data["emoji"] == %{"marko" => "marko.png", "reimu" => "reimu.png"}
assert activity.local == false
end
test "handle incoming notes - GS, subscription" do
incoming = File.read!("test/fixtures/ostatus_incoming_post.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
+ object = Object.normalize(activity.data["object"])
assert activity.data["type"] == "Create"
- assert activity.data["object"]["type"] == "Note"
- assert activity.data["object"]["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"]["content"] == "Will it blend?"
+ assert object.data["type"] == "Note"
+ assert object.data["actor"] == "https://social.heldscal.la/user/23211"
+ assert object.data["content"] == "Will it blend?"
user = User.get_cached_by_ap_id(activity.data["actor"])
assert User.ap_followers(user) in activity.data["to"]
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
@@ -64,20 +65,22 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming notes with attachments - GS, subscription" do
incoming = File.read!("test/fixtures/incoming_websub_gnusocial_attachments.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
+ object = Object.normalize(activity.data["object"])
assert activity.data["type"] == "Create"
- assert activity.data["object"]["type"] == "Note"
- assert activity.data["object"]["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"]["attachment"] |> length == 2
- assert activity.data["object"]["external_url"] == "https://social.heldscal.la/notice/2020923"
+ assert object.data["type"] == "Note"
+ assert object.data["actor"] == "https://social.heldscal.la/user/23211"
+ assert object.data["attachment"] |> length == 2
+ assert object.data["external_url"] == "https://social.heldscal.la/notice/2020923"
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
end
test "handle incoming notes with tags" do
incoming = File.read!("test/fixtures/ostatus_incoming_post_tag.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
+ object = Object.normalize(activity.data["object"])
- assert activity.data["object"]["tag"] == ["nsfw"]
+ assert object.data["tag"] == ["nsfw"]
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
end
@@ -92,10 +95,11 @@ defmodule Pleroma.Web.OStatusTest do
incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
+ object = Object.normalize(activity.data["object"])
assert activity.data["type"] == "Create"
- assert activity.data["object"]["type"] == "Note"
- assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda"
+ assert object.data["type"] == "Note"
+ assert object.data["actor"] == "https://mastodon.social/users/lambadalambda"
assert activity.data["context"] == "2hu"
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
end
@@ -103,42 +107,47 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming notes - Mastodon, with CW" do
incoming = File.read!("test/fixtures/mastodon-note-cw.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
+ object = Object.normalize(activity.data["object"])
assert activity.data["type"] == "Create"
- assert activity.data["object"]["type"] == "Note"
- assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda"
- assert activity.data["object"]["summary"] == "technologic"
+ assert object.data["type"] == "Note"
+ assert object.data["actor"] == "https://mastodon.social/users/lambadalambda"
+ assert object.data["summary"] == "technologic"
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
end
test "handle incoming unlisted messages, put public into cc" do
incoming = File.read!("test/fixtures/mastodon-note-unlisted.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
+ object = Object.normalize(activity.data["object"])
+
refute "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["cc"]
- refute "https://www.w3.org/ns/activitystreams#Public" in activity.data["object"]["to"]
- assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["object"]["cc"]
+ refute "https://www.w3.org/ns/activitystreams#Public" in object.data["to"]
+ assert "https://www.w3.org/ns/activitystreams#Public" in object.data["cc"]
end
test "handle incoming retweets - Mastodon, with CW" do
incoming = File.read!("test/fixtures/cw_retweet.xml")
{:ok, [[_activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
+ retweeted_object = Object.normalize(retweeted_activity.data["object"])
- assert retweeted_activity.data["object"]["summary"] == "Hey."
+ assert retweeted_object.data["summary"] == "Hey."
end
test "handle incoming notes - GS, subscription, reply" do
incoming = File.read!("test/fixtures/ostatus_incoming_reply.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
+ object = Object.normalize(activity.data["object"])
assert activity.data["type"] == "Create"
- assert activity.data["object"]["type"] == "Note"
- assert activity.data["object"]["actor"] == "https://social.heldscal.la/user/23211"
+ assert object.data["type"] == "Note"
+ assert object.data["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"]["content"] ==
+ assert object.data["content"] ==
"@<a href=\"https://gs.archae.me/user/4687\" class=\"h-card u-url p-nickname mention\" title=\"shpbot\">shpbot</a> why not indeed."
- assert activity.data["object"]["inReplyTo"] ==
+ assert object.data["inReplyTo"] ==
"tag:gs.archae.me,2017-04-30:noticeId=778260:objectType=note"
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
@@ -150,17 +159,18 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["type"] == "Announce"
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"] == retweeted_activity.data["object"]["id"]
+ assert activity.data["object"] == retweeted_activity.data["object"]
assert "https://pleroma.soykaf.com/users/lain" in activity.data["to"]
refute activity.local
retweeted_activity = Activity.get_by_id(retweeted_activity.id)
+ retweeted_object = Object.normalize(retweeted_activity.data["object"])
assert retweeted_activity.data["type"] == "Create"
assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
refute retweeted_activity.local
- assert retweeted_activity.data["object"]["announcement_count"] == 1
- assert String.contains?(retweeted_activity.data["object"]["content"], "mastodon")
- refute String.contains?(retweeted_activity.data["object"]["content"], "Test account")
+ assert retweeted_object.data["announcement_count"] == 1
+ assert String.contains?(retweeted_object.data["content"], "mastodon")
+ refute String.contains?(retweeted_object.data["content"], "Test account")
end
test "handle incoming retweets - GS, subscription - local message" do
@@ -192,10 +202,11 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming retweets - Mastodon, salmon" do
incoming = File.read!("test/fixtures/share.xml")
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
+ retweeted_object = Object.normalize(retweeted_activity.data["object"])
assert activity.data["type"] == "Announce"
assert activity.data["actor"] == "https://mastodon.social/users/lambadalambda"
- assert activity.data["object"] == retweeted_activity.data["object"]["id"]
+ assert activity.data["object"] == retweeted_activity.data["object"]
assert activity.data["id"] ==
"tag:mastodon.social,2017-05-03:objectId=4934452:objectType=Status"
@@ -204,7 +215,7 @@ defmodule Pleroma.Web.OStatusTest do
assert retweeted_activity.data["type"] == "Create"
assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
refute retweeted_activity.local
- refute String.contains?(retweeted_activity.data["object"]["content"], "Test account")
+ refute String.contains?(retweeted_object.data["content"], "Test account")
end
test "handle incoming favorites - GS, websub" do
@@ -214,7 +225,7 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["type"] == "Like"
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"] == favorited_activity.data["object"]["id"]
+ assert activity.data["object"] == favorited_activity.data["object"]
assert activity.data["id"] ==
"tag:social.heldscal.la,2017-05-05:fave:23211:comment:2061643:2017-05-05T09:12:50+00:00"
@@ -223,7 +234,7 @@ defmodule Pleroma.Web.OStatusTest do
assert favorited_activity.data["type"] == "Create"
assert favorited_activity.data["actor"] == "https://shitposter.club/user/1"
- assert favorited_activity.data["object"]["id"] ==
+ assert favorited_activity.data["object"] ==
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
refute favorited_activity.local
@@ -258,17 +269,17 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming replies" do
incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
+ object = Object.normalize(activity.data["object"])
assert activity.data["type"] == "Create"
- assert activity.data["object"]["type"] == "Note"
+ assert object.data["type"] == "Note"
- assert activity.data["object"]["inReplyTo"] ==
+ assert object.data["inReplyTo"] ==
"http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc"
assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"]
- assert activity.data["object"]["id"] ==
- "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
+ assert object.data["id"] == "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
end
@@ -285,8 +296,8 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["object"] == "https://pawoo.net/users/pekorino"
refute activity.local
- follower = User.get_by_ap_id(activity.data["actor"])
- followed = User.get_by_ap_id(activity.data["object"])
+ follower = User.get_cached_by_ap_id(activity.data["actor"])
+ followed = User.get_cached_by_ap_id(activity.data["object"])
assert User.following?(follower, followed)
end
@@ -309,8 +320,8 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["object"]["object"] == "https://pawoo.net/users/pekorino"
refute activity.local
- follower = User.get_by_ap_id(activity.data["actor"])
- followed = User.get_by_ap_id(activity.data["object"]["object"])
+ follower = User.get_cached_by_ap_id(activity.data["actor"])
+ followed = User.get_cached_by_ap_id(activity.data["object"]["object"])
refute User.following?(follower, followed)
end
@@ -344,7 +355,7 @@ defmodule Pleroma.Web.OStatusTest do
{:ok, user} = OStatus.find_or_make_user(uri)
- user = Pleroma.User.get_by_id(user.id)
+ user = Pleroma.User.get_cached_by_id(user.id)
assert user.name == "Constance Variable"
assert user.nickname == "lambadalambda@social.heldscal.la"
assert user.local == false
@@ -495,7 +506,7 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["actor"] == "https://shitposter.club/user/1"
- assert activity.data["object"]["id"] ==
+ assert activity.data["object"] ==
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
end)
end
@@ -504,7 +515,7 @@ defmodule Pleroma.Web.OStatusTest do
url = "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056"
{:ok, [activity]} = OStatus.fetch_activity_from_url(url)
assert activity.data["actor"] == "https://social.sakamoto.gq/users/eal"
- assert activity.data["object"]["id"] == url
+ assert activity.data["object"] == url
end
end
diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs
index 6bac2c9f6..49b2a9203 100644
--- a/test/web/push/impl_test.exs
+++ b/test/web/push/impl_test.exs
@@ -107,7 +107,7 @@ defmodule Pleroma.Web.Push.ImplTest do
"type" => "Create",
"object" => %{
"content" =>
- "<span>Lorem ipsum dolor sit amet</span>, consectetur :bear: adipiscing elit. Fusce sagittis finibus turpis."
+ "<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
}
}
}
@@ -129,7 +129,7 @@ defmodule Pleroma.Web.Push.ImplTest do
insert(:note, %{
data: %{
"content" =>
- "<span>Lorem ipsum dolor sit amet</span>, consectetur :bear: adipiscing elit. Fusce sagittis finibus turpis."
+ "<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
}
})
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
index 35503259b..7532578ca 100644
--- a/test/web/salmon/salmon_test.exs
+++ b/test/web/salmon/salmon_test.exs
@@ -99,7 +99,7 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
}
{:ok, activity} = Repo.insert(%Activity{data: activity_data, recipients: activity_data["to"]})
- user = User.get_by_ap_id(activity.data["actor"])
+ user = User.get_cached_by_ap_id(activity.data["actor"])
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
poster = fn url, _data, _headers ->
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 9a9630c19..43ad71a16 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -270,7 +270,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "returns one status", %{conn: conn} do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey!"})
- actor = Repo.get_by!(User, ap_id: activity.data["actor"])
+ actor = User.get_cached_by_ap_id(activity.data["actor"])
conn =
conn
@@ -720,7 +720,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/friendships/create.json", %{user_id: followed.id})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert User.ap_followers(followed) in current_user.following
assert json_response(conn, 200) ==
@@ -735,8 +735,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/friendships/create.json", %{user_id: followed.id})
- current_user = User.get_by_id(current_user.id)
- followed = User.get_by_id(followed.id)
+ current_user = User.get_cached_by_id(current_user.id)
+ followed = User.get_cached_by_id(followed.id)
refute User.ap_followers(followed) in current_user.following
@@ -765,7 +765,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/friendships/destroy.json", %{user_id: followed.id})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert current_user.following == [current_user.ap_id]
assert json_response(conn, 200) ==
@@ -789,7 +789,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/blocks/create.json", %{user_id: blocked.id})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert User.blocks?(current_user, blocked)
assert json_response(conn, 200) ==
@@ -816,7 +816,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/blocks/destroy.json", %{user_id: blocked.id})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert current_user.info.blocks == []
assert json_response(conn, 200) ==
@@ -847,7 +847,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/qvitter/update_avatar.json", %{img: avatar_image})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert is_map(current_user.avatar)
assert json_response(conn, 200) ==
@@ -956,7 +956,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> post(request_path)
activity = Activity.get_by_id(note_activity.id)
- activity_user = User.get_by_ap_id(note_activity.data["actor"])
+ activity_user = User.get_cached_by_ap_id(note_activity.data["actor"])
assert json_response(response, 200) ==
ActivityView.render("activity.json", %{
@@ -994,7 +994,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> post(request_path)
activity = Activity.get_by_id(note_activity.id)
- activity_user = User.get_by_ap_id(note_activity.data["actor"])
+ activity_user = User.get_cached_by_ap_id(note_activity.data["actor"])
assert json_response(response, 200) ==
ActivityView.render("activity.json", %{
@@ -1022,7 +1022,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
user = json_response(conn, 200)
- fetched_user = User.get_by_nickname("lain")
+ fetched_user = User.get_cached_by_nickname("lain")
assert user == UserView.render("show.json", %{user: fetched_user})
end
@@ -1116,7 +1116,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "it confirms the user account", %{conn: conn, user: user} do
get(conn, "/api/account/confirm_email/#{user.id}/#{user.info.confirmation_token}")
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
refute user.info.confirmation_pending
refute user.info.confirmation_token
@@ -1742,7 +1742,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
})
assert json_response(conn, 200) == %{"status" => "success"}
- fetched_user = User.get_by_id(current_user.id)
+ fetched_user = User.get_cached_by_id(current_user.id)
assert Pbkdf2.checkpw("newpass", fetched_user.password_hash) == true
end
end
@@ -1783,8 +1783,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
@@ -1823,8 +1823,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
@@ -1846,8 +1846,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
@@ -1916,7 +1916,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "POST /api/media/metadata/create" do
setup do
object = insert(:note)
- user = User.get_by_ap_id(object.data["actor"])
+ user = User.get_cached_by_ap_id(object.data["actor"])
%{object: object, user: user}
end
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 4c9ae2da8..d601c8f1f 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -41,18 +41,19 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
input = %{
"status" =>
- "Hello again, @shp.<script></script>\nThis is on another :moominmamma: line. #2hu #epic #phantasmagoric",
+ "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.data["object"])
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>.&lt;script&gt;&lt;/script&gt;<br>This is on another :moominmamma: 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>"
+ "Hello again, <span class='h-card'><a data-user='#{mentioned_user.id}' class='u-url mention' href='shp'>@<span>shp</span></a></span>.&lt;script&gt;&lt;/script&gt;<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(activity.data, ["object", "content"]) == expected_text
- assert get_in(activity.data, ["object", "type"]) == "Note"
- assert get_in(activity.data, ["object", "actor"]) == user.ap_id
+ 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))
@@ -64,21 +65,20 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert Enum.member?(get_in(activity.data, ["to"]), "shp")
assert activity.local == true
- assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} =
- activity.data["object"]["emoji"]
+ assert %{"firefox" => "http://localhost:4001/emoji/Firefox.gif"} = object.data["emoji"]
# hashtags
- assert activity.data["object"]["tag"] == ["2hu", "epic", "phantasmagoric"]
+ assert object.data["tag"] == ["2hu", "epic", "phantasmagoric"]
# Add a context
assert is_binary(get_in(activity.data, ["context"]))
- assert is_binary(get_in(activity.data, ["object", "context"]))
+ assert is_binary(get_in(object.data, ["context"]))
- assert is_list(activity.data["object"]["attachment"])
+ assert is_list(object.data["attachment"])
- assert activity.data["object"] == Object.get_by_ap_id(activity.data["object"]["id"]).data
+ assert activity.data["object"] == object.data["id"]
- user = User.get_by_ap_id(user.ap_id)
+ user = User.get_cached_by_ap_id(user.ap_id)
assert user.info.note_count == 1
end
@@ -91,6 +91,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
+ object = Object.normalize(activity.data["object"])
input = %{
"status" => "Here's your (you).",
@@ -98,13 +99,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, reply = %Activity{}} = TwitterAPI.create_status(user, input)
+ reply_object = Object.normalize(reply.data["object"])
assert get_in(reply.data, ["context"]) == get_in(activity.data, ["context"])
- assert get_in(reply.data, ["object", "context"]) ==
- get_in(activity.data, ["object", "context"])
+ assert get_in(reply_object.data, ["context"]) == get_in(object.data, ["context"])
- assert get_in(reply.data, ["object", "inReplyTo"]) == get_in(activity.data, ["object", "id"])
+ assert get_in(reply_object.data, ["inReplyTo"]) == get_in(activity.data, ["object"])
assert Activity.get_in_reply_to_activity(reply).id == activity.id
end
@@ -128,7 +129,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert User.ap_followers(followed) in user.following
- followed = User.get_by_ap_id(followed.ap_id)
+ followed = User.get_cached_by_ap_id(followed.ap_id)
assert followed.info.follower_count == 1
{:error, msg} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
@@ -280,7 +281,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("lain")
+ fetched_user = User.get_cached_by_nickname("lain")
assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user})
@@ -298,7 +299,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("lain")
+ fetched_user = User.get_cached_by_nickname("lain")
assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user})
@@ -393,7 +394,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
@@ -416,7 +417,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Invalid token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
test "returns error on expired token" do
@@ -436,7 +437,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
end
@@ -461,7 +462,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
check_fn = fn invite ->
data = Map.put(data, "token", invite.token)
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user})
@@ -498,7 +499,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("vinny")
+ refute User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
refute invite.used
@@ -533,7 +534,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
@@ -554,7 +555,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
end
@@ -584,7 +585,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
refute invite.used
@@ -609,7 +610,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
@@ -629,7 +630,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
test "returns error on overdue date" do
@@ -649,7 +650,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
test "returns error on with overdue date and after max" do
@@ -671,7 +672,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
end
@@ -687,7 +688,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, error_object} = TwitterAPI.register_user(data)
assert is_binary(error_object[:error])
- refute User.get_by_nickname("lain")
+ refute User.get_cached_by_nickname("lain")
end
test "it assigns an integer conversation_id" do
@@ -708,7 +709,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
id = "https://mastodon.social/users/lambadalambda"
user = insert(:user)
{:ok, represented} = TwitterAPI.get_external_profile(user, id)
- remote = User.get_by_ap_id(id)
+ remote = User.get_cached_by_ap_id(id)
assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"]
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index c58b49ea4..56474447b 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -245,4 +245,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert html_response(response, 200) =~ "Log in to follow"
end
end
+
+ test "GET /api/pleroma/healthcheck", %{conn: conn} do
+ conn = get(conn, "/api/pleroma/healthcheck")
+
+ assert conn.status in [200, 503]
+ end
end
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index ee9a0c834..d84ab7420 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -6,6 +6,7 @@ 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
@@ -90,16 +91,16 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
test "a create activity with a summary containing emoji" do
{:ok, activity} =
CommonAPI.post(insert(:user), %{
- "spoiler_text" => ":woollysocks: meow",
+ "spoiler_text" => ":firefox: meow",
"status" => "."
})
result = ActivityView.render("activity.json", activity: activity)
- expected = ":woollysocks: meow"
+ expected = ":firefox: meow"
expected_html =
- "<img height=\"32px\" width=\"32px\" alt=\"woollysocks\" title=\"woollysocks\" src=\"http://localhost:4001/finmoji/128px/woollysocks-128.png\" /> meow"
+ "<img height=\"32px\" width=\"32px\" alt=\"firefox\" title=\"firefox\" src=\"http://localhost:4001/emoji/Firefox.gif\" /> meow"
assert result["summary"] == expected
assert result["summary_html"] == expected_html
@@ -125,10 +126,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
other_user = insert(:user, %{nickname: "shp"})
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+ object = Object.normalize(activity.data["object"])
result = ActivityView.render("activity.json", activity: activity)
- convo_id = Utils.context_to_conversation_id(activity.data["object"]["context"])
+ convo_id = Utils.context_to_conversation_id(object.data["context"])
expected = %{
"activity_type" => "post",
@@ -136,8 +138,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"attentions" => [
UserView.render("show.json", %{user: other_user})
],
- "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
- "external_url" => activity.data["object"]["id"],
+ "created_at" => object.data["published"] |> Utils.date_to_asctime(),
+ "external_url" => object.data["id"],
"fave_num" => 0,
"favorited" => false,
"id" => activity.id,
@@ -161,7 +163,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
}\">@<span>shp</span></a></span>!",
"tags" => [],
"text" => "Hey @shp!",
- "uri" => activity.data["object"]["id"],
+ "uri" => object.data["id"],
"user" => UserView.render("show.json", %{user: user}),
"visibility" => "direct",
"card" => nil,
@@ -175,8 +177,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
user = insert(:user)
other_user = insert(:user, %{nickname: "shp"})
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
+ object = Object.normalize(activity.data["object"])
- convo_id = Utils.context_to_conversation_id(activity.data["object"]["context"])
+ convo_id = Utils.context_to_conversation_id(object.data["context"])
mocks = [
{
@@ -277,9 +280,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
other_user = insert(:user, %{nickname: "shp"})
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
- {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
+ {:ok, announce, object} = CommonAPI.repeat(activity.id, other_user)
- convo_id = Utils.context_to_conversation_id(activity.data["object"]["context"])
+ convo_id = Utils.context_to_conversation_id(object.data["context"])
activity = Activity.get_by_id(activity.id)
@@ -357,7 +360,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
test "a peertube video" do
{:ok, object} =
- ActivityPub.fetch_object_from_id(
+ Pleroma.Object.Fetcher.fetch_object_from_id(
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
)
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 0feaf4b64..36b461992 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -292,7 +292,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
}
}
- blocker = User.get_by_id(blocker.id)
+ blocker = User.get_cached_by_id(blocker.id)
assert represented == UserView.render("show.json", %{user: user, for: blocker})
end