From 54172bd322c5aef4ff7243a3ece316c8bbf80c2c Mon Sep 17 00:00:00 2001 From: Felix Date: Thu, 12 Mar 2020 01:01:25 +0100 Subject: [PATCH] updated to activitystreams 0.4.0-alpha.3 --- server/Cargo.lock | 148 +++++++++++++++++++++---------- server/Cargo.toml | 5 +- server/src/apub/community.rs | 84 +++++++++++------- server/src/apub/group_wrapper.rs | 91 ------------------- server/src/apub/mod.rs | 17 ++-- server/src/apub/post.rs | 38 ++++---- server/src/apub/puller.rs | 45 +++++++--- server/src/apub/user.rs | 71 ++++++--------- server/src/lib.rs | 11 +-- 9 files changed, 249 insertions(+), 261 deletions(-) delete mode 100644 server/src/apub/group_wrapper.rs diff --git a/server/Cargo.lock b/server/Cargo.lock index 125319206..04b11cb11 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -1,21 +1,22 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "activitypub" -version = "0.2.0" +name = "activitystreams" +version = "0.4.0-alpha.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "activitystreams-derive 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "activitystreams-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "activitystreams-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "activitystreams-derive 0.4.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "thiserror 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", + "typetag 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "activitystreams-derive" -version = "0.2.0" +version = "0.4.0-alpha.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -23,30 +24,6 @@ dependencies = [ "syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "activitystreams-traits" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", - "thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "activitystreams-types" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "activitystreams-derive 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "activitystreams-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "actix" version = "0.9.0" @@ -320,7 +297,7 @@ dependencies = [ "serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -771,6 +748,15 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ctor" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "darling" version = "0.10.2" @@ -1009,6 +995,14 @@ dependencies = [ "termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "erased-serde" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "error-chain" version = "0.12.1" @@ -1220,6 +1214,16 @@ dependencies = [ "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ghost" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "h2" version = "0.1.26" @@ -1414,6 +1418,26 @@ dependencies = [ "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "inventory" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ctor 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "ghost 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "inventory-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "inventory-impl" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "iovec" version = "0.1.4" @@ -1492,7 +1516,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "lemmy_server" version = "0.0.1" dependencies = [ - "activitypub 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "activitystreams 0.4.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)", "actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "actix-files 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "actix-rt 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1521,6 +1545,7 @@ dependencies = [ "sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "strum 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "strum_macros 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1993,7 +2018,7 @@ dependencies = [ "idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2475,7 +2500,7 @@ dependencies = [ "dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2635,15 +2660,15 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "thiserror-impl 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "thiserror-impl 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "thiserror-impl" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2874,7 +2899,7 @@ dependencies = [ "smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2913,6 +2938,28 @@ name = "typenum" version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "typetag" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "erased-serde 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)", + "inventory 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "typetag-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "typetag-impl" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "unicase" version = "2.6.0" @@ -2964,7 +3011,7 @@ dependencies = [ [[package]] name = "url" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3212,10 +3259,8 @@ dependencies = [ ] [metadata] -"checksum activitypub 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d538a21b137ec0f63cc579ef4afa4ab13aa85b4f8af15a033683edd97c50718d" -"checksum activitystreams-derive 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "65608fdeae5eb05485d5b71a3d2242d76b2b7413608c196d47eb4dff3eed7b85" -"checksum activitystreams-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0c2a3958d240f40eff1f31b5f679a6e0d4ce2a16812886a3ec0164f3a2ca517" -"checksum activitystreams-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0598820663a59e5eaafeeedd3a7f7efc93db4ed6172905baec05503095ba5c0e" +"checksum activitystreams 0.4.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cb3bd10f03af2030e904226c7c1d86ba96e8993f93f7f73959ea78833c00a314" +"checksum activitystreams-derive 0.4.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbb2213ea81c06ac7d5ce5947be3c1c4623bea2ce2303884cb9acdd29c067cb4" "checksum actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a4af87564ff659dee8f9981540cac9418c45e910c8072fdedd643a262a38fcaf" "checksum actix-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "09e55f0a5c2ca15795035d90c46bd0e73a5123b72f68f12596d6ba5282051380" "checksum actix-connect 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2b61480a8d30c94d5c883d79ef026b02ad6809931b0a4bb703f9545cd8c986" @@ -3284,6 +3329,7 @@ dependencies = [ "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" "checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" "checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" +"checksum ctor 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "47c5e5ac752e18207b12e16b10631ae5f7f68f8805f335f9b817ead83d9ffce1" "checksum darling 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" "checksum darling_core 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" "checksum darling_macro 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" @@ -3310,6 +3356,7 @@ dependencies = [ "checksum encoding_rs 0.8.22 (registry+https://github.com/rust-lang/crates.io-index)" = "cd8d03faa7fe0c1431609dfad7bbe827af30f82e1e2ae6f7ee4fca6bd764bc28" "checksum enum-as-inner 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "900a6c7fbe523f4c2884eaf26b57b81bb69b6810a01a236390a7ac021d09492e" "checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +"checksum erased-serde 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)" = "cd7d80305c9bd8cd78e3c753eb9fb110f83621e5211f1a3afffcc812b104daf9" "checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9" "checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9" "checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08" @@ -3336,6 +3383,7 @@ dependencies = [ "checksum fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" +"checksum ghost 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2a36606a68532b5640dc86bb1f33c64b45c4682aad4c50f3937b317ea387f3d6" "checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" "checksum h2 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9433d71e471c1736fd5a61b671fc0b148d7a2992f666c958d03cd8feb3b88d1" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" @@ -3354,6 +3402,8 @@ dependencies = [ "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" "checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2" +"checksum inventory 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2bf98296081bd2cb540acc09ef9c97f22b7e487841520350293605db1b2c7a27" +"checksum inventory-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0a8e30575afe28eea36a9a39136b70b2fb6b0dd0a212a5bd1f30a498395c0274" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" "checksum ipconfig 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa79fa216fbe60834a9c0737d7fcd30425b32d1c58854663e24d4c4b328ed83f" "checksum itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae3088ea4baeceb0284ee9eea42f591226e6beaecf65373e41b38d95a1b8e7a1" @@ -3491,8 +3541,8 @@ dependencies = [ "checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" "checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e" -"checksum thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6f357d1814b33bc2dc221243f8424104bfe72dbe911d5b71b3816a2dff1c977e" -"checksum thiserror-impl 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2e25d25307eb8436894f727aba8f65d07adf02e5b35a13cebed48bd282bfef" +"checksum thiserror 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ee14bf8e6767ab4c687c9e8bc003879e042a96fd67a3ba5934eadb6536bef4db" +"checksum thiserror-impl 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "a7b51e1fbc44b5a0840be594fbc0f960be09050f2617e61e6aa43bef97cd3ef4" "checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" "checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5" "checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" @@ -3516,6 +3566,8 @@ dependencies = [ "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" "checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +"checksum typetag 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ebb2c484029d695fb68a06d80e1536c68d491b3e0cf874c66abed255e831cfe" +"checksum typetag-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b63fd4799e4d0ec5cf0b055ebb8e2c3a657bbf76a84f6edc77ca60780e000204" "checksum unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b561e267b2326bb4cebfc0ef9e68355c7abe6c6f522aeac2f5bf95d56c59bdcf" @@ -3523,7 +3575,7 @@ dependencies = [ "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum untrusted 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60369ef7a31de49bcb3f6ca728d4ba7300d9a1658f94c727d4cab8c8d9f4aece" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" -"checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61" +"checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" "checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" "checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a" "checksum v_escape 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "660b101c07b5d0863deb9e7fb3138777e858d6d2a79f9e6049a27d1cc77c6da6" diff --git a/server/Cargo.toml b/server/Cargo.toml index 828230572..a4f23de41 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -9,7 +9,7 @@ diesel = { version = "1.4.2", features = ["postgres","chrono", "r2d2"] } diesel_migrations = "1.4.0" dotenv = "0.15.0" bcrypt = "0.6.1" -activitypub = "0.2.0" +activitystreams = "0.4.0-alpha.3" chrono = { version = "0.4.7", features = ["serde"] } failure = "0.1.5" serde_json = { version = "1.0.45", features = ["preserve_order"]} @@ -33,4 +33,5 @@ rss = "1.9.0" htmlescape = "0.3.1" config = "0.10.1" hjson = "0.8.2" -reqwest = "0.9.24" \ No newline at end of file +reqwest = "0.9.24" +url = "2.1.1" \ No newline at end of file diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs index 877534b32..bbb9da6ec 100644 --- a/server/src/apub/community.rs +++ b/server/src/apub/community.rs @@ -1,54 +1,64 @@ -use crate::apub::group_wrapper::GroupHelper; use crate::apub::make_apub_endpoint; +use crate::convert_datetime; use crate::db::community::Community; use crate::db::community_view::CommunityFollowerView; use crate::db::establish_unpooled_connection; -use activitypub::{actor::Group, collection::UnorderedCollection, context}; +use activitystreams::{ + actor::apub::Group, collection::apub::UnorderedCollection, context, + object::properties::ObjectProperties, +}; use actix_web::body::Body; use actix_web::web::Path; use actix_web::HttpResponse; +use failure::Error; use serde::Deserialize; -use serde_json::{Value}; impl Community { - pub fn as_group(&self) -> Group { + pub fn as_group(&self) -> Result { let base_url = make_apub_endpoint("c", &self.id); let mut group = Group::default(); + let oprops: &mut ObjectProperties = group.as_mut(); - group.object_props.set_context_object(context()).ok(); - Group::set_id(&mut group, &base_url); + oprops + .set_context_xsd_any_uri(context())? + .set_id(base_url.to_owned())? + .set_name_xsd_string(self.title.to_owned())? + .set_published(convert_datetime(self.published))? + .set_attributed_to_xsd_any_uri(make_apub_endpoint("u", &self.creator_id))?; - Group::set_title(&mut group, &self.title); - Group::set_published(&mut group, self.published); - Group::set_updated(&mut group, self.updated); - Group::set_creator_id(&mut group, make_apub_endpoint("u", &self.creator_id)); - - Group::set_description(&mut group, &self.description); - - group.ap_actor_props.inbox = Value::String(format!("{}/inbox", &base_url)); - group.ap_actor_props.outbox = Value::String(format!("{}/outbox", &base_url)); - group.ap_actor_props.followers = Some(Value::String(format!("{}/followers", &base_url))); + if let Some(u) = self.updated.to_owned() { + oprops.set_updated(convert_datetime(u))?; + } + if let Some(d) = self.description.to_owned() { + oprops.set_summary_xsd_string(d)?; + } group + .ap_actor_props + .set_inbox(format!("{}/inbox", &base_url))? + .set_outbox(format!("{}/outbox", &base_url))? + .set_followers(format!("{}/followers", &base_url))?; + + Ok(group) } - pub fn followers_as_collection(&self) -> UnorderedCollection { + pub fn followers_as_collection(&self) -> Result { let base_url = make_apub_endpoint("c", &self.name); - let mut collection = UnorderedCollection::default(); - collection.object_props.set_context_object(context()).ok(); - collection.object_props.set_id_string(base_url).ok(); - let connection = establish_unpooled_connection(); //As we are an object, we validated that the community id was valid let community_followers = CommunityFollowerView::for_community(&connection, self.id).unwrap(); + let mut collection = UnorderedCollection::default(); + let oprops: &mut ObjectProperties = collection.as_mut(); + oprops + .set_context_xsd_any_uri(context())? + .set_id(base_url)?; collection .collection_props - .set_total_items_u64(community_followers.len() as u64) - .unwrap(); - collection + .set_total_items(community_followers.len() as u64)?; + Ok(collection) } } @@ -57,26 +67,32 @@ pub struct CommunityQuery { community_name: String, } -pub async fn get_apub_community(info: Path) -> HttpResponse { +pub async fn get_apub_community(info: Path) -> Result, Error> { let connection = establish_unpooled_connection(); if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) { - HttpResponse::Ok() - .content_type("application/activity+json") - .body(serde_json::to_string(&community.as_group()).unwrap()) + Ok( + HttpResponse::Ok() + .content_type("application/activity+json") + .body(serde_json::to_string(&community.as_group()?).unwrap()), + ) } else { - HttpResponse::NotFound().finish() + Ok(HttpResponse::NotFound().finish()) } } -pub async fn get_apub_community_followers(info: Path) -> HttpResponse { +pub async fn get_apub_community_followers( + info: Path, +) -> Result, Error> { let connection = establish_unpooled_connection(); if let Ok(community) = Community::read_from_name(&connection, info.community_name.to_owned()) { - HttpResponse::Ok() - .content_type("application/activity+json") - .body(serde_json::to_string(&community.followers_as_collection()).unwrap()) + Ok( + HttpResponse::Ok() + .content_type("application/activity+json") + .body(serde_json::to_string(&community.followers_as_collection()?).unwrap()), + ) } else { - HttpResponse::NotFound().finish() + Ok(HttpResponse::NotFound().finish()) } } diff --git a/server/src/apub/group_wrapper.rs b/server/src/apub/group_wrapper.rs deleted file mode 100644 index 98eb2cf3f..000000000 --- a/server/src/apub/group_wrapper.rs +++ /dev/null @@ -1,91 +0,0 @@ -use crate::to_datetime_utc; -use activitypub::actor::Group; -use chrono::{DateTime, NaiveDateTime}; -use failure::Error; -use serde_json::Value; - -pub trait GroupHelper { - fn set_id(group: &mut Group, id: &str); - fn get_id(group: &Group) -> Result; - - fn set_title(group: &mut Group, title: &str); - fn get_title(group: &Group) -> Result; - - fn set_description(group: &mut Group, description: &Option); - fn get_description(group: &Group) -> Result, Error>; - - fn set_creator_id(group: &mut Group, creator_id: String); - fn get_creator_id(group: &Group) -> Result; - - fn set_published(group: &mut Group, published: NaiveDateTime); - fn get_published(group: &Group) -> Result; - - fn set_updated(group: &mut Group, updated: Option); - fn get_updated(group: &Group) -> Result, Error>; -} - -// TODO: something is crashing and not reporting the error -impl GroupHelper for Group { - fn set_id(group: &mut Group, id: &str) { - group.object_props.id = Some(Value::String(id.to_string())); - } - fn get_id(group: &Group) -> Result { - Ok(get_string_value(group.clone().object_props.id)) - } - - fn set_title(group: &mut Group, title: &str) { - group.object_props.name = Some(Value::String(title.to_string())); - } - fn get_title(group: &Group) -> Result { - Ok(get_string_value(group.to_owned().object_props.name)) - } - - fn set_description(group: &mut Group, description: &Option) { - group.object_props.summary = description.as_ref().map(|d| Value::String(d.to_string())); - } - fn get_description(group: &Group) -> Result, Error> { - Ok(get_string_value_opt(group.to_owned().object_props.summary)) - } - - fn set_creator_id(group: &mut Group, creator_id: String) { - group.object_props.attributed_to = Some(Value::String(creator_id.to_string())); - } - fn get_creator_id(group: &Group) -> Result { - Ok(get_string_value(group.clone().object_props.attributed_to)) - } - - fn set_published(group: &mut Group, published: NaiveDateTime) { - group.object_props.published = Some(Value::String(to_datetime_utc(published).to_string())) - } - fn get_published(group: &Group) -> Result { - let str = get_string_value(group.to_owned().object_props.published); - // TODO: date parsing is failing, no idea if this is even the right format - dbg!(&str); - let date = DateTime::parse_from_rfc2822(&str)?; - dbg!(&date); - Ok(date.naive_local()) - } - - fn set_updated(group: &mut Group, updated: Option) { - group.object_props.updated = updated.map(|u| Value::String(u.to_string())); - } - fn get_updated(group: &Group) -> Result, Error> { - let str = get_string_value_opt(group.to_owned().object_props.updated); - match str { - Some(s) => Ok(Some(DateTime::parse_from_rfc2822(&s)?.naive_local())), - None => Ok(None), - } - } -} - -fn get_string_value_opt(value: Option) -> Option { - value - .as_ref() - .map(Value::as_str) - .flatten() - .map(str::to_string) -} - -fn get_string_value(value: Option) -> String { - get_string_value_opt(value).unwrap() -} diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index 00b3b27c5..8896a36c5 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -1,5 +1,4 @@ pub mod community; -pub mod group_wrapper; pub mod post; pub mod puller; pub mod user; @@ -7,6 +6,7 @@ use crate::Settings; use failure::Error; use std::fmt::Display; +use url::Url; #[cfg(test)] mod tests { @@ -43,7 +43,7 @@ mod tests { let person = user.as_person(); assert_eq!( format!("https://{}/federation/u/thom", Settings::get().hostname), - person.object_props.id_string().unwrap() + person.unwrap().object_props.get_id().unwrap().to_string() ); } @@ -66,7 +66,7 @@ mod tests { let group = community.as_group(); assert_eq!( format!("https://{}/federation/c/Test", Settings::get().hostname), - group.object_props.id_string().unwrap() + group.unwrap().object_props.get_id().unwrap().to_string() ); } @@ -91,27 +91,28 @@ mod tests { let page = post.as_page(); assert_eq!( format!("https://{}/federation/post/62", Settings::get().hostname), - page.object_props.id_string().unwrap() + page.unwrap().object_props.get_id().unwrap().to_string() ); } } // TODO: this should take an enum community/user/post for `point` // TODO: also not sure what exactly `value` should be (numeric id, name string, ...) -pub fn make_apub_endpoint(point: S, value: T) -> String { - format!( +pub fn make_apub_endpoint(point: S, value: T) -> Url { + Url::parse(&format!( "{}://{}/federation/{}/{}", get_apub_protocol_string(), Settings::get().hostname, point, value - ) + )) + .unwrap() } /// Parses an ID generated by `make_apub_endpoint()`. Will break when federating with anything /// that is not Lemmy. This is just a crutch until we change the database to store URLs as ID. pub fn parse_apub_endpoint(id: &str) -> Result<(&str, &str), Error> { - let split = id.split("/").collect::>(); + let split = id.split('/').collect::>(); Ok((split[4], split[5])) } diff --git a/server/src/apub/post.rs b/server/src/apub/post.rs index ebb171290..f0599eef2 100644 --- a/server/src/apub/post.rs +++ b/server/src/apub/post.rs @@ -1,38 +1,36 @@ use crate::apub::make_apub_endpoint; +use crate::convert_datetime; use crate::db::post::Post; -use crate::to_datetime_utc; -use activitypub::{context, object::Page}; +use activitystreams::{context, object::apub::Page, object::properties::ObjectProperties}; +use failure::Error; impl Post { - pub fn as_page(&self) -> Page { + pub fn as_page(&self) -> Result { let base_url = make_apub_endpoint("post", self.id); let mut page = Page::default(); + let oprops: &mut ObjectProperties = page.as_mut(); - page.object_props.set_context_object(context()).ok(); - page.object_props.set_id_string(base_url).ok(); - page.object_props.set_name_string(self.name.to_owned()).ok(); + oprops + .set_context_xsd_any_uri(context())? + .set_id(base_url)? + .set_name_xsd_string(self.name.to_owned())? + .set_published(convert_datetime(self.published))? + .set_attributed_to_xsd_any_uri(make_apub_endpoint("u", &self.creator_id))?; if let Some(body) = &self.body { - page.object_props.set_content_string(body.to_owned()).ok(); + oprops.set_content_xsd_string(body.to_owned())?; } if let Some(url) = &self.url { - page.object_props.set_url_string(url.to_owned()).ok(); + oprops.set_url_xsd_any_uri(url.to_owned())?; } - //page.object_props.set_attributed_to_string - - page - .object_props - .set_published_utctime(to_datetime_utc(self.published)) - .ok(); - if let Some(updated) = self.updated { - page - .object_props - .set_updated_utctime(to_datetime_utc(updated)) - .ok(); + if let Some(u) = self.updated { + oprops.set_updated(convert_datetime(u))?; } - page + Ok(page) } } + +// TODO: need to serve this via actix diff --git a/server/src/apub/puller.rs b/server/src/apub/puller.rs index 526476951..1465415b6 100644 --- a/server/src/apub/puller.rs +++ b/server/src/apub/puller.rs @@ -1,13 +1,12 @@ extern crate reqwest; -use self::reqwest::Error; use crate::api::community::{GetCommunityResponse, ListCommunitiesResponse}; use crate::api::post::GetPosts; -use crate::apub::group_wrapper::GroupHelper; +use crate::apub::parse_apub_endpoint; use crate::db::community_view::CommunityView; use crate::settings::Settings; -use activitypub::actor::Group; -use crate::apub::parse_apub_endpoint; +use activitystreams::actor::apub::Group; +use failure::Error; // TODO: right now all of the data is requested on demand, for production we will need to store // things in the local database to not ruin the performance @@ -47,15 +46,41 @@ pub fn get_remote_community(identifier: String) -> Result()?, + id: parse_apub_endpoint(&community.object_props.get_id().unwrap().to_string())? + .1 + .parse::()?, name, - title: Group::get_title(&community)?, - description: Group::get_description(&community)?, + title: community + .object_props + .get_name_xsd_string() + .unwrap() + .to_string(), + description: community + .object_props + .get_summary_xsd_string() + .map(|s| s.to_string()), category_id: -1, - creator_id: parse_apub_endpoint(&Group::get_creator_id(&community)?)?.1.parse::()?, + creator_id: parse_apub_endpoint( + &community + .object_props + .get_attributed_to_xsd_any_uri() + .unwrap() + .to_string(), + )? + .1 + .parse::()?, removed: false, - published: Group::get_published(&community)?, - updated: Group::get_updated(&community)?, + published: community + .object_props + .get_published() + .unwrap() + .as_ref() + .naive_local() + .to_owned(), + updated: community + .object_props + .get_updated() + .map(|u| u.as_ref().to_owned().naive_local()), deleted: false, nsfw: false, creator_name: "".to_string(), diff --git a/server/src/apub/user.rs b/server/src/apub/user.rs index 5f2421f11..c1ffcedd4 100644 --- a/server/src/apub/user.rs +++ b/server/src/apub/user.rs @@ -1,58 +1,41 @@ use crate::apub::make_apub_endpoint; +use crate::convert_datetime; use crate::db::establish_unpooled_connection; use crate::db::user::User_; -use crate::to_datetime_utc; -use activitypub::{actor::Person, context}; +use activitystreams::{actor::apub::Person, context, object::properties::ObjectProperties}; use actix_web::body::Body; use actix_web::web::Path; use actix_web::HttpResponse; +use failure::Error; use serde::Deserialize; impl User_ { - pub fn as_person(&self) -> Person { + pub fn as_person(&self) -> Result { let base_url = make_apub_endpoint("u", &self.name); + let mut person = Person::default(); - person.object_props.set_context_object(context()).ok(); - person.object_props.set_id_string(base_url.to_string()).ok(); - person - .object_props - .set_name_string(self.name.to_owned()) - .ok(); - person - .object_props - .set_published_utctime(to_datetime_utc(self.published)) - .ok(); - if let Some(updated) = self.updated { - person - .object_props - .set_updated_utctime(to_datetime_utc(updated)) - .ok(); + let oprops: &mut ObjectProperties = person.as_mut(); + oprops + .set_context_xsd_any_uri(context())? + .set_id(base_url.to_string())? + .set_published(convert_datetime(self.published))?; + + if let Some(u) = self.updated { + oprops.set_updated(convert_datetime(u))?; } - person - .ap_actor_props - .set_inbox_string(format!("{}/inbox", &base_url)) - .ok(); - person - .ap_actor_props - .set_outbox_string(format!("{}/outbox", &base_url)) - .ok(); - person - .ap_actor_props - .set_following_string(format!("{}/following", &base_url)) - .ok(); - person - .ap_actor_props - .set_liked_string(format!("{}/liked", &base_url)) - .ok(); if let Some(i) = &self.preferred_username { - person - .ap_actor_props - .set_preferred_username_string(i.to_string()) - .ok(); + oprops.set_name_xsd_string(i.to_owned())?; } person + .ap_actor_props + .set_inbox(format!("{}/inbox", &base_url))? + .set_outbox(format!("{}/outbox", &base_url))? + .set_following(format!("{}/following", &base_url))? + .set_liked(format!("{}/liked", &base_url))?; + + Ok(person) } } @@ -61,14 +44,16 @@ pub struct UserQuery { user_name: String, } -pub async fn get_apub_user(info: Path) -> HttpResponse { +pub async fn get_apub_user(info: Path) -> Result, Error> { let connection = establish_unpooled_connection(); if let Ok(user) = User_::find_by_email_or_username(&connection, &info.user_name) { - HttpResponse::Ok() - .content_type("application/activity+json") - .body(serde_json::to_string(&user.as_person()).unwrap()) + Ok( + HttpResponse::Ok() + .content_type("application/activity+json") + .body(serde_json::to_string(&user.as_person()?).unwrap()), + ) } else { - HttpResponse::NotFound().finish() + Ok(HttpResponse::NotFound().finish()) } } diff --git a/server/src/lib.rs b/server/src/lib.rs index 3e22585de..254e8dd58 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -32,7 +32,7 @@ pub mod version; pub mod websocket; use crate::settings::Settings; -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{DateTime, FixedOffset, Local, NaiveDateTime}; use lettre::smtp::authentication::{Credentials, Mechanism}; use lettre::smtp::extension::ClientId; use lettre::smtp::ConnectionReuseParameters; @@ -42,10 +42,6 @@ use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; use regex::{Regex, RegexBuilder}; -pub fn to_datetime_utc(ndt: NaiveDateTime) -> DateTime { - DateTime::::from_utc(ndt, Utc) -} - pub fn naive_now() -> NaiveDateTime { chrono::prelude::Utc::now().naive_utc() } @@ -54,6 +50,11 @@ pub fn naive_from_unix(time: i64) -> NaiveDateTime { NaiveDateTime::from_timestamp(time, 0) } +pub fn convert_datetime(datetime: NaiveDateTime) -> DateTime { + let now = Local::now(); + DateTime::::from_utc(datetime, *now.offset()) +} + pub fn is_email_regex(test: &str) -> bool { EMAIL_REGEX.is_match(test) }