]> Untitled Git - lemmy.git/commitdiff
Upgrade activitypub_federation to 0.2.0, add setting federation.debug (#2300)
authorNutomic <me@nutomic.com>
Wed, 8 Jun 2022 15:45:39 +0000 (15:45 +0000)
committerGitHub <noreply@github.com>
Wed, 8 Jun 2022 15:45:39 +0000 (11:45 -0400)
60 files changed:
Cargo.lock
Cargo.toml
api_tests/prepare-drone-federation-test.sh
config/defaults.hjson
crates/api/Cargo.toml
crates/api_crud/Cargo.toml
crates/api_crud/src/community/create.rs
crates/apub/Cargo.toml
crates/apub/assets/lemmy/activities/community/report_page.json
crates/apub/assets/lemmy/activities/create_or_update/create_private_message.json
crates/apub/assets/lemmy/objects/chat_message.json
crates/apub/src/activities/block/block_user.rs
crates/apub/src/activities/block/mod.rs
crates/apub/src/activities/block/undo_block_user.rs
crates/apub/src/activities/community/add_mod.rs
crates/apub/src/activities/community/announce.rs
crates/apub/src/activities/community/mod.rs
crates/apub/src/activities/community/remove_mod.rs
crates/apub/src/activities/community/report.rs
crates/apub/src/activities/community/update.rs
crates/apub/src/activities/create_or_update/comment.rs
crates/apub/src/activities/create_or_update/mod.rs
crates/apub/src/activities/create_or_update/post.rs
crates/apub/src/activities/create_or_update/private_message.rs
crates/apub/src/activities/deletion/delete.rs
crates/apub/src/activities/deletion/delete_user.rs
crates/apub/src/activities/deletion/mod.rs
crates/apub/src/activities/deletion/undo_delete.rs
crates/apub/src/activities/following/accept.rs
crates/apub/src/activities/following/follow.rs
crates/apub/src/activities/following/undo_follow.rs
crates/apub/src/activities/mod.rs
crates/apub/src/activities/voting/undo_vote.rs
crates/apub/src/activities/voting/vote.rs
crates/apub/src/collections/community_moderators.rs
crates/apub/src/fetcher/search.rs
crates/apub/src/fetcher/user_or_community.rs
crates/apub/src/fetcher/webfinger.rs
crates/apub/src/http/community.rs
crates/apub/src/http/mod.rs
crates/apub/src/lib.rs
crates/apub/src/objects/comment.rs
crates/apub/src/objects/community.rs
crates/apub/src/objects/instance.rs
crates/apub/src/objects/person.rs
crates/apub/src/objects/post.rs
crates/apub/src/objects/private_message.rs
crates/apub/src/protocol/activities/community/report.rs
crates/apub/src/protocol/activities/create_or_update/private_message.rs
crates/apub/src/protocol/objects/chat_message.rs
crates/apub/src/protocol/objects/note.rs
crates/apub/src/protocol/objects/page.rs
crates/db_schema/Cargo.toml
crates/utils/src/settings/structs.rs
docker/federation/docker-compose.yml
docker/federation/lemmy_alpha.hjson
docker/federation/lemmy_beta.hjson
docker/federation/lemmy_delta.hjson
docker/federation/lemmy_epsilon.hjson
docker/federation/lemmy_gamma.hjson

index ba6e7afa4c86df0e58b57d4a32ac03691cebb783..800aa024054397b3407ffd557f2241e759723a2d 100644 (file)
@@ -4,9 +4,9 @@ version = 3
 
 [[package]]
 name = "activitypub_federation"
-version = "0.1.0"
+version = "0.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "78b34a144dc98c419543690aa8f182d8675ebe0610775982b8fdee84a00f70fe"
+checksum = "446e75aefabf78ed9cc7e175f0d90c74f478086fb9bc571a9614fb0b7cbe35d4"
 dependencies = [
  "activitypub_federation_derive",
  "actix-web",
@@ -19,6 +19,7 @@ dependencies = [
  "http",
  "http-signature-normalization-actix",
  "http-signature-normalization-reqwest",
+ "itertools",
  "once_cell",
  "openssl",
  "reqwest",
@@ -33,13 +34,13 @@ dependencies = [
 
 [[package]]
 name = "activitypub_federation_derive"
-version = "0.1.0"
+version = "0.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a2aaf58676b669d3b0dedf6bbb44fa518b5a6657b2959561d77899c668dec2a"
+checksum = "07520b54fc0f22ad30b90399b2a2689c6e5c113df0642ca3fa2f7ee823e54126"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -135,7 +136,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6"
 dependencies = [
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -287,7 +288,7 @@ dependencies = [
  "actix-router",
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -298,7 +299,7 @@ checksum = "6d44b8fee1ced9671ba043476deddef739dd0959bf77030b26b738cc591737a7"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -344,9 +345,9 @@ dependencies = [
 
 [[package]]
 name = "anyhow"
-version = "1.0.56"
+version = "1.0.57"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27"
+checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
 
 [[package]]
 name = "arrayvec"
@@ -391,18 +392,18 @@ checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
 name = "async-trait"
-version = "0.1.53"
+version = "0.1.56"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ed6aa3524a2dfcf9fe180c51eae2b58738348d819517ceadf95789c51fff7600"
+checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -862,7 +863,7 @@ dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
  "strsim",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -876,7 +877,7 @@ dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
  "strsim",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -890,7 +891,7 @@ dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
  "strsim",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -901,7 +902,7 @@ checksum = "29b5acf0dea37a7f66f7b25d2c5e93fd46f8f6968b1a5d7a3e02e97768afc95a"
 dependencies = [
  "darling_core 0.12.4",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -912,7 +913,7 @@ checksum = "72c41b3b7352feb3211a0d743dc5700a4e3b60f51bd2b368892d1e0f9a95f44b"
 dependencies = [
  "darling_core 0.13.1",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -923,7 +924,7 @@ checksum = "ddfc69c5bfcbd2fc09a0f38451d2daf0e372e367986a83906d1b0dbc88134fb5"
 dependencies = [
  "darling_core 0.14.1",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -962,7 +963,7 @@ dependencies = [
  "darling 0.12.4",
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -974,7 +975,7 @@ dependencies = [
  "darling 0.14.1",
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -984,7 +985,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "58a94ace95092c5acb1e97a7e846b310cfbd499652f72297da7493f618a98d73"
 dependencies = [
  "derive_builder_core 0.10.2",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -994,7 +995,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "8f0314b72bed045f3a68671b3c86328386762c93f82d98c65c3cb5e5f573dd68"
 dependencies = [
  "derive_builder_core 0.11.2",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -1007,7 +1008,7 @@ dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
  "rustc_version",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -1054,7 +1055,7 @@ checksum = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -1134,7 +1135,7 @@ dependencies = [
  "darling 0.13.1",
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -1395,7 +1396,7 @@ checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -1587,14 +1588,14 @@ dependencies = [
  "markup5ever",
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
 name = "http"
-version = "0.2.6"
+version = "0.2.8"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03"
+checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
 dependencies = [
  "bytes",
  "fnv",
@@ -1643,9 +1644,9 @@ dependencies = [
 
 [[package]]
 name = "http-signature-normalization-reqwest"
-version = "0.5.0"
+version = "0.6.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4a15d4498e747f1cb1b0114ad651619932eac790815d2dcef0fa89bd016fd991"
+checksum = "630652b9b1f4c18064199c57cce4ad0352d1ec6ec8ad8ffcb0c71dea41ac6b79"
 dependencies = [
  "base64",
  "bytes",
@@ -2327,7 +2328,7 @@ dependencies = [
  "migrations_internals",
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -2535,9 +2536,9 @@ dependencies = [
 
 [[package]]
 name = "once_cell"
-version = "1.10.0"
+version = "1.12.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
+checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
 
 [[package]]
 name = "opaque-debug"
@@ -2547,18 +2548,30 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
 
 [[package]]
 name = "openssl"
-version = "0.10.38"
+version = "0.10.40"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95"
+checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e"
 dependencies = [
  "bitflags",
  "cfg-if",
  "foreign-types",
  "libc",
  "once_cell",
+ "openssl-macros",
  "openssl-sys",
 ]
 
+[[package]]
+name = "openssl-macros"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c"
+dependencies = [
+ "proc-macro2 1.0.39",
+ "quote 1.0.18",
+ "syn 1.0.96",
+]
+
 [[package]]
 name = "openssl-probe"
 version = "0.1.5"
@@ -2567,9 +2580,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
 
 [[package]]
 name = "openssl-sys"
-version = "0.9.72"
+version = "0.9.74"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb"
+checksum = "835363342df5fba8354c5b453325b110ffd54044e588c539cf2f20a8014e4cb1"
 dependencies = [
  "autocfg",
  "cc",
@@ -2732,7 +2745,7 @@ dependencies = [
  "pest_meta",
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -2830,7 +2843,7 @@ checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -2893,7 +2906,7 @@ dependencies = [
  "proc-macro-error-attr",
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
  "version_check",
 ]
 
@@ -2966,7 +2979,7 @@ dependencies = [
  "itertools",
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -3451,29 +3464,29 @@ checksum = "d65bd28f48be7196d222d95b9243287f48d27aca604e08497513019ff0502cc4"
 
 [[package]]
 name = "serde"
-version = "1.0.136"
+version = "1.0.137"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
+checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
 dependencies = [
  "serde_derive",
 ]
 
 [[package]]
 name = "serde_derive"
-version = "1.0.136"
+version = "1.0.137"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9"
+checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
 name = "serde_json"
-version = "1.0.79"
+version = "1.0.81"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
+checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c"
 dependencies = [
  "indexmap",
  "itoa",
@@ -3513,7 +3526,7 @@ dependencies = [
  "darling 0.13.1",
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -3537,7 +3550,7 @@ dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
  "rustversion",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -3636,7 +3649,7 @@ checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -3709,7 +3722,7 @@ dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
  "rustversion",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -3725,9 +3738,9 @@ dependencies = [
 
 [[package]]
 name = "syn"
-version = "1.0.95"
+version = "1.0.96"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942"
+checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
@@ -3791,7 +3804,7 @@ checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -3894,7 +3907,7 @@ checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -3997,7 +4010,7 @@ dependencies = [
  "proc-macro2 1.0.39",
  "prost-build",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -4034,9 +4047,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6"
 
 [[package]]
 name = "tracing"
-version = "0.1.32"
+version = "0.1.34"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f"
+checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09"
 dependencies = [
  "cfg-if",
  "log",
@@ -4066,7 +4079,7 @@ checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
 ]
 
 [[package]]
@@ -4361,7 +4374,7 @@ dependencies = [
  "log",
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
  "wasm-bindgen-shared",
 ]
 
@@ -4395,7 +4408,7 @@ checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc"
 dependencies = [
  "proc-macro2 1.0.39",
  "quote 1.0.18",
- "syn 1.0.95",
+ "syn 1.0.96",
  "wasm-bindgen-backend",
  "wasm-bindgen-shared",
 ]
index f74a0ba3595bb09fcb99f6ac51d4a2c191fdefab..6c419d0733f48b92a9ccd8338b51f46b34863876 100644 (file)
@@ -42,7 +42,7 @@ lemmy_db_schema = { version = "=0.16.5", path = "./crates/db_schema" }
 lemmy_api_common = { version = "=0.16.5", path = "crates/api_common" }
 lemmy_websocket = { version = "=0.16.5", path = "./crates/websocket" }
 lemmy_routes = { version = "=0.16.5", path = "./crates/routes" }
-activitypub_federation = "0.1.0"
+activitypub_federation = "0.2.0"
 diesel = "1.4.8"
 diesel_migrations = "1.4.0"
 serde = { version = "1.0.136", features = ["derive"] }
index 2dbfbe25101e2c801af0b30c3de71efd5af197cf..3356f0a815835295cf4fc0b337c97d2d2fabf531 100755 (executable)
@@ -1,7 +1,6 @@
 #!/bin/bash
 set -e
 
-export APUB_TESTING_SEND_SYNC=1
 export RUST_BACKTRACE=1
 export RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
 
index caed23e97f077b47170e4dc6f33e952a877d89c7..1ec60243a007bdd01ac16798cc7f132ad824013d 100644 (file)
@@ -66,6 +66,9 @@
     # see information. If running number is consistently close to the worker_count, you should
     # increase it.
     worker_count: 64
+    # Use federation debug mode. Allows connecting to http and localhost urls. Also sends outgoing
+    # activities synchronously for easier testing. Do not use in production.
+    debug: false
   }
   captcha: {
     # Whether captcha is required for signup
index 0ef120e67c4858e2f9b7ded8729208a0a7b9e16b..9c65978fc703d8ffe5e59b401bb5fb60d330f5ce 100644 (file)
@@ -21,7 +21,7 @@ lemmy_db_views_moderator = { version = "=0.16.5", path = "../db_views_moderator"
 lemmy_db_views_actor = { version = "=0.16.5", path = "../db_views_actor", features = ["full"] }
 lemmy_api_common = { version = "=0.16.5", path = "../api_common", features = ["full"] }
 lemmy_websocket = { version = "=0.16.5", path = "../websocket" }
-activitypub_federation = "0.1.0"
+activitypub_federation = "0.2.0"
 diesel = "1.4.8"
 bcrypt = "0.12.1"
 chrono = { version = "0.4.19", features = ["serde"], default-features = false }
index e61a37f7737160144de18486e17fc861d02ae355..12ea4305ccb3729ae89cf22d9c04e5ac8bd9fe9c 100644 (file)
@@ -15,7 +15,7 @@ lemmy_db_views = { version = "=0.16.5", path = "../db_views", features = ["full"
 lemmy_db_views_actor = { version = "=0.16.5", path = "../db_views_actor", features = ["full"] }
 lemmy_api_common = { version = "=0.16.5", path = "../api_common", features = ["full"] }
 lemmy_websocket = { version = "=0.16.5", path = "../websocket" }
-activitypub_federation = "0.1.0"
+activitypub_federation = "0.2.0"
 bcrypt = "0.12.1"
 serde_json = { version = "1.0.79", features = ["preserve_order"] }
 serde = { version = "1.0.136", features = ["derive"] }
index 1181afc39b71c47b827d58cbdd8292e1cc92b9d4..3de024f8ef201477860aaf2b82ab58853c37dec6 100644 (file)
@@ -76,9 +76,7 @@ impl PerformCrud for CreateCommunity {
       &context.settings().get_protocol_and_hostname(),
     )?;
     let community_actor_id_wrapped = ObjectId::<ApubCommunity>::new(community_actor_id.clone());
-    let community_dupe = community_actor_id_wrapped
-      .dereference_local::<LemmyError>(context)
-      .await;
+    let community_dupe = community_actor_id_wrapped.dereference_local(context).await;
     if community_dupe.is_ok() {
       return Err(LemmyError::from_message("community_already_exists"));
     }
index 095247c6d34b2f47a14d545305fab7f28dd9b6ce..7ec5ece6ab4a6d8837b7db1b02464a8c3a9f20db 100644 (file)
@@ -19,7 +19,7 @@ lemmy_db_views = { version = "=0.16.5", path = "../db_views", features = ["full"
 lemmy_db_views_actor = { version = "=0.16.5", path = "../db_views_actor", features = ["full"] }
 lemmy_api_common = { version = "=0.16.5", path = "../api_common", features = ["full"] }
 lemmy_websocket = { version = "=0.16.5", path = "../websocket" }
-activitypub_federation = "0.1.0"
+activitypub_federation = "0.2.0"
 diesel = "1.4.8"
 activitystreams-kinds = "0.2.1"
 chrono = { version = "0.4.19", features = ["serde"], default-features = false }
index 724beb43ab32cca2b4591dffb6434991c34ec8d5..bd1691b57b437eaad1cbf5f74dfda3b29a9bde67 100644 (file)
@@ -1,6 +1,8 @@
 {
   "actor": "http://ds9.lemmy.ml/u/lemmy_alpha",
-  "to": "http://enterprise.lemmy.ml/c/main",
+  "to": [
+    "http://enterprise.lemmy.ml/c/main"
+  ],
   "object": "http://enterprise.lemmy.ml/post/7",
   "summary": "report this post",
   "type": "Flag",
index 85291bc06a3c9471ebfde03ee01e3fd18d5a2978..de080a8f9ccfef67f1f168987f6c6fc01f4b097d 100644 (file)
@@ -1,12 +1,16 @@
 {
   "id": "http://enterprise.lemmy.ml/activities/create/987d05fa-f637-46d7-85be-13d112bc269f",
   "actor": "http://enterprise.lemmy.ml/u/lemmy_beta",
-  "to": "http://ds9.lemmy.ml/u/lemmy_alpha",
+  "to": [
+    "http://ds9.lemmy.ml/u/lemmy_alpha"
+  ],
   "object": {
     "type": "ChatMessage",
     "id": "http://enterprise.lemmy.ml/private_message/1",
     "attributedTo": "http://enterprise.lemmy.ml/u/lemmy_beta",
-    "to": "http://ds9.lemmy.ml/u/lemmy_alpha",
+    "to": [
+      "http://ds9.lemmy.ml/u/lemmy_alpha"
+    ],
     "content": "hello",
     "mediaType": "text/html",
     "source": {
index e21312fc60b97210f02996f4e15bbd824f2e5441..c639aef92af7f09f34e1c20c25b34a86ad5bc533 100644 (file)
@@ -2,7 +2,9 @@
   "id": "https://enterprise.lemmy.ml/private_message/1621",
   "type": "ChatMessage",
   "attributedTo": "https://enterprise.lemmy.ml/u/picard",
-  "to": "https://queer.hacktivis.me/users/lanodan",
+  "to": [
+    "https://queer.hacktivis.me/users/lanodan"
+  ],
   "content": "<p>Hello hello, testing</p>\n",
   "mediaType": "text/html",
   "source": {
index 6e07fcd8cadda140f450b6cd58e4a0b883461c4f..2166259ce3f8ac63febca50a8d61455fe86a34d7 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   activities::{
-    block::{generate_cc, generate_instance_inboxes, SiteOrCommunity},
+    block::{generate_cc, SiteOrCommunity},
     community::{announce::GetCommunity, send_activity_in_community},
     generate_activity_id,
     send_lemmy_activity,
@@ -10,14 +10,14 @@ use crate::{
   },
   activity_lists::AnnouncableActivities,
   local_instance,
-  objects::{community::ApubCommunity, person::ApubPerson},
+  objects::{community::ApubCommunity, instance::remote_instance_inboxes, person::ApubPerson},
   protocol::activities::block::block_user::BlockUser,
   ActorType,
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
   data::Data,
-  traits::ActivityHandler,
+  traits::{ActivityHandler, Actor},
   utils::verify_domains_match,
 };
 use activitystreams_kinds::{activity::BlockType, public};
@@ -89,17 +89,16 @@ impl BlockUser {
       context,
     )
     .await?;
-    let block_id = block.id.clone();
 
     match target {
       SiteOrCommunity::Site(_) => {
-        let inboxes = generate_instance_inboxes(user, context.pool()).await?;
-        send_lemmy_activity(context, &block, &block_id, mod_, inboxes, false).await
+        let inboxes = remote_instance_inboxes(context.pool()).await?;
+        send_lemmy_activity(context, block, mod_, inboxes, false).await
       }
       SiteOrCommunity::Community(c) => {
         let activity = AnnouncableActivities::BlockUser(block);
-        let inboxes = vec![user.shared_inbox_or_inbox_url()];
-        send_activity_in_community(activity, &block_id, mod_, c, inboxes, context).await
+        let inboxes = vec![user.shared_inbox_or_inbox()];
+        send_activity_in_community(activity, mod_, c, inboxes, context).await
       }
     }
   }
@@ -127,7 +126,7 @@ impl ActivityHandler for BlockUser {
     verify_is_public(&self.to, &self.cc)?;
     match self
       .target
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?
     {
       SiteOrCommunity::Site(site) => {
@@ -165,15 +164,15 @@ impl ActivityHandler for BlockUser {
     let expires = self.expires.map(|u| u.naive_local());
     let mod_person = self
       .actor
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let blocked_person = self
       .object
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let target = self
       .target
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     match target {
       SiteOrCommunity::Site(_site) => {
@@ -252,7 +251,7 @@ impl GetCommunity for BlockUser {
   ) -> Result<ApubCommunity, LemmyError> {
     let target = self
       .target
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     match target {
       SiteOrCommunity::Community(c) => Ok(c),
index dec16cf3d313a179fc3d932256e129e4102c68ec..386260de2fe599ebc8575e678ff56c2232e9fb7d 100644 (file)
@@ -1,5 +1,5 @@
 use crate::{
-  objects::{community::ApubCommunity, instance::ApubSite, person::ApubPerson},
+  objects::{community::ApubCommunity, instance::ApubSite},
   protocol::objects::{group::Group, instance::Instance},
   ActorType,
 };
@@ -124,16 +124,3 @@ async fn generate_cc(target: &SiteOrCommunity, pool: &DbPool) -> Result<Vec<Url>
     SiteOrCommunity::Community(c) => vec![c.actor_id()],
   })
 }
-
-async fn generate_instance_inboxes(
-  blocked_user: &ApubPerson,
-  pool: &DbPool,
-) -> Result<Vec<Url>, LemmyError> {
-  let mut inboxes: Vec<Url> = blocking(pool, Site::read_remote_sites)
-    .await??
-    .into_iter()
-    .map(|s| s.inbox_url.into())
-    .collect();
-  inboxes.push(blocked_user.shared_inbox_or_inbox_url());
-  Ok(inboxes)
-}
index a6865303821204ba02b99d7e87fba1c3ecf16d5b..97ac3482522ec59bf8bf9dd613e3084da2e34d93 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   activities::{
-    block::{generate_cc, generate_instance_inboxes, SiteOrCommunity},
+    block::{generate_cc, SiteOrCommunity},
     community::{announce::GetCommunity, send_activity_in_community},
     generate_activity_id,
     send_lemmy_activity,
@@ -8,14 +8,14 @@ use crate::{
   },
   activity_lists::AnnouncableActivities,
   local_instance,
-  objects::{community::ApubCommunity, person::ApubPerson},
+  objects::{community::ApubCommunity, instance::remote_instance_inboxes, person::ApubPerson},
   protocol::activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
   ActorType,
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
   data::Data,
-  traits::ActivityHandler,
+  traits::{ActivityHandler, Actor},
   utils::verify_domains_match,
 };
 use activitystreams_kinds::{activity::UndoType, public};
@@ -57,15 +57,15 @@ impl UndoBlockUser {
       unparsed: Default::default(),
     };
 
-    let inboxes = vec![user.shared_inbox_or_inbox_url()];
+    let mut inboxes = vec![user.shared_inbox_or_inbox()];
     match target {
       SiteOrCommunity::Site(_) => {
-        let inboxes = generate_instance_inboxes(user, context.pool()).await?;
-        send_lemmy_activity(context, &undo, &id, mod_, inboxes, false).await
+        inboxes.append(&mut remote_instance_inboxes(context.pool()).await?);
+        send_lemmy_activity(context, undo, mod_, inboxes, false).await
       }
       SiteOrCommunity::Community(c) => {
         let activity = AnnouncableActivities::UndoBlockUser(undo);
-        send_activity_in_community(activity, &id, mod_, c, inboxes, context).await
+        send_activity_in_community(activity, mod_, c, inboxes, context).await
       }
     }
   }
@@ -106,17 +106,17 @@ impl ActivityHandler for UndoBlockUser {
     let expires = self.object.expires.map(|u| u.naive_local());
     let mod_person = self
       .actor
-      .dereference::<LemmyError>(context, instance, request_counter)
+      .dereference(context, instance, request_counter)
       .await?;
     let blocked_person = self
       .object
       .object
-      .dereference::<LemmyError>(context, instance, request_counter)
+      .dereference(context, instance, request_counter)
       .await?;
     match self
       .object
       .target
-      .dereference::<LemmyError>(context, instance, request_counter)
+      .dereference(context, instance, request_counter)
       .await?
     {
       SiteOrCommunity::Site(_site) => {
index 58d1006c8b636f024df5e574fbe538c38a292dc4..ada7afdf1dafc3ece6661430bf9f3e1c27d74035 100644 (file)
@@ -18,7 +18,11 @@ use crate::{
   protocol::activities::community::add_mod::AddMod,
   ActorType,
 };
-use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
+use activitypub_federation::{
+  core::object_id::ObjectId,
+  data::Data,
+  traits::{ActivityHandler, Actor},
+};
 use activitystreams_kinds::{activity::AddType, public};
 use lemmy_api_common::utils::blocking;
 use lemmy_db_schema::{
@@ -56,8 +60,8 @@ impl AddMod {
     };
 
     let activity = AnnouncableActivities::AddMod(add);
-    let inboxes = vec![added_mod.shared_inbox_or_inbox_url()];
-    send_activity_in_community(activity, &id, actor, community, inboxes, context).await
+    let inboxes = vec![added_mod.shared_inbox_or_inbox()];
+    send_activity_in_community(activity, actor, community, inboxes, context).await
   }
 }
 
@@ -104,7 +108,7 @@ impl ActivityHandler for AddMod {
     let community = self.get_community(context, request_counter).await?;
     let new_mod = self
       .object
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
 
     // If we had to refetch the community while parsing the activity, then the new mod has already
@@ -127,7 +131,7 @@ impl ActivityHandler for AddMod {
       // write mod log
       let actor = self
         .actor
-        .dereference::<LemmyError>(context, local_instance(context), request_counter)
+        .dereference(context, local_instance(context), request_counter)
         .await?;
       let form = ModAddCommunityForm {
         mod_person_id: actor.id,
index a2e00c786d3bebade51ef4c75b7f02574aca5b31..e5419680ef9fda18266e121d34b4cc5a90c008a9 100644 (file)
@@ -53,15 +53,7 @@ impl AnnounceActivity {
   ) -> Result<(), LemmyError> {
     let announce = AnnounceActivity::new(object.clone(), community, context)?;
     let inboxes = community.get_follower_inboxes(context).await?;
-    send_lemmy_activity(
-      context,
-      &announce,
-      &announce.id,
-      community,
-      inboxes.clone(),
-      false,
-    )
-    .await?;
+    send_lemmy_activity(context, announce, community, inboxes.clone(), false).await?;
 
     // Pleroma and Mastodon can't handle activities like Announce/Create/Page. So for
     // compatibility, we also send Announce/Page so that they can follow Lemmy communities.
@@ -71,15 +63,7 @@ impl AnnounceActivity {
       _ => return Ok(()),
     };
     let announce_compat = AnnounceActivity::new(object, community, context)?;
-    send_lemmy_activity(
-      context,
-      &announce_compat,
-      &announce_compat.id,
-      community,
-      inboxes,
-      false,
-    )
-    .await?;
+    send_lemmy_activity(context, announce_compat, community, inboxes, false).await?;
     Ok(())
   }
 }
index fe2aaf784d7552bf13d08c63a1c43f5f8a4fe82b..8506257178bfe4a7553e86d2aecdd2112f6df87a 100644 (file)
@@ -6,7 +6,7 @@ use crate::{
   protocol::activities::community::announce::AnnounceActivity,
   ActorType,
 };
-use activitypub_federation::core::object_id::ObjectId;
+use activitypub_federation::{core::object_id::ObjectId, traits::Actor};
 use lemmy_utils::error::LemmyError;
 use lemmy_websocket::LemmyContext;
 use url::Url;
@@ -18,16 +18,18 @@ pub mod report;
 pub mod update;
 
 #[tracing::instrument(skip_all)]
-pub(crate) async fn send_activity_in_community<T: ActorType>(
+pub(crate) async fn send_activity_in_community<ActorT>(
   activity: AnnouncableActivities,
-  activity_id: &Url,
-  actor: &T,
+  actor: &ActorT,
   community: &ApubCommunity,
   mut inboxes: Vec<Url>,
   context: &LemmyContext,
-) -> Result<(), LemmyError> {
-  inboxes.push(community.shared_inbox_or_inbox_url());
-  send_lemmy_activity(context, &activity, activity_id, actor, inboxes, false).await?;
+) -> Result<(), LemmyError>
+where
+  ActorT: Actor + ActorType,
+{
+  inboxes.push(community.shared_inbox_or_inbox());
+  send_lemmy_activity(context, activity.clone(), actor, inboxes, false).await?;
 
   if community.local {
     AnnounceActivity::send(activity, community, context).await?;
@@ -44,6 +46,6 @@ async fn get_community_from_moderators_url(
 ) -> Result<ApubCommunity, LemmyError> {
   let community_id = Url::parse(&moderators.to_string().replace("/moderators", ""))?;
   ObjectId::new(community_id)
-    .dereference::<LemmyError>(context, local_instance(context), request_counter)
+    .dereference(context, local_instance(context), request_counter)
     .await
 }
index 6af0e722d81442eaea01e347e9ec946d5980e89b..7c5d817f90776d1746f02eca9407605328fc6c6a 100644 (file)
@@ -18,7 +18,11 @@ use crate::{
   protocol::activities::community::remove_mod::RemoveMod,
   ActorType,
 };
-use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
+use activitypub_federation::{
+  core::object_id::ObjectId,
+  data::Data,
+  traits::{ActivityHandler, Actor},
+};
 use activitystreams_kinds::{activity::RemoveType, public};
 use lemmy_api_common::utils::blocking;
 use lemmy_db_schema::{
@@ -56,8 +60,8 @@ impl RemoveMod {
     };
 
     let activity = AnnouncableActivities::RemoveMod(remove);
-    let inboxes = vec![removed_mod.shared_inbox_or_inbox_url()];
-    send_activity_in_community(activity, &id, actor, community, inboxes, context).await
+    let inboxes = vec![removed_mod.shared_inbox_or_inbox()];
+    send_activity_in_community(activity, actor, community, inboxes, context).await
   }
 }
 
@@ -104,7 +108,7 @@ impl ActivityHandler for RemoveMod {
     let community = self.get_community(context, request_counter).await?;
     let remove_mod = self
       .object
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
 
     let form = CommunityModeratorForm {
@@ -119,7 +123,7 @@ impl ActivityHandler for RemoveMod {
     // write mod log
     let actor = self
       .actor
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let form = ModAddCommunityForm {
       mod_person_id: actor.id,
index b3f129e3710e84dda9a0268a0931dd40bca07380..c3b50abfeeb915d18cf07cf3abf125c34527d364 100644 (file)
@@ -6,7 +6,11 @@ use crate::{
   ActorType,
   PostOrComment,
 };
-use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
+use activitypub_federation::{
+  core::object_id::ObjectId,
+  data::Data,
+  traits::{ActivityHandler, Actor},
+};
 use activitystreams_kinds::activity::FlagType;
 use lemmy_api_common::{comment::CommentReportResponse, post::PostReportResponse, utils::blocking};
 use lemmy_db_schema::{
@@ -30,9 +34,7 @@ impl Report {
     reason: String,
     context: &LemmyContext,
   ) -> Result<(), LemmyError> {
-    let community = community_id
-      .dereference_local::<LemmyError>(context)
-      .await?;
+    let community = community_id.dereference_local(context).await?;
     let kind = FlagType::Flag;
     let id = generate_activity_id(
       kind.clone(),
@@ -40,22 +42,16 @@ impl Report {
     )?;
     let report = Report {
       actor: ObjectId::new(actor.actor_id()),
-      to: ObjectId::new(community.actor_id()),
+      to: [ObjectId::new(community.actor_id())],
       object: object_id,
       summary: reason,
       kind,
       id: id.clone(),
       unparsed: Default::default(),
     };
-    send_lemmy_activity(
-      context,
-      &report,
-      &id,
-      actor,
-      vec![community.shared_inbox_or_inbox_url()],
-      false,
-    )
-    .await
+
+    let inbox = vec![community.shared_inbox_or_inbox()];
+    send_lemmy_activity(context, report, actor, inbox, false).await
   }
 }
 
@@ -78,9 +74,8 @@ impl ActivityHandler for Report {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    let community = self
-      .to
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+    let community = self.to[0]
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
     Ok(())
@@ -94,11 +89,11 @@ impl ActivityHandler for Report {
   ) -> Result<(), LemmyError> {
     let actor = self
       .actor
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     match self
       .object
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?
     {
       PostOrComment::Post(post) => {
index 538838a23a1093912ebc178ede0e6647bf674393..51e2a6ea102bc8b416e7780ad4b17e373b1a504c 100644 (file)
@@ -49,7 +49,7 @@ impl UpdateCommunity {
     };
 
     let activity = AnnouncableActivities::UpdateCommunity(update);
-    send_activity_in_community(activity, &id, actor, &community, vec![], context).await
+    send_activity_in_community(activity, actor, &community, vec![], context).await
   }
 }
 
@@ -139,7 +139,7 @@ impl GetCommunity for UpdateCommunity {
   ) -> Result<ApubCommunity, LemmyError> {
     let cid = ObjectId::new(self.object.id.clone());
     cid
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await
   }
 }
index 456cbb6b012f4de30caa293226378acf8532cf89..e3b01feb1dde6c95f17cd572bd91f0370bd53cde 100644 (file)
@@ -17,7 +17,7 @@ use crate::{
 use activitypub_federation::{
   core::object_id::ObjectId,
   data::Data,
-  traits::{ActivityHandler, ApubObject},
+  traits::{ActivityHandler, Actor, ApubObject},
   utils::verify_domains_match,
 };
 use activitystreams_kinds::public;
@@ -86,13 +86,13 @@ impl CreateOrUpdateComment {
     let mut inboxes = vec![];
     for t in tagged_users {
       let person = t
-        .dereference::<LemmyError>(context, local_instance(context), request_counter)
+        .dereference(context, local_instance(context), request_counter)
         .await?;
-      inboxes.push(person.shared_inbox_or_inbox_url());
+      inboxes.push(person.shared_inbox_or_inbox());
     }
 
     let activity = AnnouncableActivities::CreateOrUpdateComment(create_or_update);
-    send_activity_in_community(activity, &id, actor, &community, inboxes, context).await
+    send_activity_in_community(activity, actor, &community, inboxes, context).await
   }
 }
 
index b0e0bf36af413729c8ad767c36327d251af2a7c3..c0854089aad9831e7d763b14956feae164a21346 100644 (file)
@@ -24,7 +24,7 @@ async fn get_comment_notif_recipients(
   let post_id = comment.post_id;
   let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
   let actor = actor
-    .dereference::<LemmyError>(context, local_instance(context), request_counter)
+    .dereference(context, local_instance(context), request_counter)
     .await?;
 
   // Note:
index a0d8ce6f44c48ed793ada69cac95c44080500c01..5d6f99548efd4cd646f7100f8250f3ee0c5f7b6e 100644 (file)
@@ -69,9 +69,8 @@ impl CreateOrUpdatePost {
     .into();
 
     let create_or_update = CreateOrUpdatePost::new(post, actor, &community, kind, context).await?;
-    let id = create_or_update.id.clone();
     let activity = AnnouncableActivities::CreateOrUpdatePost(Box::new(create_or_update));
-    send_activity_in_community(activity, &id, actor, &community, vec![], context).await
+    send_activity_in_community(activity, actor, &community, vec![], context).await
   }
 }
 
index acd50a1aa18705a5a6201f97f93696e7fbe508ff..9ad54769121d9cd6009254efb43abb6552746d77 100644 (file)
@@ -10,7 +10,7 @@ use crate::{
 use activitypub_federation::{
   core::object_id::ObjectId,
   data::Data,
-  traits::{ActivityHandler, ApubObject},
+  traits::{ActivityHandler, Actor, ApubObject},
   utils::verify_domains_match,
 };
 use lemmy_api_common::utils::blocking;
@@ -40,13 +40,13 @@ impl CreateOrUpdatePrivateMessage {
     let create_or_update = CreateOrUpdatePrivateMessage {
       id: id.clone(),
       actor: ObjectId::new(actor.actor_id()),
-      to: ObjectId::new(recipient.actor_id()),
+      to: [ObjectId::new(recipient.actor_id())],
       object: private_message.into_apub(context).await?,
       kind,
       unparsed: Default::default(),
     };
-    let inbox = vec![recipient.shared_inbox_or_inbox_url()];
-    send_lemmy_activity(context, &create_or_update, &id, actor, inbox, true).await
+    let inbox = vec![recipient.shared_inbox_or_inbox()];
+    send_lemmy_activity(context, create_or_update, actor, inbox, true).await
   }
 }
 
@@ -71,7 +71,7 @@ impl ActivityHandler for CreateOrUpdatePrivateMessage {
   ) -> Result<(), LemmyError> {
     verify_person(&self.actor, context, request_counter).await?;
     verify_domains_match(self.actor.inner(), self.object.id.inner())?;
-    verify_domains_match(self.to.inner(), self.object.to.inner())?;
+    verify_domains_match(self.to[0].inner(), self.object.to[0].inner())?;
     ApubPrivateMessage::verify(&self.object, self.actor.inner(), context, request_counter).await?;
     Ok(())
   }
index 3cf07bc8fbd4b49b26dde358535f15f17b0b241a..d2572590ad7a4691426e05671e3c678234933416 100644 (file)
@@ -24,7 +24,6 @@ use lemmy_db_schema::{
       ModRemovePost,
       ModRemovePostForm,
     },
-    person::Person,
     post::Post,
   },
   traits::Crud,
@@ -77,7 +76,7 @@ impl ActivityHandler for Delete {
       receive_remove_action(
         &self
           .actor
-          .dereference::<LemmyError>(context, local_instance(context), request_counter)
+          .dereference(context, local_instance(context), request_counter)
           .await?,
         self.object.id(),
         reason,
@@ -99,7 +98,7 @@ impl ActivityHandler for Delete {
 
 impl Delete {
   pub(in crate::activities::deletion) fn new(
-    actor: &Person,
+    actor: &ApubPerson,
     object: DeletableObjects,
     to: Url,
     community: Option<&Community>,
index d29139858530fbc79cd447896cdd12bfed872eb4..771d33eb35d1f74b1e6680975c4ffdd47958f6b9 100644 (file)
@@ -1,7 +1,7 @@
 use crate::{
   activities::{generate_activity_id, send_lemmy_activity, verify_is_public, verify_person},
   local_instance,
-  objects::person::ApubPerson,
+  objects::{instance::remote_instance_inboxes, person::ApubPerson},
   protocol::activities::deletion::delete_user::DeleteUser,
 };
 use activitypub_federation::{
@@ -11,8 +11,7 @@ use activitypub_federation::{
   utils::verify_urls_match,
 };
 use activitystreams_kinds::{activity::DeleteType, public};
-use lemmy_api_common::utils::{blocking, delete_user_account};
-use lemmy_db_schema::source::site::Site;
+use lemmy_api_common::utils::delete_user_account;
 use lemmy_utils::error::LemmyError;
 use lemmy_websocket::LemmyContext;
 use url::Url;
@@ -50,7 +49,7 @@ impl ActivityHandler for DeleteUser {
   ) -> Result<(), LemmyError> {
     let actor = self
       .actor
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     delete_user_account(actor.id, context.pool()).await?;
     Ok(())
@@ -74,12 +73,8 @@ impl DeleteUser {
       cc: vec![],
     };
 
-    let remote_sites = blocking(context.pool(), Site::read_remote_sites).await??;
-    let inboxes = remote_sites
-      .into_iter()
-      .map(|s| s.inbox_url.into())
-      .collect();
-    send_lemmy_activity(context, &delete, &id, actor, inboxes, true).await?;
+    let inboxes = remote_instance_inboxes(context.pool()).await?;
+    send_lemmy_activity(context, delete, actor, inboxes, true).await?;
     Ok(())
   }
 }
index 6283ffe0aa2693a7c88f59f4190ad4ee96b6c0d8..8bc67721ed1068c848605aed8f6b639989db2084 100644 (file)
@@ -21,7 +21,7 @@ use crate::{
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
-  traits::ApubObject,
+  traits::{Actor, ApubObject},
   utils::verify_domains_match,
 };
 use activitystreams_kinds::public;
@@ -65,22 +65,15 @@ pub async fn send_apub_delete_in_community(
   deleted: bool,
   context: &LemmyContext,
 ) -> Result<(), LemmyError> {
-  let (id, activity) = if deleted {
+  let actor = ApubPerson::from(actor);
+  let activity = if deleted {
     let delete = Delete::new(&actor, object, public(), Some(&community), reason, context)?;
-    (delete.id.clone(), AnnouncableActivities::Delete(delete))
+    AnnouncableActivities::Delete(delete)
   } else {
     let undo = UndoDelete::new(&actor, object, public(), Some(&community), reason, context)?;
-    (undo.id.clone(), AnnouncableActivities::UndoDelete(undo))
+    AnnouncableActivities::UndoDelete(undo)
   };
-  send_activity_in_community(
-    activity,
-    &id,
-    &ApubPerson::from(actor),
-    &community.into(),
-    vec![],
-    context,
-  )
-  .await
+  send_activity_in_community(activity, &actor, &community.into(), vec![], context).await
 }
 
 #[tracing::instrument(skip_all)]
@@ -97,15 +90,13 @@ pub async fn send_apub_delete_private_message(
       .into();
 
   let deletable = DeletableObjects::PrivateMessage(Box::new(pm.into()));
-  let inbox = vec![recipient.shared_inbox_or_inbox_url()];
+  let inbox = vec![recipient.shared_inbox_or_inbox()];
   if deleted {
     let delete = Delete::new(actor, deletable, recipient.actor_id(), None, None, context)?;
-    let id = delete.id.clone();
-    send_lemmy_activity(context, &delete, &id, actor, inbox, true).await?;
+    send_lemmy_activity(context, delete, actor, inbox, true).await?;
   } else {
     let undo = UndoDelete::new(actor, deletable, recipient.actor_id(), None, None, context)?;
-    let id = undo.id.clone();
-    send_lemmy_activity(context, &undo, &id, actor, inbox, true).await?;
+    send_lemmy_activity(context, undo, actor, inbox, true).await?;
   };
   Ok(())
 }
@@ -238,7 +229,7 @@ async fn receive_delete_action(
     DeletableObjects::Community(community) => {
       if community.local {
         let mod_: Person = actor
-          .dereference::<LemmyError>(context, local_instance(context), request_counter)
+          .dereference(context, local_instance(context), request_counter)
           .await?
           .deref()
           .clone();
index 0854c46e61d97c76bea568e28ac5b2d7c9b2d5d3..c43e4d87194c47a05c6b61663acf2be4fa81942f 100644 (file)
@@ -23,7 +23,6 @@ use lemmy_db_schema::{
       ModRemovePost,
       ModRemovePostForm,
     },
-    person::Person,
     post::Post,
   },
   traits::Crud,
@@ -76,7 +75,7 @@ impl ActivityHandler for UndoDelete {
       UndoDelete::receive_undo_remove_action(
         &self
           .actor
-          .dereference::<LemmyError>(context, local_instance(context), request_counter)
+          .dereference(context, local_instance(context), request_counter)
           .await?,
         self.object.object.id(),
         context,
@@ -98,7 +97,7 @@ impl ActivityHandler for UndoDelete {
 impl UndoDelete {
   #[tracing::instrument(skip_all)]
   pub(in crate::activities::deletion) fn new(
-    actor: &Person,
+    actor: &ApubPerson,
     object: DeletableObjects,
     to: Url,
     community: Option<&Community>,
index 410b678e73cdefa8f786ec0fb8c4175aa2dd4ef2..34764264e76647d03fb9584f909377146be7143c 100644 (file)
@@ -7,7 +7,7 @@ use crate::{
 use activitypub_federation::{
   core::object_id::ObjectId,
   data::Data,
-  traits::ActivityHandler,
+  traits::{ActivityHandler, Actor},
   utils::verify_urls_match,
 };
 use activitystreams_kinds::activity::AcceptType;
@@ -24,14 +24,11 @@ impl AcceptFollowCommunity {
     context: &LemmyContext,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    let community = follow
-      .object
-      .dereference_local::<LemmyError>(context)
-      .await?;
+    let community = follow.object.dereference_local(context).await?;
     let person = follow
       .actor
       .clone()
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let accept = AcceptFollowCommunity {
       actor: ObjectId::new(community.actor_id()),
@@ -43,8 +40,8 @@ impl AcceptFollowCommunity {
       )?,
       unparsed: Default::default(),
     };
-    let inbox = vec![person.inbox_url()];
-    send_lemmy_activity(context, &accept, &accept.id, &community, inbox, true).await
+    let inbox = vec![person.shared_inbox_or_inbox()];
+    send_lemmy_activity(context, accept, &community, inbox, true).await
   }
 }
 
@@ -81,12 +78,12 @@ impl ActivityHandler for AcceptFollowCommunity {
   ) -> Result<(), LemmyError> {
     let person = self
       .actor
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let community = self
       .object
       .actor
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     // This will throw an error if no follow was requested
     blocking(context.pool(), move |conn| {
index f78fadff0a9e010fa862e2ba1b6237e414892a04..b0ae72c7168088ba024936a2e5b067865f4fd2a3 100644 (file)
@@ -10,7 +10,11 @@ use crate::{
   protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity},
   ActorType,
 };
-use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
+use activitypub_federation::{
+  core::object_id::ObjectId,
+  data::Data,
+  traits::{ActivityHandler, Actor},
+};
 use activitystreams_kinds::activity::FollowType;
 use lemmy_api_common::utils::blocking;
 use lemmy_db_schema::{
@@ -56,8 +60,8 @@ impl FollowCommunity {
     .await?;
 
     let follow = FollowCommunity::new(actor, community, context)?;
-    let inbox = vec![community.inbox_url.clone().into()];
-    send_lemmy_activity(context, &follow, &follow.id, actor, inbox, true).await
+    let inbox = vec![community.shared_inbox_or_inbox()];
+    send_lemmy_activity(context, follow, actor, inbox, true).await
   }
 }
 
@@ -83,7 +87,7 @@ impl ActivityHandler for FollowCommunity {
     verify_person(&self.actor, context, request_counter).await?;
     let community = self
       .object
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
     Ok(())
@@ -97,11 +101,11 @@ impl ActivityHandler for FollowCommunity {
   ) -> Result<(), LemmyError> {
     let person = self
       .actor
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let community = self
       .object
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let community_follower_form = CommunityFollowerForm {
       community_id: community.id,
index fd178dab2022dd05188a0ee3d8f66590cc4e772b..94b0b68ecef5569930fe91b57c12a40c5ed2280c 100644 (file)
@@ -8,7 +8,7 @@ use crate::{
 use activitypub_federation::{
   core::object_id::ObjectId,
   data::Data,
-  traits::ActivityHandler,
+  traits::{ActivityHandler, Actor},
   utils::verify_urls_match,
 };
 use activitystreams_kinds::activity::UndoType;
@@ -39,8 +39,8 @@ impl UndoFollowCommunity {
       )?,
       unparsed: Default::default(),
     };
-    let inbox = vec![community.shared_inbox_or_inbox_url()];
-    send_lemmy_activity(context, &undo, &undo.id, actor, inbox, true).await
+    let inbox = vec![community.shared_inbox_or_inbox()];
+    send_lemmy_activity(context, undo, actor, inbox, true).await
   }
 }
 
@@ -77,12 +77,12 @@ impl ActivityHandler for UndoFollowCommunity {
   ) -> Result<(), LemmyError> {
     let person = self
       .actor
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let community = self
       .object
       .object
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
 
     let community_follower_form = CommunityFollowerForm {
index 3a4754996b282990ddd101f82eed6abeb4ab3044..4b884e4f1dc0701be1145ebfeb7cc2df85da2edf 100644 (file)
@@ -7,8 +7,9 @@ use crate::{
   CONTEXT,
 };
 use activitypub_federation::{
-  core::{activity_queue::SendActivity, object_id::ObjectId},
+  core::{activity_queue::send_activity, object_id::ObjectId},
   deser::context::WithContext,
+  traits::{ActivityHandler, Actor},
 };
 use activitystreams_kinds::public;
 use anyhow::anyhow;
@@ -39,7 +40,7 @@ async fn verify_person(
   request_counter: &mut i32,
 ) -> Result<(), LemmyError> {
   let person = person_id
-    .dereference::<LemmyError>(context, local_instance(context), request_counter)
+    .dereference(context, local_instance(context), request_counter)
     .await?;
   if person.banned {
     let err = anyhow!("Person {} is banned", person_id);
@@ -58,7 +59,7 @@ pub(crate) async fn verify_person_in_community(
   request_counter: &mut i32,
 ) -> Result<(), LemmyError> {
   let person = person_id
-    .dereference::<LemmyError>(context, local_instance(context), request_counter)
+    .dereference(context, local_instance(context), request_counter)
     .await?;
   if person.banned {
     return Err(LemmyError::from_message("Person is banned from site"));
@@ -91,7 +92,7 @@ pub(crate) async fn verify_mod_action(
 ) -> Result<(), LemmyError> {
   if community.local {
     let actor = mod_id
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
 
     // Note: this will also return true for admins in addition to mods, but as we dont know about
@@ -166,42 +167,31 @@ where
 }
 
 #[tracing::instrument(skip_all)]
-async fn send_lemmy_activity<T: Serialize>(
+async fn send_lemmy_activity<Activity, ActorT>(
   context: &LemmyContext,
-  activity: &T,
-  activity_id: &Url,
-  actor: &dyn ActorType,
-  inboxes: Vec<Url>,
+  activity: Activity,
+  actor: &ActorT,
+  inbox: Vec<Url>,
   sensitive: bool,
-) -> Result<(), LemmyError> {
-  if !context.settings().federation.enabled || inboxes.is_empty() {
-    return Ok(());
-  }
+) -> Result<(), LemmyError>
+where
+  Activity: ActivityHandler + Serialize,
+  ActorT: Actor + ActorType,
+  Activity: ActivityHandler<Error = LemmyError>,
+{
+  info!("Sending activity {}", activity.id().to_string());
   let activity = WithContext::new(activity, CONTEXT.deref().clone());
 
-  info!("Sending activity {}", activity_id.to_string());
-
-  // Don't send anything to ourselves
-  // TODO: this should be a debug assert
-  let hostname = context.settings().get_hostname_without_port()?;
-  let inboxes: Vec<Url> = inboxes
-    .into_iter()
-    .filter(|i| i.domain().expect("valid inbox url") != hostname)
-    .collect();
-
-  let serialised_activity = serde_json::to_string(&activity)?;
-
   let object_value = serde_json::to_value(&activity)?;
-  insert_activity(activity_id, object_value, true, sensitive, context.pool()).await?;
-
-  SendActivity {
-    activity_id: activity_id.clone(),
-    actor_public_key: actor.get_public_key(),
-    actor_private_key: actor.private_key().expect("actor has private key"),
-    inboxes,
-    activity: serialised_activity,
-  }
-  .send(local_instance(context))
+  insert_activity(activity.id(), object_value, true, sensitive, context.pool()).await?;
+
+  send_activity(
+    activity,
+    actor.get_public_key(),
+    actor.private_key().expect("actor has private key"),
+    inbox,
+    local_instance(context),
+  )
   .await?;
 
   Ok(())
index d2e72d9a4b1bc4be86e3f4f34cde7239f6276179..35b64251942dbdc28e787b1540c376a41f718423 100644 (file)
@@ -61,7 +61,7 @@ impl UndoVote {
       unparsed: Default::default(),
     };
     let activity = AnnouncableActivities::UndoVote(undo_vote);
-    send_activity_in_community(activity, &id, actor, &community, vec![], context).await
+    send_activity_in_community(activity, actor, &community, vec![], context).await
   }
 }
 
@@ -99,12 +99,12 @@ impl ActivityHandler for UndoVote {
   ) -> Result<(), LemmyError> {
     let actor = self
       .actor
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let object = self
       .object
       .object
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     match object {
       PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
index e08e4bb69c9db1bf70e0e7b5dbed6021c6ef1311..b4f4423880153cbe45fc65f3eb7e1d15a1ecc06e 100644 (file)
@@ -60,10 +60,9 @@ impl Vote {
     .await??
     .into();
     let vote = Vote::new(object, actor, &community, kind, context)?;
-    let vote_id = vote.id.clone();
 
     let activity = AnnouncableActivities::Vote(vote);
-    send_activity_in_community(activity, &vote_id, actor, &community, vec![], context).await
+    send_activity_in_community(activity, actor, &community, vec![], context).await
   }
 }
 
@@ -103,11 +102,11 @@ impl ActivityHandler for Vote {
   ) -> Result<(), LemmyError> {
     let actor = self
       .actor
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let object = self
       .object
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     match object {
       PostOrComment::Post(p) => vote_post(&self.kind, actor, &p, context).await,
@@ -126,7 +125,7 @@ impl GetCommunity for Vote {
   ) -> Result<ApubCommunity, LemmyError> {
     let object = self
       .object
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let cid = match object {
       PostOrComment::Post(p) => p.community_id,
index b8cd6469012ded2ea2b3bfbb654178c387546a88..7243ac3e75455250dc177a55e0b29ef837027660 100644 (file)
@@ -112,7 +112,7 @@ impl ApubObject for ApubCommunityModerators {
     for mod_id in apub.ordered_items {
       let mod_id = ObjectId::new(mod_id);
       let mod_user: ApubPerson = mod_id
-        .dereference::<LemmyError>(&data.1, local_instance(&data.1), request_counter)
+        .dereference(&data.1, local_instance(&data.1), request_counter)
         .await?;
 
       if !current_moderators
index 43244b4d7a7f54328a7029f63526e06eb8100e54..1622e451df6f463ddeb288f20bb27de2a7e885e8 100644 (file)
@@ -28,7 +28,7 @@ pub async fn search_by_apub_id(
   match Url::parse(query) {
     Ok(url) => {
       ObjectId::new(url)
-        .dereference::<LemmyError>(context, instance, request_counter)
+        .dereference(context, instance, request_counter)
         .await
     }
     Err(_) => {
@@ -39,7 +39,7 @@ pub async fn search_by_apub_id(
             webfinger_resolve_actor::<ApubPerson>(identifier, context, request_counter).await?;
           Ok(SearchableObjects::Person(
             ObjectId::new(id)
-              .dereference::<LemmyError>(context, instance, request_counter)
+              .dereference(context, instance, request_counter)
               .await?,
           ))
         }
@@ -48,7 +48,7 @@ pub async fn search_by_apub_id(
             webfinger_resolve_actor::<ApubCommunity>(identifier, context, request_counter).await?;
           Ok(SearchableObjects::Community(
             ObjectId::new(id)
-              .dereference::<LemmyError>(context, instance, request_counter)
+              .dereference(context, instance, request_counter)
               .await?,
           ))
         }
index 16a74c2e51db0aecd859f71c722e2dd18f71e10c..1ed9bb0f0425c6c39907d2000b6c8fa1ccc8317b 100644 (file)
@@ -2,7 +2,7 @@ use crate::{
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::objects::{group::Group, person::Person},
 };
-use activitypub_federation::{core::inbox::ActorPublicKey, traits::ApubObject};
+use activitypub_federation::traits::{Actor, ApubObject};
 use chrono::NaiveDateTime;
 use lemmy_utils::error::LemmyError;
 use lemmy_websocket::LemmyContext;
@@ -102,11 +102,15 @@ impl ApubObject for UserOrCommunity {
   }
 }
 
-impl ActorPublicKey for UserOrCommunity {
+impl Actor for UserOrCommunity {
   fn public_key(&self) -> &str {
     match self {
       UserOrCommunity::User(p) => p.public_key(),
       UserOrCommunity::Community(p) => p.public_key(),
     }
   }
+
+  fn inbox(&self) -> Url {
+    unimplemented!()
+  }
 }
index b53a988eec21de2713ba88d34d098c8b4157dbea..c46935426b47a7014154c6a026e20a9ec4461ff7 100644 (file)
@@ -69,7 +69,7 @@ where
     .collect();
   for l in links {
     let object = ObjectId::<Kind>::new(l)
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await;
     if object.is_ok() {
       return object.map(|o| o.actor_id().into());
index 6b8c7fe7e2eeaa6d48086355d8e55b9b5e524d63..8765959c5a45f11a5e9af13e0290c50a513a1549 100644 (file)
@@ -86,7 +86,7 @@ pub(crate) async fn get_apub_community_outbox(
   let id = ObjectId::new(generate_outbox_url(&community.actor_id)?);
   let outbox_data = CommunityContext(community.into(), context.get_ref().clone());
   let outbox: ApubCommunityOutbox = id
-    .dereference::<LemmyError>(&outbox_data, local_instance(&context), &mut 0)
+    .dereference(&outbox_data, local_instance(&context), &mut 0)
     .await?;
   Ok(create_apub_response(&outbox.into_apub(&outbox_data).await?))
 }
@@ -104,7 +104,7 @@ pub(crate) async fn get_apub_community_moderators(
   let id = ObjectId::new(generate_outbox_url(&community.actor_id)?);
   let outbox_data = CommunityContext(community, context.get_ref().clone());
   let moderators: ApubCommunityModerators = id
-    .dereference::<LemmyError>(&outbox_data, local_instance(&context), &mut 0)
+    .dereference(&outbox_data, local_instance(&context), &mut 0)
     .await?;
   Ok(create_apub_response(
     &moderators.into_apub(&outbox_data).await?,
index d5d94066187d9c2df0a218bafb73e84352e09883..87a8a41277297b6fe9c3facb9e90e1caf1c41157 100644 (file)
@@ -7,10 +7,10 @@ use crate::{
   CONTEXT,
 };
 use activitypub_federation::{
-  core::inbox::{receive_activity, ActorPublicKey},
+  core::inbox::receive_activity,
   data::Data,
   deser::context::WithContext,
-  traits::{ActivityHandler, ApubObject},
+  traits::{ActivityHandler, Actor, ApubObject},
   APUB_JSON_CONTENT_TYPE,
 };
 use actix_web::{web, HttpRequest, HttpResponse};
@@ -42,7 +42,7 @@ pub async fn shared_inbox(
   receive_lemmy_activity::<SharedInboxActivities, UserOrCommunity>(request, payload, context).await
 }
 
-pub async fn receive_lemmy_activity<Activity, Actor>(
+pub async fn receive_lemmy_activity<Activity, ActorT>(
   request: HttpRequest,
   payload: String,
   context: web::Data<LemmyContext>,
@@ -52,8 +52,8 @@ where
     + DeserializeOwned
     + Send
     + 'static,
-  Actor: ApubObject<DataType = LemmyContext, Error = LemmyError> + ActorPublicKey + Send + 'static,
-  for<'de2> <Actor as ApubObject>::ApubType: serde::Deserialize<'de2>,
+  ActorT: ApubObject<DataType = LemmyContext, Error = LemmyError> + Actor + Send + 'static,
+  for<'de2> <ActorT as ApubObject>::ApubType: serde::Deserialize<'de2>,
 {
   let activity_value: Value = serde_json::from_str(&payload)?;
   let activity: Activity = serde_json::from_value(activity_value.clone())?;
@@ -67,7 +67,7 @@ where
 
   static DATA: OnceCell<Data<LemmyContext>> = OnceCell::new();
   let data = DATA.get_or_init(|| Data::new(context.get_ref().clone()));
-  receive_activity::<Activity, Actor, LemmyContext, LemmyError>(
+  receive_activity::<Activity, ActorT, LemmyContext>(
     request,
     activity,
     local_instance(&context),
index e758e706db23e753e5731a3be98a5416db357729..910c66a70195d8a3bb181d7805bb68a67cb3b4f5 100644 (file)
@@ -1,6 +1,7 @@
 use crate::fetcher::post_or_comment::PostOrComment;
 use activitypub_federation::{
-  core::{inbox::ActorPublicKey, signatures::PublicKey},
+  core::signatures::PublicKey,
+  traits::{Actor, ApubObject},
   InstanceSettingsBuilder,
   LocalInstance,
 };
@@ -10,7 +11,6 @@ use lemmy_db_schema::{newtypes::DbUrl, source::activity::Activity, utils::DbPool
 use lemmy_utils::{error::LemmyError, location_info, settings::structs::Settings};
 use lemmy_websocket::LemmyContext;
 use once_cell::sync::{Lazy, OnceCell};
-use std::env;
 use url::{ParseError, Url};
 
 pub mod activities;
@@ -33,7 +33,7 @@ fn local_instance(context: &LemmyContext) -> &'static LocalInstance {
     let settings = InstanceSettingsBuilder::default()
       .http_fetch_retry_limit(context.settings().http_fetch_retry_limit)
       .worker_count(context.settings().federation.worker_count)
-      .testing_send_sync(env::var("APUB_TESTING_SEND_SYNC").is_ok())
+      .debug(context.settings().federation.debug)
       .verify_url_function(|url| check_apub_id_valid(url, &Settings::get()))
       .build()
       .expect("configure federation");
@@ -204,19 +204,11 @@ async fn insert_activity(
 
 /// Common methods provided by ActivityPub actors (community and person). Not all methods are
 /// implemented by all actors.
-pub trait ActorType: ActorPublicKey {
+pub trait ActorType: Actor + ApubObject {
   fn actor_id(&self) -> Url;
 
   fn private_key(&self) -> Option<String>;
 
-  fn inbox_url(&self) -> Url;
-
-  fn shared_inbox_url(&self) -> Option<Url>;
-
-  fn shared_inbox_or_inbox_url(&self) -> Url {
-    self.shared_inbox_url().unwrap_or_else(|| self.inbox_url())
-  }
-
   fn get_public_key(&self) -> PublicKey {
     PublicKey::new_main_key(self.actor_id(), self.public_key().to_string())
   }
index 30ddfdf6059cd8947933179ac72e3cab7daf008a..f898c3657bd435b937c21487245cc23fb68c16cd 100644 (file)
@@ -168,7 +168,7 @@ impl ApubObject for ApubComment {
   ) -> Result<ApubComment, LemmyError> {
     let creator = note
       .attributed_to
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let (post, parent_comment_id) = note.get_parents(context, request_counter).await?;
 
index 4c381c1c44387c83922ca91211baa8cbd88e2e09..ad75d37c5a49224b375fa7c37327be20bba6c09a 100644 (file)
@@ -13,8 +13,8 @@ use crate::{
   ActorType,
 };
 use activitypub_federation::{
-  core::{inbox::ActorPublicKey, object_id::ObjectId},
-  traits::ApubObject,
+  core::object_id::ObjectId,
+  traits::{Actor, ApubObject},
 };
 use activitystreams_kinds::actor::GroupType;
 use chrono::NaiveDateTime;
@@ -139,14 +139,14 @@ impl ApubObject for ApubCommunity {
 
     group
       .outbox
-      .dereference::<LemmyError>(&outbox_data, local_instance(context), request_counter)
+      .dereference(&outbox_data, local_instance(context), request_counter)
       .await
       .map_err(|e| debug!("{}", e))
       .ok();
 
     if let Some(moderators) = &group.moderators {
       moderators
-        .dereference::<LemmyError>(&outbox_data, local_instance(context), request_counter)
+        .dereference(&outbox_data, local_instance(context), request_counter)
         .await
         .map_err(|e| debug!("{}", e))
         .ok();
@@ -158,26 +158,26 @@ impl ApubObject for ApubCommunity {
   }
 }
 
-impl ActorType for ApubCommunity {
-  fn actor_id(&self) -> Url {
-    self.actor_id.to_owned().into()
-  }
-  fn private_key(&self) -> Option<String> {
-    self.private_key.to_owned()
+impl Actor for ApubCommunity {
+  fn public_key(&self) -> &str {
+    &self.public_key
   }
 
-  fn inbox_url(&self) -> Url {
+  fn inbox(&self) -> Url {
     self.inbox_url.clone().into()
   }
 
-  fn shared_inbox_url(&self) -> Option<Url> {
+  fn shared_inbox(&self) -> Option<Url> {
     self.shared_inbox_url.clone().map(|s| s.into())
   }
 }
 
-impl ActorPublicKey for ApubCommunity {
-  fn public_key(&self) -> &str {
-    &self.public_key
+impl ActorType for ApubCommunity {
+  fn actor_id(&self) -> Url {
+    self.actor_id.to_owned().into()
+  }
+  fn private_key(&self) -> Option<String> {
+    self.private_key.to_owned()
   }
 }
 
index cd4ceb467634c435ab2f426b4f825d6dc9f68078..1ae5e735c774cd2af1ae946cc334dd6a06bd24b2 100644 (file)
@@ -10,16 +10,16 @@ use crate::{
   ActorType,
 };
 use activitypub_federation::{
-  core::{inbox::ActorPublicKey, object_id::ObjectId},
+  core::object_id::ObjectId,
   deser::values::MediaTypeHtml,
-  traits::ApubObject,
+  traits::{Actor, ApubObject},
   utils::verify_domains_match,
 };
 use chrono::NaiveDateTime;
 use lemmy_api_common::utils::blocking;
 use lemmy_db_schema::{
   source::site::{Site, SiteForm},
-  utils::naive_now,
+  utils::{naive_now, DbPool},
 };
 use lemmy_utils::{
   error::LemmyError,
@@ -147,20 +147,16 @@ impl ActorType for ApubSite {
   fn private_key(&self) -> Option<String> {
     self.private_key.to_owned()
   }
-
-  fn inbox_url(&self) -> Url {
-    self.inbox_url.clone().into()
-  }
-
-  fn shared_inbox_url(&self) -> Option<Url> {
-    None
-  }
 }
 
-impl ActorPublicKey for ApubSite {
+impl Actor for ApubSite {
   fn public_key(&self) -> &str {
     &self.public_key
   }
+
+  fn inbox(&self) -> Url {
+    self.inbox_url.clone().into()
+  }
 }
 
 /// Instance actor is at the root path, so we simply need to clear the path and other unnecessary
@@ -181,13 +177,23 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object(
   // try to fetch the instance actor (to make things like instance rules available)
   let instance_id = instance_actor_id_from_url(object_id);
   let site = ObjectId::<ApubSite>::new(instance_id.clone())
-    .dereference::<LemmyError>(context, local_instance(context), request_counter)
+    .dereference(context, local_instance(context), request_counter)
     .await;
   if let Err(e) = site {
     debug!("Failed to dereference site for {}: {}", instance_id, e);
   }
 }
 
+pub(crate) async fn remote_instance_inboxes(pool: &DbPool) -> Result<Vec<Url>, LemmyError> {
+  Ok(
+    blocking(pool, Site::read_remote_sites)
+      .await??
+      .into_iter()
+      .map(|s| ApubSite::from(s).shared_inbox_or_inbox())
+      .collect(),
+  )
+}
+
 #[cfg(test)]
 pub(crate) mod tests {
   use super::*;
index 7b87f90113c6a63ebe35af1065024e3efdbd09c8..d7e346aa54ffc944f8245e270cf0a3ea5764dcf6 100644 (file)
@@ -13,8 +13,8 @@ use crate::{
   ActorType,
 };
 use activitypub_federation::{
-  core::{inbox::ActorPublicKey, object_id::ObjectId},
-  traits::ApubObject,
+  core::object_id::ObjectId,
+  traits::{Actor, ApubObject},
   utils::verify_domains_match,
 };
 use chrono::NaiveDateTime;
@@ -182,19 +182,19 @@ impl ActorType for ApubPerson {
   fn private_key(&self) -> Option<String> {
     self.private_key.to_owned()
   }
+}
 
-  fn inbox_url(&self) -> Url {
-    self.inbox_url.clone().into()
+impl Actor for ApubPerson {
+  fn public_key(&self) -> &str {
+    &self.public_key
   }
 
-  fn shared_inbox_url(&self) -> Option<Url> {
-    self.shared_inbox_url.clone().map(|s| s.into())
+  fn inbox(&self) -> Url {
+    self.inbox_url.clone().into()
   }
-}
 
-impl ActorPublicKey for ApubPerson {
-  fn public_key(&self) -> &str {
-    &self.public_key
+  fn shared_inbox(&self) -> Option<Url> {
+    self.shared_inbox_url.clone().map(|s| s.into())
   }
 }
 
index 65bcbda68ae93751baeec6d2b13cde003c7d3ba5..24424b9fefceca5ede5a6392c54ebccbb87cc0b6 100644 (file)
@@ -152,7 +152,7 @@ impl ApubObject for ApubPost {
   ) -> Result<ApubPost, LemmyError> {
     let creator = page
       .creator()?
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     let community = page.extract_community(context, request_counter).await?;
 
@@ -215,7 +215,7 @@ impl ApubObject for ApubPost {
 
     // read existing, local post if any (for generating mod log)
     let old_post = ObjectId::<ApubPost>::new(page.id.clone())
-      .dereference_local::<LemmyError>(context)
+      .dereference_local(context)
       .await;
 
     let post = blocking(context.pool(), move |conn| Post::upsert(conn, &form)).await??;
index 56363f7793181fb430c5459ac142a0bfaab34dc3..aab069e8b869563baa54d4c0d311eb79e336ec21 100644 (file)
@@ -90,7 +90,7 @@ impl ApubObject for ApubPrivateMessage {
       r#type: ChatMessageType::ChatMessage,
       id: ObjectId::new(self.ap_id.clone()),
       attributed_to: ObjectId::new(creator.actor_id),
-      to: ObjectId::new(recipient.actor_id),
+      to: [ObjectId::new(recipient.actor_id)],
       content: markdown_to_html(&self.content),
       media_type: Some(MediaTypeHtml::Html),
       source: Some(Source::new(self.content.clone())),
@@ -112,7 +112,7 @@ impl ApubObject for ApubPrivateMessage {
     check_apub_id_valid_with_strictness(note.id.inner(), false, &Settings::get())?;
     let person = note
       .attributed_to
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
     if person.banned {
       return Err(LemmyError::from_message("Person is banned from site"));
@@ -128,11 +128,10 @@ impl ApubObject for ApubPrivateMessage {
   ) -> Result<ApubPrivateMessage, LemmyError> {
     let creator = note
       .attributed_to
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+      .dereference(context, local_instance(context), request_counter)
       .await?;
-    let recipient = note
-      .to
-      .dereference::<LemmyError>(context, local_instance(context), request_counter)
+    let recipient = note.to[0]
+      .dereference(context, local_instance(context), request_counter)
       .await?;
 
     let form = PrivateMessageForm {
index cd66c657eee5837ae8fd12e29be8ed1465622065..4c2649eeffff8e519713df87d3a197d2388fd9c7 100644 (file)
@@ -13,7 +13,7 @@ use url::Url;
 pub struct Report {
   pub(crate) actor: ObjectId<ApubPerson>,
   #[serde(deserialize_with = "deserialize_one")]
-  pub(crate) to: ObjectId<ApubCommunity>,
+  pub(crate) to: [ObjectId<ApubCommunity>; 1],
   pub(crate) object: ObjectId<PostOrComment>,
   pub(crate) summary: String,
   #[serde(rename = "type")]
index e0288498b1e8d5a19fd5f965a43da360f9aecd45..9cee8ddf3840babc08ae442abdb06134a1ea602f 100644 (file)
@@ -12,7 +12,7 @@ pub struct CreateOrUpdatePrivateMessage {
   pub(crate) id: Url,
   pub(crate) actor: ObjectId<ApubPerson>,
   #[serde(deserialize_with = "deserialize_one")]
-  pub(crate) to: ObjectId<ApubPerson>,
+  pub(crate) to: [ObjectId<ApubPerson>; 1],
   pub(crate) object: ChatMessage,
   #[serde(rename = "type")]
   pub(crate) kind: CreateOrUpdateType,
index c2ee57e4eb4dff4a05cbc3c91b92c1f247e42cd2..152e8508fcd62186be45056bd13e08f29c29e1aa 100644 (file)
@@ -21,7 +21,7 @@ pub struct ChatMessage {
   pub(crate) id: ObjectId<ApubPrivateMessage>,
   pub(crate) attributed_to: ObjectId<ApubPerson>,
   #[serde(deserialize_with = "deserialize_one")]
-  pub(crate) to: ObjectId<ApubPerson>,
+  pub(crate) to: [ObjectId<ApubPerson>; 1],
   pub(crate) content: String,
 
   pub(crate) media_type: Option<MediaTypeHtml>,
index cd17e65d5f6cc1c102a0389a9b65f02baadace07..f052e88b273c7ea9a92a3e8a0e0e42dd83bbfd57 100644 (file)
@@ -56,7 +56,7 @@ impl Note {
     let parent = Box::pin(
       self
         .in_reply_to
-        .dereference::<LemmyError>(context, local_instance(context), request_counter)
+        .dereference(context, local_instance(context), request_counter)
         .await?,
     );
     match parent.deref() {
index 74db11afef500ba5ff99d2c719a720dd0cc8c86c..8aa5a49a03c9702d789bd63098341bf5638f11d0 100644 (file)
@@ -93,7 +93,7 @@ impl Page {
   /// Both stickied and locked need to be false on a newly created post (verified in [[CreatePost]].
   pub(crate) async fn is_mod_action(&self, context: &LemmyContext) -> Result<bool, LemmyError> {
     let old_post = ObjectId::<ApubPost>::new(self.id.clone())
-      .dereference_local::<LemmyError>(context)
+      .dereference_local(context)
       .await;
 
     let stickied_changed = Page::is_stickied_changed(&old_post, &self.stickied);
@@ -139,7 +139,7 @@ impl Page {
           if let Some(cid) = iter.next() {
             let cid = ObjectId::new(cid.clone());
             if let Ok(c) = cid
-              .dereference::<LemmyError>(context, local_instance(context), request_counter)
+              .dereference(context, local_instance(context), request_counter)
               .await
             {
               break Ok(c);
@@ -154,7 +154,7 @@ impl Page {
           .find(|a| a.kind == PersonOrGroupType::Group)
           .map(|a| ObjectId::<ApubCommunity>::new(a.id.clone().into_inner()))
           .ok_or_else(|| LemmyError::from_message("page does not specify group"))?
-          .dereference::<LemmyError>(context, local_instance(context), request_counter)
+          .dereference(context, local_instance(context), request_counter)
           .await
       }
     }
index 483c9e945ef6cf4ae6fadf1ba158c5541fc01a9c..e5f7493871d5c8ec643d7da28f876c5b8c5c8350 100644 (file)
@@ -23,7 +23,7 @@ url = { version = "2.2.2", features = ["serde"] }
 strum =  "0.24.0"
 strum_macros = "0.24.0"
 serde_json = { version = "1.0.79", features = ["preserve_order"], optional = true }
-activitypub_federation = { version = "0.1.0", optional = true }
+activitypub_federation = { version = "0.2.0", optional = true }
 lemmy_utils = { version = "=0.16.5", path = "../utils", optional = true }
 bcrypt = { version = "0.12.1", optional = true }
 diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"], optional = true }
index f57410ee30e5b05a8f95336546e0570fa4390d55..b703e0322c7c09ec83b0ccc7a573441fda476919 100644 (file)
@@ -135,6 +135,10 @@ pub struct FederationConfig {
   /// increase it.
   #[default(64)]
   pub worker_count: u64,
+  /// Use federation debug mode. Allows connecting to http and localhost urls. Also sends outgoing
+  /// activities synchronously for easier testing. Do not use in production.
+  #[default(false)]
+  pub debug: bool,
 }
 
 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
index 94d4ecb9960ffeba3757d980efb8e86539233fcb..f76316744d20b2cf43eb1d0551110f67c3058dc0 100644 (file)
@@ -40,7 +40,6 @@ services:
     volumes:
       - ./lemmy_alpha.hjson:/config/config.hjson
     environment:
-      - APUB_TESTING_SEND_SYNC
       - RUST_BACKTRACE=1
       - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
@@ -69,7 +68,6 @@ services:
     volumes:
       - ./lemmy_beta.hjson:/config/config.hjson
     environment:
-      - APUB_TESTING_SEND_SYNC
       - RUST_BACKTRACE=1
       - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
@@ -98,7 +96,6 @@ services:
     volumes:
       - ./lemmy_gamma.hjson:/config/config.hjson
     environment:
-      - APUB_TESTING_SEND_SYNC
       - RUST_BACKTRACE=1
       - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
@@ -128,7 +125,6 @@ services:
     volumes:
       - ./lemmy_delta.hjson:/config/config.hjson
     environment:
-      - APUB_TESTING_SEND_SYNC
       - RUST_BACKTRACE=1
       - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
@@ -158,7 +154,6 @@ services:
     volumes:
       - ./lemmy_epsilon.hjson:/config/config.hjson
     environment:
-      - APUB_TESTING_SEND_SYNC
       - RUST_BACKTRACE=1
       - RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
     depends_on:
index 6c0c54dff5257fde2371109c6b327094546af80c..246c1f5cab37eb44d44adf641621ae976f8d3c9a 100644 (file)
@@ -19,6 +19,7 @@
   federation: {
     enabled: true
     allowed_instances: ["lemmy-beta","lemmy-gamma","lemmy-delta","lemmy-epsilon"]
+    debug: true
   }
   captcha: {
     enabled: false
index b630dacae46a042a0c4a1ec6c3be445b755e86a5..87184f1aecaa9d898258528f990a810ba160cd22 100644 (file)
@@ -18,6 +18,7 @@
   federation: {
     enabled: true
     allowed_instances: ["lemmy-alpha","lemmy-gamma","lemmy-delta","lemmy-epsilon"]
+    debug: true
   }
   captcha: {
     enabled: false
index 8d400fc091d054d7d809fb897c042dfd5941290d..9c1c7aee716184c4e3eff1584f2939a918c0dae4 100644 (file)
@@ -18,6 +18,7 @@
   federation: {
     enabled: true
     allowed_instances: ["lemmy-beta"]
+    debug: true
   }
   captcha: {
     enabled: false
index 78b1a687e991defd8e60ad702e05cf02c1379376..c1b19f07f8b06d620ab6809caec7dd4d1b57e81c 100644 (file)
@@ -18,6 +18,7 @@
   federation: {
     enabled: true
     blocked_instances: ["lemmy-alpha"]
+    debug: true
   }
   captcha: {
     enabled: false
index 8d3f097a1fd35ba25bed17c3500ecd24b189e1b0..4d479174637218eb6fe2d734e2c689ef66085df0 100644 (file)
@@ -18,6 +18,7 @@
   federation: {
     enabled: true
     allowed_instances: ["lemmy-alpha","lemmy-beta","lemmy-delta","lemmy-epsilon"]
+    debug: true
   }
   captcha: {
     enabled: false