Compare commits
567 commits
master
...
federation
Author | SHA1 | Date | |
---|---|---|---|
1043a6b7c2 | |||
5976006859 | |||
|
785509e14c | ||
56e4bfd556 | |||
5f6cf64fc7 | |||
e823f55495 | |||
af189c59f3 | |||
c95165b01a | |||
0cfb0da9cd | |||
48d237beb2 | |||
|
bd2e26bd7b | ||
|
3d58c363db | ||
6dac23b887 | |||
61107b6546 | |||
f3ab32bada | |||
|
a5763736a9 | ||
|
50afe1a3dc | ||
|
902676a9f8 | ||
5c37591270 | |||
463d917f16 | |||
2aa3353b98 | |||
e7d13958d8 | |||
6f9c398c88 | |||
|
250dfa063d | ||
6feef5407b | |||
da21e4e1c3 | |||
|
a8e6d4638f | ||
|
a781990b85 | ||
|
e5426f8f00 | ||
|
c8e19fa7bf | ||
|
d932aaa27f | ||
|
760bf3c77f | ||
|
73cd755788 | ||
|
3c578d8420 | ||
|
4ef27428ee | ||
|
ed57418e91 | ||
|
ff6462cc02 | ||
|
95ed04906b | ||
|
8271f8a6ae | ||
|
43cbc3de1f | ||
|
9868563123 | ||
|
8431f53805 | ||
|
ac95bdd8b5 | ||
|
e7ba29c3c6 | ||
|
e2b8d2d702 | ||
|
9c1bcd6b26 | ||
|
8c17e694ef | ||
|
a0e497b793 | ||
|
22d75990b7 | ||
|
c5e9e9b674 | ||
|
9d78760ebf | ||
|
08986241b6 | ||
|
cfdf33b9d5 | ||
|
fed75ae420 | ||
|
70ba959413 | ||
|
072952e1a6 | ||
|
966a6fc70b | ||
|
6adaa067c8 | ||
|
52f5178649 | ||
|
3b82f4887b | ||
|
c3d4538219 | ||
|
585da4e911 | ||
|
ebbc09672c | ||
|
10a18145fa | ||
|
6513a1d120 | ||
|
784bcc646b | ||
|
64cad8bc3e | ||
|
9481695682 | ||
|
cade656081 | ||
|
c7a8b528a1 | ||
|
a87c101ee7 | ||
|
fa3941a6a4 | ||
|
c0a293c268 | ||
|
5418d45a82 | ||
|
d903ecb6d3 | ||
|
a5c58eb090 | ||
b7ed716659 | |||
|
36ab3b67bf | ||
f9494c2542 | |||
|
715ddc2c99 | ||
|
cdb2799191 | ||
|
8ecca704a2 | ||
|
e013553ec1 | ||
|
fc9d80e17c | ||
|
dab85b09d0 | ||
|
d6b8c68b11 | ||
|
e590b95a31 | ||
|
fe66a336e6 | ||
|
7015332d97 | ||
|
0dae5e910a | ||
|
c74d8bfc64 | ||
|
216863a51f | ||
|
219d728955 | ||
|
0ce63d6ffa | ||
|
342d226ca3 | ||
|
876bab17eb | ||
|
c430bdfcd7 | ||
|
6da1e1b931 | ||
|
ae9242a5c3 | ||
|
da2cad4ebb | ||
|
9a5da04eb7 | ||
|
d92cd2f1d4 | ||
|
65779be906 | ||
|
2a3b866577 | ||
|
50b768d39b | ||
|
3e58375fcc | ||
|
d9f87f1bf5 | ||
|
6ebdf610d4 | ||
|
f4968b56ab | ||
|
594ce2888f | ||
|
1afd03580d | ||
|
f4191a52c3 | ||
|
45592bc466 | ||
|
d04dcd88fb | ||
|
3b37fcaefd | ||
|
c8b2feb2d0 | ||
|
0a09d07231 | ||
|
ad09df640e | ||
|
b3b1210196 | ||
|
d8078cc9eb | ||
|
ff03b2dbb6 | ||
|
71cd3e3f3b | ||
|
8390744391 | ||
|
a5bfc837ea | ||
|
6deb41e3d9 | ||
|
c6a6ca68d0 | ||
|
68445a48a5 | ||
|
d892a4f28c | ||
|
f997eeca0a | ||
|
429738c9b4 | ||
|
a866d2d283 | ||
e3111431aa | |||
467cd41bd3 | |||
|
f61f4a944d | ||
2794b8b36a | |||
|
a308b3579d | ||
ae16a4b1a5 | |||
7d94cd5c96 | |||
|
5623f11b05 | ||
70995dab8c | |||
a52a954eb4 | |||
9dcfe835a9 | |||
0d9598155b | |||
|
6365439c16 | ||
|
1595b9406d | ||
|
ff8d82d82f | ||
|
b277d92226 | ||
|
fab10ef792 | ||
|
76662ca557 | ||
|
6e6cfa9cf8 | ||
|
2092cf3f4e | ||
|
e784cc8b72 | ||
|
cf66addc62 | ||
|
d667d35a7c | ||
|
4cad614c49 | ||
|
c896e01b9e | ||
|
6cde97836b | ||
|
b147ca462c | ||
|
484118ca6c | ||
|
05a8c61f67 | ||
|
beec263ae6 | ||
|
6ac491c587 | ||
|
81f1aaf298 | ||
|
8505329889 | ||
|
8c81dc04da | ||
|
8a16497eef | ||
|
fe3f733032 | ||
|
e8735e4edc | ||
|
6cb10d266a | ||
|
b79ec0cc1b | ||
|
87969e7024 | ||
|
a0e0c3edab | ||
|
3a598b7af2 | ||
|
d629f26ea7 | ||
|
7641ff0117 | ||
|
30891fe384 | ||
|
ae473c2b0d | ||
|
d6eeabd73b | ||
|
51bc048955 | ||
|
97fccb5615 | ||
|
2e38f934fe | ||
|
225bc0cca7 | ||
|
9e5cf8f272 | ||
|
58bc1d8347 | ||
|
4b4e84b309 | ||
|
be83e99334 | ||
|
cf0c0a5824 | ||
|
10223d5aef | ||
|
f98b2bd4ba | ||
|
28a3140523 | ||
|
a04b360d91 | ||
|
ee2c6e0850 | ||
|
a95f282936 | ||
|
deae2b6ade | ||
|
940ea569c7 | ||
|
d3f8e55124 | ||
|
92af8be12c | ||
|
6bddeecdb6 | ||
|
d6867fa791 | ||
|
9237226585 | ||
|
036d6260bb | ||
|
f494835e8a | ||
|
54b215a587 | ||
|
8803bf97dd | ||
|
a72d0ae42f | ||
|
469594fac8 | ||
|
49a35b1271 | ||
|
69c22b17a0 | ||
|
7f92d82b1b | ||
|
52b65bda69 | ||
|
d3e23bc90a | ||
|
b5b9705152 | ||
|
841a86a666 | ||
|
74aa161ff6 | ||
|
8c5a510cfc | ||
|
049556f146 | ||
|
1e157decec | ||
|
65145b719c | ||
|
68ac96147c | ||
|
1c182e381b | ||
|
514c1ab298 | ||
|
bbc7159ede | ||
|
c9060f76b4 | ||
|
e900313f6e | ||
|
9fb5d55569 | ||
|
018fe531be | ||
|
d5b483d4d1 | ||
|
1d4dc19d6f | ||
|
5103878741 | ||
|
7612a54894 | ||
|
6fce9911f9 | ||
|
fc81cd98d2 | ||
|
b5143e0919 | ||
|
ec9e48cbaa | ||
|
5614ed7a93 | ||
|
0fe4e22acd | ||
|
d95a1ae5e6 | ||
|
a8ef9f8726 | ||
|
8a3f5032c3 | ||
|
07fdb17557 | ||
|
1f96b73e51 | ||
|
45241cc5df | ||
|
43c187cf08 | ||
|
fe1db54a93 | ||
|
53a662e3b2 | ||
|
47a58ce0a8 | ||
|
8b04897632 | ||
|
261602335b | ||
|
ee60465643 | ||
|
5601ad5283 | ||
|
ba25af4364 | ||
|
6ec79d2696 | ||
|
b0399da27b | ||
|
d1ec4828ef | ||
|
f167906a74 | ||
|
35efca4152 | ||
|
5e4397866f | ||
|
dcad63fe2a | ||
|
ee0c802476 | ||
|
238be5f71c | ||
|
73a720e9c3 | ||
|
a4fa4a55d0 | ||
|
0732029df9 | ||
|
81b985f997 | ||
|
7382defa4c | ||
|
7037506566 | ||
|
9cb438b440 | ||
|
0b7e5a5b55 | ||
|
1bf8661834 | ||
|
1e8b359571 | ||
|
586e8861de | ||
|
3bcf82682d | ||
|
4a0bebf45a | ||
e19a22d909 | |||
2cbf191b69 | |||
|
448ac762b8 | ||
|
d4736be04f | ||
|
a221525eef | ||
|
a1060e35a7 | ||
|
3f42af9885 | ||
|
2e45e88fcc | ||
|
36c451e7c0 | ||
|
ad8e47f8d2 | ||
|
3ddbe2e370 | ||
|
bf2543c4e6 | ||
|
04df95b8b2 | ||
|
680eab53c1 | ||
|
e09e3b6a92 | ||
|
ac64786dc0 | ||
|
a40a7d515d | ||
|
f74d7b0368 | ||
|
08c6fcf6a8 | ||
|
8c2c0f0440 | ||
|
bc1b7afd60 | ||
|
323c5dc26c | ||
|
1e8fa79b67 | ||
|
3f561710ef | ||
|
034adbe3a9 | ||
|
d5bacc2839 | ||
|
82c4d04114 | ||
|
c2542137db | ||
|
8fc6b16639 | ||
|
512ff8eec9 | ||
|
f46b728499 | ||
|
cdef3a8ed0 | ||
|
be6bd0b36f | ||
|
648ac32f4b | ||
|
3a74b0b534 | ||
|
1d2b096779 | ||
|
d2136ee81d | ||
|
4f08760ef4 | ||
|
b14f7bae3c | ||
|
d81345560f | ||
|
d829b9b5ac | ||
b3e1930d03 | |||
|
7809b6ab0d | ||
|
41ac10f75e | ||
|
000e1c8660 | ||
758b6891eb | |||
|
aabb5e9973 | ||
|
a313e7fb1b | ||
|
9aa59473ff | ||
|
dd4f96673f | ||
|
213ed9b4b3 | ||
|
e370475f50 | ||
|
5060542a01 | ||
|
ca9eaade7d | ||
|
2aab6f02e7 | ||
|
eb5dae8429 | ||
|
68496128c5 | ||
|
b4f3eb29fc | ||
|
3e36fcff98 | ||
|
c09ea38af6 | ||
|
0d64f20b68 | ||
|
196d5d77b9 | ||
|
0751ed0e3c | ||
|
045f6e80d1 | ||
|
43d8a2c2ae | ||
|
a1a11e0ce7 | ||
7c0a9121c9 | |||
|
628d6729c1 | ||
|
9431f93e5f | ||
|
d639f85a30 | ||
|
beb55a471f | ||
|
e7c90bee01 | ||
|
22883c94ea | ||
|
44b08ecc61 | ||
|
866df99c4f | ||
|
8ef3abca0e | ||
|
3180491748 | ||
|
f044459fda | ||
|
e160438a90 | ||
|
88b798bb6b | ||
|
f3ece78f83 | ||
|
8ff637a57e | ||
|
8f9db655ec | ||
|
75554df998 | ||
|
3df34acdcf | ||
|
7f57ec7ca7 | ||
|
7468df649e | ||
|
a7ac1d3bad | ||
|
3b12f92752 | ||
|
2998957617 | ||
|
c5fc5cc9d0 | ||
|
7bbb071b0b | ||
|
d6d060f7ab | ||
|
61a5bcaf04 | ||
|
c83dc4f311 | ||
|
9140faded0 | ||
|
7be3cff714 | ||
|
4dfd96ce8c | ||
|
349751f143 | ||
|
bfc45aa9bc | ||
|
9024809a5c | ||
|
197bd67601 | ||
|
ada50fc3de | ||
|
351cd84ab8 | ||
|
d458571f13 | ||
|
58af4355c5 | ||
|
937489ad51 | ||
|
ba16e36202 | ||
|
c3eaa2273a | ||
|
f5b75f342b | ||
|
bd1fc2b80b | ||
|
69389f61c9 | ||
|
7fdcae4f07 | ||
752318fdf3 | |||
|
9ccff18f23 | ||
|
5197407dd2 | ||
|
58f673ab78 | ||
|
bacb9ac59e | ||
|
10c6505968 | ||
|
7d3adda0cd | ||
|
759453772d | ||
|
2b4bacaa10 | ||
|
dbe9ad0998 | ||
|
fc86b83e36 | ||
|
dc35c7b126 | ||
|
5fec981674 | ||
|
572b3b876f | ||
|
7145dde79f | ||
|
365f81b699 | ||
|
5dc0d947e9 | ||
|
6312ff333b | ||
|
2394993dd4 | ||
|
66adf67661 | ||
|
7b7fb0f5d2 | ||
|
7f0e69e54c | ||
|
3b8a2f61fc | ||
|
20c9c54806 | ||
|
dc84ccaac9 | ||
|
3edd75ed43 | ||
|
6c61dd266b | ||
e518954bca | |||
0a409bc9be | |||
|
c5eecd055e | ||
|
0c5eb47135 | ||
|
9e60e76a8c | ||
e859080632 | |||
|
126e2085fd | ||
baf77bb6be | |||
047ec97e18 | |||
2fb4900b0c | |||
cba8081579 | |||
d7285d8c25 | |||
415040a1e9 | |||
7a97c981a0 | |||
c41082f98f | |||
|
05f2bfc83c | ||
|
fb82a489d5 | ||
|
2af3f1d5cc | ||
|
b6aa9a30e8 | ||
|
676de4ab84 | ||
|
966f76f5cc | ||
|
f8e9578ff8 | ||
|
645fc9a620 | ||
|
a9c8127a69 | ||
|
5cf27d255a | ||
|
b14c8f1a46 | ||
|
d5af66c1b1 | ||
|
0457d4c8f1 | ||
|
69d816c865 | ||
|
24770126d4 | ||
|
318ce4a52a | ||
|
fc26a9a377 | ||
|
1e884c6969 | ||
|
04c7f99f67 | ||
|
efdc98dfa0 | ||
|
b0246a784b | ||
|
7e8c0b146b | ||
|
d762230f61 | ||
|
f8525b2474 | ||
|
48e221d06c | ||
|
6cd9156d3b | ||
|
655c5db59a | ||
|
10533ff005 | ||
|
0671390475 | ||
|
afdad2abc3 | ||
|
a2c469977c | ||
47d4fd1cc4 | |||
|
1cf97a8661 | ||
|
aaa64811f4 | ||
|
556016614d | ||
|
b0899cf55e | ||
|
cc11930bdd | ||
|
66f0683160 | ||
|
13a5c50c70 | ||
|
3f4cce99ed | ||
|
6260fea707 | ||
|
083fcb9c6c | ||
|
a06476fa96 | ||
|
aa502b687d | ||
|
5f4a35c80a | ||
|
a6d88fdfb0 | ||
|
7839eb6d40 | ||
|
d0de6552ab | ||
|
1707b19f80 | ||
|
ebaa96a9d6 | ||
|
33b602f353 | ||
|
7a82e9ffd2 | ||
|
ae02747ee0 | ||
|
34ddd62fd1 | ||
|
9755654734 | ||
|
38ba7dfb1a | ||
|
519a509412 | ||
|
dab6695ae2 | ||
|
a08d743747 | ||
|
ad2fc2e8d9 | ||
02bcbc42d6 | |||
|
8fe034c320 | ||
66c95993dc | |||
a2363efd40 | |||
|
6d89f6f955 | ||
|
8079b6faef | ||
|
fe264a2f30 | ||
|
2cb57b833d | ||
|
588010ea88 | ||
|
2d95db8a7d | ||
|
bd99f4994a | ||
|
813b053b5f | ||
|
0f09171d68 | ||
|
7b492cc477 | ||
|
912871d0ac | ||
|
07d7664a38 | ||
|
02cf67de4a | ||
|
4157bf9a02 | ||
|
1180b89268 | ||
|
d22bbafebb | ||
|
e3d4f9418e | ||
|
beb63aedc8 | ||
|
e339f90737 | ||
1c1f3d1316 | |||
|
8c1316aa96 | ||
|
ec146a0dea | ||
|
c939c15530 | ||
c01b40c517 | |||
ddd4baf103 | |||
|
a998bfc1f5 | ||
|
3c6eb37a1b | ||
|
2512babff1 | ||
|
f71d19729a | ||
|
04da8146ba | ||
|
b63aabfdc2 | ||
4b6bba0e7b | |||
|
a95704d5fc | ||
|
dbd1d8faa5 | ||
|
868ba5b64c | ||
49de4ccbd9 | |||
af83ec951f | |||
|
b365dd2349 | ||
|
9e20ddbfa4 | ||
|
22904e1c66 | ||
f7156bdac3 | |||
74c02c5359 | |||
|
b6c297766b | ||
|
a6bc0edc91 | ||
|
ddb512b1ae | ||
|
88fed73ea3 | ||
|
51c8735682 | ||
|
94c4504b33 | ||
|
c06d01f753 | ||
|
daf22a12d9 | ||
|
dc1fc1e04c | ||
|
18d4b3d2aa | ||
|
3a85515bd5 | ||
|
b4b8e9d7f5 | ||
|
807dd8d82c | ||
|
c31fe3857c | ||
|
14418c5a0d | ||
|
0799ae1a1f | ||
|
8a9f1dbb59 | ||
|
a42e2af203 | ||
|
8bf5d0cca6 | ||
|
6b68d54e35 | ||
|
7d291ee95a | ||
|
6248392992 | ||
f18ebed740 | |||
10da3f2554 | |||
8fb34843aa | |||
a882fbea97 | |||
ae3fccf701 | |||
f7333705dc | |||
140eff181c | |||
2c26cc26b8 | |||
bad4868a10 | |||
|
844a97a6a5 | ||
|
a347163ad7 |
221 changed files with 22434 additions and 9609 deletions
10
.dockerignore
vendored
10
.dockerignore
vendored
|
@ -1,5 +1,11 @@
|
||||||
|
# build folders and similar which are not needed for the docker build
|
||||||
ui/node_modules
|
ui/node_modules
|
||||||
ui/dist
|
|
||||||
server/target
|
server/target
|
||||||
docs
|
docker/dev/volumes
|
||||||
|
docker/federation-test/volumes
|
||||||
.git
|
.git
|
||||||
|
ansible
|
||||||
|
|
||||||
|
# exceptions, needed for federation-test build
|
||||||
|
|
||||||
|
!server/target/debug/lemmy_server
|
||||||
|
|
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
|
@ -1,3 +1,4 @@
|
||||||
# These are supported funding model platforms
|
# These are supported funding model platforms
|
||||||
|
|
||||||
patreon: dessalines
|
patreon: dessalines
|
||||||
|
liberapay: Lemmy
|
||||||
|
|
13
.gitignore
vendored
13
.gitignore
vendored
|
@ -1,4 +1,17 @@
|
||||||
|
# local ansible configuration
|
||||||
ansible/inventory
|
ansible/inventory
|
||||||
|
ansible/inventory_dev
|
||||||
ansible/passwords/
|
ansible/passwords/
|
||||||
|
|
||||||
|
# docker build files
|
||||||
|
docker/lemmy_mine.hjson
|
||||||
|
docker/dev/env_deploy.sh
|
||||||
|
docker/federation-test/volumes
|
||||||
|
docker/dev/volumes
|
||||||
|
|
||||||
|
# local build files
|
||||||
build/
|
build/
|
||||||
|
ui/src/translations
|
||||||
|
|
||||||
|
# ide config
|
||||||
.idea/
|
.idea/
|
||||||
|
|
26
.travis.yml
vendored
26
.travis.yml
vendored
|
@ -5,21 +5,31 @@ matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- rust: nightly
|
- rust: nightly
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
cache:
|
cache: cargo
|
||||||
directories:
|
|
||||||
- /home/travis/.cargo
|
|
||||||
before_cache:
|
before_cache:
|
||||||
- rm -rf /home/travis/.cargo/registry
|
- rm -rfv target/debug/incremental/lemmy_server-*
|
||||||
|
- rm -rfv target/debug/.fingerprint/lemmy_server-*
|
||||||
|
- rm -rfv target/debug/build/lemmy_server-*
|
||||||
|
- rm -rfv target/debug/deps/lemmy_server-*
|
||||||
|
- rm -rfv target/debug/lemmy_server.d
|
||||||
|
- cargo clean
|
||||||
before_script:
|
before_script:
|
||||||
- psql -c "create user rrr with password 'rrr' superuser;" -U postgres
|
- psql -c "create user lemmy with password 'password' superuser;" -U postgres
|
||||||
- psql -c 'create database rrr with owner rrr;' -U postgres
|
- psql -c 'create database lemmy with owner lemmy;' -U postgres
|
||||||
|
- rustup component add clippy --toolchain stable-x86_64-unknown-linux-gnu
|
||||||
before_install:
|
before_install:
|
||||||
- cd server
|
- cd server
|
||||||
script:
|
script:
|
||||||
- diesel migration run
|
# Default checks, but fail if anything is detected
|
||||||
- cargo build
|
- cargo build
|
||||||
|
- cargo clippy -- -D clippy::style -D clippy::correctness -D clippy::complexity -D clippy::perf
|
||||||
|
- cargo install diesel_cli --no-default-features --features postgres --force
|
||||||
|
- diesel migration run
|
||||||
- cargo test
|
- cargo test
|
||||||
env:
|
env:
|
||||||
- DATABASE_URL=postgres://rrr:rrr@localhost/rrr
|
global:
|
||||||
|
- DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
|
||||||
|
- RUST_TEST_THREADS=1
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
postgresql: "9.4"
|
postgresql: "9.4"
|
||||||
|
|
35
CODE_OF_CONDUCT.md
vendored
Normal file
35
CODE_OF_CONDUCT.md
vendored
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# Code of Conduct
|
||||||
|
|
||||||
|
- We are committed to providing a friendly, safe and welcoming environment for all, regardless of level of experience, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, nationality, or other similar characteristic.
|
||||||
|
- Please avoid using overtly sexual aliases or other nicknames that might detract from a friendly, safe and welcoming environment for all.
|
||||||
|
- Please be kind and courteous. There’s no need to be mean or rude.
|
||||||
|
- Respect that people have differences of opinion and that every design or implementation choice carries a trade-off and numerous costs. There is seldom a right answer.
|
||||||
|
- Please keep unstructured critique to a minimum. If you have solid ideas you want to experiment with, make a fork and see how it works.
|
||||||
|
- We will exclude you from interaction if you insult, demean or harass anyone. That is not welcome behavior. We interpret the term “harassment” as including the definition in the Citizen Code of Conduct; if you have any lack of clarity about what might be included in that concept, please read their definition. In particular, we don’t tolerate behavior that excludes people in socially marginalized groups.
|
||||||
|
- Private harassment is also unacceptable. No matter who you are, if you feel you have been or are being harassed or made uncomfortable by a community member, please contact one of the channel ops or any of the Lemmy moderation team immediately. Whether you’re a regular contributor or a newcomer, we care about making this community a safe place for you and we’ve got your back.
|
||||||
|
- Likewise any spamming, trolling, flaming, baiting or other attention-stealing behavior is not welcome.
|
||||||
|
|
||||||
|
[**Message the Moderation Team on Mastodon**](https://mastodon.social/@LemmyDev)
|
||||||
|
|
||||||
|
[**Email The Moderation Team**](mailto:contact@lemmy.ml)
|
||||||
|
|
||||||
|
## Moderation
|
||||||
|
|
||||||
|
These are the policies for upholding our community’s standards of conduct. If you feel that a thread needs moderation, please contact the Lemmy moderation team .
|
||||||
|
|
||||||
|
1. Remarks that violate the Lemmy standards of conduct, including hateful, hurtful, oppressive, or exclusionary remarks, are not allowed. (Cursing is allowed, but never targeting another user, and never in a hateful manner.)
|
||||||
|
2. Remarks that moderators find inappropriate, whether listed in the code of conduct or not, are also not allowed.
|
||||||
|
3. Moderators will first respond to such remarks with a warning, at the same time the offending content will likely be removed whenever possible.
|
||||||
|
4. If the warning is unheeded, the user will be “kicked,” i.e., kicked out of the communication channel to cool off.
|
||||||
|
5. If the user comes back and continues to make trouble, they will be banned, i.e., indefinitely excluded.
|
||||||
|
6. Moderators may choose at their discretion to un-ban the user if it was a first offense and they offer the offended party a genuine apology.
|
||||||
|
7. If a moderator bans someone and you think it was unjustified, please take it up with that moderator, or with a different moderator, in private. Complaints about bans in-channel are not allowed.
|
||||||
|
8. Moderators are held to a higher standard than other community members. If a moderator creates an inappropriate situation, they should expect less leeway than others.
|
||||||
|
|
||||||
|
In the Lemmy community we strive to go the extra step to look out for each other. Don’t just aim to be technically unimpeachable, try to be your best self. In particular, avoid flirting with offensive or sensitive issues, particularly if they’re off-topic; this all too often leads to unnecessary fights, hurt feelings, and damaged trust; worse, it can drive people away from the community entirely.
|
||||||
|
|
||||||
|
And if someone takes issue with something you said or did, resist the urge to be defensive. Just stop doing what it was they complained about and apologize. Even if you feel you were misinterpreted or unfairly accused, chances are good there was something you could’ve communicated better — remember that it’s your responsibility to make others comfortable. Everyone wants to get along and we are all here first and foremost because we want to talk about cool technology. You will find that people will be eager to assume good intent and forgive as long as you earn their trust.
|
||||||
|
|
||||||
|
The enforcement policies listed above apply to all official Lemmy venues; including git repositories under [github.com/dessalines/lemmy](https://github.com/dessalines/lemmy) and [yerbamate.dev/dessalines/lemmy](https://yerbamate.dev/dessalines/lemmy), the [Matrix channel](https://matrix.to/#/!BZVTUuEiNmRcbFeLeI:matrix.org?via=matrix.org&via=privacytools.io&via=permaweb.io); and all instances under lemmy.ml. For other projects adopting the Rust Code of Conduct, please contact the maintainers of those projects for enforcement. If you wish to use this code of conduct for your own project, consider explicitly mentioning your moderation policy or making a copy with your own moderation policy so as to avoid confusion.
|
||||||
|
|
||||||
|
Adapted from the [Rust Code of Conduct](https://www.rust-lang.org/policies/code-of-conduct), which is based on the [Node.js Policy on Trolling](http://blog.izs.me/post/30036893703/policy-on-trolling) as well as the [Contributor Covenant v1.3.0](https://www.contributor-covenant.org/version/1/3/0/).
|
4
CONTRIBUTING.md
vendored
Normal file
4
CONTRIBUTING.md
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# Contributing
|
||||||
|
|
||||||
|
See [here](https://dev.lemmy.ml/docs/contributing.html) for contributing Instructions.
|
||||||
|
|
301
README.md
vendored
301
README.md
vendored
|
@ -1,97 +1,41 @@
|
||||||
<p align="center">
|
|
||||||
<a href="" rel="noopener">
|
|
||||||
<img width=200px height=200px src="ui/assets/favicon.svg"></a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h3 align="center">Lemmy</h3>
|
|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||
[![Github](https://img.shields.io/badge/-Github-blue)](https://github.com/dessalines/lemmy)
|
|
||||||
[![Gitlab](https://img.shields.io/badge/-Gitlab-yellowgreen)](https://gitlab.com/dessalines/lemmy)
|
|
||||||
![Mastodon Follow](https://img.shields.io/mastodon/follow/810572?domain=https%3A%2F%2Fmastodon.social&style=social)
|
|
||||||
![GitHub stars](https://img.shields.io/github/stars/dessalines/lemmy?style=social)
|
|
||||||
[![Matrix](https://img.shields.io/matrix/rust-reddit-fediverse:matrix.org.svg?label=matrix-chat)](https://riot.im/app/#/room/#rust-reddit-fediverse:matrix.org)
|
|
||||||
![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/dessalines/lemmy.svg)
|
![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/dessalines/lemmy.svg)
|
||||||
[![Build Status](https://travis-ci.org/dessalines/lemmy.svg?branch=master)](https://travis-ci.org/dessalines/lemmy)
|
[![Build Status](https://travis-ci.org/dessalines/lemmy.svg?branch=master)](https://travis-ci.org/dessalines/lemmy)
|
||||||
[![GitHub issues](https://img.shields.io/github/issues-raw/dessalines/lemmy.svg)](https://github.com/dessalines/lemmy/issues)
|
[![GitHub issues](https://img.shields.io/github/issues-raw/dessalines/lemmy.svg)](https://github.com/dessalines/lemmy/issues)
|
||||||
[![Docker Pulls](https://img.shields.io/docker/pulls/dessalines/lemmy.svg)](https://cloud.docker.com/repository/docker/dessalines/lemmy/)
|
[![Docker Pulls](https://img.shields.io/docker/pulls/dessalines/lemmy.svg)](https://cloud.docker.com/repository/docker/dessalines/lemmy/)
|
||||||
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/dessalines/lemmy.svg)
|
[![Translation status](http://weblate.yerbamate.dev/widgets/lemmy/-/lemmy/svg-badge.svg)](http://weblate.yerbamate.dev/engage/lemmy/)
|
||||||
![GitHub repo size](https://img.shields.io/github/repo-size/dessalines/lemmy.svg)
|
|
||||||
[![License](https://img.shields.io/github/license/dessalines/lemmy.svg)](LICENSE)
|
[![License](https://img.shields.io/github/license/dessalines/lemmy.svg)](LICENSE)
|
||||||
[![Patreon](https://img.shields.io/badge/-Support%20on%20Patreon-blueviolet.svg)](https://www.patreon.com/dessalines)
|
![GitHub stars](https://img.shields.io/github/stars/dessalines/lemmy?style=social)
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
---
|
<p align="center">
|
||||||
|
<a href="https://dev.lemmy.ml/" rel="noopener">
|
||||||
|
<img width=200px height=200px src="ui/assets/favicon.svg"></a>
|
||||||
|
|
||||||
<p align="center">A link aggregator / reddit clone for the fediverse.
|
<h3 align="center"><a href="https://dev.lemmy.ml">Lemmy</a></h3>
|
||||||
<br>
|
<p align="center">
|
||||||
|
A link aggregator / reddit clone for the fediverse.
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<a href="https://dev.lemmy.ml">View Site</a>
|
||||||
|
·
|
||||||
|
<a href="https://dev.lemmy.ml/docs/index.html">Documentation</a>
|
||||||
|
·
|
||||||
|
<a href="https://github.com/dessalines/lemmy/issues">Report Bug</a>
|
||||||
|
·
|
||||||
|
<a href="https://github.com/dessalines/lemmy/issues">Request Feature</a>
|
||||||
|
·
|
||||||
|
<a href="https://github.com/dessalines/lemmy/blob/master/RELEASES.md">Releases</a>
|
||||||
|
</p>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
[Lemmy Dev instance](https://dev.lemmy.ml) *for testing purposes only*
|
## About The Project
|
||||||
|
|
||||||
This is a **very early beta version**, and a lot of features are currently broken or in active development, such as federation.
|
|
||||||
|
|
||||||
Front Page|Post
|
Front Page|Post
|
||||||
---|---
|
---|---
|
||||||
![main screen](https://i.imgur.com/kZSRcRu.png)|![chat screen](https://i.imgur.com/4XghNh6.png)
|
![main screen](https://i.imgur.com/kZSRcRu.png)|![chat screen](https://i.imgur.com/4XghNh6.png)
|
||||||
|
|
||||||
## 📝 Table of Contents
|
|
||||||
|
|
||||||
<!-- toc -->
|
|
||||||
|
|
||||||
- [Features](#features)
|
|
||||||
- [About](#about)
|
|
||||||
* [Why's it called Lemmy?](#whys-it-called-lemmy)
|
|
||||||
- [Install](#install)
|
|
||||||
* [Docker](#docker)
|
|
||||||
+ [Updating](#updating)
|
|
||||||
* [Ansible](#ansible)
|
|
||||||
* [Kubernetes](#kubernetes)
|
|
||||||
- [Develop](#develop)
|
|
||||||
* [Docker Development](#docker-development)
|
|
||||||
* [Local Development](#local-development)
|
|
||||||
+ [Requirements](#requirements)
|
|
||||||
+ [Set up Postgres DB](#set-up-postgres-db)
|
|
||||||
+ [Running](#running)
|
|
||||||
- [Documentation](#documentation)
|
|
||||||
- [Support](#support)
|
|
||||||
- [Translations](#translations)
|
|
||||||
- [Credits](#credits)
|
|
||||||
|
|
||||||
<!-- tocstop -->
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- Open source, [AGPL License](/LICENSE).
|
|
||||||
- Self hostable, easy to deploy.
|
|
||||||
- Comes with [Docker](#docker), [Ansible](#ansible), [Kubernetes](#kubernetes).
|
|
||||||
- Clean, mobile-friendly interface.
|
|
||||||
- Live-updating Comment threads.
|
|
||||||
- Full vote scores `(+/-)` like old reddit.
|
|
||||||
- Themes, including light, dark, and solarized.
|
|
||||||
- Emojis with autocomplete support. Start typing `:`
|
|
||||||
- User tagging using `@`, Community tagging using `#`.
|
|
||||||
- Notifications, on comment replies and when you're tagged.
|
|
||||||
- i18n / internationalization support.
|
|
||||||
- RSS / Atom feeds for `All`, `Subscribed`, `Inbox`, `User`, and `Community`.
|
|
||||||
- Cross-posting support.
|
|
||||||
- A *similar post search* when creating new posts. Great for question / answer communities.
|
|
||||||
- Moderation abilities.
|
|
||||||
- Public Moderation Logs.
|
|
||||||
- Both site admins, and community moderators, who can appoint other moderators.
|
|
||||||
- Can lock, remove, and restore posts and comments.
|
|
||||||
- Can ban and unban users from communities and the site.
|
|
||||||
- Can transfer site and communities to others.
|
|
||||||
- Can fully erase your data, replacing all posts and comments.
|
|
||||||
- NSFW post / community support.
|
|
||||||
- High performance.
|
|
||||||
- Server is written in rust.
|
|
||||||
- Front end is `~80kB` gzipped.
|
|
||||||
- Supports arm64 / Raspberry Pi.
|
|
||||||
|
|
||||||
## About
|
|
||||||
|
|
||||||
[Lemmy](https://github.com/dessalines/lemmy) is similar to sites like [Reddit](https://reddit.com), [Lobste.rs](https://lobste.rs), [Raddle](https://raddle.me), or [Hacker News](https://news.ycombinator.com/): you subscribe to forums you're interested in, post links and discussions, then vote, and comment on them. Behind the scenes, it is very different; anyone can easily run a server, and all these servers are federated (think email), and connected to the same universe, called the [Fediverse](https://en.wikipedia.org/wiki/Fediverse).
|
[Lemmy](https://github.com/dessalines/lemmy) is similar to sites like [Reddit](https://reddit.com), [Lobste.rs](https://lobste.rs), [Raddle](https://raddle.me), or [Hacker News](https://news.ycombinator.com/): you subscribe to forums you're interested in, post links and discussions, then vote, and comment on them. Behind the scenes, it is very different; anyone can easily run a server, and all these servers are federated (think email), and connected to the same universe, called the [Fediverse](https://en.wikipedia.org/wiki/Fediverse).
|
||||||
|
|
||||||
For a link aggregator, this means a user registered on one server can subscribe to forums on any other server, and can have discussions with users registered elsewhere.
|
For a link aggregator, this means a user registered on one server can subscribe to forums on any other server, and can have discussions with users registered elsewhere.
|
||||||
|
@ -100,6 +44,8 @@ The overall goal is to create an easily self-hostable, decentralized alternative
|
||||||
|
|
||||||
Each lemmy server can set its own moderation policy; appointing site-wide admins, and community moderators to keep out the trolls, and foster a healthy, non-toxic environment where all can feel comfortable contributing.
|
Each lemmy server can set its own moderation policy; appointing site-wide admins, and community moderators to keep out the trolls, and foster a healthy, non-toxic environment where all can feel comfortable contributing.
|
||||||
|
|
||||||
|
*Note: Federation is still in active development*
|
||||||
|
|
||||||
### Why's it called Lemmy?
|
### Why's it called Lemmy?
|
||||||
|
|
||||||
- Lead singer from [Motörhead](https://invidio.us/watch?v=pWB5JZRGl0U).
|
- Lead singer from [Motörhead](https://invidio.us/watch?v=pWB5JZRGl0U).
|
||||||
|
@ -107,163 +53,88 @@ Each lemmy server can set its own moderation policy; appointing site-wide admins
|
||||||
- The [Koopa from Super Mario](https://www.mariowiki.com/Lemmy_Koopa).
|
- The [Koopa from Super Mario](https://www.mariowiki.com/Lemmy_Koopa).
|
||||||
- The [furry rodents](http://sunchild.fpwc.org/lemming-the-little-giant-of-the-north/).
|
- The [furry rodents](http://sunchild.fpwc.org/lemming-the-little-giant-of-the-north/).
|
||||||
|
|
||||||
Made with [Rust](https://www.rust-lang.org), [Actix](https://actix.rs/), [Inferno](https://www.infernojs.org), [Typescript](https://www.typescriptlang.org/) and [Diesel](http://diesel.rs/).
|
### Built With
|
||||||
|
|
||||||
## Install
|
- [Rust](https://www.rust-lang.org)
|
||||||
|
- [Actix](https://actix.rs/)
|
||||||
|
- [Diesel](http://diesel.rs/)
|
||||||
|
- [Inferno](https://infernojs.org)
|
||||||
|
- [Typescript](https://www.typescriptlang.org/)
|
||||||
|
|
||||||
### Docker
|
## Features
|
||||||
|
|
||||||
Make sure you have both docker and docker-compose(>=`1.24.0`) installed:
|
- Open source, [AGPL License](/LICENSE).
|
||||||
|
- Self hostable, easy to deploy.
|
||||||
|
- Comes with [Docker](#docker), [Ansible](#ansible), [Kubernetes](#kubernetes).
|
||||||
|
- Clean, mobile-friendly interface.
|
||||||
|
- Only a minimum of a username and password is required to sign up!
|
||||||
|
- User avatar support.
|
||||||
|
- Live-updating Comment threads.
|
||||||
|
- Full vote scores `(+/-)` like old reddit.
|
||||||
|
- Themes, including light, dark, and solarized.
|
||||||
|
- Emojis with autocomplete support. Start typing `:`
|
||||||
|
- User tagging using `@`, Community tagging using `#`.
|
||||||
|
- Integrated image uploading in both posts and comments.
|
||||||
|
- A post can consist of a title and any combination of self text, a URL, or nothing else.
|
||||||
|
- Notifications, on comment replies and when you're tagged.
|
||||||
|
- Notifications can be sent via email.
|
||||||
|
- Private messaging support.
|
||||||
|
- i18n / internationalization support.
|
||||||
|
- RSS / Atom feeds for `All`, `Subscribed`, `Inbox`, `User`, and `Community`.
|
||||||
|
- Cross-posting support.
|
||||||
|
- A *similar post search* when creating new posts. Great for question / answer communities.
|
||||||
|
- Moderation abilities.
|
||||||
|
- Public Moderation Logs.
|
||||||
|
- Can sticky posts to the top of communities.
|
||||||
|
- Both site admins, and community moderators, who can appoint other moderators.
|
||||||
|
- Can lock, remove, and restore posts and comments.
|
||||||
|
- Can ban and unban users from communities and the site.
|
||||||
|
- Can transfer site and communities to others.
|
||||||
|
- Can fully erase your data, replacing all posts and comments.
|
||||||
|
- NSFW post / community support.
|
||||||
|
- OEmbed support via Iframely.
|
||||||
|
- High performance.
|
||||||
|
- Server is written in rust.
|
||||||
|
- Front end is `~80kB` gzipped.
|
||||||
|
- Supports arm64 / Raspberry Pi.
|
||||||
|
|
||||||
```bash
|
## Installation
|
||||||
mkdir lemmy/
|
|
||||||
cd lemmy/
|
|
||||||
wget https://raw.githubusercontent.com/dessalines/lemmy/master/docker/prod/docker-compose.yml
|
|
||||||
wget https://raw.githubusercontent.com/dessalines/lemmy/master/docker/prod/.env
|
|
||||||
# Edit the .env if you want custom passwords
|
|
||||||
docker-compose up -d
|
|
||||||
```
|
|
||||||
|
|
||||||
and go to http://localhost:8536.
|
- [Docker](https://dev.lemmy.ml/docs/administration_install_docker.html)
|
||||||
|
- [Ansible](https://dev.lemmy.ml/docs/administration_install_ansible.html)
|
||||||
|
- [Kubernetes](https://dev.lemmy.ml/docs/administration_install_kubernetes.html)
|
||||||
|
|
||||||
[A sample nginx config](/ansible/templates/nginx.conf), could be setup with:
|
## Support / Donate
|
||||||
|
|
||||||
```bash
|
|
||||||
wget https://raw.githubusercontent.com/dessalines/lemmy/master/ansible/templates/nginx.conf
|
|
||||||
# Replace the {{ vars }}
|
|
||||||
sudo mv nginx.conf /etc/nginx/sites-enabled/lemmy.conf
|
|
||||||
```
|
|
||||||
#### Updating
|
|
||||||
|
|
||||||
To update to the newest version, run:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
wget https://raw.githubusercontent.com/dessalines/lemmy/master/docker/prod/docker-compose.yml
|
|
||||||
docker-compose up -d
|
|
||||||
```
|
|
||||||
|
|
||||||
### Ansible
|
|
||||||
|
|
||||||
First, you need to [install Ansible on your local computer](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) (e.g. using `sudo apt install ansible`) or the equivalent for you platform.
|
|
||||||
|
|
||||||
Then run the following commands on your local computer:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/dessalines/lemmy.git
|
|
||||||
cd lemmy/ansible/
|
|
||||||
cp inventory.example inventory
|
|
||||||
nano inventory # enter your server, domain, contact email
|
|
||||||
ansible-playbook lemmy.yml --become
|
|
||||||
```
|
|
||||||
|
|
||||||
### Kubernetes
|
|
||||||
|
|
||||||
You'll need to have an existing Kubernetes cluster and [storage class](https://kubernetes.io/docs/concepts/storage/storage-classes/).
|
|
||||||
Setting this up will vary depending on your provider.
|
|
||||||
To try it locally, you can use [MicroK8s](https://microk8s.io/) or [Minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/).
|
|
||||||
|
|
||||||
Once you have a working cluster, edit the environment variables and volume sizes in `docker/k8s/*.yml`.
|
|
||||||
You may also want to change the service types to use `LoadBalancer`s depending on where you're running your cluster (add `type: LoadBalancer` to `ports)`, or `NodePort`s.
|
|
||||||
By default they will use `ClusterIP`s, which will allow access only within the cluster. See the [docs](https://kubernetes.io/docs/concepts/services-networking/service/) for more on networking in Kubernetes.
|
|
||||||
|
|
||||||
**Important** Running a database in Kubernetes will work, but is generally not recommended.
|
|
||||||
If you're deploying on any of the common cloud providers, you should consider using their managed database service instead (RDS, Cloud SQL, Azure Databse, etc.).
|
|
||||||
|
|
||||||
Now you can deploy:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Add `-n foo` if you want to deploy into a specific namespace `foo`;
|
|
||||||
# otherwise your resources will be created in the `default` namespace.
|
|
||||||
kubectl apply -f docker/k8s/db.yml
|
|
||||||
kubectl apply -f docker/k8s/pictshare.yml
|
|
||||||
kubectl apply -f docker/k8s/lemmy.yml
|
|
||||||
```
|
|
||||||
|
|
||||||
If you used a `LoadBalancer`, you should see it in your cloud provider's console.
|
|
||||||
|
|
||||||
## Develop
|
|
||||||
|
|
||||||
### Docker Development
|
|
||||||
|
|
||||||
Run:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/dessalines/lemmy
|
|
||||||
cd lemmy/docker/dev
|
|
||||||
./docker_update.sh # This builds and runs it, updating for your changes
|
|
||||||
```
|
|
||||||
|
|
||||||
and go to http://localhost:8536.
|
|
||||||
|
|
||||||
### Local Development
|
|
||||||
|
|
||||||
#### Requirements
|
|
||||||
|
|
||||||
- [Rust](https://www.rust-lang.org/)
|
|
||||||
- [Yarn](https://yarnpkg.com/en/)
|
|
||||||
- [Postgres](https://www.postgresql.org/)
|
|
||||||
|
|
||||||
#### Set up Postgres DB
|
|
||||||
|
|
||||||
```bash
|
|
||||||
psql -c "create user lemmy with password 'password' superuser;" -U postgres
|
|
||||||
psql -c 'create database lemmy with owner lemmy;' -U postgres
|
|
||||||
export DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Running
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/dessalines/lemmy
|
|
||||||
cd lemmy
|
|
||||||
./install.sh
|
|
||||||
# For live coding, where both the front and back end, automagically reload on any save, do:
|
|
||||||
# cd ui && yarn start
|
|
||||||
# cd server && cargo watch -x run
|
|
||||||
```
|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
- [Websocket API for App developers](docs/api.md)
|
|
||||||
- [ActivityPub API.md](docs/apub_api_outline.md)
|
|
||||||
- [Goals](docs/goals.md)
|
|
||||||
- [Ranking Algorithm](docs/ranking.md)
|
|
||||||
|
|
||||||
## Support
|
|
||||||
|
|
||||||
Lemmy is free, open-source software, meaning no advertising, monetizing, or venture capital, ever. Your donations directly support full-time development of the project.
|
Lemmy is free, open-source software, meaning no advertising, monetizing, or venture capital, ever. Your donations directly support full-time development of the project.
|
||||||
|
|
||||||
|
- [Support on Liberapay.](https://liberapay.com/Lemmy)
|
||||||
- [Support on Patreon](https://www.patreon.com/dessalines).
|
- [Support on Patreon](https://www.patreon.com/dessalines).
|
||||||
- [Sponsor List](https://dev.lemmy.ml/sponsors).
|
- [List of Sponsors](https://dev.lemmy.ml/sponsors).
|
||||||
|
|
||||||
|
### Crypto
|
||||||
|
|
||||||
- bitcoin: `1Hefs7miXS5ff5Ck5xvmjKjXf5242KzRtK`
|
- bitcoin: `1Hefs7miXS5ff5Ck5xvmjKjXf5242KzRtK`
|
||||||
- ethereum: `0x400c96c96acbC6E7B3B43B1dc1BB446540a88A01`
|
- ethereum: `0x400c96c96acbC6E7B3B43B1dc1BB446540a88A01`
|
||||||
- monero: `41taVyY6e1xApqKyMVDRVxJ76sPkfZhALLTjRvVKpaAh2pBd4wv9RgYj1tSPrx8wc6iE1uWUfjtQdTmTy2FGMeChGVKPQuV`
|
- monero: `41taVyY6e1xApqKyMVDRVxJ76sPkfZhALLTjRvVKpaAh2pBd4wv9RgYj1tSPrx8wc6iE1uWUfjtQdTmTy2FGMeChGVKPQuV`
|
||||||
|
|
||||||
## Translations
|
## Contributing
|
||||||
|
|
||||||
If you'd like to add translations, take a look a look at the [English translation file](ui/src/translations/en.ts).
|
- [Contributing instructions](https://dev.lemmy.ml/docs/contributing.html)
|
||||||
|
- [Docker Development](https://dev.lemmy.ml/docs/contributing_docker_development.html)
|
||||||
|
- [Local Development](https://dev.lemmy.ml/docs/contributing_local_development.html)
|
||||||
|
|
||||||
- Languages supported: English (`en`), Chinese (`zh`), Dutch (`nl`), Esperanto (`eo`), French (`fr`), Spanish (`es`), Swedish (`sv`), German (`de`), Russian (`ru`), Italian (`it`).
|
### Translations
|
||||||
|
|
||||||
lang | done | missing
|
If you want to help with translating, take a look at [Weblate](https://weblate.yerbamate.dev/projects/lemmy/).
|
||||||
--- | --- | ---
|
|
||||||
de | 100% |
|
|
||||||
eo | 86% | number_of_communities,preview,upload_image,formatting_help,view_source,sticky,unsticky,archive_link,stickied,delete_account,delete_account_confirm,banned,creator,number_online,replies,mentions,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,language,browser_default,theme,are_you_sure,yes,no
|
|
||||||
es | 95% | archive_link,replies,mentions,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,language,browser_default
|
|
||||||
fr | 95% | archive_link,replies,mentions,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,language,browser_default
|
|
||||||
it | 96% | archive_link,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,language,browser_default
|
|
||||||
nl | 88% | preview,upload_image,formatting_help,view_source,sticky,unsticky,archive_link,stickied,delete_account,delete_account_confirm,banned,creator,number_online,replies,mentions,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,language,browser_default,theme
|
|
||||||
ru | 82% | cross_posts,cross_post,number_of_communities,preview,upload_image,formatting_help,view_source,sticky,unsticky,archive_link,stickied,delete_account,delete_account_confirm,banned,creator,number_online,replies,mentions,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,language,browser_default,recent_comments,theme,monero,by,to,transfer_community,transfer_site,are_you_sure,yes,no
|
|
||||||
sv | 95% | archive_link,replies,mentions,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,language,browser_default
|
|
||||||
zh | 80% | cross_posts,cross_post,users,number_of_communities,preview,upload_image,formatting_help,view_source,sticky,unsticky,archive_link,settings,stickied,delete_account,delete_account_confirm,banned,creator,number_online,replies,mentions,forgot_password,reset_password_mail_sent,password_change,new_password,no_email_setup,language,browser_default,recent_comments,nsfw,show_nsfw,theme,monero,by,to,transfer_community,transfer_site,are_you_sure,yes,no
|
|
||||||
|
|
||||||
|
## Contact
|
||||||
|
|
||||||
If you'd like to update this report, run:
|
- [Mastodon](https://mastodon.social/@LemmyDev) - [![Mastodon Follow](https://img.shields.io/mastodon/follow/810572?domain=https%3A%2F%2Fmastodon.social&style=social)](https://mastodon.social/@LemmyDev)
|
||||||
|
- [Matrix](https://riot.im/app/#/room/#rust-reddit-fediverse:matrix.org) - [![Matrix](https://img.shields.io/matrix/rust-reddit-fediverse:matrix.org.svg?label=matrix-chat)](https://riot.im/app/#/room/#rust-reddit-fediverse:matrix.org)
|
||||||
```bash
|
- [GitHub](https://github.com/dessalines/lemmy)
|
||||||
cd ui
|
- [Gitea](https://yerbamate.dev/dessalines/lemmy)
|
||||||
ts-node translation_report.ts > tmp # And replace the text above.
|
- [GitLab](https://gitlab.com/dessalines/lemmy)
|
||||||
```
|
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
|
|
22
RELEASES.md
vendored
Normal file
22
RELEASES.md
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Lemmy v0.6.0 Release (2020-01-16)
|
||||||
|
|
||||||
|
`v0.6.0` is here, and we've closed [41 issues!](https://github.com/dessalines/lemmy/milestone/15?closed=1)
|
||||||
|
|
||||||
|
This is the biggest release by far:
|
||||||
|
|
||||||
|
- Avatars!
|
||||||
|
- Optional Email notifications for username mentions, post and comment replies.
|
||||||
|
- Ability to change your password and email address.
|
||||||
|
- Can set a custom language.
|
||||||
|
- Lemmy-wide settings to disable downvotes, and close registration.
|
||||||
|
- A better documentation system, hosted in lemmy itself.
|
||||||
|
- [Huge DB performance gains](https://github.com/dessalines/lemmy/issues/411) (everthing down to < `30ms`) by using materialized views.
|
||||||
|
- Fixed major issue with similar post URL and title searching.
|
||||||
|
- Upgraded to Actix `2.0`
|
||||||
|
- Faster comment / post voting.
|
||||||
|
- Better small screen support.
|
||||||
|
- Lots of bug fixes, refactoring of back end code.
|
||||||
|
|
||||||
|
Another major announcement is that Lemmy now has another lead developer besides me, [@felix@radical.town](https://radical.town/@felix). Theyve created a better documentation system, implemented RSS feeds, simplified docker and project configs, upgraded actix, working on federation, a whole lot else.
|
||||||
|
|
||||||
|
https://dev.lemmy.ml
|
1
ansible/VERSION
vendored
Normal file
1
ansible/VERSION
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
v0.6.39
|
27
ansible/lemmy.yml
vendored
27
ansible/lemmy.yml
vendored
|
@ -29,23 +29,20 @@
|
||||||
- { path: '/lemmy/' }
|
- { path: '/lemmy/' }
|
||||||
- { path: '/lemmy/volumes/' }
|
- { path: '/lemmy/volumes/' }
|
||||||
|
|
||||||
- name: add all template files
|
- block:
|
||||||
template: src={{item.src}} dest={{item.dest}}
|
- name: add template files
|
||||||
with_items:
|
template: src={{item.src}} dest={{item.dest}} mode={{item.mode}}
|
||||||
- { src: 'templates/env', dest: '/lemmy/.env' }
|
with_items:
|
||||||
- { src: '../docker/prod/docker-compose.yml', dest: '/lemmy/docker-compose.yml' }
|
- { src: 'templates/docker-compose.yml', dest: '/lemmy/docker-compose.yml', mode: '0600' }
|
||||||
- { src: 'templates/nginx.conf', dest: '/etc/nginx/sites-enabled/lemmy.conf' }
|
- { src: 'templates/nginx.conf', dest: '/etc/nginx/sites-enabled/lemmy.conf', mode: '0644' }
|
||||||
|
- { src: '../docker/iframely.config.local.js', dest: '/lemmy/iframely.config.local.js', mode: '0600' }
|
||||||
|
|
||||||
|
- name: add config file (only during initial setup)
|
||||||
|
template: src='templates/config.hjson' dest='/lemmy/lemmy.hjson' mode='0600' force='no' owner='1000' group='1000'
|
||||||
vars:
|
vars:
|
||||||
postgres_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/postgres chars=ascii_letters,digits') }}"
|
postgres_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/postgres chars=ascii_letters,digits') }}"
|
||||||
jwt_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/jwt chars=ascii_letters,digits') }}"
|
jwt_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/jwt chars=ascii_letters,digits') }}"
|
||||||
|
lemmy_docker_image: "dessalines/lemmy:{{ lookup('file', 'VERSION') }}"
|
||||||
- name: set env file permissions
|
|
||||||
file:
|
|
||||||
path: "/lemmy/.env"
|
|
||||||
state: touch
|
|
||||||
mode: 0600
|
|
||||||
access_time: preserve
|
|
||||||
modification_time: preserve
|
|
||||||
|
|
||||||
- name: enable and start docker service
|
- name: enable and start docker service
|
||||||
systemd:
|
systemd:
|
||||||
|
@ -67,4 +64,4 @@
|
||||||
special_time=daily
|
special_time=daily
|
||||||
name=certbot-renew-lemmy
|
name=certbot-renew-lemmy
|
||||||
user=root
|
user=root
|
||||||
job="certbot certonly --nginx -d '{{ domain }}' --deploy-hook 'docker-compose -f /peertube/docker-compose.yml exec nginx nginx -s reload'"
|
job="certbot certonly --nginx -d '{{ domain }}' --deploy-hook 'nginx -s reload'"
|
||||||
|
|
101
ansible/lemmy_dev.yml
vendored
Normal file
101
ansible/lemmy_dev.yml
vendored
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
vars:
|
||||||
|
lemmy_docker_image: "lemmy:dev"
|
||||||
|
|
||||||
|
# Install python if required
|
||||||
|
# https://www.josharcher.uk/code/ansible-python-connection-failure-ubuntu-server-1604/
|
||||||
|
gather_facts: False
|
||||||
|
pre_tasks:
|
||||||
|
- name: install python for Ansible
|
||||||
|
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal python-setuptools)
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
|
register: output
|
||||||
|
changed_when: output.stdout != ""
|
||||||
|
- setup: # gather facts
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: install dependencies
|
||||||
|
apt:
|
||||||
|
pkg: ['nginx', 'docker-compose', 'docker.io', 'certbot', 'python-certbot-nginx']
|
||||||
|
|
||||||
|
- name: request initial letsencrypt certificate
|
||||||
|
command: certbot certonly --nginx --agree-tos -d '{{ domain }}' -m '{{ letsencrypt_contact_email }}'
|
||||||
|
args:
|
||||||
|
creates: '/etc/letsencrypt/live/{{domain}}/privkey.pem'
|
||||||
|
|
||||||
|
- name: create lemmy folder
|
||||||
|
file: path={{item.path}} state=directory
|
||||||
|
with_items:
|
||||||
|
- { path: '/lemmy/' }
|
||||||
|
- { path: '/lemmy/volumes/' }
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: add template files
|
||||||
|
template: src={{item.src}} dest={{item.dest}} mode={{item.mode}}
|
||||||
|
with_items:
|
||||||
|
- { src: 'templates/docker-compose.yml', dest: '/lemmy/docker-compose.yml', mode: '0600' }
|
||||||
|
- { src: 'templates/nginx.conf', dest: '/etc/nginx/sites-enabled/lemmy.conf', mode: '0644' }
|
||||||
|
- { src: '../docker/iframely.config.local.js', dest: '/lemmy/iframely.config.local.js', mode: '0600' }
|
||||||
|
|
||||||
|
- name: add config file (only during initial setup)
|
||||||
|
template: src='templates/config.hjson' dest='/lemmy/lemmy.hjson' mode='0600' force='no' owner='1000' group='1000'
|
||||||
|
vars:
|
||||||
|
postgres_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/postgres chars=ascii_letters,digits') }}"
|
||||||
|
jwt_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/jwt chars=ascii_letters,digits') }}"
|
||||||
|
|
||||||
|
- name: build the dev docker image
|
||||||
|
local_action: shell cd .. && sudo docker build . -f docker/dev/Dockerfile -t lemmy:dev
|
||||||
|
register: image_build
|
||||||
|
|
||||||
|
- name: find hash of the new docker image
|
||||||
|
set_fact:
|
||||||
|
image_hash: "{{ image_build.stdout | regex_search('(?<=Successfully built )[0-9a-f]{12}') }}"
|
||||||
|
|
||||||
|
# this does not use become so that the output file is written as non-root user and is easy to delete later
|
||||||
|
- name: save dev docker image to file
|
||||||
|
local_action: shell sudo docker save lemmy:dev > lemmy-dev.tar
|
||||||
|
|
||||||
|
- name: copy dev docker image to server
|
||||||
|
copy: src=lemmy-dev.tar dest=/lemmy/lemmy-dev.tar
|
||||||
|
|
||||||
|
- name: import docker image
|
||||||
|
docker_image:
|
||||||
|
name: lemmy
|
||||||
|
tag: dev
|
||||||
|
load_path: /lemmy/lemmy-dev.tar
|
||||||
|
source: load
|
||||||
|
force_source: yes
|
||||||
|
register: image_import
|
||||||
|
|
||||||
|
- name: delete remote image file
|
||||||
|
file: path=/lemmy/lemmy-dev.tar state=absent
|
||||||
|
|
||||||
|
- name: delete local image file
|
||||||
|
local_action: file path=lemmy-dev.tar state=absent
|
||||||
|
|
||||||
|
- name: enable and start docker service
|
||||||
|
systemd:
|
||||||
|
name: docker
|
||||||
|
enabled: yes
|
||||||
|
state: started
|
||||||
|
|
||||||
|
# cant pull here because that fails due to lemmy:dev (without dessalines/) not being on docker hub, but that shouldnt
|
||||||
|
# be a problem for testing
|
||||||
|
- name: start docker-compose
|
||||||
|
docker_compose:
|
||||||
|
project_src: /lemmy/
|
||||||
|
state: present
|
||||||
|
recreate: always
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: reload nginx with new config
|
||||||
|
shell: nginx -s reload
|
||||||
|
|
||||||
|
- name: certbot renewal cronjob
|
||||||
|
cron:
|
||||||
|
special_time=daily
|
||||||
|
name=certbot-renew-lemmy
|
||||||
|
user=root
|
||||||
|
job="certbot certonly --nginx -d '{{ domain }}' --deploy-hook 'nginx -s reload'"
|
14
ansible/templates/config.hjson
vendored
Normal file
14
ansible/templates/config.hjson
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
database: {
|
||||||
|
password: "{{ postgres_password }}"
|
||||||
|
host: "postgres"
|
||||||
|
}
|
||||||
|
hostname: "{{ domain }}"
|
||||||
|
jwt_secret: "{{ jwt_password }}"
|
||||||
|
front_end_dir: "/app/dist"
|
||||||
|
email: {
|
||||||
|
smtp_server: "postfix:25"
|
||||||
|
smtp_from_address: "noreply@{{ domain }}"
|
||||||
|
use_tls: false
|
||||||
|
}
|
||||||
|
}
|
48
ansible/templates/docker-compose.yml
vendored
Normal file
48
ansible/templates/docker-compose.yml
vendored
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
version: '3.3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
lemmy:
|
||||||
|
image: {{ lemmy_docker_image }}
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8536:8536"
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- RUST_LOG=debug
|
||||||
|
volumes:
|
||||||
|
- ./lemmy.hjson:/config/config.hjson:ro
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
||||||
|
- pictshare
|
||||||
|
- iframely
|
||||||
|
|
||||||
|
postgres:
|
||||||
|
image: postgres:12-alpine
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER=lemmy
|
||||||
|
- POSTGRES_PASSWORD={{ postgres_password }}
|
||||||
|
- POSTGRES_DB=lemmy
|
||||||
|
volumes:
|
||||||
|
- ./volumes/postgres:/var/lib/postgresql/data
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
pictshare:
|
||||||
|
image: shtripok/pictshare:latest
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8537:80"
|
||||||
|
volumes:
|
||||||
|
- ./volumes/pictshare:/usr/share/nginx/html/data
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
iframely:
|
||||||
|
image: dogbin/iframely:latest
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8061:80"
|
||||||
|
volumes:
|
||||||
|
- ./iframely.config.local.js:/iframely/config.local.js:ro
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
postfix:
|
||||||
|
image: mwader/postfix-relay
|
||||||
|
environment:
|
||||||
|
- POSTFIX_myhostname={{ domain }}
|
||||||
|
restart: "always"
|
14
ansible/templates/env
vendored
14
ansible/templates/env
vendored
|
@ -1,14 +0,0 @@
|
||||||
DOMAIN={{ domain }}
|
|
||||||
DATABASE_PASSWORD={{ postgres_password }}
|
|
||||||
DATABASE_URL=postgres://lemmy:{{ postgres_password }}@lemmy_db:5432/lemmy
|
|
||||||
JWT_SECRET={{ jwt_password }}
|
|
||||||
RATE_LIMIT_MESSAGE=30
|
|
||||||
RATE_LIMIT_MESSAGE_PER_SECOND=60
|
|
||||||
RATE_LIMIT_POST=3
|
|
||||||
RATE_LIMIT_POST_PER_SECOND=600
|
|
||||||
RATE_LIMIT_REGISTER=3
|
|
||||||
RATE_LIMIT_REGISTER_PER_SECOND=3600
|
|
||||||
SMTP_SERVER={{ smtp_server }}
|
|
||||||
SMTP_LOGIN={{ smtp_login }}
|
|
||||||
SMTP_PASSWORD={{ smtp_password }}
|
|
||||||
SMTP_FROM_ADDRESS={{ smtp_from_address }}
|
|
21
ansible/templates/nginx.conf
vendored
21
ansible/templates/nginx.conf
vendored
|
@ -1,3 +1,5 @@
|
||||||
|
proxy_cache_path /var/cache/lemmy_frontend levels=1:2 keys_zone=lemmy_frontend_cache:10m max_size=100m use_temp_path=off;
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name {{ domain }};
|
server_name {{ domain }};
|
||||||
|
@ -59,6 +61,13 @@ server {
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
|
|
||||||
|
# Proxy Cache
|
||||||
|
proxy_cache lemmy_frontend_cache;
|
||||||
|
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
|
||||||
|
proxy_cache_revalidate on;
|
||||||
|
proxy_cache_lock on;
|
||||||
|
proxy_cache_min_uses 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /pictshare/ {
|
location /pictshare/ {
|
||||||
|
@ -68,10 +77,16 @@ server {
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
|
||||||
if ($request_uri ~ \.(?:ico|gif|jpe?g|png|webp|bmp|mp4)$) {
|
if ($request_uri ~ \.(?:ico|gif|jpe?g|png|webp|bmp|mp4)$) {
|
||||||
add_header Cache-Control "public";
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||||
expires max;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /iframely/ {
|
||||||
|
proxy_pass http://0.0.0.0:8061/;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Anonymize IP addresses
|
# Anonymize IP addresses
|
||||||
|
@ -85,4 +100,4 @@ map $remote_addr $remote_addr_anon {
|
||||||
}
|
}
|
||||||
log_format main '$remote_addr_anon - $remote_user [$time_local] "$request" '
|
log_format main '$remote_addr_anon - $remote_user [$time_local] "$request" '
|
||||||
'$status $body_bytes_sent "$http_referer" "$http_user_agent"';
|
'$status $body_bytes_sent "$http_referer" "$http_user_agent"';
|
||||||
access_log /dev/stdout main;
|
access_log /var/log/nginx/access.log main;
|
||||||
|
|
48
ansible/uninstall.yml
vendored
Normal file
48
ansible/uninstall.yml
vendored
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
|
||||||
|
vars_prompt:
|
||||||
|
|
||||||
|
- name: confirm_uninstall
|
||||||
|
prompt: "Do you really want to uninstall Lemmy? This will delete all data and can not be reverted [yes/no]"
|
||||||
|
private: no
|
||||||
|
|
||||||
|
- name: delete_certs
|
||||||
|
prompt: "Delete certificates? Select 'no' if you want to reinstall Lemmy [yes/no]"
|
||||||
|
private: no
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: end play if no confirmation was given
|
||||||
|
debug:
|
||||||
|
msg: "Uninstall cancelled, doing nothing"
|
||||||
|
when: not confirm_uninstall|bool
|
||||||
|
|
||||||
|
- meta: end_play
|
||||||
|
when: not confirm_uninstall|bool
|
||||||
|
|
||||||
|
- name: stop docker-compose
|
||||||
|
docker_compose:
|
||||||
|
project_src: /lemmy/
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: delete data
|
||||||
|
file: path={{item.path}} state=absent
|
||||||
|
with_items:
|
||||||
|
- { path: '/lemmy/' }
|
||||||
|
- { path: '/etc/nginx/sites-enabled/lemmy.conf' }
|
||||||
|
|
||||||
|
- name: Remove a volume
|
||||||
|
docker_volume: name={{item.name}} state=absent
|
||||||
|
with_items:
|
||||||
|
- { name: 'lemmy_lemmy_db' }
|
||||||
|
- { name: 'lemmy_lemmy_pictshare' }
|
||||||
|
|
||||||
|
- name: delete entire ecloud folder
|
||||||
|
file: path='/mnt/repo-base/' state=absent
|
||||||
|
when: delete_certs|bool
|
||||||
|
|
||||||
|
- name: remove certbot cronjob
|
||||||
|
cron:
|
||||||
|
name=certbot-renew-lemmy
|
||||||
|
state=absent
|
||||||
|
|
17
docker/dev/.env
vendored
17
docker/dev/.env
vendored
|
@ -1,17 +0,0 @@
|
||||||
DOMAIN=my_domain
|
|
||||||
DATABASE_PASSWORD=password
|
|
||||||
DATABASE_URL=postgres://lemmy:password@lemmy_db:5432/lemmy
|
|
||||||
JWT_SECRET=changeme
|
|
||||||
|
|
||||||
RATE_LIMIT_MESSAGE=30
|
|
||||||
RATE_LIMIT_MESSAGE_PER_SECOND=60
|
|
||||||
RATE_LIMIT_POST=6
|
|
||||||
RATE_LIMIT_POST_PER_SECOND=600
|
|
||||||
RATE_LIMIT_REGISTER=3
|
|
||||||
RATE_LIMIT_REGISTER_PER_SECOND=3600
|
|
||||||
|
|
||||||
# Optional email fields
|
|
||||||
SMTP_SERVER=
|
|
||||||
SMTP_LOGIN=
|
|
||||||
SMTP_PASSWORD=
|
|
||||||
SMTP_FROM_ADDRESS=Domain.com Lemmy Admin <notifications@domain.com>
|
|
13
docker/dev/Dockerfile
vendored
13
docker/dev/Dockerfile
vendored
|
@ -10,7 +10,7 @@ RUN yarn install --pure-lockfile
|
||||||
COPY ui /app/ui
|
COPY ui /app/ui
|
||||||
RUN yarn build
|
RUN yarn build
|
||||||
|
|
||||||
FROM ekidd/rust-musl-builder:1.38.0-openssl11 as rust
|
FROM ekidd/rust-musl-builder:1.40.0-openssl11 as rust
|
||||||
|
|
||||||
# Cache deps
|
# Cache deps
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
@ -32,14 +32,25 @@ RUN cargo build --frozen --release
|
||||||
# Get diesel-cli on there just in case
|
# Get diesel-cli on there just in case
|
||||||
# RUN cargo install diesel_cli --no-default-features --features postgres
|
# RUN cargo install diesel_cli --no-default-features --features postgres
|
||||||
|
|
||||||
|
|
||||||
|
FROM ekidd/rust-musl-builder:1.40.0-openssl11 as docs
|
||||||
|
WORKDIR /app
|
||||||
|
COPY docs ./docs
|
||||||
|
RUN sudo chown -R rust:rust .
|
||||||
|
RUN mdbook build docs/
|
||||||
|
|
||||||
|
|
||||||
FROM alpine:3.10
|
FROM alpine:3.10
|
||||||
|
|
||||||
# Install libpq for postgres
|
# Install libpq for postgres
|
||||||
RUN apk add libpq
|
RUN apk add libpq
|
||||||
|
|
||||||
# Copy resources
|
# Copy resources
|
||||||
|
COPY server/config/defaults.hjson /config/defaults.hjson
|
||||||
COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/release/lemmy_server /app/lemmy
|
COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/release/lemmy_server /app/lemmy
|
||||||
|
COPY --from=docs /app/docs/book/ /app/dist/documentation/
|
||||||
COPY --from=node /app/ui/dist /app/dist
|
COPY --from=node /app/ui/dist /app/dist
|
||||||
|
|
||||||
RUN addgroup -g 1000 lemmy
|
RUN addgroup -g 1000 lemmy
|
||||||
RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
|
RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
|
||||||
RUN chown lemmy:lemmy /app/lemmy
|
RUN chown lemmy:lemmy /app/lemmy
|
||||||
|
|
3
docker/dev/Dockerfile.aarch64
vendored
3
docker/dev/Dockerfile.aarch64
vendored
|
@ -15,7 +15,7 @@ RUN yarn build
|
||||||
FROM multiarch/qemu-user-static as qemu
|
FROM multiarch/qemu-user-static as qemu
|
||||||
|
|
||||||
|
|
||||||
FROM arm64v8/rust:1.37-buster as rust
|
FROM arm64v8/rust:1.40-buster as rust
|
||||||
|
|
||||||
COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin
|
COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin
|
||||||
#COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin
|
#COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin
|
||||||
|
@ -69,6 +69,7 @@ RUN addgroup --gid 1000 lemmy
|
||||||
RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
|
RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
|
||||||
|
|
||||||
# Copy resources
|
# Copy resources
|
||||||
|
COPY server/config/defaults.hjson /config/defaults.hjson
|
||||||
COPY --from=rust /app/server/ready /app/lemmy
|
COPY --from=rust /app/server/ready /app/lemmy
|
||||||
COPY --from=node /app/ui/dist /app/dist
|
COPY --from=node /app/ui/dist /app/dist
|
||||||
|
|
||||||
|
|
1
docker/dev/Dockerfile.armv7hf
vendored
1
docker/dev/Dockerfile.armv7hf
vendored
|
@ -69,6 +69,7 @@ RUN addgroup --gid 1000 lemmy
|
||||||
RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
|
RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
|
||||||
|
|
||||||
# Copy resources
|
# Copy resources
|
||||||
|
COPY server/config/defaults.hjson /config/defaults.hjson
|
||||||
COPY --from=rust /app/server/ready /app/lemmy
|
COPY --from=rust /app/server/ready /app/lemmy
|
||||||
COPY --from=node /app/ui/dist /app/dist
|
COPY --from=node /app/ui/dist /app/dist
|
||||||
|
|
||||||
|
|
33
docker/dev/Dockerfile.libc
vendored
33
docker/dev/Dockerfile.libc
vendored
|
@ -20,10 +20,11 @@ COPY ui /app/ui
|
||||||
RUN yarn build
|
RUN yarn build
|
||||||
|
|
||||||
|
|
||||||
FROM rust:1.37 as rust
|
FROM rust:1.40 as rust
|
||||||
|
|
||||||
# Cache deps
|
# Cache deps
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN USER=root cargo new server
|
RUN USER=root cargo new server
|
||||||
WORKDIR /app/server
|
WORKDIR /app/server
|
||||||
COPY server/Cargo.toml server/Cargo.lock ./
|
COPY server/Cargo.toml server/Cargo.lock ./
|
||||||
|
@ -31,24 +32,35 @@ RUN mkdir -p ./src/bin \
|
||||||
&& echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
|
&& echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
|
||||||
|
|
||||||
|
|
||||||
#RUN cargo build --release
|
RUN cargo build --release
|
||||||
RUN cargo build && \
|
#RUN cargo build && \
|
||||||
rm -f ./target/release/deps/lemmy_server* ; rm -f ./target/debug/deps/lemmy_server*
|
# rm -f ./target/release/deps/lemmy_server* ; rm -f ./target/debug/deps/lemmy_server*
|
||||||
COPY server/src ./src/
|
COPY server/src ./src/
|
||||||
COPY server/migrations ./migrations/
|
COPY server/migrations ./migrations/
|
||||||
|
|
||||||
|
|
||||||
# build for release
|
# build for release
|
||||||
# workaround for https://github.com/rust-lang/rust/issues/62896
|
# workaround for https://github.com/rust-lang/rust/issues/62896
|
||||||
#RUN RUSTFLAGS='-Ccodegen-units=1' cargo build --release
|
#RUN RUSTFLAGS='-Ccodegen-units=1' cargo build --release
|
||||||
#RUN cargo build --release --frozen
|
RUN cargo build --release --frozen
|
||||||
RUN cargo build --frozen
|
#RUN cargo build --frozen
|
||||||
|
|
||||||
# Get diesel-cli on there just in case
|
# Get diesel-cli on there just in case
|
||||||
# RUN cargo install diesel_cli --no-default-features --features postgres
|
# RUN cargo install diesel_cli --no-default-features --features postgres
|
||||||
|
|
||||||
# make result place always the same for lemmy container
|
# make result place always the same for lemmy container
|
||||||
#RUN cp /app/server/target/release/lemmy_server /app/server/ready
|
RUN cp /app/server/target/release/lemmy_server /app/server/ready
|
||||||
RUN cp /app/server/target/debug/lemmy_server /app/server/ready
|
#RUN cp /app/server/target/debug/lemmy_server /app/server/ready
|
||||||
|
|
||||||
|
|
||||||
|
FROM rust:1.40 as docs
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Build docs
|
||||||
|
COPY docs ./docs
|
||||||
|
RUN cargo install mdbook
|
||||||
|
RUN mdbook build docs/
|
||||||
|
|
||||||
|
|
||||||
#FROM alpine:3.10
|
#FROM alpine:3.10
|
||||||
|
@ -65,8 +77,11 @@ RUN addgroup --gid 1000 lemmy
|
||||||
RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
|
RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy
|
||||||
|
|
||||||
# Copy resources
|
# Copy resources
|
||||||
COPY --from=rust /app/server/ready /app/lemmy
|
COPY server/config/defaults.hjson /config/defaults.hjson
|
||||||
COPY --from=node /app/ui/dist /app/dist
|
COPY --from=node /app/ui/dist /app/dist
|
||||||
|
COPY --from=docs /app/docs/book/ /app/dist/documentation/
|
||||||
|
COPY --from=rust /app/server/ready /app/lemmy
|
||||||
|
|
||||||
RUN chown lemmy:lemmy /app/lemmy
|
RUN chown lemmy:lemmy /app/lemmy
|
||||||
USER lemmy
|
USER lemmy
|
||||||
EXPOSE 8536
|
EXPOSE 8536
|
||||||
|
|
42
docker/dev/deploy.sh
vendored
42
docker/dev/deploy.sh
vendored
|
@ -1,29 +1,36 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
git checkout master
|
git checkout master
|
||||||
|
|
||||||
|
# Import translations
|
||||||
|
git fetch weblate
|
||||||
|
git merge weblate/master
|
||||||
|
|
||||||
# Creating the new tag
|
# Creating the new tag
|
||||||
new_tag="$1"
|
new_tag="$1"
|
||||||
git tag $new_tag
|
third_semver=$(echo $new_tag | cut -d "." -f 3)
|
||||||
|
|
||||||
# Setting the version on the front end
|
# Setting the version on the front end
|
||||||
cd ../../
|
cd ../../
|
||||||
echo "export let version: string = '$(git describe --tags)';" > "ui/src/version.ts"
|
echo "export const version: string = '$new_tag';" > "ui/src/version.ts"
|
||||||
git add "ui/src/version.ts"
|
git add "ui/src/version.ts"
|
||||||
# Setting the version on the backend
|
# Setting the version on the backend
|
||||||
echo "pub const VERSION: &'static str = \"$(git describe --tags)\";" > "server/src/version.rs"
|
echo "pub const VERSION: &str = \"$new_tag\";" > "server/src/version.rs"
|
||||||
git add "server/src/version.rs"
|
git add "server/src/version.rs"
|
||||||
|
# Setting the version for Ansible
|
||||||
|
echo $new_tag > "ansible/VERSION"
|
||||||
|
git add "ansible/VERSION"
|
||||||
|
|
||||||
cd docker/dev
|
cd docker/dev || exit
|
||||||
|
|
||||||
# Changing the docker-compose prod
|
# Changing the docker-compose prod
|
||||||
sed -i "s/dessalines\/lemmy:.*/dessalines\/lemmy:$new_tag/" ../prod/docker-compose.yml
|
sed -i "s/dessalines\/lemmy:.*/dessalines\/lemmy:$new_tag/" ../prod/docker-compose.yml
|
||||||
|
sed -i "s/dessalines\/lemmy:.*/dessalines\/lemmy:$new_tag/" ../../ansible/templates/docker-compose.yml
|
||||||
git add ../prod/docker-compose.yml
|
git add ../prod/docker-compose.yml
|
||||||
|
git add ../../ansible/templates/docker-compose.yml
|
||||||
|
|
||||||
# The commit
|
# The commit
|
||||||
git commit -m"Version $new_tag"
|
git commit -m"Version $new_tag"
|
||||||
|
git tag $new_tag
|
||||||
# Registering qemu binaries
|
|
||||||
docker run --rm --privileged multiarch/qemu-user-static:register --reset
|
|
||||||
|
|
||||||
# Rebuilding docker
|
# Rebuilding docker
|
||||||
docker-compose build
|
docker-compose build
|
||||||
|
@ -38,14 +45,25 @@ docker push dessalines/lemmy:x64-$new_tag
|
||||||
# docker push dessalines/lemmy:armv7hf-$new_tag
|
# docker push dessalines/lemmy:armv7hf-$new_tag
|
||||||
|
|
||||||
# aarch64
|
# aarch64
|
||||||
docker build -t lemmy:aarch64 -f Dockerfile.aarch64 ../../
|
# Only do this on major releases (IE the third semver is 0)
|
||||||
docker tag lemmy:aarch64 dessalines/lemmy:arm64-$new_tag
|
if [ $third_semver -eq 0 ]; then
|
||||||
docker push dessalines/lemmy:arm64-$new_tag
|
# Registering qemu binaries
|
||||||
|
docker run --rm --privileged multiarch/qemu-user-static:register --reset
|
||||||
|
|
||||||
|
docker build -t lemmy:aarch64 -f Dockerfile.aarch64 ../../
|
||||||
|
docker tag lemmy:aarch64 dessalines/lemmy:arm64-$new_tag
|
||||||
|
docker push dessalines/lemmy:arm64-$new_tag
|
||||||
|
fi
|
||||||
|
|
||||||
# Creating the manifest for the multi-arch build
|
# Creating the manifest for the multi-arch build
|
||||||
docker manifest create dessalines/lemmy:$new_tag \
|
if [ $third_semver -eq 0 ]; then
|
||||||
|
docker manifest create dessalines/lemmy:$new_tag \
|
||||||
dessalines/lemmy:x64-$new_tag \
|
dessalines/lemmy:x64-$new_tag \
|
||||||
dessalines/lemmy:arm64-$new_tag
|
dessalines/lemmy:arm64-$new_tag
|
||||||
|
else
|
||||||
|
docker manifest create dessalines/lemmy:$new_tag \
|
||||||
|
dessalines/lemmy:x64-$new_tag
|
||||||
|
fi
|
||||||
|
|
||||||
docker manifest push dessalines/lemmy:$new_tag
|
docker manifest push dessalines/lemmy:$new_tag
|
||||||
|
|
||||||
|
@ -54,5 +72,5 @@ git push origin $new_tag
|
||||||
git push
|
git push
|
||||||
|
|
||||||
# Pushing to any ansible deploys
|
# Pushing to any ansible deploys
|
||||||
cd ../../ansible
|
cd ../../ansible || exit
|
||||||
ansible-playbook lemmy.yml --become
|
ansible-playbook lemmy.yml --become
|
||||||
|
|
3
docker/dev/dev_deploy.sh
vendored
3
docker/dev/dev_deploy.sh
vendored
|
@ -7,3 +7,6 @@ git checkout dev
|
||||||
docker-compose build
|
docker-compose build
|
||||||
docker tag dev_lemmy:latest dessalines/lemmy:dev
|
docker tag dev_lemmy:latest dessalines/lemmy:dev
|
||||||
docker push dessalines/lemmy:dev
|
docker push dessalines/lemmy:dev
|
||||||
|
|
||||||
|
# SSH and pull it
|
||||||
|
ssh $LEMMY_USER@$LEMMY_HOST "cd ~/git/lemmy/docker/dev && docker pull dessalines/lemmy:dev && docker-compose up -d"
|
||||||
|
|
46
docker/dev/docker-compose.yml
vendored
46
docker/dev/docker-compose.yml
vendored
|
@ -1,46 +1,44 @@
|
||||||
version: '3.3'
|
version: '3.3'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
lemmy_db:
|
postgres:
|
||||||
image: postgres:12-alpine
|
image: postgres:12-alpine
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_USER=lemmy
|
- POSTGRES_USER=lemmy
|
||||||
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
|
- POSTGRES_PASSWORD=password
|
||||||
- POSTGRES_DB=lemmy
|
- POSTGRES_DB=lemmy
|
||||||
volumes:
|
volumes:
|
||||||
- lemmy_db:/var/lib/postgresql/data
|
- ./volumes/postgres:/var/lib/postgresql/data
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
lemmy:
|
lemmy:
|
||||||
build:
|
build:
|
||||||
context: ../../
|
context: ../../
|
||||||
dockerfile: docker/dev/Dockerfile
|
dockerfile: docker/dev/Dockerfile
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8536:8536"
|
- "127.0.0.1:8536:8536"
|
||||||
environment:
|
|
||||||
- LEMMY_FRONT_END_DIR=/app/dist
|
|
||||||
- DATABASE_URL=${DATABASE_URL}
|
|
||||||
- JWT_SECRET=${JWT_SECRET}
|
|
||||||
- HOSTNAME=${DOMAIN}
|
|
||||||
- RATE_LIMIT_MESSAGE=${RATE_LIMIT_MESSAGE}
|
|
||||||
- RATE_LIMIT_MESSAGE_PER_SECOND=${RATE_LIMIT_MESSAGE_PER_SECOND}
|
|
||||||
- RATE_LIMIT_POST=${RATE_LIMIT_POST}
|
|
||||||
- RATE_LIMIT_POST_PER_SECOND=${RATE_LIMIT_POST_PER_SECOND}
|
|
||||||
- RATE_LIMIT_REGISTER=${RATE_LIMIT_REGISTER}
|
|
||||||
- RATE_LIMIT_REGISTER_PER_SECOND=${RATE_LIMIT_REGISTER_PER_SECOND}
|
|
||||||
- SMTP_SERVER=${SMTP_SERVER}
|
|
||||||
- SMTP_LOGIN=${SMTP_LOGIN}
|
|
||||||
- SMTP_PASSWORD=${SMTP_PASSWORD}
|
|
||||||
- SMTP_FROM_ADDRESS=${SMTP_FROM_ADDRESS}
|
|
||||||
restart: always
|
restart: always
|
||||||
|
environment:
|
||||||
|
- RUST_LOG=debug
|
||||||
|
volumes:
|
||||||
|
- ../lemmy.hjson:/config/config.hjson:ro
|
||||||
depends_on:
|
depends_on:
|
||||||
- lemmy_db
|
- postgres
|
||||||
lemmy_pictshare:
|
- pictshare
|
||||||
|
- iframely
|
||||||
|
|
||||||
|
pictshare:
|
||||||
image: shtripok/pictshare:latest
|
image: shtripok/pictshare:latest
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8537:80"
|
- "127.0.0.1:8537:80"
|
||||||
volumes:
|
volumes:
|
||||||
- lemmy_pictshare:/usr/share/nginx/html/data
|
- ./volumes/pictshare:/usr/share/nginx/html/data
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
iframely:
|
||||||
|
image: dogbin/iframely:latest
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8061:80"
|
||||||
|
volumes:
|
||||||
|
- ../iframely.config.local.js:/iframely/config.local.js:ro
|
||||||
restart: always
|
restart: always
|
||||||
volumes:
|
|
||||||
lemmy_db:
|
|
||||||
lemmy_pictshare:
|
|
||||||
|
|
17
docker/federation-test/Dockerfile
vendored
Normal file
17
docker/federation-test/Dockerfile
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
FROM ekidd/rust-musl-builder:1.38.0-openssl11
|
||||||
|
|
||||||
|
USER root
|
||||||
|
RUN mkdir /app/dist/documentation/ -p \
|
||||||
|
&& addgroup --gid 1001 lemmy \
|
||||||
|
&& adduser --disabled-password --shell /bin/sh -u 1001 --ingroup lemmy lemmy
|
||||||
|
|
||||||
|
# Copy resources
|
||||||
|
COPY server/config/defaults.hjson /app/config/defaults.hjson
|
||||||
|
COPY ui/dist /app/dist
|
||||||
|
COPY server/target/debug/lemmy_server /app/lemmy
|
||||||
|
|
||||||
|
RUN chown lemmy:lemmy /app/ -R
|
||||||
|
USER lemmy
|
||||||
|
EXPOSE 8536
|
||||||
|
WORKDIR /app
|
||||||
|
CMD ["/app/lemmy"]
|
64
docker/federation-test/docker-compose.yml
vendored
Normal file
64
docker/federation-test/docker-compose.yml
vendored
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
version: '3.3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
lemmy_alpha:
|
||||||
|
image: lemmy-federation-test:latest
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8540:8540"
|
||||||
|
environment:
|
||||||
|
- LEMMY_HOSTNAME=lemmy_alpha:8540
|
||||||
|
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_alpha:5432/lemmy
|
||||||
|
- LEMMY_JWT_SECRET=changeme
|
||||||
|
- LEMMY_FRONT_END_DIR=/app/dist
|
||||||
|
- LEMMY_FEDERATION__ENABLED=true
|
||||||
|
- LEMMY_FEDERATION__FOLLOWED_INSTANCES=lemmy_beta:8541
|
||||||
|
- LEMMY_FEDERATION__TLS_ENABLED=false
|
||||||
|
- LEMMY_PORT=8540
|
||||||
|
- RUST_BACKTRACE=1
|
||||||
|
restart: always
|
||||||
|
depends_on:
|
||||||
|
- postgres_alpha
|
||||||
|
postgres_alpha:
|
||||||
|
image: postgres:12-alpine
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER=lemmy
|
||||||
|
- POSTGRES_PASSWORD=password
|
||||||
|
- POSTGRES_DB=lemmy
|
||||||
|
volumes:
|
||||||
|
- ./volumes/postgres_alpha:/var/lib/postgresql/data
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
lemmy_beta:
|
||||||
|
image: lemmy-federation-test:latest
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8541:8541"
|
||||||
|
environment:
|
||||||
|
- LEMMY_HOSTNAME=lemmy_beta:8541
|
||||||
|
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_beta:5432/lemmy
|
||||||
|
- LEMMY_JWT_SECRET=changeme
|
||||||
|
- LEMMY_FRONT_END_DIR=/app/dist
|
||||||
|
- LEMMY_FEDERATION__ENABLED=true
|
||||||
|
- LEMMY_FEDERATION__FOLLOWED_INSTANCES=lemmy_alpha:8540
|
||||||
|
- LEMMY_FEDERATION__TLS_ENABLED=false
|
||||||
|
- LEMMY_PORT=8541
|
||||||
|
- RUST_BACKTRACE=1
|
||||||
|
restart: always
|
||||||
|
depends_on:
|
||||||
|
- postgres_beta
|
||||||
|
postgres_beta:
|
||||||
|
image: postgres:12-alpine
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER=lemmy
|
||||||
|
- POSTGRES_PASSWORD=password
|
||||||
|
- POSTGRES_DB=lemmy
|
||||||
|
volumes:
|
||||||
|
- ./volumes/postgres_beta:/var/lib/postgresql/data
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
iframely:
|
||||||
|
image: dogbin/iframely:latest
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8061:80"
|
||||||
|
volumes:
|
||||||
|
- ../iframely.config.local.js:/iframely/config.local.js:ro
|
||||||
|
restart: always
|
14
docker/federation-test/run-federation-test.bash
vendored
Executable file
14
docker/federation-test/run-federation-test.bash
vendored
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
pushd ../../ui/ || exit
|
||||||
|
yarn build
|
||||||
|
popd || exit
|
||||||
|
|
||||||
|
pushd ../../server/ || exit
|
||||||
|
cargo build
|
||||||
|
popd || exit
|
||||||
|
|
||||||
|
sudo docker build ../../ -f Dockerfile -t lemmy-federation-test:latest
|
||||||
|
|
||||||
|
sudo docker-compose up
|
283
docker/iframely.config.local.js
vendored
Normal file
283
docker/iframely.config.local.js
vendored
Normal file
|
@ -0,0 +1,283 @@
|
||||||
|
(function() {
|
||||||
|
var config = {
|
||||||
|
|
||||||
|
// Specify a path for custom plugins. Custom plugins will override core plugins.
|
||||||
|
// CUSTOM_PLUGINS_PATH: __dirname + '/yourcustom-plugin-folder',
|
||||||
|
|
||||||
|
DEBUG: false,
|
||||||
|
RICH_LOG_ENABLED: false,
|
||||||
|
|
||||||
|
// For embeds that require render, baseAppUrl will be used as the host.
|
||||||
|
baseAppUrl: "http://yourdomain.com",
|
||||||
|
relativeStaticUrl: "/r",
|
||||||
|
|
||||||
|
// Or just skip built-in renders altogether
|
||||||
|
SKIP_IFRAMELY_RENDERS: true,
|
||||||
|
|
||||||
|
// For legacy reasons the response format of Iframely open-source is
|
||||||
|
// different by default as it does not group the links array by rel.
|
||||||
|
// In order to get the same grouped response as in Cloud API,
|
||||||
|
// add `&group=true` to your request to change response per request
|
||||||
|
// or set `GROUP_LINKS` in your config to `true` for a global change.
|
||||||
|
GROUP_LINKS: true,
|
||||||
|
|
||||||
|
// Number of maximum redirects to follow before aborting the page
|
||||||
|
// request with `redirect loop` error.
|
||||||
|
MAX_REDIRECTS: 4,
|
||||||
|
|
||||||
|
SKIP_OEMBED_RE_LIST: [
|
||||||
|
// /^https?:\/\/yourdomain\.com\//,
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Used to pass parameters to the generate functions when creating HTML elements
|
||||||
|
// disableSizeWrapper: Don't wrap element (iframe, video, etc) in a positioned div
|
||||||
|
GENERATE_LINK_PARAMS: {
|
||||||
|
disableSizeWrapper: true
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
|
||||||
|
port: 80, //can be overridden by PORT env var
|
||||||
|
host: '0.0.0.0', // Dockers beware. See https://github.com/itteco/iframely/issues/132#issuecomment-242991246
|
||||||
|
//can be overridden by HOST env var
|
||||||
|
|
||||||
|
// Optional SSL cert, if you serve under HTTPS.
|
||||||
|
/*
|
||||||
|
ssl: {
|
||||||
|
key: require('fs').readFileSync(__dirname + '/key.pem'),
|
||||||
|
cert: require('fs').readFileSync(__dirname + '/cert.pem'),
|
||||||
|
port: 443
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Supported cache engines:
|
||||||
|
- no-cache - no caching will be used.
|
||||||
|
- node-cache - good for debug, node memory will be used (https://github.com/tcs-de/nodecache).
|
||||||
|
- redis - https://github.com/mranney/node_redis.
|
||||||
|
- memcached - https://github.com/3rd-Eden/node-memcached
|
||||||
|
*/
|
||||||
|
CACHE_ENGINE: 'node-cache',
|
||||||
|
CACHE_TTL: 0, // In seconds.
|
||||||
|
// 0 = 'never expire' for memcached & node-cache to let cache engine decide itself when to evict the record
|
||||||
|
// 0 = 'no cache' for redis. Use high enough (e.g. 365*24*60*60*1000) ttl for similar 'never expire' approach instead
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Redis cache options.
|
||||||
|
REDIS_OPTIONS: {
|
||||||
|
host: '127.0.0.1',
|
||||||
|
port: 6379
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Memcached options. See https://github.com/3rd-Eden/node-memcached#server-locations
|
||||||
|
MEMCACHED_OPTIONS: {
|
||||||
|
locations: "127.0.0.1:11211"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Access-Control-Allow-Origin list.
|
||||||
|
allowedOrigins: [
|
||||||
|
"*",
|
||||||
|
"http://another_domain.com"
|
||||||
|
],
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Uncomment to enable plugin testing framework.
|
||||||
|
tests: {
|
||||||
|
mongodb: 'mongodb://localhost:27017/iframely-tests',
|
||||||
|
single_test_timeout: 10 * 1000,
|
||||||
|
plugin_test_period: 2 * 60 * 60 * 1000,
|
||||||
|
relaunch_script_period: 5 * 60 * 1000
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
|
||||||
|
// If there's no response from remote server, the timeout will occur after
|
||||||
|
RESPONSE_TIMEOUT: 5 * 1000, //ms
|
||||||
|
|
||||||
|
/* From v1.4.0, Iframely supports HTTP/2 by default. Disable it, if you'd rather not.
|
||||||
|
Alternatively, you can also disable per origin. See `proxy` option below.
|
||||||
|
*/
|
||||||
|
// DISABLE_HTTP2: true,
|
||||||
|
|
||||||
|
// Customize API calls to oembed endpoints.
|
||||||
|
ADD_OEMBED_PARAMS: [{
|
||||||
|
// Endpoint url regexp array.
|
||||||
|
re: [/^http:\/\/api\.instagram\.com\/oembed/],
|
||||||
|
// Custom get params object.
|
||||||
|
params: {
|
||||||
|
hidecaption: true
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
re: [/^https:\/\/www\.facebook\.com\/plugins\/page\/oembed\.json/i],
|
||||||
|
params: {
|
||||||
|
show_posts: 0,
|
||||||
|
show_facepile: 0,
|
||||||
|
maxwidth: 600
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
// match i=user or i=moment or i=timeline to configure these types invidually
|
||||||
|
// see params spec at https://dev.twitter.com/web/embedded-timelines/oembed
|
||||||
|
re: [/^https?:\/\/publish\.twitter\.com\/oembed\?i=user/i],
|
||||||
|
params: {
|
||||||
|
limit: 1,
|
||||||
|
maxwidth: 600
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
}, {
|
||||||
|
// Facebook https://developers.facebook.com/docs/plugins/oembed-endpoints
|
||||||
|
re: [/^https:\/\/www\.facebook\.com\/plugins\/\w+\/oembed\.json/i],
|
||||||
|
params: {
|
||||||
|
// Skip script tag and fb-root div.
|
||||||
|
omitscript: true
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}],
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Configure use of HTTP proxies as needed.
|
||||||
|
// You don't have to specify all options per regex - just what you need to override
|
||||||
|
PROXY: [{
|
||||||
|
re: [/^https?:\/\/www\.domain\.com/],
|
||||||
|
proxy_server: 'http://1.2.3.4:8080',
|
||||||
|
user_agent: 'CHANGE YOUR AGENT',
|
||||||
|
headers: {
|
||||||
|
// HTTP headers
|
||||||
|
// Overrides previous params if overlapped.
|
||||||
|
},
|
||||||
|
request_options: {
|
||||||
|
// Refer to: https://github.com/request/request
|
||||||
|
// Overrides previous params if overlapped.
|
||||||
|
},
|
||||||
|
disable_http2: true
|
||||||
|
}],
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Customize API calls to 3rd parties. At the very least - configure required keys.
|
||||||
|
providerOptions: {
|
||||||
|
locale: "en_US", // ISO 639-1 two-letter language code, e.g. en_CA or fr_CH.
|
||||||
|
// Will be added as highest priotity in accept-language header with each request.
|
||||||
|
// Plus is used in FB, YouTube and perhaps other plugins
|
||||||
|
"twitter": {
|
||||||
|
"max-width": 550,
|
||||||
|
"min-width": 250,
|
||||||
|
hide_media: false,
|
||||||
|
hide_thread: false,
|
||||||
|
omit_script: false,
|
||||||
|
center: false,
|
||||||
|
// dnt: true,
|
||||||
|
cache_ttl: 100 * 365 * 24 * 3600 // 100 Years.
|
||||||
|
},
|
||||||
|
readability: {
|
||||||
|
enabled: false
|
||||||
|
// allowPTagDescription: true // to enable description fallback to first paragraph
|
||||||
|
},
|
||||||
|
images: {
|
||||||
|
loadSize: false, // if true, will try an load first bytes of all images to get/confirm the sizes
|
||||||
|
checkFavicon: false // if true, will verify all favicons
|
||||||
|
},
|
||||||
|
tumblr: {
|
||||||
|
consumer_key: "INSERT YOUR VALUE"
|
||||||
|
// media_only: true // disables status embeds for images and videos - will return plain media
|
||||||
|
},
|
||||||
|
google: {
|
||||||
|
// https://developers.google.com/maps/documentation/embed/guide#api_key
|
||||||
|
maps_key: "INSERT YOUR VALUE"
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Optional Camo Proxy to wrap all images: https://github.com/atmos/camo
|
||||||
|
camoProxy: {
|
||||||
|
camo_proxy_key: "INSERT YOUR VALUE",
|
||||||
|
camo_proxy_host: "INSERT YOUR VALUE"
|
||||||
|
// ssl_only: true // will only proxy non-ssl images
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
|
||||||
|
// List of query parameters to add to YouTube and Vimeo frames
|
||||||
|
// Start it with leading "?". Or omit alltogether for default values
|
||||||
|
// API key is optional, youtube will work without it too.
|
||||||
|
// It is probably the same API key you use for Google Maps.
|
||||||
|
youtube: {
|
||||||
|
// api_key: "INSERT YOUR VALUE",
|
||||||
|
get_params: "?rel=0&showinfo=1" // https://developers.google.com/youtube/player_parameters
|
||||||
|
},
|
||||||
|
vimeo: {
|
||||||
|
get_params: "?byline=0&badge=0" // https://developer.vimeo.com/player/embedding
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
soundcloud: {
|
||||||
|
old_player: true // enables classic player
|
||||||
|
},
|
||||||
|
giphy: {
|
||||||
|
media_only: true // disables branded player for gifs and returns just the image
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
bandcamp: {
|
||||||
|
get_params: '/size=large/bgcol=333333/linkcol=ffffff/artwork=small/transparent=true/',
|
||||||
|
media: {
|
||||||
|
album: {
|
||||||
|
height: 472,
|
||||||
|
'max-width': 700
|
||||||
|
},
|
||||||
|
track: {
|
||||||
|
height: 120,
|
||||||
|
'max-width': 700
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
},
|
||||||
|
|
||||||
|
// WHITELIST_WILDCARD, if present, will be added to whitelist as record for top level domain: "*"
|
||||||
|
// with it, you can define what parsers do when they run accross unknown publisher.
|
||||||
|
// If absent or empty, all generic media parsers will be disabled except for known domains
|
||||||
|
// More about format: https://iframely.com/docs/qa-format
|
||||||
|
|
||||||
|
/*
|
||||||
|
WHITELIST_WILDCARD: {
|
||||||
|
"twitter": {
|
||||||
|
"player": "allow",
|
||||||
|
"photo": "deny"
|
||||||
|
},
|
||||||
|
"oembed": {
|
||||||
|
"video": "allow",
|
||||||
|
"photo": "allow",
|
||||||
|
"rich": "deny",
|
||||||
|
"link": "deny"
|
||||||
|
},
|
||||||
|
"og": {
|
||||||
|
"video": ["allow", "ssl", "responsive"]
|
||||||
|
},
|
||||||
|
"iframely": {
|
||||||
|
"survey": "allow",
|
||||||
|
"reader": "allow",
|
||||||
|
"player": "allow",
|
||||||
|
"image": "allow"
|
||||||
|
},
|
||||||
|
"html-meta": {
|
||||||
|
"video": ["allow", "responsive"],
|
||||||
|
"promo": "allow"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Black-list any of the inappropriate domains. Iframely will return 417
|
||||||
|
// At minimum, keep your localhosts blacklisted to avoid SSRF
|
||||||
|
BLACKLIST_DOMAINS_RE: [
|
||||||
|
/^https?:\/\/127\.0\.0\.1/i,
|
||||||
|
/^https?:\/\/localhost/i,
|
||||||
|
|
||||||
|
// And this is AWS metadata service
|
||||||
|
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
|
||||||
|
/^https?:\/\/169\.254\.169\.254/
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = config;
|
||||||
|
})();
|
6
docker/k8s/lemmy.yml
vendored
6
docker/k8s/lemmy.yml
vendored
|
@ -14,13 +14,13 @@ spec:
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- env:
|
- env:
|
||||||
- name: DATABASE_URL
|
- name: LEMMY_DATABASE_URL
|
||||||
# example: 'postgres://lemmy:password@db:5432/lemmy'
|
# example: 'postgres://lemmy:password@db:5432/lemmy'
|
||||||
value: CHANGE_ME
|
value: CHANGE_ME
|
||||||
- name: HOSTNAME
|
- name: LEMMY_HOSTNAME
|
||||||
# example: 'lemmy.example.com'
|
# example: 'lemmy.example.com'
|
||||||
value: CHANGE_ME
|
value: CHANGE_ME
|
||||||
- name: JWT_SECRET
|
- name: LEMMY_JWT_SECRET
|
||||||
# example: 'very-super-good-secret'
|
# example: 'very-super-good-secret'
|
||||||
value: CHANGE_ME
|
value: CHANGE_ME
|
||||||
- name: LEMMY_FRONT_END_DIR
|
- name: LEMMY_FRONT_END_DIR
|
||||||
|
|
56
docker/lemmy.hjson
vendored
Normal file
56
docker/lemmy.hjson
vendored
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
{
|
||||||
|
database: {
|
||||||
|
# username to connect to postgres
|
||||||
|
user: "lemmy"
|
||||||
|
# password to connect to postgres
|
||||||
|
password: "password"
|
||||||
|
# host where postgres is running
|
||||||
|
host: "postgres"
|
||||||
|
# port where postgres can be accessed
|
||||||
|
port: 5432
|
||||||
|
# name of the postgres database for lemmy
|
||||||
|
database: "lemmy"
|
||||||
|
# maximum number of active sql connections
|
||||||
|
pool_size: 5
|
||||||
|
}
|
||||||
|
# the domain name of your instance (eg "dev.lemmy.ml")
|
||||||
|
hostname: "my_domain"
|
||||||
|
# address where lemmy should listen for incoming requests
|
||||||
|
bind: "0.0.0.0"
|
||||||
|
# port where lemmy should listen for incoming requests
|
||||||
|
port: 8536
|
||||||
|
# json web token for authorization between server and client
|
||||||
|
jwt_secret: "changeme"
|
||||||
|
# The dir for the front end
|
||||||
|
front_end_dir: "/app/dist"
|
||||||
|
# whether to enable activitypub federation. this feature is in alpha, do not enable in production, as might
|
||||||
|
# cause problems like remote instances fetching and permanently storing bad data.
|
||||||
|
federation_enabled: false
|
||||||
|
# rate limits for various user actions, by user ip
|
||||||
|
rate_limit: {
|
||||||
|
# maximum number of messages created in interval
|
||||||
|
message: 180
|
||||||
|
# interval length for message limit
|
||||||
|
message_per_second: 60
|
||||||
|
# maximum number of posts created in interval
|
||||||
|
post: 6
|
||||||
|
# interval length for post limit
|
||||||
|
post_per_second: 600
|
||||||
|
# maximum number of registrations in interval
|
||||||
|
register: 3
|
||||||
|
# interval length for registration limit
|
||||||
|
register_per_second: 3600
|
||||||
|
}
|
||||||
|
# # email sending configuration
|
||||||
|
# email: {
|
||||||
|
# # hostname of the smtp server
|
||||||
|
# smtp_server: ""
|
||||||
|
# # login name for smtp server
|
||||||
|
# smtp_login: ""
|
||||||
|
# # password to login to the smtp server
|
||||||
|
# smtp_password: ""
|
||||||
|
# # address to send emails from, eg "info@your-instance.com"
|
||||||
|
# smtp_from_address: ""
|
||||||
|
# }
|
||||||
|
}
|
||||||
|
|
17
docker/prod/.env
vendored
17
docker/prod/.env
vendored
|
@ -1,17 +0,0 @@
|
||||||
DOMAIN=my_domain
|
|
||||||
DATABASE_PASSWORD=password
|
|
||||||
DATABASE_URL=postgres://lemmy:password@lemmy_db:5432/lemmy
|
|
||||||
JWT_SECRET=changeme
|
|
||||||
|
|
||||||
RATE_LIMIT_MESSAGE=30
|
|
||||||
RATE_LIMIT_MESSAGE_PER_SECOND=60
|
|
||||||
RATE_LIMIT_POST=6
|
|
||||||
RATE_LIMIT_POST_PER_SECOND=600
|
|
||||||
RATE_LIMIT_REGISTER=3
|
|
||||||
RATE_LIMIT_REGISTER_PER_SECOND=3600
|
|
||||||
|
|
||||||
# Optional email fields
|
|
||||||
SMTP_SERVER=
|
|
||||||
SMTP_LOGIN=
|
|
||||||
SMTP_PASSWORD=
|
|
||||||
SMTP_FROM_ADDRESS=Domain.com Lemmy Admin <notifications@domain.com>
|
|
48
docker/prod/docker-compose.yml
vendored
48
docker/prod/docker-compose.yml
vendored
|
@ -1,44 +1,42 @@
|
||||||
version: '3.3'
|
version: '3.3'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
lemmy_db:
|
postgres:
|
||||||
image: postgres:12-alpine
|
image: postgres:12-alpine
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_USER=lemmy
|
- POSTGRES_USER=lemmy
|
||||||
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
|
- POSTGRES_PASSWORD=password
|
||||||
- POSTGRES_DB=lemmy
|
- POSTGRES_DB=lemmy
|
||||||
volumes:
|
volumes:
|
||||||
- lemmy_db:/var/lib/postgresql/data
|
- ./volumes/postgres:/var/lib/postgresql/data
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
lemmy:
|
lemmy:
|
||||||
image: dessalines/lemmy:v0.5.0.3
|
image: dessalines/lemmy:v0.6.39
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8536:8536"
|
- "127.0.0.1:8536:8536"
|
||||||
environment:
|
|
||||||
- LEMMY_FRONT_END_DIR=/app/dist
|
|
||||||
- DATABASE_URL=${DATABASE_URL}
|
|
||||||
- JWT_SECRET=${JWT_SECRET}
|
|
||||||
- HOSTNAME=${DOMAIN}
|
|
||||||
- RATE_LIMIT_MESSAGE=${RATE_LIMIT_MESSAGE}
|
|
||||||
- RATE_LIMIT_MESSAGE_PER_SECOND=${RATE_LIMIT_MESSAGE_PER_SECOND}
|
|
||||||
- RATE_LIMIT_POST=${RATE_LIMIT_POST}
|
|
||||||
- RATE_LIMIT_POST_PER_SECOND=${RATE_LIMIT_POST_PER_SECOND}
|
|
||||||
- RATE_LIMIT_REGISTER=${RATE_LIMIT_REGISTER}
|
|
||||||
- RATE_LIMIT_REGISTER_PER_SECOND=${RATE_LIMIT_REGISTER_PER_SECOND}
|
|
||||||
- SMTP_SERVER=${SMTP_SERVER}
|
|
||||||
- SMTP_LOGIN=${SMTP_LOGIN}
|
|
||||||
- SMTP_PASSWORD=${SMTP_PASSWORD}
|
|
||||||
- SMTP_FROM_ADDRESS=${SMTP_FROM_ADDRESS}
|
|
||||||
restart: always
|
restart: always
|
||||||
|
environment:
|
||||||
|
- RUST_LOG=debug
|
||||||
|
volumes:
|
||||||
|
- ./lemmy.hjson:/config/config.hjson:ro
|
||||||
depends_on:
|
depends_on:
|
||||||
- lemmy_db
|
- postgres
|
||||||
lemmy_pictshare:
|
- pictshare
|
||||||
|
- iframely
|
||||||
|
|
||||||
|
pictshare:
|
||||||
image: shtripok/pictshare:latest
|
image: shtripok/pictshare:latest
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8537:80"
|
- "127.0.0.1:8537:80"
|
||||||
volumes:
|
volumes:
|
||||||
- lemmy_pictshare:/usr/share/nginx/html/data
|
- ./volumes/pictshare:/usr/share/nginx/html/data
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
iframely:
|
||||||
|
image: dogbin/iframely:latest
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8061:80"
|
||||||
|
volumes:
|
||||||
|
- ./iframely.config.local.js:/iframely/config.local.js:ro
|
||||||
restart: always
|
restart: always
|
||||||
volumes:
|
|
||||||
lemmy_db:
|
|
||||||
lemmy_pictshare:
|
|
||||||
|
|
1
docs/.gitignore
vendored
Normal file
1
docs/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
book
|
6
docs/book.toml
vendored
Normal file
6
docs/book.toml
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[book]
|
||||||
|
authors = ["Felix Ableitner"]
|
||||||
|
language = "en"
|
||||||
|
multilingual = false
|
||||||
|
src = "src"
|
||||||
|
title = "Lemmy Documentation"
|
19
docs/src/SUMMARY.md
vendored
Normal file
19
docs/src/SUMMARY.md
vendored
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Summary
|
||||||
|
|
||||||
|
- [About](about.md)
|
||||||
|
- [Features](about_features.md)
|
||||||
|
- [Goals](about_goals.md)
|
||||||
|
- [Post and Comment Ranking](about_ranking.md)
|
||||||
|
- [Guide](about_guide.md)
|
||||||
|
- [Administration](administration.md)
|
||||||
|
- [Install with Docker](administration_install_docker.md)
|
||||||
|
- [Install with Ansible](administration_install_ansible.md)
|
||||||
|
- [Install with Kubernetes](administration_install_kubernetes.md)
|
||||||
|
- [Configuration](administration_configuration.md)
|
||||||
|
- [Contributing](contributing.md)
|
||||||
|
- [Docker Development](contributing_docker_development.md)
|
||||||
|
- [Local Development](contributing_local_development.md)
|
||||||
|
- [Websocket/HTTP API](contributing_websocket_http_api.md)
|
||||||
|
- [ActivityPub API Outline](contributing_apub_api_outline.md)
|
||||||
|
- [Theming Guide](contributing_theming.md)
|
||||||
|
- [Lemmy Council](lemmy_council.md)
|
30
docs/src/about.md
vendored
Normal file
30
docs/src/about.md
vendored
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
## About The Project
|
||||||
|
|
||||||
|
Front Page|Post
|
||||||
|
---|---
|
||||||
|
![main screen](https://i.imgur.com/kZSRcRu.png)|![chat screen](https://i.imgur.com/4XghNh6.png)
|
||||||
|
|
||||||
|
[Lemmy](https://github.com/dessalines/lemmy) is similar to sites like [Reddit](https://reddit.com), [Lobste.rs](https://lobste.rs), [Raddle](https://raddle.me), or [Hacker News](https://news.ycombinator.com/): you subscribe to forums you're interested in, post links and discussions, then vote, and comment on them. Behind the scenes, it is very different; anyone can easily run a server, and all these servers are federated (think email), and connected to the same universe, called the [Fediverse](https://en.wikipedia.org/wiki/Fediverse).
|
||||||
|
|
||||||
|
For a link aggregator, this means a user registered on one server can subscribe to forums on any other server, and can have discussions with users registered elsewhere.
|
||||||
|
|
||||||
|
The overall goal is to create an easily self-hostable, decentralized alternative to reddit and other link aggregators, outside of their corporate control and meddling.
|
||||||
|
|
||||||
|
Each lemmy server can set its own moderation policy; appointing site-wide admins, and community moderators to keep out the trolls, and foster a healthy, non-toxic environment where all can feel comfortable contributing.
|
||||||
|
|
||||||
|
*Note: Federation is still in active development*
|
||||||
|
|
||||||
|
### Why's it called Lemmy?
|
||||||
|
|
||||||
|
- Lead singer from [Motörhead](https://invidio.us/watch?v=pWB5JZRGl0U).
|
||||||
|
- The old school [video game](<https://en.wikipedia.org/wiki/Lemmings_(video_game)>).
|
||||||
|
- The [Koopa from Super Mario](https://www.mariowiki.com/Lemmy_Koopa).
|
||||||
|
- The [furry rodents](http://sunchild.fpwc.org/lemming-the-little-giant-of-the-north/).
|
||||||
|
|
||||||
|
### Built With
|
||||||
|
|
||||||
|
- [Rust](https://www.rust-lang.org)
|
||||||
|
- [Actix](https://actix.rs/)
|
||||||
|
- [Diesel](http://diesel.rs/)
|
||||||
|
- [Inferno](https://infernojs.org)
|
||||||
|
- [Typescript](https://www.typescriptlang.org/)
|
34
docs/src/about_features.md
vendored
Normal file
34
docs/src/about_features.md
vendored
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
# Features
|
||||||
|
|
||||||
|
- Open source, [AGPL License](/LICENSE).
|
||||||
|
- Self hostable, easy to deploy.
|
||||||
|
- Comes with [Docker](#docker), [Ansible](#ansible), [Kubernetes](#kubernetes).
|
||||||
|
- Clean, mobile-friendly interface.
|
||||||
|
- Only a minimum of a username and password is required to sign up!
|
||||||
|
- User avatar support.
|
||||||
|
- Live-updating Comment threads.
|
||||||
|
- Full vote scores `(+/-)` like old reddit.
|
||||||
|
- Themes, including light, dark, and solarized.
|
||||||
|
- Emojis with autocomplete support. Start typing `:`
|
||||||
|
- User tagging using `@`, Community tagging using `#`.
|
||||||
|
- Integrated image uploading in both posts and comments.
|
||||||
|
- A post can consist of a title and any combination of self text, a URL, or nothing else.
|
||||||
|
- Notifications, on comment replies and when you're tagged.
|
||||||
|
- Notifications can be sent via email.
|
||||||
|
- i18n / internationalization support.
|
||||||
|
- RSS / Atom feeds for `All`, `Subscribed`, `Inbox`, `User`, and `Community`.
|
||||||
|
- Cross-posting support.
|
||||||
|
- A *similar post search* when creating new posts. Great for question / answer communities.
|
||||||
|
- Moderation abilities.
|
||||||
|
- Public Moderation Logs.
|
||||||
|
- Can sticky posts to the top of communities.
|
||||||
|
- Both site admins, and community moderators, who can appoint other moderators.
|
||||||
|
- Can lock, remove, and restore posts and comments.
|
||||||
|
- Can ban and unban users from communities and the site.
|
||||||
|
- Can transfer site and communities to others.
|
||||||
|
- Can fully erase your data, replacing all posts and comments.
|
||||||
|
- NSFW post / community support.
|
||||||
|
- High performance.
|
||||||
|
- Server is written in rust.
|
||||||
|
- Front end is `~80kB` gzipped.
|
||||||
|
- Supports arm64 / Raspberry Pi.
|
23
docs/goals.md → docs/src/about_goals.md
vendored
23
docs/goals.md → docs/src/about_goals.md
vendored
|
@ -1,4 +1,5 @@
|
||||||
# Goals
|
# Goals
|
||||||
|
|
||||||
- Come up with a name / codename.
|
- Come up with a name / codename.
|
||||||
- Must have communities.
|
- Must have communities.
|
||||||
- Must have threaded comments.
|
- Must have threaded comments.
|
||||||
|
@ -7,6 +8,7 @@
|
||||||
- Use websockets for post / gets to your own instance.
|
- Use websockets for post / gets to your own instance.
|
||||||
|
|
||||||
# Questions
|
# Questions
|
||||||
|
|
||||||
- How does voting work? Should we go back to the old way of showing up and downvote counts? Or just a score?
|
- How does voting work? Should we go back to the old way of showing up and downvote counts? Or just a score?
|
||||||
- Decide on tech to be used
|
- Decide on tech to be used
|
||||||
- Backend: Actix, Diesel.
|
- Backend: Actix, Diesel.
|
||||||
|
@ -17,10 +19,7 @@
|
||||||
- On mobile, allow you to switch between them. Default?
|
- On mobile, allow you to switch between them. Default?
|
||||||
|
|
||||||
# Resources / Potential Libraries
|
# Resources / Potential Libraries
|
||||||
- Use the [activitypub crate.](https://docs.rs/activitypub/0.1.4/activitypub/)
|
|
||||||
- https://docs.rs/activitypub/0.1.4/activitypub/
|
|
||||||
- [Activitypub vocab.](https://www.w3.org/TR/activitystreams-vocabulary/)
|
|
||||||
- [Activitypub main](https://www.w3.org/TR/activitypub/)
|
|
||||||
- [Diesel to Postgres data types](https://kotiri.com/2018/01/31/postgresql-diesel-rust-types.html)
|
- [Diesel to Postgres data types](https://kotiri.com/2018/01/31/postgresql-diesel-rust-types.html)
|
||||||
- [helpful diesel examples](http://siciarz.net/24-days-rust-diesel/)
|
- [helpful diesel examples](http://siciarz.net/24-days-rust-diesel/)
|
||||||
- [Recursive query for adjacency list for nested comments](https://stackoverflow.com/questions/192220/what-is-the-most-efficient-elegant-way-to-parse-a-flat-table-into-a-tree/192462#192462)
|
- [Recursive query for adjacency list for nested comments](https://stackoverflow.com/questions/192220/what-is-the-most-efficient-elegant-way-to-parse-a-flat-table-into-a-tree/192462#192462)
|
||||||
|
@ -36,9 +35,15 @@
|
||||||
- [Temp Icon](https://www.flaticon.com/free-icon/mouse_194242)
|
- [Temp Icon](https://www.flaticon.com/free-icon/mouse_194242)
|
||||||
- [Rust docker build](https://shaneutt.com/blog/rust-fast-small-docker-image-builds/)
|
- [Rust docker build](https://shaneutt.com/blog/rust-fast-small-docker-image-builds/)
|
||||||
- [Zurb mentions](https://github.com/zurb/tribute)
|
- [Zurb mentions](https://github.com/zurb/tribute)
|
||||||
- Activitypub guides
|
- [TippyJS](https://github.com/atomiks/tippyjs)
|
||||||
- https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/
|
|
||||||
- https://raw.githubusercontent.com/w3c/activitypub/gh-pages/activitypub-tutorial.txt
|
|
||||||
- https://github.com/tOkeshu/activitypub-example
|
|
||||||
- https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/
|
|
||||||
|
|
||||||
|
## Activitypub guides
|
||||||
|
|
||||||
|
- https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/
|
||||||
|
- https://raw.githubusercontent.com/w3c/activitypub/gh-pages/activitypub-tutorial.txt
|
||||||
|
- https://github.com/tOkeshu/activitypub-example
|
||||||
|
- https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/
|
||||||
|
- Use the [activitypub crate.](https://docs.rs/activitypub/0.1.4/activitypub/)
|
||||||
|
- https://docs.rs/activitypub/0.1.4/activitypub/
|
||||||
|
- [Activitypub vocab.](https://www.w3.org/TR/activitystreams-vocabulary/)
|
||||||
|
- [Activitypub main](https://www.w3.org/TR/activitypub/)
|
40
docs/src/about_guide.md
vendored
Normal file
40
docs/src/about_guide.md
vendored
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# Lemmy Guide
|
||||||
|
|
||||||
|
Start typing...
|
||||||
|
|
||||||
|
- `@a_user_name` to get a list of usernames.
|
||||||
|
- `#a_community` to get a list of communities.
|
||||||
|
- `:emoji` to get a list of emojis.
|
||||||
|
|
||||||
|
## Sorting
|
||||||
|
|
||||||
|
*Applies to both posts and comments*
|
||||||
|
|
||||||
|
Type | Description
|
||||||
|
--- | ---
|
||||||
|
Hot | Shows *trending* posts, based on the score, and the most recent comment time.
|
||||||
|
New | Newest posts.
|
||||||
|
Top | Shows the highest scoring posts in the given time frame.
|
||||||
|
|
||||||
|
For more detail, check the [Post and Comment Ranking details](about_ranking.md).
|
||||||
|
|
||||||
|
## Markdown Guide
|
||||||
|
|
||||||
|
Type | Or | … to Get
|
||||||
|
--- | --- | ---
|
||||||
|
\*Italic\* | \_Italic\_ | _Italic_
|
||||||
|
\*\*Bold\*\* | \_\_Bold\_\_ | **Bold**
|
||||||
|
\# Heading 1 | Heading 1 <br> ========= | <h4>Heading 1</h4>
|
||||||
|
\## Heading 2 | Heading 2 <br>--------- | <h5>Heading 2</h5>
|
||||||
|
\[Link\](http://a.com) | \[Link\]\[1\]<br>⋮ <br>\[1\]: http://b.org | [Link](https://commonmark.org/)
|
||||||
|
!\[Image\](http://url/a.png) | !\[Image\]\[1\]<br>⋮ <br>\[1\]: http://url/b.jpg | ![Markdown](https://commonmark.org/help/images/favicon.png)
|
||||||
|
\> Blockquote | | <blockquote>Blockquote</blockquote>
|
||||||
|
\* List <br>\* List <br>\* List | \- List <br>\- List <br>\- List <br> | * List <br>* List <br>* List <br>
|
||||||
|
1\. One <br>2\. Two <br>3\. Three | 1) One<br>2) Two<br>3) Three | 1. One<br>2. Two<br>3. Three
|
||||||
|
Horizontal Rule <br>\--- | Horizontal Rule<br>\*\*\* | Horizontal Rule <br><hr>
|
||||||
|
\`Inline code\` with backticks | |`Inline code` with backticks
|
||||||
|
\`\`\`<br>\# code block <br>print '3 backticks or'<br>print 'indent 4 spaces' <br>\`\`\` | ····\# code block<br>····print '3 backticks or'<br>····print 'indent 4 spaces' | \# code block <br>print '3 backticks or'<br>print 'indent 4 spaces'
|
||||||
|
::: spoiler hidden or nsfw stuff<br>*a bunch of spoilers here*<br>::: | | <details><summary> hidden or nsfw stuff </summary><p><em>a bunch of spoilers here</em></p></details>
|
||||||
|
|
||||||
|
[CommonMark Tutorial](https://commonmark.org/help/tutorial/)
|
||||||
|
|
2
docs/ranking.md → docs/src/about_ranking.md
vendored
2
docs/ranking.md → docs/src/about_ranking.md
vendored
|
@ -18,7 +18,7 @@ Score = Upvotes - Downvotes
|
||||||
Time = time since submission (in hours)
|
Time = time since submission (in hours)
|
||||||
Gravity = Decay gravity, 1.8 is default
|
Gravity = Decay gravity, 1.8 is default
|
||||||
```
|
```
|
||||||
|
- For posts, in order to bring up active posts, it uses the latest comment time (limited to a max creation age of a month ago)
|
||||||
- Use Max(1, score) to make sure all comments are affected by time decay.
|
- Use Max(1, score) to make sure all comments are affected by time decay.
|
||||||
- Add 3 to the score, so that everything that has less than 3 downvotes will seem new. Otherwise all new comments would stay at zero, near the bottom.
|
- Add 3 to the score, so that everything that has less than 3 downvotes will seem new. Otherwise all new comments would stay at zero, near the bottom.
|
||||||
- The sign and abs of the score are necessary for dealing with the log of negative scores.
|
- The sign and abs of the score are necessary for dealing with the log of negative scores.
|
3
docs/src/administration.md
vendored
Normal file
3
docs/src/administration.md
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Admin info
|
||||||
|
|
||||||
|
Information for Lemmy instance admins, and those who want to start an instance.
|
15
docs/src/administration_configuration.md
vendored
Normal file
15
docs/src/administration_configuration.md
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# Configuration
|
||||||
|
|
||||||
|
The configuration is based on the file [defaults.hjson](server/config/defaults.hjson). This file also contains documentation for all the available options. To override the defaults, you can copy the options you want to change into your local `config.hjson` file.
|
||||||
|
|
||||||
|
Additionally, you can override any config files with environment variables. These have the same name as the config options, and are prefixed with `LEMMY_`. For example, you can override the `database.password` with
|
||||||
|
`LEMMY__DATABASE__POOL_SIZE=10`.
|
||||||
|
|
||||||
|
An additional option `LEMMY_DATABASE_URL` is available, which can be used with a PostgreSQL connection string like `postgres://lemmy:password@lemmy_db:5432/lemmy`, passing all connection details at once.
|
||||||
|
|
||||||
|
If the Docker container is not used, manually create the database specified above by running the following commands:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd server
|
||||||
|
./db-init.sh
|
||||||
|
```
|
13
docs/src/administration_install_ansible.md
vendored
Normal file
13
docs/src/administration_install_ansible.md
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Ansible Installation
|
||||||
|
|
||||||
|
First, you need to [install Ansible on your local computer](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) (e.g. using `sudo apt install ansible`) or the equivalent for you platform.
|
||||||
|
|
||||||
|
Then run the following commands on your local computer:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/dessalines/lemmy.git
|
||||||
|
cd lemmy/ansible/
|
||||||
|
cp inventory.example inventory
|
||||||
|
nano inventory # enter your server, domain, contact email
|
||||||
|
ansible-playbook lemmy.yml --become
|
||||||
|
```
|
31
docs/src/administration_install_docker.md
vendored
Normal file
31
docs/src/administration_install_docker.md
vendored
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# Docker Installation
|
||||||
|
|
||||||
|
Make sure you have both docker and docker-compose(>=`1.24.0`) installed:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir lemmy/
|
||||||
|
cd lemmy/
|
||||||
|
wget https://raw.githubusercontent.com/dessalines/lemmy/master/docker/prod/docker-compose.yml
|
||||||
|
wget https://raw.githubusercontent.com/dessalines/lemmy/master/docker/lemmy.hjson
|
||||||
|
wget https://raw.githubusercontent.com/dessalines/lemmy/master/docker/iframely.config.local.js
|
||||||
|
# Edit lemmy.hjson, and docker-compose.yml to do more configuration (like adding a custom password)
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
and go to http://localhost:8536.
|
||||||
|
|
||||||
|
[A sample nginx config](/ansible/templates/nginx.conf) (Note: Avatar / Image uploading won't work without this), could be setup with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wget https://raw.githubusercontent.com/dessalines/lemmy/master/ansible/templates/nginx.conf
|
||||||
|
# Replace the {{ vars }}
|
||||||
|
sudo mv nginx.conf /etc/nginx/sites-enabled/lemmy.conf
|
||||||
|
```
|
||||||
|
## Updating
|
||||||
|
|
||||||
|
To update to the newest version, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wget https://raw.githubusercontent.com/dessalines/lemmy/master/docker/prod/docker-compose.yml
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
24
docs/src/administration_install_kubernetes.md
vendored
Normal file
24
docs/src/administration_install_kubernetes.md
vendored
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# Kubernetes Installation
|
||||||
|
|
||||||
|
You'll need to have an existing Kubernetes cluster and [storage class](https://kubernetes.io/docs/concepts/storage/storage-classes/).
|
||||||
|
Setting this up will vary depending on your provider.
|
||||||
|
To try it locally, you can use [MicroK8s](https://microk8s.io/) or [Minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/).
|
||||||
|
|
||||||
|
Once you have a working cluster, edit the environment variables and volume sizes in `docker/k8s/*.yml`.
|
||||||
|
You may also want to change the service types to use `LoadBalancer`s depending on where you're running your cluster (add `type: LoadBalancer` to `ports)`, or `NodePort`s.
|
||||||
|
By default they will use `ClusterIP`s, which will allow access only within the cluster. See the [docs](https://kubernetes.io/docs/concepts/services-networking/service/) for more on networking in Kubernetes.
|
||||||
|
|
||||||
|
**Important** Running a database in Kubernetes will work, but is generally not recommended.
|
||||||
|
If you're deploying on any of the common cloud providers, you should consider using their managed database service instead (RDS, Cloud SQL, Azure Databse, etc.).
|
||||||
|
|
||||||
|
Now you can deploy:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Add `-n foo` if you want to deploy into a specific namespace `foo`;
|
||||||
|
# otherwise your resources will be created in the `default` namespace.
|
||||||
|
kubectl apply -f docker/k8s/db.yml
|
||||||
|
kubectl apply -f docker/k8s/pictshare.yml
|
||||||
|
kubectl apply -f docker/k8s/lemmy.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
If you used a `LoadBalancer`, you should see it in your cloud provider's console.
|
32
docs/src/contributing.md
vendored
Normal file
32
docs/src/contributing.md
vendored
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# Contributing
|
||||||
|
|
||||||
|
Information about contributing to Lemmy, whether it is translating, testing, designing or programming.
|
||||||
|
|
||||||
|
## Translating
|
||||||
|
|
||||||
|
Go [here](https://github.com/dessalines/lemmy#translations) for translation instructions.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
### Front end
|
||||||
|
|
||||||
|
- The front end is written in `typescript`, using a react-like framework called [inferno](https://infernojs.org/). All UI elements are reusable `.tsx` components.
|
||||||
|
- The main page and routing are in `ui/src/index.tsx`.
|
||||||
|
- The components are located in `ui/src/components`.
|
||||||
|
|
||||||
|
### Back end
|
||||||
|
|
||||||
|
- The back end is written in `rust`, using `diesel`, and `actix`.
|
||||||
|
- The server source code is split into main sections in `server/src`. These include:
|
||||||
|
- `db` - The low level database actions.
|
||||||
|
- Database additions are done using diesel migrations. Run `diesel migration generate xxxxx` to add new things.
|
||||||
|
- `api` - The high level user interactions (things like `CreateComment`)
|
||||||
|
- `routes` - The server endpoints .
|
||||||
|
- `apub` - The activitypub conversions.
|
||||||
|
- `websocket` - Creates the websocket server.
|
||||||
|
|
||||||
|
## Linting / Formatting
|
||||||
|
|
||||||
|
- Every front and back end commit is automatically formatted then linted using `husky`, and `lint-staged`.
|
||||||
|
- Rust with `cargo fmt` and `cargo clippy`.
|
||||||
|
- Typescript with `prettier` and `eslint`.
|
13
docs/src/contributing_docker_development.md
vendored
Normal file
13
docs/src/contributing_docker_development.md
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Docker Development
|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/dessalines/lemmy
|
||||||
|
cd lemmy/docker/dev
|
||||||
|
./docker_update.sh # This builds and runs it, updating for your changes
|
||||||
|
```
|
||||||
|
|
||||||
|
and go to http://localhost:8536.
|
||||||
|
|
||||||
|
Note that compile times when changing `Cargo.toml` are relatively long with Docker, because builds can't be incrementally cached. If this is a problem for you, you should use [Local Development](contributing_local_development.md).
|
31
docs/src/contributing_local_development.md
vendored
Normal file
31
docs/src/contributing_local_development.md
vendored
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#### Requirements
|
||||||
|
|
||||||
|
- [Rust](https://www.rust-lang.org/)
|
||||||
|
- [Yarn](https://yarnpkg.com/en/)
|
||||||
|
- [Postgres](https://www.postgresql.org/)
|
||||||
|
|
||||||
|
#### Set up Postgres DB
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd server
|
||||||
|
./db-init.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Or run the commands manually:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
psql -c "create user lemmy with password 'password' superuser;" -U postgres
|
||||||
|
psql -c 'create database lemmy with owner lemmy;' -U postgres
|
||||||
|
export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Running
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/dessalines/lemmy
|
||||||
|
cd lemmy
|
||||||
|
./install.sh
|
||||||
|
# For live coding, where both the front and back end, automagically reload on any save, do:
|
||||||
|
# cd ui && yarn start
|
||||||
|
# cd server && cargo watch -x run
|
||||||
|
```
|
18
docs/src/contributing_theming.md
vendored
Normal file
18
docs/src/contributing_theming.md
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Theming Guide
|
||||||
|
|
||||||
|
Lemmy uses [Bootstrap v4](https://getbootstrap.com/), and very few custom css classes, so any bootstrap v4 compatible theme should work fine.
|
||||||
|
|
||||||
|
## Creating
|
||||||
|
|
||||||
|
- Use a tool like [bootstrap.build](https://bootstrap.build/) to create a bootstrap v4 theme. Export the `bootstrap.min.css` once you're done, and save the `_variables.scss` too.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
- To test out a theme, you can either use your browser's web tools, or a plugin like stylus to copy-paste a theme, when viewing Lemmy.
|
||||||
|
|
||||||
|
## Adding
|
||||||
|
|
||||||
|
1. Copy `{my-theme-name}.min.css` to `ui/assets/css/themes`. (You can also copy the `_variables.scss` here if you want).
|
||||||
|
1. Go to `ui/src/utils.ts` and add `{my-theme-name}` to the themes list.
|
||||||
|
1. Test locally
|
||||||
|
1. Do a pull request with those changes.
|
File diff suppressed because it is too large
Load diff
53
docs/src/lemmy_council.md
vendored
Normal file
53
docs/src/lemmy_council.md
vendored
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
# Lemmy Council
|
||||||
|
|
||||||
|
- A group of lemmy developers and users that use a well-defined democratic process to steer the project in a positive direction, keep it aligned to community goals, and resolve conflicts.
|
||||||
|
|
||||||
|
## Voting / Decision-Making
|
||||||
|
|
||||||
|
### Process
|
||||||
|
- Anything is open for discussion
|
||||||
|
- Voting done through matrix chat reacts (thumbs up/thumbs down)
|
||||||
|
- Require a simple majority for votes. (Maybe 2/3rds for more debated decisions).
|
||||||
|
- Once a decision is reached democratically, the dicision is binding and all group members have to follow it
|
||||||
|
- All members of the Lemmy council have equal voting power.
|
||||||
|
- Voting must stay open for at least 2 days.
|
||||||
|
|
||||||
|
### What gets voted on
|
||||||
|
- Membership (joining, removing)
|
||||||
|
- Coding direction
|
||||||
|
- Priorities / Emphasis
|
||||||
|
- Controversial features (For example, an unpopular feature should be removed)
|
||||||
|
- Communication mediums
|
||||||
|
- Conflict resolution
|
||||||
|
- dev.lemmy.ml (domain and server)
|
||||||
|
- lemmy.ml and subdomains (excluding communism.lemmy.ml)
|
||||||
|
- git repo including mirrors (on github, gitea, etc)
|
||||||
|
- Any official accounts of the Lemmy project, for example the Mastodon account or the Liberapay account
|
||||||
|
- Changes to these rules
|
||||||
|
|
||||||
|
## Joining
|
||||||
|
- We use the following process: anyone who is active around Lemmy can recommend any other active person to join the council. This has to be approved by a majority of the council.
|
||||||
|
- Active users are defined as those who contribute to Lemmy in some way for at least an hour per week on average, doing things like reporting bugs, discussing rules and features, translating, promoting, developing, or doing other things that aim to improve Lemmy as a whole.
|
||||||
|
-> people should have joined at least a month ago.
|
||||||
|
- The member list is public.
|
||||||
|
- Note: we would like to have a process where community members can elect candidates for the council, but this is not realistic because a single user could easily create multiple accounts and cheat the vote.
|
||||||
|
- Limit growth to one new member per month at most.
|
||||||
|
|
||||||
|
## Removing members
|
||||||
|
- Inactive members should be removed from the council after a few months of inactivity, and after receiving a notification about this.
|
||||||
|
- Members that dont follow binding council decisions should be removed.
|
||||||
|
- Any member can be removed in a vote.
|
||||||
|
|
||||||
|
## Goals
|
||||||
|
- We encourage the membership of groups such as LGBT, religious or ethnic minorities, abuse victims, etc etc, and strive to create a safe space for them to express their opinions. We also support measures to increase participation by the previously mentioned groups.
|
||||||
|
- The following are banned, and will always be harshly punished: fascism, abuse, racism, sexism, etc etc,
|
||||||
|
|
||||||
|
## Communication
|
||||||
|
- A private Matrix chat for all council members.
|
||||||
|
- (Once private communities are done) A private community on dev.lemmy.ml for issues.
|
||||||
|
|
||||||
|
## Member List / Contact Info
|
||||||
|
General Contact [@LemmyDev Mastodon](https://mastodon.social/@LemmyDev)
|
||||||
|
|
||||||
|
- Dessalines [Matrix](https://matrix.to/#/@happydooby:matrix.org)
|
||||||
|
- Nutomic [Matrix](https://matrix.to/#/@nutomic:matrix.org), [Mastodon](https://radical.town/@felix)
|
34
install.sh
vendored
34
install.sh
vendored
|
@ -1,15 +1,43 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
export DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
|
# Set the database variable to the default first.
|
||||||
|
# Don't forget to change this string to your actual database parameters
|
||||||
|
# if you don't plan to initialize the database in this script.
|
||||||
|
export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
|
||||||
|
|
||||||
|
# Set other environment variables
|
||||||
export JWT_SECRET=changeme
|
export JWT_SECRET=changeme
|
||||||
export HOSTNAME=rrr
|
export HOSTNAME=rrr
|
||||||
|
|
||||||
|
# Optionally initialize the database
|
||||||
|
init_db_valid=0
|
||||||
|
init_db_final=0
|
||||||
|
while [ "$init_db_valid" == 0 ]
|
||||||
|
do
|
||||||
|
read -p "Initialize database (y/n)? " init_db
|
||||||
|
case "${init_db,,}" in
|
||||||
|
y|yes ) init_db_valid=1; init_db_final=1;;
|
||||||
|
n|no ) init_db_valid=1; init_db_final=0;;
|
||||||
|
* ) echo "Invalid input" 1>&2;;
|
||||||
|
esac
|
||||||
|
echo
|
||||||
|
done
|
||||||
|
if [ "$init_db_final" = 1 ]
|
||||||
|
then
|
||||||
|
source ./server/db-init.sh
|
||||||
|
read -n 1 -s -r -p "Press ANY KEY to continue execution of this script, press CTRL+C to quit..."
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build the web client
|
||||||
cd ui
|
cd ui
|
||||||
yarn
|
yarn
|
||||||
yarn build
|
yarn build
|
||||||
|
|
||||||
|
# Build and run the backend
|
||||||
cd ../server
|
cd ../server
|
||||||
cargo run
|
RUST_LOG=debug cargo run
|
||||||
|
|
||||||
# For live coding, where both the front and back end, automagically reload on any save, do:
|
# For live coding, where both the front and back end, automagically reload on any save, do:
|
||||||
# cd ui && yarn start
|
# cd ui && yarn start
|
||||||
|
|
2
server/.gitignore
vendored
2
server/.gitignore
vendored
|
@ -2,3 +2,5 @@
|
||||||
.env
|
.env
|
||||||
.idea
|
.idea
|
||||||
env_setup.sh
|
env_setup.sh
|
||||||
|
query_testing/*.json
|
||||||
|
query_testing/*.json.old
|
||||||
|
|
1
server/.rustfmt.toml
vendored
1
server/.rustfmt.toml
vendored
|
@ -1 +1,2 @@
|
||||||
tab_spaces = 2
|
tab_spaces = 2
|
||||||
|
edition="2018"
|
3164
server/Cargo.lock
generated
vendored
3164
server/Cargo.lock
generated
vendored
File diff suppressed because it is too large
Load diff
42
server/Cargo.toml
vendored
42
server/Cargo.toml
vendored
|
@ -5,28 +5,36 @@ authors = ["Dessalines <happydooby@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
diesel = { version = "1.4.2", features = ["postgres","chrono"] }
|
diesel = { version = "1.4.2", features = ["postgres","chrono", "r2d2", "64-column-tables"] }
|
||||||
diesel_migrations = "1.4.0"
|
diesel_migrations = "1.4.0"
|
||||||
dotenv = "0.14.1"
|
dotenv = "0.15.0"
|
||||||
bcrypt = "0.5.0"
|
bcrypt = "0.6.1"
|
||||||
activitypub = "0.1.5"
|
activitystreams = "0.5.0-alpha.10"
|
||||||
chrono = { version = "0.4.7", features = ["serde"] }
|
chrono = { version = "0.4.7", features = ["serde"] }
|
||||||
failure = "0.1.5"
|
failure = "0.1.5"
|
||||||
serde_json = { version = "1.0.40", features = ["preserve_order"]}
|
serde_json = { version = "1.0.45", features = ["preserve_order"]}
|
||||||
serde = { version = "1.0.94", features = ["derive"] }
|
serde = { version = "1.0.94", features = ["derive"] }
|
||||||
actix = "0.8.3"
|
actix = "0.9.0"
|
||||||
actix-web = "1.0"
|
actix-web = "2.0.0"
|
||||||
actix-files = "0.1.3"
|
actix-files = "0.2.1"
|
||||||
actix-web-actors = "1.0"
|
actix-web-actors = "2.0.0"
|
||||||
env_logger = "0.6.2"
|
actix-rt = "1.0.0"
|
||||||
rand = "0.7.0"
|
log = "0.4.0"
|
||||||
strum = "0.15.0"
|
env_logger = "0.7.1"
|
||||||
strum_macros = "0.15.0"
|
rand = "0.7.3"
|
||||||
jsonwebtoken = "6.0.1"
|
strum = "0.17.1"
|
||||||
regex = "1.1.9"
|
strum_macros = "0.17.1"
|
||||||
|
jsonwebtoken = "7.0.1"
|
||||||
|
regex = "1.3.4"
|
||||||
lazy_static = "1.3.0"
|
lazy_static = "1.3.0"
|
||||||
lettre = "0.9.2"
|
lettre = "0.9.2"
|
||||||
lettre_email = "0.9.2"
|
lettre_email = "0.9.2"
|
||||||
rust-crypto = "^0.2"
|
sha2 = "0.8.1"
|
||||||
rss = "1.8.0"
|
rss = "1.9.0"
|
||||||
htmlescape = "0.3.1"
|
htmlescape = "0.3.1"
|
||||||
|
config = "0.10.1"
|
||||||
|
hjson = "0.8.2"
|
||||||
|
reqwest = "0.9.24"
|
||||||
|
url = "2.1.1"
|
||||||
|
percent-encoding = "2.1.0"
|
||||||
|
chttp = "0.5.5"
|
||||||
|
|
7
server/clean.sh
vendored
Executable file
7
server/clean.sh
vendored
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
cargo update
|
||||||
|
cargo fmt
|
||||||
|
cargo check
|
||||||
|
cargo clippy
|
||||||
|
cargo outdated -R
|
4
server/config/config.hjson
vendored
Normal file
4
server/config/config.hjson
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
hostname: "localhost:8536"
|
||||||
|
federation_enabled: true
|
||||||
|
}
|
62
server/config/defaults.hjson
vendored
Normal file
62
server/config/defaults.hjson
vendored
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
{
|
||||||
|
# settings related to the postgresql database
|
||||||
|
database: {
|
||||||
|
# username to connect to postgres
|
||||||
|
user: "lemmy"
|
||||||
|
# password to connect to postgres
|
||||||
|
password: "password"
|
||||||
|
# host where postgres is running
|
||||||
|
host: "localhost"
|
||||||
|
# port where postgres can be accessed
|
||||||
|
port: 5432
|
||||||
|
# name of the postgres database for lemmy
|
||||||
|
database: "lemmy"
|
||||||
|
# maximum number of active sql connections
|
||||||
|
pool_size: 5
|
||||||
|
}
|
||||||
|
# the domain name of your instance (eg "dev.lemmy.ml")
|
||||||
|
hostname: null
|
||||||
|
# address where lemmy should listen for incoming requests
|
||||||
|
bind: "0.0.0.0"
|
||||||
|
# port where lemmy should listen for incoming requests
|
||||||
|
port: 8536
|
||||||
|
# json web token for authorization between server and client
|
||||||
|
jwt_secret: "changeme"
|
||||||
|
# The dir for the front end
|
||||||
|
front_end_dir: "../ui/dist"
|
||||||
|
# rate limits for various user actions, by user ip
|
||||||
|
rate_limit: {
|
||||||
|
# maximum number of messages created in interval
|
||||||
|
message: 180
|
||||||
|
# interval length for message limit
|
||||||
|
message_per_second: 60
|
||||||
|
# maximum number of posts created in interval
|
||||||
|
post: 6
|
||||||
|
# interval length for post limit
|
||||||
|
post_per_second: 600
|
||||||
|
# maximum number of registrations in interval
|
||||||
|
register: 3
|
||||||
|
# interval length for registration limit
|
||||||
|
register_per_second: 3600
|
||||||
|
}
|
||||||
|
# settings related to activitypub federation
|
||||||
|
federation: {
|
||||||
|
# whether to enable activitypub federation. this feature is in alpha, do not enable in production.
|
||||||
|
enabled: false
|
||||||
|
# comma seperated list of instances to follow
|
||||||
|
followed_instances: ""
|
||||||
|
# whether tls is required for activitypub. only disable this for debugging, never for producion.
|
||||||
|
tls_enabled: true
|
||||||
|
}
|
||||||
|
# # email sending configuration
|
||||||
|
# email: {
|
||||||
|
# # hostname of the smtp server
|
||||||
|
# smtp_server: ""
|
||||||
|
# # login name for smtp server
|
||||||
|
# smtp_login: ""
|
||||||
|
# # password to login to the smtp server
|
||||||
|
# smtp_password: ""
|
||||||
|
# # address to send emails from, eg "info@your-instance.com"
|
||||||
|
# smtp_from_address: ""
|
||||||
|
# }
|
||||||
|
}
|
43
server/db-init.sh
vendored
Executable file
43
server/db-init.sh
vendored
Executable file
|
@ -0,0 +1,43 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
username=lemmy
|
||||||
|
dbname=lemmy
|
||||||
|
port=5432
|
||||||
|
|
||||||
|
password=""
|
||||||
|
password_confirm=""
|
||||||
|
password_valid=0
|
||||||
|
|
||||||
|
while [ "$password_valid" == 0 ]
|
||||||
|
do
|
||||||
|
read -p "Enter database password: " -s password
|
||||||
|
echo
|
||||||
|
|
||||||
|
read -p "Verify database password: " -s password_confirm
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Start the loop from the top if either check fails
|
||||||
|
if [ -z "$password" ]
|
||||||
|
then
|
||||||
|
echo "Error: Password cannot be empty." 1>&2
|
||||||
|
echo
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ "$password" != "$password_confirm" ]
|
||||||
|
then
|
||||||
|
echo "Error: Passwords don't match." 1>&2
|
||||||
|
echo
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set the password_valid variable to break out of the loop
|
||||||
|
password_valid=1
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
psql -c "CREATE USER $username WITH PASSWORD '$password' SUPERUSER;" -U postgres
|
||||||
|
psql -c 'CREATE DATABASE $dbname WITH OWNER $username;' -U postgres
|
||||||
|
export LEMMY_DATABASE_URL=postgres://$username:$password@localhost:$port/$dbname
|
||||||
|
|
||||||
|
echo $LEMMY_DATABASE_URL
|
224
server/migrations/2019-12-29-164820_add_avatar/down.sql
vendored
Normal file
224
server/migrations/2019-12-29-164820_add_avatar/down.sql
vendored
Normal file
|
@ -0,0 +1,224 @@
|
||||||
|
-- the views
|
||||||
|
drop view user_mention_view;
|
||||||
|
drop view reply_view;
|
||||||
|
drop view comment_view;
|
||||||
|
drop view user_view;
|
||||||
|
|
||||||
|
-- user
|
||||||
|
create view user_view as
|
||||||
|
select id,
|
||||||
|
name,
|
||||||
|
fedi_name,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
|
||||||
|
(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
|
||||||
|
(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
|
||||||
|
(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
|
||||||
|
from user_ u;
|
||||||
|
|
||||||
|
-- post
|
||||||
|
-- Recreate the view
|
||||||
|
drop view post_view;
|
||||||
|
create view post_view as
|
||||||
|
with all_post as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
p.*,
|
||||||
|
(select u.banned from user_ u where p.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb where p.creator_id = cb.user_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where p.creator_id = user_.id) as creator_name,
|
||||||
|
(select name from community where p.community_id = community.id) as community_name,
|
||||||
|
(select removed from community c where p.community_id = c.id) as community_removed,
|
||||||
|
(select deleted from community c where p.community_id = c.id) as community_deleted,
|
||||||
|
(select nsfw from community c where p.community_id = c.id) as community_nsfw,
|
||||||
|
(select count(*) from comment where comment.post_id = p.id) as number_of_comments,
|
||||||
|
coalesce(sum(pl.score), 0) as score,
|
||||||
|
count (case when pl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when pl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(pl.score) , 0), p.published) as hot_rank
|
||||||
|
from post p
|
||||||
|
left join post_like pl on p.id = pl.post_id
|
||||||
|
group by p.id
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
-- community
|
||||||
|
|
||||||
|
drop view community_view;
|
||||||
|
create view community_view as
|
||||||
|
with all_community as
|
||||||
|
(
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where c.creator_id = u.id) as creator_name,
|
||||||
|
(select name from category ct where c.category_id = ct.id) as category_name,
|
||||||
|
(select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers,
|
||||||
|
(select count(*) from post p where p.community_id = c.id) as number_of_posts,
|
||||||
|
(select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments,
|
||||||
|
hot_rank((select count(*) from community_follower cf where cf.community_id = c.id), c.published) as hot_rank
|
||||||
|
from community c
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed
|
||||||
|
from user_ u
|
||||||
|
cross join all_community ac
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as subscribed
|
||||||
|
from all_community ac
|
||||||
|
;
|
||||||
|
|
||||||
|
-- Reply and comment view
|
||||||
|
create view comment_view as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
c.*,
|
||||||
|
(select community_id from post p where p.id = c.post_id),
|
||||||
|
(select u.banned from user_ u where c.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb, post p where c.creator_id = cb.user_id and p.id = c.post_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where c.creator_id = user_.id) as creator_name,
|
||||||
|
coalesce(sum(cl.score), 0) as score,
|
||||||
|
count (case when cl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when cl.score = -1 then 1 else null end) as downvotes
|
||||||
|
from comment c
|
||||||
|
left join comment_like cl on c.id = cl.comment_id
|
||||||
|
group by c.id
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as saved
|
||||||
|
from all_comment ac
|
||||||
|
;
|
||||||
|
|
||||||
|
create view reply_view as
|
||||||
|
with closereply as (
|
||||||
|
select
|
||||||
|
c2.id,
|
||||||
|
c2.creator_id as sender_id,
|
||||||
|
c.creator_id as recipient_id
|
||||||
|
from comment c
|
||||||
|
inner join comment c2 on c.id = c2.parent_id
|
||||||
|
where c2.creator_id != c.creator_id
|
||||||
|
-- Do union where post is null
|
||||||
|
union
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
c.creator_id as sender_id,
|
||||||
|
p.creator_id as recipient_id
|
||||||
|
from comment c, post p
|
||||||
|
where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
|
||||||
|
)
|
||||||
|
select cv.*,
|
||||||
|
closereply.recipient_id
|
||||||
|
from comment_view cv, closereply
|
||||||
|
where closereply.id = cv.id
|
||||||
|
;
|
||||||
|
|
||||||
|
-- user mention
|
||||||
|
create view user_mention_view as
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
c.creator_id,
|
||||||
|
c.post_id,
|
||||||
|
c.parent_id,
|
||||||
|
c.content,
|
||||||
|
c.removed,
|
||||||
|
um.read,
|
||||||
|
c.published,
|
||||||
|
c.updated,
|
||||||
|
c.deleted,
|
||||||
|
c.community_id,
|
||||||
|
c.banned,
|
||||||
|
c.banned_from_community,
|
||||||
|
c.creator_name,
|
||||||
|
c.score,
|
||||||
|
c.upvotes,
|
||||||
|
c.downvotes,
|
||||||
|
c.user_id,
|
||||||
|
c.my_vote,
|
||||||
|
c.saved,
|
||||||
|
um.recipient_id
|
||||||
|
from user_mention um, comment_view c
|
||||||
|
where um.comment_id = c.id;
|
||||||
|
|
||||||
|
-- community tables
|
||||||
|
drop view community_moderator_view;
|
||||||
|
drop view community_follower_view;
|
||||||
|
drop view community_user_ban_view;
|
||||||
|
drop view site_view;
|
||||||
|
|
||||||
|
create view community_moderator_view as
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where cm.user_id = u.id) as user_name,
|
||||||
|
(select name from community c where cm.community_id = c.id) as community_name
|
||||||
|
from community_moderator cm;
|
||||||
|
|
||||||
|
create view community_follower_view as
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where cf.user_id = u.id) as user_name,
|
||||||
|
(select name from community c where cf.community_id = c.id) as community_name
|
||||||
|
from community_follower cf;
|
||||||
|
|
||||||
|
create view community_user_ban_view as
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where cm.user_id = u.id) as user_name,
|
||||||
|
(select name from community c where cm.community_id = c.id) as community_name
|
||||||
|
from community_user_ban cm;
|
||||||
|
|
||||||
|
create view site_view as
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where s.creator_id = u.id) as creator_name,
|
||||||
|
(select count(*) from user_) as number_of_users,
|
||||||
|
(select count(*) from post) as number_of_posts,
|
||||||
|
(select count(*) from comment) as number_of_comments,
|
||||||
|
(select count(*) from community) as number_of_communities
|
||||||
|
from site s;
|
||||||
|
|
||||||
|
alter table user_ rename column avatar to icon;
|
||||||
|
alter table user_ alter column icon type bytea using icon::bytea;
|
234
server/migrations/2019-12-29-164820_add_avatar/up.sql
vendored
Normal file
234
server/migrations/2019-12-29-164820_add_avatar/up.sql
vendored
Normal file
|
@ -0,0 +1,234 @@
|
||||||
|
-- Rename to avatar
|
||||||
|
alter table user_ rename column icon to avatar;
|
||||||
|
alter table user_ alter column avatar type text;
|
||||||
|
|
||||||
|
-- Rebuild nearly all the views, to include the creator avatars
|
||||||
|
|
||||||
|
-- user
|
||||||
|
drop view user_view;
|
||||||
|
create view user_view as
|
||||||
|
select id,
|
||||||
|
name,
|
||||||
|
avatar,
|
||||||
|
fedi_name,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
|
||||||
|
(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
|
||||||
|
(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
|
||||||
|
(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
|
||||||
|
from user_ u;
|
||||||
|
|
||||||
|
-- post
|
||||||
|
-- Recreate the view
|
||||||
|
drop view post_view;
|
||||||
|
create view post_view as
|
||||||
|
with all_post as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
p.*,
|
||||||
|
(select u.banned from user_ u where p.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb where p.creator_id = cb.user_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where p.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where p.creator_id = user_.id) as creator_avatar,
|
||||||
|
(select name from community where p.community_id = community.id) as community_name,
|
||||||
|
(select removed from community c where p.community_id = c.id) as community_removed,
|
||||||
|
(select deleted from community c where p.community_id = c.id) as community_deleted,
|
||||||
|
(select nsfw from community c where p.community_id = c.id) as community_nsfw,
|
||||||
|
(select count(*) from comment where comment.post_id = p.id) as number_of_comments,
|
||||||
|
coalesce(sum(pl.score), 0) as score,
|
||||||
|
count (case when pl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when pl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(pl.score) , 0), p.published) as hot_rank
|
||||||
|
from post p
|
||||||
|
left join post_like pl on p.id = pl.post_id
|
||||||
|
group by p.id
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
-- community
|
||||||
|
drop view community_view;
|
||||||
|
create view community_view as
|
||||||
|
with all_community as
|
||||||
|
(
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where c.creator_id = u.id) as creator_name,
|
||||||
|
(select avatar from user_ u where c.creator_id = u.id) as creator_avatar,
|
||||||
|
(select name from category ct where c.category_id = ct.id) as category_name,
|
||||||
|
(select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers,
|
||||||
|
(select count(*) from post p where p.community_id = c.id) as number_of_posts,
|
||||||
|
(select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments,
|
||||||
|
hot_rank((select count(*) from community_follower cf where cf.community_id = c.id), c.published) as hot_rank
|
||||||
|
from community c
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed
|
||||||
|
from user_ u
|
||||||
|
cross join all_community ac
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as subscribed
|
||||||
|
from all_community ac
|
||||||
|
;
|
||||||
|
|
||||||
|
-- reply and comment view
|
||||||
|
drop view reply_view;
|
||||||
|
drop view user_mention_view;
|
||||||
|
drop view comment_view;
|
||||||
|
create view comment_view as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
c.*,
|
||||||
|
(select community_id from post p where p.id = c.post_id),
|
||||||
|
(select u.banned from user_ u where c.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb, post p where c.creator_id = cb.user_id and p.id = c.post_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where c.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where c.creator_id = user_.id) as creator_avatar,
|
||||||
|
coalesce(sum(cl.score), 0) as score,
|
||||||
|
count (case when cl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when cl.score = -1 then 1 else null end) as downvotes
|
||||||
|
from comment c
|
||||||
|
left join comment_like cl on c.id = cl.comment_id
|
||||||
|
group by c.id
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as saved
|
||||||
|
from all_comment ac
|
||||||
|
;
|
||||||
|
|
||||||
|
create view reply_view as
|
||||||
|
with closereply as (
|
||||||
|
select
|
||||||
|
c2.id,
|
||||||
|
c2.creator_id as sender_id,
|
||||||
|
c.creator_id as recipient_id
|
||||||
|
from comment c
|
||||||
|
inner join comment c2 on c.id = c2.parent_id
|
||||||
|
where c2.creator_id != c.creator_id
|
||||||
|
-- Do union where post is null
|
||||||
|
union
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
c.creator_id as sender_id,
|
||||||
|
p.creator_id as recipient_id
|
||||||
|
from comment c, post p
|
||||||
|
where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
|
||||||
|
)
|
||||||
|
select cv.*,
|
||||||
|
closereply.recipient_id
|
||||||
|
from comment_view cv, closereply
|
||||||
|
where closereply.id = cv.id
|
||||||
|
;
|
||||||
|
|
||||||
|
-- user mention
|
||||||
|
create view user_mention_view as
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
c.creator_id,
|
||||||
|
c.post_id,
|
||||||
|
c.parent_id,
|
||||||
|
c.content,
|
||||||
|
c.removed,
|
||||||
|
um.read,
|
||||||
|
c.published,
|
||||||
|
c.updated,
|
||||||
|
c.deleted,
|
||||||
|
c.community_id,
|
||||||
|
c.banned,
|
||||||
|
c.banned_from_community,
|
||||||
|
c.creator_name,
|
||||||
|
c.creator_avatar,
|
||||||
|
c.score,
|
||||||
|
c.upvotes,
|
||||||
|
c.downvotes,
|
||||||
|
c.user_id,
|
||||||
|
c.my_vote,
|
||||||
|
c.saved,
|
||||||
|
um.recipient_id
|
||||||
|
from user_mention um, comment_view c
|
||||||
|
where um.comment_id = c.id;
|
||||||
|
|
||||||
|
-- community views
|
||||||
|
drop view community_moderator_view;
|
||||||
|
drop view community_follower_view;
|
||||||
|
drop view community_user_ban_view;
|
||||||
|
drop view site_view;
|
||||||
|
|
||||||
|
create view community_moderator_view as
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where cm.user_id = u.id) as user_name,
|
||||||
|
(select avatar from user_ u where cm.user_id = u.id),
|
||||||
|
(select name from community c where cm.community_id = c.id) as community_name
|
||||||
|
from community_moderator cm;
|
||||||
|
|
||||||
|
create view community_follower_view as
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where cf.user_id = u.id) as user_name,
|
||||||
|
(select avatar from user_ u where cf.user_id = u.id),
|
||||||
|
(select name from community c where cf.community_id = c.id) as community_name
|
||||||
|
from community_follower cf;
|
||||||
|
|
||||||
|
create view community_user_ban_view as
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where cm.user_id = u.id) as user_name,
|
||||||
|
(select avatar from user_ u where cm.user_id = u.id),
|
||||||
|
(select name from community c where cm.community_id = c.id) as community_name
|
||||||
|
from community_user_ban cm;
|
||||||
|
|
||||||
|
create view site_view as
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where s.creator_id = u.id) as creator_name,
|
||||||
|
(select avatar from user_ u where s.creator_id = u.id) as creator_avatar,
|
||||||
|
(select count(*) from user_) as number_of_users,
|
||||||
|
(select count(*) from post) as number_of_posts,
|
||||||
|
(select count(*) from comment) as number_of_comments,
|
||||||
|
(select count(*) from community) as number_of_communities
|
||||||
|
from site s;
|
15
server/migrations/2020-01-01-200418_add_email_to_user_view/down.sql
vendored
Normal file
15
server/migrations/2020-01-01-200418_add_email_to_user_view/down.sql
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
-- user
|
||||||
|
drop view user_view;
|
||||||
|
create view user_view as
|
||||||
|
select id,
|
||||||
|
name,
|
||||||
|
avatar,
|
||||||
|
fedi_name,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
|
||||||
|
(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
|
||||||
|
(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
|
||||||
|
(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
|
||||||
|
from user_ u;
|
16
server/migrations/2020-01-01-200418_add_email_to_user_view/up.sql
vendored
Normal file
16
server/migrations/2020-01-01-200418_add_email_to_user_view/up.sql
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
-- user
|
||||||
|
drop view user_view;
|
||||||
|
create view user_view as
|
||||||
|
select id,
|
||||||
|
name,
|
||||||
|
avatar,
|
||||||
|
email,
|
||||||
|
fedi_name,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
|
||||||
|
(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
|
||||||
|
(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
|
||||||
|
(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
|
||||||
|
from user_ u;
|
20
server/migrations/2020-01-02-172755_add_show_avatar_and_email_notifications_to_user/down.sql
vendored
Normal file
20
server/migrations/2020-01-02-172755_add_show_avatar_and_email_notifications_to_user/down.sql
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
-- Drop the columns
|
||||||
|
drop view user_view;
|
||||||
|
alter table user_ drop column show_avatars;
|
||||||
|
alter table user_ drop column send_notifications_to_email;
|
||||||
|
|
||||||
|
-- Rebuild the view
|
||||||
|
create view user_view as
|
||||||
|
select id,
|
||||||
|
name,
|
||||||
|
avatar,
|
||||||
|
email,
|
||||||
|
fedi_name,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
|
||||||
|
(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
|
||||||
|
(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
|
||||||
|
(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
|
||||||
|
from user_ u;
|
22
server/migrations/2020-01-02-172755_add_show_avatar_and_email_notifications_to_user/up.sql
vendored
Normal file
22
server/migrations/2020-01-02-172755_add_show_avatar_and_email_notifications_to_user/up.sql
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
-- Add columns
|
||||||
|
alter table user_ add column show_avatars boolean default true not null;
|
||||||
|
alter table user_ add column send_notifications_to_email boolean default false not null;
|
||||||
|
|
||||||
|
-- Rebuild the user_view
|
||||||
|
drop view user_view;
|
||||||
|
create view user_view as
|
||||||
|
select id,
|
||||||
|
name,
|
||||||
|
avatar,
|
||||||
|
email,
|
||||||
|
fedi_name,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
show_avatars,
|
||||||
|
send_notifications_to_email,
|
||||||
|
published,
|
||||||
|
(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
|
||||||
|
(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
|
||||||
|
(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
|
||||||
|
(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
|
||||||
|
from user_ u;
|
16
server/migrations/2020-01-11-012452_add_indexes/down.sql
vendored
Normal file
16
server/migrations/2020-01-11-012452_add_indexes/down.sql
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
drop index idx_post_creator;
|
||||||
|
drop index idx_post_community;
|
||||||
|
|
||||||
|
drop index idx_post_like_post;
|
||||||
|
drop index idx_post_like_user;
|
||||||
|
|
||||||
|
drop index idx_comment_creator;
|
||||||
|
drop index idx_comment_parent;
|
||||||
|
drop index idx_comment_post;
|
||||||
|
|
||||||
|
drop index idx_comment_like_comment;
|
||||||
|
drop index idx_comment_like_user;
|
||||||
|
drop index idx_comment_like_post;
|
||||||
|
|
||||||
|
drop index idx_community_creator;
|
||||||
|
drop index idx_community_category;
|
17
server/migrations/2020-01-11-012452_add_indexes/up.sql
vendored
Normal file
17
server/migrations/2020-01-11-012452_add_indexes/up.sql
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
-- Go through all the tables joins, optimize every view, CTE, etc.
|
||||||
|
create index idx_post_creator on post (creator_id);
|
||||||
|
create index idx_post_community on post (community_id);
|
||||||
|
|
||||||
|
create index idx_post_like_post on post_like (post_id);
|
||||||
|
create index idx_post_like_user on post_like (user_id);
|
||||||
|
|
||||||
|
create index idx_comment_creator on comment (creator_id);
|
||||||
|
create index idx_comment_parent on comment (parent_id);
|
||||||
|
create index idx_comment_post on comment (post_id);
|
||||||
|
|
||||||
|
create index idx_comment_like_comment on comment_like (comment_id);
|
||||||
|
create index idx_comment_like_user on comment_like (user_id);
|
||||||
|
create index idx_comment_like_post on comment_like (post_id);
|
||||||
|
|
||||||
|
create index idx_community_creator on community (creator_id);
|
||||||
|
create index idx_community_category on community (category_id);
|
223
server/migrations/2020-01-13-025151_create_materialized_views/down.sql
vendored
Normal file
223
server/migrations/2020-01-13-025151_create_materialized_views/down.sql
vendored
Normal file
|
@ -0,0 +1,223 @@
|
||||||
|
-- functions and triggers
|
||||||
|
drop trigger refresh_user on user_;
|
||||||
|
drop function refresh_user();
|
||||||
|
drop trigger refresh_post on post;
|
||||||
|
drop function refresh_post();
|
||||||
|
drop trigger refresh_post_like on post_like;
|
||||||
|
drop function refresh_post_like();
|
||||||
|
drop trigger refresh_community on community;
|
||||||
|
drop function refresh_community();
|
||||||
|
drop trigger refresh_community_follower on community_follower;
|
||||||
|
drop function refresh_community_follower();
|
||||||
|
drop trigger refresh_community_user_ban on community_user_ban;
|
||||||
|
drop function refresh_community_user_ban();
|
||||||
|
drop trigger refresh_comment on comment;
|
||||||
|
drop function refresh_comment();
|
||||||
|
drop trigger refresh_comment_like on comment_like;
|
||||||
|
drop function refresh_comment_like();
|
||||||
|
|
||||||
|
-- post
|
||||||
|
-- Recreate the view
|
||||||
|
drop view post_view;
|
||||||
|
create view post_view as
|
||||||
|
with all_post as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
p.*,
|
||||||
|
(select u.banned from user_ u where p.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb where p.creator_id = cb.user_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where p.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where p.creator_id = user_.id) as creator_avatar,
|
||||||
|
(select name from community where p.community_id = community.id) as community_name,
|
||||||
|
(select removed from community c where p.community_id = c.id) as community_removed,
|
||||||
|
(select deleted from community c where p.community_id = c.id) as community_deleted,
|
||||||
|
(select nsfw from community c where p.community_id = c.id) as community_nsfw,
|
||||||
|
(select count(*) from comment where comment.post_id = p.id) as number_of_comments,
|
||||||
|
coalesce(sum(pl.score), 0) as score,
|
||||||
|
count (case when pl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when pl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(pl.score) , 0), p.published) as hot_rank
|
||||||
|
from post p
|
||||||
|
left join post_like pl on p.id = pl.post_id
|
||||||
|
group by p.id
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
drop view post_mview;
|
||||||
|
drop materialized view post_aggregates_mview;
|
||||||
|
drop view post_aggregates_view;
|
||||||
|
|
||||||
|
-- user
|
||||||
|
drop materialized view user_mview;
|
||||||
|
drop view user_view;
|
||||||
|
create view user_view as
|
||||||
|
select id,
|
||||||
|
name,
|
||||||
|
avatar,
|
||||||
|
email,
|
||||||
|
fedi_name,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
show_avatars,
|
||||||
|
send_notifications_to_email,
|
||||||
|
published,
|
||||||
|
(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
|
||||||
|
(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
|
||||||
|
(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
|
||||||
|
(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
|
||||||
|
from user_ u;
|
||||||
|
|
||||||
|
-- community
|
||||||
|
drop view community_mview;
|
||||||
|
drop materialized view community_aggregates_mview;
|
||||||
|
drop view community_view;
|
||||||
|
drop view community_aggregates_view;
|
||||||
|
create view community_view as
|
||||||
|
with all_community as
|
||||||
|
(
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where c.creator_id = u.id) as creator_name,
|
||||||
|
(select avatar from user_ u where c.creator_id = u.id) as creator_avatar,
|
||||||
|
(select name from category ct where c.category_id = ct.id) as category_name,
|
||||||
|
(select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers,
|
||||||
|
(select count(*) from post p where p.community_id = c.id) as number_of_posts,
|
||||||
|
(select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments,
|
||||||
|
hot_rank((select count(*) from community_follower cf where cf.community_id = c.id), c.published) as hot_rank
|
||||||
|
from community c
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed
|
||||||
|
from user_ u
|
||||||
|
cross join all_community ac
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as subscribed
|
||||||
|
from all_community ac
|
||||||
|
;
|
||||||
|
|
||||||
|
-- reply and comment view
|
||||||
|
drop view reply_view;
|
||||||
|
drop view user_mention_view;
|
||||||
|
drop view comment_view;
|
||||||
|
drop view comment_mview;
|
||||||
|
drop materialized view comment_aggregates_mview;
|
||||||
|
drop view comment_aggregates_view;
|
||||||
|
create view comment_view as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
c.*,
|
||||||
|
(select community_id from post p where p.id = c.post_id),
|
||||||
|
(select u.banned from user_ u where c.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb, post p where c.creator_id = cb.user_id and p.id = c.post_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where c.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where c.creator_id = user_.id) as creator_avatar,
|
||||||
|
coalesce(sum(cl.score), 0) as score,
|
||||||
|
count (case when cl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when cl.score = -1 then 1 else null end) as downvotes
|
||||||
|
from comment c
|
||||||
|
left join comment_like cl on c.id = cl.comment_id
|
||||||
|
group by c.id
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as saved
|
||||||
|
from all_comment ac
|
||||||
|
;
|
||||||
|
|
||||||
|
create view reply_view as
|
||||||
|
with closereply as (
|
||||||
|
select
|
||||||
|
c2.id,
|
||||||
|
c2.creator_id as sender_id,
|
||||||
|
c.creator_id as recipient_id
|
||||||
|
from comment c
|
||||||
|
inner join comment c2 on c.id = c2.parent_id
|
||||||
|
where c2.creator_id != c.creator_id
|
||||||
|
-- Do union where post is null
|
||||||
|
union
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
c.creator_id as sender_id,
|
||||||
|
p.creator_id as recipient_id
|
||||||
|
from comment c, post p
|
||||||
|
where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
|
||||||
|
)
|
||||||
|
select cv.*,
|
||||||
|
closereply.recipient_id
|
||||||
|
from comment_view cv, closereply
|
||||||
|
where closereply.id = cv.id
|
||||||
|
;
|
||||||
|
|
||||||
|
-- user mention
|
||||||
|
create view user_mention_view as
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
c.creator_id,
|
||||||
|
c.post_id,
|
||||||
|
c.parent_id,
|
||||||
|
c.content,
|
||||||
|
c.removed,
|
||||||
|
um.read,
|
||||||
|
c.published,
|
||||||
|
c.updated,
|
||||||
|
c.deleted,
|
||||||
|
c.community_id,
|
||||||
|
c.banned,
|
||||||
|
c.banned_from_community,
|
||||||
|
c.creator_name,
|
||||||
|
c.creator_avatar,
|
||||||
|
c.score,
|
||||||
|
c.upvotes,
|
||||||
|
c.downvotes,
|
||||||
|
c.user_id,
|
||||||
|
c.my_vote,
|
||||||
|
c.saved,
|
||||||
|
um.recipient_id
|
||||||
|
from user_mention um, comment_view c
|
||||||
|
where um.comment_id = c.id;
|
||||||
|
|
437
server/migrations/2020-01-13-025151_create_materialized_views/up.sql
vendored
Normal file
437
server/migrations/2020-01-13-025151_create_materialized_views/up.sql
vendored
Normal file
|
@ -0,0 +1,437 @@
|
||||||
|
-- post
|
||||||
|
create view post_aggregates_view as
|
||||||
|
select
|
||||||
|
p.*,
|
||||||
|
(select u.banned from user_ u where p.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb where p.creator_id = cb.user_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where p.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where p.creator_id = user_.id) as creator_avatar,
|
||||||
|
(select name from community where p.community_id = community.id) as community_name,
|
||||||
|
(select removed from community c where p.community_id = c.id) as community_removed,
|
||||||
|
(select deleted from community c where p.community_id = c.id) as community_deleted,
|
||||||
|
(select nsfw from community c where p.community_id = c.id) as community_nsfw,
|
||||||
|
(select count(*) from comment where comment.post_id = p.id) as number_of_comments,
|
||||||
|
coalesce(sum(pl.score), 0) as score,
|
||||||
|
count (case when pl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when pl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(pl.score) , 0), p.published) as hot_rank
|
||||||
|
from post p
|
||||||
|
left join post_like pl on p.id = pl.post_id
|
||||||
|
group by p.id;
|
||||||
|
|
||||||
|
create materialized view post_aggregates_mview as select * from post_aggregates_view;
|
||||||
|
|
||||||
|
create unique index idx_post_aggregates_mview_id on post_aggregates_mview (id);
|
||||||
|
|
||||||
|
drop view post_view;
|
||||||
|
create view post_view as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_view pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
create view post_mview as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_mview pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
-- user_view
|
||||||
|
drop view user_view;
|
||||||
|
create view user_view as
|
||||||
|
select
|
||||||
|
u.id,
|
||||||
|
u.name,
|
||||||
|
u.avatar,
|
||||||
|
u.email,
|
||||||
|
u.fedi_name,
|
||||||
|
u.admin,
|
||||||
|
u.banned,
|
||||||
|
u.show_avatars,
|
||||||
|
u.send_notifications_to_email,
|
||||||
|
u.published,
|
||||||
|
(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
|
||||||
|
(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
|
||||||
|
(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
|
||||||
|
(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
|
||||||
|
from user_ u;
|
||||||
|
|
||||||
|
create materialized view user_mview as select * from user_view;
|
||||||
|
|
||||||
|
create unique index idx_user_mview_id on user_mview (id);
|
||||||
|
|
||||||
|
-- community
|
||||||
|
create view community_aggregates_view as
|
||||||
|
select c.*,
|
||||||
|
(select name from user_ u where c.creator_id = u.id) as creator_name,
|
||||||
|
(select avatar from user_ u where c.creator_id = u.id) as creator_avatar,
|
||||||
|
(select name from category ct where c.category_id = ct.id) as category_name,
|
||||||
|
(select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers,
|
||||||
|
(select count(*) from post p where p.community_id = c.id) as number_of_posts,
|
||||||
|
(select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments,
|
||||||
|
hot_rank((select count(*) from community_follower cf where cf.community_id = c.id), c.published) as hot_rank
|
||||||
|
from community c;
|
||||||
|
|
||||||
|
create materialized view community_aggregates_mview as select * from community_aggregates_view;
|
||||||
|
|
||||||
|
create unique index idx_community_aggregates_mview_id on community_aggregates_mview (id);
|
||||||
|
|
||||||
|
drop view community_view;
|
||||||
|
create view community_view as
|
||||||
|
with all_community as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
ca.*
|
||||||
|
from community_aggregates_view ca
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed
|
||||||
|
from user_ u
|
||||||
|
cross join all_community ac
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as subscribed
|
||||||
|
from all_community ac
|
||||||
|
;
|
||||||
|
|
||||||
|
create view community_mview as
|
||||||
|
with all_community as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
ca.*
|
||||||
|
from community_aggregates_mview ca
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed
|
||||||
|
from user_ u
|
||||||
|
cross join all_community ac
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as subscribed
|
||||||
|
from all_community ac
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
-- reply and comment view
|
||||||
|
create view comment_aggregates_view as
|
||||||
|
select
|
||||||
|
c.*,
|
||||||
|
(select community_id from post p where p.id = c.post_id),
|
||||||
|
(select u.banned from user_ u where c.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb, post p where c.creator_id = cb.user_id and p.id = c.post_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where c.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where c.creator_id = user_.id) as creator_avatar,
|
||||||
|
coalesce(sum(cl.score), 0) as score,
|
||||||
|
count (case when cl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when cl.score = -1 then 1 else null end) as downvotes
|
||||||
|
from comment c
|
||||||
|
left join comment_like cl on c.id = cl.comment_id
|
||||||
|
group by c.id;
|
||||||
|
|
||||||
|
create materialized view comment_aggregates_mview as select * from comment_aggregates_view;
|
||||||
|
|
||||||
|
create unique index idx_comment_aggregates_mview_id on comment_aggregates_mview (id);
|
||||||
|
|
||||||
|
drop view reply_view;
|
||||||
|
drop view user_mention_view;
|
||||||
|
drop view comment_view;
|
||||||
|
|
||||||
|
create view comment_view as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
ca.*
|
||||||
|
from comment_aggregates_view ca
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as saved
|
||||||
|
from all_comment ac
|
||||||
|
;
|
||||||
|
|
||||||
|
create view comment_mview as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
ca.*
|
||||||
|
from comment_aggregates_mview ca
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as saved
|
||||||
|
from all_comment ac
|
||||||
|
;
|
||||||
|
|
||||||
|
create view reply_view as
|
||||||
|
with closereply as (
|
||||||
|
select
|
||||||
|
c2.id,
|
||||||
|
c2.creator_id as sender_id,
|
||||||
|
c.creator_id as recipient_id
|
||||||
|
from comment c
|
||||||
|
inner join comment c2 on c.id = c2.parent_id
|
||||||
|
where c2.creator_id != c.creator_id
|
||||||
|
-- Do union where post is null
|
||||||
|
union
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
c.creator_id as sender_id,
|
||||||
|
p.creator_id as recipient_id
|
||||||
|
from comment c, post p
|
||||||
|
where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
|
||||||
|
)
|
||||||
|
select cv.*,
|
||||||
|
closereply.recipient_id
|
||||||
|
from comment_view cv, closereply
|
||||||
|
where closereply.id = cv.id
|
||||||
|
;
|
||||||
|
|
||||||
|
-- user mention
|
||||||
|
create view user_mention_view as
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
c.creator_id,
|
||||||
|
c.post_id,
|
||||||
|
c.parent_id,
|
||||||
|
c.content,
|
||||||
|
c.removed,
|
||||||
|
um.read,
|
||||||
|
c.published,
|
||||||
|
c.updated,
|
||||||
|
c.deleted,
|
||||||
|
c.community_id,
|
||||||
|
c.banned,
|
||||||
|
c.banned_from_community,
|
||||||
|
c.creator_name,
|
||||||
|
c.creator_avatar,
|
||||||
|
c.score,
|
||||||
|
c.upvotes,
|
||||||
|
c.downvotes,
|
||||||
|
c.user_id,
|
||||||
|
c.my_vote,
|
||||||
|
c.saved,
|
||||||
|
um.recipient_id
|
||||||
|
from user_mention um, comment_view c
|
||||||
|
where um.comment_id = c.id;
|
||||||
|
|
||||||
|
-- user
|
||||||
|
create or replace function refresh_user()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently user_mview;
|
||||||
|
refresh materialized view concurrently comment_aggregates_mview; -- cause of bans
|
||||||
|
refresh materialized view concurrently post_aggregates_mview;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_user
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on user_
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_user();
|
||||||
|
|
||||||
|
-- post
|
||||||
|
create or replace function refresh_post()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently post_aggregates_mview;
|
||||||
|
refresh materialized view concurrently user_mview;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_post
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on post
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_post();
|
||||||
|
|
||||||
|
-- post_like
|
||||||
|
create or replace function refresh_post_like()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently post_aggregates_mview;
|
||||||
|
refresh materialized view concurrently user_mview;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_post_like
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on post_like
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_post_like();
|
||||||
|
|
||||||
|
-- community
|
||||||
|
create or replace function refresh_community()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently post_aggregates_mview;
|
||||||
|
refresh materialized view concurrently community_aggregates_mview;
|
||||||
|
refresh materialized view concurrently user_mview;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_community
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on community
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_community();
|
||||||
|
|
||||||
|
-- community_follower
|
||||||
|
create or replace function refresh_community_follower()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently community_aggregates_mview;
|
||||||
|
refresh materialized view concurrently post_aggregates_mview;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_community_follower
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on community_follower
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_community_follower();
|
||||||
|
|
||||||
|
-- community_user_ban
|
||||||
|
create or replace function refresh_community_user_ban()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently comment_aggregates_mview;
|
||||||
|
refresh materialized view concurrently post_aggregates_mview;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_community_user_ban
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on community_user_ban
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_community_user_ban();
|
||||||
|
|
||||||
|
-- comment
|
||||||
|
create or replace function refresh_comment()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently post_aggregates_mview;
|
||||||
|
refresh materialized view concurrently comment_aggregates_mview;
|
||||||
|
refresh materialized view concurrently community_aggregates_mview;
|
||||||
|
refresh materialized view concurrently user_mview;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_comment
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on comment
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_comment();
|
||||||
|
|
||||||
|
-- comment_like
|
||||||
|
create or replace function refresh_comment_like()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently comment_aggregates_mview;
|
||||||
|
refresh materialized view concurrently user_mview;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_comment_like
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on comment_like
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_comment_like();
|
34
server/migrations/2020-01-21-001001_create_private_message/down.sql
vendored
Normal file
34
server/migrations/2020-01-21-001001_create_private_message/down.sql
vendored
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
-- Drop the triggers
|
||||||
|
drop trigger refresh_private_message on private_message;
|
||||||
|
drop function refresh_private_message();
|
||||||
|
|
||||||
|
-- Drop the view and table
|
||||||
|
drop view private_message_view cascade;
|
||||||
|
drop table private_message;
|
||||||
|
|
||||||
|
-- Rebuild the old views
|
||||||
|
drop view user_view cascade;
|
||||||
|
create view user_view as
|
||||||
|
select
|
||||||
|
u.id,
|
||||||
|
u.name,
|
||||||
|
u.avatar,
|
||||||
|
u.email,
|
||||||
|
u.fedi_name,
|
||||||
|
u.admin,
|
||||||
|
u.banned,
|
||||||
|
u.show_avatars,
|
||||||
|
u.send_notifications_to_email,
|
||||||
|
u.published,
|
||||||
|
(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
|
||||||
|
(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
|
||||||
|
(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
|
||||||
|
(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
|
||||||
|
from user_ u;
|
||||||
|
|
||||||
|
create materialized view user_mview as select * from user_view;
|
||||||
|
|
||||||
|
create unique index idx_user_mview_id on user_mview (id);
|
||||||
|
|
||||||
|
-- Drop the columns
|
||||||
|
alter table user_ drop column matrix_user_id;
|
90
server/migrations/2020-01-21-001001_create_private_message/up.sql
vendored
Normal file
90
server/migrations/2020-01-21-001001_create_private_message/up.sql
vendored
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
-- Creating private message
|
||||||
|
create table private_message (
|
||||||
|
id serial primary key,
|
||||||
|
creator_id int references user_ on update cascade on delete cascade not null,
|
||||||
|
recipient_id int references user_ on update cascade on delete cascade not null,
|
||||||
|
content text not null,
|
||||||
|
deleted boolean default false not null,
|
||||||
|
read boolean default false not null,
|
||||||
|
published timestamp not null default now(),
|
||||||
|
updated timestamp
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Create the view and materialized view which has the avatar and creator name
|
||||||
|
create view private_message_view as
|
||||||
|
select
|
||||||
|
pm.*,
|
||||||
|
u.name as creator_name,
|
||||||
|
u.avatar as creator_avatar,
|
||||||
|
u2.name as recipient_name,
|
||||||
|
u2.avatar as recipient_avatar
|
||||||
|
from private_message pm
|
||||||
|
inner join user_ u on u.id = pm.creator_id
|
||||||
|
inner join user_ u2 on u2.id = pm.recipient_id;
|
||||||
|
|
||||||
|
create materialized view private_message_mview as select * from private_message_view;
|
||||||
|
|
||||||
|
create unique index idx_private_message_mview_id on private_message_mview (id);
|
||||||
|
|
||||||
|
-- Create the triggers
|
||||||
|
create or replace function refresh_private_message()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently private_message_mview;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_private_message
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on private_message
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_private_message();
|
||||||
|
|
||||||
|
-- Update user to include matrix id
|
||||||
|
alter table user_ add column matrix_user_id text unique;
|
||||||
|
|
||||||
|
drop view user_view cascade;
|
||||||
|
create view user_view as
|
||||||
|
select
|
||||||
|
u.id,
|
||||||
|
u.name,
|
||||||
|
u.avatar,
|
||||||
|
u.email,
|
||||||
|
u.matrix_user_id,
|
||||||
|
u.fedi_name,
|
||||||
|
u.admin,
|
||||||
|
u.banned,
|
||||||
|
u.show_avatars,
|
||||||
|
u.send_notifications_to_email,
|
||||||
|
u.published,
|
||||||
|
(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
|
||||||
|
(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
|
||||||
|
(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
|
||||||
|
(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
|
||||||
|
from user_ u;
|
||||||
|
|
||||||
|
create materialized view user_mview as select * from user_view;
|
||||||
|
|
||||||
|
create unique index idx_user_mview_id on user_mview (id);
|
||||||
|
|
||||||
|
-- This is what a group pm table would look like
|
||||||
|
-- Not going to do it now because of the complications
|
||||||
|
--
|
||||||
|
-- create table private_message (
|
||||||
|
-- id serial primary key,
|
||||||
|
-- creator_id int references user_ on update cascade on delete cascade not null,
|
||||||
|
-- content text not null,
|
||||||
|
-- deleted boolean default false not null,
|
||||||
|
-- published timestamp not null default now(),
|
||||||
|
-- updated timestamp
|
||||||
|
-- );
|
||||||
|
--
|
||||||
|
-- create table private_message_recipient (
|
||||||
|
-- id serial primary key,
|
||||||
|
-- private_message_id int references private_message on update cascade on delete cascade not null,
|
||||||
|
-- recipient_id int references user_ on update cascade on delete cascade not null,
|
||||||
|
-- read boolean default false not null,
|
||||||
|
-- published timestamp not null default now(),
|
||||||
|
-- unique(private_message_id, recipient_id)
|
||||||
|
-- )
|
25
server/migrations/2020-01-29-011901_create_reply_materialized_view/down.sql
vendored
Normal file
25
server/migrations/2020-01-29-011901_create_reply_materialized_view/down.sql
vendored
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
-- Drop the materialized / built views
|
||||||
|
drop view reply_view;
|
||||||
|
create view reply_view as
|
||||||
|
with closereply as (
|
||||||
|
select
|
||||||
|
c2.id,
|
||||||
|
c2.creator_id as sender_id,
|
||||||
|
c.creator_id as recipient_id
|
||||||
|
from comment c
|
||||||
|
inner join comment c2 on c.id = c2.parent_id
|
||||||
|
where c2.creator_id != c.creator_id
|
||||||
|
-- Do union where post is null
|
||||||
|
union
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
c.creator_id as sender_id,
|
||||||
|
p.creator_id as recipient_id
|
||||||
|
from comment c, post p
|
||||||
|
where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
|
||||||
|
)
|
||||||
|
select cv.*,
|
||||||
|
closereply.recipient_id
|
||||||
|
from comment_view cv, closereply
|
||||||
|
where closereply.id = cv.id
|
||||||
|
;
|
27
server/migrations/2020-01-29-011901_create_reply_materialized_view/up.sql
vendored
Normal file
27
server/migrations/2020-01-29-011901_create_reply_materialized_view/up.sql
vendored
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
-- https://github.com/dessalines/lemmy/issues/197
|
||||||
|
drop view reply_view;
|
||||||
|
|
||||||
|
-- Do the reply_view referencing the comment_mview
|
||||||
|
create view reply_view as
|
||||||
|
with closereply as (
|
||||||
|
select
|
||||||
|
c2.id,
|
||||||
|
c2.creator_id as sender_id,
|
||||||
|
c.creator_id as recipient_id
|
||||||
|
from comment c
|
||||||
|
inner join comment c2 on c.id = c2.parent_id
|
||||||
|
where c2.creator_id != c.creator_id
|
||||||
|
-- Do union where post is null
|
||||||
|
union
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
c.creator_id as sender_id,
|
||||||
|
p.creator_id as recipient_id
|
||||||
|
from comment c, post p
|
||||||
|
where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
|
||||||
|
)
|
||||||
|
select cv.*,
|
||||||
|
closereply.recipient_id
|
||||||
|
from comment_mview cv, closereply
|
||||||
|
where closereply.id = cv.id
|
||||||
|
;
|
1
server/migrations/2020-01-29-030825_create_user_mention_materialized_view/down.sql
vendored
Normal file
1
server/migrations/2020-01-29-030825_create_user_mention_materialized_view/down.sql
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
drop view user_mention_mview;
|
67
server/migrations/2020-01-29-030825_create_user_mention_materialized_view/up.sql
vendored
Normal file
67
server/migrations/2020-01-29-030825_create_user_mention_materialized_view/up.sql
vendored
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
create view user_mention_mview as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
ca.*
|
||||||
|
from comment_aggregates_mview ca
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
ac.creator_id,
|
||||||
|
ac.post_id,
|
||||||
|
ac.parent_id,
|
||||||
|
ac.content,
|
||||||
|
ac.removed,
|
||||||
|
um.read,
|
||||||
|
ac.published,
|
||||||
|
ac.updated,
|
||||||
|
ac.deleted,
|
||||||
|
ac.community_id,
|
||||||
|
ac.banned,
|
||||||
|
ac.banned_from_community,
|
||||||
|
ac.creator_name,
|
||||||
|
ac.creator_avatar,
|
||||||
|
ac.score,
|
||||||
|
ac.upvotes,
|
||||||
|
ac.downvotes,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved,
|
||||||
|
um.recipient_id
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
left join user_mention um on um.comment_id = ac.id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
ac.creator_id,
|
||||||
|
ac.post_id,
|
||||||
|
ac.parent_id,
|
||||||
|
ac.content,
|
||||||
|
ac.removed,
|
||||||
|
um.read,
|
||||||
|
ac.published,
|
||||||
|
ac.updated,
|
||||||
|
ac.deleted,
|
||||||
|
ac.community_id,
|
||||||
|
ac.banned,
|
||||||
|
ac.banned_from_community,
|
||||||
|
ac.creator_name,
|
||||||
|
ac.creator_avatar,
|
||||||
|
ac.score,
|
||||||
|
ac.upvotes,
|
||||||
|
ac.downvotes,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as saved,
|
||||||
|
um.recipient_id
|
||||||
|
from all_comment ac
|
||||||
|
left join user_mention um on um.comment_id = ac.id
|
||||||
|
;
|
||||||
|
|
2
server/migrations/2020-02-02-004806_add_case_insensitive_usernames/down.sql
vendored
Normal file
2
server/migrations/2020-02-02-004806_add_case_insensitive_usernames/down.sql
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
drop index idx_user_name_lower;
|
||||||
|
drop index idx_user_email_lower;
|
29
server/migrations/2020-02-02-004806_add_case_insensitive_usernames/up.sql
vendored
Normal file
29
server/migrations/2020-02-02-004806_add_case_insensitive_usernames/up.sql
vendored
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
-- Add case insensitive username and email uniqueness
|
||||||
|
|
||||||
|
-- An example of showing the dupes:
|
||||||
|
-- select
|
||||||
|
-- max(id) as id,
|
||||||
|
-- lower(name) as lname,
|
||||||
|
-- count(*)
|
||||||
|
-- from user_
|
||||||
|
-- group by lower(name)
|
||||||
|
-- having count(*) > 1;
|
||||||
|
|
||||||
|
-- Delete username dupes, keeping the first one
|
||||||
|
delete
|
||||||
|
from user_
|
||||||
|
where id not in (
|
||||||
|
select min(id)
|
||||||
|
from user_
|
||||||
|
group by lower(name), lower(fedi_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- The user index
|
||||||
|
create unique index idx_user_name_lower on user_ (lower(name));
|
||||||
|
|
||||||
|
-- Email lower
|
||||||
|
create unique index idx_user_email_lower on user_ (lower(email));
|
||||||
|
|
||||||
|
-- Set empty emails properly to null
|
||||||
|
update user_ set email = null where email = '';
|
||||||
|
|
132
server/migrations/2020-02-06-165953_change_post_title_length/down.sql
vendored
Normal file
132
server/migrations/2020-02-06-165953_change_post_title_length/down.sql
vendored
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
-- Drop the dependent views
|
||||||
|
drop view post_view;
|
||||||
|
drop view post_mview;
|
||||||
|
drop materialized view post_aggregates_mview;
|
||||||
|
drop view post_aggregates_view;
|
||||||
|
drop view mod_remove_post_view;
|
||||||
|
drop view mod_sticky_post_view;
|
||||||
|
drop view mod_lock_post_view;
|
||||||
|
drop view mod_remove_comment_view;
|
||||||
|
|
||||||
|
alter table post alter column name type varchar(100);
|
||||||
|
|
||||||
|
-- regen post view
|
||||||
|
create view post_aggregates_view as
|
||||||
|
select
|
||||||
|
p.*,
|
||||||
|
(select u.banned from user_ u where p.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb where p.creator_id = cb.user_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where p.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where p.creator_id = user_.id) as creator_avatar,
|
||||||
|
(select name from community where p.community_id = community.id) as community_name,
|
||||||
|
(select removed from community c where p.community_id = c.id) as community_removed,
|
||||||
|
(select deleted from community c where p.community_id = c.id) as community_deleted,
|
||||||
|
(select nsfw from community c where p.community_id = c.id) as community_nsfw,
|
||||||
|
(select count(*) from comment where comment.post_id = p.id) as number_of_comments,
|
||||||
|
coalesce(sum(pl.score), 0) as score,
|
||||||
|
count (case when pl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when pl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(pl.score) , 0), p.published) as hot_rank
|
||||||
|
from post p
|
||||||
|
left join post_like pl on p.id = pl.post_id
|
||||||
|
group by p.id;
|
||||||
|
|
||||||
|
create materialized view post_aggregates_mview as select * from post_aggregates_view;
|
||||||
|
|
||||||
|
create unique index idx_post_aggregates_mview_id on post_aggregates_mview (id);
|
||||||
|
|
||||||
|
create view post_view as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_view pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
create view post_mview as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_mview pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
-- The mod views
|
||||||
|
|
||||||
|
create view mod_remove_post_view as
|
||||||
|
select mrp.*,
|
||||||
|
(select name from user_ u where mrp.mod_user_id = u.id) as mod_user_name,
|
||||||
|
(select name from post p where mrp.post_id = p.id) as post_name,
|
||||||
|
(select c.id from post p, community c where mrp.post_id = p.id and p.community_id = c.id) as community_id,
|
||||||
|
(select c.name from post p, community c where mrp.post_id = p.id and p.community_id = c.id) as community_name
|
||||||
|
from mod_remove_post mrp;
|
||||||
|
|
||||||
|
create view mod_lock_post_view as
|
||||||
|
select mlp.*,
|
||||||
|
(select name from user_ u where mlp.mod_user_id = u.id) as mod_user_name,
|
||||||
|
(select name from post p where mlp.post_id = p.id) as post_name,
|
||||||
|
(select c.id from post p, community c where mlp.post_id = p.id and p.community_id = c.id) as community_id,
|
||||||
|
(select c.name from post p, community c where mlp.post_id = p.id and p.community_id = c.id) as community_name
|
||||||
|
from mod_lock_post mlp;
|
||||||
|
|
||||||
|
create view mod_remove_comment_view as
|
||||||
|
select mrc.*,
|
||||||
|
(select name from user_ u where mrc.mod_user_id = u.id) as mod_user_name,
|
||||||
|
(select c.id from comment c where mrc.comment_id = c.id) as comment_user_id,
|
||||||
|
(select name from user_ u, comment c where mrc.comment_id = c.id and u.id = c.creator_id) as comment_user_name,
|
||||||
|
(select content from comment c where mrc.comment_id = c.id) as comment_content,
|
||||||
|
(select p.id from post p, comment c where mrc.comment_id = c.id and c.post_id = p.id) as post_id,
|
||||||
|
(select p.name from post p, comment c where mrc.comment_id = c.id and c.post_id = p.id) as post_name,
|
||||||
|
(select co.id from comment c, post p, community co where mrc.comment_id = c.id and c.post_id = p.id and p.community_id = co.id) as community_id,
|
||||||
|
(select co.name from comment c, post p, community co where mrc.comment_id = c.id and c.post_id = p.id and p.community_id = co.id) as community_name
|
||||||
|
from mod_remove_comment mrc;
|
||||||
|
|
||||||
|
create view mod_sticky_post_view as
|
||||||
|
select msp.*,
|
||||||
|
(select name from user_ u where msp.mod_user_id = u.id) as mod_user_name,
|
||||||
|
(select name from post p where msp.post_id = p.id) as post_name,
|
||||||
|
(select c.id from post p, community c where msp.post_id = p.id and p.community_id = c.id) as community_id,
|
||||||
|
(select c.name from post p, community c where msp.post_id = p.id and p.community_id = c.id) as community_name
|
||||||
|
from mod_sticky_post msp;
|
133
server/migrations/2020-02-06-165953_change_post_title_length/up.sql
vendored
Normal file
133
server/migrations/2020-02-06-165953_change_post_title_length/up.sql
vendored
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
-- Drop the dependent views
|
||||||
|
drop view post_view;
|
||||||
|
drop view post_mview;
|
||||||
|
drop materialized view post_aggregates_mview;
|
||||||
|
drop view post_aggregates_view;
|
||||||
|
drop view mod_remove_post_view;
|
||||||
|
drop view mod_sticky_post_view;
|
||||||
|
drop view mod_lock_post_view;
|
||||||
|
drop view mod_remove_comment_view;
|
||||||
|
|
||||||
|
-- Add the extra post limit
|
||||||
|
alter table post alter column name type varchar(200);
|
||||||
|
|
||||||
|
-- regen post view
|
||||||
|
create view post_aggregates_view as
|
||||||
|
select
|
||||||
|
p.*,
|
||||||
|
(select u.banned from user_ u where p.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb where p.creator_id = cb.user_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where p.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where p.creator_id = user_.id) as creator_avatar,
|
||||||
|
(select name from community where p.community_id = community.id) as community_name,
|
||||||
|
(select removed from community c where p.community_id = c.id) as community_removed,
|
||||||
|
(select deleted from community c where p.community_id = c.id) as community_deleted,
|
||||||
|
(select nsfw from community c where p.community_id = c.id) as community_nsfw,
|
||||||
|
(select count(*) from comment where comment.post_id = p.id) as number_of_comments,
|
||||||
|
coalesce(sum(pl.score), 0) as score,
|
||||||
|
count (case when pl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when pl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(pl.score) , 0), p.published) as hot_rank
|
||||||
|
from post p
|
||||||
|
left join post_like pl on p.id = pl.post_id
|
||||||
|
group by p.id;
|
||||||
|
|
||||||
|
create materialized view post_aggregates_mview as select * from post_aggregates_view;
|
||||||
|
|
||||||
|
create unique index idx_post_aggregates_mview_id on post_aggregates_mview (id);
|
||||||
|
|
||||||
|
create view post_view as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_view pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
create view post_mview as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_mview pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
-- The mod views
|
||||||
|
|
||||||
|
create view mod_remove_post_view as
|
||||||
|
select mrp.*,
|
||||||
|
(select name from user_ u where mrp.mod_user_id = u.id) as mod_user_name,
|
||||||
|
(select name from post p where mrp.post_id = p.id) as post_name,
|
||||||
|
(select c.id from post p, community c where mrp.post_id = p.id and p.community_id = c.id) as community_id,
|
||||||
|
(select c.name from post p, community c where mrp.post_id = p.id and p.community_id = c.id) as community_name
|
||||||
|
from mod_remove_post mrp;
|
||||||
|
|
||||||
|
create view mod_lock_post_view as
|
||||||
|
select mlp.*,
|
||||||
|
(select name from user_ u where mlp.mod_user_id = u.id) as mod_user_name,
|
||||||
|
(select name from post p where mlp.post_id = p.id) as post_name,
|
||||||
|
(select c.id from post p, community c where mlp.post_id = p.id and p.community_id = c.id) as community_id,
|
||||||
|
(select c.name from post p, community c where mlp.post_id = p.id and p.community_id = c.id) as community_name
|
||||||
|
from mod_lock_post mlp;
|
||||||
|
|
||||||
|
create view mod_remove_comment_view as
|
||||||
|
select mrc.*,
|
||||||
|
(select name from user_ u where mrc.mod_user_id = u.id) as mod_user_name,
|
||||||
|
(select c.id from comment c where mrc.comment_id = c.id) as comment_user_id,
|
||||||
|
(select name from user_ u, comment c where mrc.comment_id = c.id and u.id = c.creator_id) as comment_user_name,
|
||||||
|
(select content from comment c where mrc.comment_id = c.id) as comment_content,
|
||||||
|
(select p.id from post p, comment c where mrc.comment_id = c.id and c.post_id = p.id) as post_id,
|
||||||
|
(select p.name from post p, comment c where mrc.comment_id = c.id and c.post_id = p.id) as post_name,
|
||||||
|
(select co.id from comment c, post p, community co where mrc.comment_id = c.id and c.post_id = p.id and p.community_id = co.id) as community_id,
|
||||||
|
(select co.name from comment c, post p, community co where mrc.comment_id = c.id and c.post_id = p.id and p.community_id = co.id) as community_name
|
||||||
|
from mod_remove_comment mrc;
|
||||||
|
|
||||||
|
create view mod_sticky_post_view as
|
||||||
|
select msp.*,
|
||||||
|
(select name from user_ u where msp.mod_user_id = u.id) as mod_user_name,
|
||||||
|
(select name from post p where msp.post_id = p.id) as post_name,
|
||||||
|
(select c.id from post p, community c where msp.post_id = p.id and p.community_id = c.id) as community_id,
|
||||||
|
(select c.name from post p, community c where msp.post_id = p.id and p.community_id = c.id) as community_name
|
||||||
|
from mod_sticky_post msp;
|
206
server/migrations/2020-02-07-210055_add_comment_subscribed/down.sql
vendored
Normal file
206
server/migrations/2020-02-07-210055_add_comment_subscribed/down.sql
vendored
Normal file
|
@ -0,0 +1,206 @@
|
||||||
|
|
||||||
|
drop view reply_view;
|
||||||
|
drop view user_mention_view;
|
||||||
|
drop view user_mention_mview;
|
||||||
|
drop view comment_view;
|
||||||
|
drop view comment_mview;
|
||||||
|
drop materialized view comment_aggregates_mview;
|
||||||
|
drop view comment_aggregates_view;
|
||||||
|
|
||||||
|
-- reply and comment view
|
||||||
|
create view comment_aggregates_view as
|
||||||
|
select
|
||||||
|
c.*,
|
||||||
|
(select community_id from post p where p.id = c.post_id),
|
||||||
|
(select u.banned from user_ u where c.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb, post p where c.creator_id = cb.user_id and p.id = c.post_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where c.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where c.creator_id = user_.id) as creator_avatar,
|
||||||
|
coalesce(sum(cl.score), 0) as score,
|
||||||
|
count (case when cl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when cl.score = -1 then 1 else null end) as downvotes
|
||||||
|
from comment c
|
||||||
|
left join comment_like cl on c.id = cl.comment_id
|
||||||
|
group by c.id;
|
||||||
|
|
||||||
|
create materialized view comment_aggregates_mview as select * from comment_aggregates_view;
|
||||||
|
|
||||||
|
create unique index idx_comment_aggregates_mview_id on comment_aggregates_mview (id);
|
||||||
|
|
||||||
|
create view comment_view as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
ca.*
|
||||||
|
from comment_aggregates_view ca
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as saved
|
||||||
|
from all_comment ac
|
||||||
|
;
|
||||||
|
|
||||||
|
create view comment_mview as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
ca.*
|
||||||
|
from comment_aggregates_mview ca
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as saved
|
||||||
|
from all_comment ac
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
-- Do the reply_view referencing the comment_mview
|
||||||
|
create view reply_view as
|
||||||
|
with closereply as (
|
||||||
|
select
|
||||||
|
c2.id,
|
||||||
|
c2.creator_id as sender_id,
|
||||||
|
c.creator_id as recipient_id
|
||||||
|
from comment c
|
||||||
|
inner join comment c2 on c.id = c2.parent_id
|
||||||
|
where c2.creator_id != c.creator_id
|
||||||
|
-- Do union where post is null
|
||||||
|
union
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
c.creator_id as sender_id,
|
||||||
|
p.creator_id as recipient_id
|
||||||
|
from comment c, post p
|
||||||
|
where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
|
||||||
|
)
|
||||||
|
select cv.*,
|
||||||
|
closereply.recipient_id
|
||||||
|
from comment_mview cv, closereply
|
||||||
|
where closereply.id = cv.id
|
||||||
|
;
|
||||||
|
|
||||||
|
-- user mention
|
||||||
|
create view user_mention_view as
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
c.creator_id,
|
||||||
|
c.post_id,
|
||||||
|
c.parent_id,
|
||||||
|
c.content,
|
||||||
|
c.removed,
|
||||||
|
um.read,
|
||||||
|
c.published,
|
||||||
|
c.updated,
|
||||||
|
c.deleted,
|
||||||
|
c.community_id,
|
||||||
|
c.banned,
|
||||||
|
c.banned_from_community,
|
||||||
|
c.creator_name,
|
||||||
|
c.creator_avatar,
|
||||||
|
c.score,
|
||||||
|
c.upvotes,
|
||||||
|
c.downvotes,
|
||||||
|
c.user_id,
|
||||||
|
c.my_vote,
|
||||||
|
c.saved,
|
||||||
|
um.recipient_id
|
||||||
|
from user_mention um, comment_view c
|
||||||
|
where um.comment_id = c.id;
|
||||||
|
|
||||||
|
|
||||||
|
create view user_mention_mview as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
ca.*
|
||||||
|
from comment_aggregates_mview ca
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
ac.creator_id,
|
||||||
|
ac.post_id,
|
||||||
|
ac.parent_id,
|
||||||
|
ac.content,
|
||||||
|
ac.removed,
|
||||||
|
um.read,
|
||||||
|
ac.published,
|
||||||
|
ac.updated,
|
||||||
|
ac.deleted,
|
||||||
|
ac.community_id,
|
||||||
|
ac.banned,
|
||||||
|
ac.banned_from_community,
|
||||||
|
ac.creator_name,
|
||||||
|
ac.creator_avatar,
|
||||||
|
ac.score,
|
||||||
|
ac.upvotes,
|
||||||
|
ac.downvotes,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved,
|
||||||
|
um.recipient_id
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
left join user_mention um on um.comment_id = ac.id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
ac.creator_id,
|
||||||
|
ac.post_id,
|
||||||
|
ac.parent_id,
|
||||||
|
ac.content,
|
||||||
|
ac.removed,
|
||||||
|
um.read,
|
||||||
|
ac.published,
|
||||||
|
ac.updated,
|
||||||
|
ac.deleted,
|
||||||
|
ac.community_id,
|
||||||
|
ac.banned,
|
||||||
|
ac.banned_from_community,
|
||||||
|
ac.creator_name,
|
||||||
|
ac.creator_avatar,
|
||||||
|
ac.score,
|
||||||
|
ac.upvotes,
|
||||||
|
ac.downvotes,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as saved,
|
||||||
|
um.recipient_id
|
||||||
|
from all_comment ac
|
||||||
|
left join user_mention um on um.comment_id = ac.id
|
||||||
|
;
|
||||||
|
|
220
server/migrations/2020-02-07-210055_add_comment_subscribed/up.sql
vendored
Normal file
220
server/migrations/2020-02-07-210055_add_comment_subscribed/up.sql
vendored
Normal file
|
@ -0,0 +1,220 @@
|
||||||
|
|
||||||
|
-- Adding community name, hot_rank, to comment_view, user_mention_view, and subscribed to comment_view
|
||||||
|
|
||||||
|
-- Rebuild the comment view
|
||||||
|
drop view reply_view;
|
||||||
|
drop view user_mention_view;
|
||||||
|
drop view user_mention_mview;
|
||||||
|
drop view comment_view;
|
||||||
|
drop view comment_mview;
|
||||||
|
drop materialized view comment_aggregates_mview;
|
||||||
|
drop view comment_aggregates_view;
|
||||||
|
|
||||||
|
-- reply and comment view
|
||||||
|
create view comment_aggregates_view as
|
||||||
|
select
|
||||||
|
c.*,
|
||||||
|
(select community_id from post p where p.id = c.post_id),
|
||||||
|
(select co.name from post p, community co where p.id = c.post_id and p.community_id = co.id) as community_name,
|
||||||
|
(select u.banned from user_ u where c.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb, post p where c.creator_id = cb.user_id and p.id = c.post_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where c.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where c.creator_id = user_.id) as creator_avatar,
|
||||||
|
coalesce(sum(cl.score), 0) as score,
|
||||||
|
count (case when cl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when cl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(cl.score) , 0), c.published) as hot_rank
|
||||||
|
from comment c
|
||||||
|
left join comment_like cl on c.id = cl.comment_id
|
||||||
|
group by c.id;
|
||||||
|
|
||||||
|
create materialized view comment_aggregates_mview as select * from comment_aggregates_view;
|
||||||
|
|
||||||
|
create unique index idx_comment_aggregates_mview_id on comment_aggregates_mview (id);
|
||||||
|
|
||||||
|
create view comment_view as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
ca.*
|
||||||
|
from comment_aggregates_view ca
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.community_id = cf.community_id) as subscribed,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as saved
|
||||||
|
from all_comment ac
|
||||||
|
;
|
||||||
|
|
||||||
|
create view comment_mview as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
ca.*
|
||||||
|
from comment_aggregates_mview ca
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.community_id = cf.community_id) as subscribed,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as saved
|
||||||
|
from all_comment ac
|
||||||
|
;
|
||||||
|
|
||||||
|
-- Do the reply_view referencing the comment_mview
|
||||||
|
create view reply_view as
|
||||||
|
with closereply as (
|
||||||
|
select
|
||||||
|
c2.id,
|
||||||
|
c2.creator_id as sender_id,
|
||||||
|
c.creator_id as recipient_id
|
||||||
|
from comment c
|
||||||
|
inner join comment c2 on c.id = c2.parent_id
|
||||||
|
where c2.creator_id != c.creator_id
|
||||||
|
-- Do union where post is null
|
||||||
|
union
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
c.creator_id as sender_id,
|
||||||
|
p.creator_id as recipient_id
|
||||||
|
from comment c, post p
|
||||||
|
where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
|
||||||
|
)
|
||||||
|
select cv.*,
|
||||||
|
closereply.recipient_id
|
||||||
|
from comment_mview cv, closereply
|
||||||
|
where closereply.id = cv.id
|
||||||
|
;
|
||||||
|
|
||||||
|
-- user mention
|
||||||
|
create view user_mention_view as
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
c.creator_id,
|
||||||
|
c.post_id,
|
||||||
|
c.parent_id,
|
||||||
|
c.content,
|
||||||
|
c.removed,
|
||||||
|
um.read,
|
||||||
|
c.published,
|
||||||
|
c.updated,
|
||||||
|
c.deleted,
|
||||||
|
c.community_id,
|
||||||
|
c.community_name,
|
||||||
|
c.banned,
|
||||||
|
c.banned_from_community,
|
||||||
|
c.creator_name,
|
||||||
|
c.creator_avatar,
|
||||||
|
c.score,
|
||||||
|
c.upvotes,
|
||||||
|
c.downvotes,
|
||||||
|
c.hot_rank,
|
||||||
|
c.user_id,
|
||||||
|
c.my_vote,
|
||||||
|
c.saved,
|
||||||
|
um.recipient_id
|
||||||
|
from user_mention um, comment_view c
|
||||||
|
where um.comment_id = c.id;
|
||||||
|
|
||||||
|
|
||||||
|
create view user_mention_mview as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
ca.*
|
||||||
|
from comment_aggregates_mview ca
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
ac.creator_id,
|
||||||
|
ac.post_id,
|
||||||
|
ac.parent_id,
|
||||||
|
ac.content,
|
||||||
|
ac.removed,
|
||||||
|
um.read,
|
||||||
|
ac.published,
|
||||||
|
ac.updated,
|
||||||
|
ac.deleted,
|
||||||
|
ac.community_id,
|
||||||
|
ac.community_name,
|
||||||
|
ac.banned,
|
||||||
|
ac.banned_from_community,
|
||||||
|
ac.creator_name,
|
||||||
|
ac.creator_avatar,
|
||||||
|
ac.score,
|
||||||
|
ac.upvotes,
|
||||||
|
ac.downvotes,
|
||||||
|
ac.hot_rank,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved,
|
||||||
|
um.recipient_id
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
left join user_mention um on um.comment_id = ac.id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
ac.creator_id,
|
||||||
|
ac.post_id,
|
||||||
|
ac.parent_id,
|
||||||
|
ac.content,
|
||||||
|
ac.removed,
|
||||||
|
um.read,
|
||||||
|
ac.published,
|
||||||
|
ac.updated,
|
||||||
|
ac.deleted,
|
||||||
|
ac.community_id,
|
||||||
|
ac.community_name,
|
||||||
|
ac.banned,
|
||||||
|
ac.banned_from_community,
|
||||||
|
ac.creator_name,
|
||||||
|
ac.creator_avatar,
|
||||||
|
ac.score,
|
||||||
|
ac.upvotes,
|
||||||
|
ac.downvotes,
|
||||||
|
ac.hot_rank,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as saved,
|
||||||
|
um.recipient_id
|
||||||
|
from all_comment ac
|
||||||
|
left join user_mention um on um.comment_id = ac.id
|
||||||
|
;
|
||||||
|
|
88
server/migrations/2020-02-08-145624_add_post_newest_activity_time/down.sql
vendored
Normal file
88
server/migrations/2020-02-08-145624_add_post_newest_activity_time/down.sql
vendored
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
drop view post_view;
|
||||||
|
drop view post_mview;
|
||||||
|
drop materialized view post_aggregates_mview;
|
||||||
|
drop view post_aggregates_view;
|
||||||
|
|
||||||
|
-- regen post view
|
||||||
|
create view post_aggregates_view as
|
||||||
|
select
|
||||||
|
p.*,
|
||||||
|
(select u.banned from user_ u where p.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb where p.creator_id = cb.user_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where p.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where p.creator_id = user_.id) as creator_avatar,
|
||||||
|
(select name from community where p.community_id = community.id) as community_name,
|
||||||
|
(select removed from community c where p.community_id = c.id) as community_removed,
|
||||||
|
(select deleted from community c where p.community_id = c.id) as community_deleted,
|
||||||
|
(select nsfw from community c where p.community_id = c.id) as community_nsfw,
|
||||||
|
(select count(*) from comment where comment.post_id = p.id) as number_of_comments,
|
||||||
|
coalesce(sum(pl.score), 0) as score,
|
||||||
|
count (case when pl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when pl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(pl.score) , 0), p.published) as hot_rank
|
||||||
|
from post p
|
||||||
|
left join post_like pl on p.id = pl.post_id
|
||||||
|
group by p.id;
|
||||||
|
|
||||||
|
create materialized view post_aggregates_mview as select * from post_aggregates_view;
|
||||||
|
|
||||||
|
create unique index idx_post_aggregates_mview_id on post_aggregates_mview (id);
|
||||||
|
|
||||||
|
create view post_view as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_view pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
create view post_mview as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_mview pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
106
server/migrations/2020-02-08-145624_add_post_newest_activity_time/up.sql
vendored
Normal file
106
server/migrations/2020-02-08-145624_add_post_newest_activity_time/up.sql
vendored
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
-- Adds a newest_activity_time for the post_views, in order to sort by newest comment
|
||||||
|
drop view post_view;
|
||||||
|
drop view post_mview;
|
||||||
|
drop materialized view post_aggregates_mview;
|
||||||
|
drop view post_aggregates_view;
|
||||||
|
|
||||||
|
-- regen post view
|
||||||
|
create view post_aggregates_view as
|
||||||
|
select
|
||||||
|
p.*,
|
||||||
|
(select u.banned from user_ u where p.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb where p.creator_id = cb.user_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where p.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where p.creator_id = user_.id) as creator_avatar,
|
||||||
|
(select name from community where p.community_id = community.id) as community_name,
|
||||||
|
(select removed from community c where p.community_id = c.id) as community_removed,
|
||||||
|
(select deleted from community c where p.community_id = c.id) as community_deleted,
|
||||||
|
(select nsfw from community c where p.community_id = c.id) as community_nsfw,
|
||||||
|
(select count(*) from comment where comment.post_id = p.id) as number_of_comments,
|
||||||
|
coalesce(sum(pl.score), 0) as score,
|
||||||
|
count (case when pl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when pl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(pl.score) , 0),
|
||||||
|
(
|
||||||
|
case when (p.published < ('now'::timestamp - '1 month'::interval)) then p.published -- Prevents necro-bumps
|
||||||
|
else greatest(c.recent_comment_time, p.published)
|
||||||
|
end
|
||||||
|
)
|
||||||
|
) as hot_rank,
|
||||||
|
(
|
||||||
|
case when (p.published < ('now'::timestamp - '1 month'::interval)) then p.published -- Prevents necro-bumps
|
||||||
|
else greatest(c.recent_comment_time, p.published)
|
||||||
|
end
|
||||||
|
) as newest_activity_time
|
||||||
|
from post p
|
||||||
|
left join post_like pl on p.id = pl.post_id
|
||||||
|
left join (
|
||||||
|
select post_id,
|
||||||
|
max(published) as recent_comment_time
|
||||||
|
from comment
|
||||||
|
group by 1
|
||||||
|
) c on p.id = c.post_id
|
||||||
|
group by p.id, c.recent_comment_time;
|
||||||
|
|
||||||
|
create materialized view post_aggregates_mview as select * from post_aggregates_view;
|
||||||
|
|
||||||
|
create unique index idx_post_aggregates_mview_id on post_aggregates_mview (id);
|
||||||
|
|
||||||
|
create view post_view as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_view pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
create view post_mview as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_mview pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
112
server/migrations/2020-03-06-202329_add_post_iframely_data/down.sql
vendored
Normal file
112
server/migrations/2020-03-06-202329_add_post_iframely_data/down.sql
vendored
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
-- Adds a newest_activity_time for the post_views, in order to sort by newest comment
|
||||||
|
drop view post_view;
|
||||||
|
drop view post_mview;
|
||||||
|
drop materialized view post_aggregates_mview;
|
||||||
|
drop view post_aggregates_view;
|
||||||
|
|
||||||
|
-- Drop the columns
|
||||||
|
alter table post drop column embed_title;
|
||||||
|
alter table post drop column embed_description;
|
||||||
|
alter table post drop column embed_html;
|
||||||
|
alter table post drop column thumbnail_url;
|
||||||
|
|
||||||
|
-- regen post view
|
||||||
|
create view post_aggregates_view as
|
||||||
|
select
|
||||||
|
p.*,
|
||||||
|
(select u.banned from user_ u where p.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb where p.creator_id = cb.user_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where p.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where p.creator_id = user_.id) as creator_avatar,
|
||||||
|
(select name from community where p.community_id = community.id) as community_name,
|
||||||
|
(select removed from community c where p.community_id = c.id) as community_removed,
|
||||||
|
(select deleted from community c where p.community_id = c.id) as community_deleted,
|
||||||
|
(select nsfw from community c where p.community_id = c.id) as community_nsfw,
|
||||||
|
(select count(*) from comment where comment.post_id = p.id) as number_of_comments,
|
||||||
|
coalesce(sum(pl.score), 0) as score,
|
||||||
|
count (case when pl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when pl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(pl.score) , 0),
|
||||||
|
(
|
||||||
|
case when (p.published < ('now'::timestamp - '1 month'::interval)) then p.published -- Prevents necro-bumps
|
||||||
|
else greatest(c.recent_comment_time, p.published)
|
||||||
|
end
|
||||||
|
)
|
||||||
|
) as hot_rank,
|
||||||
|
(
|
||||||
|
case when (p.published < ('now'::timestamp - '1 month'::interval)) then p.published -- Prevents necro-bumps
|
||||||
|
else greatest(c.recent_comment_time, p.published)
|
||||||
|
end
|
||||||
|
) as newest_activity_time
|
||||||
|
from post p
|
||||||
|
left join post_like pl on p.id = pl.post_id
|
||||||
|
left join (
|
||||||
|
select post_id,
|
||||||
|
max(published) as recent_comment_time
|
||||||
|
from comment
|
||||||
|
group by 1
|
||||||
|
) c on p.id = c.post_id
|
||||||
|
group by p.id, c.recent_comment_time;
|
||||||
|
|
||||||
|
create materialized view post_aggregates_mview as select * from post_aggregates_view;
|
||||||
|
|
||||||
|
create unique index idx_post_aggregates_mview_id on post_aggregates_mview (id);
|
||||||
|
|
||||||
|
create view post_view as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_view pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
create view post_mview as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_mview pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
115
server/migrations/2020-03-06-202329_add_post_iframely_data/up.sql
vendored
Normal file
115
server/migrations/2020-03-06-202329_add_post_iframely_data/up.sql
vendored
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
-- Add the columns
|
||||||
|
alter table post add column embed_title text;
|
||||||
|
alter table post add column embed_description text;
|
||||||
|
alter table post add column embed_html text;
|
||||||
|
alter table post add column thumbnail_url text;
|
||||||
|
|
||||||
|
-- Regenerate the views
|
||||||
|
|
||||||
|
-- Adds a newest_activity_time for the post_views, in order to sort by newest comment
|
||||||
|
drop view post_view;
|
||||||
|
drop view post_mview;
|
||||||
|
drop materialized view post_aggregates_mview;
|
||||||
|
drop view post_aggregates_view;
|
||||||
|
|
||||||
|
-- regen post view
|
||||||
|
create view post_aggregates_view as
|
||||||
|
select
|
||||||
|
p.*,
|
||||||
|
(select u.banned from user_ u where p.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb where p.creator_id = cb.user_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where p.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where p.creator_id = user_.id) as creator_avatar,
|
||||||
|
(select name from community where p.community_id = community.id) as community_name,
|
||||||
|
(select removed from community c where p.community_id = c.id) as community_removed,
|
||||||
|
(select deleted from community c where p.community_id = c.id) as community_deleted,
|
||||||
|
(select nsfw from community c where p.community_id = c.id) as community_nsfw,
|
||||||
|
(select count(*) from comment where comment.post_id = p.id) as number_of_comments,
|
||||||
|
coalesce(sum(pl.score), 0) as score,
|
||||||
|
count (case when pl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when pl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(pl.score) , 0),
|
||||||
|
(
|
||||||
|
case when (p.published < ('now'::timestamp - '1 month'::interval)) then p.published -- Prevents necro-bumps
|
||||||
|
else greatest(c.recent_comment_time, p.published)
|
||||||
|
end
|
||||||
|
)
|
||||||
|
) as hot_rank,
|
||||||
|
(
|
||||||
|
case when (p.published < ('now'::timestamp - '1 month'::interval)) then p.published -- Prevents necro-bumps
|
||||||
|
else greatest(c.recent_comment_time, p.published)
|
||||||
|
end
|
||||||
|
) as newest_activity_time
|
||||||
|
from post p
|
||||||
|
left join post_like pl on p.id = pl.post_id
|
||||||
|
left join (
|
||||||
|
select post_id,
|
||||||
|
max(published) as recent_comment_time
|
||||||
|
from comment
|
||||||
|
group by 1
|
||||||
|
) c on p.id = c.post_id
|
||||||
|
group by p.id, c.recent_comment_time;
|
||||||
|
|
||||||
|
create materialized view post_aggregates_mview as select * from post_aggregates_view;
|
||||||
|
|
||||||
|
create unique index idx_post_aggregates_mview_id on post_aggregates_mview (id);
|
||||||
|
|
||||||
|
create view post_view as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_view pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
create view post_mview as
|
||||||
|
with all_post as (
|
||||||
|
select
|
||||||
|
pa.*
|
||||||
|
from post_aggregates_mview pa
|
||||||
|
)
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
|
211
server/migrations_testing/2020-01-13-025151_create_materialized_views/down.sql
vendored
Normal file
211
server/migrations_testing/2020-01-13-025151_create_materialized_views/down.sql
vendored
Normal file
|
@ -0,0 +1,211 @@
|
||||||
|
-- functions and triggers
|
||||||
|
drop trigger refresh_user on user_;
|
||||||
|
drop function refresh_user();
|
||||||
|
drop trigger refresh_post on post;
|
||||||
|
drop function refresh_post();
|
||||||
|
drop trigger refresh_post_like on post_like;
|
||||||
|
drop function refresh_post_like();
|
||||||
|
drop trigger refresh_community on community;
|
||||||
|
drop function refresh_community();
|
||||||
|
drop trigger refresh_community_follower on community_follower;
|
||||||
|
drop function refresh_community_follower();
|
||||||
|
drop trigger refresh_comment on comment;
|
||||||
|
drop function refresh_comment();
|
||||||
|
drop trigger refresh_comment_like on comment_like;
|
||||||
|
drop function refresh_comment_like();
|
||||||
|
|
||||||
|
-- post
|
||||||
|
-- Recreate the view
|
||||||
|
drop materialized view post_view;
|
||||||
|
create view post_view as
|
||||||
|
with all_post as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
p.*,
|
||||||
|
(select u.banned from user_ u where p.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb where p.creator_id = cb.user_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where p.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where p.creator_id = user_.id) as creator_avatar,
|
||||||
|
(select name from community where p.community_id = community.id) as community_name,
|
||||||
|
(select removed from community c where p.community_id = c.id) as community_removed,
|
||||||
|
(select deleted from community c where p.community_id = c.id) as community_deleted,
|
||||||
|
(select nsfw from community c where p.community_id = c.id) as community_nsfw,
|
||||||
|
(select count(*) from comment where comment.post_id = p.id) as number_of_comments,
|
||||||
|
coalesce(sum(pl.score), 0) as score,
|
||||||
|
count (case when pl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when pl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(pl.score) , 0), p.published) as hot_rank
|
||||||
|
from post p
|
||||||
|
left join post_like pl on p.id = pl.post_id
|
||||||
|
group by p.id
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
drop materialized view user_view;
|
||||||
|
create view user_view as
|
||||||
|
select id,
|
||||||
|
name,
|
||||||
|
avatar,
|
||||||
|
email,
|
||||||
|
fedi_name,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
show_avatars,
|
||||||
|
send_notifications_to_email,
|
||||||
|
published,
|
||||||
|
(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
|
||||||
|
(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
|
||||||
|
(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
|
||||||
|
(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
|
||||||
|
from user_ u;
|
||||||
|
|
||||||
|
|
||||||
|
-- community
|
||||||
|
drop materialized view community_view;
|
||||||
|
create view community_view as
|
||||||
|
with all_community as
|
||||||
|
(
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where c.creator_id = u.id) as creator_name,
|
||||||
|
(select avatar from user_ u where c.creator_id = u.id) as creator_avatar,
|
||||||
|
(select name from category ct where c.category_id = ct.id) as category_name,
|
||||||
|
(select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers,
|
||||||
|
(select count(*) from post p where p.community_id = c.id) as number_of_posts,
|
||||||
|
(select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments,
|
||||||
|
hot_rank((select count(*) from community_follower cf where cf.community_id = c.id), c.published) as hot_rank
|
||||||
|
from community c
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed
|
||||||
|
from user_ u
|
||||||
|
cross join all_community ac
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as subscribed
|
||||||
|
from all_community ac
|
||||||
|
;
|
||||||
|
|
||||||
|
-- reply and comment view
|
||||||
|
drop view reply_view;
|
||||||
|
drop view user_mention_view;
|
||||||
|
drop materialized view comment_view;
|
||||||
|
create view comment_view as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
c.*,
|
||||||
|
(select community_id from post p where p.id = c.post_id),
|
||||||
|
(select u.banned from user_ u where c.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb, post p where c.creator_id = cb.user_id and p.id = c.post_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where c.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where c.creator_id = user_.id) as creator_avatar,
|
||||||
|
coalesce(sum(cl.score), 0) as score,
|
||||||
|
count (case when cl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when cl.score = -1 then 1 else null end) as downvotes
|
||||||
|
from comment c
|
||||||
|
left join comment_like cl on c.id = cl.comment_id
|
||||||
|
group by c.id
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as saved
|
||||||
|
from all_comment ac
|
||||||
|
;
|
||||||
|
|
||||||
|
create view reply_view as
|
||||||
|
with closereply as (
|
||||||
|
select
|
||||||
|
c2.id,
|
||||||
|
c2.creator_id as sender_id,
|
||||||
|
c.creator_id as recipient_id
|
||||||
|
from comment c
|
||||||
|
inner join comment c2 on c.id = c2.parent_id
|
||||||
|
where c2.creator_id != c.creator_id
|
||||||
|
-- Do union where post is null
|
||||||
|
union
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
c.creator_id as sender_id,
|
||||||
|
p.creator_id as recipient_id
|
||||||
|
from comment c, post p
|
||||||
|
where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
|
||||||
|
)
|
||||||
|
select cv.*,
|
||||||
|
closereply.recipient_id
|
||||||
|
from comment_view cv, closereply
|
||||||
|
where closereply.id = cv.id
|
||||||
|
;
|
||||||
|
|
||||||
|
-- user mention
|
||||||
|
create view user_mention_view as
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
c.creator_id,
|
||||||
|
c.post_id,
|
||||||
|
c.parent_id,
|
||||||
|
c.content,
|
||||||
|
c.removed,
|
||||||
|
um.read,
|
||||||
|
c.published,
|
||||||
|
c.updated,
|
||||||
|
c.deleted,
|
||||||
|
c.community_id,
|
||||||
|
c.banned,
|
||||||
|
c.banned_from_community,
|
||||||
|
c.creator_name,
|
||||||
|
c.creator_avatar,
|
||||||
|
c.score,
|
||||||
|
c.upvotes,
|
||||||
|
c.downvotes,
|
||||||
|
c.user_id,
|
||||||
|
c.my_vote,
|
||||||
|
c.saved,
|
||||||
|
um.recipient_id
|
||||||
|
from user_mention um, comment_view c
|
||||||
|
where um.comment_id = c.id;
|
||||||
|
|
324
server/migrations_testing/2020-01-13-025151_create_materialized_views/up.sql
vendored
Normal file
324
server/migrations_testing/2020-01-13-025151_create_materialized_views/up.sql
vendored
Normal file
|
@ -0,0 +1,324 @@
|
||||||
|
-- post
|
||||||
|
drop view post_view;
|
||||||
|
create materialized view post_view as
|
||||||
|
with all_post as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
p.*,
|
||||||
|
(select u.banned from user_ u where p.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb where p.creator_id = cb.user_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where p.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where p.creator_id = user_.id) as creator_avatar,
|
||||||
|
(select name from community where p.community_id = community.id) as community_name,
|
||||||
|
(select removed from community c where p.community_id = c.id) as community_removed,
|
||||||
|
(select deleted from community c where p.community_id = c.id) as community_deleted,
|
||||||
|
(select nsfw from community c where p.community_id = c.id) as community_nsfw,
|
||||||
|
(select count(*) from comment where comment.post_id = p.id) as number_of_comments,
|
||||||
|
coalesce(sum(pl.score), 0) as score,
|
||||||
|
count (case when pl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when pl.score = -1 then 1 else null end) as downvotes,
|
||||||
|
hot_rank(coalesce(sum(pl.score) , 0), p.published) as hot_rank
|
||||||
|
from post p
|
||||||
|
left join post_like pl on p.id = pl.post_id
|
||||||
|
group by p.id
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(pl.score, 0) as my_vote,
|
||||||
|
(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed,
|
||||||
|
(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read,
|
||||||
|
(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_post ap
|
||||||
|
left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ap.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as subscribed,
|
||||||
|
null as read,
|
||||||
|
null as saved
|
||||||
|
from all_post ap
|
||||||
|
with data
|
||||||
|
;
|
||||||
|
|
||||||
|
create unique index idx_post_view_unique on post_view (id, user_id);
|
||||||
|
create index idx_post_view_user_id on post_view (user_id);
|
||||||
|
create index idx_post_view_hot_rank_published on post_view (hot_rank desc, published desc);
|
||||||
|
create index idx_post_view_published on post_view (published desc);
|
||||||
|
create index idx_post_view_score on post_view (score desc);
|
||||||
|
|
||||||
|
-- user_view
|
||||||
|
drop view user_view;
|
||||||
|
create materialized view user_view as
|
||||||
|
select id,
|
||||||
|
name,
|
||||||
|
avatar,
|
||||||
|
email,
|
||||||
|
fedi_name,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
show_avatars,
|
||||||
|
send_notifications_to_email,
|
||||||
|
published,
|
||||||
|
(select count(*) from post p where p.creator_id = u.id) as number_of_posts,
|
||||||
|
(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score,
|
||||||
|
(select count(*) from comment c where c.creator_id = u.id) as number_of_comments,
|
||||||
|
(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score
|
||||||
|
from user_ u;
|
||||||
|
|
||||||
|
create unique index idx_user_view_unique on user_view (id);
|
||||||
|
create index idx_user_view_comment_published on user_view (comment_score desc, published desc);
|
||||||
|
create index idx_user_view_admin on user_view (admin);
|
||||||
|
create index idx_user_view_banned on user_view (banned);
|
||||||
|
|
||||||
|
-- community
|
||||||
|
drop view community_view;
|
||||||
|
create materialized view community_view as
|
||||||
|
with all_community as
|
||||||
|
(
|
||||||
|
select *,
|
||||||
|
(select name from user_ u where c.creator_id = u.id) as creator_name,
|
||||||
|
(select avatar from user_ u where c.creator_id = u.id) as creator_avatar,
|
||||||
|
(select name from category ct where c.category_id = ct.id) as category_name,
|
||||||
|
(select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers,
|
||||||
|
(select count(*) from post p where p.community_id = c.id) as number_of_posts,
|
||||||
|
(select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments,
|
||||||
|
hot_rank((select count(*) from community_follower cf where cf.community_id = c.id), c.published) as hot_rank
|
||||||
|
from community c
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed
|
||||||
|
from user_ u
|
||||||
|
cross join all_community ac
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as subscribed
|
||||||
|
from all_community ac
|
||||||
|
;
|
||||||
|
|
||||||
|
create unique index idx_community_view_unique on community_view (id, user_id);
|
||||||
|
create index idx_community_view_user_id on community_view (user_id);
|
||||||
|
create index idx_community_view_hot_rank_subscribed on community_view (hot_rank desc, number_of_subscribers desc);
|
||||||
|
|
||||||
|
|
||||||
|
-- reply and comment view
|
||||||
|
drop view reply_view;
|
||||||
|
drop view user_mention_view;
|
||||||
|
drop view comment_view;
|
||||||
|
create materialized view comment_view as
|
||||||
|
with all_comment as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
c.*,
|
||||||
|
(select community_id from post p where p.id = c.post_id),
|
||||||
|
(select u.banned from user_ u where c.creator_id = u.id) as banned,
|
||||||
|
(select cb.id::bool from community_user_ban cb, post p where c.creator_id = cb.user_id and p.id = c.post_id and p.community_id = cb.community_id) as banned_from_community,
|
||||||
|
(select name from user_ where c.creator_id = user_.id) as creator_name,
|
||||||
|
(select avatar from user_ where c.creator_id = user_.id) as creator_avatar,
|
||||||
|
coalesce(sum(cl.score), 0) as score,
|
||||||
|
count (case when cl.score = 1 then 1 else null end) as upvotes,
|
||||||
|
count (case when cl.score = -1 then 1 else null end) as downvotes
|
||||||
|
from comment c
|
||||||
|
left join comment_like cl on c.id = cl.comment_id
|
||||||
|
group by c.id
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
u.id as user_id,
|
||||||
|
coalesce(cl.score, 0) as my_vote,
|
||||||
|
(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
|
||||||
|
from user_ u
|
||||||
|
cross join all_comment ac
|
||||||
|
left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
|
||||||
|
|
||||||
|
union all
|
||||||
|
|
||||||
|
select
|
||||||
|
ac.*,
|
||||||
|
null as user_id,
|
||||||
|
null as my_vote,
|
||||||
|
null as saved
|
||||||
|
from all_comment ac
|
||||||
|
;
|
||||||
|
|
||||||
|
create unique index idx_comment_view_unique on comment_view (id, user_id);
|
||||||
|
create index idx_comment_view_user_id on comment_view (user_id);
|
||||||
|
create index idx_comment_view_creator_id on comment_view (creator_id);
|
||||||
|
create index idx_comment_view_post_id on comment_view (post_id);
|
||||||
|
create index idx_comment_view_score on comment_view (score desc);
|
||||||
|
|
||||||
|
create view reply_view as
|
||||||
|
with closereply as (
|
||||||
|
select
|
||||||
|
c2.id,
|
||||||
|
c2.creator_id as sender_id,
|
||||||
|
c.creator_id as recipient_id
|
||||||
|
from comment c
|
||||||
|
inner join comment c2 on c.id = c2.parent_id
|
||||||
|
where c2.creator_id != c.creator_id
|
||||||
|
-- Do union where post is null
|
||||||
|
union
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
c.creator_id as sender_id,
|
||||||
|
p.creator_id as recipient_id
|
||||||
|
from comment c, post p
|
||||||
|
where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
|
||||||
|
)
|
||||||
|
select cv.*,
|
||||||
|
closereply.recipient_id
|
||||||
|
from comment_view cv, closereply
|
||||||
|
where closereply.id = cv.id
|
||||||
|
;
|
||||||
|
|
||||||
|
-- user mention
|
||||||
|
create view user_mention_view as
|
||||||
|
select
|
||||||
|
c.id,
|
||||||
|
um.id as user_mention_id,
|
||||||
|
c.creator_id,
|
||||||
|
c.post_id,
|
||||||
|
c.parent_id,
|
||||||
|
c.content,
|
||||||
|
c.removed,
|
||||||
|
um.read,
|
||||||
|
c.published,
|
||||||
|
c.updated,
|
||||||
|
c.deleted,
|
||||||
|
c.community_id,
|
||||||
|
c.banned,
|
||||||
|
c.banned_from_community,
|
||||||
|
c.creator_name,
|
||||||
|
c.creator_avatar,
|
||||||
|
c.score,
|
||||||
|
c.upvotes,
|
||||||
|
c.downvotes,
|
||||||
|
c.user_id,
|
||||||
|
c.my_vote,
|
||||||
|
c.saved,
|
||||||
|
um.recipient_id
|
||||||
|
from user_mention um, comment_view c
|
||||||
|
where um.comment_id = c.id;
|
||||||
|
|
||||||
|
-- user
|
||||||
|
create or replace function refresh_user()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently comment_view; -- cause of bans
|
||||||
|
refresh materialized view concurrently post_view;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_user
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on user_
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_user();
|
||||||
|
|
||||||
|
-- post
|
||||||
|
create or replace function refresh_post()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently post_view;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_post
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on post
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_post();
|
||||||
|
|
||||||
|
-- post_like
|
||||||
|
create or replace function refresh_post_like()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently post_view;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_post_like
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on post_like
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_post_like();
|
||||||
|
|
||||||
|
-- community
|
||||||
|
create or replace function refresh_community()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently post_view;
|
||||||
|
refresh materialized view concurrently community_view;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_community
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on community
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_community();
|
||||||
|
|
||||||
|
-- community_follower
|
||||||
|
create or replace function refresh_community_follower()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently community_view;
|
||||||
|
refresh materialized view concurrently post_view;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_community_follower
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on community_follower
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_community_follower();
|
||||||
|
|
||||||
|
-- comment
|
||||||
|
create or replace function refresh_comment()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently post_view;
|
||||||
|
refresh materialized view concurrently comment_view;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_comment
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on comment
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_comment();
|
||||||
|
|
||||||
|
-- comment_like
|
||||||
|
create or replace function refresh_comment_like()
|
||||||
|
returns trigger language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
refresh materialized view concurrently comment_view;
|
||||||
|
return null;
|
||||||
|
end $$;
|
||||||
|
|
||||||
|
create trigger refresh_comment_like
|
||||||
|
after insert or update or delete or truncate
|
||||||
|
on comment_like
|
||||||
|
for each statement
|
||||||
|
execute procedure refresh_comment_like();
|
26
server/query_testing/apache_bench_report.sh
vendored
Executable file
26
server/query_testing/apache_bench_report.sh
vendored
Executable file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
declare -a arr=(
|
||||||
|
"https://mastodon.social/"
|
||||||
|
"https://peertube.social/"
|
||||||
|
"https://dev.lemmy.ml/"
|
||||||
|
"https://dev.lemmy.ml/feeds/all.xml"
|
||||||
|
"https://dev.lemmy.ml/.well-known/nodeinfo"
|
||||||
|
"https://fediverse.blog/.well-known/nodeinfo"
|
||||||
|
"https://torrents-csv.ml/service/search?q=wheel&page=1&type_=torrent"
|
||||||
|
)
|
||||||
|
|
||||||
|
## now loop through the above array
|
||||||
|
for i in "${arr[@]}"
|
||||||
|
do
|
||||||
|
ab -c 10 -t 10 "$i" > out.abtest
|
||||||
|
grep "Server Hostname:" out.abtest
|
||||||
|
grep "Document Path:" out.abtest
|
||||||
|
grep "Requests per second" out.abtest
|
||||||
|
grep "(mean, across all concurrent requests)" out.abtest
|
||||||
|
grep "Transfer rate:" out.abtest
|
||||||
|
echo "---"
|
||||||
|
done
|
||||||
|
|
||||||
|
rm *.abtest
|
34
server/query_testing/api_benchmark.sh
vendored
Executable file
34
server/query_testing/api_benchmark.sh
vendored
Executable file
|
@ -0,0 +1,34 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# By default, this script runs against `http://127.0.0.1:8536`, but you can pass a different Lemmy instance,
|
||||||
|
# eg `./api_benchmark.sh "https://example.com"`.
|
||||||
|
DOMAIN=${1:-"http://127.0.0.1:8536"}
|
||||||
|
|
||||||
|
declare -a arr=(
|
||||||
|
"/api/v1/site"
|
||||||
|
"/api/v1/categories"
|
||||||
|
"/api/v1/modlog"
|
||||||
|
"/api/v1/search?q=test&type_=Posts&sort=Hot"
|
||||||
|
"/api/v1/community"
|
||||||
|
"/api/v1/community/list?sort=Hot"
|
||||||
|
"/api/v1/post/list?sort=Hot&type_=All"
|
||||||
|
)
|
||||||
|
|
||||||
|
## now loop through the above array
|
||||||
|
for path in "${arr[@]}"
|
||||||
|
do
|
||||||
|
URL="$DOMAIN$path"
|
||||||
|
printf "\n\n\n"
|
||||||
|
echo "testing $URL"
|
||||||
|
curl --show-error --fail --silent "$URL" >/dev/null
|
||||||
|
ab -c 64 -t 10 "$URL" > out.abtest
|
||||||
|
grep "Server Hostname:" out.abtest
|
||||||
|
grep "Document Path:" out.abtest
|
||||||
|
grep "Requests per second" out.abtest
|
||||||
|
grep "(mean, across all concurrent requests)" out.abtest
|
||||||
|
grep "Transfer rate:" out.abtest
|
||||||
|
echo "---"
|
||||||
|
done
|
||||||
|
|
||||||
|
rm *.abtest
|
32
server/query_testing/generate_explain_reports.sh
vendored
Executable file
32
server/query_testing/generate_explain_reports.sh
vendored
Executable file
|
@ -0,0 +1,32 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Do the views first
|
||||||
|
|
||||||
|
echo "explain (analyze, format json) select * from user_mview" > explain.sql
|
||||||
|
psql -qAt -U lemmy -f explain.sql > user_view.json
|
||||||
|
|
||||||
|
echo "explain (analyze, format json) select * from post_mview where user_id is null order by hot_rank desc, published desc" > explain.sql
|
||||||
|
psql -qAt -U lemmy -f explain.sql > post_view.json
|
||||||
|
|
||||||
|
echo "explain (analyze, format json) select * from comment_mview where user_id is null" > explain.sql
|
||||||
|
psql -qAt -U lemmy -f explain.sql > comment_view.json
|
||||||
|
|
||||||
|
echo "explain (analyze, format json) select * from community_mview where user_id is null order by hot_rank desc" > explain.sql
|
||||||
|
psql -qAt -U lemmy -f explain.sql > community_view.json
|
||||||
|
|
||||||
|
echo "explain (analyze, format json) select * from site_view limit 1" > explain.sql
|
||||||
|
psql -qAt -U lemmy -f explain.sql > site_view.json
|
||||||
|
|
||||||
|
echo "explain (analyze, format json) select * from reply_view where user_id = 34 and recipient_id = 34" > explain.sql
|
||||||
|
psql -qAt -U lemmy -f explain.sql > reply_view.json
|
||||||
|
|
||||||
|
echo "explain (analyze, format json) select * from user_mention_view where user_id = 34 and recipient_id = 34" > explain.sql
|
||||||
|
psql -qAt -U lemmy -f explain.sql > user_mention_view.json
|
||||||
|
|
||||||
|
echo "explain (analyze, format json) select * from user_mention_mview where user_id = 34 and recipient_id = 34" > explain.sql
|
||||||
|
psql -qAt -U lemmy -f explain.sql > user_mention_mview.json
|
||||||
|
|
||||||
|
grep "Execution Time" *.json
|
||||||
|
|
||||||
|
rm explain.sql
|
|
@ -1,10 +1,15 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::send_email;
|
||||||
|
use crate::settings::Settings;
|
||||||
|
use diesel::PgConnection;
|
||||||
|
use log::error;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct CreateComment {
|
pub struct CreateComment {
|
||||||
content: String,
|
content: String,
|
||||||
parent_id: Option<i32>,
|
parent_id: Option<i32>,
|
||||||
edit_id: Option<i32>,
|
edit_id: Option<i32>, // TODO this isn't used
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
auth: String,
|
auth: String,
|
||||||
}
|
}
|
||||||
|
@ -12,7 +17,7 @@ pub struct CreateComment {
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct EditComment {
|
pub struct EditComment {
|
||||||
content: String,
|
content: String,
|
||||||
parent_id: Option<i32>,
|
parent_id: Option<i32>, // TODO why are the parent_id, creator_id, post_id, etc fields required? They aren't going to change
|
||||||
edit_id: i32,
|
edit_id: i32,
|
||||||
creator_id: i32,
|
creator_id: i32,
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
|
@ -32,8 +37,8 @@ pub struct SaveComment {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct CommentResponse {
|
pub struct CommentResponse {
|
||||||
op: String,
|
|
||||||
pub comment: CommentView,
|
pub comment: CommentView,
|
||||||
|
pub recipient_ids: Vec<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
@ -44,27 +49,43 @@ pub struct CreateCommentLike {
|
||||||
auth: String,
|
auth: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetComments {
|
||||||
|
type_: String,
|
||||||
|
sort: String,
|
||||||
|
page: Option<i64>,
|
||||||
|
limit: Option<i64>,
|
||||||
|
pub community_id: Option<i32>,
|
||||||
|
auth: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetCommentsResponse {
|
||||||
|
comments: Vec<CommentView>,
|
||||||
|
}
|
||||||
|
|
||||||
impl Perform<CommentResponse> for Oper<CreateComment> {
|
impl Perform<CommentResponse> for Oper<CreateComment> {
|
||||||
fn perform(&self) -> Result<CommentResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<CommentResponse, Error> {
|
||||||
let data: &CreateComment = &self.data;
|
let data: &CreateComment = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
|
||||||
|
let hostname = &format!("https://{}", Settings::get().hostname);
|
||||||
|
|
||||||
// Check for a community ban
|
// Check for a community ban
|
||||||
let post = Post::read(&conn, data.post_id)?;
|
let post = Post::read(&conn, data.post_id)?;
|
||||||
if CommunityUserBanView::get(&conn, user_id, post.community_id).is_ok() {
|
if CommunityUserBanView::get(&conn, user_id, post.community_id).is_ok() {
|
||||||
return Err(APIError::err(&self.op, "community_ban"))?;
|
return Err(APIError::err("community_ban").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a site ban
|
// Check for a site ban
|
||||||
if UserView::read(&conn, user_id)?.banned {
|
if UserView::read(&conn, user_id)?.banned {
|
||||||
return Err(APIError::err(&self.op, "site_ban"))?;
|
return Err(APIError::err("site_ban").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let content_slurs_removed = remove_slurs(&data.content.to_owned());
|
let content_slurs_removed = remove_slurs(&data.content.to_owned());
|
||||||
|
@ -82,24 +103,24 @@ impl Perform<CommentResponse> for Oper<CreateComment> {
|
||||||
|
|
||||||
let inserted_comment = match Comment::create(&conn, &comment_form) {
|
let inserted_comment = match Comment::create(&conn, &comment_form) {
|
||||||
Ok(comment) => comment,
|
Ok(comment) => comment,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_create_comment"))?,
|
Err(_e) => return Err(APIError::err("couldnt_create_comment").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut recipient_ids = Vec::new();
|
||||||
|
|
||||||
// Scan the comment for user mentions, add those rows
|
// Scan the comment for user mentions, add those rows
|
||||||
let extracted_usernames = extract_usernames(&comment_form.content);
|
let extracted_usernames = extract_usernames(&comment_form.content);
|
||||||
|
|
||||||
for username_mention in &extracted_usernames {
|
for username_mention in &extracted_usernames {
|
||||||
let mention_user = User_::read_from_name(&conn, username_mention.to_string());
|
if let Ok(mention_user) = User_::read_from_name(&conn, (*username_mention).to_string()) {
|
||||||
|
|
||||||
if mention_user.is_ok() {
|
|
||||||
let mention_user_id = mention_user?.id;
|
|
||||||
|
|
||||||
// You can't mention yourself
|
// You can't mention yourself
|
||||||
// At some point, make it so you can't tag the parent creator either
|
// At some point, make it so you can't tag the parent creator either
|
||||||
// This can cause two notifications, one for reply and the other for mention
|
// This can cause two notifications, one for reply and the other for mention
|
||||||
if mention_user_id != user_id {
|
if mention_user.id != user_id {
|
||||||
|
recipient_ids.push(mention_user.id);
|
||||||
|
|
||||||
let user_mention_form = UserMentionForm {
|
let user_mention_form = UserMentionForm {
|
||||||
recipient_id: mention_user_id,
|
recipient_id: mention_user.id,
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
read: None,
|
read: None,
|
||||||
};
|
};
|
||||||
|
@ -108,12 +129,85 @@ impl Perform<CommentResponse> for Oper<CreateComment> {
|
||||||
// Let the uniqueness handle this fail
|
// Let the uniqueness handle this fail
|
||||||
match UserMention::create(&conn, &user_mention_form) {
|
match UserMention::create(&conn, &user_mention_form) {
|
||||||
Ok(_mention) => (),
|
Ok(_mention) => (),
|
||||||
Err(_e) => eprintln!("{}", &_e),
|
Err(_e) => error!("{}", &_e),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send an email to those users that have notifications on
|
||||||
|
if mention_user.send_notifications_to_email {
|
||||||
|
if let Some(mention_email) = mention_user.email {
|
||||||
|
let subject = &format!(
|
||||||
|
"{} - Mentioned by {}",
|
||||||
|
Settings::get().hostname,
|
||||||
|
claims.username
|
||||||
|
);
|
||||||
|
let html = &format!(
|
||||||
|
"<h1>User Mention</h1><br><div>{} - {}</div><br><a href={}/inbox>inbox</a>",
|
||||||
|
claims.username, comment_form.content, hostname
|
||||||
|
);
|
||||||
|
match send_email(subject, &mention_email, &mention_user.name, html) {
|
||||||
|
Ok(_o) => _o,
|
||||||
|
Err(e) => error!("{}", e),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send notifs to the parent commenter / poster
|
||||||
|
match data.parent_id {
|
||||||
|
Some(parent_id) => {
|
||||||
|
let parent_comment = Comment::read(&conn, parent_id)?;
|
||||||
|
if parent_comment.creator_id != user_id {
|
||||||
|
let parent_user = User_::read(&conn, parent_comment.creator_id)?;
|
||||||
|
recipient_ids.push(parent_user.id);
|
||||||
|
|
||||||
|
if parent_user.send_notifications_to_email {
|
||||||
|
if let Some(comment_reply_email) = parent_user.email {
|
||||||
|
let subject = &format!(
|
||||||
|
"{} - Reply from {}",
|
||||||
|
Settings::get().hostname,
|
||||||
|
claims.username
|
||||||
|
);
|
||||||
|
let html = &format!(
|
||||||
|
"<h1>Comment Reply</h1><br><div>{} - {}</div><br><a href={}/inbox>inbox</a>",
|
||||||
|
claims.username, comment_form.content, hostname
|
||||||
|
);
|
||||||
|
match send_email(subject, &comment_reply_email, &parent_user.name, html) {
|
||||||
|
Ok(_o) => _o,
|
||||||
|
Err(e) => error!("{}", e),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Its a post
|
||||||
|
None => {
|
||||||
|
if post.creator_id != user_id {
|
||||||
|
let parent_user = User_::read(&conn, post.creator_id)?;
|
||||||
|
recipient_ids.push(parent_user.id);
|
||||||
|
|
||||||
|
if parent_user.send_notifications_to_email {
|
||||||
|
if let Some(post_reply_email) = parent_user.email {
|
||||||
|
let subject = &format!(
|
||||||
|
"{} - Reply from {}",
|
||||||
|
Settings::get().hostname,
|
||||||
|
claims.username
|
||||||
|
);
|
||||||
|
let html = &format!(
|
||||||
|
"<h1>Post Reply</h1><br><div>{} - {}</div><br><a href={}/inbox>inbox</a>",
|
||||||
|
claims.username, comment_form.content, hostname
|
||||||
|
);
|
||||||
|
match send_email(subject, &post_reply_email, &parent_user.name, html) {
|
||||||
|
Ok(_o) => _o,
|
||||||
|
Err(e) => error!("{}", e),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// You like your own comment by default
|
// You like your own comment by default
|
||||||
let like_form = CommentLikeForm {
|
let like_form = CommentLikeForm {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
|
@ -124,26 +218,25 @@ impl Perform<CommentResponse> for Oper<CreateComment> {
|
||||||
|
|
||||||
let _inserted_like = match CommentLike::like(&conn, &like_form) {
|
let _inserted_like = match CommentLike::like(&conn, &like_form) {
|
||||||
Ok(like) => like,
|
Ok(like) => like,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_like_comment"))?,
|
Err(_e) => return Err(APIError::err("couldnt_like_comment").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let comment_view = CommentView::read(&conn, inserted_comment.id, Some(user_id))?;
|
let comment_view = CommentView::read(&conn, inserted_comment.id, Some(user_id))?;
|
||||||
|
|
||||||
Ok(CommentResponse {
|
Ok(CommentResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
comment: comment_view,
|
comment: comment_view,
|
||||||
|
recipient_ids,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<CommentResponse> for Oper<EditComment> {
|
impl Perform<CommentResponse> for Oper<EditComment> {
|
||||||
fn perform(&self) -> Result<CommentResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<CommentResponse, Error> {
|
||||||
let data: &EditComment = &self.data;
|
let data: &EditComment = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -163,17 +256,17 @@ impl Perform<CommentResponse> for Oper<EditComment> {
|
||||||
editors.append(&mut UserView::admins(&conn)?.into_iter().map(|a| a.id).collect());
|
editors.append(&mut UserView::admins(&conn)?.into_iter().map(|a| a.id).collect());
|
||||||
|
|
||||||
if !editors.contains(&user_id) {
|
if !editors.contains(&user_id) {
|
||||||
return Err(APIError::err(&self.op, "no_comment_edit_allowed"))?;
|
return Err(APIError::err("no_comment_edit_allowed").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a community ban
|
// Check for a community ban
|
||||||
if CommunityUserBanView::get(&conn, user_id, orig_comment.community_id).is_ok() {
|
if CommunityUserBanView::get(&conn, user_id, orig_comment.community_id).is_ok() {
|
||||||
return Err(APIError::err(&self.op, "community_ban"))?;
|
return Err(APIError::err("community_ban").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a site ban
|
// Check for a site ban
|
||||||
if UserView::read(&conn, user_id)?.banned {
|
if UserView::read(&conn, user_id)?.banned {
|
||||||
return Err(APIError::err(&self.op, "site_ban"))?;
|
return Err(APIError::err("site_ban").into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,14 +289,16 @@ impl Perform<CommentResponse> for Oper<EditComment> {
|
||||||
|
|
||||||
let _updated_comment = match Comment::update(&conn, data.edit_id, &comment_form) {
|
let _updated_comment = match Comment::update(&conn, data.edit_id, &comment_form) {
|
||||||
Ok(comment) => comment,
|
Ok(comment) => comment,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_comment"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut recipient_ids = Vec::new();
|
||||||
|
|
||||||
// Scan the comment for user mentions, add those rows
|
// Scan the comment for user mentions, add those rows
|
||||||
let extracted_usernames = extract_usernames(&comment_form.content);
|
let extracted_usernames = extract_usernames(&comment_form.content);
|
||||||
|
|
||||||
for username_mention in &extracted_usernames {
|
for username_mention in &extracted_usernames {
|
||||||
let mention_user = User_::read_from_name(&conn, username_mention.to_string());
|
let mention_user = User_::read_from_name(&conn, (*username_mention).to_string());
|
||||||
|
|
||||||
if mention_user.is_ok() {
|
if mention_user.is_ok() {
|
||||||
let mention_user_id = mention_user?.id;
|
let mention_user_id = mention_user?.id;
|
||||||
|
@ -212,6 +307,8 @@ impl Perform<CommentResponse> for Oper<EditComment> {
|
||||||
// At some point, make it so you can't tag the parent creator either
|
// At some point, make it so you can't tag the parent creator either
|
||||||
// This can cause two notifications, one for reply and the other for mention
|
// This can cause two notifications, one for reply and the other for mention
|
||||||
if mention_user_id != user_id {
|
if mention_user_id != user_id {
|
||||||
|
recipient_ids.push(mention_user_id);
|
||||||
|
|
||||||
let user_mention_form = UserMentionForm {
|
let user_mention_form = UserMentionForm {
|
||||||
recipient_id: mention_user_id,
|
recipient_id: mention_user_id,
|
||||||
comment_id: data.edit_id,
|
comment_id: data.edit_id,
|
||||||
|
@ -222,12 +319,27 @@ impl Perform<CommentResponse> for Oper<EditComment> {
|
||||||
// Let the uniqueness handle this fail
|
// Let the uniqueness handle this fail
|
||||||
match UserMention::create(&conn, &user_mention_form) {
|
match UserMention::create(&conn, &user_mention_form) {
|
||||||
Ok(_mention) => (),
|
Ok(_mention) => (),
|
||||||
Err(_e) => eprintln!("{}", &_e),
|
Err(_e) => error!("{}", &_e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add to recipient ids
|
||||||
|
match data.parent_id {
|
||||||
|
Some(parent_id) => {
|
||||||
|
let parent_comment = Comment::read(&conn, parent_id)?;
|
||||||
|
if parent_comment.creator_id != user_id {
|
||||||
|
let parent_user = User_::read(&conn, parent_comment.creator_id)?;
|
||||||
|
recipient_ids.push(parent_user.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let post = Post::read(&conn, data.post_id)?;
|
||||||
|
recipient_ids.push(post.creator_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
if let Some(removed) = data.removed.to_owned() {
|
if let Some(removed) = data.removed.to_owned() {
|
||||||
let form = ModRemoveCommentForm {
|
let form = ModRemoveCommentForm {
|
||||||
|
@ -242,20 +354,19 @@ impl Perform<CommentResponse> for Oper<EditComment> {
|
||||||
let comment_view = CommentView::read(&conn, data.edit_id, Some(user_id))?;
|
let comment_view = CommentView::read(&conn, data.edit_id, Some(user_id))?;
|
||||||
|
|
||||||
Ok(CommentResponse {
|
Ok(CommentResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
comment: comment_view,
|
comment: comment_view,
|
||||||
|
recipient_ids,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<CommentResponse> for Oper<SaveComment> {
|
impl Perform<CommentResponse> for Oper<SaveComment> {
|
||||||
fn perform(&self) -> Result<CommentResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<CommentResponse, Error> {
|
||||||
let data: &SaveComment = &self.data;
|
let data: &SaveComment = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -268,53 +379,70 @@ impl Perform<CommentResponse> for Oper<SaveComment> {
|
||||||
if data.save {
|
if data.save {
|
||||||
match CommentSaved::save(&conn, &comment_saved_form) {
|
match CommentSaved::save(&conn, &comment_saved_form) {
|
||||||
Ok(comment) => comment,
|
Ok(comment) => comment,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_save_comment"))?,
|
Err(_e) => return Err(APIError::err("couldnt_save_comment").into()),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
match CommentSaved::unsave(&conn, &comment_saved_form) {
|
match CommentSaved::unsave(&conn, &comment_saved_form) {
|
||||||
Ok(comment) => comment,
|
Ok(comment) => comment,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_save_comment"))?,
|
Err(_e) => return Err(APIError::err("couldnt_save_comment").into()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let comment_view = CommentView::read(&conn, data.comment_id, Some(user_id))?;
|
let comment_view = CommentView::read(&conn, data.comment_id, Some(user_id))?;
|
||||||
|
|
||||||
Ok(CommentResponse {
|
Ok(CommentResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
comment: comment_view,
|
comment: comment_view,
|
||||||
|
recipient_ids: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<CommentResponse> for Oper<CreateCommentLike> {
|
impl Perform<CommentResponse> for Oper<CreateCommentLike> {
|
||||||
fn perform(&self) -> Result<CommentResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<CommentResponse, Error> {
|
||||||
let data: &CreateCommentLike = &self.data;
|
let data: &CreateCommentLike = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
|
||||||
|
let mut recipient_ids = Vec::new();
|
||||||
|
|
||||||
// Don't do a downvote if site has downvotes disabled
|
// Don't do a downvote if site has downvotes disabled
|
||||||
if data.score == -1 {
|
if data.score == -1 {
|
||||||
let site = SiteView::read(&conn)?;
|
let site = SiteView::read(&conn)?;
|
||||||
if site.enable_downvotes == false {
|
if !site.enable_downvotes {
|
||||||
return Err(APIError::err(&self.op, "downvotes_disabled"))?;
|
return Err(APIError::err("downvotes_disabled").into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a community ban
|
// Check for a community ban
|
||||||
let post = Post::read(&conn, data.post_id)?;
|
let post = Post::read(&conn, data.post_id)?;
|
||||||
if CommunityUserBanView::get(&conn, user_id, post.community_id).is_ok() {
|
if CommunityUserBanView::get(&conn, user_id, post.community_id).is_ok() {
|
||||||
return Err(APIError::err(&self.op, "community_ban"))?;
|
return Err(APIError::err("community_ban").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a site ban
|
// Check for a site ban
|
||||||
if UserView::read(&conn, user_id)?.banned {
|
if UserView::read(&conn, user_id)?.banned {
|
||||||
return Err(APIError::err(&self.op, "site_ban"))?;
|
return Err(APIError::err("site_ban").into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let comment = Comment::read(&conn, data.comment_id)?;
|
||||||
|
|
||||||
|
// Add to recipient ids
|
||||||
|
match comment.parent_id {
|
||||||
|
Some(parent_id) => {
|
||||||
|
let parent_comment = Comment::read(&conn, parent_id)?;
|
||||||
|
if parent_comment.creator_id != user_id {
|
||||||
|
let parent_user = User_::read(&conn, parent_comment.creator_id)?;
|
||||||
|
recipient_ids.push(parent_user.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
recipient_ids.push(post.creator_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let like_form = CommentLikeForm {
|
let like_form = CommentLikeForm {
|
||||||
|
@ -328,11 +456,11 @@ impl Perform<CommentResponse> for Oper<CreateCommentLike> {
|
||||||
CommentLike::remove(&conn, &like_form)?;
|
CommentLike::remove(&conn, &like_form)?;
|
||||||
|
|
||||||
// Only add the like if the score isnt 0
|
// Only add the like if the score isnt 0
|
||||||
let do_add = &like_form.score != &0 && (&like_form.score == &1 || &like_form.score == &-1);
|
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
|
||||||
if do_add {
|
if do_add {
|
||||||
let _inserted_like = match CommentLike::like(&conn, &like_form) {
|
let _inserted_like = match CommentLike::like(&conn, &like_form) {
|
||||||
Ok(like) => like,
|
Ok(like) => like,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_like_comment"))?,
|
Err(_e) => return Err(APIError::err("couldnt_like_comment").into()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,8 +468,45 @@ impl Perform<CommentResponse> for Oper<CreateCommentLike> {
|
||||||
let liked_comment = CommentView::read(&conn, data.comment_id, Some(user_id))?;
|
let liked_comment = CommentView::read(&conn, data.comment_id, Some(user_id))?;
|
||||||
|
|
||||||
Ok(CommentResponse {
|
Ok(CommentResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
comment: liked_comment,
|
comment: liked_comment,
|
||||||
|
recipient_ids,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Perform<GetCommentsResponse> for Oper<GetComments> {
|
||||||
|
fn perform(&self, conn: &PgConnection) -> Result<GetCommentsResponse, Error> {
|
||||||
|
let data: &GetComments = &self.data;
|
||||||
|
|
||||||
|
let user_claims: Option<Claims> = match &data.auth {
|
||||||
|
Some(auth) => match Claims::decode(&auth) {
|
||||||
|
Ok(claims) => Some(claims.claims),
|
||||||
|
Err(_e) => None,
|
||||||
|
},
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let user_id = match &user_claims {
|
||||||
|
Some(claims) => Some(claims.id),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let type_ = ListingType::from_str(&data.type_)?;
|
||||||
|
let sort = SortType::from_str(&data.sort)?;
|
||||||
|
|
||||||
|
let comments = match CommentQueryBuilder::create(&conn)
|
||||||
|
.listing_type(type_)
|
||||||
|
.sort(&sort)
|
||||||
|
.for_community_id(data.community_id)
|
||||||
|
.my_user_id(user_id)
|
||||||
|
.page(data.page)
|
||||||
|
.limit(data.limit)
|
||||||
|
.list()
|
||||||
|
{
|
||||||
|
Ok(comments) => comments,
|
||||||
|
Err(_e) => return Err(APIError::err("couldnt_get_comments").into()),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(GetCommentsResponse { comments })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::apub::puller::{get_all_communities, get_remote_community};
|
||||||
|
use crate::settings::Settings;
|
||||||
|
use diesel::PgConnection;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct GetCommunity {
|
pub struct GetCommunity {
|
||||||
id: Option<i32>,
|
id: Option<i32>,
|
||||||
name: Option<String>,
|
pub name: Option<String>,
|
||||||
auth: Option<String>,
|
auth: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct GetCommunityResponse {
|
pub struct GetCommunityResponse {
|
||||||
op: String,
|
pub community: CommunityView,
|
||||||
community: CommunityView,
|
pub moderators: Vec<CommunityModeratorView>,
|
||||||
moderators: Vec<CommunityModeratorView>,
|
pub admins: Vec<UserView>,
|
||||||
admins: Vec<UserView>,
|
pub online: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
@ -28,22 +31,21 @@ pub struct CreateCommunity {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct CommunityResponse {
|
pub struct CommunityResponse {
|
||||||
op: String,
|
|
||||||
pub community: CommunityView,
|
pub community: CommunityView,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct ListCommunities {
|
pub struct ListCommunities {
|
||||||
sort: String,
|
sort: String,
|
||||||
page: Option<i64>,
|
page: Option<i64>,
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
auth: Option<String>,
|
auth: Option<String>,
|
||||||
|
local_only: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct ListCommunitiesResponse {
|
pub struct ListCommunitiesResponse {
|
||||||
op: String,
|
pub communities: Vec<CommunityView>,
|
||||||
communities: Vec<CommunityView>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
@ -58,7 +60,6 @@ pub struct BanFromCommunity {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct BanFromCommunityResponse {
|
pub struct BanFromCommunityResponse {
|
||||||
op: String,
|
|
||||||
user: UserView,
|
user: UserView,
|
||||||
banned: bool,
|
banned: bool,
|
||||||
}
|
}
|
||||||
|
@ -73,7 +74,6 @@ pub struct AddModToCommunity {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct AddModToCommunityResponse {
|
pub struct AddModToCommunityResponse {
|
||||||
op: String,
|
|
||||||
moderators: Vec<CommunityModeratorView>,
|
moderators: Vec<CommunityModeratorView>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,6 @@ pub struct GetFollowedCommunities {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct GetFollowedCommunitiesResponse {
|
pub struct GetFollowedCommunitiesResponse {
|
||||||
op: String,
|
|
||||||
communities: Vec<CommunityFollowerView>,
|
communities: Vec<CommunityFollowerView>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,9 +117,15 @@ pub struct TransferCommunity {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<GetCommunityResponse> for Oper<GetCommunity> {
|
impl Perform<GetCommunityResponse> for Oper<GetCommunity> {
|
||||||
fn perform(&self) -> Result<GetCommunityResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetCommunityResponse, Error> {
|
||||||
let data: &GetCommunity = &self.data;
|
let data: &GetCommunity = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
if data.name.is_some()
|
||||||
|
&& Settings::get().federation.enabled
|
||||||
|
&& data.name.as_ref().unwrap().contains('@')
|
||||||
|
{
|
||||||
|
return get_remote_community(data.name.as_ref().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
let user_id: Option<i32> = match &data.auth {
|
let user_id: Option<i32> = match &data.auth {
|
||||||
Some(auth) => match Claims::decode(&auth) {
|
Some(auth) => match Claims::decode(&auth) {
|
||||||
|
@ -136,21 +141,24 @@ impl Perform<GetCommunityResponse> for Oper<GetCommunity> {
|
||||||
let community_id = match data.id {
|
let community_id = match data.id {
|
||||||
Some(id) => id,
|
Some(id) => id,
|
||||||
None => {
|
None => {
|
||||||
match Community::read_from_name(&conn, data.name.to_owned().unwrap_or("main".to_string())) {
|
match Community::read_from_name(
|
||||||
|
&conn,
|
||||||
|
data.name.to_owned().unwrap_or_else(|| "main".to_string()),
|
||||||
|
) {
|
||||||
Ok(community) => community.id,
|
Ok(community) => community.id,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_community"))?,
|
Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let community_view = match CommunityView::read(&conn, community_id, user_id) {
|
let community_view = match CommunityView::read(&conn, community_id, user_id) {
|
||||||
Ok(community) => community,
|
Ok(community) => community,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_community"))?,
|
Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let moderators = match CommunityModeratorView::for_community(&conn, community_id) {
|
let moderators = match CommunityModeratorView::for_community(&conn, community_id) {
|
||||||
Ok(moderators) => moderators,
|
Ok(moderators) => moderators,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_community"))?,
|
Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let site_creator_id = Site::read(&conn, 1)?.creator_id;
|
let site_creator_id = Site::read(&conn, 1)?.creator_id;
|
||||||
|
@ -161,36 +169,42 @@ impl Perform<GetCommunityResponse> for Oper<GetCommunity> {
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(GetCommunityResponse {
|
Ok(GetCommunityResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
community: community_view,
|
community: community_view,
|
||||||
moderators,
|
moderators,
|
||||||
admins,
|
admins,
|
||||||
|
online: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<CommunityResponse> for Oper<CreateCommunity> {
|
impl Perform<CommunityResponse> for Oper<CreateCommunity> {
|
||||||
fn perform(&self) -> Result<CommunityResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<CommunityResponse, Error> {
|
||||||
let data: &CreateCommunity = &self.data;
|
let data: &CreateCommunity = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if has_slurs(&data.name)
|
if let Err(slurs) = slur_check(&data.name) {
|
||||||
|| has_slurs(&data.title)
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
|| (data.description.is_some() && has_slurs(&data.description.to_owned().unwrap()))
|
}
|
||||||
{
|
|
||||||
return Err(APIError::err(&self.op, "no_slurs"))?;
|
if let Err(slurs) = slur_check(&data.title) {
|
||||||
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(description) = &data.description {
|
||||||
|
if let Err(slurs) = slur_check(description) {
|
||||||
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
|
||||||
// Check for a site ban
|
// Check for a site ban
|
||||||
if UserView::read(&conn, user_id)?.banned {
|
if UserView::read(&conn, user_id)?.banned {
|
||||||
return Err(APIError::err(&self.op, "site_ban"))?;
|
return Err(APIError::err("site_ban").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// When you create a community, make sure the user becomes a moderator and a follower
|
// When you create a community, make sure the user becomes a moderator and a follower
|
||||||
|
@ -208,7 +222,7 @@ impl Perform<CommunityResponse> for Oper<CreateCommunity> {
|
||||||
|
|
||||||
let inserted_community = match Community::create(&conn, &community_form) {
|
let inserted_community = match Community::create(&conn, &community_form) {
|
||||||
Ok(community) => community,
|
Ok(community) => community,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "community_already_exists"))?,
|
Err(_e) => return Err(APIError::err("community_already_exists").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let community_moderator_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
|
@ -219,12 +233,7 @@ impl Perform<CommunityResponse> for Oper<CreateCommunity> {
|
||||||
let _inserted_community_moderator =
|
let _inserted_community_moderator =
|
||||||
match CommunityModerator::join(&conn, &community_moderator_form) {
|
match CommunityModerator::join(&conn, &community_moderator_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => {
|
Err(_e) => return Err(APIError::err("community_moderator_already_exists").into()),
|
||||||
return Err(APIError::err(
|
|
||||||
&self.op,
|
|
||||||
"community_moderator_already_exists",
|
|
||||||
))?
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
|
@ -235,38 +244,45 @@ impl Perform<CommunityResponse> for Oper<CreateCommunity> {
|
||||||
let _inserted_community_follower =
|
let _inserted_community_follower =
|
||||||
match CommunityFollower::follow(&conn, &community_follower_form) {
|
match CommunityFollower::follow(&conn, &community_follower_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "community_follower_already_exists"))?,
|
Err(_e) => return Err(APIError::err("community_follower_already_exists").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let community_view = CommunityView::read(&conn, inserted_community.id, Some(user_id))?;
|
let community_view = CommunityView::read(&conn, inserted_community.id, Some(user_id))?;
|
||||||
|
|
||||||
Ok(CommunityResponse {
|
Ok(CommunityResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
community: community_view,
|
community: community_view,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<CommunityResponse> for Oper<EditCommunity> {
|
impl Perform<CommunityResponse> for Oper<EditCommunity> {
|
||||||
fn perform(&self) -> Result<CommunityResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<CommunityResponse, Error> {
|
||||||
let data: &EditCommunity = &self.data;
|
let data: &EditCommunity = &self.data;
|
||||||
|
|
||||||
if has_slurs(&data.name) || has_slurs(&data.title) {
|
if let Err(slurs) = slur_check(&data.name) {
|
||||||
return Err(APIError::err(&self.op, "no_slurs"))?;
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let conn = establish_connection();
|
if let Err(slurs) = slur_check(&data.title) {
|
||||||
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(description) = &data.description {
|
||||||
|
if let Err(slurs) = slur_check(description) {
|
||||||
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
|
||||||
// Check for a site ban
|
// Check for a site ban
|
||||||
if UserView::read(&conn, user_id)?.banned {
|
if UserView::read(&conn, user_id)?.banned {
|
||||||
return Err(APIError::err(&self.op, "site_ban"))?;
|
return Err(APIError::err("site_ban").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify its a mod
|
// Verify its a mod
|
||||||
|
@ -279,7 +295,7 @@ impl Perform<CommunityResponse> for Oper<EditCommunity> {
|
||||||
);
|
);
|
||||||
editors.append(&mut UserView::admins(&conn)?.into_iter().map(|a| a.id).collect());
|
editors.append(&mut UserView::admins(&conn)?.into_iter().map(|a| a.id).collect());
|
||||||
if !editors.contains(&user_id) {
|
if !editors.contains(&user_id) {
|
||||||
return Err(APIError::err(&self.op, "no_community_edit_allowed"))?;
|
return Err(APIError::err("no_community_edit_allowed").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let community_form = CommunityForm {
|
let community_form = CommunityForm {
|
||||||
|
@ -296,7 +312,7 @@ impl Perform<CommunityResponse> for Oper<EditCommunity> {
|
||||||
|
|
||||||
let _updated_community = match Community::update(&conn, data.edit_id, &community_form) {
|
let _updated_community = match Community::update(&conn, data.edit_id, &community_form) {
|
||||||
Ok(community) => community,
|
Ok(community) => community,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_community"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_community").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
|
@ -318,16 +334,21 @@ impl Perform<CommunityResponse> for Oper<EditCommunity> {
|
||||||
let community_view = CommunityView::read(&conn, data.edit_id, Some(user_id))?;
|
let community_view = CommunityView::read(&conn, data.edit_id, Some(user_id))?;
|
||||||
|
|
||||||
Ok(CommunityResponse {
|
Ok(CommunityResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
community: community_view,
|
community: community_view,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<ListCommunitiesResponse> for Oper<ListCommunities> {
|
impl Perform<ListCommunitiesResponse> for Oper<ListCommunities> {
|
||||||
fn perform(&self) -> Result<ListCommunitiesResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<ListCommunitiesResponse, Error> {
|
||||||
let data: &ListCommunities = &self.data;
|
let data: &ListCommunities = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
let local_only = data.local_only.unwrap_or(false);
|
||||||
|
if Settings::get().federation.enabled && !local_only {
|
||||||
|
return Ok(ListCommunitiesResponse {
|
||||||
|
communities: get_all_communities()?,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let user_claims: Option<Claims> = match &data.auth {
|
let user_claims: Option<Claims> = match &data.auth {
|
||||||
Some(auth) => match Claims::decode(&auth) {
|
Some(auth) => match Claims::decode(&auth) {
|
||||||
|
@ -351,28 +372,24 @@ impl Perform<ListCommunitiesResponse> for Oper<ListCommunities> {
|
||||||
|
|
||||||
let communities = CommunityQueryBuilder::create(&conn)
|
let communities = CommunityQueryBuilder::create(&conn)
|
||||||
.sort(&sort)
|
.sort(&sort)
|
||||||
.from_user_id(user_id)
|
.for_user(user_id)
|
||||||
.show_nsfw(show_nsfw)
|
.show_nsfw(show_nsfw)
|
||||||
.page(data.page)
|
.page(data.page)
|
||||||
.limit(data.limit)
|
.limit(data.limit)
|
||||||
.list()?;
|
.list()?;
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(ListCommunitiesResponse {
|
Ok(ListCommunitiesResponse { communities })
|
||||||
op: self.op.to_string(),
|
|
||||||
communities,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<CommunityResponse> for Oper<FollowCommunity> {
|
impl Perform<CommunityResponse> for Oper<FollowCommunity> {
|
||||||
fn perform(&self) -> Result<CommunityResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<CommunityResponse, Error> {
|
||||||
let data: &FollowCommunity = &self.data;
|
let data: &FollowCommunity = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -385,32 +402,30 @@ impl Perform<CommunityResponse> for Oper<FollowCommunity> {
|
||||||
if data.follow {
|
if data.follow {
|
||||||
match CommunityFollower::follow(&conn, &community_follower_form) {
|
match CommunityFollower::follow(&conn, &community_follower_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "community_follower_already_exists"))?,
|
Err(_e) => return Err(APIError::err("community_follower_already_exists").into()),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
match CommunityFollower::ignore(&conn, &community_follower_form) {
|
match CommunityFollower::ignore(&conn, &community_follower_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "community_follower_already_exists"))?,
|
Err(_e) => return Err(APIError::err("community_follower_already_exists").into()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let community_view = CommunityView::read(&conn, data.community_id, Some(user_id))?;
|
let community_view = CommunityView::read(&conn, data.community_id, Some(user_id))?;
|
||||||
|
|
||||||
Ok(CommunityResponse {
|
Ok(CommunityResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
community: community_view,
|
community: community_view,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<GetFollowedCommunitiesResponse> for Oper<GetFollowedCommunities> {
|
impl Perform<GetFollowedCommunitiesResponse> for Oper<GetFollowedCommunities> {
|
||||||
fn perform(&self) -> Result<GetFollowedCommunitiesResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetFollowedCommunitiesResponse, Error> {
|
||||||
let data: &GetFollowedCommunities = &self.data;
|
let data: &GetFollowedCommunities = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -418,25 +433,21 @@ impl Perform<GetFollowedCommunitiesResponse> for Oper<GetFollowedCommunities> {
|
||||||
let communities: Vec<CommunityFollowerView> =
|
let communities: Vec<CommunityFollowerView> =
|
||||||
match CommunityFollowerView::for_user(&conn, user_id) {
|
match CommunityFollowerView::for_user(&conn, user_id) {
|
||||||
Ok(communities) => communities,
|
Ok(communities) => communities,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "system_err_login"))?,
|
Err(_e) => return Err(APIError::err("system_err_login").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(GetFollowedCommunitiesResponse {
|
Ok(GetFollowedCommunitiesResponse { communities })
|
||||||
op: self.op.to_string(),
|
|
||||||
communities,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<BanFromCommunityResponse> for Oper<BanFromCommunity> {
|
impl Perform<BanFromCommunityResponse> for Oper<BanFromCommunity> {
|
||||||
fn perform(&self) -> Result<BanFromCommunityResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<BanFromCommunityResponse, Error> {
|
||||||
let data: &BanFromCommunity = &self.data;
|
let data: &BanFromCommunity = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -449,12 +460,12 @@ impl Perform<BanFromCommunityResponse> for Oper<BanFromCommunity> {
|
||||||
if data.ban {
|
if data.ban {
|
||||||
match CommunityUserBan::ban(&conn, &community_user_ban_form) {
|
match CommunityUserBan::ban(&conn, &community_user_ban_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "community_user_already_banned"))?,
|
Err(_e) => return Err(APIError::err("community_user_already_banned").into()),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
match CommunityUserBan::unban(&conn, &community_user_ban_form) {
|
match CommunityUserBan::unban(&conn, &community_user_ban_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "community_user_already_banned"))?,
|
Err(_e) => return Err(APIError::err("community_user_already_banned").into()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,7 +488,6 @@ impl Perform<BanFromCommunityResponse> for Oper<BanFromCommunity> {
|
||||||
let user_view = UserView::read(&conn, data.user_id)?;
|
let user_view = UserView::read(&conn, data.user_id)?;
|
||||||
|
|
||||||
Ok(BanFromCommunityResponse {
|
Ok(BanFromCommunityResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
user: user_view,
|
user: user_view,
|
||||||
banned: data.ban,
|
banned: data.ban,
|
||||||
})
|
})
|
||||||
|
@ -485,13 +495,12 @@ impl Perform<BanFromCommunityResponse> for Oper<BanFromCommunity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<AddModToCommunityResponse> for Oper<AddModToCommunity> {
|
impl Perform<AddModToCommunityResponse> for Oper<AddModToCommunity> {
|
||||||
fn perform(&self) -> Result<AddModToCommunityResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<AddModToCommunityResponse, Error> {
|
||||||
let data: &AddModToCommunity = &self.data;
|
let data: &AddModToCommunity = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -504,22 +513,12 @@ impl Perform<AddModToCommunityResponse> for Oper<AddModToCommunity> {
|
||||||
if data.added {
|
if data.added {
|
||||||
match CommunityModerator::join(&conn, &community_moderator_form) {
|
match CommunityModerator::join(&conn, &community_moderator_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => {
|
Err(_e) => return Err(APIError::err("community_moderator_already_exists").into()),
|
||||||
return Err(APIError::err(
|
|
||||||
&self.op,
|
|
||||||
"community_moderator_already_exists",
|
|
||||||
))?
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
match CommunityModerator::leave(&conn, &community_moderator_form) {
|
match CommunityModerator::leave(&conn, &community_moderator_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => {
|
Err(_e) => return Err(APIError::err("community_moderator_already_exists").into()),
|
||||||
return Err(APIError::err(
|
|
||||||
&self.op,
|
|
||||||
"community_moderator_already_exists",
|
|
||||||
))?
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,21 +533,17 @@ impl Perform<AddModToCommunityResponse> for Oper<AddModToCommunity> {
|
||||||
|
|
||||||
let moderators = CommunityModeratorView::for_community(&conn, data.community_id)?;
|
let moderators = CommunityModeratorView::for_community(&conn, data.community_id)?;
|
||||||
|
|
||||||
Ok(AddModToCommunityResponse {
|
Ok(AddModToCommunityResponse { moderators })
|
||||||
op: self.op.to_string(),
|
|
||||||
moderators,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<GetCommunityResponse> for Oper<TransferCommunity> {
|
impl Perform<GetCommunityResponse> for Oper<TransferCommunity> {
|
||||||
fn perform(&self) -> Result<GetCommunityResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetCommunityResponse, Error> {
|
||||||
let data: &TransferCommunity = &self.data;
|
let data: &TransferCommunity = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -562,14 +557,8 @@ impl Perform<GetCommunityResponse> for Oper<TransferCommunity> {
|
||||||
admins.insert(0, creator_user);
|
admins.insert(0, creator_user);
|
||||||
|
|
||||||
// Make sure user is the creator, or an admin
|
// Make sure user is the creator, or an admin
|
||||||
if user_id != read_community.creator_id
|
if user_id != read_community.creator_id && !admins.iter().map(|a| a.id).any(|x| x == user_id) {
|
||||||
&& !admins
|
return Err(APIError::err("not_an_admin").into());
|
||||||
.iter()
|
|
||||||
.map(|a| a.id)
|
|
||||||
.collect::<Vec<i32>>()
|
|
||||||
.contains(&user_id)
|
|
||||||
{
|
|
||||||
return Err(APIError::err(&self.op, "not_an_admin"))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let community_form = CommunityForm {
|
let community_form = CommunityForm {
|
||||||
|
@ -586,7 +575,7 @@ impl Perform<GetCommunityResponse> for Oper<TransferCommunity> {
|
||||||
|
|
||||||
let _updated_community = match Community::update(&conn, data.community_id, &community_form) {
|
let _updated_community = match Community::update(&conn, data.community_id, &community_form) {
|
||||||
Ok(community) => community,
|
Ok(community) => community,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_community"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_community").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// You also have to re-do the community_moderator table, reordering it.
|
// You also have to re-do the community_moderator table, reordering it.
|
||||||
|
@ -609,12 +598,7 @@ impl Perform<GetCommunityResponse> for Oper<TransferCommunity> {
|
||||||
let _inserted_community_moderator =
|
let _inserted_community_moderator =
|
||||||
match CommunityModerator::join(&conn, &community_moderator_form) {
|
match CommunityModerator::join(&conn, &community_moderator_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => {
|
Err(_e) => return Err(APIError::err("community_moderator_already_exists").into()),
|
||||||
return Err(APIError::err(
|
|
||||||
&self.op,
|
|
||||||
"community_moderator_already_exists",
|
|
||||||
))?
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -629,20 +613,20 @@ impl Perform<GetCommunityResponse> for Oper<TransferCommunity> {
|
||||||
|
|
||||||
let community_view = match CommunityView::read(&conn, data.community_id, Some(user_id)) {
|
let community_view = match CommunityView::read(&conn, data.community_id, Some(user_id)) {
|
||||||
Ok(community) => community,
|
Ok(community) => community,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_community"))?,
|
Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let moderators = match CommunityModeratorView::for_community(&conn, data.community_id) {
|
let moderators = match CommunityModeratorView::for_community(&conn, data.community_id) {
|
||||||
Ok(moderators) => moderators,
|
Ok(moderators) => moderators,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_community"))?,
|
Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(GetCommunityResponse {
|
Ok(GetCommunityResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
community: community_view,
|
community: community_view,
|
||||||
moderators,
|
moderators,
|
||||||
admins,
|
admins,
|
||||||
|
online: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ use crate::db::moderator_views::*;
|
||||||
use crate::db::password_reset_request::*;
|
use crate::db::password_reset_request::*;
|
||||||
use crate::db::post::*;
|
use crate::db::post::*;
|
||||||
use crate::db::post_view::*;
|
use crate::db::post_view::*;
|
||||||
|
use crate::db::private_message::*;
|
||||||
|
use crate::db::private_message_view::*;
|
||||||
use crate::db::site::*;
|
use crate::db::site::*;
|
||||||
use crate::db::site_view::*;
|
use crate::db::site_view::*;
|
||||||
use crate::db::user::*;
|
use crate::db::user::*;
|
||||||
|
@ -15,7 +17,11 @@ use crate::db::user_mention::*;
|
||||||
use crate::db::user_mention_view::*;
|
use crate::db::user_mention_view::*;
|
||||||
use crate::db::user_view::*;
|
use crate::db::user_view::*;
|
||||||
use crate::db::*;
|
use crate::db::*;
|
||||||
use crate::{extract_usernames, has_slurs, naive_from_unix, naive_now, remove_slurs, Settings};
|
use crate::{
|
||||||
|
extract_usernames, fetch_iframely_and_pictshare_data, naive_from_unix, naive_now, remove_slurs,
|
||||||
|
slur_check, slurs_vec_to_str,
|
||||||
|
};
|
||||||
|
use diesel::PgConnection;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -25,78 +31,32 @@ pub mod post;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
#[derive(EnumString, ToString, Debug)]
|
|
||||||
pub enum UserOperation {
|
|
||||||
Login,
|
|
||||||
Register,
|
|
||||||
CreateCommunity,
|
|
||||||
CreatePost,
|
|
||||||
ListCommunities,
|
|
||||||
ListCategories,
|
|
||||||
GetPost,
|
|
||||||
GetCommunity,
|
|
||||||
CreateComment,
|
|
||||||
EditComment,
|
|
||||||
SaveComment,
|
|
||||||
CreateCommentLike,
|
|
||||||
GetPosts,
|
|
||||||
CreatePostLike,
|
|
||||||
EditPost,
|
|
||||||
SavePost,
|
|
||||||
EditCommunity,
|
|
||||||
FollowCommunity,
|
|
||||||
GetFollowedCommunities,
|
|
||||||
GetUserDetails,
|
|
||||||
GetReplies,
|
|
||||||
GetUserMentions,
|
|
||||||
EditUserMention,
|
|
||||||
GetModlog,
|
|
||||||
BanFromCommunity,
|
|
||||||
AddModToCommunity,
|
|
||||||
CreateSite,
|
|
||||||
EditSite,
|
|
||||||
GetSite,
|
|
||||||
AddAdmin,
|
|
||||||
BanUser,
|
|
||||||
Search,
|
|
||||||
MarkAllAsRead,
|
|
||||||
SaveUserSettings,
|
|
||||||
TransferCommunity,
|
|
||||||
TransferSite,
|
|
||||||
DeleteAccount,
|
|
||||||
PasswordReset,
|
|
||||||
PasswordChange,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Fail, Debug)]
|
#[derive(Fail, Debug)]
|
||||||
#[fail(display = "{{\"op\":\"{}\", \"error\":\"{}\"}}", op, message)]
|
#[fail(display = "{{\"error\":\"{}\"}}", message)]
|
||||||
pub struct APIError {
|
pub struct APIError {
|
||||||
pub op: String,
|
|
||||||
pub message: String,
|
pub message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl APIError {
|
impl APIError {
|
||||||
pub fn err(op: &UserOperation, msg: &str) -> Self {
|
pub fn err(msg: &str) -> Self {
|
||||||
APIError {
|
APIError {
|
||||||
op: op.to_string(),
|
|
||||||
message: msg.to_string(),
|
message: msg.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Oper<T> {
|
pub struct Oper<T> {
|
||||||
op: UserOperation,
|
|
||||||
data: T,
|
data: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Oper<T> {
|
impl<T> Oper<T> {
|
||||||
pub fn new(op: UserOperation, data: T) -> Oper<T> {
|
pub fn new(data: T) -> Oper<T> {
|
||||||
Oper { op, data }
|
Oper { data }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Perform<T> {
|
pub trait Perform<T> {
|
||||||
fn perform(&self) -> Result<T, Error>
|
fn perform(&self, conn: &PgConnection) -> Result<T, Error>
|
||||||
where
|
where
|
||||||
T: Sized;
|
T: Sized;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::settings::Settings;
|
||||||
|
use diesel::PgConnection;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
@ -7,13 +9,12 @@ pub struct CreatePost {
|
||||||
url: Option<String>,
|
url: Option<String>,
|
||||||
body: Option<String>,
|
body: Option<String>,
|
||||||
nsfw: bool,
|
nsfw: bool,
|
||||||
community_id: i32,
|
pub community_id: i32,
|
||||||
auth: String,
|
auth: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct PostResponse {
|
pub struct PostResponse {
|
||||||
op: String,
|
|
||||||
pub post: PostView,
|
pub post: PostView,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,28 +26,27 @@ pub struct GetPost {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct GetPostResponse {
|
pub struct GetPostResponse {
|
||||||
op: String,
|
|
||||||
post: PostView,
|
post: PostView,
|
||||||
comments: Vec<CommentView>,
|
comments: Vec<CommentView>,
|
||||||
community: CommunityView,
|
community: CommunityView,
|
||||||
moderators: Vec<CommunityModeratorView>,
|
moderators: Vec<CommunityModeratorView>,
|
||||||
admins: Vec<UserView>,
|
admins: Vec<UserView>,
|
||||||
|
pub online: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct GetPosts {
|
pub struct GetPosts {
|
||||||
type_: String,
|
type_: String,
|
||||||
sort: String,
|
sort: String,
|
||||||
page: Option<i64>,
|
page: Option<i64>,
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
community_id: Option<i32>,
|
pub community_id: Option<i32>,
|
||||||
auth: Option<String>,
|
auth: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct GetPostsResponse {
|
pub struct GetPostsResponse {
|
||||||
op: String,
|
pub posts: Vec<PostView>,
|
||||||
posts: Vec<PostView>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
@ -56,12 +56,6 @@ pub struct CreatePostLike {
|
||||||
auth: String,
|
auth: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct CreatePostLikeResponse {
|
|
||||||
op: String,
|
|
||||||
post: PostView,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct EditPost {
|
pub struct EditPost {
|
||||||
pub edit_id: i32,
|
pub edit_id: i32,
|
||||||
|
@ -87,31 +81,40 @@ pub struct SavePost {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<PostResponse> for Oper<CreatePost> {
|
impl Perform<PostResponse> for Oper<CreatePost> {
|
||||||
fn perform(&self) -> Result<PostResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<PostResponse, Error> {
|
||||||
let data: &CreatePost = &self.data;
|
let data: &CreatePost = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if has_slurs(&data.name) || (data.body.is_some() && has_slurs(&data.body.to_owned().unwrap())) {
|
if let Err(slurs) = slur_check(&data.name) {
|
||||||
return Err(APIError::err(&self.op, "no_slurs"))?;
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(body) = &data.body {
|
||||||
|
if let Err(slurs) = slur_check(body) {
|
||||||
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
|
||||||
// Check for a community ban
|
// Check for a community ban
|
||||||
if CommunityUserBanView::get(&conn, user_id, data.community_id).is_ok() {
|
if CommunityUserBanView::get(&conn, user_id, data.community_id).is_ok() {
|
||||||
return Err(APIError::err(&self.op, "community_ban"))?;
|
return Err(APIError::err("community_ban").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a site ban
|
// Check for a site ban
|
||||||
if UserView::read(&conn, user_id)?.banned {
|
if UserView::read(&conn, user_id)?.banned {
|
||||||
return Err(APIError::err(&self.op, "site_ban"))?;
|
return Err(APIError::err("site_ban").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch Iframely and Pictshare cached image
|
||||||
|
let (iframely_title, iframely_description, iframely_html, pictshare_thumbnail) =
|
||||||
|
fetch_iframely_and_pictshare_data(data.url.to_owned());
|
||||||
|
|
||||||
let post_form = PostForm {
|
let post_form = PostForm {
|
||||||
name: data.name.to_owned(),
|
name: data.name.to_owned(),
|
||||||
url: data.url.to_owned(),
|
url: data.url.to_owned(),
|
||||||
|
@ -124,11 +127,23 @@ impl Perform<PostResponse> for Oper<CreatePost> {
|
||||||
locked: None,
|
locked: None,
|
||||||
stickied: None,
|
stickied: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
|
embed_title: iframely_title,
|
||||||
|
embed_description: iframely_description,
|
||||||
|
embed_html: iframely_html,
|
||||||
|
thumbnail_url: pictshare_thumbnail,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_post = match Post::create(&conn, &post_form) {
|
let inserted_post = match Post::create(&conn, &post_form) {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_create_post"))?,
|
Err(e) => {
|
||||||
|
let err_type = if e.to_string() == "value too long for type character varying(200)" {
|
||||||
|
"post_title_too_long"
|
||||||
|
} else {
|
||||||
|
"couldnt_create_post"
|
||||||
|
};
|
||||||
|
|
||||||
|
return Err(APIError::err(err_type).into());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// They like their own post by default
|
// They like their own post by default
|
||||||
|
@ -141,26 +156,22 @@ impl Perform<PostResponse> for Oper<CreatePost> {
|
||||||
// Only add the like if the score isnt 0
|
// Only add the like if the score isnt 0
|
||||||
let _inserted_like = match PostLike::like(&conn, &like_form) {
|
let _inserted_like = match PostLike::like(&conn, &like_form) {
|
||||||
Ok(like) => like,
|
Ok(like) => like,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_like_post"))?,
|
Err(_e) => return Err(APIError::err("couldnt_like_post").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Refetch the view
|
// Refetch the view
|
||||||
let post_view = match PostView::read(&conn, inserted_post.id, Some(user_id)) {
|
let post_view = match PostView::read(&conn, inserted_post.id, Some(user_id)) {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_post"))?,
|
Err(_e) => return Err(APIError::err("couldnt_find_post").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(PostResponse {
|
Ok(PostResponse { post: post_view })
|
||||||
op: self.op.to_string(),
|
|
||||||
post: post_view,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<GetPostResponse> for Oper<GetPost> {
|
impl Perform<GetPostResponse> for Oper<GetPost> {
|
||||||
fn perform(&self) -> Result<GetPostResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetPostResponse, Error> {
|
||||||
let data: &GetPost = &self.data;
|
let data: &GetPost = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let user_id: Option<i32> = match &data.auth {
|
let user_id: Option<i32> = match &data.auth {
|
||||||
Some(auth) => match Claims::decode(&auth) {
|
Some(auth) => match Claims::decode(&auth) {
|
||||||
|
@ -175,7 +186,7 @@ impl Perform<GetPostResponse> for Oper<GetPost> {
|
||||||
|
|
||||||
let post_view = match PostView::read(&conn, data.id, user_id) {
|
let post_view = match PostView::read(&conn, data.id, user_id) {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_post"))?,
|
Err(_e) => return Err(APIError::err("couldnt_find_post").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let comments = CommentQueryBuilder::create(&conn)
|
let comments = CommentQueryBuilder::create(&conn)
|
||||||
|
@ -196,20 +207,24 @@ impl Perform<GetPostResponse> for Oper<GetPost> {
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(GetPostResponse {
|
Ok(GetPostResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
post: post_view,
|
post: post_view,
|
||||||
comments,
|
comments,
|
||||||
community,
|
community,
|
||||||
moderators,
|
moderators,
|
||||||
admins,
|
admins,
|
||||||
|
online: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<GetPostsResponse> for Oper<GetPosts> {
|
impl Perform<GetPostsResponse> for Oper<GetPosts> {
|
||||||
fn perform(&self) -> Result<GetPostsResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetPostsResponse, Error> {
|
||||||
let data: &GetPosts = &self.data;
|
let data: &GetPosts = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
if Settings::get().federation.enabled {
|
||||||
|
// TODO: intercept here (but the type is wrong)
|
||||||
|
//get_remote_community_posts(get_posts.community_id.unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
let user_claims: Option<Claims> = match &data.auth {
|
let user_claims: Option<Claims> = match &data.auth {
|
||||||
Some(auth) => match Claims::decode(&auth) {
|
Some(auth) => match Claims::decode(&auth) {
|
||||||
|
@ -243,24 +258,20 @@ impl Perform<GetPostsResponse> for Oper<GetPosts> {
|
||||||
.list()
|
.list()
|
||||||
{
|
{
|
||||||
Ok(posts) => posts,
|
Ok(posts) => posts,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_get_posts"))?,
|
Err(_e) => return Err(APIError::err("couldnt_get_posts").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(GetPostsResponse {
|
Ok(GetPostsResponse { posts })
|
||||||
op: self.op.to_string(),
|
|
||||||
posts,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> {
|
impl Perform<PostResponse> for Oper<CreatePostLike> {
|
||||||
fn perform(&self) -> Result<CreatePostLikeResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<PostResponse, Error> {
|
||||||
let data: &CreatePostLike = &self.data;
|
let data: &CreatePostLike = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -268,20 +279,20 @@ impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> {
|
||||||
// Don't do a downvote if site has downvotes disabled
|
// Don't do a downvote if site has downvotes disabled
|
||||||
if data.score == -1 {
|
if data.score == -1 {
|
||||||
let site = SiteView::read(&conn)?;
|
let site = SiteView::read(&conn)?;
|
||||||
if site.enable_downvotes == false {
|
if !site.enable_downvotes {
|
||||||
return Err(APIError::err(&self.op, "downvotes_disabled"))?;
|
return Err(APIError::err("downvotes_disabled").into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a community ban
|
// Check for a community ban
|
||||||
let post = Post::read(&conn, data.post_id)?;
|
let post = Post::read(&conn, data.post_id)?;
|
||||||
if CommunityUserBanView::get(&conn, user_id, post.community_id).is_ok() {
|
if CommunityUserBanView::get(&conn, user_id, post.community_id).is_ok() {
|
||||||
return Err(APIError::err(&self.op, "community_ban"))?;
|
return Err(APIError::err("community_ban").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a site ban
|
// Check for a site ban
|
||||||
if UserView::read(&conn, user_id)?.banned {
|
if UserView::read(&conn, user_id)?.banned {
|
||||||
return Err(APIError::err(&self.op, "site_ban"))?;
|
return Err(APIError::err("site_ban").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let like_form = PostLikeForm {
|
let like_form = PostLikeForm {
|
||||||
|
@ -294,39 +305,41 @@ impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> {
|
||||||
PostLike::remove(&conn, &like_form)?;
|
PostLike::remove(&conn, &like_form)?;
|
||||||
|
|
||||||
// Only add the like if the score isnt 0
|
// Only add the like if the score isnt 0
|
||||||
let do_add = &like_form.score != &0 && (&like_form.score == &1 || &like_form.score == &-1);
|
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
|
||||||
if do_add {
|
if do_add {
|
||||||
let _inserted_like = match PostLike::like(&conn, &like_form) {
|
let _inserted_like = match PostLike::like(&conn, &like_form) {
|
||||||
Ok(like) => like,
|
Ok(like) => like,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_like_post"))?,
|
Err(_e) => return Err(APIError::err("couldnt_like_post").into()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let post_view = match PostView::read(&conn, data.post_id, Some(user_id)) {
|
let post_view = match PostView::read(&conn, data.post_id, Some(user_id)) {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_post"))?,
|
Err(_e) => return Err(APIError::err("couldnt_find_post").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// just output the score
|
// just output the score
|
||||||
Ok(CreatePostLikeResponse {
|
Ok(PostResponse { post: post_view })
|
||||||
op: self.op.to_string(),
|
|
||||||
post: post_view,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<PostResponse> for Oper<EditPost> {
|
impl Perform<PostResponse> for Oper<EditPost> {
|
||||||
fn perform(&self) -> Result<PostResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<PostResponse, Error> {
|
||||||
let data: &EditPost = &self.data;
|
let data: &EditPost = &self.data;
|
||||||
if has_slurs(&data.name) || (data.body.is_some() && has_slurs(&data.body.to_owned().unwrap())) {
|
|
||||||
return Err(APIError::err(&self.op, "no_slurs"))?;
|
if let Err(slurs) = slur_check(&data.name) {
|
||||||
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let conn = establish_connection();
|
if let Some(body) = &data.body {
|
||||||
|
if let Err(slurs) = slur_check(body) {
|
||||||
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -341,19 +354,23 @@ impl Perform<PostResponse> for Oper<EditPost> {
|
||||||
);
|
);
|
||||||
editors.append(&mut UserView::admins(&conn)?.into_iter().map(|a| a.id).collect());
|
editors.append(&mut UserView::admins(&conn)?.into_iter().map(|a| a.id).collect());
|
||||||
if !editors.contains(&user_id) {
|
if !editors.contains(&user_id) {
|
||||||
return Err(APIError::err(&self.op, "no_post_edit_allowed"))?;
|
return Err(APIError::err("no_post_edit_allowed").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a community ban
|
// Check for a community ban
|
||||||
if CommunityUserBanView::get(&conn, user_id, data.community_id).is_ok() {
|
if CommunityUserBanView::get(&conn, user_id, data.community_id).is_ok() {
|
||||||
return Err(APIError::err(&self.op, "community_ban"))?;
|
return Err(APIError::err("community_ban").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a site ban
|
// Check for a site ban
|
||||||
if UserView::read(&conn, user_id)?.banned {
|
if UserView::read(&conn, user_id)?.banned {
|
||||||
return Err(APIError::err(&self.op, "site_ban"))?;
|
return Err(APIError::err("site_ban").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch Iframely and Pictshare cached image
|
||||||
|
let (iframely_title, iframely_description, iframely_html, pictshare_thumbnail) =
|
||||||
|
fetch_iframely_and_pictshare_data(data.url.to_owned());
|
||||||
|
|
||||||
let post_form = PostForm {
|
let post_form = PostForm {
|
||||||
name: data.name.to_owned(),
|
name: data.name.to_owned(),
|
||||||
url: data.url.to_owned(),
|
url: data.url.to_owned(),
|
||||||
|
@ -366,11 +383,23 @@ impl Perform<PostResponse> for Oper<EditPost> {
|
||||||
locked: data.locked.to_owned(),
|
locked: data.locked.to_owned(),
|
||||||
stickied: data.stickied.to_owned(),
|
stickied: data.stickied.to_owned(),
|
||||||
updated: Some(naive_now()),
|
updated: Some(naive_now()),
|
||||||
|
embed_title: iframely_title,
|
||||||
|
embed_description: iframely_description,
|
||||||
|
embed_html: iframely_html,
|
||||||
|
thumbnail_url: pictshare_thumbnail,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _updated_post = match Post::update(&conn, data.edit_id, &post_form) {
|
let _updated_post = match Post::update(&conn, data.edit_id, &post_form) {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_post"))?,
|
Err(e) => {
|
||||||
|
let err_type = if e.to_string() == "value too long for type character varying(200)" {
|
||||||
|
"post_title_too_long"
|
||||||
|
} else {
|
||||||
|
"couldnt_update_post"
|
||||||
|
};
|
||||||
|
|
||||||
|
return Err(APIError::err(err_type).into());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
|
@ -404,21 +433,17 @@ impl Perform<PostResponse> for Oper<EditPost> {
|
||||||
|
|
||||||
let post_view = PostView::read(&conn, data.edit_id, Some(user_id))?;
|
let post_view = PostView::read(&conn, data.edit_id, Some(user_id))?;
|
||||||
|
|
||||||
Ok(PostResponse {
|
Ok(PostResponse { post: post_view })
|
||||||
op: self.op.to_string(),
|
|
||||||
post: post_view,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<PostResponse> for Oper<SavePost> {
|
impl Perform<PostResponse> for Oper<SavePost> {
|
||||||
fn perform(&self) -> Result<PostResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<PostResponse, Error> {
|
||||||
let data: &SavePost = &self.data;
|
let data: &SavePost = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -431,20 +456,17 @@ impl Perform<PostResponse> for Oper<SavePost> {
|
||||||
if data.save {
|
if data.save {
|
||||||
match PostSaved::save(&conn, &post_saved_form) {
|
match PostSaved::save(&conn, &post_saved_form) {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_save_post"))?,
|
Err(_e) => return Err(APIError::err("couldnt_save_post").into()),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
match PostSaved::unsave(&conn, &post_saved_form) {
|
match PostSaved::unsave(&conn, &post_saved_form) {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_save_post"))?,
|
Err(_e) => return Err(APIError::err("couldnt_save_post").into()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let post_view = PostView::read(&conn, data.post_id, Some(user_id))?;
|
let post_view = PostView::read(&conn, data.post_id, Some(user_id))?;
|
||||||
|
|
||||||
Ok(PostResponse {
|
Ok(PostResponse { post: post_view })
|
||||||
op: self.op.to_string(),
|
|
||||||
post: post_view,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use diesel::PgConnection;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct ListCategories;
|
pub struct ListCategories {}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct ListCategoriesResponse {
|
pub struct ListCategoriesResponse {
|
||||||
op: String,
|
|
||||||
categories: Vec<Category>,
|
categories: Vec<Category>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,11 +18,11 @@ pub struct Search {
|
||||||
sort: String,
|
sort: String,
|
||||||
page: Option<i64>,
|
page: Option<i64>,
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
|
auth: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct SearchResponse {
|
pub struct SearchResponse {
|
||||||
op: String,
|
|
||||||
type_: String,
|
type_: String,
|
||||||
comments: Vec<CommentView>,
|
comments: Vec<CommentView>,
|
||||||
posts: Vec<PostView>,
|
posts: Vec<PostView>,
|
||||||
|
@ -40,7 +40,6 @@ pub struct GetModlog {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct GetModlogResponse {
|
pub struct GetModlogResponse {
|
||||||
op: String,
|
|
||||||
removed_posts: Vec<ModRemovePostView>,
|
removed_posts: Vec<ModRemovePostView>,
|
||||||
locked_posts: Vec<ModLockPostView>,
|
locked_posts: Vec<ModLockPostView>,
|
||||||
stickied_posts: Vec<ModStickyPostView>,
|
stickied_posts: Vec<ModStickyPostView>,
|
||||||
|
@ -73,17 +72,15 @@ pub struct EditSite {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct GetSite;
|
pub struct GetSite {}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct SiteResponse {
|
pub struct SiteResponse {
|
||||||
op: String,
|
|
||||||
site: SiteView,
|
site: SiteView,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct GetSiteResponse {
|
pub struct GetSiteResponse {
|
||||||
op: String,
|
|
||||||
site: Option<SiteView>,
|
site: Option<SiteView>,
|
||||||
admins: Vec<UserView>,
|
admins: Vec<UserView>,
|
||||||
banned: Vec<UserView>,
|
banned: Vec<UserView>,
|
||||||
|
@ -97,24 +94,19 @@ pub struct TransferSite {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<ListCategoriesResponse> for Oper<ListCategories> {
|
impl Perform<ListCategoriesResponse> for Oper<ListCategories> {
|
||||||
fn perform(&self) -> Result<ListCategoriesResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<ListCategoriesResponse, Error> {
|
||||||
let _data: &ListCategories = &self.data;
|
let _data: &ListCategories = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let categories: Vec<Category> = Category::list_all(&conn)?;
|
let categories: Vec<Category> = Category::list_all(&conn)?;
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(ListCategoriesResponse {
|
Ok(ListCategoriesResponse { categories })
|
||||||
op: self.op.to_string(),
|
|
||||||
categories,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<GetModlogResponse> for Oper<GetModlog> {
|
impl Perform<GetModlogResponse> for Oper<GetModlog> {
|
||||||
fn perform(&self) -> Result<GetModlogResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetModlogResponse, Error> {
|
||||||
let data: &GetModlog = &self.data;
|
let data: &GetModlog = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let removed_posts = ModRemovePostView::list(
|
let removed_posts = ModRemovePostView::list(
|
||||||
&conn,
|
&conn,
|
||||||
|
@ -160,20 +152,18 @@ impl Perform<GetModlogResponse> for Oper<GetModlog> {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// These arrays are only for the full modlog, when a community isn't given
|
// These arrays are only for the full modlog, when a community isn't given
|
||||||
let mut removed_communities = Vec::new();
|
let (removed_communities, banned, added) = if data.community_id.is_none() {
|
||||||
let mut banned = Vec::new();
|
(
|
||||||
let mut added = Vec::new();
|
ModRemoveCommunityView::list(&conn, data.mod_user_id, data.page, data.limit)?,
|
||||||
|
ModBanView::list(&conn, data.mod_user_id, data.page, data.limit)?,
|
||||||
if data.community_id.is_none() {
|
ModAddView::list(&conn, data.mod_user_id, data.page, data.limit)?,
|
||||||
removed_communities =
|
)
|
||||||
ModRemoveCommunityView::list(&conn, data.mod_user_id, data.page, data.limit)?;
|
} else {
|
||||||
banned = ModBanView::list(&conn, data.mod_user_id, data.page, data.limit)?;
|
(Vec::new(), Vec::new(), Vec::new())
|
||||||
added = ModAddView::list(&conn, data.mod_user_id, data.page, data.limit)?;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(GetModlogResponse {
|
Ok(GetModlogResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
removed_posts,
|
removed_posts,
|
||||||
locked_posts,
|
locked_posts,
|
||||||
stickied_posts,
|
stickied_posts,
|
||||||
|
@ -188,26 +178,29 @@ impl Perform<GetModlogResponse> for Oper<GetModlog> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<SiteResponse> for Oper<CreateSite> {
|
impl Perform<SiteResponse> for Oper<CreateSite> {
|
||||||
fn perform(&self) -> Result<SiteResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<SiteResponse, Error> {
|
||||||
let data: &CreateSite = &self.data;
|
let data: &CreateSite = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if has_slurs(&data.name)
|
if let Err(slurs) = slur_check(&data.name) {
|
||||||
|| (data.description.is_some() && has_slurs(&data.description.to_owned().unwrap()))
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
{
|
}
|
||||||
return Err(APIError::err(&self.op, "no_slurs"))?;
|
|
||||||
|
if let Some(description) = &data.description {
|
||||||
|
if let Err(slurs) = slur_check(description) {
|
||||||
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
if !UserView::read(&conn, user_id)?.admin {
|
if !UserView::read(&conn, user_id)?.admin {
|
||||||
return Err(APIError::err(&self.op, "not_an_admin"))?;
|
return Err(APIError::err("not_an_admin").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let site_form = SiteForm {
|
let site_form = SiteForm {
|
||||||
|
@ -222,39 +215,39 @@ impl Perform<SiteResponse> for Oper<CreateSite> {
|
||||||
|
|
||||||
match Site::create(&conn, &site_form) {
|
match Site::create(&conn, &site_form) {
|
||||||
Ok(site) => site,
|
Ok(site) => site,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "site_already_exists"))?,
|
Err(_e) => return Err(APIError::err("site_already_exists").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let site_view = SiteView::read(&conn)?;
|
let site_view = SiteView::read(&conn)?;
|
||||||
|
|
||||||
Ok(SiteResponse {
|
Ok(SiteResponse { site: site_view })
|
||||||
op: self.op.to_string(),
|
|
||||||
site: site_view,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<SiteResponse> for Oper<EditSite> {
|
impl Perform<SiteResponse> for Oper<EditSite> {
|
||||||
fn perform(&self) -> Result<SiteResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<SiteResponse, Error> {
|
||||||
let data: &EditSite = &self.data;
|
let data: &EditSite = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if has_slurs(&data.name)
|
if let Err(slurs) = slur_check(&data.name) {
|
||||||
|| (data.description.is_some() && has_slurs(&data.description.to_owned().unwrap()))
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
{
|
}
|
||||||
return Err(APIError::err(&self.op, "no_slurs"))?;
|
|
||||||
|
if let Some(description) = &data.description {
|
||||||
|
if let Err(slurs) = slur_check(description) {
|
||||||
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
if UserView::read(&conn, user_id)?.admin == false {
|
if !UserView::read(&conn, user_id)?.admin {
|
||||||
return Err(APIError::err(&self.op, "not_an_admin"))?;
|
return Err(APIError::err("not_an_admin").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let found_site = Site::read(&conn, 1)?;
|
let found_site = Site::read(&conn, 1)?;
|
||||||
|
@ -271,22 +264,18 @@ impl Perform<SiteResponse> for Oper<EditSite> {
|
||||||
|
|
||||||
match Site::update(&conn, 1, &site_form) {
|
match Site::update(&conn, 1, &site_form) {
|
||||||
Ok(site) => site,
|
Ok(site) => site,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_site"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_site").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let site_view = SiteView::read(&conn)?;
|
let site_view = SiteView::read(&conn)?;
|
||||||
|
|
||||||
Ok(SiteResponse {
|
Ok(SiteResponse { site: site_view })
|
||||||
op: self.op.to_string(),
|
|
||||||
site: site_view,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<GetSiteResponse> for Oper<GetSite> {
|
impl Perform<GetSiteResponse> for Oper<GetSite> {
|
||||||
fn perform(&self) -> Result<GetSiteResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetSiteResponse, Error> {
|
||||||
let _data: &GetSite = &self.data;
|
let _data: &GetSite = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
// It can return a null site in order to redirect
|
// It can return a null site in order to redirect
|
||||||
let site_view = match Site::read(&conn, 1) {
|
let site_view = match Site::read(&conn, 1) {
|
||||||
|
@ -305,7 +294,6 @@ impl Perform<GetSiteResponse> for Oper<GetSite> {
|
||||||
let banned = UserView::banned(&conn)?;
|
let banned = UserView::banned(&conn)?;
|
||||||
|
|
||||||
Ok(GetSiteResponse {
|
Ok(GetSiteResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
site: site_view,
|
site: site_view,
|
||||||
admins,
|
admins,
|
||||||
banned,
|
banned,
|
||||||
|
@ -315,9 +303,19 @@ impl Perform<GetSiteResponse> for Oper<GetSite> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<SearchResponse> for Oper<Search> {
|
impl Perform<SearchResponse> for Oper<Search> {
|
||||||
fn perform(&self) -> Result<SearchResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<SearchResponse, Error> {
|
||||||
let data: &Search = &self.data;
|
let data: &Search = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
let user_id: Option<i32> = match &data.auth {
|
||||||
|
Some(auth) => match Claims::decode(&auth) {
|
||||||
|
Ok(claims) => {
|
||||||
|
let user_id = claims.claims.id;
|
||||||
|
Some(user_id)
|
||||||
|
}
|
||||||
|
Err(_e) => None,
|
||||||
|
},
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
let sort = SortType::from_str(&data.sort)?;
|
let sort = SortType::from_str(&data.sort)?;
|
||||||
let type_ = SearchType::from_str(&data.type_)?;
|
let type_ = SearchType::from_str(&data.type_)?;
|
||||||
|
@ -336,6 +334,7 @@ impl Perform<SearchResponse> for Oper<Search> {
|
||||||
.show_nsfw(true)
|
.show_nsfw(true)
|
||||||
.for_community_id(data.community_id)
|
.for_community_id(data.community_id)
|
||||||
.search_term(data.q.to_owned())
|
.search_term(data.q.to_owned())
|
||||||
|
.my_user_id(user_id)
|
||||||
.page(data.page)
|
.page(data.page)
|
||||||
.limit(data.limit)
|
.limit(data.limit)
|
||||||
.list()?;
|
.list()?;
|
||||||
|
@ -344,6 +343,7 @@ impl Perform<SearchResponse> for Oper<Search> {
|
||||||
comments = CommentQueryBuilder::create(&conn)
|
comments = CommentQueryBuilder::create(&conn)
|
||||||
.sort(&sort)
|
.sort(&sort)
|
||||||
.search_term(data.q.to_owned())
|
.search_term(data.q.to_owned())
|
||||||
|
.my_user_id(user_id)
|
||||||
.page(data.page)
|
.page(data.page)
|
||||||
.limit(data.limit)
|
.limit(data.limit)
|
||||||
.list()?;
|
.list()?;
|
||||||
|
@ -370,6 +370,7 @@ impl Perform<SearchResponse> for Oper<Search> {
|
||||||
.show_nsfw(true)
|
.show_nsfw(true)
|
||||||
.for_community_id(data.community_id)
|
.for_community_id(data.community_id)
|
||||||
.search_term(data.q.to_owned())
|
.search_term(data.q.to_owned())
|
||||||
|
.my_user_id(user_id)
|
||||||
.page(data.page)
|
.page(data.page)
|
||||||
.limit(data.limit)
|
.limit(data.limit)
|
||||||
.list()?;
|
.list()?;
|
||||||
|
@ -377,6 +378,7 @@ impl Perform<SearchResponse> for Oper<Search> {
|
||||||
comments = CommentQueryBuilder::create(&conn)
|
comments = CommentQueryBuilder::create(&conn)
|
||||||
.sort(&sort)
|
.sort(&sort)
|
||||||
.search_term(data.q.to_owned())
|
.search_term(data.q.to_owned())
|
||||||
|
.my_user_id(user_id)
|
||||||
.page(data.page)
|
.page(data.page)
|
||||||
.limit(data.limit)
|
.limit(data.limit)
|
||||||
.list()?;
|
.list()?;
|
||||||
|
@ -409,7 +411,6 @@ impl Perform<SearchResponse> for Oper<Search> {
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(SearchResponse {
|
Ok(SearchResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
type_: data.type_.to_owned(),
|
type_: data.type_.to_owned(),
|
||||||
comments,
|
comments,
|
||||||
posts,
|
posts,
|
||||||
|
@ -420,13 +421,12 @@ impl Perform<SearchResponse> for Oper<Search> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<GetSiteResponse> for Oper<TransferSite> {
|
impl Perform<GetSiteResponse> for Oper<TransferSite> {
|
||||||
fn perform(&self) -> Result<GetSiteResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetSiteResponse, Error> {
|
||||||
let data: &TransferSite = &self.data;
|
let data: &TransferSite = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -435,7 +435,7 @@ impl Perform<GetSiteResponse> for Oper<TransferSite> {
|
||||||
|
|
||||||
// Make sure user is the creator
|
// Make sure user is the creator
|
||||||
if read_site.creator_id != user_id {
|
if read_site.creator_id != user_id {
|
||||||
return Err(APIError::err(&self.op, "not_an_admin"))?;
|
return Err(APIError::err("not_an_admin").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let site_form = SiteForm {
|
let site_form = SiteForm {
|
||||||
|
@ -450,7 +450,7 @@ impl Perform<GetSiteResponse> for Oper<TransferSite> {
|
||||||
|
|
||||||
match Site::update(&conn, 1, &site_form) {
|
match Site::update(&conn, 1, &site_form) {
|
||||||
Ok(site) => site,
|
Ok(site) => site,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_site"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_site").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
|
@ -475,7 +475,6 @@ impl Perform<GetSiteResponse> for Oper<TransferSite> {
|
||||||
let banned = UserView::banned(&conn)?;
|
let banned = UserView::banned(&conn)?;
|
||||||
|
|
||||||
Ok(GetSiteResponse {
|
Ok(GetSiteResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
site: Some(site_view),
|
site: Some(site_view),
|
||||||
admins,
|
admins,
|
||||||
banned,
|
banned,
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::settings::Settings;
|
||||||
use crate::{generate_random_string, send_email};
|
use crate::{generate_random_string, send_email};
|
||||||
use bcrypt::verify;
|
use bcrypt::verify;
|
||||||
|
use diesel::PgConnection;
|
||||||
|
use log::error;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
@ -26,12 +29,19 @@ pub struct SaveUserSettings {
|
||||||
default_sort_type: i16,
|
default_sort_type: i16,
|
||||||
default_listing_type: i16,
|
default_listing_type: i16,
|
||||||
lang: String,
|
lang: String,
|
||||||
|
avatar: Option<String>,
|
||||||
|
email: Option<String>,
|
||||||
|
matrix_user_id: Option<String>,
|
||||||
|
new_password: Option<String>,
|
||||||
|
new_password_verify: Option<String>,
|
||||||
|
old_password: Option<String>,
|
||||||
|
show_avatars: bool,
|
||||||
|
send_notifications_to_email: bool,
|
||||||
auth: String,
|
auth: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct LoginResponse {
|
pub struct LoginResponse {
|
||||||
op: String,
|
|
||||||
jwt: String,
|
jwt: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +59,6 @@ pub struct GetUserDetails {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct GetUserDetailsResponse {
|
pub struct GetUserDetailsResponse {
|
||||||
op: String,
|
|
||||||
user: UserView,
|
user: UserView,
|
||||||
follows: Vec<CommunityFollowerView>,
|
follows: Vec<CommunityFollowerView>,
|
||||||
moderates: Vec<CommunityModeratorView>,
|
moderates: Vec<CommunityModeratorView>,
|
||||||
|
@ -60,13 +69,11 @@ pub struct GetUserDetailsResponse {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct GetRepliesResponse {
|
pub struct GetRepliesResponse {
|
||||||
op: String,
|
|
||||||
replies: Vec<ReplyView>,
|
replies: Vec<ReplyView>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct GetUserMentionsResponse {
|
pub struct GetUserMentionsResponse {
|
||||||
op: String,
|
|
||||||
mentions: Vec<UserMentionView>,
|
mentions: Vec<UserMentionView>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +91,6 @@ pub struct AddAdmin {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct AddAdminResponse {
|
pub struct AddAdminResponse {
|
||||||
op: String,
|
|
||||||
admins: Vec<UserView>,
|
admins: Vec<UserView>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +105,6 @@ pub struct BanUser {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct BanUserResponse {
|
pub struct BanUserResponse {
|
||||||
op: String,
|
|
||||||
user: UserView,
|
user: UserView,
|
||||||
banned: bool,
|
banned: bool,
|
||||||
}
|
}
|
||||||
|
@ -131,7 +136,6 @@ pub struct EditUserMention {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct UserMentionResponse {
|
pub struct UserMentionResponse {
|
||||||
op: String,
|
|
||||||
mention: UserMentionView,
|
mention: UserMentionView,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,9 +151,7 @@ pub struct PasswordReset {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct PasswordResetResponse {
|
pub struct PasswordResetResponse {}
|
||||||
op: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct PasswordChange {
|
pub struct PasswordChange {
|
||||||
|
@ -158,67 +160,103 @@ pub struct PasswordChange {
|
||||||
password_verify: String,
|
password_verify: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct CreatePrivateMessage {
|
||||||
|
content: String,
|
||||||
|
pub recipient_id: i32,
|
||||||
|
auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct EditPrivateMessage {
|
||||||
|
edit_id: i32,
|
||||||
|
content: Option<String>,
|
||||||
|
deleted: Option<bool>,
|
||||||
|
read: Option<bool>,
|
||||||
|
auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct GetPrivateMessages {
|
||||||
|
unread_only: bool,
|
||||||
|
page: Option<i64>,
|
||||||
|
limit: Option<i64>,
|
||||||
|
auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct PrivateMessagesResponse {
|
||||||
|
messages: Vec<PrivateMessageView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct PrivateMessageResponse {
|
||||||
|
message: PrivateMessageView,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct UserJoin {
|
||||||
|
auth: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct UserJoinResponse {
|
||||||
|
pub user_id: i32,
|
||||||
|
}
|
||||||
|
|
||||||
impl Perform<LoginResponse> for Oper<Login> {
|
impl Perform<LoginResponse> for Oper<Login> {
|
||||||
fn perform(&self) -> Result<LoginResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<LoginResponse, Error> {
|
||||||
let data: &Login = &self.data;
|
let data: &Login = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
// Fetch that username / email
|
// Fetch that username / email
|
||||||
let user: User_ = match User_::find_by_email_or_username(&conn, &data.username_or_email) {
|
let user: User_ = match User_::find_by_email_or_username(&conn, &data.username_or_email) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => {
|
Err(_e) => return Err(APIError::err("couldnt_find_that_username_or_email").into()),
|
||||||
return Err(APIError::err(
|
|
||||||
&self.op,
|
|
||||||
"couldnt_find_that_username_or_email",
|
|
||||||
))?
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Verify the password
|
// Verify the password
|
||||||
let valid: bool = verify(&data.password, &user.password_encrypted).unwrap_or(false);
|
let valid: bool = verify(&data.password, &user.password_encrypted).unwrap_or(false);
|
||||||
if !valid {
|
if !valid {
|
||||||
return Err(APIError::err(&self.op, "password_incorrect"))?;
|
return Err(APIError::err("password_incorrect").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(LoginResponse {
|
Ok(LoginResponse { jwt: user.jwt() })
|
||||||
op: self.op.to_string(),
|
|
||||||
jwt: user.jwt(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<LoginResponse> for Oper<Register> {
|
impl Perform<LoginResponse> for Oper<Register> {
|
||||||
fn perform(&self) -> Result<LoginResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<LoginResponse, Error> {
|
||||||
let data: &Register = &self.data;
|
let data: &Register = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
// Make sure site has open registration
|
// Make sure site has open registration
|
||||||
if let Ok(site) = SiteView::read(&conn) {
|
if let Ok(site) = SiteView::read(&conn) {
|
||||||
if !site.open_registration {
|
if !site.open_registration {
|
||||||
return Err(APIError::err(&self.op, "registration_closed"))?;
|
return Err(APIError::err("registration_closed").into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure passwords match
|
// Make sure passwords match
|
||||||
if &data.password != &data.password_verify {
|
if data.password != data.password_verify {
|
||||||
return Err(APIError::err(&self.op, "passwords_dont_match"))?;
|
return Err(APIError::err("passwords_dont_match").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if has_slurs(&data.username) {
|
if let Err(slurs) = slur_check(&data.username) {
|
||||||
return Err(APIError::err(&self.op, "no_slurs"))?;
|
return Err(APIError::err(&slurs_vec_to_str(slurs)).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure there are no admins
|
// Make sure there are no admins
|
||||||
if data.admin && UserView::admins(&conn)?.len() > 0 {
|
if data.admin && !UserView::admins(&conn)?.is_empty() {
|
||||||
return Err(APIError::err(&self.op, "admin_already_created"))?;
|
return Err(APIError::err("admin_already_created").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the new user
|
// Register the new user
|
||||||
let user_form = UserForm {
|
let user_form = UserForm {
|
||||||
name: data.username.to_owned(),
|
name: data.username.to_owned(),
|
||||||
fedi_name: Settings::get().hostname.into(),
|
fedi_name: Settings::get().hostname.to_owned(),
|
||||||
email: data.email.to_owned(),
|
email: data.email.to_owned(),
|
||||||
|
matrix_user_id: None,
|
||||||
|
avatar: None,
|
||||||
password_encrypted: data.password.to_owned(),
|
password_encrypted: data.password.to_owned(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
|
@ -229,12 +267,24 @@ impl Perform<LoginResponse> for Oper<Register> {
|
||||||
default_sort_type: SortType::Hot as i16,
|
default_sort_type: SortType::Hot as i16,
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
default_listing_type: ListingType::Subscribed as i16,
|
||||||
lang: "browser".into(),
|
lang: "browser".into(),
|
||||||
|
show_avatars: true,
|
||||||
|
send_notifications_to_email: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the user
|
// Create the user
|
||||||
let inserted_user = match User_::register(&conn, &user_form) {
|
let inserted_user = match User_::register(&conn, &user_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "user_already_exists"))?,
|
Err(e) => {
|
||||||
|
let err_type = if e.to_string()
|
||||||
|
== "duplicate key value violates unique constraint \"user__email_key\""
|
||||||
|
{
|
||||||
|
"email_already_exists"
|
||||||
|
} else {
|
||||||
|
"user_already_exists"
|
||||||
|
};
|
||||||
|
|
||||||
|
return Err(APIError::err(err_type).into());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the main community if it doesn't exist
|
// Create the main community if it doesn't exist
|
||||||
|
@ -265,7 +315,7 @@ impl Perform<LoginResponse> for Oper<Register> {
|
||||||
let _inserted_community_follower =
|
let _inserted_community_follower =
|
||||||
match CommunityFollower::follow(&conn, &community_follower_form) {
|
match CommunityFollower::follow(&conn, &community_follower_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "community_follower_already_exists"))?,
|
Err(_e) => return Err(APIError::err("community_follower_already_exists").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// If its an admin, add them as a mod and follower to main
|
// If its an admin, add them as a mod and follower to main
|
||||||
|
@ -278,42 +328,70 @@ impl Perform<LoginResponse> for Oper<Register> {
|
||||||
let _inserted_community_moderator =
|
let _inserted_community_moderator =
|
||||||
match CommunityModerator::join(&conn, &community_moderator_form) {
|
match CommunityModerator::join(&conn, &community_moderator_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => {
|
Err(_e) => return Err(APIError::err("community_moderator_already_exists").into()),
|
||||||
return Err(APIError::err(
|
|
||||||
&self.op,
|
|
||||||
"community_moderator_already_exists",
|
|
||||||
))?
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(LoginResponse {
|
Ok(LoginResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
jwt: inserted_user.jwt(),
|
jwt: inserted_user.jwt(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<LoginResponse> for Oper<SaveUserSettings> {
|
impl Perform<LoginResponse> for Oper<SaveUserSettings> {
|
||||||
fn perform(&self) -> Result<LoginResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<LoginResponse, Error> {
|
||||||
let data: &SaveUserSettings = &self.data;
|
let data: &SaveUserSettings = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
|
||||||
let read_user = User_::read(&conn, user_id)?;
|
let read_user = User_::read(&conn, user_id)?;
|
||||||
|
|
||||||
|
let email = match &data.email {
|
||||||
|
Some(email) => Some(email.to_owned()),
|
||||||
|
None => read_user.email,
|
||||||
|
};
|
||||||
|
|
||||||
|
let password_encrypted = match &data.new_password {
|
||||||
|
Some(new_password) => {
|
||||||
|
match &data.new_password_verify {
|
||||||
|
Some(new_password_verify) => {
|
||||||
|
// Make sure passwords match
|
||||||
|
if new_password != new_password_verify {
|
||||||
|
return Err(APIError::err("passwords_dont_match").into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the old password
|
||||||
|
match &data.old_password {
|
||||||
|
Some(old_password) => {
|
||||||
|
let valid: bool =
|
||||||
|
verify(old_password, &read_user.password_encrypted).unwrap_or(false);
|
||||||
|
if !valid {
|
||||||
|
return Err(APIError::err("password_incorrect").into());
|
||||||
|
}
|
||||||
|
User_::update_password(&conn, user_id, &new_password)?.password_encrypted
|
||||||
|
}
|
||||||
|
None => return Err(APIError::err("password_incorrect").into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => return Err(APIError::err("passwords_dont_match").into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => read_user.password_encrypted,
|
||||||
|
};
|
||||||
|
|
||||||
let user_form = UserForm {
|
let user_form = UserForm {
|
||||||
name: read_user.name,
|
name: read_user.name,
|
||||||
fedi_name: read_user.fedi_name,
|
fedi_name: read_user.fedi_name,
|
||||||
email: read_user.email,
|
email,
|
||||||
password_encrypted: read_user.password_encrypted,
|
matrix_user_id: data.matrix_user_id.to_owned(),
|
||||||
|
avatar: data.avatar.to_owned(),
|
||||||
|
password_encrypted,
|
||||||
preferred_username: read_user.preferred_username,
|
preferred_username: read_user.preferred_username,
|
||||||
updated: Some(naive_now()),
|
updated: Some(naive_now()),
|
||||||
admin: read_user.admin,
|
admin: read_user.admin,
|
||||||
|
@ -323,25 +401,35 @@ impl Perform<LoginResponse> for Oper<SaveUserSettings> {
|
||||||
default_sort_type: data.default_sort_type,
|
default_sort_type: data.default_sort_type,
|
||||||
default_listing_type: data.default_listing_type,
|
default_listing_type: data.default_listing_type,
|
||||||
lang: data.lang.to_owned(),
|
lang: data.lang.to_owned(),
|
||||||
|
show_avatars: data.show_avatars,
|
||||||
|
send_notifications_to_email: data.send_notifications_to_email,
|
||||||
};
|
};
|
||||||
|
|
||||||
let updated_user = match User_::update(&conn, user_id, &user_form) {
|
let updated_user = match User_::update(&conn, user_id, &user_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_user"))?,
|
Err(e) => {
|
||||||
|
let err_type = if e.to_string()
|
||||||
|
== "duplicate key value violates unique constraint \"user__email_key\""
|
||||||
|
{
|
||||||
|
"email_already_exists"
|
||||||
|
} else {
|
||||||
|
"user_already_exists"
|
||||||
|
};
|
||||||
|
|
||||||
|
return Err(APIError::err(err_type).into());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(LoginResponse {
|
Ok(LoginResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
jwt: updated_user.jwt(),
|
jwt: updated_user.jwt(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<GetUserDetailsResponse> for Oper<GetUserDetails> {
|
impl Perform<GetUserDetailsResponse> for Oper<GetUserDetails> {
|
||||||
fn perform(&self) -> Result<GetUserDetailsResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetUserDetailsResponse, Error> {
|
||||||
let data: &GetUserDetails = &self.data;
|
let data: &GetUserDetails = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let user_claims: Option<Claims> = match &data.auth {
|
let user_claims: Option<Claims> = match &data.auth {
|
||||||
Some(auth) => match Claims::decode(&auth) {
|
Some(auth) => match Claims::decode(&auth) {
|
||||||
|
@ -366,15 +454,20 @@ impl Perform<GetUserDetailsResponse> for Oper<GetUserDetails> {
|
||||||
let user_details_id = match data.user_id {
|
let user_details_id = match data.user_id {
|
||||||
Some(id) => id,
|
Some(id) => id,
|
||||||
None => {
|
None => {
|
||||||
User_::read_from_name(
|
match User_::read_from_name(
|
||||||
&conn,
|
&conn,
|
||||||
data.username.to_owned().unwrap_or("admin".to_string()),
|
data
|
||||||
)?
|
.username
|
||||||
.id
|
.to_owned()
|
||||||
|
.unwrap_or_else(|| "admin".to_string()),
|
||||||
|
) {
|
||||||
|
Ok(user) => user.id,
|
||||||
|
Err(_e) => return Err(APIError::err("couldnt_find_that_username_or_email").into()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_view = UserView::read(&conn, user_details_id)?;
|
let mut user_view = UserView::read(&conn, user_details_id)?;
|
||||||
|
|
||||||
let mut posts_query = PostQueryBuilder::create(&conn)
|
let mut posts_query = PostQueryBuilder::create(&conn)
|
||||||
.sort(&sort)
|
.sort(&sort)
|
||||||
|
@ -410,9 +503,17 @@ impl Perform<GetUserDetailsResponse> for Oper<GetUserDetails> {
|
||||||
let creator_user = admins.remove(creator_index);
|
let creator_user = admins.remove(creator_index);
|
||||||
admins.insert(0, creator_user);
|
admins.insert(0, creator_user);
|
||||||
|
|
||||||
|
// If its not the same user, remove the email
|
||||||
|
if let Some(user_id) = user_id {
|
||||||
|
if user_details_id != user_id {
|
||||||
|
user_view.email = None;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
user_view.email = None;
|
||||||
|
}
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(GetUserDetailsResponse {
|
Ok(GetUserDetailsResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
user: user_view,
|
user: user_view,
|
||||||
follows,
|
follows,
|
||||||
moderates,
|
moderates,
|
||||||
|
@ -424,28 +525,30 @@ impl Perform<GetUserDetailsResponse> for Oper<GetUserDetails> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<AddAdminResponse> for Oper<AddAdmin> {
|
impl Perform<AddAdminResponse> for Oper<AddAdmin> {
|
||||||
fn perform(&self) -> Result<AddAdminResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<AddAdminResponse, Error> {
|
||||||
let data: &AddAdmin = &self.data;
|
let data: &AddAdmin = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
if UserView::read(&conn, user_id)?.admin == false {
|
if !UserView::read(&conn, user_id)?.admin {
|
||||||
return Err(APIError::err(&self.op, "not_an_admin"))?;
|
return Err(APIError::err("not_an_admin").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let read_user = User_::read(&conn, data.user_id)?;
|
let read_user = User_::read(&conn, data.user_id)?;
|
||||||
|
|
||||||
|
// TODO make addadmin easier
|
||||||
let user_form = UserForm {
|
let user_form = UserForm {
|
||||||
name: read_user.name,
|
name: read_user.name,
|
||||||
fedi_name: read_user.fedi_name,
|
fedi_name: read_user.fedi_name,
|
||||||
email: read_user.email,
|
email: read_user.email,
|
||||||
|
matrix_user_id: read_user.matrix_user_id,
|
||||||
|
avatar: read_user.avatar,
|
||||||
password_encrypted: read_user.password_encrypted,
|
password_encrypted: read_user.password_encrypted,
|
||||||
preferred_username: read_user.preferred_username,
|
preferred_username: read_user.preferred_username,
|
||||||
updated: Some(naive_now()),
|
updated: Some(naive_now()),
|
||||||
|
@ -456,11 +559,13 @@ impl Perform<AddAdminResponse> for Oper<AddAdmin> {
|
||||||
default_sort_type: read_user.default_sort_type,
|
default_sort_type: read_user.default_sort_type,
|
||||||
default_listing_type: read_user.default_listing_type,
|
default_listing_type: read_user.default_listing_type,
|
||||||
lang: read_user.lang,
|
lang: read_user.lang,
|
||||||
|
show_avatars: read_user.show_avatars,
|
||||||
|
send_notifications_to_email: read_user.send_notifications_to_email,
|
||||||
};
|
};
|
||||||
|
|
||||||
match User_::update(&conn, data.user_id, &user_form) {
|
match User_::update(&conn, data.user_id, &user_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_user"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_user").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
|
@ -478,36 +583,35 @@ impl Perform<AddAdminResponse> for Oper<AddAdmin> {
|
||||||
let creator_user = admins.remove(creator_index);
|
let creator_user = admins.remove(creator_index);
|
||||||
admins.insert(0, creator_user);
|
admins.insert(0, creator_user);
|
||||||
|
|
||||||
Ok(AddAdminResponse {
|
Ok(AddAdminResponse { admins })
|
||||||
op: self.op.to_string(),
|
|
||||||
admins,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<BanUserResponse> for Oper<BanUser> {
|
impl Perform<BanUserResponse> for Oper<BanUser> {
|
||||||
fn perform(&self) -> Result<BanUserResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<BanUserResponse, Error> {
|
||||||
let data: &BanUser = &self.data;
|
let data: &BanUser = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
if UserView::read(&conn, user_id)?.admin == false {
|
if !UserView::read(&conn, user_id)?.admin {
|
||||||
return Err(APIError::err(&self.op, "not_an_admin"))?;
|
return Err(APIError::err("not_an_admin").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let read_user = User_::read(&conn, data.user_id)?;
|
let read_user = User_::read(&conn, data.user_id)?;
|
||||||
|
|
||||||
|
// TODO make bans and addadmins easier
|
||||||
let user_form = UserForm {
|
let user_form = UserForm {
|
||||||
name: read_user.name,
|
name: read_user.name,
|
||||||
fedi_name: read_user.fedi_name,
|
fedi_name: read_user.fedi_name,
|
||||||
email: read_user.email,
|
email: read_user.email,
|
||||||
|
matrix_user_id: read_user.matrix_user_id,
|
||||||
|
avatar: read_user.avatar,
|
||||||
password_encrypted: read_user.password_encrypted,
|
password_encrypted: read_user.password_encrypted,
|
||||||
preferred_username: read_user.preferred_username,
|
preferred_username: read_user.preferred_username,
|
||||||
updated: Some(naive_now()),
|
updated: Some(naive_now()),
|
||||||
|
@ -518,11 +622,13 @@ impl Perform<BanUserResponse> for Oper<BanUser> {
|
||||||
default_sort_type: read_user.default_sort_type,
|
default_sort_type: read_user.default_sort_type,
|
||||||
default_listing_type: read_user.default_listing_type,
|
default_listing_type: read_user.default_listing_type,
|
||||||
lang: read_user.lang,
|
lang: read_user.lang,
|
||||||
|
show_avatars: read_user.show_avatars,
|
||||||
|
send_notifications_to_email: read_user.send_notifications_to_email,
|
||||||
};
|
};
|
||||||
|
|
||||||
match User_::update(&conn, data.user_id, &user_form) {
|
match User_::update(&conn, data.user_id, &user_form) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_user"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_user").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
|
@ -544,7 +650,6 @@ impl Perform<BanUserResponse> for Oper<BanUser> {
|
||||||
let user_view = UserView::read(&conn, data.user_id)?;
|
let user_view = UserView::read(&conn, data.user_id)?;
|
||||||
|
|
||||||
Ok(BanUserResponse {
|
Ok(BanUserResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
user: user_view,
|
user: user_view,
|
||||||
banned: data.ban,
|
banned: data.ban,
|
||||||
})
|
})
|
||||||
|
@ -552,13 +657,12 @@ impl Perform<BanUserResponse> for Oper<BanUser> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<GetRepliesResponse> for Oper<GetReplies> {
|
impl Perform<GetRepliesResponse> for Oper<GetReplies> {
|
||||||
fn perform(&self) -> Result<GetRepliesResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetRepliesResponse, Error> {
|
||||||
let data: &GetReplies = &self.data;
|
let data: &GetReplies = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -572,21 +676,17 @@ impl Perform<GetRepliesResponse> for Oper<GetReplies> {
|
||||||
.limit(data.limit)
|
.limit(data.limit)
|
||||||
.list()?;
|
.list()?;
|
||||||
|
|
||||||
Ok(GetRepliesResponse {
|
Ok(GetRepliesResponse { replies })
|
||||||
op: self.op.to_string(),
|
|
||||||
replies,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<GetUserMentionsResponse> for Oper<GetUserMentions> {
|
impl Perform<GetUserMentionsResponse> for Oper<GetUserMentions> {
|
||||||
fn perform(&self) -> Result<GetUserMentionsResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetUserMentionsResponse, Error> {
|
||||||
let data: &GetUserMentions = &self.data;
|
let data: &GetUserMentions = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -600,21 +700,17 @@ impl Perform<GetUserMentionsResponse> for Oper<GetUserMentions> {
|
||||||
.limit(data.limit)
|
.limit(data.limit)
|
||||||
.list()?;
|
.list()?;
|
||||||
|
|
||||||
Ok(GetUserMentionsResponse {
|
Ok(GetUserMentionsResponse { mentions })
|
||||||
op: self.op.to_string(),
|
|
||||||
mentions,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<UserMentionResponse> for Oper<EditUserMention> {
|
impl Perform<UserMentionResponse> for Oper<EditUserMention> {
|
||||||
fn perform(&self) -> Result<UserMentionResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<UserMentionResponse, Error> {
|
||||||
let data: &EditUserMention = &self.data;
|
let data: &EditUserMention = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -630,26 +726,24 @@ impl Perform<UserMentionResponse> for Oper<EditUserMention> {
|
||||||
let _updated_user_mention =
|
let _updated_user_mention =
|
||||||
match UserMention::update(&conn, user_mention.id, &user_mention_form) {
|
match UserMention::update(&conn, user_mention.id, &user_mention_form) {
|
||||||
Ok(comment) => comment,
|
Ok(comment) => comment,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_comment"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_mention_view = UserMentionView::read(&conn, user_mention.id, user_id)?;
|
let user_mention_view = UserMentionView::read(&conn, user_mention.id, user_id)?;
|
||||||
|
|
||||||
Ok(UserMentionResponse {
|
Ok(UserMentionResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
mention: user_mention_view,
|
mention: user_mention_view,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<GetRepliesResponse> for Oper<MarkAllAsRead> {
|
impl Perform<GetRepliesResponse> for Oper<MarkAllAsRead> {
|
||||||
fn perform(&self) -> Result<GetRepliesResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<GetRepliesResponse, Error> {
|
||||||
let data: &MarkAllAsRead = &self.data;
|
let data: &MarkAllAsRead = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -674,7 +768,7 @@ impl Perform<GetRepliesResponse> for Oper<MarkAllAsRead> {
|
||||||
|
|
||||||
let _updated_comment = match Comment::update(&conn, reply.id, &comment_form) {
|
let _updated_comment = match Comment::update(&conn, reply.id, &comment_form) {
|
||||||
Ok(comment) => comment,
|
Ok(comment) => comment,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_comment"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,25 +789,45 @@ impl Perform<GetRepliesResponse> for Oper<MarkAllAsRead> {
|
||||||
let _updated_mention =
|
let _updated_mention =
|
||||||
match UserMention::update(&conn, mention.user_mention_id, &mention_form) {
|
match UserMention::update(&conn, mention.user_mention_id, &mention_form) {
|
||||||
Ok(mention) => mention,
|
Ok(mention) => mention,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_comment"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(GetRepliesResponse {
|
// messages
|
||||||
op: self.op.to_string(),
|
let messages = PrivateMessageQueryBuilder::create(&conn, user_id)
|
||||||
replies: vec![],
|
.page(1)
|
||||||
})
|
.limit(999)
|
||||||
|
.unread_only(true)
|
||||||
|
.list()?;
|
||||||
|
|
||||||
|
for message in &messages {
|
||||||
|
let private_message_form = PrivateMessageForm {
|
||||||
|
content: None,
|
||||||
|
creator_id: message.to_owned().creator_id,
|
||||||
|
recipient_id: message.to_owned().recipient_id,
|
||||||
|
deleted: None,
|
||||||
|
read: Some(true),
|
||||||
|
updated: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let _updated_message = match PrivateMessage::update(&conn, message.id, &private_message_form)
|
||||||
|
{
|
||||||
|
Ok(message) => message,
|
||||||
|
Err(_e) => return Err(APIError::err("couldnt_update_private_message").into()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(GetRepliesResponse { replies: vec![] })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<LoginResponse> for Oper<DeleteAccount> {
|
impl Perform<LoginResponse> for Oper<DeleteAccount> {
|
||||||
fn perform(&self) -> Result<LoginResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<LoginResponse, Error> {
|
||||||
let data: &DeleteAccount = &self.data;
|
let data: &DeleteAccount = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?,
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let user_id = claims.id;
|
let user_id = claims.id;
|
||||||
|
@ -723,7 +837,7 @@ impl Perform<LoginResponse> for Oper<DeleteAccount> {
|
||||||
// Verify the password
|
// Verify the password
|
||||||
let valid: bool = verify(&data.password, &user.password_encrypted).unwrap_or(false);
|
let valid: bool = verify(&data.password, &user.password_encrypted).unwrap_or(false);
|
||||||
if !valid {
|
if !valid {
|
||||||
return Err(APIError::err(&self.op, "password_incorrect"))?;
|
return Err(APIError::err("password_incorrect").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comments
|
// Comments
|
||||||
|
@ -746,7 +860,7 @@ impl Perform<LoginResponse> for Oper<DeleteAccount> {
|
||||||
|
|
||||||
let _updated_comment = match Comment::update(&conn, comment.id, &comment_form) {
|
let _updated_comment = match Comment::update(&conn, comment.id, &comment_form) {
|
||||||
Ok(comment) => comment,
|
Ok(comment) => comment,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_comment"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -770,35 +884,32 @@ impl Perform<LoginResponse> for Oper<DeleteAccount> {
|
||||||
locked: None,
|
locked: None,
|
||||||
stickied: None,
|
stickied: None,
|
||||||
updated: Some(naive_now()),
|
updated: Some(naive_now()),
|
||||||
|
embed_title: None,
|
||||||
|
embed_description: None,
|
||||||
|
embed_html: None,
|
||||||
|
thumbnail_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _updated_post = match Post::update(&conn, post.id, &post_form) {
|
let _updated_post = match Post::update(&conn, post.id, &post_form) {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_post"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_post").into()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(LoginResponse {
|
Ok(LoginResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
jwt: data.auth.to_owned(),
|
jwt: data.auth.to_owned(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<PasswordResetResponse> for Oper<PasswordReset> {
|
impl Perform<PasswordResetResponse> for Oper<PasswordReset> {
|
||||||
fn perform(&self) -> Result<PasswordResetResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<PasswordResetResponse, Error> {
|
||||||
let data: &PasswordReset = &self.data;
|
let data: &PasswordReset = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
// Fetch that email
|
// Fetch that email
|
||||||
let user: User_ = match User_::find_by_email(&conn, &data.email) {
|
let user: User_ = match User_::find_by_email(&conn, &data.email) {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => {
|
Err(_e) => return Err(APIError::err("couldnt_find_that_username_or_email").into()),
|
||||||
return Err(APIError::err(
|
|
||||||
&self.op,
|
|
||||||
"couldnt_find_that_username_or_email",
|
|
||||||
))?
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate a random token
|
// Generate a random token
|
||||||
|
@ -815,57 +926,186 @@ impl Perform<PasswordResetResponse> for Oper<PasswordReset> {
|
||||||
let html = &format!("<h1>Password Reset Request for {}</h1><br><a href={}/password_change/{}>Click here to reset your password</a>", user.name, hostname, &token);
|
let html = &format!("<h1>Password Reset Request for {}</h1><br><a href={}/password_change/{}>Click here to reset your password</a>", user.name, hostname, &token);
|
||||||
match send_email(subject, user_email, &user.name, html) {
|
match send_email(subject, user_email, &user.name, html) {
|
||||||
Ok(_o) => _o,
|
Ok(_o) => _o,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, &_e.to_string()))?,
|
Err(_e) => return Err(APIError::err(&_e).into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(PasswordResetResponse {
|
Ok(PasswordResetResponse {})
|
||||||
op: self.op.to_string(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Perform<LoginResponse> for Oper<PasswordChange> {
|
impl Perform<LoginResponse> for Oper<PasswordChange> {
|
||||||
fn perform(&self) -> Result<LoginResponse, Error> {
|
fn perform(&self, conn: &PgConnection) -> Result<LoginResponse, Error> {
|
||||||
let data: &PasswordChange = &self.data;
|
let data: &PasswordChange = &self.data;
|
||||||
let conn = establish_connection();
|
|
||||||
|
|
||||||
// Fetch the user_id from the token
|
// Fetch the user_id from the token
|
||||||
let user_id = PasswordResetRequest::read_from_token(&conn, &data.token)?.user_id;
|
let user_id = PasswordResetRequest::read_from_token(&conn, &data.token)?.user_id;
|
||||||
|
|
||||||
// Make sure passwords match
|
// Make sure passwords match
|
||||||
if &data.password != &data.password_verify {
|
if data.password != data.password_verify {
|
||||||
return Err(APIError::err(&self.op, "passwords_dont_match"))?;
|
return Err(APIError::err("passwords_dont_match").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the user
|
|
||||||
let read_user = User_::read(&conn, user_id)?;
|
|
||||||
|
|
||||||
// Update the user with the new password
|
// Update the user with the new password
|
||||||
let user_form = UserForm {
|
let updated_user = match User_::update_password(&conn, user_id, &data.password) {
|
||||||
name: read_user.name,
|
|
||||||
fedi_name: read_user.fedi_name,
|
|
||||||
email: read_user.email,
|
|
||||||
password_encrypted: data.password.to_owned(),
|
|
||||||
preferred_username: read_user.preferred_username,
|
|
||||||
updated: Some(naive_now()),
|
|
||||||
admin: read_user.admin,
|
|
||||||
banned: read_user.banned,
|
|
||||||
show_nsfw: read_user.show_nsfw,
|
|
||||||
theme: read_user.theme,
|
|
||||||
default_sort_type: read_user.default_sort_type,
|
|
||||||
default_listing_type: read_user.default_listing_type,
|
|
||||||
lang: read_user.lang,
|
|
||||||
};
|
|
||||||
|
|
||||||
let updated_user = match User_::update_password(&conn, user_id, &user_form) {
|
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_user"))?,
|
Err(_e) => return Err(APIError::err("couldnt_update_user").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(LoginResponse {
|
Ok(LoginResponse {
|
||||||
op: self.op.to_string(),
|
|
||||||
jwt: updated_user.jwt(),
|
jwt: updated_user.jwt(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Perform<PrivateMessageResponse> for Oper<CreatePrivateMessage> {
|
||||||
|
fn perform(&self, conn: &PgConnection) -> Result<PrivateMessageResponse, Error> {
|
||||||
|
let data: &CreatePrivateMessage = &self.data;
|
||||||
|
|
||||||
|
let claims = match Claims::decode(&data.auth) {
|
||||||
|
Ok(claims) => claims.claims,
|
||||||
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let user_id = claims.id;
|
||||||
|
|
||||||
|
let hostname = &format!("https://{}", Settings::get().hostname);
|
||||||
|
|
||||||
|
// Check for a site ban
|
||||||
|
if UserView::read(&conn, user_id)?.banned {
|
||||||
|
return Err(APIError::err("site_ban").into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let content_slurs_removed = remove_slurs(&data.content.to_owned());
|
||||||
|
|
||||||
|
let private_message_form = PrivateMessageForm {
|
||||||
|
content: Some(content_slurs_removed.to_owned()),
|
||||||
|
creator_id: user_id,
|
||||||
|
recipient_id: data.recipient_id,
|
||||||
|
deleted: None,
|
||||||
|
read: None,
|
||||||
|
updated: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let inserted_private_message = match PrivateMessage::create(&conn, &private_message_form) {
|
||||||
|
Ok(private_message) => private_message,
|
||||||
|
Err(_e) => {
|
||||||
|
return Err(APIError::err("couldnt_create_private_message").into());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send notifications to the recipient
|
||||||
|
let recipient_user = User_::read(&conn, data.recipient_id)?;
|
||||||
|
if recipient_user.send_notifications_to_email {
|
||||||
|
if let Some(email) = recipient_user.email {
|
||||||
|
let subject = &format!(
|
||||||
|
"{} - Private Message from {}",
|
||||||
|
Settings::get().hostname,
|
||||||
|
claims.username
|
||||||
|
);
|
||||||
|
let html = &format!(
|
||||||
|
"<h1>Private Message</h1><br><div>{} - {}</div><br><a href={}/inbox>inbox</a>",
|
||||||
|
claims.username, &content_slurs_removed, hostname
|
||||||
|
);
|
||||||
|
match send_email(subject, &email, &recipient_user.name, html) {
|
||||||
|
Ok(_o) => _o,
|
||||||
|
Err(e) => error!("{}", e),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let message = PrivateMessageView::read(&conn, inserted_private_message.id)?;
|
||||||
|
|
||||||
|
Ok(PrivateMessageResponse { message })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Perform<PrivateMessageResponse> for Oper<EditPrivateMessage> {
|
||||||
|
fn perform(&self, conn: &PgConnection) -> Result<PrivateMessageResponse, Error> {
|
||||||
|
let data: &EditPrivateMessage = &self.data;
|
||||||
|
|
||||||
|
let claims = match Claims::decode(&data.auth) {
|
||||||
|
Ok(claims) => claims.claims,
|
||||||
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let user_id = claims.id;
|
||||||
|
|
||||||
|
let orig_private_message = PrivateMessage::read(&conn, data.edit_id)?;
|
||||||
|
|
||||||
|
// Check for a site ban
|
||||||
|
if UserView::read(&conn, user_id)?.banned {
|
||||||
|
return Err(APIError::err("site_ban").into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check to make sure they are the creator (or the recipient marking as read
|
||||||
|
if !(data.read.is_some() && orig_private_message.recipient_id.eq(&user_id)
|
||||||
|
|| orig_private_message.creator_id.eq(&user_id))
|
||||||
|
{
|
||||||
|
return Err(APIError::err("no_private_message_edit_allowed").into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let content_slurs_removed = match &data.content {
|
||||||
|
Some(content) => Some(remove_slurs(content)),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let private_message_form = PrivateMessageForm {
|
||||||
|
content: content_slurs_removed,
|
||||||
|
creator_id: orig_private_message.creator_id,
|
||||||
|
recipient_id: orig_private_message.recipient_id,
|
||||||
|
deleted: data.deleted.to_owned(),
|
||||||
|
read: data.read.to_owned(),
|
||||||
|
updated: if data.read.is_some() {
|
||||||
|
orig_private_message.updated
|
||||||
|
} else {
|
||||||
|
Some(naive_now())
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let _updated_private_message =
|
||||||
|
match PrivateMessage::update(&conn, data.edit_id, &private_message_form) {
|
||||||
|
Ok(private_message) => private_message,
|
||||||
|
Err(_e) => return Err(APIError::err("couldnt_update_private_message").into()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let message = PrivateMessageView::read(&conn, data.edit_id)?;
|
||||||
|
|
||||||
|
Ok(PrivateMessageResponse { message })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Perform<PrivateMessagesResponse> for Oper<GetPrivateMessages> {
|
||||||
|
fn perform(&self, conn: &PgConnection) -> Result<PrivateMessagesResponse, Error> {
|
||||||
|
let data: &GetPrivateMessages = &self.data;
|
||||||
|
|
||||||
|
let claims = match Claims::decode(&data.auth) {
|
||||||
|
Ok(claims) => claims.claims,
|
||||||
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let user_id = claims.id;
|
||||||
|
|
||||||
|
let messages = PrivateMessageQueryBuilder::create(&conn, user_id)
|
||||||
|
.page(data.page)
|
||||||
|
.limit(data.limit)
|
||||||
|
.unread_only(data.unread_only)
|
||||||
|
.list()?;
|
||||||
|
|
||||||
|
Ok(PrivateMessagesResponse { messages })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Perform<UserJoinResponse> for Oper<UserJoin> {
|
||||||
|
fn perform(&self, _conn: &PgConnection) -> Result<UserJoinResponse, Error> {
|
||||||
|
let data: &UserJoin = &self.data;
|
||||||
|
|
||||||
|
let claims = match Claims::decode(&data.auth) {
|
||||||
|
Ok(claims) => claims.claims,
|
||||||
|
Err(_e) => return Err(APIError::err("not_logged_in").into()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let user_id = claims.id;
|
||||||
|
Ok(UserJoinResponse { user_id })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,90 +0,0 @@
|
||||||
extern crate activitypub;
|
|
||||||
use self::activitypub::{actor::Person, context};
|
|
||||||
use crate::db::user::User_;
|
|
||||||
|
|
||||||
impl User_ {
|
|
||||||
pub fn person(&self) -> Person {
|
|
||||||
use crate::{to_datetime_utc, Settings};
|
|
||||||
let base_url = &format!("{}/user/{}", Settings::get().api_endpoint(), self.name);
|
|
||||||
let mut person = Person::default();
|
|
||||||
person.object_props.set_context_object(context()).ok();
|
|
||||||
person.object_props.set_id_string(base_url.to_string()).ok();
|
|
||||||
person
|
|
||||||
.object_props
|
|
||||||
.set_name_string(self.name.to_owned())
|
|
||||||
.ok();
|
|
||||||
person
|
|
||||||
.object_props
|
|
||||||
.set_published_utctime(to_datetime_utc(self.published))
|
|
||||||
.ok();
|
|
||||||
if let Some(i) = self.updated {
|
|
||||||
person
|
|
||||||
.object_props
|
|
||||||
.set_updated_utctime(to_datetime_utc(i))
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
// person.object_props.summary = self.summary;
|
|
||||||
|
|
||||||
person
|
|
||||||
.ap_actor_props
|
|
||||||
.set_inbox_string(format!("{}/inbox", &base_url))
|
|
||||||
.ok();
|
|
||||||
person
|
|
||||||
.ap_actor_props
|
|
||||||
.set_outbox_string(format!("{}/outbox", &base_url))
|
|
||||||
.ok();
|
|
||||||
person
|
|
||||||
.ap_actor_props
|
|
||||||
.set_following_string(format!("{}/following", &base_url))
|
|
||||||
.ok();
|
|
||||||
person
|
|
||||||
.ap_actor_props
|
|
||||||
.set_liked_string(format!("{}/liked", &base_url))
|
|
||||||
.ok();
|
|
||||||
if let Some(i) = &self.preferred_username {
|
|
||||||
person
|
|
||||||
.ap_actor_props
|
|
||||||
.set_preferred_username_string(i.to_string())
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
person
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::User_;
|
|
||||||
use crate::db::{ListingType, SortType};
|
|
||||||
use crate::naive_now;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_person() {
|
|
||||||
let expected_user = User_ {
|
|
||||||
id: 52,
|
|
||||||
name: "thom".into(),
|
|
||||||
fedi_name: "rrf".into(),
|
|
||||||
preferred_username: None,
|
|
||||||
password_encrypted: "here".into(),
|
|
||||||
email: None,
|
|
||||||
icon: None,
|
|
||||||
published: naive_now(),
|
|
||||||
admin: false,
|
|
||||||
banned: false,
|
|
||||||
updated: None,
|
|
||||||
show_nsfw: false,
|
|
||||||
theme: "darkly".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let person = expected_user.person();
|
|
||||||
assert_eq!(
|
|
||||||
"rrr/api/v1/user/thom",
|
|
||||||
person.object_props.id_string().unwrap()
|
|
||||||
);
|
|
||||||
let json = serde_json::to_string_pretty(&person).unwrap();
|
|
||||||
println!("{}", json);
|
|
||||||
}
|
|
||||||
}
|
|
119
server/src/apub/community.rs
Normal file
119
server/src/apub/community.rs
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
use crate::apub::{create_apub_response, make_apub_endpoint, EndpointType};
|
||||||
|
use crate::convert_datetime;
|
||||||
|
use crate::db::community::Community;
|
||||||
|
use crate::db::community_view::CommunityFollowerView;
|
||||||
|
use crate::db::establish_unpooled_connection;
|
||||||
|
use crate::db::post_view::{PostQueryBuilder, PostView};
|
||||||
|
use activitystreams::collection::OrderedCollection;
|
||||||
|
use activitystreams::{
|
||||||
|
actor::{properties::ApActorProperties, Group},
|
||||||
|
collection::UnorderedCollection,
|
||||||
|
context,
|
||||||
|
ext::Extensible,
|
||||||
|
object::properties::ObjectProperties,
|
||||||
|
};
|
||||||
|
use actix_web::body::Body;
|
||||||
|
use actix_web::web::Path;
|
||||||
|
use actix_web::HttpResponse;
|
||||||
|
use actix_web::{web, Result};
|
||||||
|
use diesel::r2d2::{ConnectionManager, Pool};
|
||||||
|
use diesel::PgConnection;
|
||||||
|
use failure::Error;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct CommunityQuery {
|
||||||
|
community_name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_apub_community(
|
||||||
|
info: Path<CommunityQuery>,
|
||||||
|
db: web::Data<Pool<ConnectionManager<PgConnection>>>,
|
||||||
|
) -> Result<HttpResponse<Body>, Error> {
|
||||||
|
let community = Community::read_from_name(&&db.get()?, info.community_name.to_owned())?;
|
||||||
|
let base_url = make_apub_endpoint(EndpointType::Community, &community.name);
|
||||||
|
|
||||||
|
let mut group = Group::default();
|
||||||
|
let oprops: &mut ObjectProperties = group.as_mut();
|
||||||
|
|
||||||
|
oprops
|
||||||
|
.set_context_xsd_any_uri(context())?
|
||||||
|
.set_id(base_url.to_owned())?
|
||||||
|
.set_name_xsd_string(community.title.to_owned())?
|
||||||
|
.set_published(convert_datetime(community.published))?
|
||||||
|
.set_attributed_to_xsd_any_uri(make_apub_endpoint(
|
||||||
|
EndpointType::User,
|
||||||
|
&community.creator_id.to_string(),
|
||||||
|
))?;
|
||||||
|
|
||||||
|
if let Some(u) = community.updated.to_owned() {
|
||||||
|
oprops.set_updated(convert_datetime(u))?;
|
||||||
|
}
|
||||||
|
if let Some(d) = community.description {
|
||||||
|
oprops.set_summary_xsd_string(d)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut actor_props = ApActorProperties::default();
|
||||||
|
|
||||||
|
actor_props
|
||||||
|
.set_inbox(format!("{}/inbox", &base_url))?
|
||||||
|
.set_outbox(format!("{}/outbox", &base_url))?
|
||||||
|
.set_followers(format!("{}/followers", &base_url))?;
|
||||||
|
|
||||||
|
Ok(create_apub_response(&group.extend(actor_props)))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_apub_community_followers(
|
||||||
|
info: Path<CommunityQuery>,
|
||||||
|
db: web::Data<Pool<ConnectionManager<PgConnection>>>,
|
||||||
|
) -> Result<HttpResponse<Body>, Error> {
|
||||||
|
let community = Community::read_from_name(&&db.get()?, info.community_name.to_owned())?;
|
||||||
|
let base_url = make_apub_endpoint(EndpointType::Community, &community.name);
|
||||||
|
|
||||||
|
let connection = establish_unpooled_connection();
|
||||||
|
//As we are an object, we validated that the community id was valid
|
||||||
|
let community_followers =
|
||||||
|
CommunityFollowerView::for_community(&connection, community.id).unwrap();
|
||||||
|
|
||||||
|
let mut collection = UnorderedCollection::default();
|
||||||
|
let oprops: &mut ObjectProperties = collection.as_mut();
|
||||||
|
oprops
|
||||||
|
.set_context_xsd_any_uri(context())?
|
||||||
|
.set_id(base_url)?;
|
||||||
|
collection
|
||||||
|
.collection_props
|
||||||
|
.set_total_items(community_followers.len() as u64)?;
|
||||||
|
Ok(create_apub_response(&collection))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_apub_community_outbox(
|
||||||
|
info: Path<CommunityQuery>,
|
||||||
|
db: web::Data<Pool<ConnectionManager<PgConnection>>>,
|
||||||
|
) -> Result<HttpResponse<Body>, Error> {
|
||||||
|
let community = Community::read_from_name(&&db.get()?, info.community_name.to_owned())?;
|
||||||
|
let base_url = make_apub_endpoint(EndpointType::Community, &community.name);
|
||||||
|
|
||||||
|
let connection = establish_unpooled_connection();
|
||||||
|
//As we are an object, we validated that the community id was valid
|
||||||
|
let community_posts: Vec<PostView> = PostQueryBuilder::create(&connection)
|
||||||
|
.for_community_id(community.id)
|
||||||
|
.list()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut collection = OrderedCollection::default();
|
||||||
|
let oprops: &mut ObjectProperties = collection.as_mut();
|
||||||
|
oprops
|
||||||
|
.set_context_xsd_any_uri(context())?
|
||||||
|
.set_id(base_url)?;
|
||||||
|
collection
|
||||||
|
.collection_props
|
||||||
|
.set_many_items_object_boxs(
|
||||||
|
community_posts
|
||||||
|
.iter()
|
||||||
|
.map(|c| c.as_page().unwrap())
|
||||||
|
.collect(),
|
||||||
|
)?
|
||||||
|
.set_total_items(community_posts.len() as u64)?;
|
||||||
|
|
||||||
|
Ok(create_apub_response(&collection))
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue