mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-03-29 14:45:27 +00:00
Merge branch 'combined_profile' into combined_modlog
This commit is contained in:
commit
b6d0ecfcb3
67 changed files with 1216 additions and 876 deletions
|
@ -6,7 +6,7 @@ variables:
|
||||||
# as well. Otherwise release builds can fail if Lemmy or dependencies rely on new Rust
|
# as well. Otherwise release builds can fail if Lemmy or dependencies rely on new Rust
|
||||||
# features. In particular the ARM builder image needs to be updated manually in the repo below:
|
# features. In particular the ARM builder image needs to be updated manually in the repo below:
|
||||||
# https://github.com/raskyld/lemmy-cross-toolchains
|
# https://github.com/raskyld/lemmy-cross-toolchains
|
||||||
- &rust_image "rust:1.81"
|
- &rust_image "rust:1.83"
|
||||||
- &rust_nightly_image "rustlang/rust:nightly"
|
- &rust_nightly_image "rustlang/rust:nightly"
|
||||||
- &install_pnpm "corepack enable pnpm"
|
- &install_pnpm "corepack enable pnpm"
|
||||||
- &install_binstall "wget -O- https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz | tar -xvz -C /usr/local/cargo/bin"
|
- &install_binstall "wget -O- https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz | tar -xvz -C /usr/local/cargo/bin"
|
||||||
|
|
96
Cargo.lock
generated
96
Cargo.lock
generated
|
@ -435,9 +435,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.93"
|
version = "1.0.95"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
|
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
]
|
]
|
||||||
|
@ -460,9 +460,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-compression"
|
name = "async-compression"
|
||||||
version = "0.4.12"
|
version = "0.4.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fec134f64e2bc57411226dfc4e52dec859ddfc7e711fc5e07b612584f000e4aa"
|
checksum = "df895a515f70646414f4b45c0b79082783b80552b373a68283012928df56f522"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flate2",
|
"flate2",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
@ -495,15 +495,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atom_syndication"
|
name = "atom_syndication"
|
||||||
version = "0.12.4"
|
version = "0.12.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2a3a5ed3201df5658d1aa45060c5a57dc9dba8a8ada20d696d67cb0c479ee043"
|
checksum = "3ee79fb83c725eae67b55218870813d2fc39fd85e4f1583848ef9f4f823cfe7c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"derive_builder",
|
"derive_builder",
|
||||||
"diligent-date-parser",
|
"diligent-date-parser",
|
||||||
"never",
|
"never",
|
||||||
"quick-xml 0.36.1",
|
"quick-xml 0.37.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -514,21 +514,20 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aws-lc-rs"
|
name = "aws-lc-rs"
|
||||||
version = "1.9.0"
|
version = "1.11.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2f95446d919226d587817a7d21379e6eb099b97b45110a7f272a444ca5c54070"
|
checksum = "f47bb8cc16b669d267eeccf585aea077d0882f4777b1c1f740217885d6e6e5a3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aws-lc-sys",
|
"aws-lc-sys",
|
||||||
"mirai-annotations",
|
|
||||||
"paste",
|
"paste",
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aws-lc-sys"
|
name = "aws-lc-sys"
|
||||||
version = "0.21.1"
|
version = "0.23.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "234314bd569802ec87011d653d6815c6d7b9ffb969e9fee5b8b20ef860e8dce9"
|
checksum = "a2101df3813227bbaaaa0b04cd61c534c7954b22bd68d399b440be937dc63ff7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
"cc",
|
"cc",
|
||||||
|
@ -618,9 +617,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bindgen"
|
name = "bindgen"
|
||||||
version = "0.69.4"
|
version = "0.69.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0"
|
checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.6.0",
|
||||||
"cexpr",
|
"cexpr",
|
||||||
|
@ -798,9 +797,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.38"
|
version = "0.4.39"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
|
checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android-tzdata",
|
"android-tzdata",
|
||||||
"iana-time-zone",
|
"iana-time-zone",
|
||||||
|
@ -844,9 +843,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.21"
|
version = "4.5.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f"
|
checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
"clap_derive",
|
"clap_derive",
|
||||||
|
@ -854,9 +853,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_builder"
|
name = "clap_builder"
|
||||||
version = "4.5.21"
|
version = "4.5.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec"
|
checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
|
@ -878,9 +877,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_lex"
|
name = "clap_lex"
|
||||||
version = "0.7.2"
|
version = "0.7.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
|
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clearurls"
|
name = "clearurls"
|
||||||
|
@ -907,9 +906,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cmake"
|
name = "cmake"
|
||||||
version = "0.1.51"
|
version = "0.1.52"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fb1e43aa7fd152b1f968787f7dbcdeb306d1867ff373c69955211876c053f91a"
|
checksum = "c682c223677e0e5b6b7f63a64b9351844c3f1b1678a68b7ee617e30fb082620e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
@ -1374,9 +1373,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "diligent-date-parser"
|
name = "diligent-date-parser"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f6cf7fe294274a222363f84bcb63cdea762979a0443b4cf1f4f8fd17c86b1182"
|
checksum = "c8ede7d79366f419921e2e2f67889c12125726692a313bffb474bd5f37a581e9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
]
|
]
|
||||||
|
@ -1471,9 +1470,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "email-encoding"
|
name = "email-encoding"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "60d1d33cdaede7e24091f039632eb5d3c7469fe5b066a985281a34fc70fa317f"
|
checksum = "ea3d894bbbab314476b265f9b2d46bf24b123a36dd0e96b06a1b49545b9d9dcc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
@ -1599,9 +1598,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "2.1.1"
|
version = "2.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6"
|
checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fdeflate"
|
name = "fdeflate"
|
||||||
|
@ -2686,8 +2685,10 @@ dependencies = [
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"serde_with",
|
"serde_with",
|
||||||
"serial_test",
|
"serial_test",
|
||||||
|
"test-context",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"ts-rs",
|
"ts-rs",
|
||||||
|
@ -2810,7 +2811,6 @@ dependencies = [
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"prometheus",
|
"prometheus",
|
||||||
"reqwest 0.12.8",
|
|
||||||
"reqwest-middleware",
|
"reqwest-middleware",
|
||||||
"reqwest-tracing",
|
"reqwest-tracing",
|
||||||
"rustls 0.23.16",
|
"rustls 0.23.16",
|
||||||
|
@ -2901,12 +2901,12 @@ checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libloading"
|
name = "libloading"
|
||||||
version = "0.8.5"
|
version = "0.8.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
|
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"windows-targets 0.52.6",
|
"windows-targets 0.48.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3223,12 +3223,6 @@ dependencies = [
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "mirai-annotations"
|
|
||||||
version = "1.12.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c9be0862c1b3f26a88803c4a49de6889c10e608b3ee9344e6ef5b45fb37ad3d1"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mockall"
|
name = "mockall"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
|
@ -3602,9 +3596,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.3.30"
|
version = "0.3.31"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
|
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "plist"
|
name = "plist"
|
||||||
|
@ -3729,9 +3723,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "prettyplease"
|
name = "prettyplease"
|
||||||
version = "0.2.22"
|
version = "0.2.25"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba"
|
checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"syn 2.0.87",
|
"syn 2.0.87",
|
||||||
|
@ -3825,16 +3819,6 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quick-xml"
|
|
||||||
version = "0.36.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "96a05e2e8efddfa51a84ca47cec303fac86c8541b686d37cac5efc0e094417bc"
|
|
||||||
dependencies = [
|
|
||||||
"encoding_rs",
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quick-xml"
|
name = "quick-xml"
|
||||||
version = "0.37.1"
|
version = "0.37.1"
|
||||||
|
@ -4328,9 +4312,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.17"
|
version = "1.0.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
|
checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
|
|
14
Cargo.toml
14
Cargo.toml
|
@ -103,21 +103,21 @@ diesel-async = "0.5.1"
|
||||||
serde = { version = "1.0.215", features = ["derive"] }
|
serde = { version = "1.0.215", features = ["derive"] }
|
||||||
serde_with = "3.9.0"
|
serde_with = "3.9.0"
|
||||||
actix-web = { version = "4.9.0", default-features = false, features = [
|
actix-web = { version = "4.9.0", default-features = false, features = [
|
||||||
"macros",
|
|
||||||
"rustls-0_23",
|
|
||||||
"compress-brotli",
|
"compress-brotli",
|
||||||
"compress-gzip",
|
"compress-gzip",
|
||||||
"compress-zstd",
|
"compress-zstd",
|
||||||
"cookies",
|
"cookies",
|
||||||
|
"macros",
|
||||||
|
"rustls-0_23",
|
||||||
] }
|
] }
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-actix-web = { version = "0.7.10", default-features = false }
|
tracing-actix-web = { version = "0.7.10", default-features = false }
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||||
url = { version = "2.5.3", features = ["serde"] }
|
url = { version = "2.5.3", features = ["serde"] }
|
||||||
reqwest = { version = "0.12.7", default-features = false, features = [
|
reqwest = { version = "0.12.7", default-features = false, features = [
|
||||||
"json",
|
|
||||||
"blocking",
|
"blocking",
|
||||||
"gzip",
|
"gzip",
|
||||||
|
"json",
|
||||||
"rustls-tls",
|
"rustls-tls",
|
||||||
] }
|
] }
|
||||||
reqwest-middleware = "0.3.3"
|
reqwest-middleware = "0.3.3"
|
||||||
|
@ -126,17 +126,15 @@ clokwerk = "0.4.0"
|
||||||
doku = { version = "0.21.1", features = ["url-2"] }
|
doku = { version = "0.21.1", features = ["url-2"] }
|
||||||
bcrypt = "0.15.1"
|
bcrypt = "0.15.1"
|
||||||
chrono = { version = "0.4.38", features = [
|
chrono = { version = "0.4.38", features = [
|
||||||
"serde",
|
|
||||||
"now",
|
"now",
|
||||||
|
"serde",
|
||||||
], default-features = false }
|
], default-features = false }
|
||||||
serde_json = { version = "1.0.132", features = ["preserve_order"] }
|
serde_json = { version = "1.0.132", features = ["preserve_order"] }
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
uuid = { version = "1.11.0", features = ["serde"] }
|
uuid = { version = "1.11.0", features = ["serde"] }
|
||||||
async-trait = "0.1.83"
|
async-trait = "0.1.83"
|
||||||
captcha = "0.0.9"
|
captcha = "0.0.9"
|
||||||
anyhow = { version = "1.0.93", features = [
|
anyhow = { version = "1.0.93", features = ["backtrace"] }
|
||||||
"backtrace",
|
|
||||||
] } # backtrace is on by default on nightly, but not stable rust
|
|
||||||
diesel_ltree = "0.3.1"
|
diesel_ltree = "0.3.1"
|
||||||
serial_test = "3.2.0"
|
serial_test = "3.2.0"
|
||||||
tokio = { version = "1.41.1", features = ["full"] }
|
tokio = { version = "1.41.1", features = ["full"] }
|
||||||
|
@ -149,7 +147,6 @@ futures = "0.3.31"
|
||||||
http = "1.1"
|
http = "1.1"
|
||||||
rosetta-i18n = "0.1.3"
|
rosetta-i18n = "0.1.3"
|
||||||
ts-rs = { version = "10.0.0", features = [
|
ts-rs = { version = "10.0.0", features = [
|
||||||
"serde-compat",
|
|
||||||
"chrono-impl",
|
"chrono-impl",
|
||||||
"no-serde-warnings",
|
"no-serde-warnings",
|
||||||
"url-impl",
|
"url-impl",
|
||||||
|
@ -185,7 +182,6 @@ tracing = { workspace = true }
|
||||||
tracing-actix-web = { workspace = true }
|
tracing-actix-web = { workspace = true }
|
||||||
tracing-subscriber = { workspace = true }
|
tracing-subscriber = { workspace = true }
|
||||||
url = { workspace = true }
|
url = { workspace = true }
|
||||||
reqwest = { workspace = true }
|
|
||||||
reqwest-middleware = { workspace = true }
|
reqwest-middleware = { workspace = true }
|
||||||
reqwest-tracing = { workspace = true }
|
reqwest-tracing = { workspace = true }
|
||||||
clokwerk = { workspace = true }
|
clokwerk = { workspace = true }
|
||||||
|
|
|
@ -15,7 +15,9 @@ export LEMMY_TEST_FAST_FEDERATION=1 # by default, the persistent federation queu
|
||||||
|
|
||||||
# pictrs setup
|
# pictrs setup
|
||||||
if [ ! -f "api_tests/pict-rs" ]; then
|
if [ ! -f "api_tests/pict-rs" ]; then
|
||||||
curl "https://git.asonix.dog/asonix/pict-rs/releases/download/v0.5.16/pict-rs-linux-amd64" -o api_tests/pict-rs
|
# This one sometimes goes down
|
||||||
|
# curl "https://git.asonix.dog/asonix/pict-rs/releases/download/v0.5.16/pict-rs-linux-amd64" -o api_tests/pict-rs
|
||||||
|
curl "https://codeberg.org/asonix/pict-rs/releases/download/v0.5.6/pict-rs-linux-amd64" -o api_tests/pict-rs
|
||||||
chmod +x api_tests/pict-rs
|
chmod +x api_tests/pict-rs
|
||||||
fi
|
fi
|
||||||
./api_tests/pict-rs \
|
./api_tests/pict-rs \
|
||||||
|
|
|
@ -698,7 +698,7 @@ test("Report a post", async () => {
|
||||||
() =>
|
() =>
|
||||||
listReports(beta).then(p =>
|
listReports(beta).then(p =>
|
||||||
p.reports.find(r => {
|
p.reports.find(r => {
|
||||||
return checkReportName(r, gammaReport);
|
return checkPostReportName(r, gammaReport);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
res => !!res,
|
res => !!res,
|
||||||
|
@ -718,15 +718,7 @@ test("Report a post", async () => {
|
||||||
() =>
|
() =>
|
||||||
listReports(alpha).then(p =>
|
listReports(alpha).then(p =>
|
||||||
p.reports.find(r => {
|
p.reports.find(r => {
|
||||||
switch (r.type_) {
|
return checkPostReportName(r, gammaReport);
|
||||||
case "Post":
|
|
||||||
return (
|
|
||||||
r.post_report.original_post_name ===
|
|
||||||
gammaReport.original_post_name
|
|
||||||
);
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
res => !!res,
|
res => !!res,
|
||||||
|
@ -833,7 +825,7 @@ test("Rewrite markdown links", async () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
function checkReportName(rcv: ReportCombinedView, report: PostReport) {
|
function checkPostReportName(rcv: ReportCombinedView, report: PostReport) {
|
||||||
switch (rcv.type_) {
|
switch (rcv.type_) {
|
||||||
case "Post":
|
case "Post":
|
||||||
return rcv.post_report.original_post_name === report.original_post_name;
|
return rcv.post_report.original_post_name === report.original_post_name;
|
||||||
|
|
|
@ -6,23 +6,31 @@ use lemmy_api_common::{
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{LocalUserView, SiteView};
|
use lemmy_db_views::structs::{LocalUserView, SiteView};
|
||||||
use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn reset_password(
|
pub async fn reset_password(
|
||||||
data: Json<PasswordReset>,
|
data: Json<PasswordReset>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> LemmyResult<Json<SuccessResponse>> {
|
) -> LemmyResult<Json<SuccessResponse>> {
|
||||||
// Fetch that email
|
|
||||||
let email = data.email.to_lowercase();
|
let email = data.email.to_lowercase();
|
||||||
let local_user_view = LocalUserView::find_by_email(&mut context.pool(), &email)
|
// For security, errors are not returned.
|
||||||
.await
|
// https://github.com/LemmyNet/lemmy/issues/5277
|
||||||
.with_lemmy_type(LemmyErrorType::IncorrectLogin)?;
|
let _ = try_reset_password(&email, &context).await;
|
||||||
|
|
||||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
|
||||||
check_email_verified(&local_user_view, &site_view)?;
|
|
||||||
|
|
||||||
// Email the pure token to the user.
|
|
||||||
send_password_reset_email(&local_user_view, &mut context.pool(), context.settings()).await?;
|
|
||||||
Ok(Json(SuccessResponse::default()))
|
Ok(Json(SuccessResponse::default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn try_reset_password(email: &str, context: &LemmyContext) -> LemmyResult<()> {
|
||||||
|
let local_user_view = LocalUserView::find_by_email(&mut context.pool(), email).await?;
|
||||||
|
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||||
|
|
||||||
|
check_email_verified(&local_user_view, &site_view)?;
|
||||||
|
if let Err(e) =
|
||||||
|
send_password_reset_email(&local_user_view, &mut context.pool(), context.settings()).await
|
||||||
|
{
|
||||||
|
error!("Failed to send password reset email: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
@ -67,9 +67,9 @@ urlencoding = { workspace = true }
|
||||||
mime = { version = "0.3.17", optional = true }
|
mime = { version = "0.3.17", optional = true }
|
||||||
mime_guess = "2.0.5"
|
mime_guess = "2.0.5"
|
||||||
infer = "0.16.0"
|
infer = "0.16.0"
|
||||||
webpage = { version = "2.0", default-features = false, features = [
|
webpage = { version = "2.0", default-features = false, optional = true, features = [
|
||||||
"serde",
|
"serde",
|
||||||
], optional = true }
|
] }
|
||||||
encoding_rs = { version = "0.8.35", optional = true }
|
encoding_rs = { version = "0.8.35", optional = true }
|
||||||
jsonwebtoken = { version = "9.3.0", optional = true }
|
jsonwebtoken = { version = "9.3.0", optional = true }
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId},
|
newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId, TagId},
|
||||||
ListingType,
|
ListingType,
|
||||||
PostFeatureType,
|
PostFeatureType,
|
||||||
PostSortType,
|
PostSortType,
|
||||||
|
@ -37,6 +37,8 @@ pub struct CreatePost {
|
||||||
/// Instead of fetching a thumbnail, use a custom one.
|
/// Instead of fetching a thumbnail, use a custom one.
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub custom_thumbnail: Option<String>,
|
pub custom_thumbnail: Option<String>,
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub tags: Option<Vec<TagId>>,
|
||||||
/// Time when this post should be scheduled. Null means publish immediately.
|
/// Time when this post should be scheduled. Null means publish immediately.
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub scheduled_publish_time: Option<i64>,
|
pub scheduled_publish_time: Option<i64>,
|
||||||
|
@ -164,6 +166,8 @@ pub struct EditPost {
|
||||||
/// Instead of fetching a thumbnail, use a custom one.
|
/// Instead of fetching a thumbnail, use a custom one.
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub custom_thumbnail: Option<String>,
|
pub custom_thumbnail: Option<String>,
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub tags: Option<Vec<TagId>>,
|
||||||
/// Time when this post should be scheduled. Null means publish immediately.
|
/// Time when this post should be scheduled. Null means publish immediately.
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub scheduled_publish_time: Option<i64>,
|
pub scheduled_publish_time: Option<i64>,
|
||||||
|
|
|
@ -51,9 +51,11 @@ pub fn client_builder(settings: &Settings) -> ClientBuilder {
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn fetch_link_metadata(url: &Url, context: &LemmyContext) -> LemmyResult<LinkMetadata> {
|
pub async fn fetch_link_metadata(url: &Url, context: &LemmyContext) -> LemmyResult<LinkMetadata> {
|
||||||
info!("Fetching site metadata for url: {}", url);
|
info!("Fetching site metadata for url: {}", url);
|
||||||
// We only fetch the first 64kB of data in order to not waste bandwidth especially for large
|
// We only fetch the first MB of data in order to not waste bandwidth especially for large
|
||||||
// binary files
|
// binary files. This high limit is particularly needed for youtube, which includes a lot of
|
||||||
let bytes_to_fetch = 64 * 1024;
|
// javascript code before the opengraph tags. Mastodon also uses a 1 MB limit:
|
||||||
|
// https://github.com/mastodon/mastodon/blob/295ad6f19a016b3f16e1201ffcbb1b3ad6b455a2/app/lib/request.rb#L213
|
||||||
|
let bytes_to_fetch = 1024 * 1024;
|
||||||
let response = context
|
let response = context
|
||||||
.client()
|
.client()
|
||||||
.get(url.as_str())
|
.get(url.as_str())
|
||||||
|
|
|
@ -552,7 +552,9 @@ pub async fn get_url_blocklist(context: &LemmyContext) -> LemmyResult<RegexSet>
|
||||||
let urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?;
|
let urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?;
|
||||||
|
|
||||||
// The urls are already validated on saving, so just escape them.
|
// The urls are already validated on saving, so just escape them.
|
||||||
let regexes = urls.iter().map(|url| escape(&url.url));
|
// If this regex creation changes it must be synced with
|
||||||
|
// lemmy_utils::utils::markdown::create_url_blocklist_test_regex_set.
|
||||||
|
let regexes = urls.iter().map(|url| format!(r"\b{}\b", escape(&url.url)));
|
||||||
|
|
||||||
let set = RegexSet::new(regexes)?;
|
let set = RegexSet::new(regexes)?;
|
||||||
Ok(set)
|
Ok(set)
|
||||||
|
|
|
@ -107,7 +107,7 @@ pub async fn create_post(
|
||||||
let scheduled_publish_time =
|
let scheduled_publish_time =
|
||||||
convert_published_time(data.scheduled_publish_time, &local_user_view, &context).await?;
|
convert_published_time(data.scheduled_publish_time, &local_user_view, &context).await?;
|
||||||
let post_form = PostInsertForm {
|
let post_form = PostInsertForm {
|
||||||
url: url.map(Into::into),
|
url,
|
||||||
body,
|
body,
|
||||||
alt_text: data.alt_text.clone(),
|
alt_text: data.alt_text.clone(),
|
||||||
nsfw: data.nsfw,
|
nsfw: data.nsfw,
|
||||||
|
|
|
@ -151,6 +151,8 @@ pub async fn update_site(
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
if let Some(url_blocklist) = data.blocked_urls.clone() {
|
if let Some(url_blocklist) = data.blocked_urls.clone() {
|
||||||
|
// If this validation changes it must be synced with
|
||||||
|
// lemmy_utils::utils::markdown::create_url_blocklist_test_regex_set.
|
||||||
let parsed_urls = check_urls_are_valid(&url_blocklist)?;
|
let parsed_urls = check_urls_are_valid(&url_blocklist)?;
|
||||||
LocalSiteUrlBlocklist::replace(&mut context.pool(), parsed_urls).await?;
|
LocalSiteUrlBlocklist::replace(&mut context.pool(), parsed_urls).await?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ impl ActivityHandler for BlockUser {
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
|
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
|
||||||
insert_received_activity(&self.id, context).await?;
|
insert_received_activity(&self.id, context).await?;
|
||||||
let expires = self.end_time.map(Into::into);
|
let expires = self.end_time;
|
||||||
let mod_person = self.actor.dereference(context).await?;
|
let mod_person = self.actor.dereference(context).await?;
|
||||||
let blocked_person = self.object.dereference(context).await?;
|
let blocked_person = self.object.dereference(context).await?;
|
||||||
let target = self.target.dereference(context).await?;
|
let target = self.target.dereference(context).await?;
|
||||||
|
|
|
@ -100,7 +100,7 @@ impl ActivityHandler for UndoBlockUser {
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
|
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
|
||||||
insert_received_activity(&self.id, context).await?;
|
insert_received_activity(&self.id, context).await?;
|
||||||
let expires = self.object.end_time.map(Into::into);
|
let expires = self.object.end_time;
|
||||||
let mod_person = self.actor.dereference(context).await?;
|
let mod_person = self.actor.dereference(context).await?;
|
||||||
let blocked_person = self.object.object.dereference(context).await?;
|
let blocked_person = self.object.object.dereference(context).await?;
|
||||||
match self.object.target.dereference(context).await? {
|
match self.object.target.dereference(context).await? {
|
||||||
|
|
|
@ -98,8 +98,8 @@ impl ActivityHandler for UpdateCommunity {
|
||||||
&None,
|
&None,
|
||||||
&self.object.source,
|
&self.object.source,
|
||||||
)),
|
)),
|
||||||
published: self.object.published.map(Into::into),
|
published: self.object.published,
|
||||||
updated: Some(self.object.updated.map(Into::into)),
|
updated: Some(self.object.updated),
|
||||||
nsfw: Some(self.object.sensitive.unwrap_or(false)),
|
nsfw: Some(self.object.sensitive.unwrap_or(false)),
|
||||||
actor_id: Some(self.object.id.into()),
|
actor_id: Some(self.object.id.into()),
|
||||||
public_key: Some(self.object.public_key.public_key_pem),
|
public_key: Some(self.object.public_key.public_key_pem),
|
||||||
|
|
|
@ -35,7 +35,6 @@ pub async fn read_person(
|
||||||
.map(|l| is_admin(l).is_ok())
|
.map(|l| is_admin(l).is_ok())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let person_view = PersonView::read(&mut context.pool(), person_details_id, is_admin).await?;
|
let person_view = PersonView::read(&mut context.pool(), person_details_id, is_admin).await?;
|
||||||
|
|
||||||
let moderates = CommunityModeratorView::for_person(
|
let moderates = CommunityModeratorView::for_person(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
person_details_id,
|
person_details_id,
|
||||||
|
|
|
@ -42,7 +42,8 @@ pub async fn markdown_rewrite_remote_links(
|
||||||
let mut local_url = local_url.to_string();
|
let mut local_url = local_url.to_string();
|
||||||
// restore title
|
// restore title
|
||||||
if let Some(extra) = extra {
|
if let Some(extra) = extra {
|
||||||
local_url = format!("{local_url} {extra}");
|
local_url.push(' ');
|
||||||
|
local_url.push_str(extra);
|
||||||
}
|
}
|
||||||
src.replace_range(start..end, local_url.as_str());
|
src.replace_range(start..end, local_url.as_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,8 +194,8 @@ impl Object for ApubComment {
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
content,
|
content,
|
||||||
removed: None,
|
removed: None,
|
||||||
published: note.published.map(Into::into),
|
published: note.published,
|
||||||
updated: note.updated.map(Into::into),
|
updated: note.updated,
|
||||||
deleted: Some(false),
|
deleted: Some(false),
|
||||||
ap_id: Some(note.id.into()),
|
ap_id: Some(note.id.into()),
|
||||||
distinguished: note.distinguished,
|
distinguished: note.distinguished,
|
||||||
|
|
|
@ -167,8 +167,8 @@ impl Object for ApubPerson {
|
||||||
deleted: Some(false),
|
deleted: Some(false),
|
||||||
avatar,
|
avatar,
|
||||||
banner,
|
banner,
|
||||||
published: person.published.map(Into::into),
|
published: person.published,
|
||||||
updated: person.updated.map(Into::into),
|
updated: person.updated,
|
||||||
actor_id: Some(person.id.into()),
|
actor_id: Some(person.id.into()),
|
||||||
bio,
|
bio,
|
||||||
local: Some(false),
|
local: Some(false),
|
||||||
|
|
|
@ -249,8 +249,8 @@ impl Object for ApubPost {
|
||||||
url: url.map(Into::into),
|
url: url.map(Into::into),
|
||||||
body,
|
body,
|
||||||
alt_text,
|
alt_text,
|
||||||
published: page.published.map(Into::into),
|
published: page.published,
|
||||||
updated: page.updated.map(Into::into),
|
updated: page.updated,
|
||||||
deleted: Some(false),
|
deleted: Some(false),
|
||||||
nsfw: page.sensitive,
|
nsfw: page.sensitive,
|
||||||
ap_id: Some(page.id.clone().into()),
|
ap_id: Some(page.id.clone().into()),
|
||||||
|
|
|
@ -166,8 +166,8 @@ impl Object for ApubPrivateMessage {
|
||||||
creator_id: creator.id,
|
creator_id: creator.id,
|
||||||
recipient_id: recipient.id,
|
recipient_id: recipient.id,
|
||||||
content,
|
content,
|
||||||
published: note.published.map(Into::into),
|
published: note.published,
|
||||||
updated: note.updated.map(Into::into),
|
updated: note.updated,
|
||||||
deleted: Some(false),
|
deleted: Some(false),
|
||||||
read: None,
|
read: None,
|
||||||
ap_id: Some(note.id.into()),
|
ap_id: Some(note.id.into()),
|
||||||
|
|
|
@ -52,8 +52,8 @@ activitypub_federation = { workspace = true, optional = true }
|
||||||
lemmy_utils = { workspace = true, optional = true }
|
lemmy_utils = { workspace = true, optional = true }
|
||||||
bcrypt = { workspace = true, optional = true }
|
bcrypt = { workspace = true, optional = true }
|
||||||
diesel = { workspace = true, features = [
|
diesel = { workspace = true, features = [
|
||||||
"postgres",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"postgres",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"uuid",
|
"uuid",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
|
@ -61,14 +61,14 @@ diesel-derive-newtype = { workspace = true, optional = true }
|
||||||
diesel-derive-enum = { workspace = true, optional = true }
|
diesel-derive-enum = { workspace = true, optional = true }
|
||||||
diesel_migrations = { workspace = true, optional = true }
|
diesel_migrations = { workspace = true, optional = true }
|
||||||
diesel-async = { workspace = true, features = [
|
diesel-async = { workspace = true, features = [
|
||||||
"postgres",
|
|
||||||
"deadpool",
|
"deadpool",
|
||||||
|
"postgres",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
regex = { workspace = true, optional = true }
|
regex = { workspace = true, optional = true }
|
||||||
diesel_ltree = { workspace = true, optional = true }
|
diesel_ltree = { workspace = true, optional = true }
|
||||||
async-trait = { workspace = true }
|
async-trait = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
deadpool = { version = "0.12.1", features = ["rt_tokio_1"], optional = true }
|
deadpool = { version = "0.12.1", optional = true, features = ["rt_tokio_1"] }
|
||||||
ts-rs = { workspace = true, optional = true }
|
ts-rs = { workspace = true, optional = true }
|
||||||
futures-util = { workspace = true }
|
futures-util = { workspace = true }
|
||||||
tokio = { workspace = true, optional = true }
|
tokio = { workspace = true, optional = true }
|
||||||
|
|
|
@ -731,12 +731,12 @@ BEGIN
|
||||||
AND p.thing_id = OLD.thing_id;
|
AND p.thing_id = OLD.thing_id;
|
||||||
ELSIF (TG_OP = 'INSERT') THEN
|
ELSIF (TG_OP = 'INSERT') THEN
|
||||||
IF NEW.saved IS NOT NULL THEN
|
IF NEW.saved IS NOT NULL THEN
|
||||||
INSERT INTO person_saved_combined (published, person_id, thing_id)
|
INSERT INTO person_saved_combined (saved, person_id, thing_id)
|
||||||
VALUES (NEW.saved, NEW.person_id, NEW.thing_id);
|
VALUES (NEW.saved, NEW.person_id, NEW.thing_id);
|
||||||
END IF;
|
END IF;
|
||||||
ELSIF (TG_OP = 'UPDATE') THEN
|
ELSIF (TG_OP = 'UPDATE') THEN
|
||||||
IF NEW.saved IS NOT NULL THEN
|
IF NEW.saved IS NOT NULL THEN
|
||||||
INSERT INTO person_saved_combined (published, person_id, thing_id)
|
INSERT INTO person_saved_combined (saved, person_id, thing_id)
|
||||||
VALUES (NEW.saved, NEW.person_id, NEW.thing_id);
|
VALUES (NEW.saved, NEW.person_id, NEW.thing_id);
|
||||||
-- If saved gets set as null, delete the row
|
-- If saved gets set as null, delete the row
|
||||||
ELSE
|
ELSE
|
||||||
|
|
|
@ -186,26 +186,26 @@ BEGIN
|
||||||
AND pe.bot_account = FALSE
|
AND pe.bot_account = FALSE
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
SELECT
|
||||||
pl.person_id,
|
pa.person_id,
|
||||||
p.community_id
|
p.community_id
|
||||||
FROM
|
FROM
|
||||||
post_like pl
|
post_actions pa
|
||||||
INNER JOIN post p ON pl.post_id = p.id
|
INNER JOIN post p ON pa.post_id = p.id
|
||||||
INNER JOIN person pe ON pl.person_id = pe.id
|
INNER JOIN person pe ON pa.person_id = pe.id
|
||||||
WHERE
|
WHERE
|
||||||
pl.published > ('now'::timestamp - i::interval)
|
pa.liked > ('now'::timestamp - i::interval)
|
||||||
AND pe.bot_account = FALSE
|
AND pe.bot_account = FALSE
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
SELECT
|
||||||
cl.person_id,
|
ca.person_id,
|
||||||
p.community_id
|
p.community_id
|
||||||
FROM
|
FROM
|
||||||
comment_like cl
|
comment_actions ca
|
||||||
INNER JOIN comment c ON cl.comment_id = c.id
|
INNER JOIN comment c ON ca.comment_id = c.id
|
||||||
INNER JOIN post p ON c.post_id = p.id
|
INNER JOIN post p ON c.post_id = p.id
|
||||||
INNER JOIN person pe ON cl.person_id = pe.id
|
INNER JOIN person pe ON ca.person_id = pe.id
|
||||||
WHERE
|
WHERE
|
||||||
cl.published > ('now'::timestamp - i::interval)
|
ca.liked > ('now'::timestamp - i::interval)
|
||||||
AND pe.bot_account = FALSE) a
|
AND pe.bot_account = FALSE) a
|
||||||
GROUP BY
|
GROUP BY
|
||||||
community_id;
|
community_id;
|
||||||
|
@ -244,22 +244,22 @@ BEGIN
|
||||||
AND pe.bot_account = FALSE
|
AND pe.bot_account = FALSE
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
SELECT
|
||||||
pl.person_id
|
pa.person_id
|
||||||
FROM
|
FROM
|
||||||
post_like pl
|
post_actions pa
|
||||||
INNER JOIN person pe ON pl.person_id = pe.id
|
INNER JOIN person pe ON pa.person_id = pe.id
|
||||||
WHERE
|
WHERE
|
||||||
pl.published > ('now'::timestamp - i::interval)
|
pa.liked > ('now'::timestamp - i::interval)
|
||||||
AND pe.local = TRUE
|
AND pe.local = TRUE
|
||||||
AND pe.bot_account = FALSE
|
AND pe.bot_account = FALSE
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
SELECT
|
||||||
cl.person_id
|
ca.person_id
|
||||||
FROM
|
FROM
|
||||||
comment_like cl
|
comment_actions ca
|
||||||
INNER JOIN person pe ON cl.person_id = pe.id
|
INNER JOIN person pe ON ca.person_id = pe.id
|
||||||
WHERE
|
WHERE
|
||||||
cl.published > ('now'::timestamp - i::interval)
|
ca.liked > ('now'::timestamp - i::interval)
|
||||||
AND pe.local = TRUE
|
AND pe.local = TRUE
|
||||||
AND pe.bot_account = FALSE) a;
|
AND pe.bot_account = FALSE) a;
|
||||||
RETURN count_;
|
RETURN count_;
|
||||||
|
|
|
@ -35,4 +35,5 @@ pub mod private_message_report;
|
||||||
pub mod registration_application;
|
pub mod registration_application;
|
||||||
pub mod secret;
|
pub mod secret;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
|
pub mod tag;
|
||||||
pub mod tagline;
|
pub mod tagline;
|
||||||
|
|
|
@ -55,13 +55,11 @@ impl OAuthProvider {
|
||||||
pub fn convert_providers_to_public(
|
pub fn convert_providers_to_public(
|
||||||
oauth_providers: Vec<OAuthProvider>,
|
oauth_providers: Vec<OAuthProvider>,
|
||||||
) -> Vec<PublicOAuthProvider> {
|
) -> Vec<PublicOAuthProvider> {
|
||||||
let mut result = Vec::<PublicOAuthProvider>::new();
|
oauth_providers
|
||||||
for oauth_provider in &oauth_providers {
|
.into_iter()
|
||||||
if oauth_provider.enabled {
|
.filter(|x| x.enabled)
|
||||||
result.push(PublicOAuthProvider(oauth_provider.clone()));
|
.map(PublicOAuthProvider)
|
||||||
}
|
.collect()
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_all_public(pool: &mut DbPool<'_>) -> Result<Vec<PublicOAuthProvider>, Error> {
|
pub async fn get_all_public(pool: &mut DbPool<'_>) -> Result<Vec<PublicOAuthProvider>, Error> {
|
||||||
|
|
53
crates/db_schema/src/impls/tag.rs
Normal file
53
crates/db_schema/src/impls/tag.rs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
use crate::{
|
||||||
|
newtypes::TagId,
|
||||||
|
schema::{post_tag, tag},
|
||||||
|
source::tag::{PostTagInsertForm, Tag, TagInsertForm},
|
||||||
|
traits::Crud,
|
||||||
|
utils::{get_conn, DbPool},
|
||||||
|
};
|
||||||
|
use diesel::{insert_into, result::Error, QueryDsl};
|
||||||
|
use diesel_async::RunQueryDsl;
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Crud for Tag {
|
||||||
|
type InsertForm = TagInsertForm;
|
||||||
|
|
||||||
|
type UpdateForm = TagInsertForm;
|
||||||
|
|
||||||
|
type IdType = TagId;
|
||||||
|
|
||||||
|
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
insert_into(tag::table)
|
||||||
|
.values(form)
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn update(
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
pid: TagId,
|
||||||
|
form: &Self::UpdateForm,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
diesel::update(tag::table.find(pid))
|
||||||
|
.set(form)
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostTagInsertForm {
|
||||||
|
pub async fn insert_tag_associations(
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
tags: &[PostTagInsertForm],
|
||||||
|
) -> LemmyResult<()> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
insert_into(post_tag::table)
|
||||||
|
.values(tags)
|
||||||
|
.execute(conn)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -179,20 +179,18 @@ pub struct LtreeDef(pub String);
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
pub struct DbUrl(pub(crate) Box<Url>);
|
pub struct DbUrl(pub(crate) Box<Url>);
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
||||||
/// The report combined id
|
/// The report combined id
|
||||||
pub struct ReportCombinedId(i32);
|
pub struct ReportCombinedId(i32);
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// The person content combined id
|
/// The person content combined id
|
||||||
pub struct PersonContentCombinedId(i32);
|
pub struct PersonContentCombinedId(i32);
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// The person saved combined id
|
/// The person saved combined id
|
||||||
pub struct PersonSavedCombinedId(i32);
|
pub struct PersonSavedCombinedId(i32);
|
||||||
|
|
||||||
|
@ -389,3 +387,9 @@ impl InstanceId {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// The internal tag id.
|
||||||
|
pub struct TagId(pub i32);
|
||||||
|
|
|
@ -775,7 +775,7 @@ diesel::table! {
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
person_saved_combined (id) {
|
person_saved_combined (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
published -> Timestamptz,
|
saved -> Timestamptz,
|
||||||
person_id -> Int4,
|
person_id -> Int4,
|
||||||
post_id -> Nullable<Int4>,
|
post_id -> Nullable<Int4>,
|
||||||
comment_id -> Nullable<Int4>,
|
comment_id -> Nullable<Int4>,
|
||||||
|
@ -869,6 +869,14 @@ diesel::table! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diesel::table! {
|
||||||
|
post_tag (post_id, tag_id) {
|
||||||
|
post_id -> Int4,
|
||||||
|
tag_id -> Int4,
|
||||||
|
published -> Timestamptz,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
private_message (id) {
|
private_message (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
|
@ -1004,6 +1012,18 @@ diesel::table! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diesel::table! {
|
||||||
|
tag (id) {
|
||||||
|
id -> Int4,
|
||||||
|
ap_id -> Text,
|
||||||
|
name -> Text,
|
||||||
|
community_id -> Int4,
|
||||||
|
published -> Timestamptz,
|
||||||
|
updated -> Nullable<Timestamptz>,
|
||||||
|
deleted -> Bool,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
tagline (id) {
|
tagline (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
|
@ -1107,6 +1127,8 @@ diesel::joinable!(post_aggregates -> instance (instance_id));
|
||||||
diesel::joinable!(post_aggregates -> person (creator_id));
|
diesel::joinable!(post_aggregates -> person (creator_id));
|
||||||
diesel::joinable!(post_aggregates -> post (post_id));
|
diesel::joinable!(post_aggregates -> post (post_id));
|
||||||
diesel::joinable!(post_report -> post (post_id));
|
diesel::joinable!(post_report -> post (post_id));
|
||||||
|
diesel::joinable!(post_tag -> post (post_id));
|
||||||
|
diesel::joinable!(post_tag -> tag (tag_id));
|
||||||
diesel::joinable!(private_message_report -> private_message (private_message_id));
|
diesel::joinable!(private_message_report -> private_message (private_message_id));
|
||||||
diesel::joinable!(registration_application -> local_user (local_user_id));
|
diesel::joinable!(registration_application -> local_user (local_user_id));
|
||||||
diesel::joinable!(registration_application -> person (admin_id));
|
diesel::joinable!(registration_application -> person (admin_id));
|
||||||
|
@ -1117,6 +1139,7 @@ diesel::joinable!(site -> instance (instance_id));
|
||||||
diesel::joinable!(site_aggregates -> site (site_id));
|
diesel::joinable!(site_aggregates -> site (site_id));
|
||||||
diesel::joinable!(site_language -> language (language_id));
|
diesel::joinable!(site_language -> language (language_id));
|
||||||
diesel::joinable!(site_language -> site (site_id));
|
diesel::joinable!(site_language -> site (site_id));
|
||||||
|
diesel::joinable!(tag -> community (community_id));
|
||||||
|
|
||||||
diesel::allow_tables_to_appear_in_same_query!(
|
diesel::allow_tables_to_appear_in_same_query!(
|
||||||
admin_allow_instance,
|
admin_allow_instance,
|
||||||
|
@ -1179,6 +1202,7 @@ diesel::allow_tables_to_appear_in_same_query!(
|
||||||
post_actions,
|
post_actions,
|
||||||
post_aggregates,
|
post_aggregates,
|
||||||
post_report,
|
post_report,
|
||||||
|
post_tag,
|
||||||
private_message,
|
private_message,
|
||||||
private_message_report,
|
private_message_report,
|
||||||
received_activity,
|
received_activity,
|
||||||
|
@ -1190,5 +1214,6 @@ diesel::allow_tables_to_appear_in_same_query!(
|
||||||
site,
|
site,
|
||||||
site_aggregates,
|
site_aggregates,
|
||||||
site_language,
|
site_language,
|
||||||
|
tag,
|
||||||
tagline,
|
tagline,
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,11 +4,8 @@ use crate::schema::person_content_combined;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
use i_love_jesus::CursorKeysModule;
|
use i_love_jesus::CursorKeysModule;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use serde_with::skip_serializing_none;
|
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)]
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "full",
|
feature = "full",
|
||||||
derive(Identifiable, Queryable, Selectable, CursorKeysModule)
|
derive(Identifiable, Queryable, Selectable, CursorKeysModule)
|
||||||
|
|
|
@ -4,11 +4,8 @@ use crate::schema::person_saved_combined;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
use i_love_jesus::CursorKeysModule;
|
use i_love_jesus::CursorKeysModule;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use serde_with::skip_serializing_none;
|
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)]
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "full",
|
feature = "full",
|
||||||
derive(Identifiable, Queryable, Selectable, CursorKeysModule)
|
derive(Identifiable, Queryable, Selectable, CursorKeysModule)
|
||||||
|
@ -19,7 +16,7 @@ use serde_with::skip_serializing_none;
|
||||||
/// A combined person_saved table.
|
/// A combined person_saved table.
|
||||||
pub struct PersonSavedCombined {
|
pub struct PersonSavedCombined {
|
||||||
pub id: PersonSavedCombinedId,
|
pub id: PersonSavedCombinedId,
|
||||||
pub published: DateTime<Utc>,
|
pub saved: DateTime<Utc>,
|
||||||
pub person_id: PersonId,
|
pub person_id: PersonId,
|
||||||
pub post_id: Option<PostId>,
|
pub post_id: Option<PostId>,
|
||||||
pub comment_id: Option<CommentId>,
|
pub comment_id: Option<CommentId>,
|
||||||
|
|
|
@ -4,11 +4,8 @@ use crate::schema::report_combined;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
use i_love_jesus::CursorKeysModule;
|
use i_love_jesus::CursorKeysModule;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use serde_with::skip_serializing_none;
|
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)]
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "full",
|
feature = "full",
|
||||||
derive(Identifiable, Queryable, Selectable, CursorKeysModule)
|
derive(Identifiable, Queryable, Selectable, CursorKeysModule)
|
||||||
|
|
|
@ -41,6 +41,7 @@ pub mod private_message_report;
|
||||||
pub mod registration_application;
|
pub mod registration_application;
|
||||||
pub mod secret;
|
pub mod secret;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
|
pub mod tag;
|
||||||
pub mod tagline;
|
pub mod tagline;
|
||||||
|
|
||||||
/// Default value for columns like [community::Community.inbox_url] which are marked as serde(skip).
|
/// Default value for columns like [community::Community.inbox_url] which are marked as serde(skip).
|
||||||
|
|
57
crates/db_schema/src/source/tag.rs
Normal file
57
crates/db_schema/src/source/tag.rs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
use crate::newtypes::{CommunityId, DbUrl, PostId, TagId};
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use crate::schema::{post_tag, tag};
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_with::skip_serializing_none;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use ts_rs::TS;
|
||||||
|
|
||||||
|
/// A tag that can be assigned to a post within a community.
|
||||||
|
/// The tag object is created by the community moderators.
|
||||||
|
/// The assignment happens by the post creator and can be updated by the community moderators.
|
||||||
|
///
|
||||||
|
/// A tag is a federatable object that gives additional context to another object, which can be
|
||||||
|
/// displayed and filtered on currently, we only have community post tags, which is a tag that is
|
||||||
|
/// created by post authors as well as mods of a community, to categorize a post. in the future we
|
||||||
|
/// may add more tag types, depending on the requirements, this will lead to either expansion of
|
||||||
|
/// this table (community_id optional, addition of tag_type enum) or split of this table / creation
|
||||||
|
/// of new tables.
|
||||||
|
#[skip_serializing_none]
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS, Queryable, Selectable, Identifiable))]
|
||||||
|
#[cfg_attr(feature = "full", diesel(table_name = tag))]
|
||||||
|
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
pub struct Tag {
|
||||||
|
pub id: TagId,
|
||||||
|
pub ap_id: DbUrl,
|
||||||
|
pub name: String,
|
||||||
|
/// the community that owns this tag
|
||||||
|
pub community_id: CommunityId,
|
||||||
|
pub published: DateTime<Utc>,
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub updated: Option<DateTime<Utc>>,
|
||||||
|
pub deleted: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
|
||||||
|
#[cfg_attr(feature = "full", diesel(table_name = tag))]
|
||||||
|
pub struct TagInsertForm {
|
||||||
|
pub ap_id: DbUrl,
|
||||||
|
pub name: String,
|
||||||
|
pub community_id: CommunityId,
|
||||||
|
// default now
|
||||||
|
pub published: Option<DateTime<Utc>>,
|
||||||
|
pub updated: Option<DateTime<Utc>>,
|
||||||
|
pub deleted: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
|
||||||
|
#[cfg_attr(feature = "full", diesel(table_name = post_tag))]
|
||||||
|
pub struct PostTagInsertForm {
|
||||||
|
pub post_id: PostId,
|
||||||
|
pub tag_id: TagId,
|
||||||
|
}
|
|
@ -547,6 +547,11 @@ pub mod functions {
|
||||||
|
|
||||||
// really this function is variadic, this just adds the two-argument version
|
// really this function is variadic, this just adds the two-argument version
|
||||||
define_sql_function!(fn coalesce<T: diesel::sql_types::SqlType + diesel::sql_types::SingleValue>(x: diesel::sql_types::Nullable<T>, y: T) -> T);
|
define_sql_function!(fn coalesce<T: diesel::sql_types::SqlType + diesel::sql_types::SingleValue>(x: diesel::sql_types::Nullable<T>, y: T) -> T);
|
||||||
|
|
||||||
|
define_sql_function! {
|
||||||
|
#[aggregate]
|
||||||
|
fn json_agg<T: diesel::sql_types::SqlType + diesel::sql_types::SingleValue>(obj: T) -> Json
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const DELETED_REPLACEMENT_TEXT: &str = "*Permanently Deleted*";
|
pub const DELETED_REPLACEMENT_TEXT: &str = "*Permanently Deleted*";
|
||||||
|
|
|
@ -35,6 +35,7 @@ diesel-async = { workspace = true, optional = true }
|
||||||
diesel_ltree = { workspace = true, optional = true }
|
diesel_ltree = { workspace = true, optional = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_with = { workspace = true }
|
serde_with = { workspace = true }
|
||||||
|
serde_json = { workspace = true }
|
||||||
tracing = { workspace = true, optional = true }
|
tracing = { workspace = true, optional = true }
|
||||||
ts-rs = { workspace = true, optional = true }
|
ts-rs = { workspace = true, optional = true }
|
||||||
actix-web = { workspace = true, optional = true }
|
actix-web = { workspace = true, optional = true }
|
||||||
|
@ -47,3 +48,4 @@ serial_test = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
pretty_assertions = { workspace = true }
|
pretty_assertions = { workspace = true }
|
||||||
url = { workspace = true }
|
url = { workspace = true }
|
||||||
|
test-context = "0.3.0"
|
||||||
|
|
|
@ -141,28 +141,25 @@ fn queries<'a>() -> Queries<
|
||||||
query.first(&mut conn).await
|
query.first(&mut conn).await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, (options, site): (CommentQuery<'a>, &'a Site)| async move {
|
let list = move |mut conn: DbConn<'a>, (o, site): (CommentQuery<'a>, &'a Site)| async move {
|
||||||
// The left join below will return None in this case
|
// The left join below will return None in this case
|
||||||
let local_user_id_join = options
|
let local_user_id_join = o.local_user.local_user_id().unwrap_or(LocalUserId(-1));
|
||||||
.local_user
|
|
||||||
.local_user_id()
|
|
||||||
.unwrap_or(LocalUserId(-1));
|
|
||||||
|
|
||||||
let mut query = all_joins(comment::table.into_boxed(), options.local_user.person_id());
|
let mut query = all_joins(comment::table.into_boxed(), o.local_user.person_id());
|
||||||
|
|
||||||
if let Some(creator_id) = options.creator_id {
|
if let Some(creator_id) = o.creator_id {
|
||||||
query = query.filter(comment::creator_id.eq(creator_id));
|
query = query.filter(comment::creator_id.eq(creator_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(post_id) = options.post_id {
|
if let Some(post_id) = o.post_id {
|
||||||
query = query.filter(comment::post_id.eq(post_id));
|
query = query.filter(comment::post_id.eq(post_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(parent_path) = options.parent_path.as_ref() {
|
if let Some(parent_path) = o.parent_path.as_ref() {
|
||||||
query = query.filter(comment::path.contained_by(parent_path));
|
query = query.filter(comment::path.contained_by(parent_path));
|
||||||
};
|
};
|
||||||
//filtering out removed and deleted comments from search
|
//filtering out removed and deleted comments from search
|
||||||
if let Some(search_term) = options.search_term {
|
if let Some(search_term) = o.search_term {
|
||||||
query = query.filter(
|
query = query.filter(
|
||||||
comment::content
|
comment::content
|
||||||
.ilike(fuzzy_search(&search_term))
|
.ilike(fuzzy_search(&search_term))
|
||||||
|
@ -170,13 +167,13 @@ fn queries<'a>() -> Queries<
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(community_id) = options.community_id {
|
if let Some(community_id) = o.community_id {
|
||||||
query = query.filter(post::community_id.eq(community_id));
|
query = query.filter(post::community_id.eq(community_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_subscribed = community_actions::followed.is_not_null();
|
let is_subscribed = community_actions::followed.is_not_null();
|
||||||
|
|
||||||
match options.listing_type.unwrap_or_default() {
|
match o.listing_type.unwrap_or_default() {
|
||||||
ListingType::Subscribed => query = query.filter(is_subscribed), /* TODO could be this: and(community_follower::person_id.eq(person_id_join)), */
|
ListingType::Subscribed => query = query.filter(is_subscribed), /* TODO could be this: and(community_follower::person_id.eq(person_id_join)), */
|
||||||
ListingType::Local => {
|
ListingType::Local => {
|
||||||
query = query
|
query = query
|
||||||
|
@ -189,26 +186,24 @@ fn queries<'a>() -> Queries<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(my_id) = options.local_user.person_id() {
|
if let Some(my_id) = o.local_user.person_id() {
|
||||||
let not_creator_filter = comment::creator_id.ne(my_id);
|
let not_creator_filter = comment::creator_id.ne(my_id);
|
||||||
if options.liked_only.unwrap_or_default() {
|
if o.liked_only.unwrap_or_default() {
|
||||||
query = query
|
query = query
|
||||||
.filter(not_creator_filter)
|
.filter(not_creator_filter)
|
||||||
.filter(comment_actions::like_score.eq(1));
|
.filter(comment_actions::like_score.eq(1));
|
||||||
} else if options.disliked_only.unwrap_or_default() {
|
} else if o.disliked_only.unwrap_or_default() {
|
||||||
query = query
|
query = query
|
||||||
.filter(not_creator_filter)
|
.filter(not_creator_filter)
|
||||||
.filter(comment_actions::like_score.eq(-1));
|
.filter(comment_actions::like_score.eq(-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !options.local_user.show_bot_accounts() {
|
if !o.local_user.show_bot_accounts() {
|
||||||
query = query.filter(person::bot_account.eq(false));
|
query = query.filter(person::bot_account.eq(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
if options.local_user.is_some()
|
if o.local_user.is_some() && o.listing_type.unwrap_or_default() != ListingType::ModeratorView {
|
||||||
&& options.listing_type.unwrap_or_default() != ListingType::ModeratorView
|
|
||||||
{
|
|
||||||
// Filter out the rows with missing languages
|
// Filter out the rows with missing languages
|
||||||
query = query.filter(exists(
|
query = query.filter(exists(
|
||||||
local_user_language::table.filter(
|
local_user_language::table.filter(
|
||||||
|
@ -225,15 +220,15 @@ fn queries<'a>() -> Queries<
|
||||||
.filter(person_actions::blocked.is_null());
|
.filter(person_actions::blocked.is_null());
|
||||||
};
|
};
|
||||||
|
|
||||||
if !options.local_user.show_nsfw(site) {
|
if !o.local_user.show_nsfw(site) {
|
||||||
query = query
|
query = query
|
||||||
.filter(post::nsfw.eq(false))
|
.filter(post::nsfw.eq(false))
|
||||||
.filter(community::nsfw.eq(false));
|
.filter(community::nsfw.eq(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
query = options.local_user.visible_communities_only(query);
|
query = o.local_user.visible_communities_only(query);
|
||||||
|
|
||||||
if !options.local_user.is_admin() {
|
if !o.local_user.is_admin() {
|
||||||
query = query.filter(
|
query = query.filter(
|
||||||
community::visibility
|
community::visibility
|
||||||
.ne(CommunityVisibility::Private)
|
.ne(CommunityVisibility::Private)
|
||||||
|
@ -242,8 +237,8 @@ fn queries<'a>() -> Queries<
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Max depth given means its a tree fetch
|
// A Max depth given means its a tree fetch
|
||||||
let (limit, offset) = if let Some(max_depth) = options.max_depth {
|
let (limit, offset) = if let Some(max_depth) = o.max_depth {
|
||||||
let depth_limit = if let Some(parent_path) = options.parent_path.as_ref() {
|
let depth_limit = if let Some(parent_path) = o.parent_path.as_ref() {
|
||||||
parent_path.0.split('.').count() as i32 + max_depth
|
parent_path.0.split('.').count() as i32 + max_depth
|
||||||
// Add one because of root "0"
|
// Add one because of root "0"
|
||||||
} else {
|
} else {
|
||||||
|
@ -254,7 +249,7 @@ fn queries<'a>() -> Queries<
|
||||||
|
|
||||||
// only order if filtering by a post id, or parent_path. DOS potential otherwise and max_depth
|
// only order if filtering by a post id, or parent_path. DOS potential otherwise and max_depth
|
||||||
// + !post_id isn't used anyways (afaik)
|
// + !post_id isn't used anyways (afaik)
|
||||||
if options.post_id.is_some() || options.parent_path.is_some() {
|
if o.post_id.is_some() || o.parent_path.is_some() {
|
||||||
// Always order by the parent path first
|
// Always order by the parent path first
|
||||||
query = query.then_order_by(subpath(comment::path, 0, -1));
|
query = query.then_order_by(subpath(comment::path, 0, -1));
|
||||||
}
|
}
|
||||||
|
@ -271,16 +266,16 @@ fn queries<'a>() -> Queries<
|
||||||
// (i64::MAX, 0)
|
// (i64::MAX, 0)
|
||||||
(300, 0)
|
(300, 0)
|
||||||
} else {
|
} else {
|
||||||
// limit_and_offset_unlimited(options.page, options.limit)
|
// limit_and_offset_unlimited(o.page, o.limit)
|
||||||
limit_and_offset(options.page, options.limit)?
|
limit_and_offset(o.page, o.limit)?
|
||||||
};
|
};
|
||||||
|
|
||||||
// distinguished comments should go first when viewing post
|
// distinguished comments should go first when viewing post
|
||||||
if options.post_id.is_some() || options.parent_path.is_some() {
|
if o.post_id.is_some() || o.parent_path.is_some() {
|
||||||
query = query.then_order_by(comment::distinguished.desc());
|
query = query.then_order_by(comment::distinguished.desc());
|
||||||
}
|
}
|
||||||
|
|
||||||
query = match options.sort.unwrap_or(CommentSortType::Hot) {
|
query = match o.sort.unwrap_or(CommentSortType::Hot) {
|
||||||
CommentSortType::Hot => query
|
CommentSortType::Hot => query
|
||||||
.then_order_by(comment_aggregates::hot_rank.desc())
|
.then_order_by(comment_aggregates::hot_rank.desc())
|
||||||
.then_order_by(comment_aggregates::score.desc()),
|
.then_order_by(comment_aggregates::score.desc()),
|
||||||
|
|
|
@ -18,6 +18,8 @@ pub mod person_saved_combined_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod post_report_view;
|
pub mod post_report_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
pub mod post_tags_view;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
pub mod post_view;
|
pub mod post_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod private_message_report_view;
|
pub mod private_message_report_view;
|
||||||
|
|
|
@ -34,6 +34,8 @@ use lemmy_db_schema::{
|
||||||
post,
|
post,
|
||||||
post_actions,
|
post_actions,
|
||||||
post_aggregates,
|
post_aggregates,
|
||||||
|
post_tag,
|
||||||
|
tag,
|
||||||
},
|
},
|
||||||
source::{
|
source::{
|
||||||
combined::person_content::{person_content_combined_keys as key, PersonContentCombined},
|
combined::person_content::{person_content_combined_keys as key, PersonContentCombined},
|
||||||
|
@ -96,6 +98,15 @@ impl PersonContentCombinedQuery {
|
||||||
|
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
|
let post_tags = post_tag::table
|
||||||
|
.inner_join(tag::table)
|
||||||
|
.select(diesel::dsl::sql::<diesel::sql_types::Json>(
|
||||||
|
"json_agg(tag.*)",
|
||||||
|
))
|
||||||
|
.filter(post_tag::post_id.eq(post::id))
|
||||||
|
.filter(tag::deleted.eq(false))
|
||||||
|
.single_value();
|
||||||
|
|
||||||
// Notes: since the post_id and comment_id are optional columns,
|
// Notes: since the post_id and comment_id are optional columns,
|
||||||
// many joins must use an OR condition.
|
// many joins must use an OR condition.
|
||||||
// For example, the creator must be the person table joined to either:
|
// For example, the creator must be the person table joined to either:
|
||||||
|
@ -170,6 +181,7 @@ impl PersonContentCombinedQuery {
|
||||||
post_actions::hidden.nullable().is_not_null(),
|
post_actions::hidden.nullable().is_not_null(),
|
||||||
post_actions::like_score.nullable(),
|
post_actions::like_score.nullable(),
|
||||||
image_details::all_columns.nullable(),
|
image_details::all_columns.nullable(),
|
||||||
|
post_tags,
|
||||||
// Comment-specific
|
// Comment-specific
|
||||||
comment::all_columns.nullable(),
|
comment::all_columns.nullable(),
|
||||||
comment_aggregates::all_columns.nullable(),
|
comment_aggregates::all_columns.nullable(),
|
||||||
|
@ -260,6 +272,7 @@ impl InternalToCombinedView for PersonContentViewInternal {
|
||||||
my_vote: v.my_post_vote,
|
my_vote: v.my_post_vote,
|
||||||
image_details: v.image_details,
|
image_details: v.image_details,
|
||||||
banned_from_community: v.banned_from_community,
|
banned_from_community: v.banned_from_community,
|
||||||
|
tags: v.post_tags,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ use lemmy_db_schema::{
|
||||||
post,
|
post,
|
||||||
post_actions,
|
post_actions,
|
||||||
post_aggregates,
|
post_aggregates,
|
||||||
|
post_tag,
|
||||||
|
tag,
|
||||||
},
|
},
|
||||||
source::{
|
source::{
|
||||||
combined::person_saved::{person_saved_combined_keys as key, PersonSavedCombined},
|
combined::person_saved::{person_saved_combined_keys as key, PersonSavedCombined},
|
||||||
|
@ -90,6 +92,15 @@ impl PersonSavedCombinedQuery {
|
||||||
|
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
|
let post_tags = post_tag::table
|
||||||
|
.inner_join(tag::table)
|
||||||
|
.select(diesel::dsl::sql::<diesel::sql_types::Json>(
|
||||||
|
"json_agg(tag.*)",
|
||||||
|
))
|
||||||
|
.filter(post_tag::post_id.eq(post::id))
|
||||||
|
.filter(tag::deleted.eq(false))
|
||||||
|
.single_value();
|
||||||
|
|
||||||
// Notes: since the post_id and comment_id are optional columns,
|
// Notes: since the post_id and comment_id are optional columns,
|
||||||
// many joins must use an OR condition.
|
// many joins must use an OR condition.
|
||||||
// For example, the creator must be the person table joined to either:
|
// For example, the creator must be the person table joined to either:
|
||||||
|
@ -172,6 +183,7 @@ impl PersonSavedCombinedQuery {
|
||||||
post_actions::hidden.nullable().is_not_null(),
|
post_actions::hidden.nullable().is_not_null(),
|
||||||
post_actions::like_score.nullable(),
|
post_actions::like_score.nullable(),
|
||||||
image_details::all_columns.nullable(),
|
image_details::all_columns.nullable(),
|
||||||
|
post_tags,
|
||||||
// Comment-specific
|
// Comment-specific
|
||||||
comment::all_columns.nullable(),
|
comment::all_columns.nullable(),
|
||||||
comment_aggregates::all_columns.nullable(),
|
comment_aggregates::all_columns.nullable(),
|
||||||
|
@ -206,9 +218,9 @@ impl PersonSavedCombinedQuery {
|
||||||
query = query.after(page_after);
|
query = query.after(page_after);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sorting by published
|
// Sorting by saved desc
|
||||||
query = query
|
query = query
|
||||||
.then_desc(key::published)
|
.then_desc(key::saved)
|
||||||
// Tie breaker
|
// Tie breaker
|
||||||
.then_desc(key::id);
|
.then_desc(key::id);
|
||||||
|
|
||||||
|
|
30
crates/db_views/src/post_tags_view.rs
Normal file
30
crates/db_views/src/post_tags_view.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
//! see post_view.rs for the reason for this json decoding
|
||||||
|
use crate::structs::PostTags;
|
||||||
|
use diesel::{
|
||||||
|
deserialize::FromSql,
|
||||||
|
pg::{Pg, PgValue},
|
||||||
|
serialize::ToSql,
|
||||||
|
sql_types::{self, Nullable},
|
||||||
|
};
|
||||||
|
|
||||||
|
impl FromSql<Nullable<sql_types::Json>, Pg> for PostTags {
|
||||||
|
fn from_sql(bytes: PgValue) -> diesel::deserialize::Result<Self> {
|
||||||
|
let value = <serde_json::Value as FromSql<sql_types::Json, Pg>>::from_sql(bytes)?;
|
||||||
|
Ok(serde_json::from_value::<PostTags>(value)?)
|
||||||
|
}
|
||||||
|
fn from_nullable_sql(
|
||||||
|
bytes: Option<<Pg as diesel::backend::Backend>::RawValue<'_>>,
|
||||||
|
) -> diesel::deserialize::Result<Self> {
|
||||||
|
match bytes {
|
||||||
|
Some(bytes) => Self::from_sql(bytes),
|
||||||
|
None => Ok(Self { tags: vec![] }),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToSql<Nullable<sql_types::Json>, Pg> for PostTags {
|
||||||
|
fn to_sql(&self, out: &mut diesel::serialize::Output<Pg>) -> diesel::serialize::Result {
|
||||||
|
let value = serde_json::to_value(self)?;
|
||||||
|
<serde_json::Value as ToSql<sql_types::Json, Pg>>::to_sql(&value, &mut out.reborrow())
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load diff
|
@ -53,8 +53,7 @@ fn queries<'a>() -> Queries<
|
||||||
.await
|
.await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>,
|
let list = move |mut conn: DbConn<'a>, (o, recipient_id): (PrivateMessageQuery, PersonId)| async move {
|
||||||
(options, recipient_id): (PrivateMessageQuery, PersonId)| async move {
|
|
||||||
let mut query = all_joins(private_message::table.into_boxed())
|
let mut query = all_joins(private_message::table.into_boxed())
|
||||||
.select(selection)
|
.select(selection)
|
||||||
// Dont show replies from blocked users
|
// Dont show replies from blocked users
|
||||||
|
@ -63,9 +62,9 @@ fn queries<'a>() -> Queries<
|
||||||
.filter(instance_actions::blocked.is_null());
|
.filter(instance_actions::blocked.is_null());
|
||||||
|
|
||||||
// If its unread, I only want the ones to me
|
// If its unread, I only want the ones to me
|
||||||
if options.unread_only {
|
if o.unread_only {
|
||||||
query = query.filter(private_message::read.eq(false));
|
query = query.filter(private_message::read.eq(false));
|
||||||
if let Some(i) = options.creator_id {
|
if let Some(i) = o.creator_id {
|
||||||
query = query.filter(private_message::creator_id.eq(i))
|
query = query.filter(private_message::creator_id.eq(i))
|
||||||
}
|
}
|
||||||
query = query.filter(private_message::recipient_id.eq(recipient_id));
|
query = query.filter(private_message::recipient_id.eq(recipient_id));
|
||||||
|
@ -77,7 +76,7 @@ fn queries<'a>() -> Queries<
|
||||||
.eq(recipient_id)
|
.eq(recipient_id)
|
||||||
.or(private_message::creator_id.eq(recipient_id)),
|
.or(private_message::creator_id.eq(recipient_id)),
|
||||||
);
|
);
|
||||||
if let Some(i) = options.creator_id {
|
if let Some(i) = o.creator_id {
|
||||||
query = query.filter(
|
query = query.filter(
|
||||||
private_message::creator_id
|
private_message::creator_id
|
||||||
.eq(i)
|
.eq(i)
|
||||||
|
@ -86,7 +85,7 @@ fn queries<'a>() -> Queries<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
let (limit, offset) = limit_and_offset(o.page, o.limit)?;
|
||||||
|
|
||||||
query = query
|
query = query
|
||||||
.filter(private_message::deleted.eq(false))
|
.filter(private_message::deleted.eq(false))
|
||||||
|
|
|
@ -53,12 +53,12 @@ fn queries<'a>() -> Queries<
|
||||||
query.first(&mut conn).await
|
query.first(&mut conn).await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, options: RegistrationApplicationQuery| async move {
|
let list = move |mut conn: DbConn<'a>, o: RegistrationApplicationQuery| async move {
|
||||||
let mut query = all_joins(registration_application::table.into_boxed());
|
let mut query = all_joins(registration_application::table.into_boxed());
|
||||||
|
|
||||||
// If viewing all applications, order by newest, but if viewing unresolved only, show the oldest
|
// If viewing all applications, order by newest, but if viewing unresolved only, show the oldest
|
||||||
// first (FIFO)
|
// first (FIFO)
|
||||||
if options.unread_only {
|
if o.unread_only {
|
||||||
query = query
|
query = query
|
||||||
.filter(registration_application::admin_id.is_null())
|
.filter(registration_application::admin_id.is_null())
|
||||||
.order_by(registration_application::published.asc());
|
.order_by(registration_application::published.asc());
|
||||||
|
@ -66,11 +66,11 @@ fn queries<'a>() -> Queries<
|
||||||
query = query.order_by(registration_application::published.desc());
|
query = query.order_by(registration_application::published.desc());
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.verified_email_only {
|
if o.verified_email_only {
|
||||||
query = query.filter(local_user::email_verified.eq(true))
|
query = query.filter(local_user::email_verified.eq(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
let (limit, offset) = limit_and_offset(o.page, o.limit)?;
|
||||||
|
|
||||||
query = query.limit(limit).offset(offset);
|
query = query.limit(limit).offset(offset);
|
||||||
|
|
||||||
|
|
|
@ -576,7 +576,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
CommentReport::report(pool, &sara_report_comment_form).await?;
|
CommentReport::report(pool, &sara_report_comment_form).await?;
|
||||||
|
|
||||||
// Timmy creates a private message report
|
// Timmy creates a private message
|
||||||
let pm_form = PrivateMessageInsertForm::new(
|
let pm_form = PrivateMessageInsertForm::new(
|
||||||
data.timmy.id,
|
data.timmy.id,
|
||||||
data.sara.id,
|
data.sara.id,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
use diesel::Queryable;
|
use diesel::Queryable;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use diesel::{deserialize::FromSqlRow, expression::AsExpression, sql_types};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::{CommentAggregates, PersonAggregates, PostAggregates, SiteAggregates},
|
aggregates::structs::{CommentAggregates, PersonAggregates, PostAggregates, SiteAggregates},
|
||||||
source::{
|
source::{
|
||||||
|
@ -20,6 +22,7 @@ use lemmy_db_schema::{
|
||||||
private_message_report::PrivateMessageReport,
|
private_message_report::PrivateMessageReport,
|
||||||
registration_application::RegistrationApplication,
|
registration_application::RegistrationApplication,
|
||||||
site::Site,
|
site::Site,
|
||||||
|
tag::Tag,
|
||||||
},
|
},
|
||||||
SubscribedType,
|
SubscribedType,
|
||||||
};
|
};
|
||||||
|
@ -169,6 +172,7 @@ pub struct PostView {
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub my_vote: Option<i16>,
|
pub my_vote: Option<i16>,
|
||||||
pub unread_comments: i64,
|
pub unread_comments: i64,
|
||||||
|
pub tags: PostTags,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
||||||
|
@ -315,6 +319,7 @@ pub struct PersonContentViewInternal {
|
||||||
pub post_hidden: bool,
|
pub post_hidden: bool,
|
||||||
pub my_post_vote: Option<i16>,
|
pub my_post_vote: Option<i16>,
|
||||||
pub image_details: Option<ImageDetails>,
|
pub image_details: Option<ImageDetails>,
|
||||||
|
pub post_tags: PostTags,
|
||||||
// Comment-specific
|
// Comment-specific
|
||||||
pub comment: Option<Comment>,
|
pub comment: Option<Comment>,
|
||||||
pub comment_counts: Option<CommentAggregates>,
|
pub comment_counts: Option<CommentAggregates>,
|
||||||
|
@ -341,3 +346,12 @@ pub enum PersonContentCombinedView {
|
||||||
Post(PostView),
|
Post(PostView),
|
||||||
Comment(CommentView),
|
Comment(CommentView),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, serde::Serialize, serde::Deserialize, Debug, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS, FromSqlRow, AsExpression))]
|
||||||
|
#[serde(transparent)]
|
||||||
|
#[cfg_attr(feature = "full", diesel(sql_type = Nullable<sql_types::Json>))]
|
||||||
|
/// we wrap this in a struct so we can implement FromSqlRow<Json> for it
|
||||||
|
pub struct PostTags {
|
||||||
|
pub tags: Vec<Tag>,
|
||||||
|
}
|
||||||
|
|
|
@ -26,13 +26,13 @@ full = [
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_db_schema = { workspace = true }
|
lemmy_db_schema = { workspace = true }
|
||||||
diesel = { workspace = true, features = [
|
diesel = { workspace = true, features = [
|
||||||
"postgres",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"postgres",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
diesel-async = { workspace = true, features = [
|
diesel-async = { workspace = true, features = [
|
||||||
"postgres",
|
|
||||||
"deadpool",
|
"deadpool",
|
||||||
|
"postgres",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_with = { workspace = true }
|
serde_with = { workspace = true }
|
||||||
|
|
|
@ -113,24 +113,24 @@ fn queries<'a>() -> Queries<
|
||||||
.await
|
.await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, options: CommentReplyQuery| async move {
|
let list = move |mut conn: DbConn<'a>, o: CommentReplyQuery| async move {
|
||||||
// These filters need to be kept in sync with the filters in
|
// These filters need to be kept in sync with the filters in
|
||||||
// CommentReplyView::get_unread_replies()
|
// CommentReplyView::get_unread_replies()
|
||||||
let mut query = all_joins(comment_reply::table.into_boxed(), options.my_person_id);
|
let mut query = all_joins(comment_reply::table.into_boxed(), o.my_person_id);
|
||||||
|
|
||||||
if let Some(recipient_id) = options.recipient_id {
|
if let Some(recipient_id) = o.recipient_id {
|
||||||
query = query.filter(comment_reply::recipient_id.eq(recipient_id));
|
query = query.filter(comment_reply::recipient_id.eq(recipient_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.unread_only {
|
if o.unread_only {
|
||||||
query = query.filter(comment_reply::read.eq(false));
|
query = query.filter(comment_reply::read.eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !options.show_bot_accounts {
|
if !o.show_bot_accounts {
|
||||||
query = query.filter(not(person::bot_account));
|
query = query.filter(not(person::bot_account));
|
||||||
};
|
};
|
||||||
|
|
||||||
query = match options.sort.unwrap_or(CommentSortType::New) {
|
query = match o.sort.unwrap_or(CommentSortType::New) {
|
||||||
CommentSortType::Hot => query.then_order_by(comment_aggregates::hot_rank.desc()),
|
CommentSortType::Hot => query.then_order_by(comment_aggregates::hot_rank.desc()),
|
||||||
CommentSortType::Controversial => {
|
CommentSortType::Controversial => {
|
||||||
query.then_order_by(comment_aggregates::controversy_rank.desc())
|
query.then_order_by(comment_aggregates::controversy_rank.desc())
|
||||||
|
@ -143,7 +143,7 @@ fn queries<'a>() -> Queries<
|
||||||
// Don't show replies from blocked persons
|
// Don't show replies from blocked persons
|
||||||
query = query.filter(person_actions::blocked.is_null());
|
query = query.filter(person_actions::blocked.is_null());
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
let (limit, offset) = limit_and_offset(o.page, o.limit)?;
|
||||||
|
|
||||||
query
|
query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
|
@ -90,17 +90,17 @@ fn queries<'a>() -> Queries<
|
||||||
query.first(&mut conn).await
|
query.first(&mut conn).await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, (options, site): (CommunityQuery<'a>, &'a Site)| async move {
|
let list = move |mut conn: DbConn<'a>, (o, site): (CommunityQuery<'a>, &'a Site)| async move {
|
||||||
use CommunitySortType::*;
|
use CommunitySortType::*;
|
||||||
|
|
||||||
let mut query = all_joins(community::table.into_boxed(), options.local_user).select(selection);
|
let mut query = all_joins(community::table.into_boxed(), o.local_user).select(selection);
|
||||||
|
|
||||||
if let Some(search_term) = options.search_term {
|
if let Some(search_term) = o.search_term {
|
||||||
let searcher = fuzzy_search(&search_term);
|
let searcher = fuzzy_search(&search_term);
|
||||||
let name_filter = community::name.ilike(searcher.clone());
|
let name_filter = community::name.ilike(searcher.clone());
|
||||||
let title_filter = community::title.ilike(searcher.clone());
|
let title_filter = community::title.ilike(searcher.clone());
|
||||||
let description_filter = community::description.ilike(searcher.clone());
|
let description_filter = community::description.ilike(searcher.clone());
|
||||||
query = if options.title_only.unwrap_or_default() {
|
query = if o.title_only.unwrap_or_default() {
|
||||||
query.filter(name_filter.or(title_filter))
|
query.filter(name_filter.or(title_filter))
|
||||||
} else {
|
} else {
|
||||||
query.filter(name_filter.or(title_filter.or(description_filter)))
|
query.filter(name_filter.or(title_filter.or(description_filter)))
|
||||||
|
@ -108,7 +108,7 @@ fn queries<'a>() -> Queries<
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide deleted and removed for non-admins or mods
|
// Hide deleted and removed for non-admins or mods
|
||||||
if !options.is_mod_or_admin {
|
if !o.is_mod_or_admin {
|
||||||
query = query.filter(not_removed_or_deleted).filter(
|
query = query.filter(not_removed_or_deleted).filter(
|
||||||
community::hidden
|
community::hidden
|
||||||
.eq(false)
|
.eq(false)
|
||||||
|
@ -116,7 +116,7 @@ fn queries<'a>() -> Queries<
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
match options.sort.unwrap_or(Hot) {
|
match o.sort.unwrap_or(Hot) {
|
||||||
Hot | Active | Scaled => query = query.order_by(community_aggregates::hot_rank.desc()),
|
Hot | Active | Scaled => query = query.order_by(community_aggregates::hot_rank.desc()),
|
||||||
NewComments | TopDay | TopTwelveHour | TopSixHour | TopHour => {
|
NewComments | TopDay | TopTwelveHour | TopSixHour | TopHour => {
|
||||||
query = query.order_by(community_aggregates::users_active_day.desc())
|
query = query.order_by(community_aggregates::users_active_day.desc())
|
||||||
|
@ -137,7 +137,7 @@ fn queries<'a>() -> Queries<
|
||||||
NameDesc => query = query.order_by(lower(community::name).desc()),
|
NameDesc => query = query.order_by(lower(community::name).desc()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(listing_type) = options.listing_type {
|
if let Some(listing_type) = o.listing_type {
|
||||||
query = match listing_type {
|
query = match listing_type {
|
||||||
ListingType::Subscribed => {
|
ListingType::Subscribed => {
|
||||||
query.filter(community_actions::follow_state.eq(Some(CommunityFollowerState::Accepted)))
|
query.filter(community_actions::follow_state.eq(Some(CommunityFollowerState::Accepted)))
|
||||||
|
@ -151,13 +151,13 @@ fn queries<'a>() -> Queries<
|
||||||
// also hidden (based on profile setting)
|
// also hidden (based on profile setting)
|
||||||
query = query.filter(instance_actions::blocked.is_null());
|
query = query.filter(instance_actions::blocked.is_null());
|
||||||
query = query.filter(community_actions::blocked.is_null());
|
query = query.filter(community_actions::blocked.is_null());
|
||||||
if !(options.local_user.show_nsfw(site) || options.show_nsfw) {
|
if !(o.local_user.show_nsfw(site) || o.show_nsfw) {
|
||||||
query = query.filter(community::nsfw.eq(false));
|
query = query.filter(community::nsfw.eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
query = options.local_user.visible_communities_only(query);
|
query = o.local_user.visible_communities_only(query);
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
let (limit, offset) = limit_and_offset(o.page, o.limit)?;
|
||||||
query
|
query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
|
|
|
@ -113,24 +113,24 @@ fn queries<'a>() -> Queries<
|
||||||
.await
|
.await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, options: PersonMentionQuery| async move {
|
let list = move |mut conn: DbConn<'a>, o: PersonMentionQuery| async move {
|
||||||
// These filters need to be kept in sync with the filters in
|
// These filters need to be kept in sync with the filters in
|
||||||
// PersonMentionView::get_unread_mentions()
|
// PersonMentionView::get_unread_mentions()
|
||||||
let mut query = all_joins(person_mention::table.into_boxed(), options.my_person_id);
|
let mut query = all_joins(person_mention::table.into_boxed(), o.my_person_id);
|
||||||
|
|
||||||
if let Some(recipient_id) = options.recipient_id {
|
if let Some(recipient_id) = o.recipient_id {
|
||||||
query = query.filter(person_mention::recipient_id.eq(recipient_id));
|
query = query.filter(person_mention::recipient_id.eq(recipient_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.unread_only {
|
if o.unread_only {
|
||||||
query = query.filter(person_mention::read.eq(false));
|
query = query.filter(person_mention::read.eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !options.show_bot_accounts {
|
if !o.show_bot_accounts {
|
||||||
query = query.filter(not(person::bot_account));
|
query = query.filter(not(person::bot_account));
|
||||||
};
|
};
|
||||||
|
|
||||||
query = match options.sort.unwrap_or(CommentSortType::Hot) {
|
query = match o.sort.unwrap_or(CommentSortType::Hot) {
|
||||||
CommentSortType::Hot => query.then_order_by(comment_aggregates::hot_rank.desc()),
|
CommentSortType::Hot => query.then_order_by(comment_aggregates::hot_rank.desc()),
|
||||||
CommentSortType::Controversial => {
|
CommentSortType::Controversial => {
|
||||||
query.then_order_by(comment_aggregates::controversy_rank.desc())
|
query.then_order_by(comment_aggregates::controversy_rank.desc())
|
||||||
|
@ -143,7 +143,7 @@ fn queries<'a>() -> Queries<
|
||||||
// Don't show mentions from blocked persons
|
// Don't show mentions from blocked persons
|
||||||
query = query.filter(person_actions::blocked.is_null());
|
query = query.filter(person_actions::blocked.is_null());
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
let (limit, offset) = limit_and_offset(o.page, o.limit)?;
|
||||||
|
|
||||||
query
|
query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
|
@ -99,15 +99,15 @@ fn queries<'a>(
|
||||||
)
|
)
|
||||||
.filter(person::deleted.eq(false));
|
.filter(person::deleted.eq(false));
|
||||||
}
|
}
|
||||||
ListMode::Query(options) => {
|
ListMode::Query(o) => {
|
||||||
if let Some(search_term) = options.search_term {
|
if let Some(search_term) = o.search_term {
|
||||||
let searcher = fuzzy_search(&search_term);
|
let searcher = fuzzy_search(&search_term);
|
||||||
query = query
|
query = query
|
||||||
.filter(person::name.ilike(searcher.clone()))
|
.filter(person::name.ilike(searcher.clone()))
|
||||||
.or_filter(person::display_name.ilike(searcher));
|
.or_filter(person::display_name.ilike(searcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
let sort = options.sort.map(post_to_person_sort_type);
|
let sort = o.sort.map(post_to_person_sort_type);
|
||||||
query = match sort.unwrap_or(PersonSortType::CommentScore) {
|
query = match sort.unwrap_or(PersonSortType::CommentScore) {
|
||||||
PersonSortType::New => query.order_by(person::published.desc()),
|
PersonSortType::New => query.order_by(person::published.desc()),
|
||||||
PersonSortType::Old => query.order_by(person::published.asc()),
|
PersonSortType::Old => query.order_by(person::published.asc()),
|
||||||
|
@ -117,10 +117,10 @@ fn queries<'a>(
|
||||||
PersonSortType::PostCount => query.order_by(person_aggregates::post_count.desc()),
|
PersonSortType::PostCount => query.order_by(person_aggregates::post_count.desc()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
let (limit, offset) = limit_and_offset(o.page, o.limit)?;
|
||||||
query = query.limit(limit).offset(offset);
|
query = query.limit(limit).offset(offset);
|
||||||
|
|
||||||
if let Some(listing_type) = options.listing_type {
|
if let Some(listing_type) = o.listing_type {
|
||||||
query = match listing_type {
|
query = match listing_type {
|
||||||
// return nothing as its not possible to follow users
|
// return nothing as its not possible to follow users
|
||||||
ListingType::Subscribed => query.limit(0),
|
ListingType::Subscribed => query.limit(0),
|
||||||
|
|
|
@ -29,13 +29,13 @@ lemmy_db_schema = { workspace = true }
|
||||||
lemmy_utils = { workspace = true, optional = true }
|
lemmy_utils = { workspace = true, optional = true }
|
||||||
i-love-jesus = { workspace = true, optional = true }
|
i-love-jesus = { workspace = true, optional = true }
|
||||||
diesel = { workspace = true, features = [
|
diesel = { workspace = true, features = [
|
||||||
"postgres",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"postgres",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
diesel-async = { workspace = true, features = [
|
diesel-async = { workspace = true, features = [
|
||||||
"postgres",
|
|
||||||
"deadpool",
|
"deadpool",
|
||||||
|
"postgres",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_with = { workspace = true }
|
serde_with = { workspace = true }
|
||||||
|
|
|
@ -25,7 +25,7 @@ activitypub_federation.workspace = true
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
chrono.workspace = true
|
chrono.workspace = true
|
||||||
diesel = { workspace = true, features = ["postgres", "chrono", "serde_json"] }
|
diesel = { workspace = true, features = ["chrono", "postgres", "serde_json"] }
|
||||||
diesel-async = { workspace = true, features = ["deadpool", "postgres"] }
|
diesel-async = { workspace = true, features = ["deadpool", "postgres"] }
|
||||||
reqwest.workspace = true
|
reqwest.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
|
|
@ -454,7 +454,6 @@ fn build_item(
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> LemmyResult<Item> {
|
) -> LemmyResult<Item> {
|
||||||
// TODO add images
|
// TODO add images
|
||||||
let author_url = format!("{protocol_and_hostname}/u/{creator_name}");
|
|
||||||
let guid = Some(Guid {
|
let guid = Some(Guid {
|
||||||
permalink: true,
|
permalink: true,
|
||||||
value: url.to_owned(),
|
value: url.to_owned(),
|
||||||
|
@ -464,7 +463,8 @@ fn build_item(
|
||||||
Ok(Item {
|
Ok(Item {
|
||||||
title: Some(format!("Reply from {creator_name}")),
|
title: Some(format!("Reply from {creator_name}")),
|
||||||
author: Some(format!(
|
author: Some(format!(
|
||||||
"/u/{creator_name} <a href=\"{author_url}\">(link)</a>"
|
"/u/{creator_name} <a href=\"{}\">(link)</a>",
|
||||||
|
format_args!("{protocol_and_hostname}/u/{creator_name}")
|
||||||
)),
|
)),
|
||||||
pub_date: Some(published.to_rfc2822()),
|
pub_date: Some(published.to_rfc2822()),
|
||||||
comments: Some(url.to_owned()),
|
comments: Some(url.to_owned()),
|
||||||
|
|
|
@ -65,10 +65,10 @@ anyhow = { workspace = true, optional = true }
|
||||||
reqwest-middleware = { workspace = true, optional = true }
|
reqwest-middleware = { workspace = true, optional = true }
|
||||||
strum = { workspace = true }
|
strum = { workspace = true }
|
||||||
futures = { workspace = true, optional = true }
|
futures = { workspace = true, optional = true }
|
||||||
diesel = { workspace = true, features = ["chrono"], optional = true }
|
diesel = { workspace = true, optional = true, features = ["chrono"] }
|
||||||
http = { workspace = true, optional = true }
|
http = { workspace = true, optional = true }
|
||||||
doku = { workspace = true, features = ["url-2"], optional = true }
|
doku = { workspace = true, features = ["url-2"], optional = true }
|
||||||
uuid = { workspace = true, features = ["serde", "v4"], optional = true }
|
uuid = { workspace = true, optional = true, features = ["v4"] }
|
||||||
rosetta-i18n = { workspace = true, optional = true }
|
rosetta-i18n = { workspace = true, optional = true }
|
||||||
tokio = { workspace = true, optional = true }
|
tokio = { workspace = true, optional = true }
|
||||||
urlencoding = { workspace = true, optional = true }
|
urlencoding = { workspace = true, optional = true }
|
||||||
|
@ -77,9 +77,8 @@ deser-hjson = { version = "2.2.4", optional = true }
|
||||||
smart-default = { version = "0.7.1", optional = true }
|
smart-default = { version = "0.7.1", optional = true }
|
||||||
lettre = { version = "0.11.10", default-features = false, features = [
|
lettre = { version = "0.11.10", default-features = false, features = [
|
||||||
"builder",
|
"builder",
|
||||||
"tokio1",
|
|
||||||
"tokio1-rustls-tls",
|
|
||||||
"smtp-transport",
|
"smtp-transport",
|
||||||
|
"tokio1-rustls-tls",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
markdown-it = { version = "0.6.1", optional = true }
|
markdown-it = { version = "0.6.1", optional = true }
|
||||||
ts-rs = { workspace = true, optional = true }
|
ts-rs = { workspace = true, optional = true }
|
||||||
|
|
|
@ -24,7 +24,8 @@ pub fn markdown_rewrite_image_links(mut src: String) -> (String, Vec<Url>) {
|
||||||
);
|
);
|
||||||
// restore custom emoji format
|
// restore custom emoji format
|
||||||
if let Some(extra) = extra {
|
if let Some(extra) = extra {
|
||||||
proxied = format!("{proxied} {extra}");
|
proxied.push(' ');
|
||||||
|
proxied.push_str(extra);
|
||||||
}
|
}
|
||||||
src.replace_range(start..end, &proxied);
|
src.replace_range(start..end, &proxied);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,10 @@ pub fn markdown_check_for_blocked_urls(text: &str, blocklist: &RegexSet) -> Lemm
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::utils::validation::check_urls_are_valid;
|
||||||
use image_links::markdown_rewrite_image_links;
|
use image_links::markdown_rewrite_image_links;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
use regex::escape;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_basic_markdown() {
|
fn test_basic_markdown() {
|
||||||
|
@ -191,9 +193,20 @@ mod tests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This replicates the logic when saving url blocklist patterns and querying them.
|
||||||
|
// Refer to lemmy_api_crud::site::update::update_site and
|
||||||
|
// lemmy_api_common::utils::get_url_blocklist().
|
||||||
|
fn create_url_blocklist_test_regex_set(patterns: Vec<&str>) -> LemmyResult<RegexSet> {
|
||||||
|
let url_blocklist = patterns.iter().map(|&s| s.to_string()).collect();
|
||||||
|
let valid_urls = check_urls_are_valid(&url_blocklist)?;
|
||||||
|
let regexes = valid_urls.iter().map(|p| format!(r"\b{}\b", escape(p)));
|
||||||
|
let set = RegexSet::new(regexes)?;
|
||||||
|
Ok(set)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_url_blocking() -> LemmyResult<()> {
|
fn test_url_blocking() -> LemmyResult<()> {
|
||||||
let set = RegexSet::new(vec![r"(https://)?example\.com/?"])?;
|
let set = create_url_blocklist_test_regex_set(vec!["example.com/"])?;
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
markdown_check_for_blocked_urls(&String::from("[](https://example.com)"), &set).is_err()
|
markdown_check_for_blocked_urls(&String::from("[](https://example.com)"), &set).is_err()
|
||||||
|
@ -221,37 +234,42 @@ mod tests {
|
||||||
)
|
)
|
||||||
.is_err());
|
.is_err());
|
||||||
|
|
||||||
let set = RegexSet::new(vec![r"(https://)?example\.com/spam\.jpg"])?;
|
let set = create_url_blocklist_test_regex_set(vec!["example.com/spam.jpg"])?;
|
||||||
assert!(markdown_check_for_blocked_urls(
|
assert!(markdown_check_for_blocked_urls("", &set).is_err());
|
||||||
&String::from(""),
|
assert!(markdown_check_for_blocked_urls("", &set).is_ok());
|
||||||
&set
|
// TODO: the following should not be matched, scunthorpe problem.
|
||||||
)
|
assert!(
|
||||||
.is_err());
|
markdown_check_for_blocked_urls("", &set).is_err()
|
||||||
|
);
|
||||||
|
|
||||||
let set = RegexSet::new(vec![
|
let set = create_url_blocklist_test_regex_set(vec![
|
||||||
r"(https://)?quo\.example\.com/?",
|
r"quo.example.com/",
|
||||||
r"(https://)?foo\.example\.com/?",
|
r"foo.example.com/",
|
||||||
r"(https://)?bar\.example\.com/?",
|
r"bar.example.com/",
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
assert!(
|
assert!(markdown_check_for_blocked_urls("https://baz.example.com", &set).is_ok());
|
||||||
markdown_check_for_blocked_urls(&String::from("https://baz.example.com"), &set).is_ok()
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(
|
assert!(markdown_check_for_blocked_urls("https://bar.example.com", &set).is_err());
|
||||||
markdown_check_for_blocked_urls(&String::from("https://bar.example.com"), &set).is_err()
|
|
||||||
);
|
|
||||||
|
|
||||||
let set = RegexSet::new(vec![r"(https://)?example\.com/banned_page"])?;
|
let set = create_url_blocklist_test_regex_set(vec!["example.com/banned_page"])?;
|
||||||
|
|
||||||
assert!(
|
assert!(markdown_check_for_blocked_urls("https://example.com/page", &set).is_ok());
|
||||||
markdown_check_for_blocked_urls(&String::from("https://example.com/page"), &set).is_ok()
|
|
||||||
);
|
|
||||||
|
|
||||||
let set = RegexSet::new(vec![r"(https://)?ex\.mple\.com/?"])?;
|
let set = create_url_blocklist_test_regex_set(vec!["ex.mple.com/"])?;
|
||||||
|
|
||||||
assert!(markdown_check_for_blocked_urls("example.com", &set).is_ok());
|
assert!(markdown_check_for_blocked_urls("example.com", &set).is_ok());
|
||||||
|
|
||||||
|
let set = create_url_blocklist_test_regex_set(vec!["rt.com/"])?;
|
||||||
|
|
||||||
|
assert!(markdown_check_for_blocked_urls("deviantart.com", &set).is_ok());
|
||||||
|
assert!(markdown_check_for_blocked_urls("art.com.example.com", &set).is_ok());
|
||||||
|
assert!(markdown_check_for_blocked_urls("https://rt.com/abc", &set).is_err());
|
||||||
|
assert!(markdown_check_for_blocked_urls("go to rt.com.", &set).is_err());
|
||||||
|
assert!(markdown_check_for_blocked_urls("check out rt.computer", &set).is_ok());
|
||||||
|
// TODO: the following should not be matched, scunthorpe problem.
|
||||||
|
assert!(markdown_check_for_blocked_urls("rt.com.example.com", &set).is_err());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# syntax=docker/dockerfile:1.10
|
# syntax=docker/dockerfile:1.12
|
||||||
ARG RUST_VERSION=1.81
|
ARG RUST_VERSION=1.81
|
||||||
ARG CARGO_BUILD_FEATURES=default
|
ARG CARGO_BUILD_FEATURES=default
|
||||||
ARG RUST_RELEASE_MODE=debug
|
ARG RUST_RELEASE_MODE=debug
|
||||||
|
|
|
@ -53,7 +53,7 @@ services:
|
||||||
|
|
||||||
lemmy-ui:
|
lemmy-ui:
|
||||||
# use "image" to pull down an already compiled lemmy-ui. make sure to comment out "build".
|
# use "image" to pull down an already compiled lemmy-ui. make sure to comment out "build".
|
||||||
image: dessalines/lemmy-ui:0.19.6
|
image: dessalines/lemmy-ui:0.19.8
|
||||||
# platform: linux/x86_64 # no arm64 support. uncomment platform if using m1.
|
# platform: linux/x86_64 # no arm64 support. uncomment platform if using m1.
|
||||||
# use "build" to build your local lemmy ui image for development. make sure to comment out "image".
|
# use "build" to build your local lemmy ui image for development. make sure to comment out "image".
|
||||||
# run: docker compose up --build
|
# run: docker compose up --build
|
||||||
|
|
|
@ -12,8 +12,6 @@ CREATE TABLE person_content_combined (
|
||||||
|
|
||||||
CREATE INDEX idx_person_content_combined_published ON person_content_combined (published DESC, id DESC);
|
CREATE INDEX idx_person_content_combined_published ON person_content_combined (published DESC, id DESC);
|
||||||
|
|
||||||
CREATE INDEX idx_person_content_combined_published_asc ON person_content_combined (reverse_timestamp_sort (published) DESC, id DESC);
|
|
||||||
|
|
||||||
-- Updating the history
|
-- Updating the history
|
||||||
INSERT INTO person_content_combined (published, post_id, comment_id)
|
INSERT INTO person_content_combined (published, post_id, comment_id)
|
||||||
SELECT
|
SELECT
|
||||||
|
@ -33,7 +31,7 @@ FROM
|
||||||
-- This one is special, because you use the saved date, not the ordinary published
|
-- This one is special, because you use the saved date, not the ordinary published
|
||||||
CREATE TABLE person_saved_combined (
|
CREATE TABLE person_saved_combined (
|
||||||
id serial PRIMARY KEY,
|
id serial PRIMARY KEY,
|
||||||
published timestamptz NOT NULL,
|
saved timestamptz NOT NULL,
|
||||||
person_id int NOT NULL REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE,
|
person_id int NOT NULL REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
post_id int UNIQUE REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE,
|
post_id int UNIQUE REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
comment_id int UNIQUE REFERENCES COMMENT ON UPDATE CASCADE ON DELETE CASCADE,
|
comment_id int UNIQUE REFERENCES COMMENT ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
|
@ -41,14 +39,12 @@ CREATE TABLE person_saved_combined (
|
||||||
CHECK (num_nonnulls (post_id, comment_id) = 1)
|
CHECK (num_nonnulls (post_id, comment_id) = 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_person_saved_combined_published ON person_saved_combined (published DESC, id DESC);
|
CREATE INDEX idx_person_saved_combined_published ON person_saved_combined (saved DESC, id DESC);
|
||||||
|
|
||||||
CREATE INDEX idx_person_saved_combined_published_asc ON person_saved_combined (reverse_timestamp_sort (published) DESC, id DESC);
|
|
||||||
|
|
||||||
CREATE INDEX idx_person_saved_combined ON person_saved_combined (person_id);
|
CREATE INDEX idx_person_saved_combined ON person_saved_combined (person_id);
|
||||||
|
|
||||||
-- Updating the history
|
-- Updating the history
|
||||||
INSERT INTO person_saved_combined (published, person_id, post_id, comment_id)
|
INSERT INTO person_saved_combined (saved, person_id, post_id, comment_id)
|
||||||
SELECT
|
SELECT
|
||||||
saved,
|
saved,
|
||||||
person_id,
|
person_id,
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
DROP TABLE post_tag;
|
||||||
|
|
||||||
|
DROP TABLE tag;
|
||||||
|
|
23
migrations/2024-12-17-144959_community-post-tags/up.sql
Normal file
23
migrations/2024-12-17-144959_community-post-tags/up.sql
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
-- a tag is a federatable object that gives additional context to another object, which can be displayed and filtered on
|
||||||
|
-- currently, we only have community post tags, which is a tag that is created by post authors as well as mods of a community,
|
||||||
|
-- to categorize a post. in the future we may add more tag types, depending on the requirements,
|
||||||
|
-- this will lead to either expansion of this table (community_id optional, addition of tag_type enum)
|
||||||
|
-- or split of this table / creation of new tables.
|
||||||
|
CREATE TABLE tag (
|
||||||
|
id serial PRIMARY KEY,
|
||||||
|
ap_id text NOT NULL UNIQUE,
|
||||||
|
name text NOT NULL,
|
||||||
|
community_id int NOT NULL REFERENCES community (id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
|
published timestamptz NOT NULL DEFAULT now(),
|
||||||
|
updated timestamptz,
|
||||||
|
deleted boolean NOT NULL DEFAULT FALSE
|
||||||
|
);
|
||||||
|
|
||||||
|
-- an association between a post and a tag. created/updated by the post author or mods of a community
|
||||||
|
CREATE TABLE post_tag (
|
||||||
|
post_id int NOT NULL REFERENCES post (id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
|
tag_id int NOT NULL REFERENCES tag (id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
|
published timestamptz NOT NULL DEFAULT now(),
|
||||||
|
PRIMARY KEY (post_id, tag_id)
|
||||||
|
);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
SELECT
|
||||||
|
1;
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
SELECT
|
||||||
|
1;
|
||||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -370,3 +370,18 @@ fn cors_config(settings: &Settings) -> Cors {
|
||||||
_ => cors_default,
|
_ => cors_default,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod tests {
|
||||||
|
use activitypub_federation::config::Data;
|
||||||
|
use lemmy_api_common::context::LemmyContext;
|
||||||
|
use std::env::set_current_dir;
|
||||||
|
|
||||||
|
pub async fn test_context() -> Data<LemmyContext> {
|
||||||
|
// hack, necessary so that config file can be loaded from hardcoded, relative path.
|
||||||
|
// Ignore errors as this gets called once for every test (so changing dir again would fail).
|
||||||
|
set_current_dir("crates/utils").ok();
|
||||||
|
|
||||||
|
LemmyContext::init_test_context().await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -40,16 +40,19 @@ use lemmy_db_schema::{
|
||||||
utils::{find_action, functions::coalesce, get_conn, now, DbPool, DELETED_REPLACEMENT_TEXT},
|
utils::{find_action, functions::coalesce, get_conn, now, DbPool, DELETED_REPLACEMENT_TEXT},
|
||||||
};
|
};
|
||||||
use lemmy_routes::nodeinfo::{NodeInfo, NodeInfoWellKnown};
|
use lemmy_routes::nodeinfo::{NodeInfo, NodeInfoWellKnown};
|
||||||
use lemmy_utils::error::LemmyResult;
|
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
||||||
use reqwest_middleware::ClientWithMiddleware;
|
use reqwest_middleware::ClientWithMiddleware;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tracing::{error, info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
/// Schedules various cleanup tasks for lemmy in a background thread
|
/// Schedules various cleanup tasks for lemmy in a background thread
|
||||||
pub async fn setup(context: Data<LemmyContext>) -> LemmyResult<()> {
|
pub async fn setup(context: Data<LemmyContext>) -> LemmyResult<()> {
|
||||||
// Setup the connections
|
// Setup the connections
|
||||||
let mut scheduler = AsyncScheduler::new();
|
let mut scheduler = AsyncScheduler::new();
|
||||||
startup_jobs(&mut context.pool()).await;
|
startup_jobs(&mut context.pool())
|
||||||
|
.await
|
||||||
|
.inspect_err(|e| warn!("Failed to run startup tasks: {e}"))
|
||||||
|
.ok();
|
||||||
|
|
||||||
let context_1 = context.clone();
|
let context_1 = context.clone();
|
||||||
// Update active counts expired bans and unpublished posts every hour
|
// Update active counts expired bans and unpublished posts every hour
|
||||||
|
@ -57,9 +60,18 @@ pub async fn setup(context: Data<LemmyContext>) -> LemmyResult<()> {
|
||||||
let context = context_1.clone();
|
let context = context_1.clone();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
active_counts(&mut context.pool()).await;
|
active_counts(&mut context.pool())
|
||||||
update_banned_when_expired(&mut context.pool()).await;
|
.await
|
||||||
delete_instance_block_when_expired(&mut context.pool()).await;
|
.inspect_err(|e| warn!("Failed to update active counts: {e}"))
|
||||||
|
.ok();
|
||||||
|
update_banned_when_expired(&mut context.pool())
|
||||||
|
.await
|
||||||
|
.inspect_err(|e| warn!("Failed to update expired bans: {e}"))
|
||||||
|
.ok();
|
||||||
|
delete_instance_block_when_expired(&mut context.pool())
|
||||||
|
.await
|
||||||
|
.inspect_err(|e| warn!("Failed to delete expired instance bans: {e}"))
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -69,9 +81,18 @@ pub async fn setup(context: Data<LemmyContext>) -> LemmyResult<()> {
|
||||||
let context = context_1.reset_request_count();
|
let context = context_1.reset_request_count();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
update_hot_ranks(&mut context.pool()).await;
|
update_hot_ranks(&mut context.pool())
|
||||||
delete_expired_captcha_answers(&mut context.pool()).await;
|
.await
|
||||||
publish_scheduled_posts(&context).await;
|
.inspect_err(|e| warn!("Failed to update hot ranks: {e}"))
|
||||||
|
.ok();
|
||||||
|
delete_expired_captcha_answers(&mut context.pool())
|
||||||
|
.await
|
||||||
|
.inspect_err(|e| warn!("Failed to delete expired captcha answers: {e}"))
|
||||||
|
.ok();
|
||||||
|
publish_scheduled_posts(&context)
|
||||||
|
.await
|
||||||
|
.inspect_err(|e| warn!("Failed to publish scheduled posts: {e}"))
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -81,7 +102,10 @@ pub async fn setup(context: Data<LemmyContext>) -> LemmyResult<()> {
|
||||||
let context = context_1.clone();
|
let context = context_1.clone();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
clear_old_activities(&mut context.pool()).await;
|
clear_old_activities(&mut context.pool())
|
||||||
|
.await
|
||||||
|
.inspect_err(|e| warn!("Failed to clear old activities: {e}"))
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -94,8 +118,14 @@ pub async fn setup(context: Data<LemmyContext>) -> LemmyResult<()> {
|
||||||
let context = context_1.clone();
|
let context = context_1.clone();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
overwrite_deleted_posts_and_comments(&mut context.pool()).await;
|
overwrite_deleted_posts_and_comments(&mut context.pool())
|
||||||
delete_old_denied_users(&mut context.pool()).await;
|
.await
|
||||||
|
.inspect_err(|e| warn!("Failed to overwrite deleted posts/comments: {e}"))
|
||||||
|
.ok();
|
||||||
|
delete_old_denied_users(&mut context.pool())
|
||||||
|
.await
|
||||||
|
.inspect_err(|e| warn!("Failed to delete old denied users: {e}"))
|
||||||
|
.ok();
|
||||||
update_instance_software(&mut context.pool(), context.client())
|
update_instance_software(&mut context.pool(), context.client())
|
||||||
.await
|
.await
|
||||||
.inspect_err(|e| warn!("Failed to update instance software: {e}"))
|
.inspect_err(|e| warn!("Failed to update instance software: {e}"))
|
||||||
|
@ -111,26 +141,25 @@ pub async fn setup(context: Data<LemmyContext>) -> LemmyResult<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run these on server startup
|
/// Run these on server startup
|
||||||
async fn startup_jobs(pool: &mut DbPool<'_>) {
|
async fn startup_jobs(pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||||
active_counts(pool).await;
|
active_counts(pool).await?;
|
||||||
update_hot_ranks(pool).await;
|
update_hot_ranks(pool).await?;
|
||||||
update_banned_when_expired(pool).await;
|
update_banned_when_expired(pool).await?;
|
||||||
delete_instance_block_when_expired(pool).await;
|
delete_instance_block_when_expired(pool).await?;
|
||||||
clear_old_activities(pool).await;
|
clear_old_activities(pool).await?;
|
||||||
overwrite_deleted_posts_and_comments(pool).await;
|
overwrite_deleted_posts_and_comments(pool).await?;
|
||||||
delete_old_denied_users(pool).await;
|
delete_old_denied_users(pool).await?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the hot_rank columns for the aggregates tables
|
/// Update the hot_rank columns for the aggregates tables
|
||||||
/// Runs in batches until all necessary rows are updated once
|
/// Runs in batches until all necessary rows are updated once
|
||||||
async fn update_hot_ranks(pool: &mut DbPool<'_>) {
|
async fn update_hot_ranks(pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||||
info!("Updating hot ranks for all history...");
|
info!("Updating hot ranks for all history...");
|
||||||
|
|
||||||
let conn = get_conn(pool).await;
|
let mut conn = get_conn(pool).await?;
|
||||||
|
|
||||||
match conn {
|
process_post_aggregates_ranks_in_batches(&mut conn).await?;
|
||||||
Ok(mut conn) => {
|
|
||||||
process_post_aggregates_ranks_in_batches(&mut conn).await;
|
|
||||||
|
|
||||||
process_ranks_in_batches(
|
process_ranks_in_batches(
|
||||||
&mut conn,
|
&mut conn,
|
||||||
|
@ -138,7 +167,7 @@ async fn update_hot_ranks(pool: &mut DbPool<'_>) {
|
||||||
"a.hot_rank != 0",
|
"a.hot_rank != 0",
|
||||||
"SET hot_rank = r.hot_rank(a.score, a.published)",
|
"SET hot_rank = r.hot_rank(a.score, a.published)",
|
||||||
)
|
)
|
||||||
.await;
|
.await?;
|
||||||
|
|
||||||
process_ranks_in_batches(
|
process_ranks_in_batches(
|
||||||
&mut conn,
|
&mut conn,
|
||||||
|
@ -146,14 +175,10 @@ async fn update_hot_ranks(pool: &mut DbPool<'_>) {
|
||||||
"a.hot_rank != 0",
|
"a.hot_rank != 0",
|
||||||
"SET hot_rank = r.hot_rank(a.subscribers, a.published)",
|
"SET hot_rank = r.hot_rank(a.subscribers, a.published)",
|
||||||
)
|
)
|
||||||
.await;
|
.await?;
|
||||||
|
|
||||||
info!("Finished hot ranks update!");
|
info!("Finished hot ranks update!");
|
||||||
}
|
Ok(())
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to get connection from pool: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(QueryableByName)]
|
#[derive(QueryableByName)]
|
||||||
|
@ -171,7 +196,7 @@ async fn process_ranks_in_batches(
|
||||||
table_name: &str,
|
table_name: &str,
|
||||||
where_clause: &str,
|
where_clause: &str,
|
||||||
set_clause: &str,
|
set_clause: &str,
|
||||||
) {
|
) -> LemmyResult<()> {
|
||||||
let process_start_time: DateTime<Utc> = Utc.timestamp_opt(0, 0).single().unwrap_or_default();
|
let process_start_time: DateTime<Utc> = Utc.timestamp_opt(0, 0).single().unwrap_or_default();
|
||||||
|
|
||||||
let update_batch_size = 1000; // Bigger batches than this tend to cause seq scans
|
let update_batch_size = 1000; // Bigger batches than this tend to cause seq scans
|
||||||
|
@ -180,7 +205,7 @@ async fn process_ranks_in_batches(
|
||||||
while let Some(previous_batch_last_published) = previous_batch_result {
|
while let Some(previous_batch_last_published) = previous_batch_result {
|
||||||
// Raw `sql_query` is used as a performance optimization - Diesel does not support doing this
|
// Raw `sql_query` is used as a performance optimization - Diesel does not support doing this
|
||||||
// in a single query (neither as a CTE, nor using a subquery)
|
// in a single query (neither as a CTE, nor using a subquery)
|
||||||
let result = sql_query(format!(
|
let updated_rows = sql_query(format!(
|
||||||
r#"WITH batch AS (SELECT a.{id_column}
|
r#"WITH batch AS (SELECT a.{id_column}
|
||||||
FROM {aggregates_table} a
|
FROM {aggregates_table} a
|
||||||
WHERE a.published > $1 AND ({where_clause})
|
WHERE a.published > $1 AND ({where_clause})
|
||||||
|
@ -190,43 +215,37 @@ async fn process_ranks_in_batches(
|
||||||
UPDATE {aggregates_table} a {set_clause}
|
UPDATE {aggregates_table} a {set_clause}
|
||||||
FROM batch WHERE a.{id_column} = batch.{id_column} RETURNING a.published;
|
FROM batch WHERE a.{id_column} = batch.{id_column} RETURNING a.published;
|
||||||
"#,
|
"#,
|
||||||
id_column = format!("{table_name}_id"),
|
id_column = format_args!("{table_name}_id"),
|
||||||
aggregates_table = format!("{table_name}_aggregates"),
|
aggregates_table = format_args!("{table_name}_aggregates"),
|
||||||
set_clause = set_clause,
|
|
||||||
where_clause = where_clause
|
|
||||||
))
|
))
|
||||||
.bind::<Timestamptz, _>(previous_batch_last_published)
|
.bind::<Timestamptz, _>(previous_batch_last_published)
|
||||||
.bind::<Integer, _>(update_batch_size)
|
.bind::<Integer, _>(update_batch_size)
|
||||||
.get_results::<HotRanksUpdateResult>(conn)
|
.get_results::<HotRanksUpdateResult>(conn)
|
||||||
.await;
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
LemmyErrorType::Unknown(format!("Failed to update {} hot_ranks: {}", table_name, e))
|
||||||
|
})?;
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(updated_rows) => {
|
|
||||||
processed_rows_count += updated_rows.len();
|
processed_rows_count += updated_rows.len();
|
||||||
previous_batch_result = updated_rows.last().map(|row| row.published);
|
previous_batch_result = updated_rows.last().map(|row| row.published);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to update {} hot_ranks: {}", table_name, e);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
info!(
|
info!(
|
||||||
"Finished process_hot_ranks_in_batches execution for {} (processed {} rows)",
|
"Finished process_hot_ranks_in_batches execution for {} (processed {} rows)",
|
||||||
table_name, processed_rows_count
|
table_name, processed_rows_count
|
||||||
);
|
);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Post aggregates is a special case, since it needs to join to the community_aggregates
|
/// Post aggregates is a special case, since it needs to join to the community_aggregates
|
||||||
/// table, to get the active monthly user counts.
|
/// table, to get the active monthly user counts.
|
||||||
async fn process_post_aggregates_ranks_in_batches(conn: &mut AsyncPgConnection) {
|
async fn process_post_aggregates_ranks_in_batches(conn: &mut AsyncPgConnection) -> LemmyResult<()> {
|
||||||
let process_start_time: DateTime<Utc> = Utc.timestamp_opt(0, 0).single().unwrap_or_default();
|
let process_start_time: DateTime<Utc> = Utc.timestamp_opt(0, 0).single().unwrap_or_default();
|
||||||
|
|
||||||
let update_batch_size = 1000; // Bigger batches than this tend to cause seq scans
|
let update_batch_size = 1000; // Bigger batches than this tend to cause seq scans
|
||||||
let mut processed_rows_count = 0;
|
let mut processed_rows_count = 0;
|
||||||
let mut previous_batch_result = Some(process_start_time);
|
let mut previous_batch_result = Some(process_start_time);
|
||||||
while let Some(previous_batch_last_published) = previous_batch_result {
|
while let Some(previous_batch_last_published) = previous_batch_result {
|
||||||
let result = sql_query(
|
let updated_rows = sql_query(
|
||||||
r#"WITH batch AS (SELECT pa.post_id
|
r#"WITH batch AS (SELECT pa.post_id
|
||||||
FROM post_aggregates pa
|
FROM post_aggregates pa
|
||||||
WHERE pa.published > $1
|
WHERE pa.published > $1
|
||||||
|
@ -245,96 +264,62 @@ async fn process_post_aggregates_ranks_in_batches(conn: &mut AsyncPgConnection)
|
||||||
.bind::<Timestamptz, _>(previous_batch_last_published)
|
.bind::<Timestamptz, _>(previous_batch_last_published)
|
||||||
.bind::<Integer, _>(update_batch_size)
|
.bind::<Integer, _>(update_batch_size)
|
||||||
.get_results::<HotRanksUpdateResult>(conn)
|
.get_results::<HotRanksUpdateResult>(conn)
|
||||||
.await;
|
.await.map_err(|e| LemmyErrorType::Unknown(format!("Failed to update {} hot_ranks: {}", "post_aggregates", e)))?;
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(updated_rows) => {
|
|
||||||
processed_rows_count += updated_rows.len();
|
processed_rows_count += updated_rows.len();
|
||||||
previous_batch_result = updated_rows.last().map(|row| row.published);
|
previous_batch_result = updated_rows.last().map(|row| row.published);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to update {} hot_ranks: {}", "post_aggregates", e);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
info!(
|
info!(
|
||||||
"Finished process_hot_ranks_in_batches execution for {} (processed {} rows)",
|
"Finished process_hot_ranks_in_batches execution for {} (processed {} rows)",
|
||||||
"post_aggregates", processed_rows_count
|
"post_aggregates", processed_rows_count
|
||||||
);
|
);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete_expired_captcha_answers(pool: &mut DbPool<'_>) {
|
async fn delete_expired_captcha_answers(pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||||
let conn = get_conn(pool).await;
|
let mut conn = get_conn(pool).await?;
|
||||||
|
|
||||||
match conn {
|
|
||||||
Ok(mut conn) => {
|
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
captcha_answer::table
|
captcha_answer::table.filter(captcha_answer::published.lt(now() - IntervalDsl::minutes(10))),
|
||||||
.filter(captcha_answer::published.lt(now() - IntervalDsl::minutes(10))),
|
|
||||||
)
|
)
|
||||||
.execute(&mut conn)
|
.execute(&mut conn)
|
||||||
.await
|
.await?;
|
||||||
.map(|_| {
|
|
||||||
info!("Done.");
|
info!("Done.");
|
||||||
})
|
|
||||||
.inspect_err(|e| error!("Failed to clear old captcha answers: {e}"))
|
Ok(())
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to get connection from pool: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear old activities (this table gets very large)
|
/// Clear old activities (this table gets very large)
|
||||||
async fn clear_old_activities(pool: &mut DbPool<'_>) {
|
async fn clear_old_activities(pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||||
info!("Clearing old activities...");
|
info!("Clearing old activities...");
|
||||||
let conn = get_conn(pool).await;
|
let mut conn = get_conn(pool).await?;
|
||||||
|
|
||||||
match conn {
|
|
||||||
Ok(mut conn) => {
|
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
sent_activity::table.filter(sent_activity::published.lt(now() - IntervalDsl::days(7))),
|
sent_activity::table.filter(sent_activity::published.lt(now() - IntervalDsl::days(7))),
|
||||||
)
|
)
|
||||||
.execute(&mut conn)
|
.execute(&mut conn)
|
||||||
.await
|
.await?;
|
||||||
.inspect_err(|e| error!("Failed to clear old sent activities: {e}"))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
received_activity::table
|
received_activity::table.filter(received_activity::published.lt(now() - IntervalDsl::days(7))),
|
||||||
.filter(received_activity::published.lt(now() - IntervalDsl::days(7))),
|
|
||||||
)
|
)
|
||||||
.execute(&mut conn)
|
.execute(&mut conn)
|
||||||
.await
|
.await?;
|
||||||
.map(|_| info!("Done."))
|
info!("Done.");
|
||||||
.inspect_err(|e| error!("Failed to clear old received activities: {e}"))
|
Ok(())
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to get connection from pool: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete_old_denied_users(pool: &mut DbPool<'_>) {
|
async fn delete_old_denied_users(pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||||
LocalUser::delete_old_denied_local_users(pool)
|
LocalUser::delete_old_denied_local_users(pool).await?;
|
||||||
.await
|
|
||||||
.map(|_| {
|
|
||||||
info!("Done.");
|
info!("Done.");
|
||||||
})
|
Ok(())
|
||||||
.inspect_err(|e| error!("Failed to deleted old denied users: {e}"))
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// overwrite posts and comments 30d after deletion
|
/// overwrite posts and comments 30d after deletion
|
||||||
async fn overwrite_deleted_posts_and_comments(pool: &mut DbPool<'_>) {
|
async fn overwrite_deleted_posts_and_comments(pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||||
info!("Overwriting deleted posts...");
|
info!("Overwriting deleted posts...");
|
||||||
let conn = get_conn(pool).await;
|
let mut conn = get_conn(pool).await?;
|
||||||
|
|
||||||
match conn {
|
|
||||||
Ok(mut conn) => {
|
|
||||||
diesel::update(
|
diesel::update(
|
||||||
post::table
|
post::table
|
||||||
.filter(post::deleted.eq(true))
|
.filter(post::deleted.eq(true))
|
||||||
|
@ -346,12 +331,7 @@ async fn overwrite_deleted_posts_and_comments(pool: &mut DbPool<'_>) {
|
||||||
post::name.eq(DELETED_REPLACEMENT_TEXT),
|
post::name.eq(DELETED_REPLACEMENT_TEXT),
|
||||||
))
|
))
|
||||||
.execute(&mut conn)
|
.execute(&mut conn)
|
||||||
.await
|
.await?;
|
||||||
.map(|_| {
|
|
||||||
info!("Done.");
|
|
||||||
})
|
|
||||||
.inspect_err(|e| error!("Failed to overwrite deleted posts: {e}"))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
info!("Overwriting deleted comments...");
|
info!("Overwriting deleted comments...");
|
||||||
diesel::update(
|
diesel::update(
|
||||||
|
@ -362,27 +342,17 @@ async fn overwrite_deleted_posts_and_comments(pool: &mut DbPool<'_>) {
|
||||||
)
|
)
|
||||||
.set(comment::content.eq(DELETED_REPLACEMENT_TEXT))
|
.set(comment::content.eq(DELETED_REPLACEMENT_TEXT))
|
||||||
.execute(&mut conn)
|
.execute(&mut conn)
|
||||||
.await
|
.await?;
|
||||||
.map(|_| {
|
|
||||||
info!("Done.");
|
info!("Done.");
|
||||||
})
|
Ok(())
|
||||||
.inspect_err(|e| error!("Failed to overwrite deleted comments: {e}"))
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to get connection from pool: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Re-calculate the site and community active counts every 12 hours
|
/// Re-calculate the site and community active counts every 12 hours
|
||||||
async fn active_counts(pool: &mut DbPool<'_>) {
|
async fn active_counts(pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||||
info!("Updating active site and community aggregates ...");
|
info!("Updating active site and community aggregates ...");
|
||||||
|
|
||||||
let conn = get_conn(pool).await;
|
let mut conn = get_conn(pool).await?;
|
||||||
|
|
||||||
match conn {
|
|
||||||
Ok(mut conn) => {
|
|
||||||
let intervals = vec![
|
let intervals = vec![
|
||||||
("1 day", "day"),
|
("1 day", "day"),
|
||||||
("1 week", "week"),
|
("1 week", "week"),
|
||||||
|
@ -395,35 +365,21 @@ async fn active_counts(pool: &mut DbPool<'_>) {
|
||||||
"update site_aggregates set users_active_{} = (select * from r.site_aggregates_activity('{}')) where site_id = 1",
|
"update site_aggregates set users_active_{} = (select * from r.site_aggregates_activity('{}')) where site_id = 1",
|
||||||
abbr, full_form
|
abbr, full_form
|
||||||
);
|
);
|
||||||
sql_query(update_site_stmt)
|
sql_query(update_site_stmt).execute(&mut conn).await?;
|
||||||
.execute(&mut conn)
|
|
||||||
.await
|
|
||||||
.inspect_err(|e| error!("Failed to update site stats: {e}"))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
let update_community_stmt = format!("update community_aggregates ca set users_active_{} = mv.count_ from r.community_aggregates_activity('{}') mv where ca.community_id = mv.community_id_", abbr, full_form);
|
let update_community_stmt = format!("update community_aggregates ca set users_active_{} = mv.count_ from r.community_aggregates_activity('{}') mv where ca.community_id = mv.community_id_", abbr, full_form);
|
||||||
sql_query(update_community_stmt)
|
sql_query(update_community_stmt).execute(&mut conn).await?;
|
||||||
.execute(&mut conn)
|
|
||||||
.await
|
|
||||||
.inspect_err(|e| error!("Failed to update community stats: {e}"))
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Done.");
|
info!("Done.");
|
||||||
}
|
Ok(())
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to get connection from pool: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set banned to false after ban expires
|
/// Set banned to false after ban expires
|
||||||
async fn update_banned_when_expired(pool: &mut DbPool<'_>) {
|
async fn update_banned_when_expired(pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||||
info!("Updating banned column if it expires ...");
|
info!("Updating banned column if it expires ...");
|
||||||
let conn = get_conn(pool).await;
|
let mut conn = get_conn(pool).await?;
|
||||||
|
|
||||||
match conn {
|
|
||||||
Ok(mut conn) => {
|
|
||||||
diesel::update(
|
diesel::update(
|
||||||
person::table
|
person::table
|
||||||
.filter(person::banned.eq(true))
|
.filter(person::banned.eq(true))
|
||||||
|
@ -431,52 +387,34 @@ async fn update_banned_when_expired(pool: &mut DbPool<'_>) {
|
||||||
)
|
)
|
||||||
.set(person::banned.eq(false))
|
.set(person::banned.eq(false))
|
||||||
.execute(&mut conn)
|
.execute(&mut conn)
|
||||||
.await
|
.await?;
|
||||||
.inspect_err(|e| error!("Failed to update person.banned when expires: {e}"))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
community_actions::table.filter(community_actions::ban_expires.lt(now().nullable())),
|
community_actions::table.filter(community_actions::ban_expires.lt(now().nullable())),
|
||||||
)
|
)
|
||||||
.execute(&mut conn)
|
.execute(&mut conn)
|
||||||
.await
|
.await?;
|
||||||
.inspect_err(|e| error!("Failed to remove community_ban expired rows: {e}"))
|
Ok(())
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to get connection from pool: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set banned to false after ban expires
|
/// Set banned to false after ban expires
|
||||||
async fn delete_instance_block_when_expired(pool: &mut DbPool<'_>) {
|
async fn delete_instance_block_when_expired(pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||||
info!("Delete instance blocks when expired ...");
|
info!("Delete instance blocks when expired ...");
|
||||||
let conn = get_conn(pool).await;
|
let mut conn = get_conn(pool).await?;
|
||||||
|
|
||||||
match conn {
|
|
||||||
Ok(mut conn) => {
|
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
federation_blocklist::table.filter(federation_blocklist::expires.lt(now().nullable())),
|
federation_blocklist::table.filter(federation_blocklist::expires.lt(now().nullable())),
|
||||||
)
|
)
|
||||||
.execute(&mut conn)
|
.execute(&mut conn)
|
||||||
.await
|
.await?;
|
||||||
.inspect_err(|e| error!("Failed to remove federation_blocklist expired rows: {e}"))
|
Ok(())
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to get connection from pool: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find all unpublished posts with scheduled date in the future, and publish them.
|
/// Find all unpublished posts with scheduled date in the future, and publish them.
|
||||||
async fn publish_scheduled_posts(context: &Data<LemmyContext>) {
|
async fn publish_scheduled_posts(context: &Data<LemmyContext>) -> LemmyResult<()> {
|
||||||
let pool = &mut context.pool();
|
let pool = &mut context.pool();
|
||||||
let conn = get_conn(pool).await;
|
let mut conn = get_conn(pool).await?;
|
||||||
|
|
||||||
match conn {
|
|
||||||
Ok(mut conn) => {
|
|
||||||
let scheduled_posts: Vec<_> = post::table
|
let scheduled_posts: Vec<_> = post::table
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
@ -494,10 +432,7 @@ async fn publish_scheduled_posts(context: &Data<LemmyContext>) {
|
||||||
))))
|
))))
|
||||||
.select((post::all_columns, community::all_columns))
|
.select((post::all_columns, community::all_columns))
|
||||||
.get_results::<(Post, Community)>(&mut conn)
|
.get_results::<(Post, Community)>(&mut conn)
|
||||||
.await
|
.await?;
|
||||||
.inspect_err(|e| error!("Failed to read unpublished posts: {e}"))
|
|
||||||
.ok()
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
for (post, community) in scheduled_posts {
|
for (post, community) in scheduled_posts {
|
||||||
// mark post as published in db
|
// mark post as published in db
|
||||||
|
@ -505,23 +440,14 @@ async fn publish_scheduled_posts(context: &Data<LemmyContext>) {
|
||||||
scheduled_publish_time: Some(None),
|
scheduled_publish_time: Some(None),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
Post::update(&mut context.pool(), post.id, &form)
|
Post::update(&mut context.pool(), post.id, &form).await?;
|
||||||
.await
|
|
||||||
.inspect_err(|e| error!("Failed update scheduled post: {e}"))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
// send out post via federation and webmention
|
// send out post via federation and webmention
|
||||||
let send_activity = SendActivityData::CreatePost(post.clone());
|
let send_activity = SendActivityData::CreatePost(post.clone());
|
||||||
ActivityChannel::submit_activity(send_activity, context)
|
ActivityChannel::submit_activity(send_activity, context)?;
|
||||||
.inspect_err(|e| error!("Failed federate scheduled post: {e}"))
|
|
||||||
.ok();
|
|
||||||
send_webmention(post, community);
|
send_webmention(post, community);
|
||||||
}
|
}
|
||||||
}
|
Ok(())
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to get connection from pool: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the instance software and version.
|
/// Updates the instance software and version.
|
||||||
|
@ -535,10 +461,8 @@ async fn update_instance_software(
|
||||||
client: &ClientWithMiddleware,
|
client: &ClientWithMiddleware,
|
||||||
) -> LemmyResult<()> {
|
) -> LemmyResult<()> {
|
||||||
info!("Updating instances software and versions...");
|
info!("Updating instances software and versions...");
|
||||||
let conn = get_conn(pool).await;
|
let mut conn = get_conn(pool).await?;
|
||||||
|
|
||||||
match conn {
|
|
||||||
Ok(mut conn) => {
|
|
||||||
let instances = instance::table.get_results::<Instance>(&mut conn).await?;
|
let instances = instance::table.get_results::<Instance>(&mut conn).await?;
|
||||||
|
|
||||||
for instance in instances {
|
for instance in instances {
|
||||||
|
@ -547,11 +471,6 @@ async fn update_instance_software(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info!("Finished updating instances software and versions...");
|
info!("Finished updating instances software and versions...");
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to get connection from pool: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,7 +542,8 @@ async fn build_update_instance_form(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::scheduled_tasks::build_update_instance_form;
|
use super::*;
|
||||||
|
use crate::{scheduled_tasks::build_update_instance_form, tests::test_context};
|
||||||
use lemmy_api_common::request::client_builder;
|
use lemmy_api_common::request::client_builder;
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
error::{LemmyErrorType, LemmyResult},
|
error::{LemmyErrorType, LemmyResult},
|
||||||
|
@ -634,7 +554,6 @@ mod tests {
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
|
||||||
async fn test_nodeinfo_lemmy_ml() -> LemmyResult<()> {
|
async fn test_nodeinfo_lemmy_ml() -> LemmyResult<()> {
|
||||||
let client = ClientBuilder::new(client_builder(&Settings::default()).build()?).build();
|
let client = ClientBuilder::new(client_builder(&Settings::default()).build()?).build();
|
||||||
let form = build_update_instance_form("lemmy.ml", &client)
|
let form = build_update_instance_form("lemmy.ml", &client)
|
||||||
|
@ -645,7 +564,6 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
|
||||||
async fn test_nodeinfo_mastodon_social() -> LemmyResult<()> {
|
async fn test_nodeinfo_mastodon_social() -> LemmyResult<()> {
|
||||||
let client = ClientBuilder::new(client_builder(&Settings::default()).build()?).build();
|
let client = ClientBuilder::new(client_builder(&Settings::default()).build()?).build();
|
||||||
let form = build_update_instance_form("mastodon.social", &client)
|
let form = build_update_instance_form("mastodon.social", &client)
|
||||||
|
@ -654,4 +572,16 @@ mod tests {
|
||||||
assert_eq!(form.software.ok_or(LemmyErrorType::NotFound)?, "mastodon");
|
assert_eq!(form.software.ok_or(LemmyErrorType::NotFound)?, "mastodon");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[serial]
|
||||||
|
async fn test_scheduled_tasks_no_errors() -> LemmyResult<()> {
|
||||||
|
let context = test_context().await;
|
||||||
|
|
||||||
|
startup_jobs(&mut context.pool()).await?;
|
||||||
|
update_instance_software(&mut context.pool(), context.client()).await?;
|
||||||
|
delete_expired_captcha_answers(&mut context.pool()).await?;
|
||||||
|
publish_scheduled_posts(&context).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ where
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::*;
|
use crate::tests::test_context;
|
||||||
use actix_web::test::TestRequest;
|
use actix_web::test::TestRequest;
|
||||||
use lemmy_api_common::claims::Claims;
|
use lemmy_api_common::claims::Claims;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -107,45 +107,29 @@ mod tests {
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
local_user::{LocalUser, LocalUserInsertForm},
|
local_user::{LocalUser, LocalUserInsertForm},
|
||||||
person::{Person, PersonInsertForm},
|
person::{Person, PersonInsertForm},
|
||||||
secret::Secret,
|
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::build_db_pool_for_tests,
|
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyResult, rate_limit::RateLimitCell};
|
use lemmy_utils::error::LemmyResult;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use reqwest::Client;
|
|
||||||
use reqwest_middleware::ClientBuilder;
|
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use std::env::set_current_dir;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_session_auth() -> LemmyResult<()> {
|
async fn test_session_auth() -> LemmyResult<()> {
|
||||||
// hack, necessary so that config file can be loaded from hardcoded, relative path
|
let context = test_context().await;
|
||||||
set_current_dir("crates/utils")?;
|
|
||||||
|
|
||||||
let pool_ = build_db_pool_for_tests();
|
let inserted_instance =
|
||||||
let pool = &mut (&pool_).into();
|
Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?;
|
||||||
|
|
||||||
let secret = Secret::init(pool).await?;
|
|
||||||
|
|
||||||
let context = LemmyContext::create(
|
|
||||||
pool_.clone(),
|
|
||||||
ClientBuilder::new(Client::default()).build(),
|
|
||||||
secret,
|
|
||||||
RateLimitCell::with_test_config(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
|
|
||||||
|
|
||||||
let new_person = PersonInsertForm::test_form(inserted_instance.id, "Gerry9812");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "Gerry9812");
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await?;
|
let inserted_person = Person::create(&mut context.pool(), &new_person).await?;
|
||||||
|
|
||||||
let local_user_form = LocalUserInsertForm::test_form(inserted_person.id);
|
let local_user_form = LocalUserInsertForm::test_form(inserted_person.id);
|
||||||
|
|
||||||
let inserted_local_user = LocalUser::create(pool, &local_user_form, vec![]).await?;
|
let inserted_local_user =
|
||||||
|
LocalUser::create(&mut context.pool(), &local_user_form, vec![]).await?;
|
||||||
|
|
||||||
let req = TestRequest::default().to_http_request();
|
let req = TestRequest::default().to_http_request();
|
||||||
let jwt = Claims::generate(inserted_local_user.id, req, &context).await?;
|
let jwt = Claims::generate(inserted_local_user.id, req, &context).await?;
|
||||||
|
@ -153,7 +137,7 @@ mod tests {
|
||||||
let valid = Claims::validate(&jwt, &context).await;
|
let valid = Claims::validate(&jwt, &context).await;
|
||||||
assert!(valid.is_ok());
|
assert!(valid.is_ok());
|
||||||
|
|
||||||
let num_deleted = Person::delete(pool, inserted_person.id).await?;
|
let num_deleted = Person::delete(&mut context.pool(), inserted_person.id).await?;
|
||||||
assert_eq!(1, num_deleted);
|
assert_eq!(1, num_deleted);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue