mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-24 09:27:38 +00:00
Compare commits
154
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8967c43bb | ||
|
|
2b0b3669fc | ||
|
|
1ed620c524 | ||
|
|
2497a959c9 | ||
|
|
9e7d931416 | ||
|
|
cf573e4b8c | ||
|
|
6ae1d5a578 | ||
|
|
6a75755a65 | ||
|
|
e22fd7706e | ||
|
|
99b09e062b | ||
|
|
22a8b3e66d | ||
|
|
e8c9085839 | ||
|
|
f78362cab8 | ||
|
|
3356655f85 | ||
|
|
f2ec8ca672 | ||
|
|
76b06afa19 | ||
|
|
d4469af359 | ||
|
|
1c7bc292f9 | ||
|
|
9dd2911649 | ||
|
|
068196ac22 | ||
|
|
4c63baea0e | ||
|
|
b11e91c47a | ||
|
|
6b6243ba1d | ||
|
|
188d8b3a1b | ||
|
|
2887f340c9 | ||
|
|
7a8a07e55f | ||
|
|
638cc0e037 | ||
|
|
e79e0cbf9d | ||
|
|
bd1046cbbb | ||
|
|
e67b5fade2 | ||
|
|
6ec38cac03 | ||
|
|
5ebed3a650 | ||
|
|
8118a1b69c | ||
|
|
57eeee4b34 | ||
|
|
a3d9b8e1c9 | ||
|
|
2f0ceeefa2 | ||
|
|
adb00e4b81 | ||
|
|
8c4ac0eefb | ||
|
|
287b8b5fd9 | ||
|
|
a07822cf3a | ||
|
|
301ae16891 | ||
|
|
0143a4d479 | ||
|
|
83918e3531 | ||
|
|
5fabbfb6ec | ||
|
|
5c9675299e | ||
|
|
815bfa1ed4 | ||
|
|
2a34f40c06 | ||
|
|
ea3c90746d | ||
|
|
0a64abbb58 | ||
|
|
cda88eced0 | ||
|
|
35acbb10bf | ||
|
|
803bdb0cc3 | ||
|
|
12be07e15c | ||
|
|
8572f4c99b | ||
|
|
bed9098196 | ||
|
|
ad21c26bc2 | ||
|
|
ebcba065cf | ||
|
|
9958ad9ed8 | ||
|
|
3435524ec9 | ||
|
|
cf225f473f | ||
|
|
1d589ba8b5 | ||
|
|
4f3bcef52f | ||
|
|
f04d1b4924 | ||
|
|
63bb96648a | ||
|
|
cafe6ca318 | ||
|
|
9b448db40c | ||
|
|
56bbad650e | ||
|
|
d8bea25ed9 | ||
|
|
b4b343f057 | ||
|
|
03e4a8cc0d | ||
|
|
5a4bcfbd1e | ||
|
|
9a00e2c30e | ||
|
|
fa20cfa247 | ||
|
|
66072c9cf7 | ||
|
|
a75b805691 | ||
|
|
9f8209f9ef | ||
|
|
7c9ab2a4fe | ||
|
|
4b0278f569 | ||
|
|
31d2751f5c | ||
|
|
45b3158fce | ||
|
|
d1b0e3bda6 | ||
|
|
fbd7cbeb09 | ||
|
|
652597f696 | ||
|
|
481c4bb399 | ||
|
|
aaf0525c3b | ||
|
|
cacde94ffc | ||
|
|
3dbec51e8f | ||
|
|
c2b6af275f | ||
|
|
268ed38b43 | ||
|
|
b80b9a7950 | ||
|
|
c51acb7acb | ||
|
|
5110930add | ||
|
|
7250561aed | ||
|
|
d7434f7047 | ||
|
|
d5d0127ff4 | ||
|
|
ab1fc060a7 | ||
|
|
ddc9e795d8 | ||
|
|
87892a9739 | ||
|
|
3e2d454989 | ||
|
|
a79e7a01a8 | ||
|
|
b378cb8c5d | ||
|
|
68e31282ef | ||
|
|
f40e0c7773 | ||
|
|
fbb855a404 | ||
|
|
2325e8fa4c | ||
|
|
6906d63013 | ||
|
|
16de2a2cc0 | ||
|
|
108a4fe336 | ||
|
|
83396db5de | ||
|
|
839138c02e | ||
|
|
e03c90c2ac | ||
|
|
379ef5014c | ||
|
|
2ab177f100 | ||
|
|
a818f51396 | ||
|
|
09bfe79a44 | ||
|
|
d041adadc8 | ||
|
|
189ed1c394 | ||
|
|
36c32938ae | ||
|
|
915643c965 | ||
|
|
4063b2c7da | ||
|
|
943bd81ce9 | ||
|
|
2942d9133e | ||
|
|
18a7a85fe4 | ||
|
|
0fdb1be938 | ||
|
|
867a3ac376 | ||
|
|
7a6eff091a | ||
|
|
c278663f65 | ||
|
|
c822c945e7 | ||
|
|
6eb3dc1f9d | ||
|
|
789ec71b75 | ||
|
|
1cfa3ff10b | ||
|
|
02cf6b5695 | ||
|
|
4cc4893376 | ||
|
|
7643b64f60 | ||
|
|
3d9fd34012 | ||
|
|
630963d6e1 | ||
|
|
36da6f5bf3 | ||
|
|
462ef63945 | ||
|
|
46bcfe5605 | ||
|
|
16321cf467 | ||
|
|
4d59e07006 | ||
|
|
ec5f50c68e | ||
|
|
db1b08532e | ||
|
|
d8f67e3b46 | ||
|
|
2124fcf325 | ||
|
|
38b4065270 | ||
|
|
2e62ca93a8 | ||
|
|
b7a6c819b7 | ||
|
|
eccc878ee9 | ||
|
|
8b762cf2e6 | ||
|
|
1ce9ae2cbf | ||
|
|
6a3370005e | ||
|
|
675cfb964a | ||
|
|
09312791a7 |
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
dotenv_if_exists
|
dotenv_if_exists
|
||||||
|
|
||||||
if [ -f /etc/os-release ] && grep -q '^ID=nixos' /etc/os-release; then
|
if command -v nix >/dev/null 2>&1; then
|
||||||
use flake ".#${DIRENV_DEVSHELL:-default}"
|
use flake ".#${DIRENV_DEVSHELL:-default}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ runs:
|
|||||||
- name: Install sccache
|
- name: Install sccache
|
||||||
uses: https://git.tomfos.tr/tom/sccache-action@v1
|
uses: https://git.tomfos.tr/tom/sccache-action@v1
|
||||||
- name: Configure sccache
|
- name: Configure sccache
|
||||||
uses: https://github.com/actions/github-script@v8
|
uses: https://github.com/actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
|
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
|
||||||
|
|||||||
@@ -149,37 +149,6 @@ runs:
|
|||||||
- name: Setup sccache
|
- name: Setup sccache
|
||||||
uses: https://git.tomfos.tr/tom/sccache-action@v1
|
uses: https://git.tomfos.tr/tom/sccache-action@v1
|
||||||
|
|
||||||
- name: Cache dependencies
|
|
||||||
id: deps-cache
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
target/**/.fingerprint
|
|
||||||
target/**/deps
|
|
||||||
target/**/*.d
|
|
||||||
target/**/.cargo-lock
|
|
||||||
target/**/CACHEDIR.TAG
|
|
||||||
target/**/.rustc_info.json
|
|
||||||
/timelord/
|
|
||||||
# Dependencies cache - based on Cargo.lock, survives source code changes
|
|
||||||
key: >-
|
|
||||||
continuwuity-deps-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ steps.rust-setup.outputs.version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('rust-toolchain.toml', '**/Cargo.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
continuwuity-deps-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ steps.rust-setup.outputs.version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-
|
|
||||||
|
|
||||||
- name: Cache incremental compilation
|
|
||||||
id: incremental-cache
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
target/**/incremental
|
|
||||||
# Incremental cache - based on source code changes
|
|
||||||
key: >-
|
|
||||||
continuwuity-incremental-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ steps.rust-setup.outputs.version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('rust-toolchain.toml', '**/Cargo.lock') }}-${{ hashFiles('**/*.rs', '**/Cargo.toml') }}
|
|
||||||
restore-keys: |
|
|
||||||
continuwuity-incremental-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ steps.rust-setup.outputs.version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('rust-toolchain.toml', '**/Cargo.lock') }}-
|
|
||||||
continuwuity-incremental-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ steps.rust-setup.outputs.version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-
|
|
||||||
|
|
||||||
- name: End build cache restore group
|
- name: End build cache restore group
|
||||||
shell: bash
|
shell: bash
|
||||||
run: echo "::endgroup::"
|
run: echo "::endgroup::"
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Manage PR Comment
|
- name: Manage PR Comment
|
||||||
uses: https://github.com/actions/github-script@v8
|
uses: https://github.com/actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
|
||||||
env:
|
env:
|
||||||
HAS_CHANGELOG: ${{ steps.check_files.outputs.has_changelog }}
|
HAS_CHANGELOG: ${{ steps.check_files.outputs.has_changelog }}
|
||||||
SRC_CHANGED: ${{ steps.check_files.outputs.src_changed }}
|
SRC_CHANGED: ${{ steps.check_files.outputs.src_changed }}
|
||||||
|
|||||||
@@ -51,10 +51,8 @@ jobs:
|
|||||||
# owner: continuwuity
|
# owner: continuwuity
|
||||||
# repositories: continuwuity
|
# repositories: continuwuity
|
||||||
|
|
||||||
- name: Install regctl
|
- name: Install regsync
|
||||||
uses: https://forgejo.ellis.link/continuwuation/regclient-actions/regctl-installer@main
|
uses: https://github.com/regclient/actions/regsync-installer@main
|
||||||
with:
|
|
||||||
binary: regsync
|
|
||||||
|
|
||||||
- name: Check what images need mirroring
|
- name: Check what images need mirroring
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -16,48 +16,19 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
|
||||||
fetch-tags: false
|
|
||||||
fetch-single-branch: true
|
|
||||||
submodules: false
|
|
||||||
persist-credentials: true
|
persist-credentials: true
|
||||||
token: ${{ secrets.FORGEJO_TOKEN }}
|
token: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
|
|
||||||
- uses: https://github.com/cachix/install-nix-action@19effe9fe722874e6d46dd7182e4b8b7a43c4a99 # v31.10.0
|
- name: Install Lix
|
||||||
|
uses: https://github.com/samueldr/lix-gha-installer-action@f5e94192f565f53d84f41a056956dc0d3183b343
|
||||||
with:
|
with:
|
||||||
nix_path: nixpkgs=channel:nixos-unstable
|
extra_nix_config: experimental-features = nix-command flakes flake-self-attrs
|
||||||
|
|
||||||
# We can skip getting a toolchain hash if this was ran as a dispatch with the intent
|
|
||||||
# to update just the rocksdb hash. If this was ran as a dispatch and the toolchain
|
|
||||||
# files are changed, we still update them, as well as the rocksdb import.
|
|
||||||
- name: Detect changed files
|
|
||||||
id: changes
|
|
||||||
run: |
|
|
||||||
git fetch origin ${{ github.base_ref }} --depth=1 || true
|
|
||||||
if [ -n "${{ github.event.pull_request.base.sha }}" ]; then
|
|
||||||
base=${{ github.event.pull_request.base.sha }}
|
|
||||||
else
|
|
||||||
base=$(git rev-parse HEAD~1)
|
|
||||||
fi
|
|
||||||
echo "Base: $base"
|
|
||||||
echo "HEAD: $(git rev-parse HEAD)"
|
|
||||||
git diff --name-only $base HEAD > changed_files.txt
|
|
||||||
echo "detected changes in $(cat changed_files.txt)"
|
|
||||||
# Join files with commas
|
|
||||||
files=$(paste -sd, changed_files.txt)
|
|
||||||
echo "files=$files" >> $FORGEJO_OUTPUT
|
|
||||||
|
|
||||||
- name: Debug output
|
|
||||||
run: |
|
|
||||||
echo "State of output"
|
|
||||||
echo "Changed files: ${{ steps.changes.outputs.files }}"
|
|
||||||
|
|
||||||
- name: Get new toolchain hash
|
- name: Get new toolchain hash
|
||||||
if: contains(steps.changes.outputs.files, 'Cargo.toml') || contains(steps.changes.outputs.files, 'Cargo.lock') || contains(steps.changes.outputs.files, 'rust-toolchain.toml')
|
|
||||||
run: |
|
run: |
|
||||||
# Set the current sha256 to an empty hash to make `nix build` calculate a new one
|
# Set the current sha256 to an empty hash to make `nix build` calculate a new one
|
||||||
awk '/fromToolchainFile *\{/{found=1; print; next} found && /sha256 =/{sub(/sha256 = .*/, "sha256 = lib.fakeSha256;"); found=0} 1' nix/packages/rust.nix > temp.nix
|
awk '/fromToolchainFile *\{/{found=1; print; next} found && /sha256 =/{sub(/sha256 = .*/, "sha256 = lib.fakeSha256;"); found=0} 1' nix/rust.nix > temp.nix
|
||||||
mv temp.nix nix/packages/rust.nix
|
mv temp.nix nix/rust.nix
|
||||||
|
|
||||||
# Build continuwuity and filter for the new hash
|
# Build continuwuity and filter for the new hash
|
||||||
# We do `|| true` because we want this to fail without stopping the workflow
|
# We do `|| true` because we want this to fail without stopping the workflow
|
||||||
@@ -65,36 +36,17 @@ jobs:
|
|||||||
|
|
||||||
# Place the new hash in place of the empty hash
|
# Place the new hash in place of the empty hash
|
||||||
new_hash=$(cat new_toolchain_hash.txt)
|
new_hash=$(cat new_toolchain_hash.txt)
|
||||||
sed -i "s|lib.fakeSha256|\"$new_hash\"|" nix/packages/rust.nix
|
sed -i "s|lib.fakeSha256|\"$new_hash\"|" nix/rust.nix
|
||||||
|
|
||||||
echo "New hash:"
|
echo "New hash:"
|
||||||
awk -F'"' '/fromToolchainFile/{found=1; next} found && /sha256 =/{print $2; found=0}' nix/packages/rust.nix
|
awk -F'"' '/fromToolchainFile/{found=1; next} found && /sha256 =/{print $2; found=0}' nix/rust.nix
|
||||||
echo "Expected new hash:"
|
echo "Expected new hash:"
|
||||||
cat new_toolchain_hash.txt
|
cat new_toolchain_hash.txt
|
||||||
|
|
||||||
rm new_toolchain_hash.txt
|
rm new_toolchain_hash.txt
|
||||||
|
|
||||||
- name: Get new rocksdb hash
|
- name: Update rocksdb
|
||||||
if: contains(steps.changes.outputs.files, '.nix') || contains(steps.changes.outputs.files, 'flake.lock')
|
run: nix run .#update-rocksdb
|
||||||
run: |
|
|
||||||
# Set the current sha256 to an empty hash to make `nix build` calculate a new one
|
|
||||||
awk '/repo = "rocksdb";/{found=1; print; next} found && /sha256 =/{sub(/sha256 = .*/, "sha256 = lib.fakeSha256;"); found=0} 1' nix/packages/rocksdb/package.nix > temp.nix
|
|
||||||
mv temp.nix nix/packages/rocksdb/package.nix
|
|
||||||
|
|
||||||
# Build continuwuity and filter for the new hash
|
|
||||||
# We do `|| true` because we want this to fail without stopping the workflow
|
|
||||||
nix build .#default 2>&1 | tee >(grep 'got:' | awk '{print $2}' > new_rocksdb_hash.txt) || true
|
|
||||||
|
|
||||||
# Place the new hash in place of the empty hash
|
|
||||||
new_hash=$(cat new_rocksdb_hash.txt)
|
|
||||||
sed -i "s|lib.fakeSha256|\"$new_hash\"|" nix/packages/rocksdb/package.nix
|
|
||||||
|
|
||||||
echo "New hash:"
|
|
||||||
awk -F'"' '/repo = "rocksdb";/{found=1; next} found && /sha256 =/{print $2; found=0}' nix/packages/rocksdb/package.nix
|
|
||||||
echo "Expected new hash:"
|
|
||||||
cat new_rocksdb_hash.txt
|
|
||||||
|
|
||||||
rm new_rocksdb_hash.txt
|
|
||||||
|
|
||||||
- name: Show diff
|
- name: Show diff
|
||||||
run: git diff flake.nix nix
|
run: git diff flake.nix nix
|
||||||
|
|||||||
Generated
+333
-456
File diff suppressed because it is too large.
Load diff
+30
-28
@@ -39,7 +39,7 @@ features = ["ffi", "std", "union"]
|
|||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
|
||||||
[workspace.dependencies.ctor]
|
[workspace.dependencies.ctor]
|
||||||
version = "0.6.0"
|
version = "0.9.0"
|
||||||
|
|
||||||
[workspace.dependencies.cargo_toml]
|
[workspace.dependencies.cargo_toml]
|
||||||
version = "0.22"
|
version = "0.22"
|
||||||
@@ -47,9 +47,9 @@ default-features = false
|
|||||||
features = ["features"]
|
features = ["features"]
|
||||||
|
|
||||||
[workspace.dependencies.toml]
|
[workspace.dependencies.toml]
|
||||||
version = "0.9.5"
|
version = "1.0.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["parse"]
|
features = ["parse", "serde"]
|
||||||
|
|
||||||
[workspace.dependencies.sanitize-filename]
|
[workspace.dependencies.sanitize-filename]
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
@@ -68,7 +68,7 @@ default-features = false
|
|||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
|
|
||||||
[workspace.dependencies.rand]
|
[workspace.dependencies.rand]
|
||||||
version = "0.10.0"
|
version = "0.10.1"
|
||||||
|
|
||||||
# Used for the http request / response body type for Ruma endpoints used with reqwest
|
# Used for the http request / response body type for Ruma endpoints used with reqwest
|
||||||
[workspace.dependencies.bytes]
|
[workspace.dependencies.bytes]
|
||||||
@@ -159,7 +159,7 @@ features = ["raw_value"]
|
|||||||
|
|
||||||
# Used for appservice registration files
|
# Used for appservice registration files
|
||||||
[workspace.dependencies.serde-saphyr]
|
[workspace.dependencies.serde-saphyr]
|
||||||
version = "0.0.21"
|
version = "0.0.23"
|
||||||
|
|
||||||
# Used to load forbidden room/user regex from config
|
# Used to load forbidden room/user regex from config
|
||||||
[workspace.dependencies.serde_regex]
|
[workspace.dependencies.serde_regex]
|
||||||
@@ -167,7 +167,7 @@ version = "1.1.0"
|
|||||||
|
|
||||||
# Used for ruma wrapper
|
# Used for ruma wrapper
|
||||||
[workspace.dependencies.serde_html_form]
|
[workspace.dependencies.serde_html_form]
|
||||||
version = "0.2.6"
|
version = "0.4.0"
|
||||||
|
|
||||||
# Used for password hashing
|
# Used for password hashing
|
||||||
[workspace.dependencies.argon2]
|
[workspace.dependencies.argon2]
|
||||||
@@ -340,50 +340,48 @@ version = "0.1.88"
|
|||||||
[workspace.dependencies.lru-cache]
|
[workspace.dependencies.lru-cache]
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
|
|
||||||
|
[workspace.dependencies.assign]
|
||||||
|
version = "1.1.1"
|
||||||
|
|
||||||
# Used for matrix spec type definitions and helpers
|
# Used for matrix spec type definitions and helpers
|
||||||
[workspace.dependencies.ruma]
|
[workspace.dependencies.ruma]
|
||||||
git = "https://forgejo.ellis.link/continuwuation/ruwuma"
|
# version = "0.14.1"
|
||||||
#branch = "conduwuit-changes"
|
git = "https://github.com/gingershaped/ruwuma.git"
|
||||||
rev = "a97b91adcc012ef04991d823b8b5a79c6686ae48"
|
rev = "ce7ea072a3d47f1e674bb4badcb2af15b30e4088"
|
||||||
features = [
|
features = [
|
||||||
"compat",
|
|
||||||
"rand",
|
|
||||||
"appservice-api-c",
|
"appservice-api-c",
|
||||||
"client-api",
|
"client-api",
|
||||||
"federation-api",
|
"federation-api",
|
||||||
"markdown",
|
|
||||||
"push-gateway-api-c",
|
"push-gateway-api-c",
|
||||||
"unstable-exhaustive-types",
|
"state-res",
|
||||||
|
"rand",
|
||||||
|
"markdown",
|
||||||
"ring-compat",
|
"ring-compat",
|
||||||
"compat-upload-signatures",
|
"compat-upload-signatures",
|
||||||
"identifiers-validation",
|
|
||||||
"unstable-unspecified",
|
|
||||||
"unstable-msc2448",
|
"unstable-msc2448",
|
||||||
"unstable-msc2666",
|
"unstable-msc2666",
|
||||||
"unstable-msc2867",
|
"unstable-msc2867",
|
||||||
"unstable-msc2870",
|
"unstable-msc2870",
|
||||||
"unstable-msc3026",
|
|
||||||
"unstable-msc3061",
|
"unstable-msc3061",
|
||||||
"unstable-msc3814",
|
"unstable-msc3814",
|
||||||
"unstable-msc3245",
|
"unstable-msc3245",
|
||||||
"unstable-msc3266",
|
"unstable-msc3381",
|
||||||
"unstable-msc3381", # polls
|
"unstable-msc3489",
|
||||||
"unstable-msc3489", # beacon / live location
|
"unstable-msc3930",
|
||||||
"unstable-msc3575",
|
|
||||||
"unstable-msc3930", # polls push rules
|
|
||||||
"unstable-msc4075",
|
"unstable-msc4075",
|
||||||
"unstable-msc4095",
|
"unstable-msc4095",
|
||||||
"unstable-msc4121",
|
"unstable-msc4121",
|
||||||
"unstable-msc4125",
|
"unstable-msc4125",
|
||||||
"unstable-msc4155",
|
|
||||||
"unstable-msc4186",
|
"unstable-msc4186",
|
||||||
"unstable-msc4203", # sending to-device events to appservices
|
"unstable-msc4195",
|
||||||
"unstable-msc4210", # remove legacy mentions
|
"unstable-msc4203",
|
||||||
|
"unstable-msc4310",
|
||||||
|
"unstable-msc4373",
|
||||||
|
"unstable-msc4380",
|
||||||
|
"unstable-msc4143",
|
||||||
|
"unstable-msc4406",
|
||||||
|
"unstable-msc4439",
|
||||||
"unstable-extensible-events",
|
"unstable-extensible-events",
|
||||||
"unstable-pdu",
|
|
||||||
"unstable-msc4155",
|
|
||||||
"unstable-msc4143", # livekit well_known response
|
|
||||||
"unstable-msc4284"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.dependencies.rust-rocksdb]
|
[workspace.dependencies.rust-rocksdb]
|
||||||
@@ -656,6 +654,10 @@ default-features = false
|
|||||||
package = "conduwuit"
|
package = "conduwuit"
|
||||||
path = "src/main"
|
path = "src/main"
|
||||||
|
|
||||||
|
[workspace.dependencies.ruminuwuity]
|
||||||
|
package = "ruminuwuity"
|
||||||
|
path = "src/ruminuwuity"
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# Release profiles
|
# Release profiles
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Added support for requiring users to accept terms and conditions when registering.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Switched from Continuwuity's fork of Ruma back to upstream Ruma, unblocking exciting new features such as OAuth login. Contributed by @ginger.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Refactored nix package. Breaking, since `all-features` package no longer exists. Continuwuity is now built with jemalloc and liburing by default. Contributed by @Henry-Hiles (QuadRadical).
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Add new config option for [MSC4439](https://github.com/matrix-org/matrix-spec-proposals/pull/4439)
|
||||||
|
PGP key URIs. Contributed by LogN.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Fixed resolving IP of servers that only use SRV delegation. Contributed by @tulir.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Fixed compiler warning in cf_opts.rs when building in release. Contributed by @ezera.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Fixed "Sender must be a local user" error for make_join, make_knock, and make_leave federation routes. Contributed by @nex.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Added admin commands to get build information and features. Contributed by @Jade
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Fixed restricted joins not being signed when we are being used as an authorising server. Contributed by @nex, reported by [vel](matrix:u/vel:nhjkl.com?action=chat).
|
||||||
+17
-12
@@ -523,6 +523,18 @@
|
|||||||
#
|
#
|
||||||
#recaptcha_private_site_key =
|
#recaptcha_private_site_key =
|
||||||
|
|
||||||
|
# Policy documents, such as terms and conditions or a privacy policy,
|
||||||
|
# which users must agree to when registering an account.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# ```ignore
|
||||||
|
# [global.registration_terms.privacy_policy]
|
||||||
|
# en = { name = "Privacy Policy", url = "https://homeserver.example/en/privacy_policy.html" }
|
||||||
|
# es = { name = "Política de Privacidad", url = "https://homeserver.example/es/privacy_policy.html" }
|
||||||
|
# ```
|
||||||
|
#
|
||||||
|
#registration_terms = {}
|
||||||
|
|
||||||
# Controls whether encrypted rooms and events are allowed.
|
# Controls whether encrypted rooms and events are allowed.
|
||||||
#
|
#
|
||||||
#allow_encryption = true
|
#allow_encryption = true
|
||||||
@@ -561,18 +573,6 @@
|
|||||||
#
|
#
|
||||||
#allow_public_room_directory_over_federation = false
|
#allow_public_room_directory_over_federation = false
|
||||||
|
|
||||||
# Allow guests/unauthenticated users to access TURN credentials.
|
|
||||||
#
|
|
||||||
# This is the equivalent of Synapse's `turn_allow_guests` config option.
|
|
||||||
# This allows any unauthenticated user to call the endpoint
|
|
||||||
# `/_matrix/client/v3/voip/turnServer`.
|
|
||||||
#
|
|
||||||
# It is unlikely you need to enable this as all major clients support
|
|
||||||
# authentication for this endpoint and prevents misuse of your TURN server
|
|
||||||
# from potential bots.
|
|
||||||
#
|
|
||||||
#turn_allow_guests = false
|
|
||||||
|
|
||||||
# Set this to true to lock down your server's public room directory and
|
# Set this to true to lock down your server's public room directory and
|
||||||
# only allow admins to publish rooms to the room directory. Unpublishing
|
# only allow admins to publish rooms to the room directory. Unpublishing
|
||||||
# is still allowed by all users with this enabled.
|
# is still allowed by all users with this enabled.
|
||||||
@@ -1869,6 +1869,11 @@
|
|||||||
#
|
#
|
||||||
#support_mxid =
|
#support_mxid =
|
||||||
|
|
||||||
|
# PGP key URI for server support contacts, to be served as part of the
|
||||||
|
# MSC1929 server support endpoint.
|
||||||
|
#
|
||||||
|
#support_pgp_key =
|
||||||
|
|
||||||
# **DEPRECATED**: Use `[global.matrix_rtc].foci` instead.
|
# **DEPRECATED**: Use `[global.matrix_rtc].foci` instead.
|
||||||
#
|
#
|
||||||
# A list of MatrixRTC foci URLs which will be served as part of the
|
# A list of MatrixRTC foci URLs which will be served as part of the
|
||||||
|
|||||||
+3
-3
@@ -15,13 +15,13 @@ ARG LLVM_VERSION=21
|
|||||||
|
|
||||||
# Install repo tools
|
# Install repo tools
|
||||||
# Line one: compiler tools
|
# Line one: compiler tools
|
||||||
# Line two: curl, for downloading binaries
|
# Line two: curl, for downloading binaries and wget because llvm.sh is broken with curl
|
||||||
# Line three: for xx-verify
|
# Line three: for xx-verify
|
||||||
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||||
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||||
apt-get update && apt-get install -y \
|
apt-get update && apt-get install -y \
|
||||||
pkg-config make jq \
|
pkg-config make jq \
|
||||||
curl git software-properties-common \
|
wget curl git software-properties-common \
|
||||||
file
|
file
|
||||||
|
|
||||||
# LLVM packages
|
# LLVM packages
|
||||||
@@ -48,7 +48,7 @@ EOF
|
|||||||
|
|
||||||
# Developer tool versions
|
# Developer tool versions
|
||||||
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
|
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
|
||||||
ENV BINSTALL_VERSION=1.17.8
|
ENV BINSTALL_VERSION=1.17.9
|
||||||
# renovate: datasource=github-releases depName=psastras/sbom-rs
|
# renovate: datasource=github-releases depName=psastras/sbom-rs
|
||||||
ENV CARGO_SBOM_VERSION=0.9.1
|
ENV CARGO_SBOM_VERSION=0.9.1
|
||||||
# renovate: datasource=crate depName=lddtree
|
# renovate: datasource=crate depName=lddtree
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ RUN --mount=type=cache,target=/etc/apk/cache apk add \
|
|||||||
|
|
||||||
# Developer tool versions
|
# Developer tool versions
|
||||||
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
|
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
|
||||||
ENV BINSTALL_VERSION=1.17.8
|
ENV BINSTALL_VERSION=1.17.9
|
||||||
# renovate: datasource=github-releases depName=psastras/sbom-rs
|
# renovate: datasource=github-releases depName=psastras/sbom-rs
|
||||||
ENV CARGO_SBOM_VERSION=0.9.1
|
ENV CARGO_SBOM_VERSION=0.9.1
|
||||||
# renovate: datasource=crate depName=lddtree
|
# renovate: datasource=crate depName=lddtree
|
||||||
|
|||||||
+34
-26
@@ -14,6 +14,7 @@ Download the binary for your architecture (x86_64 or aarch64) -
|
|||||||
run the `uname -m` to check which you need.
|
run the `uname -m` to check which you need.
|
||||||
|
|
||||||
Prebuilt binaries are available from:
|
Prebuilt binaries are available from:
|
||||||
|
|
||||||
- **Tagged releases**: [Latest release page](https://forgejo.ellis.link/continuwuation/continuwuity/releases/latest)
|
- **Tagged releases**: [Latest release page](https://forgejo.ellis.link/continuwuation/continuwuity/releases/latest)
|
||||||
- **Development builds**: CI artifacts from the `main` branch
|
- **Development builds**: CI artifacts from the `main` branch
|
||||||
(includes Debian/Ubuntu packages)
|
(includes Debian/Ubuntu packages)
|
||||||
@@ -42,32 +43,36 @@ build profile with
|
|||||||
[link-time optimisation (LTO)](https://doc.rust-lang.org/cargo/reference/profiles.html#lto)
|
[link-time optimisation (LTO)](https://doc.rust-lang.org/cargo/reference/profiles.html#lto)
|
||||||
and, for amd64, target the haswell CPU architecture.
|
and, for amd64, target the haswell CPU architecture.
|
||||||
|
|
||||||
|
### Nix
|
||||||
|
|
||||||
|
Theres a Nix package defined in our flake, available for Linux and MacOS. Add continuwuity as an input to your flake, and use `inputs.continuwuity.packages.${system}.default` to get a working Continuwuity package.
|
||||||
|
|
||||||
|
If you simply wish to generate a binary using Nix, you can run `nix build git+https://forgejo.ellis.link/continuwuation/continuwuity` to generate a binary in `result/bin/conduwuit`.
|
||||||
|
|
||||||
### Compiling
|
### Compiling
|
||||||
|
|
||||||
Alternatively, you may compile the binary yourself.
|
Alternatively, you may compile the binary yourself.
|
||||||
|
|
||||||
### Building with the Rust toolchain
|
#### Using Docker
|
||||||
|
|
||||||
If wanting to build using standard Rust toolchains, make sure you install:
|
If you would like to build using docker, you can run the command `docker build -f ./docker/Dockerfile -t forgejo.ellis.link/continuwuation/continuwuity:main .` to compile continuwuity.
|
||||||
|
|
||||||
- (On linux) `liburing-dev` on the compiling machine, and `liburing` on the target host
|
#### Manual
|
||||||
- (On linux) `pkg-config` on the compiling machine to allow finding `liburing`
|
|
||||||
- A C++ compiler and (on linux) `libclang` for RocksDB
|
##### Dependencies
|
||||||
|
|
||||||
|
- Run `nix develop` to get a devshell with everything you need
|
||||||
|
- Or, install the following:
|
||||||
|
- (On linux) `liburing-dev` on the compiling machine, and `liburing` on the target host
|
||||||
|
- (On linux) `pkg-config` on the compiling machine to allow finding `liburing`
|
||||||
|
- A C++ compiler and (on linux) `libclang` for RocksDB
|
||||||
|
|
||||||
|
##### Build
|
||||||
|
|
||||||
You can build Continuwuity using `cargo build --release`.
|
You can build Continuwuity using `cargo build --release`.
|
||||||
|
|
||||||
Continuwuity supports various optional features that can be enabled during compilation. Please see the Cargo.toml file for a comprehensive list, or ask in our rooms.
|
Continuwuity supports various optional features that can be enabled during compilation. Please see the Cargo.toml file for a comprehensive list, or ask in our rooms.
|
||||||
|
|
||||||
### Building with Nix
|
|
||||||
|
|
||||||
If you prefer, you can use Nix (or [Lix](https://lix.systems)) to build Continuwuity. This provides improved reproducibility and makes it easy to set up a build environment and generate output. This approach also allows for easy cross-compilation.
|
|
||||||
|
|
||||||
You can run the `nix build -L .#static-x86_64-linux-musl-all-features` or
|
|
||||||
`nix build -L .#static-aarch64-linux-musl-all-features` commands based
|
|
||||||
on architecture to cross-compile the necessary static binary located at
|
|
||||||
`result/bin/conduwuit`. This is reproducible with the static binaries produced
|
|
||||||
in our CI.
|
|
||||||
|
|
||||||
## Adding a Continuwuity user
|
## Adding a Continuwuity user
|
||||||
|
|
||||||
While Continuwuity can run as any user, it is better to use dedicated users for
|
While Continuwuity can run as any user, it is better to use dedicated users for
|
||||||
@@ -128,13 +133,11 @@ and entering the following:
|
|||||||
ReadWritePaths=/path/to/custom/database/path
|
ReadWritePaths=/path/to/custom/database/path
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Example systemd Unit File
|
### Example systemd Unit File
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Click to expand systemd unit file (conduwuit.service)</summary>
|
<summary>Click to expand systemd unit file (conduwuit.service)</summary>
|
||||||
|
|
||||||
|
|
||||||
```ini file="../../pkg/conduwuit.service"
|
```ini file="../../pkg/conduwuit.service"
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -202,23 +205,27 @@ sudo systemctl enable --now caddy
|
|||||||
As we prefer our users to use Caddy, we do not provide configuration files for other proxies.
|
As we prefer our users to use Caddy, we do not provide configuration files for other proxies.
|
||||||
|
|
||||||
You will need to reverse proxy everything under the following routes:
|
You will need to reverse proxy everything under the following routes:
|
||||||
|
|
||||||
- `/_matrix/` - core Matrix C-S and S-S APIs
|
- `/_matrix/` - core Matrix C-S and S-S APIs
|
||||||
- `/_conduwuit/` and/or `/_continuwuity/` - ad-hoc Continuwuity routes such as `/local_user_count` and
|
- `/_conduwuit/` and/or `/_continuwuity/` - ad-hoc Continuwuity routes such as `/local_user_count` and
|
||||||
`/server_version`
|
`/server_version`
|
||||||
|
|
||||||
You can optionally reverse proxy the following individual routes:
|
You can optionally reverse proxy the following individual routes:
|
||||||
|
|
||||||
- `/.well-known/matrix/client` and `/.well-known/matrix/server` if using
|
- `/.well-known/matrix/client` and `/.well-known/matrix/server` if using
|
||||||
Continuwuity to perform delegation (see the `[global.well_known]` config section)
|
Continuwuity to perform delegation (see the `[global.well_known]` config section)
|
||||||
- `/.well-known/matrix/support` if using Continuwuity to send the homeserver admin
|
- `/.well-known/matrix/support` if using Continuwuity to send the homeserver admin
|
||||||
contact and support page (formerly known as MSC1929)
|
contact and support page (formerly known as MSC1929)
|
||||||
- `/` if you would like to see `hewwo from conduwuit woof!` at the root
|
- `/` if you would like to see `hewwo from conduwuit woof!` at the root
|
||||||
|
|
||||||
See the following spec pages for more details on these files:
|
See the following spec pages for more details on these files:
|
||||||
|
|
||||||
- [`/.well-known/matrix/server`](https://spec.matrix.org/latest/client-server-api/#getwell-knownmatrixserver)
|
- [`/.well-known/matrix/server`](https://spec.matrix.org/latest/client-server-api/#getwell-knownmatrixserver)
|
||||||
- [`/.well-known/matrix/client`](https://spec.matrix.org/latest/client-server-api/#getwell-knownmatrixclient)
|
- [`/.well-known/matrix/client`](https://spec.matrix.org/latest/client-server-api/#getwell-knownmatrixclient)
|
||||||
- [`/.well-known/matrix/support`](https://spec.matrix.org/latest/client-server-api/#getwell-knownmatrixsupport)
|
- [`/.well-known/matrix/support`](https://spec.matrix.org/latest/client-server-api/#getwell-knownmatrixsupport)
|
||||||
|
|
||||||
Examples of delegation:
|
Examples of delegation:
|
||||||
|
|
||||||
- https://continuwuity.org/.well-known/matrix/server
|
- https://continuwuity.org/.well-known/matrix/server
|
||||||
- https://continuwuity.org/.well-known/matrix/client
|
- https://continuwuity.org/.well-known/matrix/client
|
||||||
- https://ellis.link/.well-known/matrix/server
|
- https://ellis.link/.well-known/matrix/server
|
||||||
@@ -232,6 +239,7 @@ header, making federation non-functional. If you find a workaround, please share
|
|||||||
If using Apache, you need to use `nocanon` in your `ProxyPass` directive to prevent httpd from interfering with the `X-Matrix` header (note that Apache is not ideal as a general reverse proxy, so we discourage using it if alternatives are available).
|
If using Apache, you need to use `nocanon` in your `ProxyPass` directive to prevent httpd from interfering with the `X-Matrix` header (note that Apache is not ideal as a general reverse proxy, so we discourage using it if alternatives are available).
|
||||||
|
|
||||||
If using Nginx, you need to pass the request URI to Continuwuity using `$request_uri`, like this:
|
If using Nginx, you need to pass the request URI to Continuwuity using `$request_uri`, like this:
|
||||||
|
|
||||||
- `proxy_pass http://127.0.0.1:6167$request_uri;`
|
- `proxy_pass http://127.0.0.1:6167$request_uri;`
|
||||||
- `proxy_pass http://127.0.0.1:6167;`
|
- `proxy_pass http://127.0.0.1:6167;`
|
||||||
|
|
||||||
@@ -271,17 +279,17 @@ curl https://your.server.name:8448/_matrix/federation/v1/version
|
|||||||
```
|
```
|
||||||
|
|
||||||
- To check if your server can communicate with other homeservers, use the
|
- To check if your server can communicate with other homeservers, use the
|
||||||
[Matrix Federation Tester](https://federationtester.mtrnord.blog/). If you can
|
[Matrix Federation Tester](https://federationtester.mtrnord.blog/). If you can
|
||||||
register but cannot join federated rooms, check your configuration and verify
|
register but cannot join federated rooms, check your configuration and verify
|
||||||
that port 8448 is open and forwarded correctly.
|
that port 8448 is open and forwarded correctly.
|
||||||
|
|
||||||
# What's next?
|
## What's next?
|
||||||
|
|
||||||
## Audio/Video calls
|
### Audio/Video calls
|
||||||
|
|
||||||
For Audio/Video call functionality see the [Calls](../calls.md) page.
|
For Audio/Video call functionality see the [Calls](../calls.md) page.
|
||||||
|
|
||||||
## Appservices
|
### Appservices
|
||||||
|
|
||||||
If you want to set up an appservice, take a look at the [Appservice
|
If you want to set up an appservice, take a look at the [Appservice
|
||||||
Guide](../appservices.md).
|
Guide](../appservices.md).
|
||||||
+37
-93
@@ -1,40 +1,40 @@
|
|||||||
# Continuwuity for NixOS
|
# Continuwuity for NixOS
|
||||||
|
|
||||||
NixOS packages Continuwuity as `matrix-continuwuity`. This package includes both the Continuwuity software and a dedicated NixOS module for configuration and deployment.
|
## Nix package
|
||||||
|
|
||||||
## Installation methods
|
You can get a Nix package for Continuwuity from the following sources:
|
||||||
|
|
||||||
You can acquire Continuwuity with Nix (or [Lix][lix]) from these sources:
|
- Directly from Nixpkgs: `pkgs.matrix-continuwuity`
|
||||||
|
- Or, using `continuwuity.packages.${system}.default` from:
|
||||||
|
- The `flake.nix` at the root of the Continuwuity repo, by adding Continuwuity to your flake inputs:
|
||||||
|
|
||||||
* Directly from Nixpkgs using the official package (`pkgs.matrix-continuwuity`)
|
```nix
|
||||||
* The `flake.nix` at the root of the Continuwuity repo
|
inputs.continuwuity.url = "git+https://forgejo.ellis.link/continuwuation/continuwuity";
|
||||||
* The `default.nix` at the root of the Continuwuity repo
|
```
|
||||||
|
|
||||||
|
- The `default.nix` at the root of the Continuwuity repo
|
||||||
|
|
||||||
## NixOS module
|
## NixOS module
|
||||||
|
|
||||||
Continuwuity now has an official NixOS module that simplifies configuration and deployment. The module is available in Nixpkgs as `services.matrix-continuwuity` from NixOS 25.05.
|
Continuwuity has an official NixOS module that simplifies configuration and deployment. The module is available in Nixpkgs as `services.matrix-continuwuity`.
|
||||||
|
|
||||||
Here's a basic example of how to use the module:
|
Here's a basic example of how to use the module:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{ config, pkgs, ... }:
|
services.matrix-continuwuity = {
|
||||||
|
enable = true;
|
||||||
|
settings = {
|
||||||
|
global = {
|
||||||
|
server_name = "example.com";
|
||||||
|
|
||||||
{
|
# Continuwuity listens on localhost by default,
|
||||||
services.matrix-continuwuity = {
|
# address and port are handled automatically
|
||||||
enable = true;
|
|
||||||
settings = {
|
# You can add any further configuration here, e.g.
|
||||||
global = {
|
# trusted_servers = [ "matrix.org" ];
|
||||||
server_name = "example.com";
|
|
||||||
# Listening on localhost by default
|
|
||||||
# address and port are handled automatically
|
|
||||||
allow_registration = false;
|
|
||||||
allow_encryption = true;
|
|
||||||
allow_federation = true;
|
|
||||||
trusted_servers = [ "matrix.org" ];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
### Available options
|
### Available options
|
||||||
@@ -45,86 +45,30 @@ The NixOS module provides these configuration options:
|
|||||||
- `user`: The user to run Continuwuity as (defaults to "continuwuity")
|
- `user`: The user to run Continuwuity as (defaults to "continuwuity")
|
||||||
- `group`: The group to run Continuwuity as (defaults to "continuwuity")
|
- `group`: The group to run Continuwuity as (defaults to "continuwuity")
|
||||||
- `extraEnvironment`: Extra environment variables to pass to the Continuwuity server
|
- `extraEnvironment`: Extra environment variables to pass to the Continuwuity server
|
||||||
- `package`: The Continuwuity package to use
|
- `package`: The Continuwuity package to use, defaults to `pkgs.matrix-continuwuity`
|
||||||
- `settings`: The Continuwuity configuration (in TOML format)
|
- You may want to override this to be from our flake, for faster updates and unstable versions:
|
||||||
|
```nix
|
||||||
|
package = inputs.continuwuity.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
||||||
|
```
|
||||||
|
- `admin.enable`: Whether to add the `conduwuit` binary to `PATH` for administration (enabled by default)
|
||||||
|
- `settings`: The Continuwuity configuration
|
||||||
|
|
||||||
Use the `settings` option to configure Continuwuity itself. See the [example configuration file](../reference/config.mdx) for all available options.
|
Use the `settings` option to configure Continuwuity itself. See the [example configuration file](../reference/config.mdx) for all available options.
|
||||||
|
|
||||||
### UNIX sockets
|
Settings are automatically translated from Nix to TOML. For example, the following line of Nix:
|
||||||
|
|
||||||
The NixOS module natively supports UNIX sockets through the `global.unix_socket_path` option. When using UNIX sockets, set `global.address` to `null`:
|
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
services.matrix-continuwuity = {
|
settings.global.well_known.client = "https://matrix.example.com";
|
||||||
enable = true;
|
|
||||||
settings = {
|
|
||||||
global = {
|
|
||||||
server_name = "example.com";
|
|
||||||
address = null; # Must be null when using unix_socket_path
|
|
||||||
unix_socket_path = "/run/continuwuity/continuwuity.sock";
|
|
||||||
unix_socket_perms = 660; # Default permissions for the socket
|
|
||||||
# ...
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The module automatically sets the correct `RestrictAddressFamilies` in the systemd service configuration to allow access to UNIX sockets.
|
Would become this equivalent TOML configuration:
|
||||||
|
|
||||||
### RocksDB database
|
```toml
|
||||||
|
[global.well_known]
|
||||||
Continuwuity exclusively uses RocksDB as its database backend. The system configures the database path automatically to `/var/lib/continuwuity/` and you cannot change it due to the service's reliance on systemd's StateDir.
|
client = "https://matrix.example.com"
|
||||||
|
|
||||||
If you're migrating from Conduit with SQLite, use this [tool to migrate a Conduit SQLite database to RocksDB](https://github.com/ShadowJonathan/conduit_toolbox/).
|
|
||||||
|
|
||||||
### jemalloc and hardened profile
|
|
||||||
|
|
||||||
Continuwuity uses jemalloc by default. This may interfere with the [`hardened.nix` profile][hardened.nix] because it uses `scudo` by default. Either disable/hide `scudo` from Continuwuity or disable jemalloc like this:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
services.matrix-continuwuity = {
|
|
||||||
enable = true;
|
|
||||||
package = pkgs.matrix-continuwuity.override {
|
|
||||||
enableJemalloc = false;
|
|
||||||
};
|
|
||||||
# ...
|
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Upgrading from Conduit
|
|
||||||
|
|
||||||
If you previously used Conduit with the `services.matrix-conduit` module:
|
|
||||||
|
|
||||||
1. Ensure your Conduit uses the RocksDB backend, or migrate from SQLite using the [migration tool](https://github.com/ShadowJonathan/conduit_toolbox/)
|
|
||||||
2. Switch to the new module by changing `services.matrix-conduit` to `services.matrix-continuwuity` in your configuration
|
|
||||||
3. Update any custom configuration to match the new module's structure
|
|
||||||
|
|
||||||
## Reverse proxy configuration
|
## Reverse proxy configuration
|
||||||
|
|
||||||
You'll need to set up a reverse proxy (like nginx or caddy) to expose Continuwuity to the internet. Configure your reverse proxy to forward requests to `/_matrix` on port 443 and 8448 to your Continuwuity instance.
|
You'll need to set up a reverse proxy (like NGINX or Caddy) to expose Continuwuity to the internet. You can configure your reverse proxy using NixOS options (e.g. `services.caddy`).
|
||||||
|
See the [reverse proxy setup guide](./generic.mdx#setting-up-the-reverse-proxy) for information on correct reverse proxy configuration.
|
||||||
Here's an example nginx configuration:
|
|
||||||
|
|
||||||
```nginx
|
|
||||||
server {
|
|
||||||
listen 443 ssl;
|
|
||||||
listen [::]:443 ssl;
|
|
||||||
listen 8448 ssl;
|
|
||||||
listen [::]:8448 ssl;
|
|
||||||
|
|
||||||
server_name example.com;
|
|
||||||
|
|
||||||
# SSL configuration here...
|
|
||||||
|
|
||||||
location /_matrix/ {
|
|
||||||
proxy_pass http://127.0.0.1:6167$request_uri;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
[lix]: https://lix.systems/
|
|
||||||
[hardened.nix]: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/profiles/hardened.nix
|
|
||||||
@@ -133,6 +133,18 @@ pusher service
|
|||||||
|
|
||||||
Returns all the pushers for the user
|
Returns all the pushers for the user
|
||||||
|
|
||||||
|
### `!admin query pusher delete-pusher`
|
||||||
|
|
||||||
|
Deletes a specific pusher by ID
|
||||||
|
|
||||||
|
### `!admin query pusher delete-all-user`
|
||||||
|
|
||||||
|
Deletes all pushers for a user
|
||||||
|
|
||||||
|
### `!admin query pusher delete-all-device`
|
||||||
|
|
||||||
|
Deletes all pushers associated with a device ID
|
||||||
|
|
||||||
## `!admin query short`
|
## `!admin query short`
|
||||||
|
|
||||||
short service
|
short service
|
||||||
|
|||||||
@@ -47,3 +47,11 @@ Restart the server
|
|||||||
## `!admin server shutdown`
|
## `!admin server shutdown`
|
||||||
|
|
||||||
Shutdown the server
|
Shutdown the server
|
||||||
|
|
||||||
|
## `!admin server list-features`
|
||||||
|
|
||||||
|
List features built into the server
|
||||||
|
|
||||||
|
## `!admin server build-info`
|
||||||
|
|
||||||
|
Build information
|
||||||
@@ -157,3 +157,7 @@ Force joins all local users to the specified room.
|
|||||||
At least 1 server admin must be in the room to reduce abuse.
|
At least 1 server admin must be in the room to reduce abuse.
|
||||||
|
|
||||||
Requires the `--yes-i-want-to-do-this` flag.
|
Requires the `--yes-i-want-to-do-this` flag.
|
||||||
|
|
||||||
|
## `!admin users reset-push-rules`
|
||||||
|
|
||||||
|
Resets the push-rules (notification settings) of the target user to the server defaults
|
||||||
Generated
+24
-24
@@ -3,11 +3,11 @@
|
|||||||
"advisory-db": {
|
"advisory-db": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1773786698,
|
"lastModified": 1775907537,
|
||||||
"narHash": "sha256-o/J7ZculgwSs1L4H4UFlFZENOXTJzq1X0n71x6oNNvY=",
|
"narHash": "sha256-vbeLNgmsx1Z6TwnlDV0dKyeBCcon3UpkV9yLr/yc6HM=",
|
||||||
"owner": "rustsec",
|
"owner": "rustsec",
|
||||||
"repo": "advisory-db",
|
"repo": "advisory-db",
|
||||||
"rev": "99e9de91bb8b61f06ef234ff84e11f758ecd5384",
|
"rev": "d99f7b9eb81731bddebf80a355f8be7b2f8b1b28",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -18,11 +18,11 @@
|
|||||||
},
|
},
|
||||||
"crane": {
|
"crane": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1773189535,
|
"lastModified": 1775839657,
|
||||||
"narHash": "sha256-E1G/Or6MWeP+L6mpQ0iTFLpzSzlpGrITfU2220Gq47g=",
|
"narHash": "sha256-SPm9ck7jh3Un9nwPuMGbRU04UroFmOHjLP56T10MOeM=",
|
||||||
"owner": "ipetkov",
|
"owner": "ipetkov",
|
||||||
"repo": "crane",
|
"repo": "crane",
|
||||||
"rev": "6fa2fb4cf4a89ba49fc9dd5a3eb6cde99d388269",
|
"rev": "7cf72d978629469c4bd4206b95c402514c1f6000",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -39,11 +39,11 @@
|
|||||||
"rust-analyzer-src": "rust-analyzer-src"
|
"rust-analyzer-src": "rust-analyzer-src"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1773732206,
|
"lastModified": 1775891769,
|
||||||
"narHash": "sha256-HKibxaUXyWd4Hs+ZUnwo6XslvaFqFqJh66uL9tphU4Q=",
|
"narHash": "sha256-EOfVlTKw2n8w1uhfh46GS4hEGnQ7oWrIWQfIY6utIkI=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "fenix",
|
"repo": "fenix",
|
||||||
"rev": "0aa13c1b54063a8d8679b28a5cd357ba98f4a56b",
|
"rev": "6fbc54dde15aee725bdc7aae5e478849685d5f56",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -74,11 +74,11 @@
|
|||||||
"nixpkgs-lib": "nixpkgs-lib"
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1772408722,
|
"lastModified": 1775087534,
|
||||||
"narHash": "sha256-rHuJtdcOjK7rAHpHphUb1iCvgkU3GpfvicLMwwnfMT0=",
|
"narHash": "sha256-91qqW8lhL7TLwgQWijoGBbiD4t7/q75KTi8NxjVmSmA=",
|
||||||
"owner": "hercules-ci",
|
"owner": "hercules-ci",
|
||||||
"repo": "flake-parts",
|
"repo": "flake-parts",
|
||||||
"rev": "f20dc5d9b8027381c474144ecabc9034d6a839a3",
|
"rev": "3107b77cd68437b9a76194f0f7f9c55f2329ca5b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -89,11 +89,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1773734432,
|
"lastModified": 1775710090,
|
||||||
"narHash": "sha256-IF5ppUWh6gHGHYDbtVUyhwy/i7D261P7fWD1bPefOsw=",
|
"narHash": "sha256-ar3rofg+awPB8QXDaFJhJ2jJhu+KqN/PRCXeyuXR76E=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "cda48547b432e8d3b18b4180ba07473762ec8558",
|
"rev": "4c1018dae018162ec878d42fec712642d214fdfa",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -105,11 +105,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs-lib": {
|
"nixpkgs-lib": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1772328832,
|
"lastModified": 1774748309,
|
||||||
"narHash": "sha256-e+/T/pmEkLP6BHhYjx6GmwP5ivonQQn0bJdH9YrRB+Q=",
|
"narHash": "sha256-+U7gF3qxzwD5TZuANzZPeJTZRHS29OFQgkQ2kiTJBIQ=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "nixpkgs.lib",
|
"repo": "nixpkgs.lib",
|
||||||
"rev": "c185c7a5e5dd8f9add5b2f8ebeff00888b070742",
|
"rev": "333c4e0545a6da976206c74db8773a1645b5870a",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -132,11 +132,11 @@
|
|||||||
"rust-analyzer-src": {
|
"rust-analyzer-src": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1773697963,
|
"lastModified": 1775843361,
|
||||||
"narHash": "sha256-xdKI77It9PM6eNrCcDZsnP4SKulZwk8VkDgBRVMnCb8=",
|
"narHash": "sha256-j53ZgyDvmYf3Sjh1IPvvTjqa614qUfVQSzj59+MpzkY=",
|
||||||
"owner": "rust-lang",
|
"owner": "rust-lang",
|
||||||
"repo": "rust-analyzer",
|
"repo": "rust-analyzer",
|
||||||
"rev": "2993637174252ff60a582fd1f55b9ab52c39db6d",
|
"rev": "9eb97ea96d8400e8957ddd56702e962614296583",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -153,11 +153,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1773297127,
|
"lastModified": 1775636079,
|
||||||
"narHash": "sha256-6E/yhXP7Oy/NbXtf1ktzmU8SdVqJQ09HC/48ebEGBpk=",
|
"narHash": "sha256-pc20NRoMdiar8oPQceQT47UUZMBTiMdUuWrYu2obUP0=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "treefmt-nix",
|
"repo": "treefmt-nix",
|
||||||
"rev": "71b125cd05fbfd78cab3e070b73544abe24c5016",
|
"rev": "790751ff7fd3801feeaf96d7dc416a8d581265ba",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@@ -29,7 +29,6 @@
|
|||||||
url = "github:edolstra/flake-compat?ref=master";
|
url = "github:edolstra/flake-compat?ref=master";
|
||||||
flake = false;
|
flake = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
@@ -37,10 +36,10 @@
|
|||||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||||
imports = [ ./nix ];
|
imports = [ ./nix ];
|
||||||
systems = [
|
systems = [
|
||||||
# good support
|
|
||||||
"x86_64-linux"
|
"x86_64-linux"
|
||||||
# support untested but theoretically there
|
|
||||||
"aarch64-linux"
|
"aarch64-linux"
|
||||||
|
# support untested but theoretically there
|
||||||
|
"aarch64-darwin"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
{ inputs, ... }:
|
|
||||||
{
|
|
||||||
perSystem =
|
|
||||||
{
|
|
||||||
self',
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
uwulib = inputs.self.uwulib.init pkgs;
|
|
||||||
|
|
||||||
rocksdbAllFeatures = self'.packages.rocksdb.override {
|
|
||||||
enableJemalloc = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
commonAttrs = (uwulib.build.commonAttrs { }) // {
|
|
||||||
buildInputs = [
|
|
||||||
pkgs.liburing
|
|
||||||
pkgs.rust-jemalloc-sys-unprefixed
|
|
||||||
rocksdbAllFeatures
|
|
||||||
];
|
|
||||||
nativeBuildInputs = [
|
|
||||||
pkgs.pkg-config
|
|
||||||
# bindgen needs the build platform's libclang. Apparently due to "splicing
|
|
||||||
# weirdness", pkgs.rustPlatform.bindgenHook on its own doesn't quite do the
|
|
||||||
# right thing here.
|
|
||||||
pkgs.rustPlatform.bindgenHook
|
|
||||||
];
|
|
||||||
env = {
|
|
||||||
LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.llvmPackages.libclang.lib ];
|
|
||||||
LD_LIBRARY_PATH = lib.makeLibraryPath [
|
|
||||||
pkgs.liburing
|
|
||||||
pkgs.rust-jemalloc-sys-unprefixed
|
|
||||||
rocksdbAllFeatures
|
|
||||||
];
|
|
||||||
}
|
|
||||||
// uwulib.environment.buildPackageEnv
|
|
||||||
// {
|
|
||||||
ROCKSDB_INCLUDE_DIR = "${rocksdbAllFeatures}/include";
|
|
||||||
ROCKSDB_LIB_DIR = "${rocksdbAllFeatures}/lib";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
cargoArtifacts = self'.packages.continuwuity-all-features-deps;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
# taken from
|
|
||||||
#
|
|
||||||
# https://crane.dev/examples/quick-start.html
|
|
||||||
checks = {
|
|
||||||
continuwuity-all-features-build = self'.packages.continuwuity-all-features-bin;
|
|
||||||
|
|
||||||
continuwuity-all-features-clippy = uwulib.build.craneLibForChecks.cargoClippy (
|
|
||||||
commonAttrs
|
|
||||||
// {
|
|
||||||
inherit cargoArtifacts;
|
|
||||||
cargoClippyExtraArgs = "-- --deny warnings";
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
continuwuity-all-features-docs = uwulib.build.craneLibForChecks.cargoDoc (
|
|
||||||
commonAttrs
|
|
||||||
// {
|
|
||||||
inherit cargoArtifacts;
|
|
||||||
# This can be commented out or tweaked as necessary, e.g. set to
|
|
||||||
# `--deny rustdoc::broken-intra-doc-links` to only enforce that lint
|
|
||||||
env.RUSTDOCFLAGS = "--deny warnings";
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
# Check formatting
|
|
||||||
continuwuity-all-features-fmt = uwulib.build.craneLibForChecks.cargoFmt {
|
|
||||||
src = uwulib.build.src;
|
|
||||||
};
|
|
||||||
|
|
||||||
continuwuity-all-features-toml-fmt = uwulib.build.craneLibForChecks.taploFmt {
|
|
||||||
src = pkgs.lib.sources.sourceFilesBySuffices uwulib.build.src [ ".toml" ];
|
|
||||||
# taplo arguments can be further customized below as needed
|
|
||||||
taploExtraArgs = "--config ${inputs.self}/taplo.toml";
|
|
||||||
};
|
|
||||||
|
|
||||||
# Audit dependencies
|
|
||||||
continuwuity-all-features-audit = uwulib.build.craneLibForChecks.cargoAudit {
|
|
||||||
inherit (inputs) advisory-db;
|
|
||||||
src = uwulib.build.src;
|
|
||||||
};
|
|
||||||
|
|
||||||
# Audit licenses
|
|
||||||
continuwuity-all-features-deny = uwulib.build.craneLibForChecks.cargoDeny {
|
|
||||||
src = uwulib.build.src;
|
|
||||||
};
|
|
||||||
|
|
||||||
# Run tests with cargo-nextest
|
|
||||||
# Consider setting `doCheck = false` on `continuwuity-all-features` if you do not want
|
|
||||||
# the tests to run twice
|
|
||||||
continuwuity-all-features-nextest = uwulib.build.craneLibForChecks.cargoNextest (
|
|
||||||
commonAttrs
|
|
||||||
// {
|
|
||||||
inherit cargoArtifacts;
|
|
||||||
partitions = 1;
|
|
||||||
partitionType = "count";
|
|
||||||
cargoNextestPartitionsExtraArgs = "--no-tests=pass";
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{ inputs, ... }:
|
||||||
|
{
|
||||||
|
perSystem =
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
self',
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
_module.args.craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (
|
||||||
|
pkgs: self'.packages.stable-toolchain
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
+4
-5
@@ -1,11 +1,10 @@
|
|||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./checks
|
./rust.nix
|
||||||
|
./crane.nix
|
||||||
./packages
|
./packages
|
||||||
./shells
|
./devshell.nix
|
||||||
./tests
|
|
||||||
|
|
||||||
./hydra.nix
|
|
||||||
./fmt.nix
|
./fmt.nix
|
||||||
|
./rocksdb-updater.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
perSystem =
|
||||||
|
{
|
||||||
|
craneLib,
|
||||||
|
self',
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
# basic nix shell containing all things necessary to build continuwuity in all flavors manually (on x86_64-linux)
|
||||||
|
devShells.default = craneLib.devShell {
|
||||||
|
packages = [
|
||||||
|
self'.packages.rocksdb
|
||||||
|
pkgs.nodejs
|
||||||
|
pkgs.pkg-config
|
||||||
|
]
|
||||||
|
++ lib.optionals pkgs.stdenv.isLinux [
|
||||||
|
pkgs.liburing
|
||||||
|
pkgs.rust-jemalloc-sys-unprefixed
|
||||||
|
];
|
||||||
|
|
||||||
|
env = {
|
||||||
|
LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.llvmPackages.libclang.lib ];
|
||||||
|
LD_LIBRARY_PATH = lib.makeLibraryPath (
|
||||||
|
[
|
||||||
|
pkgs.stdenv.cc.cc.lib
|
||||||
|
]
|
||||||
|
++ lib.optionals pkgs.stdenv.isLinux [
|
||||||
|
pkgs.liburing
|
||||||
|
pkgs.jemalloc
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// lib.optionalAttrs pkgs.stdenv.isLinux {
|
||||||
|
PKG_CONFIG_PATH = lib.makeSearchPath "lib/pkgconfig" [
|
||||||
|
pkgs.liburing.dev
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{ inputs, ... }:
|
|
||||||
let
|
|
||||||
lib = inputs.nixpkgs.lib;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
flake.hydraJobs.packages = builtins.mapAttrs (
|
|
||||||
_name: lib.hydraJob
|
|
||||||
) inputs.self.packages.x86_64-linux;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
self,
|
||||||
|
stdenv,
|
||||||
|
liburing,
|
||||||
|
craneLib,
|
||||||
|
pkg-config,
|
||||||
|
callPackage,
|
||||||
|
rustPlatform,
|
||||||
|
cargoExtraArgs ? "",
|
||||||
|
rocksdb ? callPackage ./rocksdb.nix { },
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
# see https://crane.dev/API.html#cranelibfiltercargosources
|
||||||
|
# we need to keep the `web` directory which would be filtered out by the regular source filtering function
|
||||||
|
# https://crane.dev/API.html#cranelibcleancargosource
|
||||||
|
isWebTemplate = path: _type: builtins.match ".*(src/(web|service)|docs).*" path != null;
|
||||||
|
isRust = craneLib.filterCargoSources;
|
||||||
|
isNix = path: _type: builtins.match ".+/nix.*" path != null;
|
||||||
|
webOrRustNotNix = p: t: !(isNix p t) && (isWebTemplate p t || isRust p t);
|
||||||
|
|
||||||
|
src = lib.cleanSourceWith {
|
||||||
|
src = self;
|
||||||
|
filter = webOrRustNotNix;
|
||||||
|
name = "source";
|
||||||
|
};
|
||||||
|
|
||||||
|
attrs = {
|
||||||
|
inherit src;
|
||||||
|
nativeBuildInputs = [
|
||||||
|
pkg-config
|
||||||
|
rustPlatform.bindgenHook
|
||||||
|
];
|
||||||
|
buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ liburing ];
|
||||||
|
env = {
|
||||||
|
ROCKSDB_INCLUDE_DIR = "${rocksdb}/include";
|
||||||
|
ROCKSDB_LIB_DIR = "${rocksdb}/lib";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
craneLib.buildPackage (
|
||||||
|
lib.recursiveUpdate attrs {
|
||||||
|
inherit cargoExtraArgs;
|
||||||
|
cargoArtifacts = craneLib.buildDepsOnly attrs;
|
||||||
|
|
||||||
|
# Needed to make continuwuity link to rocksdb
|
||||||
|
postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
|
||||||
|
old_rpath="$(patchelf --print-rpath $out/bin/conduwuit)"
|
||||||
|
extra_rpath="${
|
||||||
|
lib.makeLibraryPath [
|
||||||
|
rocksdb
|
||||||
|
]
|
||||||
|
}"
|
||||||
|
|
||||||
|
patchelf --set-rpath "$old_rpath:$extra_rpath" $out/bin/conduwuit
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
description = "A community-driven Matrix homeserver in Rust";
|
||||||
|
mainProgram = "conduwuit";
|
||||||
|
platforms = lib.platforms.all;
|
||||||
|
maintainers = with lib.maintainers; [ quadradical ];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
{ inputs, ... }:
|
|
||||||
{
|
|
||||||
perSystem =
|
|
||||||
{
|
|
||||||
self',
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
uwulib = inputs.self.uwulib.init pkgs;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
packages =
|
|
||||||
lib.pipe
|
|
||||||
[
|
|
||||||
# this is the default variant
|
|
||||||
{
|
|
||||||
variantName = "default";
|
|
||||||
commonAttrsArgs.profile = "release";
|
|
||||||
rocksdb = self'.packages.rocksdb;
|
|
||||||
features = { };
|
|
||||||
}
|
|
||||||
# this is the variant with all features enabled (liburing + jemalloc)
|
|
||||||
{
|
|
||||||
variantName = "all-features";
|
|
||||||
commonAttrsArgs.profile = "release";
|
|
||||||
rocksdb = self'.packages.rocksdb.override {
|
|
||||||
enableJemalloc = true;
|
|
||||||
};
|
|
||||||
features = {
|
|
||||||
enabledFeatures = "all";
|
|
||||||
disabledFeatures = uwulib.features.defaultDisabledFeatures ++ [ "bindgen-static" ];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
]
|
|
||||||
[
|
|
||||||
(builtins.map (cfg: rec {
|
|
||||||
deps = {
|
|
||||||
name = "continuwuity-${cfg.variantName}-deps";
|
|
||||||
value = uwulib.build.buildDeps {
|
|
||||||
features = uwulib.features.calcFeatures cfg.features;
|
|
||||||
inherit (cfg) commonAttrsArgs rocksdb;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
bin = {
|
|
||||||
name = "continuwuity-${cfg.variantName}-bin";
|
|
||||||
value = uwulib.build.buildPackage {
|
|
||||||
deps = self'.packages.${deps.name};
|
|
||||||
features = uwulib.features.calcFeatures cfg.features;
|
|
||||||
inherit (cfg) commonAttrsArgs rocksdb;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}))
|
|
||||||
(builtins.concatMap builtins.attrValues)
|
|
||||||
builtins.listToAttrs
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,18 @@
|
|||||||
{
|
{
|
||||||
imports = [
|
self,
|
||||||
./continuwuity
|
...
|
||||||
./rocksdb
|
}:
|
||||||
./rust.nix
|
{
|
||||||
./uwulib
|
|
||||||
];
|
|
||||||
|
|
||||||
perSystem =
|
perSystem =
|
||||||
{ self', ... }:
|
|
||||||
{
|
{
|
||||||
packages.default = self'.packages.continuwuity-default-bin;
|
pkgs,
|
||||||
|
craneLib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
packages = {
|
||||||
|
rocksdb = pkgs.callPackage ./rocksdb.nix { };
|
||||||
|
default = pkgs.callPackage ./continuwuity.nix { inherit self craneLib; };
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
stdenv,
|
||||||
|
rocksdb,
|
||||||
|
fetchFromGitea,
|
||||||
|
rust-jemalloc-sys-unprefixed,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
(rocksdb.override {
|
||||||
|
# rocksdb fails to build with prefixed jemalloc, which is required on
|
||||||
|
# darwin due to [1]. In this case, fall back to building rocksdb with
|
||||||
|
# libc malloc. This should not cause conflicts, because all of the
|
||||||
|
# jemalloc symbols are prefixed.
|
||||||
|
#
|
||||||
|
# [1]: https://github.com/tikv/jemallocator/blob/ab0676d77e81268cd09b059260c75b38dbef2d51/jemalloc-sys/src/env.rs#L17
|
||||||
|
jemalloc = rust-jemalloc-sys-unprefixed;
|
||||||
|
enableJemalloc = stdenv.hostPlatform.isLinux;
|
||||||
|
}).overrideAttrs
|
||||||
|
({
|
||||||
|
version = "continuwuity-v0.5.0-unstable-2026-03-27";
|
||||||
|
src = fetchFromGitea {
|
||||||
|
domain = "forgejo.ellis.link";
|
||||||
|
owner = "continuwuation";
|
||||||
|
repo = "rocksdb";
|
||||||
|
rev = "463f47afceebfe088f6922420265546bd237f249";
|
||||||
|
hash = "sha256-1ef75IDMs5Hba4VWEyXPJb02JyShy5k4gJfzGDhopRk=";
|
||||||
|
};
|
||||||
|
|
||||||
|
# We have this already at https://forgejo.ellis.link/continuwuation/rocksdb/commit/a935c0273e1ba44eacf88ce3685a9b9831486155
|
||||||
|
# Unsetting `patches` so we don't have to revert it and make this nix exclusive
|
||||||
|
patches = [ ];
|
||||||
|
|
||||||
|
# Unset postPatch, as our version override breaks version-specific sed calls in the original package
|
||||||
|
postPatch = "";
|
||||||
|
})
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
perSystem =
|
|
||||||
{
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
packages = {
|
|
||||||
rocksdb = pkgs.callPackage ./package.nix { };
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
{
|
|
||||||
lib,
|
|
||||||
stdenv,
|
|
||||||
|
|
||||||
rocksdb,
|
|
||||||
liburing,
|
|
||||||
rust-jemalloc-sys-unprefixed,
|
|
||||||
|
|
||||||
enableJemalloc ? false,
|
|
||||||
|
|
||||||
fetchFromGitea,
|
|
||||||
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
notDarwin = !stdenv.hostPlatform.isDarwin;
|
|
||||||
in
|
|
||||||
(rocksdb.override {
|
|
||||||
# Override the liburing input for the build with our own so
|
|
||||||
# we have it built with the library flag
|
|
||||||
inherit liburing;
|
|
||||||
jemalloc = rust-jemalloc-sys-unprefixed;
|
|
||||||
|
|
||||||
# rocksdb fails to build with prefixed jemalloc, which is required on
|
|
||||||
# darwin due to [1]. In this case, fall back to building rocksdb with
|
|
||||||
# libc malloc. This should not cause conflicts, because all of the
|
|
||||||
# jemalloc symbols are prefixed.
|
|
||||||
#
|
|
||||||
# [1]: https://github.com/tikv/jemallocator/blob/ab0676d77e81268cd09b059260c75b38dbef2d51/jemalloc-sys/src/env.rs#L17
|
|
||||||
enableJemalloc = enableJemalloc && notDarwin;
|
|
||||||
|
|
||||||
# for some reason enableLiburing in nixpkgs rocksdb is default true
|
|
||||||
# which breaks Darwin entirely
|
|
||||||
enableLiburing = notDarwin;
|
|
||||||
}).overrideAttrs
|
|
||||||
(old: {
|
|
||||||
src = fetchFromGitea {
|
|
||||||
domain = "forgejo.ellis.link";
|
|
||||||
owner = "continuwuation";
|
|
||||||
repo = "rocksdb";
|
|
||||||
rev = "10.5.fb";
|
|
||||||
sha256 = "sha256-X4ApGLkHF9ceBtBg77dimEpu720I79ffLoyPa8JMHaU=";
|
|
||||||
};
|
|
||||||
version = "10.5.fb";
|
|
||||||
cmakeFlags =
|
|
||||||
lib.subtractLists (builtins.map (flag: lib.cmakeBool flag true) [
|
|
||||||
# No real reason to have snappy or zlib, no one uses this
|
|
||||||
"WITH_SNAPPY"
|
|
||||||
"ZLIB"
|
|
||||||
"WITH_ZLIB"
|
|
||||||
# We don't need to use ldb or sst_dump (core_tools)
|
|
||||||
"WITH_CORE_TOOLS"
|
|
||||||
# We don't need to build rocksdb tests
|
|
||||||
"WITH_TESTS"
|
|
||||||
# We use rust-rocksdb via C interface and don't need C++ RTTI
|
|
||||||
"USE_RTTI"
|
|
||||||
# This doesn't exist in RocksDB, and USE_SSE is deprecated for
|
|
||||||
# PORTABLE=$(march)
|
|
||||||
"FORCE_SSE42"
|
|
||||||
]) old.cmakeFlags
|
|
||||||
++ (builtins.map (flag: lib.cmakeBool flag false) [
|
|
||||||
# No real reason to have snappy, no one uses this
|
|
||||||
"WITH_SNAPPY"
|
|
||||||
"ZLIB"
|
|
||||||
"WITH_ZLIB"
|
|
||||||
# We don't need to use ldb or sst_dump (core_tools)
|
|
||||||
"WITH_CORE_TOOLS"
|
|
||||||
# We don't need trace tools
|
|
||||||
"WITH_TRACE_TOOLS"
|
|
||||||
# We don't need to build rocksdb tests
|
|
||||||
"WITH_TESTS"
|
|
||||||
# We use rust-rocksdb via C interface and don't need C++ RTTI
|
|
||||||
"USE_RTTI"
|
|
||||||
]);
|
|
||||||
|
|
||||||
enableLiburing = notDarwin;
|
|
||||||
|
|
||||||
# outputs has "tools" which we don't need or use
|
|
||||||
outputs = [ "out" ];
|
|
||||||
|
|
||||||
# preInstall hooks has stuff for messing with ldb/sst_dump which we don't need or use
|
|
||||||
preInstall = "";
|
|
||||||
|
|
||||||
# We have this already at https://forgejo.ellis.link/continuwuation/rocksdb/commit/a935c0273e1ba44eacf88ce3685a9b9831486155
|
|
||||||
# Unsetting `patches` so we don't have to revert it and make this nix exclusive
|
|
||||||
patches = [ ];
|
|
||||||
})
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
args@{ pkgs, inputs, ... }:
|
|
||||||
let
|
|
||||||
inherit (pkgs) lib;
|
|
||||||
uwuenv = import ./environment.nix args;
|
|
||||||
selfpkgs = inputs.self.packages.${pkgs.stdenv.system};
|
|
||||||
in
|
|
||||||
rec {
|
|
||||||
# basic, very minimal instance of the crane library with a minimal rust toolchain
|
|
||||||
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (_: selfpkgs.build-toolchain);
|
|
||||||
# the checks require more rust toolchain components, hence we have this separate instance of the crane library
|
|
||||||
craneLibForChecks = (inputs.crane.mkLib pkgs).overrideToolchain (_: selfpkgs.dev-toolchain);
|
|
||||||
|
|
||||||
# meta information (name, version, etc) of the rust crate based on the Cargo.toml
|
|
||||||
crateInfo = craneLib.crateNameFromCargoToml { cargoToml = "${inputs.self}/Cargo.toml"; };
|
|
||||||
|
|
||||||
src =
|
|
||||||
let
|
|
||||||
# see https://crane.dev/API.html#cranelibfiltercargosources
|
|
||||||
#
|
|
||||||
# we need to keep the `web` directory which would be filtered out by the regular source filtering function
|
|
||||||
#
|
|
||||||
# https://crane.dev/API.html#cranelibcleancargosource
|
|
||||||
isWebTemplate = path: _type: builtins.match ".*(src/(web|service)|docs).*" path != null;
|
|
||||||
isRust = craneLib.filterCargoSources;
|
|
||||||
isNix = path: _type: builtins.match ".+/nix.*" path != null;
|
|
||||||
webOrRustNotNix = p: t: !(isNix p t) && (isWebTemplate p t || isRust p t);
|
|
||||||
in
|
|
||||||
lib.cleanSourceWith {
|
|
||||||
src = inputs.self;
|
|
||||||
filter = webOrRustNotNix;
|
|
||||||
name = "source";
|
|
||||||
};
|
|
||||||
|
|
||||||
# common attrs that are shared between building continuwuity's deps and the package itself
|
|
||||||
commonAttrs =
|
|
||||||
{
|
|
||||||
profile ? "dev",
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
inherit (crateInfo)
|
|
||||||
pname
|
|
||||||
version
|
|
||||||
;
|
|
||||||
inherit src;
|
|
||||||
|
|
||||||
# this prevents unnecessary rebuilds
|
|
||||||
strictDeps = true;
|
|
||||||
|
|
||||||
dontStrip = profile == "dev" || profile == "test";
|
|
||||||
dontPatchELF = profile == "dev" || profile == "test";
|
|
||||||
|
|
||||||
doCheck = true;
|
|
||||||
|
|
||||||
nativeBuildInputs = [
|
|
||||||
# bindgen needs the build platform's libclang. Apparently due to "splicing
|
|
||||||
# weirdness", pkgs.rustPlatform.bindgenHook on its own doesn't quite do the
|
|
||||||
# right thing here.
|
|
||||||
pkgs.rustPlatform.bindgenHook
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
makeRocksDBEnv =
|
|
||||||
{ rocksdb }:
|
|
||||||
{
|
|
||||||
ROCKSDB_INCLUDE_DIR = "${rocksdb}/include";
|
|
||||||
ROCKSDB_LIB_DIR = "${rocksdb}/lib";
|
|
||||||
};
|
|
||||||
|
|
||||||
# function that builds the continuwuity dependencies derivation
|
|
||||||
buildDeps =
|
|
||||||
{
|
|
||||||
rocksdb,
|
|
||||||
features,
|
|
||||||
commonAttrsArgs,
|
|
||||||
}:
|
|
||||||
craneLib.buildDepsOnly (
|
|
||||||
(commonAttrs commonAttrsArgs)
|
|
||||||
// {
|
|
||||||
env = uwuenv.buildDepsOnlyEnv
|
|
||||||
// (makeRocksDBEnv { inherit rocksdb; })
|
|
||||||
// {
|
|
||||||
# required since we started using unstable reqwest apparently ... otherwise the all-features build will fail
|
|
||||||
RUSTFLAGS = "--cfg reqwest_unstable";
|
|
||||||
};
|
|
||||||
inherit (features) cargoExtraArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
# function that builds the continuwuity package
|
|
||||||
buildPackage =
|
|
||||||
{
|
|
||||||
deps,
|
|
||||||
rocksdb,
|
|
||||||
features,
|
|
||||||
commonAttrsArgs,
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
rocksdbEnv = makeRocksDBEnv { inherit rocksdb; };
|
|
||||||
in
|
|
||||||
craneLib.buildPackage (
|
|
||||||
(commonAttrs commonAttrsArgs)
|
|
||||||
// {
|
|
||||||
postFixup = ''
|
|
||||||
patchelf --set-rpath "$(${pkgs.patchelf}/bin/patchelf --print-rpath $out/bin/${crateInfo.pname}):${rocksdb}/lib" $out/bin/${crateInfo.pname}
|
|
||||||
'';
|
|
||||||
cargoArtifacts = deps;
|
|
||||||
doCheck = true;
|
|
||||||
env =
|
|
||||||
uwuenv.buildPackageEnv
|
|
||||||
// rocksdbEnv
|
|
||||||
// {
|
|
||||||
# required since we started using unstable reqwest apparently ... otherwise the all-features build will fail
|
|
||||||
RUSTFLAGS = "--cfg reqwest_unstable";
|
|
||||||
};
|
|
||||||
passthru.env = uwuenv.buildPackageEnv // rocksdbEnv;
|
|
||||||
meta.mainProgram = crateInfo.pname;
|
|
||||||
inherit (features) cargoExtraArgs;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{ inputs, ... }:
|
|
||||||
{
|
|
||||||
flake.uwulib = {
|
|
||||||
init = pkgs: {
|
|
||||||
features = import ./features.nix { inherit pkgs inputs; };
|
|
||||||
environment = import ./environment.nix { inherit pkgs inputs; };
|
|
||||||
build = import ./build.nix { inherit pkgs inputs; };
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
args@{ pkgs, inputs, ... }:
|
|
||||||
let
|
|
||||||
uwubuild = import ./build.nix args;
|
|
||||||
in
|
|
||||||
rec {
|
|
||||||
buildDepsOnlyEnv = {
|
|
||||||
# https://crane.dev/faq/rebuilds-bindgen.html
|
|
||||||
NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa";
|
|
||||||
CARGO_PROFILE = "release";
|
|
||||||
}
|
|
||||||
// uwubuild.craneLib.mkCrossToolchainEnv (p: pkgs.clangStdenv);
|
|
||||||
|
|
||||||
buildPackageEnv = {
|
|
||||||
GIT_COMMIT_HASH = inputs.self.rev or inputs.self.dirtyRev or "";
|
|
||||||
GIT_COMMIT_HASH_SHORT = inputs.self.shortRev or inputs.self.dirtyShortRev or "";
|
|
||||||
}
|
|
||||||
// buildDepsOnlyEnv;
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
{ pkgs, inputs, ... }:
|
|
||||||
let
|
|
||||||
inherit (pkgs) lib;
|
|
||||||
in
|
|
||||||
rec {
|
|
||||||
defaultDisabledFeatures = [
|
|
||||||
# dont include experimental features
|
|
||||||
"experimental"
|
|
||||||
# jemalloc profiling/stats features are expensive and shouldn't
|
|
||||||
# be expected on non-debug builds.
|
|
||||||
"jemalloc_prof"
|
|
||||||
"jemalloc_stats"
|
|
||||||
# this is non-functional on nix for some reason
|
|
||||||
"hardened_malloc"
|
|
||||||
# conduwuit_mods is a development-only hot reload feature
|
|
||||||
"conduwuit_mods"
|
|
||||||
# we don't want to enable this feature set by default but be more specific about it
|
|
||||||
"full"
|
|
||||||
];
|
|
||||||
# We perform default-feature unification in nix, because some of the dependencies
|
|
||||||
# on the nix side depend on feature values.
|
|
||||||
calcFeatures =
|
|
||||||
{
|
|
||||||
tomlPath ? "${inputs.self}/src/main",
|
|
||||||
# either a list of feature names or a string "all" which enables all non-default features
|
|
||||||
enabledFeatures ? [ ],
|
|
||||||
disabledFeatures ? defaultDisabledFeatures,
|
|
||||||
default_features ? true,
|
|
||||||
disable_release_max_log_level ? false,
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
# simple helper to get the contents of a Cargo.toml file in a nix format
|
|
||||||
getToml = path: lib.importTOML "${path}/Cargo.toml";
|
|
||||||
|
|
||||||
# get all the features except for the default features
|
|
||||||
allFeatures = lib.pipe tomlPath [
|
|
||||||
getToml
|
|
||||||
(manifest: manifest.features)
|
|
||||||
lib.attrNames
|
|
||||||
(lib.remove "default")
|
|
||||||
];
|
|
||||||
|
|
||||||
# get just the default enabled features
|
|
||||||
allDefaultFeatures = lib.pipe tomlPath [
|
|
||||||
getToml
|
|
||||||
(manifest: manifest.features.default)
|
|
||||||
];
|
|
||||||
|
|
||||||
# depending on the value of enabledFeatures choose just a set or all non-default features
|
|
||||||
#
|
|
||||||
# - [ list of features ] -> choose exactly the features listed
|
|
||||||
# - "all" -> choose all non-default features
|
|
||||||
additionalFeatures = if enabledFeatures == "all" then allFeatures else enabledFeatures;
|
|
||||||
|
|
||||||
# unification with default features (if enabled)
|
|
||||||
features = lib.unique (additionalFeatures ++ lib.optionals default_features allDefaultFeatures);
|
|
||||||
|
|
||||||
# prepare the features that are subtracted from the set
|
|
||||||
disabledFeatures' =
|
|
||||||
disabledFeatures ++ lib.optionals disable_release_max_log_level [ "release_max_log_level" ];
|
|
||||||
|
|
||||||
# construct the final feature set
|
|
||||||
finalFeatures = lib.subtractLists disabledFeatures' features;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
# final feature set, useful for querying it
|
|
||||||
features = finalFeatures;
|
|
||||||
|
|
||||||
# crane flag with the relevant features
|
|
||||||
cargoExtraArgs = builtins.concatStringsSep " " [
|
|
||||||
"--no-default-features"
|
|
||||||
"--locked"
|
|
||||||
(lib.optionalString (finalFeatures != [ ]) "--features")
|
|
||||||
(builtins.concatStringsSep "," finalFeatures)
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
perSystem =
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
apps.update-rocksdb = {
|
||||||
|
type = "app";
|
||||||
|
program = pkgs.writeShellApplication {
|
||||||
|
name = "update-rocksdb";
|
||||||
|
runtimeInputs = [ pkgs.nix-update ];
|
||||||
|
text = "nix-update rocksdb -F --version branch";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
{
|
{
|
||||||
system,
|
system,
|
||||||
lib,
|
lib,
|
||||||
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
@@ -11,7 +12,7 @@
|
|||||||
let
|
let
|
||||||
fnx = inputs.fenix.packages.${system};
|
fnx = inputs.fenix.packages.${system};
|
||||||
|
|
||||||
stable = fnx.fromToolchainFile {
|
stable-toolchain = fnx.fromToolchainFile {
|
||||||
file = inputs.self + "/rust-toolchain.toml";
|
file = inputs.self + "/rust-toolchain.toml";
|
||||||
|
|
||||||
# See also `rust-toolchain.toml`
|
# See also `rust-toolchain.toml`
|
||||||
@@ -19,11 +20,10 @@
|
|||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# used for building nix stuff (doesn't include rustfmt overhead)
|
inherit stable-toolchain;
|
||||||
build-toolchain = stable;
|
|
||||||
# used for dev shells
|
|
||||||
dev-toolchain = fnx.combine [
|
dev-toolchain = fnx.combine [
|
||||||
stable
|
stable-toolchain
|
||||||
# use the nightly rustfmt because we use nightly features
|
# use the nightly rustfmt because we use nightly features
|
||||||
fnx.complete.rustfmt
|
fnx.complete.rustfmt
|
||||||
];
|
];
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
{ inputs, ... }:
|
|
||||||
{
|
|
||||||
perSystem =
|
|
||||||
{
|
|
||||||
self',
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
uwulib = inputs.self.uwulib.init pkgs;
|
|
||||||
rocksdbAllFeatures = self'.packages.rocksdb.override {
|
|
||||||
enableJemalloc = true;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
# basic nix shell containing all things necessary to build continuwuity in all flavors manually (on x86_64-linux)
|
|
||||||
devShells.default = uwulib.build.craneLib.devShell {
|
|
||||||
packages = [
|
|
||||||
pkgs.nodejs
|
|
||||||
pkgs.pkg-config
|
|
||||||
pkgs.liburing
|
|
||||||
pkgs.rust-jemalloc-sys-unprefixed
|
|
||||||
rocksdbAllFeatures
|
|
||||||
];
|
|
||||||
env.LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.llvmPackages.libclang.lib ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
{
|
|
||||||
perSystem =
|
|
||||||
{
|
|
||||||
self',
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
baseTestScript =
|
|
||||||
pkgs.writers.writePython3Bin "do_test" { libraries = [ pkgs.python3Packages.matrix-nio ]; }
|
|
||||||
''
|
|
||||||
import asyncio
|
|
||||||
import nio
|
|
||||||
|
|
||||||
|
|
||||||
async def main() -> None:
|
|
||||||
# Connect to continuwuity
|
|
||||||
client = nio.AsyncClient("http://continuwuity:6167", "alice")
|
|
||||||
|
|
||||||
# Register as user alice
|
|
||||||
response = await client.register("alice", "my-secret-password")
|
|
||||||
|
|
||||||
# Log in as user alice
|
|
||||||
response = await client.login("my-secret-password")
|
|
||||||
|
|
||||||
# Create a new room
|
|
||||||
response = await client.room_create(federate=False)
|
|
||||||
print("Matrix room create response:", response)
|
|
||||||
assert isinstance(response, nio.RoomCreateResponse)
|
|
||||||
room_id = response.room_id
|
|
||||||
|
|
||||||
# Join the room
|
|
||||||
response = await client.join(room_id)
|
|
||||||
print("Matrix join response:", response)
|
|
||||||
assert isinstance(response, nio.JoinResponse)
|
|
||||||
|
|
||||||
# Send a message to the room
|
|
||||||
response = await client.room_send(
|
|
||||||
room_id=room_id,
|
|
||||||
message_type="m.room.message",
|
|
||||||
content={
|
|
||||||
"msgtype": "m.text",
|
|
||||||
"body": "Hello continuwuity!"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
print("Matrix room send response:", response)
|
|
||||||
assert isinstance(response, nio.RoomSendResponse)
|
|
||||||
|
|
||||||
# Sync responses
|
|
||||||
response = await client.sync(timeout=30000)
|
|
||||||
print("Matrix sync response:", response)
|
|
||||||
assert isinstance(response, nio.SyncResponse)
|
|
||||||
|
|
||||||
# Check the message was received by continuwuity
|
|
||||||
last_message = response.rooms.join[room_id].timeline.events[-1].body
|
|
||||||
assert last_message == "Hello continuwuity!"
|
|
||||||
|
|
||||||
# Leave the room
|
|
||||||
response = await client.room_leave(room_id)
|
|
||||||
print("Matrix room leave response:", response)
|
|
||||||
assert isinstance(response, nio.RoomLeaveResponse)
|
|
||||||
|
|
||||||
# Close the client
|
|
||||||
await client.close()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
asyncio.run(main())
|
|
||||||
'';
|
|
||||||
in
|
|
||||||
{
|
|
||||||
# run some nixos tests as checks
|
|
||||||
checks = lib.pipe self'.packages [
|
|
||||||
# we take all packages (names)
|
|
||||||
builtins.attrNames
|
|
||||||
# we filter out all packages that end with `-bin` (which we are interested in for testing)
|
|
||||||
(builtins.filter (lib.hasSuffix "-bin"))
|
|
||||||
# for each of these binaries we built the basic nixos test
|
|
||||||
#
|
|
||||||
# this test was initially yoinked from
|
|
||||||
#
|
|
||||||
# https://github.com/NixOS/nixpkgs/blob/960ce26339661b1b69c6f12b9063ca51b688615f/nixos/tests/matrix/continuwuity.nix
|
|
||||||
(builtins.concatMap (
|
|
||||||
name:
|
|
||||||
builtins.map
|
|
||||||
(
|
|
||||||
{ config, suffix }:
|
|
||||||
{
|
|
||||||
name = "test-${name}-${suffix}";
|
|
||||||
value = pkgs.testers.runNixOSTest {
|
|
||||||
inherit name;
|
|
||||||
|
|
||||||
nodes = {
|
|
||||||
continuwuity = {
|
|
||||||
services.matrix-continuwuity = {
|
|
||||||
enable = true;
|
|
||||||
package = self'.packages.${name};
|
|
||||||
settings = config;
|
|
||||||
extraEnvironment.RUST_BACKTRACE = "yes";
|
|
||||||
};
|
|
||||||
networking.firewall.allowedTCPPorts = [ 6167 ];
|
|
||||||
};
|
|
||||||
client.environment.systemPackages = [ baseTestScript ];
|
|
||||||
};
|
|
||||||
|
|
||||||
testScript = ''
|
|
||||||
start_all()
|
|
||||||
|
|
||||||
with subtest("start continuwuity"):
|
|
||||||
continuwuity.wait_for_unit("continuwuity.service")
|
|
||||||
continuwuity.wait_for_open_port(6167)
|
|
||||||
|
|
||||||
with subtest("ensure messages can be exchanged"):
|
|
||||||
client.succeed("${lib.getExe baseTestScript} >&2")
|
|
||||||
'';
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
)
|
|
||||||
[
|
|
||||||
{
|
|
||||||
suffix = "base";
|
|
||||||
config = {
|
|
||||||
global = {
|
|
||||||
server_name = name;
|
|
||||||
address = [ "0.0.0.0" ];
|
|
||||||
allow_registration = true;
|
|
||||||
yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
{
|
|
||||||
suffix = "with-room-version";
|
|
||||||
config = {
|
|
||||||
global = {
|
|
||||||
server_name = name;
|
|
||||||
address = [ "0.0.0.0" ];
|
|
||||||
allow_registration = true;
|
|
||||||
yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true;
|
|
||||||
default_room_version = "12";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
]
|
|
||||||
))
|
|
||||||
builtins.listToAttrs
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Generated
+123
-553
File diff suppressed because it is too large.
Load diff
@@ -2,6 +2,7 @@
|
|||||||
name = "conduwuit_admin"
|
name = "conduwuit_admin"
|
||||||
description.workspace = true
|
description.workspace = true
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
|
homepage.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
readme.workspace = true
|
readme.workspace = true
|
||||||
repository.workspace = true
|
repository.workspace = true
|
||||||
@@ -79,9 +80,11 @@ conduwuit-database.workspace = true
|
|||||||
conduwuit-macros.workspace = true
|
conduwuit-macros.workspace = true
|
||||||
conduwuit-service.workspace = true
|
conduwuit-service.workspace = true
|
||||||
const-str.workspace = true
|
const-str.workspace = true
|
||||||
|
ctor.workspace = true
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
lettre.workspace = true
|
lettre.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
|
assign.workspace = true
|
||||||
ruma.workspace = true
|
ruma.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
serde-saphyr.workspace = true
|
serde-saphyr.workspace = true
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crate::Context;
|
|||||||
#[implement(Context, params = "<'_>")]
|
#[implement(Context, params = "<'_>")]
|
||||||
pub(super) async fn check_all_users(&self) -> Result {
|
pub(super) async fn check_all_users(&self) -> Result {
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
let users = self.services.users.iter().collect::<Vec<_>>().await;
|
let users = self.services.users.stream().collect::<Vec<_>>().await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|
||||||
let total = users.len();
|
let total = users.len();
|
||||||
|
|||||||
+37
-24
@@ -79,12 +79,14 @@ pub(super) async fn parse_pdu(&self) -> Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let string = self.body[1..self.body.len().saturating_sub(1)].join("\n");
|
let string = self.body[1..self.body.len().saturating_sub(1)].join("\n");
|
||||||
|
let room_version_rules = RoomVersionId::V12.rules().unwrap();
|
||||||
|
|
||||||
match serde_json::from_str(&string) {
|
match serde_json::from_str(&string) {
|
||||||
| Err(e) => return Err!("Invalid json in command body: {e}"),
|
| Err(e) => return Err!("Invalid json in command body: {e}"),
|
||||||
| Ok(value) => match ruma::signatures::reference_hash(&value, &RoomVersionId::V6) {
|
| Ok(value) => match ruma::signatures::reference_hash(&value, &room_version_rules) {
|
||||||
| Err(e) => return Err!("Could not parse PDU JSON: {e:?}"),
|
| Err(e) => return Err!("Could not parse PDU JSON: {e:?}"),
|
||||||
| Ok(hash) => {
|
| Ok(hash) => {
|
||||||
let event_id = OwnedEventId::parse(format!("${hash}"));
|
let event_id = EventId::parse(format!("${hash}"));
|
||||||
match serde_json::from_value::<PduEvent>(serde_json::to_value(value)?) {
|
match serde_json::from_value::<PduEvent>(serde_json::to_value(value)?) {
|
||||||
| Err(e) => return Err!("EventId: {event_id:?}\nCould not parse event: {e}"),
|
| Err(e) => return Err!("EventId: {event_id:?}\nCould not parse event: {e}"),
|
||||||
| Ok(pdu) => write!(self, "EventId: {event_id:?}\n{pdu:#?}"),
|
| Ok(pdu) => write!(self, "EventId: {event_id:?}\n{pdu:#?}"),
|
||||||
@@ -119,7 +121,7 @@ pub(super) async fn get_pdu(&self, event_id: OwnedEventId) -> Result {
|
|||||||
} else {
|
} else {
|
||||||
"PDU found in our database"
|
"PDU found in our database"
|
||||||
};
|
};
|
||||||
write!(self, "{msg}\n```json\n{text}\n```",)
|
write!(self, "{msg}\n```json\n{text}\n```")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
@@ -187,10 +189,7 @@ pub(super) async fn get_remote_pdu_list(&self, server: OwnedServerName, force: b
|
|||||||
|
|
||||||
for event_id in list {
|
for event_id in list {
|
||||||
if force {
|
if force {
|
||||||
match self
|
match self.get_remote_pdu(event_id.clone(), server.clone()).await {
|
||||||
.get_remote_pdu(event_id.to_owned(), server.clone())
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
failed_count = failed_count.saturating_add(1);
|
failed_count = failed_count.saturating_add(1);
|
||||||
self.services
|
self.services
|
||||||
@@ -205,7 +204,7 @@ pub(super) async fn get_remote_pdu_list(&self, server: OwnedServerName, force: b
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.get_remote_pdu(event_id.to_owned(), server.clone())
|
self.get_remote_pdu(event_id.clone(), server.clone())
|
||||||
.await?;
|
.await?;
|
||||||
success_count = success_count.saturating_add(1);
|
success_count = success_count.saturating_add(1);
|
||||||
}
|
}
|
||||||
@@ -237,10 +236,10 @@ pub(super) async fn get_remote_pdu(
|
|||||||
match self
|
match self
|
||||||
.services
|
.services
|
||||||
.sending
|
.sending
|
||||||
.send_federation_request(&server, ruma::api::federation::event::get_event::v1::Request {
|
.send_federation_request(
|
||||||
event_id: event_id.clone(),
|
&server,
|
||||||
include_unredacted_content: None,
|
ruma::api::federation::event::get_event::v1::Request::new(event_id.clone()),
|
||||||
})
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
@@ -330,9 +329,9 @@ pub(super) async fn ping(&self, server: OwnedServerName) -> Result {
|
|||||||
match self
|
match self
|
||||||
.services
|
.services
|
||||||
.sending
|
.sending
|
||||||
.send_federation_request(
|
.send_unauthenticated_request(
|
||||||
&server,
|
&server,
|
||||||
ruma::api::federation::discovery::get_server_version::v1::Request {},
|
ruma::api::federation::discovery::get_server_version::v1::Request::new(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -361,7 +360,7 @@ pub(super) async fn force_device_list_updates(&self) -> Result {
|
|||||||
self.services
|
self.services
|
||||||
.users
|
.users
|
||||||
.stream()
|
.stream()
|
||||||
.for_each(|user_id| self.services.users.mark_device_key_update(user_id))
|
.for_each(async |user_id| self.services.users.mark_device_key_update(&user_id).await)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
write!(self, "Marked all devices for all users as having new keys to update").await
|
write!(self, "Marked all devices for all users as having new keys to update").await
|
||||||
@@ -430,9 +429,16 @@ pub(super) async fn verify_json(&self) -> Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let string = self.body[1..self.body.len().checked_sub(1).unwrap()].join("\n");
|
let string = self.body[1..self.body.len().checked_sub(1).unwrap()].join("\n");
|
||||||
|
let room_version_rules = RoomVersionId::V12.rules().unwrap();
|
||||||
|
|
||||||
match serde_json::from_str::<CanonicalJsonObject>(&string) {
|
match serde_json::from_str::<CanonicalJsonObject>(&string) {
|
||||||
| Err(e) => return Err!("Invalid json: {e}"),
|
| Err(e) => return Err!("Invalid json: {e}"),
|
||||||
| Ok(value) => match self.services.server_keys.verify_json(&value, None).await {
|
| Ok(value) => match self
|
||||||
|
.services
|
||||||
|
.server_keys
|
||||||
|
.verify_json(&value, &room_version_rules)
|
||||||
|
.await
|
||||||
|
{
|
||||||
| Err(e) => return Err!("Signature verification failed: {e}"),
|
| Err(e) => return Err!("Signature verification failed: {e}"),
|
||||||
| Ok(()) => write!(self, "Signature correct"),
|
| Ok(()) => write!(self, "Signature correct"),
|
||||||
},
|
},
|
||||||
@@ -445,9 +451,15 @@ pub(super) async fn verify_pdu(&self, event_id: OwnedEventId) -> Result {
|
|||||||
use ruma::signatures::Verified;
|
use ruma::signatures::Verified;
|
||||||
|
|
||||||
let mut event = self.services.rooms.timeline.get_pdu_json(&event_id).await?;
|
let mut event = self.services.rooms.timeline.get_pdu_json(&event_id).await?;
|
||||||
|
let room_version_rules = RoomVersionId::V12.rules().unwrap();
|
||||||
|
|
||||||
event.remove("event_id");
|
event.remove("event_id");
|
||||||
let msg = match self.services.server_keys.verify_event(&event, None).await {
|
let msg = match self
|
||||||
|
.services
|
||||||
|
.server_keys
|
||||||
|
.verify_event(&event, &room_version_rules)
|
||||||
|
.await
|
||||||
|
{
|
||||||
| Err(e) => return Err(e),
|
| Err(e) => return Err(e),
|
||||||
| Ok(Verified::Signatures) => "signatures OK, but content hash failed (redaction).",
|
| Ok(Verified::Signatures) => "signatures OK, but content hash failed (redaction).",
|
||||||
| Ok(Verified::All) => "signatures and hashes OK.",
|
| Ok(Verified::All) => "signatures and hashes OK.",
|
||||||
@@ -544,16 +556,17 @@ pub(super) async fn force_set_room_state_from_server(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let room_version = self.services.rooms.state.get_room_version(&room_id).await?;
|
let room_version = self.services.rooms.state.get_room_version(&room_id).await?;
|
||||||
|
let room_version_rules = room_version.rules().unwrap();
|
||||||
|
|
||||||
let mut state: HashMap<u64, OwnedEventId> = HashMap::new();
|
let mut state: HashMap<u64, OwnedEventId> = HashMap::new();
|
||||||
|
|
||||||
let remote_state_response = self
|
let remote_state_response = self
|
||||||
.services
|
.services
|
||||||
.sending
|
.sending
|
||||||
.send_federation_request(&server_name, get_room_state::v1::Request {
|
.send_federation_request(
|
||||||
room_id: room_id.clone(),
|
&server_name,
|
||||||
event_id: at_event_id,
|
get_room_state::v1::Request::new(at_event_id, room_id.clone()),
|
||||||
})
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for pdu in remote_state_response.pdus.clone() {
|
for pdu in remote_state_response.pdus.clone() {
|
||||||
@@ -576,7 +589,7 @@ pub(super) async fn force_set_room_state_from_server(
|
|||||||
for result in remote_state_response.pdus.iter().map(|pdu| {
|
for result in remote_state_response.pdus.iter().map(|pdu| {
|
||||||
self.services
|
self.services
|
||||||
.server_keys
|
.server_keys
|
||||||
.validate_and_add_event_id(pdu, &room_version)
|
.validate_and_add_event_id(pdu, &room_version_rules)
|
||||||
}) {
|
}) {
|
||||||
let Ok((event_id, value)) = result.await else {
|
let Ok((event_id, value)) = result.await else {
|
||||||
continue;
|
continue;
|
||||||
@@ -608,7 +621,7 @@ pub(super) async fn force_set_room_state_from_server(
|
|||||||
for result in remote_state_response.auth_chain.iter().map(|pdu| {
|
for result in remote_state_response.auth_chain.iter().map(|pdu| {
|
||||||
self.services
|
self.services
|
||||||
.server_keys
|
.server_keys
|
||||||
.validate_and_add_event_id(pdu, &room_version)
|
.validate_and_add_event_id(pdu, &room_version_rules)
|
||||||
}) {
|
}) {
|
||||||
let Ok((event_id, value)) = result.await else {
|
let Ok((event_id, value)) = result.await else {
|
||||||
continue;
|
continue;
|
||||||
@@ -625,7 +638,7 @@ pub(super) async fn force_set_room_state_from_server(
|
|||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
.event_handler
|
.event_handler
|
||||||
.resolve_state(&room_id, &room_version, state)
|
.resolve_state(&room_id, &room_version_rules, state)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
info!("Compressing new room state");
|
info!("Compressing new room state");
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ pub(super) async fn remote_user_in_rooms(&self, user_id: OwnedUserId) -> Result
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.rooms_joined(&user_id)
|
.rooms_joined(&user_id)
|
||||||
.then(|room_id| get_room_info(self.services, room_id))
|
.then(async |room_id| get_room_info(self.services, &room_id).await)
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -129,6 +129,6 @@ pub(super) async fn remote_user_in_rooms(&self, user_id: OwnedUserId) -> Result
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
self.write_str(&format!("Rooms {user_id} shares with us ({num}):\n```\n{body}\n```",))
|
self.write_str(&format!("Rooms {user_id} shares with us ({num}):\n```\n{body}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,8 @@ use conduwuit::{
|
|||||||
warn,
|
warn,
|
||||||
};
|
};
|
||||||
use conduwuit_service::media::Dim;
|
use conduwuit_service::media::Dim;
|
||||||
use ruma::{Mxc, OwnedEventId, OwnedMxcUri, OwnedServerName};
|
use ruma::{OwnedEventId, OwnedMxcUri, OwnedServerName};
|
||||||
|
use service::media::mxc::Mxc;
|
||||||
|
|
||||||
use crate::{admin_command, utils::parse_local_user_id};
|
use crate::{admin_command, utils::parse_local_user_id};
|
||||||
|
|
||||||
@@ -261,7 +262,7 @@ pub(super) async fn delete_past_remote_media(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.write_str(&format!("Deleted {deleted_count} total files.",))
|
self.write_str(&format!("Deleted {deleted_count} total files."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,7 +272,7 @@ pub(super) async fn delete_all_from_user(&self, username: String) -> Result {
|
|||||||
|
|
||||||
let deleted_count = self.services.media.delete_from_user(&user_id).await?;
|
let deleted_count = self.services.media.delete_from_user(&user_id).await?;
|
||||||
|
|
||||||
self.write_str(&format!("Deleted {deleted_count} total files.",))
|
self.write_str(&format!("Deleted {deleted_count} total files."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,7 +331,7 @@ pub(super) async fn delete_all_from_server(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.write_str(&format!("Deleted {deleted_count} total files.",))
|
self.write_str(&format!("Deleted {deleted_count} total files."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#![allow(clippy::enum_glob_use)]
|
#![allow(clippy::enum_glob_use)]
|
||||||
#![allow(clippy::too_many_arguments)]
|
#![allow(clippy::too_many_arguments)]
|
||||||
|
|
||||||
|
conduwuit_macros::introspect_crate! {}
|
||||||
|
|
||||||
pub(crate) mod admin;
|
pub(crate) mod admin;
|
||||||
pub(crate) mod context;
|
pub(crate) mod context;
|
||||||
pub(crate) mod processor;
|
pub(crate) mod processor;
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ use futures::{AsyncWriteExt, future::FutureExt, io::BufWriter};
|
|||||||
use ruma::{
|
use ruma::{
|
||||||
EventId,
|
EventId,
|
||||||
events::{
|
events::{
|
||||||
relation::InReplyTo,
|
relation::{InReplyTo, Reply},
|
||||||
room::message::{Relation::Reply, RoomMessageEventContent},
|
room::message::{Relation, RoomMessageEventContent},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use service::{
|
use service::{
|
||||||
@@ -38,6 +38,7 @@ pub(super) fn dispatch(services: Arc<Services>, command: CommandInput) -> Proces
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, name = "admin", level = "info")]
|
#[tracing::instrument(skip_all, name = "admin", level = "info")]
|
||||||
|
#[allow(clippy::result_large_err)]
|
||||||
async fn handle_command(services: Arc<Services>, command: CommandInput) -> ProcessorResult {
|
async fn handle_command(services: Arc<Services>, command: CommandInput) -> ProcessorResult {
|
||||||
AssertUnwindSafe(Box::pin(process_command(services, &command)))
|
AssertUnwindSafe(Box::pin(process_command(services, &command)))
|
||||||
.catch_unwind()
|
.catch_unwind()
|
||||||
@@ -277,9 +278,8 @@ fn reply(
|
|||||||
mut content: RoomMessageEventContent,
|
mut content: RoomMessageEventContent,
|
||||||
reply_id: Option<&EventId>,
|
reply_id: Option<&EventId>,
|
||||||
) -> RoomMessageEventContent {
|
) -> RoomMessageEventContent {
|
||||||
content.relates_to = reply_id.map(|event_id| Reply {
|
content.relates_to =
|
||||||
in_reply_to: InReplyTo { event_id: event_id.to_owned() },
|
reply_id.map(|event_id| Relation::Reply(Reply::new(InReplyTo::new(event_id.to_owned()))));
|
||||||
});
|
|
||||||
|
|
||||||
content
|
content
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ async fn destinations_cache(&self, server_name: Option<OwnedServerName>) -> Resu
|
|||||||
|
|
||||||
while let Some((name, CachedDest { dest, host, expire })) = destinations.next().await {
|
while let Some((name, CachedDest { dest, host, expire })) = destinations.next().await {
|
||||||
if let Some(server_name) = server_name.as_ref() {
|
if let Some(server_name) = server_name.as_ref() {
|
||||||
if name != server_name {
|
if name != *server_name {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ async fn overrides_cache(&self, server_name: Option<String>) -> Result {
|
|||||||
overrides.next().await
|
overrides.next().await
|
||||||
{
|
{
|
||||||
if let Some(server_name) = server_name.as_ref() {
|
if let Some(server_name) = server_name.as_ref() {
|
||||||
if name != server_name {
|
if name != *server_name {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ pub(super) async fn process(subcommand: RoomAliasCommand, context: &Context<'_>)
|
|||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.local_aliases_for_room(&room_id)
|
.local_aliases_for_room(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
@@ -54,7 +53,7 @@ pub(super) async fn process(subcommand: RoomAliasCommand, context: &Context<'_>)
|
|||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.all_local_aliases()
|
.all_local_aliases()
|
||||||
.map(|(room_id, alias)| (room_id.to_owned(), alias.to_owned()))
|
.map(|(room_id, alias)| (room_id, alias.to_owned()))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.room_servers(&room_id)
|
.room_servers(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
@@ -118,7 +117,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.server_rooms(&server)
|
.server_rooms(&server)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
@@ -135,7 +133,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.room_members(&room_id)
|
.room_members(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
@@ -152,7 +149,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.local_users_in_room(&room_id)
|
.local_users_in_room(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
@@ -169,7 +165,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.active_local_users_in_room(&room_id)
|
.active_local_users_in_room(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
@@ -212,7 +207,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.room_useroncejoined(&room_id)
|
.room_useroncejoined(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
@@ -229,7 +223,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.room_members_invited(&room_id)
|
.room_members_invited(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
@@ -276,7 +269,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.rooms_joined(&user_id)
|
.rooms_joined(&user_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ async fn get_shared_rooms(&self, user_a: OwnedUserId, user_b: OwnedUserId) -> Re
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.get_shared_rooms(&user_a, &user_b)
|
.get_shared_rooms(&user_a, &user_b)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
@@ -217,8 +216,7 @@ async fn iter_users2(&self) -> Result {
|
|||||||
let result: Vec<_> = self.services.users.stream().collect().await;
|
let result: Vec<_> = self.services.users.stream().collect().await;
|
||||||
let result: Vec<_> = result
|
let result: Vec<_> = result
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(ruma::UserId::as_bytes)
|
.map(|user_id| String::from_utf8_lossy(user_id.as_bytes()).into_owned())
|
||||||
.map(String::from_utf8_lossy)
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
@@ -254,7 +252,6 @@ async fn list_devices(&self, user_id: OwnedUserId) -> Result {
|
|||||||
.services
|
.services
|
||||||
.users
|
.users
|
||||||
.all_device_ids(&user_id)
|
.all_device_ids(&user_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::fmt::Write;
|
|||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use conduwuit::{Err, Result};
|
use conduwuit::{Err, Result};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::{OwnedRoomAliasId, OwnedRoomId};
|
use ruma::{OwnedRoomAliasId, OwnedRoomId, RoomAliasId};
|
||||||
|
|
||||||
use crate::Context;
|
use crate::Context;
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ pub(super) async fn process(command: RoomAliasCommand, context: &Context<'_>) ->
|
|||||||
| RoomAliasCommand::Which { ref room_alias_localpart } => {
|
| RoomAliasCommand::Which { ref room_alias_localpart } => {
|
||||||
let room_alias_str =
|
let room_alias_str =
|
||||||
format!("#{}:{}", room_alias_localpart, services.globals.server_name());
|
format!("#{}:{}", room_alias_localpart, services.globals.server_name());
|
||||||
let room_alias = match OwnedRoomAliasId::parse(room_alias_str) {
|
let room_alias = match RoomAliasId::parse(room_alias_str) {
|
||||||
| Ok(alias) => alias,
|
| Ok(alias) => alias,
|
||||||
| Err(err) => {
|
| Err(err) => {
|
||||||
return Err!("Failed to parse alias: {err}");
|
return Err!("Failed to parse alias: {err}");
|
||||||
@@ -139,7 +139,7 @@ pub(super) async fn process(command: RoomAliasCommand, context: &Context<'_>) ->
|
|||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.all_local_aliases()
|
.all_local_aliases()
|
||||||
.map(|(room_id, localpart)| (room_id.into(), localpart.into()))
|
.map(|(room_id, localpart)| (room_id, localpart.into()))
|
||||||
.collect::<Vec<(OwnedRoomId, String)>>()
|
.collect::<Vec<(OwnedRoomId, String)>>()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ pub(super) async fn list_rooms(
|
|||||||
.metadata
|
.metadata
|
||||||
.iter_ids()
|
.iter_ids()
|
||||||
.filter_map(|room_id| async move {
|
.filter_map(|room_id| async move {
|
||||||
(!exclude_disabled || !self.services.rooms.metadata.is_disabled(room_id).await)
|
(!exclude_disabled || !self.services.rooms.metadata.is_disabled(&room_id).await)
|
||||||
.then_some(room_id)
|
.then_some(room_id)
|
||||||
})
|
})
|
||||||
.filter_map(|room_id| async move {
|
.filter_map(|room_id| async move {
|
||||||
(!exclude_banned || !self.services.rooms.metadata.is_banned(room_id).await)
|
(!exclude_banned || !self.services.rooms.metadata.is_banned(&room_id).await)
|
||||||
.then_some(room_id)
|
.then_some(room_id)
|
||||||
})
|
})
|
||||||
.then(|room_id| get_room_info(self.services, room_id))
|
.then(async |room_id| get_room_info(self.services, &room_id).await)
|
||||||
.then(|(room_id, total_members, name)| async move {
|
.then(|(room_id, total_members, name)| async move {
|
||||||
let local_members: Vec<_> = self
|
let local_members: Vec<_> = self
|
||||||
.services
|
.services
|
||||||
@@ -72,7 +72,7 @@ pub(super) async fn list_rooms(
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
self.write_str(&format!("Rooms ({}):\n```\n{body}\n```", rooms.len(),))
|
self.write_str(&format!("Rooms ({}):\n```\n{body}\n```", rooms.len()))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ pub(super) async fn process(command: RoomDirectoryCommand, context: &Context<'_>
|
|||||||
.rooms
|
.rooms
|
||||||
.directory
|
.directory
|
||||||
.public_rooms()
|
.public_rooms()
|
||||||
.then(|room_id| get_room_info(services, room_id))
|
.then(async |room_id| get_room_info(services, &room_id).await)
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ pub(super) async fn process(command: RoomDirectoryCommand, context: &Context<'_>
|
|||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
context
|
context
|
||||||
.write_str(&format!("Rooms (page {page}):\n```\n{body}\n```",))
|
.write_str(&format!("Rooms (page {page}):\n```\n{body}\n```"))
|
||||||
.await
|
.await
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ async fn list_joined_members(&self, room_id: OwnedRoomId, local_only: bool) -> R
|
|||||||
.then(|| self.services.globals.user_is_local(user_id))
|
.then(|| self.services.globals.user_is_local(user_id))
|
||||||
.unwrap_or(true)
|
.unwrap_or(true)
|
||||||
})
|
})
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.filter_map(|user_id| async move {
|
.filter_map(|user_id| async move {
|
||||||
Some((
|
Some((
|
||||||
self.services
|
self.services
|
||||||
@@ -67,7 +66,7 @@ async fn list_joined_members(&self, room_id: OwnedRoomId, local_only: bool) -> R
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
self.write_str(&format!("{num} Members in Room \"{room_name}\":\n```\n{body}\n```",))
|
self.write_str(&format!("{num} Members in Room \"{room_name}\":\n```\n{body}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
|||||||
|
|
||||||
debug!("Room specified is a room ID, banning room ID");
|
debug!("Room specified is a room ID, banning room ID");
|
||||||
|
|
||||||
room_id.to_owned()
|
room_id.clone()
|
||||||
} else if room.is_room_alias_id() {
|
} else if room.is_room_alias_id() {
|
||||||
let room_alias = match RoomAliasId::parse(&room) {
|
let room_alias = match RoomAliasId::parse(&room) {
|
||||||
| Ok(room_alias) => room_alias,
|
| Ok(room_alias) => room_alias,
|
||||||
@@ -89,7 +89,7 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
|||||||
locally, if not using get_alias_helper to fetch room ID remotely"
|
locally, if not using get_alias_helper to fetch room ID remotely"
|
||||||
);
|
);
|
||||||
|
|
||||||
match self.services.rooms.alias.resolve_alias(room_alias).await {
|
match self.services.rooms.alias.resolve_alias(&room_alias).await {
|
||||||
| Ok((room_id, servers)) => {
|
| Ok((room_id, servers)) => {
|
||||||
debug!(
|
debug!(
|
||||||
%room_id,
|
%room_id,
|
||||||
@@ -116,7 +116,6 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.room_members(&room_id)
|
.room_members(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.ready_filter(|user| self.services.globals.user_is_local(user))
|
.ready_filter(|user| self.services.globals.user_is_local(user))
|
||||||
.boxed();
|
.boxed();
|
||||||
|
|
||||||
@@ -140,7 +139,6 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
|||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.local_aliases_for_room(&room_id)
|
.local_aliases_for_room(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.for_each(|local_alias| async move {
|
.for_each(|local_alias| async move {
|
||||||
self.services
|
self.services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -205,7 +203,7 @@ async fn ban_list_of_rooms(&self) -> Result {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
room_ids.push(room_id.to_owned());
|
room_ids.push(room_id.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if room_alias_or_id.is_room_alias_id() {
|
if room_alias_or_id.is_room_alias_id() {
|
||||||
@@ -215,7 +213,7 @@ async fn ban_list_of_rooms(&self) -> Result {
|
|||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.resolve_local_alias(room_alias)
|
.resolve_local_alias(&room_alias)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
| Ok(room_id) => room_id,
|
| Ok(room_id) => room_id,
|
||||||
@@ -229,7 +227,7 @@ async fn ban_list_of_rooms(&self) -> Result {
|
|||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.resolve_alias(room_alias)
|
.resolve_alias(&room_alias)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
| Ok((room_id, servers)) => {
|
| Ok((room_id, servers)) => {
|
||||||
@@ -284,7 +282,6 @@ async fn ban_list_of_rooms(&self) -> Result {
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.room_members(&room_id)
|
.room_members(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.ready_filter(|user| self.services.globals.user_is_local(user))
|
.ready_filter(|user| self.services.globals.user_is_local(user))
|
||||||
.boxed();
|
.boxed();
|
||||||
|
|
||||||
@@ -309,7 +306,6 @@ async fn ban_list_of_rooms(&self) -> Result {
|
|||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.local_aliases_for_room(&room_id)
|
.local_aliases_for_room(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.for_each(|local_alias| async move {
|
.for_each(|local_alias| async move {
|
||||||
self.services
|
self.services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -348,9 +344,9 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
|||||||
};
|
};
|
||||||
|
|
||||||
debug!("Room specified is a room ID, unbanning room ID");
|
debug!("Room specified is a room ID, unbanning room ID");
|
||||||
self.services.rooms.metadata.ban_room(room_id, false);
|
self.services.rooms.metadata.ban_room(&room_id, false);
|
||||||
|
|
||||||
room_id.to_owned()
|
room_id.clone()
|
||||||
} else if room.is_room_alias_id() {
|
} else if room.is_room_alias_id() {
|
||||||
let room_alias = match RoomAliasId::parse(&room) {
|
let room_alias = match RoomAliasId::parse(&room) {
|
||||||
| Ok(room_alias) => room_alias,
|
| Ok(room_alias) => room_alias,
|
||||||
@@ -372,7 +368,7 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
|||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.resolve_local_alias(room_alias)
|
.resolve_local_alias(&room_alias)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
| Ok(room_id) => room_id,
|
| Ok(room_id) => room_id,
|
||||||
@@ -382,7 +378,7 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
|||||||
room ID over federation"
|
room ID over federation"
|
||||||
);
|
);
|
||||||
|
|
||||||
match self.services.rooms.alias.resolve_alias(room_alias).await {
|
match self.services.rooms.alias.resolve_alias(&room_alias).await {
|
||||||
| Ok((room_id, servers)) => {
|
| Ok((room_id, servers)) => {
|
||||||
debug!(
|
debug!(
|
||||||
%room_id,
|
%room_id,
|
||||||
@@ -453,6 +449,6 @@ async fn list_banned_rooms(&self, no_details: bool) -> Result {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
self.write_str(&format!("Rooms Banned ({num}):\n```\n{body}\n```",))
|
self.write_str(&format!("Rooms Banned ({num}):\n```\n{body}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::{path::PathBuf, sync::Arc};
|
use std::{fmt::Write, path::PathBuf, sync::Arc};
|
||||||
|
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result,
|
Err, Result,
|
||||||
@@ -153,3 +153,97 @@ pub(super) async fn shutdown(&self) -> Result {
|
|||||||
|
|
||||||
self.write_str("Shutting down server...").await
|
self.write_str("Shutting down server...").await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[admin_command]
|
||||||
|
pub(super) async fn list_features(&self) -> Result {
|
||||||
|
let mut enabled_features = conduwuit::info::introspection::ENABLED_FEATURES
|
||||||
|
.lock()
|
||||||
|
.expect("locked")
|
||||||
|
.values()
|
||||||
|
.flat_map(|f| f.iter())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
enabled_features.sort_unstable();
|
||||||
|
enabled_features.dedup();
|
||||||
|
|
||||||
|
let mut available_features = conduwuit::build_metadata::WORKSPACE_FEATURES
|
||||||
|
.iter()
|
||||||
|
.flat_map(|(_, f)| f.iter())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
available_features.sort_unstable();
|
||||||
|
available_features.dedup();
|
||||||
|
|
||||||
|
let mut features = String::new();
|
||||||
|
|
||||||
|
for feature in available_features {
|
||||||
|
let active = enabled_features.contains(&feature);
|
||||||
|
let emoji = if active { "✅" } else { "❌" };
|
||||||
|
let remark = if active { "[enabled]" } else { "" };
|
||||||
|
writeln!(features, "{emoji} {feature} {remark}")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.write_str(&features).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[admin_command]
|
||||||
|
pub(super) async fn build_info(&self) -> Result {
|
||||||
|
use conduwuit::build_metadata::built;
|
||||||
|
|
||||||
|
let mut info = String::new();
|
||||||
|
|
||||||
|
// Version information
|
||||||
|
writeln!(info, "# Build Information\n")?;
|
||||||
|
writeln!(info, "**Version:** {}", built::PKG_VERSION)?;
|
||||||
|
writeln!(info, "**Package:** {}", built::PKG_NAME)?;
|
||||||
|
writeln!(info, "**Description:** {}", built::PKG_DESCRIPTION)?;
|
||||||
|
|
||||||
|
// Git information
|
||||||
|
writeln!(info, "\n## Git Information\n")?;
|
||||||
|
if let Some(hash) = conduwuit::build_metadata::GIT_COMMIT_HASH {
|
||||||
|
writeln!(info, "**Commit Hash:** {hash}")?;
|
||||||
|
}
|
||||||
|
if let Some(hash) = conduwuit::build_metadata::GIT_COMMIT_HASH_SHORT {
|
||||||
|
writeln!(info, "**Commit Hash (short):** {hash}")?;
|
||||||
|
}
|
||||||
|
if let Some(url) = conduwuit::build_metadata::GIT_REMOTE_WEB_URL {
|
||||||
|
writeln!(info, "**Repository:** {url}")?;
|
||||||
|
}
|
||||||
|
if let Some(url) = conduwuit::build_metadata::GIT_REMOTE_COMMIT_URL {
|
||||||
|
writeln!(info, "**Commit URL:** {url}")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build environment
|
||||||
|
writeln!(info, "\n## Build Environment\n")?;
|
||||||
|
writeln!(info, "**Profile:** {}", built::PROFILE)?;
|
||||||
|
writeln!(info, "**Optimization Level:** {}", built::OPT_LEVEL)?;
|
||||||
|
writeln!(info, "**Debug:** {}", built::DEBUG)?;
|
||||||
|
writeln!(info, "**Target:** {}", built::TARGET)?;
|
||||||
|
writeln!(info, "**Host:** {}", built::HOST)?;
|
||||||
|
|
||||||
|
// Rust compiler information
|
||||||
|
writeln!(info, "\n## Compiler Information\n")?;
|
||||||
|
writeln!(info, "**Rustc Version:** {}", built::RUSTC_VERSION)?;
|
||||||
|
if !built::RUSTDOC_VERSION.is_empty() {
|
||||||
|
writeln!(info, "**Rustdoc Version:** {}", built::RUSTDOC_VERSION)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Target configuration
|
||||||
|
writeln!(info, "\n## Target Configuration\n")?;
|
||||||
|
writeln!(info, "**Architecture:** {}", built::CFG_TARGET_ARCH)?;
|
||||||
|
writeln!(info, "**OS:** {}", built::CFG_OS)?;
|
||||||
|
writeln!(info, "**Family:** {}", built::CFG_FAMILY)?;
|
||||||
|
writeln!(info, "**Endianness:** {}", built::CFG_ENDIAN)?;
|
||||||
|
writeln!(info, "**Pointer Width:** {} bits", built::CFG_POINTER_WIDTH)?;
|
||||||
|
if !built::CFG_ENV.is_empty() {
|
||||||
|
writeln!(info, "**Environment:** {}", built::CFG_ENV)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// CI information
|
||||||
|
if let Some(ci) = built::CI_PLATFORM {
|
||||||
|
writeln!(info, "\n## CI Platform\n")?;
|
||||||
|
writeln!(info, "**Platform:** {ci}")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.write_str(&info).await
|
||||||
|
}
|
||||||
@@ -52,4 +52,10 @@ pub enum ServerCommand {
|
|||||||
|
|
||||||
/// Shutdown the server
|
/// Shutdown the server
|
||||||
Shutdown,
|
Shutdown,
|
||||||
|
|
||||||
|
/// List features built into the server
|
||||||
|
ListFeatures,
|
||||||
|
|
||||||
|
/// Build information
|
||||||
|
BuildInfo,
|
||||||
}
|
}
|
||||||
+55
-63
@@ -9,20 +9,18 @@ use api::client::{
|
|||||||
};
|
};
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, debug_warn, error, info,
|
Err, Result, debug_warn, error, info,
|
||||||
matrix::{Event, pdu::PduBuilder},
|
matrix::{Event, pdu::PartialPdu},
|
||||||
utils::{self, ReadyExt},
|
utils::{self, ReadyExt},
|
||||||
warn,
|
warn,
|
||||||
};
|
};
|
||||||
use futures::{FutureExt, StreamExt};
|
use futures::{FutureExt, StreamExt};
|
||||||
use lettre::Address;
|
use lettre::Address;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, UserId,
|
OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, ServerName,
|
||||||
|
UserId, assign,
|
||||||
events::{
|
events::{
|
||||||
RoomAccountDataEventType, StateEventType,
|
RoomAccountDataEventType,
|
||||||
room::{
|
room::{power_levels::RoomPowerLevelsEventContent, redaction::RoomRedactionEventContent},
|
||||||
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
|
|
||||||
redaction::RoomRedactionEventContent,
|
|
||||||
},
|
|
||||||
tag::{TagEvent, TagEventContent, TagInfo},
|
tag::{TagEvent, TagEventContent, TagInfo},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -41,7 +39,7 @@ pub(super) async fn list_users(&self) -> Result {
|
|||||||
.services
|
.services
|
||||||
.users
|
.users
|
||||||
.list_local_users()
|
.list_local_users()
|
||||||
.map(ToString::to_string)
|
.map(|id| id.as_str().to_owned())
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -103,11 +101,12 @@ pub(super) async fn create_user(&self, username: String, password: Option<String
|
|||||||
ruma::events::GlobalAccountDataEventType::PushRules
|
ruma::events::GlobalAccountDataEventType::PushRules
|
||||||
.to_string()
|
.to_string()
|
||||||
.into(),
|
.into(),
|
||||||
&serde_json::to_value(ruma::events::push_rules::PushRulesEvent {
|
&serde_json::to_value(ruma::events::push_rules::PushRulesEvent::new(
|
||||||
content: ruma::events::push_rules::PushRulesEventContent {
|
ruma::events::push_rules::PushRulesEventContent::new(
|
||||||
global: ruma::push::Ruleset::server_default(&user_id),
|
ruma::push::Ruleset::server_default(&user_id),
|
||||||
},
|
),
|
||||||
})?,
|
))
|
||||||
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -292,7 +291,12 @@ pub(super) async fn reset_password(
|
|||||||
self.services
|
self.services
|
||||||
.users
|
.users
|
||||||
.all_device_ids(&user_id)
|
.all_device_ids(&user_id)
|
||||||
.for_each(|device_id| self.services.users.remove_device(&user_id, device_id))
|
.for_each(async |device_id| {
|
||||||
|
self.services
|
||||||
|
.users
|
||||||
|
.remove_device(&user_id, &device_id)
|
||||||
|
.await;
|
||||||
|
})
|
||||||
.await;
|
.await;
|
||||||
write!(self, "\nAll existing sessions have been logged out.").await?;
|
write!(self, "\nAll existing sessions have been logged out.").await?;
|
||||||
}
|
}
|
||||||
@@ -437,7 +441,7 @@ pub(super) async fn list_joined_rooms(&self, user_id: String) -> Result {
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.rooms_joined(&user_id)
|
.rooms_joined(&user_id)
|
||||||
.then(|room_id| get_room_info(self.services, room_id))
|
.then(async |room_id| get_room_info(self.services, &room_id).await)
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -454,7 +458,7 @@ pub(super) async fn list_joined_rooms(&self, user_id: String) -> Result {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
self.write_str(&format!("Rooms {user_id} Joined ({}):\n```\n{body}\n```", rooms.len(),))
|
self.write_str(&format!("Rooms {user_id} Joined ({}):\n```\n{body}\n```", rooms.len()))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,7 +510,7 @@ pub(super) async fn force_join_list_of_local_users(
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.room_members(&room_id)
|
.room_members(&room_id)
|
||||||
.ready_any(|user_id| server_admins.contains(&user_id.to_owned()))
|
.ready_any(|user_id| server_admins.contains(&user_id))
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
return Err!("There is not a single server admin in the room.",);
|
return Err!("There is not a single server admin in the room.",);
|
||||||
@@ -620,7 +624,7 @@ pub(super) async fn force_join_all_local_users(
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.room_members(&room_id)
|
.room_members(&room_id)
|
||||||
.ready_any(|user_id| server_admins.contains(&user_id.to_owned()))
|
.ready_any(|user_id| server_admins.contains(&user_id))
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
return Err!("There is not a single server admin in the room.",);
|
return Err!("There is not a single server admin in the room.",);
|
||||||
@@ -633,7 +637,6 @@ pub(super) async fn force_join_all_local_users(
|
|||||||
.services
|
.services
|
||||||
.users
|
.users
|
||||||
.list_local_users()
|
.list_local_users()
|
||||||
.map(UserId::to_owned)
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -684,7 +687,7 @@ pub(super) async fn force_join_room(
|
|||||||
);
|
);
|
||||||
join_room_by_id_helper(self.services, &user_id, &room_id, None, &servers, &None).await?;
|
join_room_by_id_helper(self.services, &user_id, &room_id, None, &servers, &None).await?;
|
||||||
|
|
||||||
self.write_str(&format!("{user_id} has been joined to {room_id}.",))
|
self.write_str(&format!("{user_id} has been joined to {room_id}."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -716,7 +719,7 @@ pub(super) async fn force_leave_room(
|
|||||||
.boxed()
|
.boxed()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.write_str(&format!("{user_id} has left {room_id}.",))
|
self.write_str(&format!("{user_id} has left {room_id}."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -730,42 +733,34 @@ pub(super) async fn force_demote(&self, user_id: String, room_id: OwnedRoomOrAli
|
|||||||
"Parsed user_id must be a local user"
|
"Parsed user_id must be a local user"
|
||||||
);
|
);
|
||||||
|
|
||||||
let state_lock = self.services.rooms.state.mutex.lock(&room_id).await;
|
let state_lock = self.services.rooms.state.mutex.lock(room_id.as_str()).await;
|
||||||
|
|
||||||
let room_power_levels: Option<RoomPowerLevelsEventContent> = self
|
let mut room_power_levels = self
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.room_state_get_content(&room_id, &StateEventType::RoomPowerLevels, "")
|
.get_room_power_levels(&room_id)
|
||||||
.await
|
.await;
|
||||||
.ok();
|
|
||||||
|
|
||||||
let user_can_demote_self = room_power_levels
|
let user_can_demote_self =
|
||||||
.as_ref()
|
room_power_levels.user_can_change_user_power_level(&user_id, &user_id);
|
||||||
.is_some_and(|power_levels_content| {
|
|
||||||
RoomPowerLevels::from(power_levels_content.clone())
|
|
||||||
.user_can_change_user_power_level(&user_id, &user_id)
|
|
||||||
}) || self
|
|
||||||
.services
|
|
||||||
.rooms
|
|
||||||
.state_accessor
|
|
||||||
.room_state_get(&room_id, &StateEventType::RoomCreate, "")
|
|
||||||
.await
|
|
||||||
.is_ok_and(|event| event.sender() == user_id);
|
|
||||||
|
|
||||||
if !user_can_demote_self {
|
if !user_can_demote_self {
|
||||||
return Err!("User is not allowed to modify their own power levels in the room.",);
|
return Err!("User is not allowed to modify their own power levels in the room.",);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut power_levels_content = room_power_levels.unwrap_or_default();
|
room_power_levels.users.remove(&user_id);
|
||||||
power_levels_content.users.remove(&user_id);
|
|
||||||
|
|
||||||
let event_id = self
|
let event_id = self
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PduBuilder::state(String::new(), &power_levels_content),
|
PartialPdu::state(
|
||||||
|
String::new(),
|
||||||
|
&RoomPowerLevelsEventContent::try_from(room_power_levels)
|
||||||
|
.expect("PLs should be valid for room version"),
|
||||||
|
),
|
||||||
&user_id,
|
&user_id,
|
||||||
Some(&room_id),
|
Some(&room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -793,7 +788,7 @@ pub(super) async fn make_user_admin(&self, user_id: String) -> Result {
|
|||||||
.boxed()
|
.boxed()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.write_str(&format!("{user_id} has been granted admin privileges.",))
|
self.write_str(&format!("{user_id} has been granted admin privileges."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,9 +806,7 @@ pub(super) async fn put_room_tag(
|
|||||||
.account_data
|
.account_data
|
||||||
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
||||||
.await
|
.await
|
||||||
.unwrap_or(TagEvent {
|
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||||
content: TagEventContent { tags: BTreeMap::new() },
|
|
||||||
});
|
|
||||||
|
|
||||||
tags_event
|
tags_event
|
||||||
.content
|
.content
|
||||||
@@ -850,9 +843,7 @@ pub(super) async fn delete_room_tag(
|
|||||||
.account_data
|
.account_data
|
||||||
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
||||||
.await
|
.await
|
||||||
.unwrap_or(TagEvent {
|
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||||
content: TagEventContent { tags: BTreeMap::new() },
|
|
||||||
});
|
|
||||||
|
|
||||||
tags_event.content.tags.remove(&tag.clone().into());
|
tags_event.content.tags.remove(&tag.clone().into());
|
||||||
|
|
||||||
@@ -882,9 +873,7 @@ pub(super) async fn get_room_tags(&self, user_id: String, room_id: OwnedRoomId)
|
|||||||
.account_data
|
.account_data
|
||||||
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
||||||
.await
|
.await
|
||||||
.unwrap_or(TagEvent {
|
.unwrap_or_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||||
content: TagEventContent { tags: BTreeMap::new() },
|
|
||||||
});
|
|
||||||
|
|
||||||
self.write_str(&format!("```\n{:#?}\n```", tags_event.content.tags))
|
self.write_str(&format!("```\n{:#?}\n```", tags_event.content.tags))
|
||||||
.await
|
.await
|
||||||
@@ -921,19 +910,19 @@ pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result {
|
|||||||
.rooms
|
.rooms
|
||||||
.state
|
.state
|
||||||
.mutex
|
.mutex
|
||||||
.lock(&event.room_id_or_hash())
|
.lock(event.room_id_or_hash().as_str())
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
self.services
|
self.services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PduBuilder {
|
PartialPdu {
|
||||||
redacts: Some(event.event_id().to_owned()),
|
redacts: Some(event.event_id().to_owned()),
|
||||||
..PduBuilder::timeline(&RoomRedactionEventContent {
|
..PartialPdu::timeline(&assign!(RoomRedactionEventContent::new_v1(), {
|
||||||
redacts: Some(event.event_id().to_owned()),
|
redacts: Some(event.event_id().to_owned()),
|
||||||
reason: Some(reason),
|
reason: Some(reason),
|
||||||
})
|
}))
|
||||||
},
|
},
|
||||||
event.sender(),
|
event.sender(),
|
||||||
Some(&event.room_id_or_hash()),
|
Some(&event.room_id_or_hash()),
|
||||||
@@ -963,7 +952,7 @@ pub(super) async fn force_leave_remote_room(
|
|||||||
.resolve_with_servers(
|
.resolve_with_servers(
|
||||||
&room_id,
|
&room_id,
|
||||||
if let Some(v) = via.clone() {
|
if let Some(v) = via.clone() {
|
||||||
Some(vec![OwnedServerName::parse(v)?])
|
Some(vec![ServerName::parse(v)?])
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
@@ -976,7 +965,7 @@ pub(super) async fn force_leave_remote_room(
|
|||||||
);
|
);
|
||||||
let mut vias: HashSet<OwnedServerName> = HashSet::new();
|
let mut vias: HashSet<OwnedServerName> = HashSet::new();
|
||||||
if let Some(via) = via {
|
if let Some(via) = via {
|
||||||
vias.insert(OwnedServerName::parse(via)?);
|
vias.insert(ServerName::parse(via)?);
|
||||||
}
|
}
|
||||||
for server in vias_raw {
|
for server in vias_raw {
|
||||||
vias.insert(server);
|
vias.insert(server);
|
||||||
@@ -1051,7 +1040,12 @@ pub(super) async fn logout(&self, user_id: String) -> Result {
|
|||||||
self.services
|
self.services
|
||||||
.users
|
.users
|
||||||
.all_device_ids(&user_id)
|
.all_device_ids(&user_id)
|
||||||
.for_each(|device_id| self.services.users.remove_device(&user_id, device_id))
|
.for_each(async |device_id| {
|
||||||
|
self.services
|
||||||
|
.users
|
||||||
|
.remove_device(&user_id, &device_id)
|
||||||
|
.await;
|
||||||
|
})
|
||||||
.await;
|
.await;
|
||||||
self.write_str(&format!("User {user_id} has been logged out from all devices."))
|
self.write_str(&format!("User {user_id} has been logged out from all devices."))
|
||||||
.await
|
.await
|
||||||
@@ -1129,11 +1123,9 @@ pub(super) async fn get_user_by_email(&self, email: String) -> Result {
|
|||||||
|
|
||||||
match self.services.threepid.get_localpart_for_email(&email).await {
|
match self.services.threepid.get_localpart_for_email(&email).await {
|
||||||
| Some(localpart) => {
|
| Some(localpart) => {
|
||||||
let user_id = OwnedUserId::parse(format!(
|
let user_id =
|
||||||
"@{localpart}:{}",
|
UserId::parse(format!("@{localpart}:{}", self.services.globals.server_name()))
|
||||||
self.services.globals.server_name()
|
.unwrap();
|
||||||
))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
self.write_str(&format!("{email} belongs to {user_id}."))
|
self.write_str(&format!("{email} belongs to {user_id}."))
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
name = "conduwuit_api"
|
name = "conduwuit_api"
|
||||||
description.workspace = true
|
description.workspace = true
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
|
homepage.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
readme.workspace = true
|
readme.workspace = true
|
||||||
repository.workspace = true
|
repository.workspace = true
|
||||||
@@ -76,8 +77,10 @@ axum.workspace = true
|
|||||||
base64.workspace = true
|
base64.workspace = true
|
||||||
bytes.workspace = true
|
bytes.workspace = true
|
||||||
conduwuit-core.workspace = true
|
conduwuit-core.workspace = true
|
||||||
|
conduwuit-macros.workspace = true
|
||||||
conduwuit-service.workspace = true
|
conduwuit-service.workspace = true
|
||||||
const-str.workspace = true
|
const-str.workspace = true
|
||||||
|
ctor.workspace = true
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
hmac.workspace = true
|
hmac.workspace = true
|
||||||
http.workspace = true
|
http.workspace = true
|
||||||
@@ -89,7 +92,9 @@ lettre.workspace = true
|
|||||||
log.workspace = true
|
log.workspace = true
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
reqwest.workspace = true
|
reqwest.workspace = true
|
||||||
|
assign.workspace = true
|
||||||
ruma.workspace = true
|
ruma.workspace = true
|
||||||
|
ruminuwuity.workspace = true
|
||||||
serde_html_form.workspace = true
|
serde_html_form.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result, info, utils::ReadyExt, warn};
|
use conduwuit::{Err, Result, info, utils::ReadyExt, warn};
|
||||||
use futures::{FutureExt, StreamExt};
|
use futures::{FutureExt, StreamExt};
|
||||||
use ruma::{
|
use ruma::{OwnedRoomAliasId, events::room::message::RoomMessageEventContent};
|
||||||
OwnedRoomAliasId, continuwuity_admin_api::rooms,
|
use ruminuwuity::admin::continuwuity::rooms;
|
||||||
events::room::message::RoomMessageEventContent,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{Ruma, client::leave_room};
|
use crate::{Ruma, client::leave_room};
|
||||||
|
|
||||||
@@ -36,7 +34,6 @@ pub(crate) async fn ban_room(
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.room_members(&body.room_id)
|
.room_members(&body.room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.ready_filter(|user| services.globals.user_is_local(user))
|
.ready_filter(|user| services.globals.user_is_local(user))
|
||||||
.boxed();
|
.boxed();
|
||||||
let mut evicted = Vec::new();
|
let mut evicted = Vec::new();
|
||||||
@@ -63,9 +60,9 @@ pub(crate) async fn ban_room(
|
|||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.local_aliases_for_room(&body.room_id)
|
.local_aliases_for_room(&body.room_id)
|
||||||
.map(ToOwned::to_owned)
|
.collect()
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
for alias in &aliases {
|
for alias in &aliases {
|
||||||
info!("Removing alias {} for banned room {}", alias, body.room_id);
|
info!("Removing alias {} for banned room {}", alias, body.room_id);
|
||||||
services
|
services
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result};
|
use conduwuit::{Err, Result};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::{OwnedRoomId, continuwuity_admin_api::rooms};
|
use ruma::OwnedRoomId;
|
||||||
|
use ruminuwuity::admin::continuwuity::rooms;
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
@@ -22,8 +23,8 @@ pub(crate) async fn list_rooms(
|
|||||||
.metadata
|
.metadata
|
||||||
.iter_ids()
|
.iter_ids()
|
||||||
.filter_map(|room_id| async move {
|
.filter_map(|room_id| async move {
|
||||||
if !services.rooms.metadata.is_banned(room_id).await {
|
if !services.rooms.metadata.is_banned(&room_id).await {
|
||||||
Some(room_id.to_owned())
|
Some(room_id.clone())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::InsecureClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Event, Result, err, info,
|
Err, Result, err, info,
|
||||||
pdu::PduBuilder,
|
pdu::PartialPdu,
|
||||||
utils::{ReadyExt, stream::BroadbandExt},
|
utils::{ReadyExt, stream::BroadbandExt},
|
||||||
};
|
};
|
||||||
use conduwuit_service::Services;
|
use conduwuit_service::Services;
|
||||||
use futures::{FutureExt, StreamExt};
|
use futures::{FutureExt, StreamExt};
|
||||||
use lettre::{Address, message::Mailbox};
|
use lettre::{Address, message::Mailbox};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedRoomId, OwnedUserId, UserId,
|
OwnedRoomId, UserId,
|
||||||
api::client::{
|
api::client::{
|
||||||
account::{
|
account::{
|
||||||
ThirdPartyIdRemovalStatus, change_password, check_registration_token_validity,
|
ThirdPartyIdRemovalStatus, change_password, check_registration_token_validity,
|
||||||
@@ -18,12 +18,10 @@ use ruma::{
|
|||||||
},
|
},
|
||||||
uiaa::{AuthFlow, AuthType},
|
uiaa::{AuthFlow, AuthType},
|
||||||
},
|
},
|
||||||
events::{
|
assign,
|
||||||
StateEventType,
|
events::room::{
|
||||||
room::{
|
member::{MembershipState, RoomMemberEventContent},
|
||||||
member::{MembershipState, RoomMemberEventContent},
|
power_levels::RoomPowerLevelsEventContent,
|
||||||
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use service::{mailer::messages, uiaa::Identity};
|
use service::{mailer::messages, uiaa::Identity};
|
||||||
@@ -87,7 +85,7 @@ pub(crate) async fn get_register_available_route(
|
|||||||
return Err!(Request(Exclusive("Username is reserved by an appservice.")));
|
return Err!(Request(Exclusive("Username is reserved by an appservice.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_username_availability::v3::Response { available: true })
|
Ok(get_username_availability::v3::Response::new(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/account/password`
|
/// # `POST /_matrix/client/r0/account/password`
|
||||||
@@ -143,7 +141,7 @@ pub(crate) async fn change_password_route(
|
|||||||
.await?
|
.await?
|
||||||
};
|
};
|
||||||
|
|
||||||
let sender_user = OwnedUserId::parse(format!(
|
let sender_user = UserId::parse(format!(
|
||||||
"@{}:{}",
|
"@{}:{}",
|
||||||
identity.localpart.expect("localpart should be known"),
|
identity.localpart.expect("localpart should be known"),
|
||||||
services.globals.server_name()
|
services.globals.server_name()
|
||||||
@@ -161,7 +159,7 @@ pub(crate) async fn change_password_route(
|
|||||||
.users
|
.users
|
||||||
.all_device_ids(&sender_user)
|
.all_device_ids(&sender_user)
|
||||||
.ready_filter(|id| *id != body.sender_device())
|
.ready_filter(|id| *id != body.sender_device())
|
||||||
.for_each(|id| services.users.remove_device(&sender_user, id))
|
.for_each(async |id| services.users.remove_device(&sender_user, &id).await)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Remove all pushers except the ones associated with this session
|
// Remove all pushers except the ones associated with this session
|
||||||
@@ -175,8 +173,8 @@ pub(crate) async fn change_password_route(
|
|||||||
.get_pusher_device(&pushkey)
|
.get_pusher_device(&pushkey)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|pusher_device| pusher_device != body.sender_device())
|
.as_ref()
|
||||||
.is_some()
|
.is_some_and(|pusher_device| pusher_device != body.sender_device())
|
||||||
.then_some(pushkey)
|
.then_some(pushkey)
|
||||||
})
|
})
|
||||||
.for_each(async |pushkey| {
|
.for_each(async |pushkey| {
|
||||||
@@ -194,7 +192,7 @@ pub(crate) async fn change_password_route(
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(change_password::v3::Response {})
|
Ok(change_password::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/v3/account/password/email/requestToken`
|
/// # `POST /_matrix/client/v3/account/password/email/requestToken`
|
||||||
@@ -215,7 +213,7 @@ pub(crate) async fn request_password_change_token_via_email_route(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let user_id =
|
let user_id =
|
||||||
OwnedUserId::parse(format!("@{localpart}:{}", services.globals.server_name())).unwrap();
|
UserId::parse(format!("@{localpart}:{}", services.globals.server_name())).unwrap();
|
||||||
let display_name = services.users.displayname(&user_id).await.ok();
|
let display_name = services.users.displayname(&user_id).await.ok();
|
||||||
|
|
||||||
let session = services
|
let session = services
|
||||||
@@ -251,11 +249,10 @@ pub(crate) async fn whoami_route(
|
|||||||
.map_err(|_| {
|
.map_err(|_| {
|
||||||
err!(Request(Forbidden("Application service has not registered this user.")))
|
err!(Request(Forbidden("Application service has not registered this user.")))
|
||||||
})? && body.appservice_info.is_none();
|
})? && body.appservice_info.is_none();
|
||||||
Ok(whoami::v3::Response {
|
|
||||||
user_id: body.sender_user().to_owned(),
|
Ok(assign!(whoami::v3::Response::new(body.sender_user().to_owned(), is_guest), {
|
||||||
device_id: body.sender_device.clone(),
|
device_id: body.sender_device.clone(),
|
||||||
is_guest,
|
}))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/account/deactivate`
|
/// # `POST /_matrix/client/r0/account/deactivate`
|
||||||
@@ -310,9 +307,7 @@ pub(crate) async fn deactivate_route(
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(deactivate::v3::Response {
|
Ok(deactivate::v3::Response::new(ThirdPartyIdRemovalStatus::Success))
|
||||||
id_server_unbind_result: ThirdPartyIdRemovalStatus::Success,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/v1/register/m.login.registration_token/validity`
|
/// # `GET /_matrix/client/v1/register/m.login.registration_token/validity`
|
||||||
@@ -330,7 +325,7 @@ pub(crate) async fn check_registration_token_validity(
|
|||||||
.await
|
.await
|
||||||
.is_some();
|
.is_some();
|
||||||
|
|
||||||
Ok(check_registration_token_validity::v1::Response { valid })
|
Ok(check_registration_token_validity::v1::Response::new(valid))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs through all the deactivation steps:
|
/// Runs through all the deactivation steps:
|
||||||
@@ -354,13 +349,7 @@ pub async fn full_user_deactivate(
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
services
|
services.users.clear_profile(user_id).await;
|
||||||
.users
|
|
||||||
.all_profile_keys(user_id)
|
|
||||||
.ready_for_each(|(profile_key, _)| {
|
|
||||||
services.users.set_profile_key(user_id, &profile_key, None);
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
|
|
||||||
services
|
services
|
||||||
.pusher
|
.pusher
|
||||||
@@ -372,60 +361,49 @@ pub async fn full_user_deactivate(
|
|||||||
|
|
||||||
// TODO: Rescind all user invites
|
// TODO: Rescind all user invites
|
||||||
|
|
||||||
let mut pdu_queue: Vec<(PduBuilder, &OwnedRoomId)> = Vec::new();
|
let mut pdu_queue: Vec<(PartialPdu, &OwnedRoomId)> = Vec::new();
|
||||||
|
|
||||||
for room_id in all_joined_rooms {
|
for room_id in all_joined_rooms {
|
||||||
let room_power_levels = services
|
let room_power_levels = services
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.room_state_get_content::<RoomPowerLevelsEventContent>(
|
.get_room_power_levels(room_id)
|
||||||
room_id,
|
.await;
|
||||||
&StateEventType::RoomPowerLevels,
|
|
||||||
"",
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
let user_can_demote_self =
|
let user_can_demote_self =
|
||||||
room_power_levels
|
room_power_levels.user_can_change_user_power_level(user_id, user_id);
|
||||||
.as_ref()
|
|
||||||
.is_some_and(|power_levels_content| {
|
|
||||||
RoomPowerLevels::from(power_levels_content.clone())
|
|
||||||
.user_can_change_user_power_level(user_id, user_id)
|
|
||||||
}) || services
|
|
||||||
.rooms
|
|
||||||
.state_accessor
|
|
||||||
.room_state_get(room_id, &StateEventType::RoomCreate, "")
|
|
||||||
.await
|
|
||||||
.is_ok_and(|event| event.sender() == user_id);
|
|
||||||
|
|
||||||
if user_can_demote_self {
|
if user_can_demote_self
|
||||||
let mut power_levels_content = room_power_levels.unwrap_or_default();
|
&& let Ok(mut power_levels_content) =
|
||||||
|
RoomPowerLevelsEventContent::try_from(room_power_levels)
|
||||||
|
{
|
||||||
power_levels_content.users.remove(user_id);
|
power_levels_content.users.remove(user_id);
|
||||||
let pl_evt = PduBuilder::state(String::new(), &power_levels_content);
|
let pl_evt = PartialPdu::state(String::new(), &power_levels_content);
|
||||||
pdu_queue.push((pl_evt, room_id));
|
pdu_queue.push((pl_evt, room_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leave the room
|
// Leave the room
|
||||||
pdu_queue.push((
|
pdu_queue.push((
|
||||||
PduBuilder::state(user_id.to_string(), &RoomMemberEventContent {
|
PartialPdu::state(
|
||||||
avatar_url: None,
|
user_id.to_string(),
|
||||||
blurhash: None,
|
&RoomMemberEventContent::new(MembershipState::Leave),
|
||||||
membership: MembershipState::Leave,
|
),
|
||||||
displayname: None,
|
|
||||||
join_authorized_via_users_server: None,
|
|
||||||
reason: None,
|
|
||||||
is_direct: None,
|
|
||||||
third_party_invite: None,
|
|
||||||
redact_events: None,
|
|
||||||
}),
|
|
||||||
room_id,
|
room_id,
|
||||||
));
|
));
|
||||||
|
|
||||||
// TODO: Redact all messages sent by the user in the room
|
// TODO: Redact all messages sent by the user in the room
|
||||||
}
|
}
|
||||||
|
|
||||||
super::update_all_rooms(services, pdu_queue, user_id).await;
|
for (pdu, room_id) in pdu_queue {
|
||||||
|
let state_lock = services.rooms.state.mutex.lock(room_id.as_str()).await;
|
||||||
|
|
||||||
|
let _ = services
|
||||||
|
.rooms
|
||||||
|
.timeline
|
||||||
|
.build_and_append_pdu(pdu, user_id, Some(room_id.as_ref()), &state_lock)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
for room_id in all_joined_rooms {
|
for room_id in all_joined_rooms {
|
||||||
services.rooms.state_cache.forget(room_id, user_id);
|
services.rooms.state_cache.forget(room_id, user_id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,11 @@ use ruma::{
|
|||||||
},
|
},
|
||||||
uiaa::{AuthFlow, AuthType},
|
uiaa::{AuthFlow, AuthType},
|
||||||
},
|
},
|
||||||
events::{GlobalAccountDataEventType, room::message::RoomMessageEventContent},
|
assign,
|
||||||
|
events::{
|
||||||
|
GlobalAccountDataEventType, push_rules::PushRulesEvent,
|
||||||
|
room::message::RoomMessageEventContent,
|
||||||
|
},
|
||||||
push,
|
push,
|
||||||
};
|
};
|
||||||
use serde_json::value::RawValue;
|
use serde_json::value::RawValue;
|
||||||
@@ -209,23 +213,15 @@ pub(crate) async fn register_route(
|
|||||||
None,
|
None,
|
||||||
&user_id,
|
&user_id,
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
GlobalAccountDataEventType::PushRules.to_string().into(),
|
||||||
&serde_json::to_value(ruma::events::push_rules::PushRulesEvent {
|
&serde_json::to_value(PushRulesEvent::new(
|
||||||
content: ruma::events::push_rules::PushRulesEventContent {
|
push::Ruleset::server_default(&user_id).into(),
|
||||||
global: push::Ruleset::server_default(&user_id),
|
))
|
||||||
},
|
.expect("should be able to serialize push rules"),
|
||||||
})?,
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Generate new device id if the user didn't specify one
|
// Generate new device id if the user didn't specify one
|
||||||
let no_device = body.inhibit_login
|
let (token, device) = if !body.inhibit_login {
|
||||||
|| body
|
|
||||||
.appservice_info
|
|
||||||
.as_ref()
|
|
||||||
.is_some_and(|aps| aps.registration.device_management);
|
|
||||||
|
|
||||||
let (token, device) = if !no_device {
|
|
||||||
// Don't create a device for inhibited logins
|
|
||||||
let device_id = if is_guest { None } else { body.device_id.clone() }
|
let device_id = if is_guest { None } else { body.device_id.clone() }
|
||||||
.unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH).into());
|
.unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH).into());
|
||||||
|
|
||||||
@@ -243,12 +239,14 @@ pub(crate) async fn register_route(
|
|||||||
Some(client.to_string()),
|
Some(client.to_string()),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
debug_info!(%user_id, %device_id, "User account was created");
|
|
||||||
(Some(new_token), Some(device_id))
|
(Some(new_token), Some(device_id))
|
||||||
} else {
|
} else {
|
||||||
|
// Don't create a device for inhibited logins
|
||||||
(None, None)
|
(None, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
debug_info!(%user_id, ?device, "User account was created");
|
||||||
|
|
||||||
// If the user registered with an email, associate it with their account.
|
// If the user registered with an email, associate it with their account.
|
||||||
if let Some(identity) = identity
|
if let Some(identity) = identity
|
||||||
&& let Some(email) = identity.email
|
&& let Some(email) = identity.email
|
||||||
@@ -393,13 +391,12 @@ pub(crate) async fn register_route(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(register::v3::Response {
|
Ok(assign!(register::v3::Response::new(user_id), {
|
||||||
access_token: token,
|
access_token: token,
|
||||||
user_id,
|
|
||||||
device_id: device,
|
device_id: device,
|
||||||
refresh_token: None,
|
refresh_token: None,
|
||||||
expires_in: None,
|
expires_in: None,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine which flows and parameters should be presented when
|
/// Determine which flows and parameters should be presented when
|
||||||
@@ -462,6 +459,31 @@ async fn create_registration_uiaa_session(
|
|||||||
flows.push(untrusted_flow);
|
flows.push(untrusted_flow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Require all users to agree to the terms and conditions, if configured
|
||||||
|
let terms = &services.config.registration_terms;
|
||||||
|
if !terms.is_empty() {
|
||||||
|
let mut terms =
|
||||||
|
serde_json::to_value(terms.clone()).expect("failed to serialize terms");
|
||||||
|
|
||||||
|
// Insert a dummy `version` field
|
||||||
|
for (_, documents) in terms.as_object_mut().unwrap() {
|
||||||
|
let documents = documents.as_object_mut().unwrap();
|
||||||
|
|
||||||
|
documents.insert("version".to_owned(), "latest".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
params.insert(
|
||||||
|
AuthType::Terms.as_str().to_owned(),
|
||||||
|
serde_json::json!({
|
||||||
|
"policies": terms,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
for flow in &mut flows {
|
||||||
|
flow.stages.insert(0, AuthType::Terms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if flows.is_empty() {
|
if flows.is_empty() {
|
||||||
// No flows are configured. Bail out by default
|
// No flows are configured. Bail out by default
|
||||||
// unless open registration was explicitly enabled.
|
// unless open registration was explicitly enabled.
|
||||||
|
|||||||
@@ -133,9 +133,7 @@ pub(crate) async fn delete_3pid_route(
|
|||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
|
|
||||||
if body.medium != Medium::Email {
|
if body.medium != Medium::Email {
|
||||||
return Ok(delete_3pid::v3::Response {
|
return Ok(delete_3pid::v3::Response::new(ThirdPartyIdRemovalStatus::NoSupport));
|
||||||
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if services
|
if services
|
||||||
@@ -147,7 +145,5 @@ pub(crate) async fn delete_3pid_route(
|
|||||||
return Err!(Request(ThreepidNotFound("Your account has no associated email.")));
|
return Err!(Request(ThreepidNotFound("Your account has no associated email.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(delete_3pid::v3::Response {
|
Ok(delete_3pid::v3::Response::new(ThirdPartyIdRemovalStatus::Success))
|
||||||
id_server_unbind_result: ThirdPartyIdRemovalStatus::Success,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
@@ -7,10 +7,7 @@ use ruma::{
|
|||||||
get_global_account_data, get_room_account_data, set_global_account_data,
|
get_global_account_data, get_room_account_data, set_global_account_data,
|
||||||
set_room_account_data,
|
set_room_account_data,
|
||||||
},
|
},
|
||||||
events::{
|
events::{AnyGlobalAccountDataEventContent, AnyRoomAccountDataEventContent},
|
||||||
AnyGlobalAccountDataEventContent, AnyRoomAccountDataEventContent,
|
|
||||||
RoomAccountDataEventType,
|
|
||||||
},
|
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -40,7 +37,7 @@ pub(crate) async fn set_global_account_data_route(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(set_global_account_data::v3::Response {})
|
Ok(set_global_account_data::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
||||||
@@ -65,7 +62,7 @@ pub(crate) async fn set_room_account_data_route(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(set_room_account_data::v3::Response {})
|
Ok(set_room_account_data::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}`
|
/// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}`
|
||||||
@@ -87,7 +84,7 @@ pub(crate) async fn get_global_account_data_route(
|
|||||||
.await
|
.await
|
||||||
.map_err(|_| err!(Request(NotFound("Data not found."))))?;
|
.map_err(|_| err!(Request(NotFound("Data not found."))))?;
|
||||||
|
|
||||||
Ok(get_global_account_data::v3::Response { account_data: account_data.content })
|
Ok(get_global_account_data::v3::Response::new(account_data.content))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
||||||
@@ -109,7 +106,7 @@ pub(crate) async fn get_room_account_data_route(
|
|||||||
.await
|
.await
|
||||||
.map_err(|_| err!(Request(NotFound("Data not found."))))?;
|
.map_err(|_| err!(Request(NotFound("Data not found."))))?;
|
||||||
|
|
||||||
Ok(get_room_account_data::v3::Response { account_data: account_data.content })
|
Ok(get_room_account_data::v3::Response::new(account_data.content))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn set_account_data(
|
async fn set_account_data(
|
||||||
@@ -119,7 +116,7 @@ async fn set_account_data(
|
|||||||
event_type_s: &str,
|
event_type_s: &str,
|
||||||
data: &RawJsonValue,
|
data: &RawJsonValue,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
if event_type_s == RoomAccountDataEventType::FullyRead.to_cow_str() {
|
if event_type_s == "m.fully_read" {
|
||||||
return Err!(Request(BadJson(
|
return Err!(Request(BadJson(
|
||||||
"This endpoint cannot be used for marking a room as fully read (setting \
|
"This endpoint cannot be used for marking a room as fully read (setting \
|
||||||
m.fully_read)"
|
m.fully_read)"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result};
|
use conduwuit::{Err, Result};
|
||||||
use futures::future::{join, join3};
|
use futures::future::{join, join3};
|
||||||
use ruma::api::client::admin::{get_suspended, set_suspended};
|
use ruminuwuity::admin::{get_suspended, set_suspended};
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result, err};
|
use conduwuit::{Err, Result, err};
|
||||||
use ruma::api::{appservice::ping, client::appservice::request_ping};
|
use ruma::{
|
||||||
|
api::{appservice::ping, client::appservice::request_ping},
|
||||||
|
assign,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
@@ -40,12 +43,12 @@ pub(crate) async fn appservice_ping(
|
|||||||
.sending
|
.sending
|
||||||
.send_appservice_request(
|
.send_appservice_request(
|
||||||
appservice_info.registration.clone(),
|
appservice_info.registration.clone(),
|
||||||
ping::send_ping::v1::Request {
|
assign!(ping::send_ping::v1::Request::new(), {
|
||||||
transaction_id: body.transaction_id.clone(),
|
transaction_id: body.transaction_id.clone(),
|
||||||
},
|
}),
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.expect("We already validated if an appservice URL exists above");
|
.expect("We already validated if an appservice URL exists above");
|
||||||
|
|
||||||
Ok(request_ping::v1::Response { duration: timer.elapsed() })
|
Ok(request_ping::v1::Response::new(timer.elapsed()))
|
||||||
}
|
}
|
||||||
+29
-33
@@ -3,7 +3,6 @@ use std::cmp::Ordering;
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result, err};
|
use conduwuit::{Err, Result, err};
|
||||||
use conduwuit_service::Services;
|
use conduwuit_service::Services;
|
||||||
use futures::{FutureExt, future::try_join};
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
UInt, UserId,
|
UInt, UserId,
|
||||||
api::client::backup::{
|
api::client::backup::{
|
||||||
@@ -28,7 +27,7 @@ pub(crate) async fn create_backup_version_route(
|
|||||||
.key_backups
|
.key_backups
|
||||||
.create_backup(body.sender_user(), &body.algorithm)?;
|
.create_backup(body.sender_user(), &body.algorithm)?;
|
||||||
|
|
||||||
Ok(create_backup_version::v3::Response { version })
|
Ok(create_backup_version::v3::Response::new(version))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/version/{version}`
|
/// # `PUT /_matrix/client/r0/room_keys/version/{version}`
|
||||||
@@ -44,7 +43,7 @@ pub(crate) async fn update_backup_version_route(
|
|||||||
.update_backup(body.sender_user(), &body.version, &body.algorithm)
|
.update_backup(body.sender_user(), &body.version, &body.algorithm)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(update_backup_version::v3::Response {})
|
Ok(update_backup_version::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/version`
|
/// # `GET /_matrix/client/r0/room_keys/version`
|
||||||
@@ -60,9 +59,9 @@ pub(crate) async fn get_latest_backup_info_route(
|
|||||||
.await
|
.await
|
||||||
.map_err(|_| err!(Request(NotFound("Key backup does not exist."))))?;
|
.map_err(|_| err!(Request(NotFound("Key backup does not exist."))))?;
|
||||||
|
|
||||||
let (count, etag) = get_count_etag(&services, body.sender_user(), &version).await?;
|
let (count, etag) = get_count_etag(&services, body.sender_user(), &version).await;
|
||||||
|
|
||||||
Ok(get_latest_backup_info::v3::Response { algorithm, count, etag, version })
|
Ok(get_latest_backup_info::v3::Response::new(algorithm, count, etag, version))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/v3/room_keys/version/{version}`
|
/// # `GET /_matrix/client/v3/room_keys/version/{version}`
|
||||||
@@ -80,14 +79,9 @@ pub(crate) async fn get_backup_info_route(
|
|||||||
err!(Request(NotFound("Key backup does not exist at version {:?}", body.version)))
|
err!(Request(NotFound("Key backup does not exist at version {:?}", body.version)))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?;
|
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await;
|
||||||
|
|
||||||
Ok(get_backup_info::v3::Response {
|
Ok(get_backup_info::v3::Response::new(algorithm, count, etag, body.version.clone()))
|
||||||
algorithm,
|
|
||||||
count,
|
|
||||||
etag,
|
|
||||||
version: body.version.clone(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/version/{version}`
|
/// # `DELETE /_matrix/client/r0/room_keys/version/{version}`
|
||||||
@@ -105,7 +99,7 @@ pub(crate) async fn delete_backup_version_route(
|
|||||||
.delete_backup(body.sender_user(), &body.version)
|
.delete_backup(body.sender_user(), &body.version)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(delete_backup_version::v3::Response {})
|
Ok(delete_backup_version::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/keys`
|
/// # `PUT /_matrix/client/r0/room_keys/keys`
|
||||||
@@ -140,9 +134,9 @@ pub(crate) async fn add_backup_keys_route(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?;
|
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await;
|
||||||
|
|
||||||
Ok(add_backup_keys::v3::Response { count, etag })
|
Ok(add_backup_keys::v3::Response::new(etag, count))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}`
|
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}`
|
||||||
@@ -175,9 +169,9 @@ pub(crate) async fn add_backup_keys_for_room_route(
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?;
|
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await;
|
||||||
|
|
||||||
Ok(add_backup_keys_for_room::v3::Response { count, etag })
|
Ok(add_backup_keys_for_room::v3::Response::new(etag, count))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
||||||
@@ -275,9 +269,9 @@ pub(crate) async fn add_backup_keys_for_session_route(
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?;
|
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await;
|
||||||
|
|
||||||
Ok(add_backup_keys_for_session::v3::Response { count, etag })
|
Ok(add_backup_keys_for_session::v3::Response::new(etag, count))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/keys`
|
/// # `GET /_matrix/client/r0/room_keys/keys`
|
||||||
@@ -292,7 +286,7 @@ pub(crate) async fn get_backup_keys_route(
|
|||||||
.get_all(body.sender_user(), &body.version)
|
.get_all(body.sender_user(), &body.version)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(get_backup_keys::v3::Response { rooms })
|
Ok(get_backup_keys::v3::Response::new(rooms))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}`
|
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}`
|
||||||
@@ -307,7 +301,7 @@ pub(crate) async fn get_backup_keys_for_room_route(
|
|||||||
.get_room(body.sender_user(), &body.version, &body.room_id)
|
.get_room(body.sender_user(), &body.version, &body.room_id)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(get_backup_keys_for_room::v3::Response { sessions })
|
Ok(get_backup_keys_for_room::v3::Response::new(sessions))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
||||||
@@ -325,7 +319,7 @@ pub(crate) async fn get_backup_keys_for_session_route(
|
|||||||
err!(Request(NotFound(debug_error!("Backup key not found for this user's session."))))
|
err!(Request(NotFound(debug_error!("Backup key not found for this user's session."))))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(get_backup_keys_for_session::v3::Response { key_data })
|
Ok(get_backup_keys_for_session::v3::Response::new(key_data))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/keys`
|
/// # `DELETE /_matrix/client/r0/room_keys/keys`
|
||||||
@@ -340,9 +334,9 @@ pub(crate) async fn delete_backup_keys_route(
|
|||||||
.delete_all_keys(body.sender_user(), &body.version)
|
.delete_all_keys(body.sender_user(), &body.version)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?;
|
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await;
|
||||||
|
|
||||||
Ok(delete_backup_keys::v3::Response { count, etag })
|
Ok(delete_backup_keys::v3::Response::new(etag, count))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}`
|
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}`
|
||||||
@@ -357,9 +351,9 @@ pub(crate) async fn delete_backup_keys_for_room_route(
|
|||||||
.delete_room_keys(body.sender_user(), &body.version, &body.room_id)
|
.delete_room_keys(body.sender_user(), &body.version, &body.room_id)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?;
|
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await;
|
||||||
|
|
||||||
Ok(delete_backup_keys_for_room::v3::Response { count, etag })
|
Ok(delete_backup_keys_for_room::v3::Response::new(etag, count))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
||||||
@@ -374,22 +368,24 @@ pub(crate) async fn delete_backup_keys_for_session_route(
|
|||||||
.delete_room_key(body.sender_user(), &body.version, &body.room_id, &body.session_id)
|
.delete_room_key(body.sender_user(), &body.version, &body.room_id, &body.session_id)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?;
|
let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await;
|
||||||
|
|
||||||
Ok(delete_backup_keys_for_session::v3::Response { count, etag })
|
Ok(delete_backup_keys_for_session::v3::Response::new(etag, count))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_count_etag(
|
async fn get_count_etag(
|
||||||
services: &Services,
|
services: &Services,
|
||||||
sender_user: &UserId,
|
sender_user: &UserId,
|
||||||
version: &str,
|
version: &str,
|
||||||
) -> Result<(UInt, String)> {
|
) -> (UInt, String) {
|
||||||
let count = services
|
let count: UInt = services
|
||||||
.key_backups
|
.key_backups
|
||||||
.count_keys(sender_user, version)
|
.count_keys(sender_user, version)
|
||||||
.map(TryInto::try_into);
|
.await
|
||||||
|
.try_into()
|
||||||
|
.expect("number of keys should fit into a UInt");
|
||||||
|
|
||||||
let etag = services.key_backups.get_etag(sender_user, version).map(Ok);
|
let etag = services.key_backups.get_etag(sender_user, version).await;
|
||||||
|
|
||||||
Ok(try_join(count, etag).await?)
|
(count, etag)
|
||||||
}
|
}
|
||||||
@@ -5,8 +5,11 @@ use conduwuit::{Result, Server};
|
|||||||
use ruma::{
|
use ruma::{
|
||||||
RoomVersionId,
|
RoomVersionId,
|
||||||
api::client::discovery::get_capabilities::{
|
api::client::discovery::get_capabilities::{
|
||||||
self, Capabilities, GetLoginTokenCapability, RoomVersionStability,
|
self,
|
||||||
RoomVersionsCapability, ThirdPartyIdChangesCapability,
|
v3::{
|
||||||
|
Capabilities, GetLoginTokenCapability, RoomVersionStability, RoomVersionsCapability,
|
||||||
|
ThirdPartyIdChangesCapability,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@@ -25,19 +28,17 @@ pub(crate) async fn get_capabilities_route(
|
|||||||
Server::available_room_versions().collect();
|
Server::available_room_versions().collect();
|
||||||
|
|
||||||
let mut capabilities = Capabilities::default();
|
let mut capabilities = Capabilities::default();
|
||||||
capabilities.room_versions = RoomVersionsCapability {
|
capabilities.room_versions = RoomVersionsCapability::new(
|
||||||
|
services.server.config.default_room_version.clone(),
|
||||||
available,
|
available,
|
||||||
default: services.server.config.default_room_version.clone(),
|
);
|
||||||
};
|
|
||||||
|
|
||||||
// Only allow 3pid changes if SMTP is configured
|
// Only allow 3pid changes if SMTP is configured
|
||||||
capabilities.thirdparty_id_changes = ThirdPartyIdChangesCapability {
|
capabilities.thirdparty_id_changes =
|
||||||
enabled: services.mailer.mailer().is_some(),
|
ThirdPartyIdChangesCapability::new(services.mailer.mailer().is_some());
|
||||||
};
|
|
||||||
|
|
||||||
capabilities.get_login_token = GetLoginTokenCapability {
|
capabilities.get_login_token =
|
||||||
enabled: services.server.config.login_via_existing_session,
|
GetLoginTokenCapability::new(services.server.config.login_via_existing_session);
|
||||||
};
|
|
||||||
|
|
||||||
// MSC4133 capability
|
// MSC4133 capability
|
||||||
capabilities.set("uk.tcpip.msc4133.profile_fields", json!({"enabled": true}))?;
|
capabilities.set("uk.tcpip.msc4133.profile_fields", json!({"enabled": true}))?;
|
||||||
@@ -56,5 +57,5 @@ pub(crate) async fn get_capabilities_route(
|
|||||||
capabilities.set("uk.timedout.msc4323", json!({"suspend": true, "lock": false}))?;
|
capabilities.set("uk.timedout.msc4323", json!({"suspend": true, "lock": false}))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_capabilities::v3::Response { capabilities })
|
Ok(get_capabilities::v3::Response::new(capabilities))
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,9 @@ use futures::{
|
|||||||
FutureExt, StreamExt, TryFutureExt, TryStreamExt,
|
FutureExt, StreamExt, TryFutureExt, TryStreamExt,
|
||||||
future::{OptionFuture, join, join3, try_join3},
|
future::{OptionFuture, join, join3, try_join3},
|
||||||
};
|
};
|
||||||
use ruma::{OwnedEventId, UserId, api::client::context::get_context, events::StateEventType};
|
use ruma::{
|
||||||
|
OwnedEventId, UserId, api::client::context::get_context, assign, events::StateEventType,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Ruma,
|
Ruma,
|
||||||
@@ -213,7 +215,7 @@ pub(crate) async fn get_context_route(
|
|||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(get_context::v3::Response {
|
Ok(assign!(get_context::v3::Response::new(), {
|
||||||
event: base_event.map(at!(1)).map(Event::into_format),
|
event: base_event.map(at!(1)).map(Event::into_format),
|
||||||
|
|
||||||
start: events_before
|
start: events_before
|
||||||
@@ -243,5 +245,5 @@ pub(crate) async fn get_context_route(
|
|||||||
.collect(),
|
.collect(),
|
||||||
|
|
||||||
state,
|
state,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,14 @@ use axum::extract::State;
|
|||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::InsecureClientIp;
|
||||||
use conduwuit::{Err, Result, at};
|
use conduwuit::{Err, Result, at};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::api::client::dehydrated_device::{
|
use ruma::{
|
||||||
delete_dehydrated_device::unstable as delete_dehydrated_device,
|
api::client::dehydrated_device::{
|
||||||
get_dehydrated_device::unstable as get_dehydrated_device, get_events::unstable as get_events,
|
delete_dehydrated_device::unstable as delete_dehydrated_device,
|
||||||
put_dehydrated_device::unstable as put_dehydrated_device,
|
get_dehydrated_device::unstable as get_dehydrated_device,
|
||||||
|
get_events::unstable as get_events,
|
||||||
|
put_dehydrated_device::unstable as put_dehydrated_device,
|
||||||
|
},
|
||||||
|
assign,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
@@ -33,7 +37,7 @@ pub(crate) async fn put_dehydrated_device_route(
|
|||||||
.set_dehydrated_device(sender_user, body.body)
|
.set_dehydrated_device(sender_user, body.body)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(put_dehydrated_device::Response { device_id })
|
Ok(put_dehydrated_device::Response::new(device_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/../dehydrated_device`
|
/// # `DELETE /_matrix/client/../dehydrated_device`
|
||||||
@@ -51,7 +55,7 @@ pub(crate) async fn delete_dehydrated_device_route(
|
|||||||
|
|
||||||
services.users.remove_device(sender_user, &device_id).await;
|
services.users.remove_device(sender_user, &device_id).await;
|
||||||
|
|
||||||
Ok(delete_dehydrated_device::Response { device_id })
|
Ok(delete_dehydrated_device::Response::new(device_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/../dehydrated_device`
|
/// # `GET /_matrix/client/../dehydrated_device`
|
||||||
@@ -67,10 +71,7 @@ pub(crate) async fn get_dehydrated_device_route(
|
|||||||
|
|
||||||
let device = services.users.get_dehydrated_device(sender_user).await?;
|
let device = services.users.get_dehydrated_device(sender_user).await?;
|
||||||
|
|
||||||
Ok(get_dehydrated_device::Response {
|
Ok(get_dehydrated_device::Response::new(device.device_id, device.device_data))
|
||||||
device_id: device.device_id,
|
|
||||||
device_data: device.device_data,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/../dehydrated_device/{device_id}/events`
|
/// # `GET /_matrix/client/../dehydrated_device/{device_id}/events`
|
||||||
@@ -114,8 +115,7 @@ pub(crate) async fn get_dehydrated_events_route(
|
|||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(get_events::Response {
|
Ok(assign!(get_events::Response::new(events), {
|
||||||
events,
|
|
||||||
next_batch: next_batch.as_ref().map(ToString::to_string),
|
next_batch: next_batch.as_ref().map(ToString::to_string),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
+23
-46
@@ -25,7 +25,7 @@ pub(crate) async fn get_devices_route(
|
|||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(get_devices::v3::Response { devices })
|
Ok(get_devices::v3::Response::new(devices))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/devices/{deviceId}`
|
/// # `GET /_matrix/client/r0/devices/{deviceId}`
|
||||||
@@ -41,7 +41,7 @@ pub(crate) async fn get_device_route(
|
|||||||
.await
|
.await
|
||||||
.map_err(|_| err!(Request(NotFound("Device not found."))))?;
|
.map_err(|_| err!(Request(NotFound("Device not found."))))?;
|
||||||
|
|
||||||
Ok(get_device::v3::Response { device })
|
Ok(get_device::v3::Response::new(device))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
|
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
|
||||||
@@ -73,19 +73,16 @@ pub(crate) async fn update_device_route(
|
|||||||
.update_device_metadata(sender_user, &body.device_id, &device)
|
.update_device_metadata(sender_user, &body.device_id, &device)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(update_device::v3::Response {})
|
Ok(update_device::v3::Response::new())
|
||||||
},
|
},
|
||||||
| Err(_) => {
|
| Err(_) => {
|
||||||
let Some(appservice) = appservice else {
|
let Some(appservice) = appservice else {
|
||||||
return Err!(Request(NotFound("Device not found.")));
|
return Err!(Request(NotFound("Device not found.")));
|
||||||
};
|
};
|
||||||
if !appservice.registration.device_management {
|
|
||||||
return Err!(Request(NotFound("Device not found.")));
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Creating new device for {sender_user} from appservice {} as MSC4190 is enabled \
|
"Creating new device for {sender_user} from appservice {} as device ID does not \
|
||||||
and device ID does not exist",
|
exist",
|
||||||
appservice.registration.id
|
appservice.registration.id
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -102,7 +99,7 @@ pub(crate) async fn update_device_route(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(update_device::v3::Response {});
|
return Ok(update_device::v3::Response::new());
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,39 +121,28 @@ pub(crate) async fn delete_device_route(
|
|||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
let appservice = body.appservice_info.as_ref();
|
let appservice = body.appservice_info.as_ref();
|
||||||
|
|
||||||
if appservice.is_some_and(|appservice| appservice.registration.device_management) {
|
// Appservices get to skip UIAA for this endpoint
|
||||||
debug!(
|
if appservice.is_none() {
|
||||||
"Skipping UIAA for {sender_user} as this is from an appservice and MSC4190 is \
|
// Prompt the user to confirm with their password using UIAA
|
||||||
enabled"
|
let _ = services
|
||||||
);
|
.uiaa
|
||||||
services
|
.authenticate_password(&body.auth, Some(Identity::from_user_id(sender_user)))
|
||||||
.users
|
.await?;
|
||||||
.remove_device(sender_user, &body.device_id)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
return Ok(delete_device::v3::Response {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prompt the user to confirm with their password using UIAA
|
|
||||||
let _ = services
|
|
||||||
.uiaa
|
|
||||||
.authenticate_password(&body.auth, Some(Identity::from_user_id(sender_user)))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
services
|
services
|
||||||
.users
|
.users
|
||||||
.remove_device(sender_user, &body.device_id)
|
.remove_device(sender_user, &body.device_id)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(delete_device::v3::Response {})
|
Ok(delete_device::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/v3/delete_devices`
|
/// # `POST /_matrix/client/v3/delete_devices`
|
||||||
///
|
///
|
||||||
/// Deletes the given list of devices.
|
/// Deletes the given list of devices.
|
||||||
///
|
///
|
||||||
/// - Requires UIAA to verify user password unless from an appservice with
|
/// - Requires UIAA to verify user password.
|
||||||
/// MSC4190 enabled.
|
|
||||||
///
|
///
|
||||||
/// For each device:
|
/// For each device:
|
||||||
/// - Invalidates access token
|
/// - Invalidates access token
|
||||||
@@ -171,27 +157,18 @@ pub(crate) async fn delete_devices_route(
|
|||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
let appservice = body.appservice_info.as_ref();
|
let appservice = body.appservice_info.as_ref();
|
||||||
|
|
||||||
if appservice.is_some_and(|appservice| appservice.registration.device_management) {
|
// Appservices get to skip UIAA for this endpoint
|
||||||
debug!(
|
if appservice.is_none() {
|
||||||
"Skipping UIAA for {sender_user} as this is from an appservice and MSC4190 is \
|
// Prompt the user to confirm with their password using UIAA
|
||||||
enabled"
|
let _ = services
|
||||||
);
|
.uiaa
|
||||||
for device_id in &body.devices {
|
.authenticate_password(&body.auth, Some(Identity::from_user_id(sender_user)))
|
||||||
services.users.remove_device(sender_user, device_id).await;
|
.await?;
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(delete_devices::v3::Response {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prompt the user to confirm with their password using UIAA
|
|
||||||
let _ = services
|
|
||||||
.uiaa
|
|
||||||
.authenticate_password(&body.auth, Some(Identity::from_user_id(sender_user)))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
for device_id in &body.devices {
|
for device_id in &body.devices {
|
||||||
services.users.remove_device(sender_user, device_id).await;
|
services.users.remove_device(sender_user, device_id).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(delete_devices::v3::Response {})
|
Ok(delete_devices::v3::Response::new())
|
||||||
}
|
}
|
||||||
+65
-124
@@ -1,21 +1,16 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::InsecureClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Event, Result, err, info,
|
Err, Result, err, info,
|
||||||
utils::{
|
utils::{
|
||||||
TryFutureExtExt,
|
|
||||||
math::Expected,
|
math::Expected,
|
||||||
result::FlatOk,
|
|
||||||
stream::{ReadyExt, WidebandExt},
|
stream::{ReadyExt, WidebandExt},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use conduwuit_service::Services;
|
use conduwuit_service::Services;
|
||||||
use futures::{
|
use futures::StreamExt;
|
||||||
FutureExt, StreamExt, TryFutureExt,
|
|
||||||
future::{join, join4, join5},
|
|
||||||
};
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedRoomId, RoomId, ServerName, UInt, UserId,
|
RoomId, ServerName, UInt, UserId,
|
||||||
api::{
|
api::{
|
||||||
client::{
|
client::{
|
||||||
directory::{
|
directory::{
|
||||||
@@ -26,16 +21,12 @@ use ruma::{
|
|||||||
},
|
},
|
||||||
federation,
|
federation,
|
||||||
},
|
},
|
||||||
directory::{Filter, PublicRoomJoinRule, PublicRoomsChunk, RoomNetwork, RoomTypeFilter},
|
assign,
|
||||||
events::{
|
directory::{Filter, PublicRoomsChunk, RoomNetwork, RoomTypeFilter},
|
||||||
StateEventType,
|
events::StateEventType,
|
||||||
room::{
|
|
||||||
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
|
||||||
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
uint,
|
uint,
|
||||||
};
|
};
|
||||||
|
use tokio::join;
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
@@ -105,12 +96,11 @@ pub(crate) async fn get_public_rooms_route(
|
|||||||
err!(Request(Unknown(warn!(?body.server, "Failed to return /publicRooms: {e}"))))
|
err!(Request(Unknown(warn!(?body.server, "Failed to return /publicRooms: {e}"))))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(get_public_rooms::v3::Response {
|
Ok(assign!(get_public_rooms::v3::Response::new(response.chunk), {
|
||||||
chunk: response.chunk,
|
|
||||||
prev_batch: response.prev_batch,
|
prev_batch: response.prev_batch,
|
||||||
next_batch: response.next_batch,
|
next_batch: response.next_batch,
|
||||||
total_room_count_estimate: response.total_room_count_estimate,
|
total_room_count_estimate: response.total_room_count_estimate,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/directory/list/room/{roomId}`
|
/// # `PUT /_matrix/client/r0/directory/list/room/{roomId}`
|
||||||
@@ -193,7 +183,7 @@ pub(crate) async fn set_room_visibility_route(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(set_room_visibility::v3::Response {})
|
Ok(set_room_visibility::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/directory/list/room/{roomId}`
|
/// # `GET /_matrix/client/r0/directory/list/room/{roomId}`
|
||||||
@@ -208,13 +198,13 @@ pub(crate) async fn get_room_visibility_route(
|
|||||||
return Err!(Request(NotFound("Room not found")));
|
return Err!(Request(NotFound("Room not found")));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_room_visibility::v3::Response {
|
let visibility = if services.rooms.directory.is_public_room(&body.room_id).await {
|
||||||
visibility: if services.rooms.directory.is_public_room(&body.room_id).await {
|
room::Visibility::Public
|
||||||
room::Visibility::Public
|
} else {
|
||||||
} else {
|
room::Visibility::Private
|
||||||
room::Visibility::Private
|
};
|
||||||
},
|
|
||||||
})
|
Ok(get_room_visibility::v3::Response::new(visibility))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_public_rooms_filtered_helper(
|
pub(crate) async fn get_public_rooms_filtered_helper(
|
||||||
@@ -232,24 +222,24 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||||||
.sending
|
.sending
|
||||||
.send_federation_request(
|
.send_federation_request(
|
||||||
other_server,
|
other_server,
|
||||||
federation::directory::get_public_rooms_filtered::v1::Request {
|
assign!(federation::directory::get_public_rooms_filtered::v1::Request::new(), {
|
||||||
limit,
|
limit,
|
||||||
since: since.map(ToOwned::to_owned),
|
since: since.map(ToOwned::to_owned),
|
||||||
filter: Filter {
|
filter: assign!(Filter::new(), {
|
||||||
generic_search_term: filter.generic_search_term.clone(),
|
generic_search_term: filter.generic_search_term.clone(),
|
||||||
room_types: filter.room_types.clone(),
|
room_types: filter.room_types.clone(),
|
||||||
},
|
}),
|
||||||
room_network: RoomNetwork::Matrix,
|
room_network: RoomNetwork::Matrix,
|
||||||
},
|
}),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(get_public_rooms_filtered::v3::Response {
|
return Ok(assign!(get_public_rooms_filtered::v3::Response::new(), {
|
||||||
chunk: response.chunk,
|
chunk: response.chunk,
|
||||||
prev_batch: response.prev_batch,
|
prev_batch: response.prev_batch,
|
||||||
next_batch: response.next_batch,
|
next_batch: response.next_batch,
|
||||||
total_room_count_estimate: response.total_room_count_estimate,
|
total_room_count_estimate: response.total_room_count_estimate,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use limit or else 10, with maximum 100
|
// Use limit or else 10, with maximum 100
|
||||||
@@ -280,16 +270,24 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||||||
.rooms
|
.rooms
|
||||||
.directory
|
.directory
|
||||||
.public_rooms()
|
.public_rooms()
|
||||||
.map(ToOwned::to_owned)
|
.wide_then(async |room_id| {
|
||||||
.wide_then(|room_id| public_rooms_chunk(services, room_id))
|
let summary = services
|
||||||
.ready_filter_map(|chunk| {
|
.rooms
|
||||||
|
.summary
|
||||||
|
.build_local_room_summary(&room_id)
|
||||||
|
.await
|
||||||
|
.expect("room in public room directory should exist");
|
||||||
|
|
||||||
|
summary.into()
|
||||||
|
})
|
||||||
|
.ready_filter_map(|chunk: PublicRoomsChunk| {
|
||||||
if !filter.room_types.is_empty() && !filter.room_types.contains(&RoomTypeFilter::from(chunk.room_type.clone())) {
|
if !filter.room_types.is_empty() && !filter.room_types.contains(&RoomTypeFilter::from(chunk.room_type.clone())) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(query) = filter.generic_search_term.as_ref().map(|q| q.to_lowercase()) {
|
if let Some(query) = filter.generic_search_term.as_ref().map(|q| q.to_lowercase()) {
|
||||||
if let Some(name) = &chunk.name {
|
if let Some(name) = &chunk.name {
|
||||||
if name.as_str().to_lowercase().contains(&query) {
|
if name.to_lowercase().contains(&query) {
|
||||||
return Some(chunk);
|
return Some(chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -316,7 +314,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
all_rooms.sort_by(|l, r| r.num_joined_members.cmp(&l.num_joined_members));
|
all_rooms.sort_by_key(|r| std::cmp::Reverse(r.num_joined_members));
|
||||||
|
|
||||||
let total_room_count_estimate = UInt::try_from(all_rooms.len())
|
let total_room_count_estimate = UInt::try_from(all_rooms.len())
|
||||||
.unwrap_or_else(|_| uint!(0))
|
.unwrap_or_else(|_| uint!(0))
|
||||||
@@ -331,103 +329,46 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||||||
.ge(&limit)
|
.ge(&limit)
|
||||||
.then_some(format!("n{}", num_since.expected_add(limit)));
|
.then_some(format!("n{}", num_since.expected_add(limit)));
|
||||||
|
|
||||||
Ok(get_public_rooms_filtered::v3::Response {
|
Ok(assign!(get_public_rooms_filtered::v3::Response::new(), {
|
||||||
chunk,
|
chunk,
|
||||||
prev_batch,
|
prev_batch,
|
||||||
next_batch,
|
next_batch,
|
||||||
total_room_count_estimate,
|
total_room_count_estimate,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check whether the user can publish to the room directory via power levels of
|
/// Checks whether the given user ID is allowed to publish the target room to
|
||||||
/// room history visibility event or room creator
|
/// the server's public room directory. Users are allowed to publish rooms if
|
||||||
|
/// they are server admins, room creators (in v12), or have the power level to
|
||||||
|
/// send `m.room.canonical_alias`.
|
||||||
async fn user_can_publish_room(
|
async fn user_can_publish_room(
|
||||||
services: &Services,
|
services: &Services,
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
match services
|
if services.users.is_admin(user_id).await {
|
||||||
.rooms
|
// Server admins can always publish to their own room directory.
|
||||||
.state_accessor
|
return Ok(true);
|
||||||
.room_state_get(room_id, &StateEventType::RoomPowerLevels, "")
|
}
|
||||||
.await
|
|
||||||
|
let (room_version, room_creators, power_levels) = join!(
|
||||||
|
services.rooms.state.get_room_version(room_id),
|
||||||
|
services.rooms.state_accessor.get_room_creators(room_id),
|
||||||
|
services.rooms.state_accessor.get_room_power_levels(room_id),
|
||||||
|
);
|
||||||
|
|
||||||
|
let room_version = room_version
|
||||||
|
.as_ref()
|
||||||
|
.map_err(|_| err!(Request(NotFound("Unknown room"))))?;
|
||||||
|
let room_version_rules = room_version.rules().unwrap();
|
||||||
|
|
||||||
|
if room_version_rules
|
||||||
|
.authorization
|
||||||
|
.explicitly_privilege_room_creators
|
||||||
|
&& room_creators.contains(user_id)
|
||||||
{
|
{
|
||||||
| Ok(event) => serde_json::from_str(event.content().get())
|
return Ok(true);
|
||||||
.map_err(|_| err!(Database("Invalid event content for m.room.power_levels")))
|
|
||||||
.map(|content: RoomPowerLevelsEventContent| {
|
|
||||||
RoomPowerLevels::from(content)
|
|
||||||
.user_can_send_state(user_id, StateEventType::RoomHistoryVisibility)
|
|
||||||
}),
|
|
||||||
| _ => {
|
|
||||||
match services
|
|
||||||
.rooms
|
|
||||||
.state_accessor
|
|
||||||
.room_state_get(room_id, &StateEventType::RoomCreate, "")
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
| Ok(event) => Ok(event.sender() == user_id),
|
|
||||||
| _ => Err!(Request(Forbidden("User is not allowed to publish this room"))),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn public_rooms_chunk(services: &Services, room_id: OwnedRoomId) -> PublicRoomsChunk {
|
|
||||||
let name = services.rooms.state_accessor.get_name(&room_id).ok();
|
|
||||||
|
|
||||||
let room_type = services.rooms.state_accessor.get_room_type(&room_id).ok();
|
|
||||||
|
|
||||||
let canonical_alias = services
|
|
||||||
.rooms
|
|
||||||
.state_accessor
|
|
||||||
.get_canonical_alias(&room_id)
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
let avatar_url = services.rooms.state_accessor.get_avatar(&room_id);
|
|
||||||
|
|
||||||
let topic = services.rooms.state_accessor.get_room_topic(&room_id).ok();
|
|
||||||
|
|
||||||
let world_readable = services.rooms.state_accessor.is_world_readable(&room_id);
|
|
||||||
|
|
||||||
let join_rule = services
|
|
||||||
.rooms
|
|
||||||
.state_accessor
|
|
||||||
.room_state_get_content(&room_id, &StateEventType::RoomJoinRules, "")
|
|
||||||
.map_ok(|c: RoomJoinRulesEventContent| match c.join_rule {
|
|
||||||
| JoinRule::Public => PublicRoomJoinRule::Public,
|
|
||||||
| JoinRule::Knock => "knock".into(),
|
|
||||||
| JoinRule::KnockRestricted(_) => "knock_restricted".into(),
|
|
||||||
| _ => "invite".into(),
|
|
||||||
});
|
|
||||||
|
|
||||||
let guest_can_join = services.rooms.state_accessor.guest_can_join(&room_id);
|
|
||||||
|
|
||||||
let num_joined_members = services.rooms.state_cache.room_joined_count(&room_id);
|
|
||||||
|
|
||||||
let (
|
|
||||||
(avatar_url, canonical_alias, guest_can_join, join_rule, name),
|
|
||||||
(num_joined_members, room_type, topic, world_readable),
|
|
||||||
) = join(
|
|
||||||
join5(avatar_url, canonical_alias, guest_can_join, join_rule, name),
|
|
||||||
join4(num_joined_members, room_type, topic, world_readable),
|
|
||||||
)
|
|
||||||
.boxed()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
PublicRoomsChunk {
|
|
||||||
avatar_url: avatar_url.into_option().unwrap_or_default().url,
|
|
||||||
canonical_alias,
|
|
||||||
guest_can_join,
|
|
||||||
join_rule: join_rule.unwrap_or_default(),
|
|
||||||
name,
|
|
||||||
num_joined_members: num_joined_members
|
|
||||||
.map(TryInto::try_into)
|
|
||||||
.map(Result::ok)
|
|
||||||
.flat_ok()
|
|
||||||
.unwrap_or_else(|| uint!(0)),
|
|
||||||
room_id,
|
|
||||||
room_type,
|
|
||||||
topic,
|
|
||||||
world_readable,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(power_levels.user_can_send_state(user_id, StateEventType::RoomCanonicalAlias))
|
||||||
}
|
}
|
||||||
+45
-61
@@ -5,7 +5,7 @@ use std::{
|
|||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Error, Result, debug, debug_warn, err,
|
Err, Result, debug, debug_warn, err,
|
||||||
result::NotFound,
|
result::NotFound,
|
||||||
utils::{IterStream, stream::WidebandExt},
|
utils::{IterStream, stream::WidebandExt},
|
||||||
};
|
};
|
||||||
@@ -14,16 +14,14 @@ use futures::{StreamExt, stream::FuturesUnordered};
|
|||||||
use ruma::{
|
use ruma::{
|
||||||
OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId,
|
OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId,
|
||||||
api::{
|
api::{
|
||||||
client::{
|
client::keys::{
|
||||||
error::ErrorKind,
|
claim_keys, get_key_changes, get_keys, upload_keys,
|
||||||
keys::{
|
upload_signatures::{self},
|
||||||
claim_keys, get_key_changes, get_keys, upload_keys,
|
upload_signing_keys,
|
||||||
upload_signatures::{self},
|
|
||||||
upload_signing_keys,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
federation,
|
federation,
|
||||||
},
|
},
|
||||||
|
assign,
|
||||||
encryption::CrossSigningKey,
|
encryption::CrossSigningKey,
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
};
|
};
|
||||||
@@ -115,12 +113,12 @@ pub(crate) async fn upload_keys_route(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(upload_keys::v3::Response {
|
let one_time_key_counts = services
|
||||||
one_time_key_counts: services
|
.users
|
||||||
.users
|
.count_one_time_keys(sender_user, sender_device)
|
||||||
.count_one_time_keys(sender_user, sender_device)
|
.await;
|
||||||
.await,
|
|
||||||
})
|
Ok(upload_keys::v3::Response::new(one_time_key_counts))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/query`
|
/// # `POST /_matrix/client/r0/keys/query`
|
||||||
@@ -214,7 +212,7 @@ pub(crate) async fn upload_signing_keys_route(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(upload_signing_keys::v3::Response {})
|
Ok(upload_signing_keys::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn check_for_new_keys(
|
async fn check_for_new_keys(
|
||||||
@@ -226,8 +224,7 @@ async fn check_for_new_keys(
|
|||||||
) -> Result<Option<upload_signing_keys::v3::Response>> {
|
) -> Result<Option<upload_signing_keys::v3::Response>> {
|
||||||
debug!("checking for existing keys");
|
debug!("checking for existing keys");
|
||||||
let mut empty = false;
|
let mut empty = false;
|
||||||
if let Some(master_signing_key) = master_signing_key {
|
if master_signing_key.is_some() {
|
||||||
let (key, value) = parse_master_key(user_id, master_signing_key)?;
|
|
||||||
let result = services
|
let result = services
|
||||||
.users
|
.users
|
||||||
.get_master_key(None, user_id, &|_| true)
|
.get_master_key(None, user_id, &|_| true)
|
||||||
@@ -235,16 +232,12 @@ async fn check_for_new_keys(
|
|||||||
if result.is_not_found() {
|
if result.is_not_found() {
|
||||||
empty = true;
|
empty = true;
|
||||||
} else {
|
} else {
|
||||||
let existing_master_key = result?;
|
return Err!(Request(Forbidden(
|
||||||
let (existing_key, existing_value) = parse_master_key(user_id, &existing_master_key)?;
|
"Tried to change an existing master key, UIA required"
|
||||||
if existing_key != key || existing_value != value {
|
)));
|
||||||
return Err!(Request(Forbidden(
|
|
||||||
"Tried to change an existing master key, UIA required"
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(user_signing_key) = user_signing_key {
|
if user_signing_key.is_some() {
|
||||||
let key = services.users.get_user_signing_key(user_id).await;
|
let key = services.users.get_user_signing_key(user_id).await;
|
||||||
if key.is_not_found() && !empty {
|
if key.is_not_found() && !empty {
|
||||||
return Err!(Request(Forbidden(
|
return Err!(Request(Forbidden(
|
||||||
@@ -252,15 +245,12 @@ async fn check_for_new_keys(
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
if !key.is_not_found() {
|
if !key.is_not_found() {
|
||||||
let existing_signing_key = key?.deserialize()?;
|
return Err!(Request(Forbidden(
|
||||||
if existing_signing_key != user_signing_key.deserialize()? {
|
"Tried to change an existing user signing key, UIA required"
|
||||||
return Err!(Request(Forbidden(
|
)));
|
||||||
"Tried to change an existing user signing key, UIA required"
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(self_signing_key) = self_signing_key {
|
if self_signing_key.is_some() {
|
||||||
let key = services
|
let key = services
|
||||||
.users
|
.users
|
||||||
.get_self_signing_key(None, user_id, &|_| true)
|
.get_self_signing_key(None, user_id, &|_| true)
|
||||||
@@ -272,19 +262,16 @@ async fn check_for_new_keys(
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
if !key.is_not_found() {
|
if !key.is_not_found() {
|
||||||
let existing_signing_key = key?.deserialize()?;
|
return Err!(Request(Forbidden(
|
||||||
if existing_signing_key != self_signing_key.deserialize()? {
|
"Tried to update an existing self signing key, UIA required"
|
||||||
return Err!(Request(Forbidden(
|
)));
|
||||||
"Tried to update an existing self signing key, UIA required"
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if empty {
|
if empty {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some(upload_signing_keys::v3::Response {}))
|
Ok(Some(upload_signing_keys::v3::Response::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/signatures/upload`
|
/// # `POST /_matrix/client/r0/keys/signatures/upload`
|
||||||
@@ -343,7 +330,7 @@ pub(crate) async fn upload_signatures_route(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(upload_signatures::v3::Response { failures: BTreeMap::new() })
|
Ok(upload_signatures::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/changes`
|
/// # `POST /_matrix/client/r0/keys/changes`
|
||||||
@@ -363,18 +350,17 @@ pub(crate) async fn get_key_changes_route(
|
|||||||
let from = body
|
let from = body
|
||||||
.from
|
.from
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from`."))?;
|
.map_err(|_| err!(Request(InvalidParam("Invalid `from`."))))?;
|
||||||
|
|
||||||
let to = body
|
let to = body
|
||||||
.to
|
.to
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `to`."))?;
|
.map_err(|_| err!(Request(InvalidParam("Invalid `to`."))))?;
|
||||||
|
|
||||||
device_list_updates.extend(
|
device_list_updates.extend(
|
||||||
services
|
services
|
||||||
.users
|
.users
|
||||||
.keys_changed(sender_user, Some(from), Some(to))
|
.keys_changed(sender_user, Some(from), Some(to))
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await,
|
.await,
|
||||||
);
|
);
|
||||||
@@ -385,18 +371,18 @@ pub(crate) async fn get_key_changes_route(
|
|||||||
device_list_updates.extend(
|
device_list_updates.extend(
|
||||||
services
|
services
|
||||||
.users
|
.users
|
||||||
.room_keys_changed(room_id, Some(from), Some(to))
|
.room_keys_changed(&room_id, Some(from), Some(to))
|
||||||
.map(|(user_id, _)| user_id)
|
.map(|(user_id, _)| user_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await,
|
.await,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_key_changes::v3::Response {
|
Ok(get_key_changes::v3::Response::new(
|
||||||
changed: device_list_updates.into_iter().collect(),
|
device_list_updates.into_iter().collect(),
|
||||||
left: Vec::new(), // TODO
|
// TODO
|
||||||
})
|
vec![],
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_keys_helper<F>(
|
pub(crate) async fn get_keys_helper<F>(
|
||||||
@@ -433,10 +419,10 @@ where
|
|||||||
let mut devices = services.users.all_device_ids(user_id).boxed();
|
let mut devices = services.users.all_device_ids(user_id).boxed();
|
||||||
|
|
||||||
while let Some(device_id) = devices.next().await {
|
while let Some(device_id) = devices.next().await {
|
||||||
if let Ok(mut keys) = services.users.get_device_keys(user_id, device_id).await {
|
if let Ok(mut keys) = services.users.get_device_keys(user_id, &device_id).await {
|
||||||
let metadata = services
|
let metadata = services
|
||||||
.users
|
.users
|
||||||
.get_device_metadata(user_id, device_id)
|
.get_device_metadata(user_id, &device_id)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| {
|
.map_err(|_| {
|
||||||
err!(Database("all_device_keys contained nonexistent device."))
|
err!(Database("all_device_keys contained nonexistent device."))
|
||||||
@@ -445,7 +431,7 @@ where
|
|||||||
add_unsigned_device_display_name(&mut keys, metadata, include_display_names)
|
add_unsigned_device_display_name(&mut keys, metadata, include_display_names)
|
||||||
.map_err(|_| err!(Database("invalid device keys in database")))?;
|
.map_err(|_| err!(Database("invalid device keys in database")))?;
|
||||||
|
|
||||||
container.insert(device_id.to_owned(), keys);
|
container.insert(device_id.clone(), keys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,8 +492,7 @@ where
|
|||||||
device_keys_input_fed.insert(user_id.to_owned(), keys.clone());
|
device_keys_input_fed.insert(user_id.to_owned(), keys.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
let request =
|
let request = federation::keys::get_keys::v1::Request::new(device_keys_input_fed);
|
||||||
federation::keys::get_keys::v1::Request { device_keys: device_keys_input_fed };
|
|
||||||
let response = tokio::time::timeout(
|
let response = tokio::time::timeout(
|
||||||
timeout,
|
timeout,
|
||||||
services.sending.send_federation_request(server, request),
|
services.sending.send_federation_request(server, request),
|
||||||
@@ -561,13 +546,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_keys::v3::Response {
|
Ok(assign!(get_keys::v3::Response::new(), {
|
||||||
failures,
|
failures,
|
||||||
device_keys,
|
device_keys,
|
||||||
master_keys,
|
master_keys,
|
||||||
self_signing_keys,
|
self_signing_keys,
|
||||||
user_signing_keys,
|
user_signing_keys,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_unsigned_device_display_name(
|
fn add_unsigned_device_display_name(
|
||||||
@@ -576,7 +561,8 @@ fn add_unsigned_device_display_name(
|
|||||||
include_display_names: bool,
|
include_display_names: bool,
|
||||||
) -> serde_json::Result<()> {
|
) -> serde_json::Result<()> {
|
||||||
if let Some(display_name) = metadata.display_name {
|
if let Some(display_name) = metadata.display_name {
|
||||||
let mut object = keys.deserialize_as::<serde_json::Map<String, serde_json::Value>>()?;
|
let mut object =
|
||||||
|
keys.deserialize_as_unchecked::<serde_json::Map<String, serde_json::Value>>()?;
|
||||||
|
|
||||||
let unsigned = object.entry("unsigned").or_insert_with(|| json!({}));
|
let unsigned = object.entry("unsigned").or_insert_with(|| json!({}));
|
||||||
if let serde_json::Value::Object(unsigned_object) = unsigned {
|
if let serde_json::Value::Object(unsigned_object) = unsigned {
|
||||||
@@ -642,9 +628,7 @@ pub(crate) async fn claim_keys_helper(
|
|||||||
timeout,
|
timeout,
|
||||||
services.sending.send_federation_request(
|
services.sending.send_federation_request(
|
||||||
server,
|
server,
|
||||||
federation::keys::claim_keys::v1::Request {
|
federation::keys::claim_keys::v1::Request::new(one_time_keys_input_fed),
|
||||||
one_time_keys: one_time_keys_input_fed,
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -667,5 +651,5 @@ pub(crate) async fn claim_keys_helper(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(claim_keys::v3::Response { failures, one_time_keys })
|
Ok(assign!(claim_keys::v3::Response::new(one_time_keys), { failures: failures }))
|
||||||
}
|
}
|
||||||
+36
-81
@@ -9,11 +9,11 @@ use conduwuit::{
|
|||||||
use conduwuit_core::error;
|
use conduwuit_core::error;
|
||||||
use conduwuit_service::{
|
use conduwuit_service::{
|
||||||
Services,
|
Services,
|
||||||
media::{CACHE_CONTROL_IMMUTABLE, CORP_CROSS_ORIGIN, Dim, FileMeta, MXC_LENGTH},
|
media::{Dim, FileMeta, MXC_LENGTH},
|
||||||
};
|
};
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
Mxc, UserId,
|
UserId,
|
||||||
api::client::{
|
api::client::{
|
||||||
authenticated_media::{
|
authenticated_media::{
|
||||||
get_content, get_content_as_filename, get_content_thumbnail, get_media_config,
|
get_content, get_content_as_filename, get_content_thumbnail, get_media_config,
|
||||||
@@ -21,7 +21,9 @@ use ruma::{
|
|||||||
},
|
},
|
||||||
media::create_content,
|
media::create_content,
|
||||||
},
|
},
|
||||||
|
assign,
|
||||||
};
|
};
|
||||||
|
use service::media::mxc::Mxc;
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
@@ -30,9 +32,9 @@ pub(crate) async fn get_media_config_route(
|
|||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
_body: Ruma<get_media_config::v1::Request>,
|
_body: Ruma<get_media_config::v1::Request>,
|
||||||
) -> Result<get_media_config::v1::Response> {
|
) -> Result<get_media_config::v1::Response> {
|
||||||
Ok(get_media_config::v1::Response {
|
Ok(get_media_config::v1::Response::new(ruma_from_usize(
|
||||||
upload_size: ruma_from_usize(services.server.config.max_request_size),
|
services.server.config.max_request_size,
|
||||||
})
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/media/v3/upload`
|
/// # `POST /_matrix/media/v3/upload`
|
||||||
@@ -82,10 +84,9 @@ pub(crate) async fn create_content_route(
|
|||||||
.flatten()
|
.flatten()
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(create_content::v3::Response {
|
Ok(assign!(create_content::v3::Response::new(mxc.to_string().into()), {
|
||||||
content_uri: mxc.to_string().into(),
|
|
||||||
blurhash: blurhash.flatten(),
|
blurhash: blurhash.flatten(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/v1/media/thumbnail/{serverName}/{mediaId}`
|
/// # `GET /_matrix/client/v1/media/thumbnail/{serverName}/{mediaId}`
|
||||||
@@ -114,7 +115,7 @@ pub(crate) async fn get_content_thumbnail_route(
|
|||||||
content,
|
content,
|
||||||
content_type,
|
content_type,
|
||||||
content_disposition,
|
content_disposition,
|
||||||
} = match fetch_thumbnail(&services, &mxc, user, body.timeout_ms, &dim).await {
|
} = match fetch_thumbnail_meta(&services, &mxc, user, body.timeout_ms, &dim).await {
|
||||||
| Ok(meta) => meta,
|
| Ok(meta) => meta,
|
||||||
| Err(conduwuit::Error::Io(e)) => match e.kind() {
|
| Err(conduwuit::Error::Io(e)) => match e.kind() {
|
||||||
| std::io::ErrorKind::NotFound =>
|
| std::io::ErrorKind::NotFound =>
|
||||||
@@ -128,13 +129,14 @@ pub(crate) async fn get_content_thumbnail_route(
|
|||||||
| Err(_) => return Err!(Request(Unknown("Unknown error when fetching thumbnail."))),
|
| Err(_) => return Err!(Request(Unknown("Unknown error when fetching thumbnail."))),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_content_thumbnail::v1::Response {
|
let content_disposition =
|
||||||
file: content.expect("entire file contents"),
|
make_content_disposition(content_disposition.as_ref(), content_type.as_deref(), None);
|
||||||
content_type: content_type.map(Into::into),
|
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
Ok(get_content_thumbnail::v1::Response::new(
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
content.expect("entire file contents"),
|
||||||
|
content_type.unwrap_or_default(),
|
||||||
content_disposition,
|
content_disposition,
|
||||||
})
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/v1/media/download/{serverName}/{mediaId}`
|
/// # `GET /_matrix/client/v1/media/download/{serverName}/{mediaId}`
|
||||||
@@ -161,7 +163,7 @@ pub(crate) async fn get_content_route(
|
|||||||
content,
|
content,
|
||||||
content_type,
|
content_type,
|
||||||
content_disposition,
|
content_disposition,
|
||||||
} = match fetch_file(&services, &mxc, user, body.timeout_ms, None).await {
|
} = match fetch_file_meta(&services, &mxc, user, body.timeout_ms).await {
|
||||||
| Ok(meta) => meta,
|
| Ok(meta) => meta,
|
||||||
| Err(conduwuit::Error::Io(e)) => match e.kind() {
|
| Err(conduwuit::Error::Io(e)) => match e.kind() {
|
||||||
| std::io::ErrorKind::NotFound => return Err!(Request(NotFound("Media not found."))),
|
| std::io::ErrorKind::NotFound => return Err!(Request(NotFound("Media not found."))),
|
||||||
@@ -174,13 +176,14 @@ pub(crate) async fn get_content_route(
|
|||||||
| Err(_) => return Err!(Request(Unknown("Unknown error when fetching file."))),
|
| Err(_) => return Err!(Request(Unknown("Unknown error when fetching file."))),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_content::v1::Response {
|
let content_disposition =
|
||||||
file: content.expect("entire file contents"),
|
make_content_disposition(content_disposition.as_ref(), content_type.as_deref(), None);
|
||||||
content_type: content_type.map(Into::into),
|
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
Ok(get_content::v1::Response::new(
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
content.expect("entire file contents"),
|
||||||
|
content_type.unwrap_or_default(),
|
||||||
content_disposition,
|
content_disposition,
|
||||||
})
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/v1/media/download/{serverName}/{mediaId}/{fileName}`
|
/// # `GET /_matrix/client/v1/media/download/{serverName}/{mediaId}/{fileName}`
|
||||||
@@ -208,7 +211,7 @@ pub(crate) async fn get_content_as_filename_route(
|
|||||||
content,
|
content,
|
||||||
content_type,
|
content_type,
|
||||||
content_disposition,
|
content_disposition,
|
||||||
} = match fetch_file(&services, &mxc, user, body.timeout_ms, None).await {
|
} = match fetch_file_meta(&services, &mxc, user, body.timeout_ms).await {
|
||||||
| Ok(meta) => meta,
|
| Ok(meta) => meta,
|
||||||
| Err(conduwuit::Error::Io(e)) => match e.kind() {
|
| Err(conduwuit::Error::Io(e)) => match e.kind() {
|
||||||
| std::io::ErrorKind::NotFound => return Err!(Request(NotFound("Media not found."))),
|
| std::io::ErrorKind::NotFound => return Err!(Request(NotFound("Media not found."))),
|
||||||
@@ -221,13 +224,17 @@ pub(crate) async fn get_content_as_filename_route(
|
|||||||
| Err(_) => return Err!(Request(Unknown("Unknown error when fetching file."))),
|
| Err(_) => return Err!(Request(Unknown("Unknown error when fetching file."))),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_content_as_filename::v1::Response {
|
let content_disposition = make_content_disposition(
|
||||||
file: content.expect("entire file contents"),
|
content_disposition.as_ref(),
|
||||||
content_type: content_type.map(Into::into),
|
content_type.as_deref(),
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
Some(&body.filename),
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
);
|
||||||
|
|
||||||
|
Ok(get_content_as_filename::v1::Response::new(
|
||||||
|
content.expect("entire file contents"),
|
||||||
|
content_type.unwrap_or_default(),
|
||||||
content_disposition,
|
content_disposition,
|
||||||
})
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/v1/media/preview_url`
|
/// # `GET /_matrix/client/v1/media/preview_url`
|
||||||
@@ -278,58 +285,6 @@ pub(crate) async fn get_media_preview_route(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_thumbnail(
|
|
||||||
services: &Services,
|
|
||||||
mxc: &Mxc<'_>,
|
|
||||||
user: &UserId,
|
|
||||||
timeout_ms: Duration,
|
|
||||||
dim: &Dim,
|
|
||||||
) -> Result<FileMeta> {
|
|
||||||
let FileMeta {
|
|
||||||
content,
|
|
||||||
content_type,
|
|
||||||
content_disposition,
|
|
||||||
} = fetch_thumbnail_meta(services, mxc, user, timeout_ms, dim).await?;
|
|
||||||
|
|
||||||
let content_disposition = Some(make_content_disposition(
|
|
||||||
content_disposition.as_ref(),
|
|
||||||
content_type.as_deref(),
|
|
||||||
None,
|
|
||||||
));
|
|
||||||
|
|
||||||
Ok(FileMeta {
|
|
||||||
content,
|
|
||||||
content_type,
|
|
||||||
content_disposition,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fetch_file(
|
|
||||||
services: &Services,
|
|
||||||
mxc: &Mxc<'_>,
|
|
||||||
user: &UserId,
|
|
||||||
timeout_ms: Duration,
|
|
||||||
filename: Option<&str>,
|
|
||||||
) -> Result<FileMeta> {
|
|
||||||
let FileMeta {
|
|
||||||
content,
|
|
||||||
content_type,
|
|
||||||
content_disposition,
|
|
||||||
} = fetch_file_meta(services, mxc, user, timeout_ms).await?;
|
|
||||||
|
|
||||||
let content_disposition = Some(make_content_disposition(
|
|
||||||
content_disposition.as_ref(),
|
|
||||||
content_type.as_deref(),
|
|
||||||
filename,
|
|
||||||
));
|
|
||||||
|
|
||||||
Ok(FileMeta {
|
|
||||||
content,
|
|
||||||
content_type,
|
|
||||||
content_disposition,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fetch_thumbnail_meta(
|
async fn fetch_thumbnail_meta(
|
||||||
services: &Services,
|
services: &Services,
|
||||||
mxc: &Mxc<'_>,
|
mxc: &Mxc<'_>,
|
||||||
|
|||||||
@@ -6,15 +6,16 @@ use conduwuit::{
|
|||||||
Err, Result, err,
|
Err, Result, err,
|
||||||
utils::{content_disposition::make_content_disposition, math::ruma_from_usize},
|
utils::{content_disposition::make_content_disposition, math::ruma_from_usize},
|
||||||
};
|
};
|
||||||
use conduwuit_service::media::{CACHE_CONTROL_IMMUTABLE, CORP_CROSS_ORIGIN, Dim, FileMeta};
|
use conduwuit_service::media::{CORP_CROSS_ORIGIN, Dim, FileMeta};
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
Mxc,
|
|
||||||
api::client::media::{
|
api::client::media::{
|
||||||
create_content, get_content, get_content_as_filename, get_content_thumbnail,
|
create_content, get_content, get_content_as_filename, get_content_thumbnail,
|
||||||
get_media_config, get_media_preview,
|
get_media_config, get_media_preview,
|
||||||
},
|
},
|
||||||
|
assign,
|
||||||
};
|
};
|
||||||
|
use service::media::mxc::Mxc;
|
||||||
|
|
||||||
use crate::{Ruma, RumaResponse, client::create_content_route};
|
use crate::{Ruma, RumaResponse, client::create_content_route};
|
||||||
|
|
||||||
@@ -25,9 +26,9 @@ pub(crate) async fn get_media_config_legacy_route(
|
|||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
_body: Ruma<get_media_config::v3::Request>,
|
_body: Ruma<get_media_config::v3::Request>,
|
||||||
) -> Result<get_media_config::v3::Response> {
|
) -> Result<get_media_config::v3::Response> {
|
||||||
Ok(get_media_config::v3::Response {
|
Ok(get_media_config::v3::Response::new(ruma_from_usize(
|
||||||
upload_size: ruma_from_usize(services.server.config.max_request_size),
|
services.server.config.max_request_size,
|
||||||
})
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/media/v1/config`
|
/// # `GET /_matrix/media/v1/config`
|
||||||
@@ -153,13 +154,16 @@ pub(crate) async fn get_content_legacy_route(
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(get_content::v3::Response {
|
Ok(assign!(
|
||||||
file: content.expect("entire file contents"),
|
get_content::v3::Response::new(
|
||||||
content_type: content_type.map(Into::into),
|
content.expect("entire file contents"),
|
||||||
content_disposition: Some(content_disposition),
|
content_type.unwrap_or_default(),
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
content_disposition,
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
),
|
||||||
})
|
{
|
||||||
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
|
}
|
||||||
|
))
|
||||||
},
|
},
|
||||||
| _ =>
|
| _ =>
|
||||||
if !services.globals.server_is_ours(&body.server_name) && body.allow_remote {
|
if !services.globals.server_is_ours(&body.server_name) && body.allow_remote {
|
||||||
@@ -177,13 +181,16 @@ pub(crate) async fn get_content_legacy_route(
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(get_content::v3::Response {
|
Ok(assign!(
|
||||||
file: response.file,
|
get_content::v3::Response::new(
|
||||||
content_type: response.content_type,
|
response.file,
|
||||||
content_disposition: Some(content_disposition),
|
response.content_type.unwrap_or_default(),
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
content_disposition,
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
),
|
||||||
})
|
{
|
||||||
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
|
}
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Err!(Request(NotFound("Media not found.")))
|
Err!(Request(NotFound("Media not found.")))
|
||||||
},
|
},
|
||||||
@@ -244,13 +251,15 @@ pub(crate) async fn get_content_as_filename_legacy_route(
|
|||||||
Some(&body.filename),
|
Some(&body.filename),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(get_content_as_filename::v3::Response {
|
Ok(assign!(get_content_as_filename::v3::Response::new(
|
||||||
file: content.expect("entire file contents"),
|
content.expect("entire file contents"),
|
||||||
content_type: content_type.map(Into::into),
|
content_type.unwrap_or_default(),
|
||||||
content_disposition: Some(content_disposition),
|
content_disposition,
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
),
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
{
|
||||||
})
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
|
}
|
||||||
|
))
|
||||||
},
|
},
|
||||||
| _ =>
|
| _ =>
|
||||||
if !services.globals.server_is_ours(&body.server_name) && body.allow_remote {
|
if !services.globals.server_is_ours(&body.server_name) && body.allow_remote {
|
||||||
@@ -268,13 +277,16 @@ pub(crate) async fn get_content_as_filename_legacy_route(
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(get_content_as_filename::v3::Response {
|
Ok(assign!(
|
||||||
content_disposition: Some(content_disposition),
|
get_content_as_filename::v3::Response::new(
|
||||||
content_type: response.content_type,
|
response.file,
|
||||||
file: response.file,
|
response.content_type.unwrap_or_default(),
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
content_disposition,
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
),
|
||||||
})
|
{
|
||||||
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
|
}
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Err!(Request(NotFound("Media not found.")))
|
Err!(Request(NotFound("Media not found.")))
|
||||||
},
|
},
|
||||||
@@ -335,13 +347,16 @@ pub(crate) async fn get_content_thumbnail_legacy_route(
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(get_content_thumbnail::v3::Response {
|
Ok(assign!(
|
||||||
file: content.expect("entire file contents"),
|
get_content_thumbnail::v3::Response::new(
|
||||||
content_type: content_type.map(Into::into),
|
content.expect("entire file contents"),
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
content_type.unwrap_or_default(),
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
content_disposition,
|
||||||
content_disposition: Some(content_disposition),
|
),
|
||||||
})
|
{
|
||||||
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()),
|
||||||
|
}
|
||||||
|
))
|
||||||
},
|
},
|
||||||
| _ =>
|
| _ =>
|
||||||
if !services.globals.server_is_ours(&body.server_name) && body.allow_remote {
|
if !services.globals.server_is_ours(&body.server_name) && body.allow_remote {
|
||||||
@@ -359,13 +374,16 @@ pub(crate) async fn get_content_thumbnail_legacy_route(
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(get_content_thumbnail::v3::Response {
|
Ok(assign!(
|
||||||
file: response.file,
|
get_content_thumbnail::v3::Response::new(
|
||||||
content_type: response.content_type,
|
response.file,
|
||||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
response.content_type.unwrap_or_default(),
|
||||||
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
content_disposition,
|
||||||
content_disposition: Some(content_disposition),
|
),
|
||||||
})
|
{
|
||||||
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()),
|
||||||
|
}
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Err!(Request(NotFound("Media not found.")))
|
Err!(Request(NotFound("Media not found.")))
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result, matrix::pdu::PduBuilder};
|
use conduwuit::{Err, Result, matrix::pdu::PartialPdu};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::membership::ban_user,
|
api::client::membership::ban_user,
|
||||||
events::room::member::{MembershipState, RoomMemberEventContent},
|
events::room::member::{MembershipState, RoomMemberEventContent},
|
||||||
@@ -24,30 +24,29 @@ pub(crate) async fn ban_user_route(
|
|||||||
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
let state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
|
||||||
|
|
||||||
let current_member_content = services
|
let mut content = services
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.get_member(&body.room_id, &body.user_id)
|
.get_member(&body.room_id, &body.user_id)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|_| RoomMemberEventContent::new(MembershipState::Ban));
|
.unwrap_or_else(|_| RoomMemberEventContent::new(MembershipState::Ban));
|
||||||
|
|
||||||
|
content.membership = MembershipState::Ban;
|
||||||
|
content.reason.clone_from(&body.reason);
|
||||||
|
content.displayname = None;
|
||||||
|
content.avatar_url = None;
|
||||||
|
content.is_direct = None;
|
||||||
|
content.join_authorized_via_users_server = None;
|
||||||
|
content.third_party_invite = None;
|
||||||
|
// TODO(upstream): MSC4293
|
||||||
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent {
|
PartialPdu::state(body.user_id.to_string(), &content),
|
||||||
membership: MembershipState::Ban,
|
|
||||||
reason: body.reason.clone(),
|
|
||||||
displayname: None, // display name may be offensive
|
|
||||||
avatar_url: None, // avatar may be offensive
|
|
||||||
is_direct: None,
|
|
||||||
join_authorized_via_users_server: None,
|
|
||||||
third_party_invite: None,
|
|
||||||
redact_events: body.redact_events,
|
|
||||||
..current_member_content
|
|
||||||
}),
|
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
|
|||||||
@@ -2,18 +2,19 @@ use axum::extract::State;
|
|||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::InsecureClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, debug_error, err, info,
|
Err, Result, debug_error, err, info,
|
||||||
matrix::{event::gen_event_id_canonical_json, pdu::PduBuilder},
|
matrix::{event::gen_event_id_canonical_json, pdu::PartialPdu},
|
||||||
warn,
|
warn,
|
||||||
};
|
};
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
RoomId, UserId,
|
RoomId, UserId,
|
||||||
api::{client::membership::invite_user, federation::membership::create_invite},
|
api::{
|
||||||
events::{
|
client::membership::invite_user::{self, v3::InviteUserId},
|
||||||
invite_permission_config::FilterLevel,
|
federation::membership::create_invite,
|
||||||
room::member::{MembershipState, RoomMemberEventContent},
|
|
||||||
},
|
},
|
||||||
|
events::room::member::{MembershipState, RoomMemberEventContent},
|
||||||
};
|
};
|
||||||
|
use ruminuwuity::invite_permission_config::FilterLevel;
|
||||||
use service::Services;
|
use service::Services;
|
||||||
|
|
||||||
use super::banned_room_check;
|
use super::banned_room_check;
|
||||||
@@ -51,7 +52,11 @@ pub(crate) async fn invite_user_route(
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
match &body.recipient {
|
match &body.recipient {
|
||||||
| invite_user::v3::InvitationRecipient::UserId { user_id: recipient_user } => {
|
| invite_user::v3::InvitationRecipient::UserId(InviteUserId {
|
||||||
|
user_id: recipient_user,
|
||||||
|
reason,
|
||||||
|
..
|
||||||
|
}) => {
|
||||||
let sender_filter_level = services
|
let sender_filter_level = services
|
||||||
.users
|
.users
|
||||||
.invite_filter_level(recipient_user, sender_user)
|
.invite_filter_level(recipient_user, sender_user)
|
||||||
@@ -59,7 +64,7 @@ pub(crate) async fn invite_user_route(
|
|||||||
|
|
||||||
if !matches!(sender_filter_level, FilterLevel::Allow) {
|
if !matches!(sender_filter_level, FilterLevel::Allow) {
|
||||||
// drop invites if the sender has the recipient filtered
|
// drop invites if the sender has the recipient filtered
|
||||||
return Ok(invite_user::v3::Response {});
|
return Ok(invite_user::v3::Response::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(target_user_membership) = services
|
if let Ok(target_user_membership) = services
|
||||||
@@ -95,13 +100,13 @@ pub(crate) async fn invite_user_route(
|
|||||||
sender_user,
|
sender_user,
|
||||||
recipient_user,
|
recipient_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
body.reason.clone(),
|
reason.clone(),
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(invite_user::v3::Response {})
|
Ok(invite_user::v3::Response::new())
|
||||||
},
|
},
|
||||||
| _ => {
|
| _ => {
|
||||||
Err!(Request(NotFound("User not found.")))
|
Err!(Request(NotFound("User not found.")))
|
||||||
@@ -141,18 +146,17 @@ pub(crate) async fn invite_helper(
|
|||||||
let (pdu, pdu_json, invite_room_state) = {
|
let (pdu, pdu_json, invite_room_state) = {
|
||||||
let state_lock = services.rooms.state.mutex.lock(room_id).await;
|
let state_lock = services.rooms.state.mutex.lock(room_id).await;
|
||||||
|
|
||||||
let content = RoomMemberEventContent {
|
let mut content = RoomMemberEventContent::new(MembershipState::Invite);
|
||||||
avatar_url: services.users.avatar_url(recipient_user).await.ok(),
|
content.displayname = services.users.displayname(recipient_user).await.ok();
|
||||||
is_direct: Some(is_direct),
|
content.avatar_url = services.users.avatar_url(recipient_user).await.ok();
|
||||||
reason,
|
content.is_direct = Some(is_direct);
|
||||||
..RoomMemberEventContent::new(MembershipState::Invite)
|
content.reason = reason;
|
||||||
};
|
|
||||||
|
|
||||||
let (pdu, pdu_json) = services
|
let (pdu, pdu_json) = services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.create_hash_and_sign_event(
|
.create_hash_and_sign_event(
|
||||||
PduBuilder::state(recipient_user.to_string(), &content),
|
PartialPdu::state(recipient_user.to_string(), &content),
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(room_id),
|
Some(room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -168,32 +172,39 @@ pub(crate) async fn invite_helper(
|
|||||||
|
|
||||||
let room_version_id = services.rooms.state.get_room_version(room_id).await?;
|
let room_version_id = services.rooms.state.get_room_version(room_id).await?;
|
||||||
|
|
||||||
|
let mut request = create_invite::v2::Request::new(
|
||||||
|
room_id.to_owned(),
|
||||||
|
(*pdu.event_id).to_owned(),
|
||||||
|
room_version_id.clone(),
|
||||||
|
services
|
||||||
|
.sending
|
||||||
|
.convert_to_outgoing_federation_event(pdu_json.clone())
|
||||||
|
.await,
|
||||||
|
invite_room_state,
|
||||||
|
);
|
||||||
|
request.via = services
|
||||||
|
.rooms
|
||||||
|
.state_cache
|
||||||
|
.servers_route_via(room_id)
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
|
||||||
let response = services
|
let response = services
|
||||||
.sending
|
.sending
|
||||||
.send_federation_request(recipient_user.server_name(), create_invite::v2::Request {
|
.send_federation_request(recipient_user.server_name(), request)
|
||||||
room_id: room_id.to_owned(),
|
|
||||||
event_id: (*pdu.event_id).to_owned(),
|
|
||||||
room_version: room_version_id.clone(),
|
|
||||||
event: services
|
|
||||||
.sending
|
|
||||||
.convert_to_outgoing_federation_event(pdu_json.clone())
|
|
||||||
.await,
|
|
||||||
invite_room_state,
|
|
||||||
via: services
|
|
||||||
.rooms
|
|
||||||
.state_cache
|
|
||||||
.servers_route_via(room_id)
|
|
||||||
.await
|
|
||||||
.ok(),
|
|
||||||
})
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// We do not add the event_id field to the pdu here because of signature and
|
// We do not add the event_id field to the pdu here because of signature and
|
||||||
// hashes checks
|
// hashes checks
|
||||||
let (event_id, value) = gen_event_id_canonical_json(&response.event, &room_version_id)
|
let (event_id, value) = gen_event_id_canonical_json(
|
||||||
.map_err(|e| {
|
&response.event,
|
||||||
err!(Request(BadJson(warn!("Could not convert event to canonical JSON: {e}"))))
|
&room_version_id
|
||||||
})?;
|
.rules()
|
||||||
|
.expect("room version should have defined rules"),
|
||||||
|
)
|
||||||
|
.map_err(|e| {
|
||||||
|
err!(Request(BadJson(warn!("Could not convert event to canonical JSON: {e}"))))
|
||||||
|
})?;
|
||||||
|
|
||||||
if pdu.event_id != event_id {
|
if pdu.event_id != event_id {
|
||||||
return Err!(Request(BadJson(warn!(
|
return Err!(Request(BadJson(warn!(
|
||||||
@@ -229,20 +240,18 @@ pub(crate) async fn invite_helper(
|
|||||||
|
|
||||||
let state_lock = services.rooms.state.mutex.lock(room_id).await;
|
let state_lock = services.rooms.state.mutex.lock(room_id).await;
|
||||||
|
|
||||||
let content = RoomMemberEventContent {
|
let mut content = RoomMemberEventContent::new(MembershipState::Invite);
|
||||||
displayname: services.users.displayname(recipient_user).await.ok(),
|
content.displayname = services.users.displayname(recipient_user).await.ok();
|
||||||
avatar_url: services.users.avatar_url(recipient_user).await.ok(),
|
content.avatar_url = services.users.avatar_url(recipient_user).await.ok();
|
||||||
blurhash: services.users.blurhash(recipient_user).await.ok(),
|
content.blurhash = services.users.blurhash(recipient_user).await.ok();
|
||||||
is_direct: Some(is_direct),
|
content.is_direct = Some(is_direct);
|
||||||
reason,
|
content.reason = reason;
|
||||||
..RoomMemberEventContent::new(MembershipState::Invite)
|
|
||||||
};
|
|
||||||
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PduBuilder::state(recipient_user.to_string(), &content),
|
PartialPdu::state(recipient_user.to_string(), &content),
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(room_id),
|
Some(room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use conduwuit::{
|
|||||||
matrix::{
|
matrix::{
|
||||||
StateKey,
|
StateKey,
|
||||||
event::{gen_event_id, gen_event_id_canonical_json},
|
event::{gen_event_id, gen_event_id_canonical_json},
|
||||||
pdu::{PduBuilder, PduEvent},
|
pdu::{PartialPdu, PduEvent},
|
||||||
state_res,
|
state_res,
|
||||||
},
|
},
|
||||||
result::FlatOk,
|
result::FlatOk,
|
||||||
@@ -24,10 +24,8 @@ use ruma::{
|
|||||||
CanonicalJsonObject, CanonicalJsonValue, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId,
|
CanonicalJsonObject, CanonicalJsonValue, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId,
|
||||||
RoomVersionId, UserId,
|
RoomVersionId, UserId,
|
||||||
api::{
|
api::{
|
||||||
client::{
|
client::membership::{join_room_by_id, join_room_by_id_or_alias},
|
||||||
error::ErrorKind,
|
error::{ErrorKind, IncompatibleRoomVersionErrorData},
|
||||||
membership::{join_room_by_id, join_room_by_id_or_alias},
|
|
||||||
},
|
|
||||||
federation::{self},
|
federation::{self},
|
||||||
},
|
},
|
||||||
canonical_json::to_canonical_value,
|
canonical_json::to_canonical_value,
|
||||||
@@ -89,7 +87,6 @@ pub(crate) async fn join_room_by_id_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.servers_invite_via(&body.room_id)
|
.servers_invite_via(&body.room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -168,7 +165,6 @@ pub(crate) async fn join_room_by_id_or_alias_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.servers_invite_via(&room_id)
|
.servers_invite_via(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await,
|
.await,
|
||||||
);
|
);
|
||||||
@@ -209,11 +205,7 @@ pub(crate) async fn join_room_by_id_or_alias_route(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let addl_via_servers = services
|
let addl_via_servers = services.rooms.state_cache.servers_invite_via(&room_id);
|
||||||
.rooms
|
|
||||||
.state_cache
|
|
||||||
.servers_invite_via(&room_id)
|
|
||||||
.map(ToOwned::to_owned);
|
|
||||||
|
|
||||||
let addl_state_servers = services
|
let addl_state_servers = services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -226,7 +218,7 @@ pub(crate) async fn join_room_by_id_or_alias_route(
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|event| event.get_field("sender"))
|
.map(|event| event.get_field("sender"))
|
||||||
.filter_map(FlatOk::flat_ok)
|
.filter_map(FlatOk::flat_ok)
|
||||||
.map(|user: &UserId| user.server_name().to_owned())
|
.map(|user: OwnedUserId| user.server_name().to_owned())
|
||||||
.stream()
|
.stream()
|
||||||
.chain(addl_via_servers)
|
.chain(addl_via_servers)
|
||||||
.collect()
|
.collect()
|
||||||
@@ -252,7 +244,7 @@ pub(crate) async fn join_room_by_id_or_alias_route(
|
|||||||
.boxed()
|
.boxed()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(join_room_by_id_or_alias::v3::Response { room_id: join_room_response.room_id })
|
Ok(join_room_by_id_or_alias::v3::Response::new(join_room_response.room_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn join_room_by_id_helper(
|
pub async fn join_room_by_id_helper(
|
||||||
@@ -283,7 +275,7 @@ pub async fn join_room_by_id_helper(
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
debug_warn!("{sender_user} is already joined in {room_id}");
|
debug_warn!("{sender_user} is already joined in {room_id}");
|
||||||
return Ok(join_room_by_id::v3::Response { room_id: room_id.into() });
|
return Ok(join_room_by_id::v3::Response::new(room_id.to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = services
|
if let Err(e) = services
|
||||||
@@ -383,12 +375,15 @@ async fn join_room_by_id_helper_remote(
|
|||||||
|
|
||||||
info!("make_join finished");
|
info!("make_join finished");
|
||||||
|
|
||||||
let room_version_id = make_join_response.room_version.unwrap_or(RoomVersionId::V1);
|
let room_version = make_join_response.room_version.unwrap_or(RoomVersionId::V1);
|
||||||
|
let room_version_rules = room_version
|
||||||
|
.rules()
|
||||||
|
.expect("room version should have defined rules");
|
||||||
|
|
||||||
if !services.server.supported_room_version(&room_version_id) {
|
if !services.server.supported_room_version(&room_version) {
|
||||||
// How did we get here?
|
// How did we get here?
|
||||||
return Err!(BadServerResponse(
|
return Err!(BadServerResponse(
|
||||||
"Remote room version {room_version_id} is not supported by conduwuit"
|
"Remote room version {room_version} is not supported by conduwuit"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,7 +396,7 @@ async fn join_room_by_id_helper_remote(
|
|||||||
|
|
||||||
let join_authorized_via_users_server = {
|
let join_authorized_via_users_server = {
|
||||||
use RoomVersionId::*;
|
use RoomVersionId::*;
|
||||||
if !matches!(room_version_id, V1 | V2 | V3 | V4 | V5 | V6 | V7) {
|
if !matches!(room_version, V1 | V2 | V3 | V4 | V5 | V6 | V7) {
|
||||||
join_event_stub
|
join_event_stub
|
||||||
.get("content")
|
.get("content")
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
@@ -423,36 +418,32 @@ async fn join_room_by_id_helper_remote(
|
|||||||
.expect("Timestamp is valid js_int value"),
|
.expect("Timestamp is valid js_int value"),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut join_content = RoomMemberEventContent::new(MembershipState::Join);
|
||||||
|
join_content.displayname = services.users.displayname(sender_user).await.ok();
|
||||||
|
join_content.avatar_url = services.users.avatar_url(sender_user).await.ok();
|
||||||
|
join_content.blurhash = services.users.blurhash(sender_user).await.ok();
|
||||||
|
join_content.reason = reason;
|
||||||
|
join_content
|
||||||
|
.join_authorized_via_users_server
|
||||||
|
.clone_from(&join_authorized_via_users_server);
|
||||||
|
|
||||||
join_event_stub.insert(
|
join_event_stub.insert(
|
||||||
"content".to_owned(),
|
"content".to_owned(),
|
||||||
to_canonical_value(RoomMemberEventContent {
|
to_canonical_value(join_content).expect("event is valid, we just created it"),
|
||||||
displayname: services.users.displayname(sender_user).await.ok(),
|
|
||||||
avatar_url: services.users.avatar_url(sender_user).await.ok(),
|
|
||||||
blurhash: services.users.blurhash(sender_user).await.ok(),
|
|
||||||
reason,
|
|
||||||
join_authorized_via_users_server: join_authorized_via_users_server.clone(),
|
|
||||||
..RoomMemberEventContent::new(MembershipState::Join)
|
|
||||||
})
|
|
||||||
.expect("event is valid, we just created it"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// We keep the "event_id" in the pdu only in v1 or
|
// Remove event id if it exists
|
||||||
// v2 rooms
|
join_event_stub.remove("event_id");
|
||||||
match room_version_id {
|
|
||||||
| RoomVersionId::V1 | RoomVersionId::V2 => {},
|
|
||||||
| _ => {
|
|
||||||
join_event_stub.remove("event_id");
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
||||||
// to be present
|
// to be present
|
||||||
services
|
services
|
||||||
.server_keys
|
.server_keys
|
||||||
.hash_and_sign_event(&mut join_event_stub, &room_version_id)?;
|
.hash_and_sign_event(&mut join_event_stub, &room_version_rules)?;
|
||||||
|
|
||||||
// Generate event id
|
// Generate event id
|
||||||
let event_id = gen_event_id(&join_event_stub, &room_version_id)?;
|
let event_id = gen_event_id(&join_event_stub, &room_version_rules)?;
|
||||||
|
|
||||||
// Add event_id back
|
// Add event_id back
|
||||||
join_event_stub
|
join_event_stub
|
||||||
@@ -462,15 +453,14 @@ async fn join_room_by_id_helper_remote(
|
|||||||
let mut join_event = join_event_stub;
|
let mut join_event = join_event_stub;
|
||||||
|
|
||||||
info!("Asking {remote_server} for send_join in room {room_id}");
|
info!("Asking {remote_server} for send_join in room {room_id}");
|
||||||
let send_join_request = federation::membership::create_join_event::v2::Request {
|
let send_join_request = federation::membership::create_join_event::v2::Request::new(
|
||||||
room_id: room_id.to_owned(),
|
room_id.to_owned(),
|
||||||
event_id: event_id.clone(),
|
event_id.clone(),
|
||||||
omit_members: false,
|
services
|
||||||
pdu: services
|
|
||||||
.sending
|
.sending
|
||||||
.convert_to_outgoing_federation_event(join_event.clone())
|
.convert_to_outgoing_federation_event(join_event.clone())
|
||||||
.await,
|
.await,
|
||||||
};
|
);
|
||||||
|
|
||||||
let send_join_response = match services
|
let send_join_response = match services
|
||||||
.sending
|
.sending
|
||||||
@@ -494,7 +484,7 @@ async fn join_room_by_id_helper_remote(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let (signed_event_id, signed_value) =
|
let (signed_event_id, signed_value) =
|
||||||
gen_event_id_canonical_json(signed_raw, &room_version_id).map_err(|e| {
|
gen_event_id_canonical_json(signed_raw, &room_version_rules).map_err(|e| {
|
||||||
err!(Request(BadJson(warn!(
|
err!(Request(BadJson(warn!(
|
||||||
"Could not convert event to canonical JSON: {e}"
|
"Could not convert event to canonical JSON: {e}"
|
||||||
))))
|
))))
|
||||||
@@ -569,7 +559,7 @@ async fn join_room_by_id_helper_remote(
|
|||||||
.then(|pdu| {
|
.then(|pdu| {
|
||||||
services
|
services
|
||||||
.server_keys
|
.server_keys
|
||||||
.validate_and_add_event_id_no_fetch(pdu, &room_version_id)
|
.validate_and_add_event_id_no_fetch(pdu, &room_version_rules)
|
||||||
.inspect_err(|e| {
|
.inspect_err(|e| {
|
||||||
debug_warn!("Could not validate send_join response room_state event: {e:?}");
|
debug_warn!("Could not validate send_join response room_state event: {e:?}");
|
||||||
})
|
})
|
||||||
@@ -617,7 +607,7 @@ async fn join_room_by_id_helper_remote(
|
|||||||
.then(|pdu| {
|
.then(|pdu| {
|
||||||
services
|
services
|
||||||
.server_keys
|
.server_keys
|
||||||
.validate_and_add_event_id_no_fetch(pdu, &room_version_id)
|
.validate_and_add_event_id_no_fetch(pdu, &room_version_rules)
|
||||||
})
|
})
|
||||||
.ready_filter_map(Result::ok)
|
.ready_filter_map(Result::ok)
|
||||||
.ready_for_each(|(event_id, value)| {
|
.ready_for_each(|(event_id, value)| {
|
||||||
@@ -638,7 +628,7 @@ async fn join_room_by_id_helper_remote(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let auth_check = state_res::event_auth::auth_check(
|
let auth_check = state_res::event_auth::auth_check(
|
||||||
&state_res::RoomVersion::new(&room_version_id)?,
|
&room_version.rules().unwrap(),
|
||||||
&parsed_join_pdu,
|
&parsed_join_pdu,
|
||||||
None, // TODO: third party invite
|
None, // TODO: third party invite
|
||||||
|k, s| state_fetch(k.clone(), s.into()),
|
|k, s| state_fetch(k.clone(), s.into()),
|
||||||
@@ -745,8 +735,7 @@ async fn join_room_by_id_helper_local(
|
|||||||
// This is a restricted room, check if we can complete the join requirements
|
// This is a restricted room, check if we can complete the join requirements
|
||||||
// locally.
|
// locally.
|
||||||
let needs_auth_user =
|
let needs_auth_user =
|
||||||
user_can_perform_restricted_join(services, sender_user, room_id, &room_version)
|
user_can_perform_restricted_join(services, sender_user, room_id).await;
|
||||||
.await;
|
|
||||||
if needs_auth_user.is_ok_and(is_true!()) {
|
if needs_auth_user.is_ok_and(is_true!()) {
|
||||||
// If there was an error or the value is false, we'll try joining over
|
// If there was an error or the value is false, we'll try joining over
|
||||||
// federation. Since it's Ok(true), we can authorise this locally.
|
// federation. Since it's Ok(true), we can authorise this locally.
|
||||||
@@ -759,21 +748,19 @@ async fn join_room_by_id_helper_local(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = RoomMemberEventContent {
|
let mut content = RoomMemberEventContent::new(MembershipState::Join);
|
||||||
displayname: services.users.displayname(sender_user).await.ok(),
|
content.displayname = services.users.displayname(sender_user).await.ok();
|
||||||
avatar_url: services.users.avatar_url(sender_user).await.ok(),
|
content.avatar_url = services.users.avatar_url(sender_user).await.ok();
|
||||||
blurhash: services.users.blurhash(sender_user).await.ok(),
|
content.blurhash = services.users.blurhash(sender_user).await.ok();
|
||||||
reason: reason.clone(),
|
content.reason.clone_from(&reason);
|
||||||
join_authorized_via_users_server: auth_user,
|
content.join_authorized_via_users_server = auth_user;
|
||||||
..RoomMemberEventContent::new(MembershipState::Join)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Try normal join first
|
// Try normal join first
|
||||||
let Err(error) = services
|
let Err(error) = services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PduBuilder::state(sender_user.to_string(), &content),
|
PartialPdu::state(sender_user.to_string(), &content),
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(room_id),
|
Some(room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -822,16 +809,16 @@ async fn make_join_request(
|
|||||||
"Asking {remote_server} for make_join (attempt {make_join_counter}/{})",
|
"Asking {remote_server} for make_join (attempt {make_join_counter}/{})",
|
||||||
servers.len()
|
servers.len()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut request = federation::membership::prepare_join_event::v1::Request::new(
|
||||||
|
room_id.to_owned(),
|
||||||
|
sender_user.to_owned(),
|
||||||
|
);
|
||||||
|
request.ver = services.server.supported_room_versions().collect();
|
||||||
|
|
||||||
let make_join_response = services
|
let make_join_response = services
|
||||||
.sending
|
.sending
|
||||||
.send_federation_request(
|
.send_federation_request(remote_server, request)
|
||||||
remote_server,
|
|
||||||
federation::membership::prepare_join_event::v1::Request {
|
|
||||||
room_id: room_id.to_owned(),
|
|
||||||
user_id: sender_user.to_owned(),
|
|
||||||
ver: services.server.supported_room_versions().collect(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
trace!("make_join response: {:?}", make_join_response);
|
trace!("make_join response: {:?}", make_join_response);
|
||||||
@@ -864,14 +851,17 @@ async fn make_join_request(
|
|||||||
rules, but is unable to authorise a join for us. Will continue trying."
|
rules, but is unable to authorise a join for us. Will continue trying."
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
| ErrorKind::IncompatibleRoomVersion { room_version } => {
|
| ErrorKind::IncompatibleRoomVersion(IncompatibleRoomVersionErrorData {
|
||||||
|
room_version,
|
||||||
|
..
|
||||||
|
}) => {
|
||||||
warn!(
|
warn!(
|
||||||
"{remote_server} reports the room we are trying to join is \
|
"{remote_server} reports the room we are trying to join is \
|
||||||
v{room_version}, which we do not support."
|
v{room_version}, which we do not support."
|
||||||
);
|
);
|
||||||
return Err(e);
|
return Err(e);
|
||||||
},
|
},
|
||||||
| ErrorKind::Forbidden { .. } => {
|
| ErrorKind::Forbidden => {
|
||||||
warn!("{remote_server} refuses to let us join: {e}.");
|
warn!("{remote_server} refuses to let us join: {e}.");
|
||||||
return Err(e);
|
return Err(e);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result, matrix::pdu::PduBuilder};
|
use conduwuit::{Err, Result, matrix::pdu::PartialPdu};
|
||||||
use ruma::{
|
use ruma::{api::client::membership::kick_user, events::room::member::MembershipState};
|
||||||
api::client::membership::kick_user,
|
|
||||||
events::room::member::{MembershipState, RoomMemberEventContent},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
@@ -18,9 +15,9 @@ pub(crate) async fn kick_user_route(
|
|||||||
if services.users.is_suspended(sender_user).await? {
|
if services.users.is_suspended(sender_user).await? {
|
||||||
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
||||||
}
|
}
|
||||||
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
let state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
|
||||||
|
|
||||||
let Ok(event) = services
|
let Ok(mut event) = services
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.get_member(&body.room_id, &body.user_id)
|
.get_member(&body.room_id, &body.user_id)
|
||||||
@@ -41,18 +38,17 @@ pub(crate) async fn kick_user_route(
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event.membership = MembershipState::Leave;
|
||||||
|
event.reason.clone_from(&body.reason);
|
||||||
|
event.is_direct = None;
|
||||||
|
event.join_authorized_via_users_server = None;
|
||||||
|
event.third_party_invite = None;
|
||||||
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent {
|
PartialPdu::state(body.user_id.to_string(), &event),
|
||||||
membership: MembershipState::Leave,
|
|
||||||
reason: body.reason.clone(),
|
|
||||||
is_direct: None,
|
|
||||||
join_authorized_via_users_server: None,
|
|
||||||
third_party_invite: None,
|
|
||||||
..event
|
|
||||||
}),
|
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use conduwuit::{
|
|||||||
Err, Result, debug, debug_info, debug_warn, err, info,
|
Err, Result, debug, debug_info, debug_warn, err, info,
|
||||||
matrix::{
|
matrix::{
|
||||||
event::gen_event_id,
|
event::gen_event_id,
|
||||||
pdu::{PduBuilder, PduEvent},
|
pdu::{PartialPdu, PduEvent},
|
||||||
},
|
},
|
||||||
result::FlatOk,
|
result::FlatOk,
|
||||||
trace,
|
trace,
|
||||||
@@ -15,8 +15,8 @@ use conduwuit::{
|
|||||||
};
|
};
|
||||||
use futures::{FutureExt, StreamExt};
|
use futures::{FutureExt, StreamExt};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, OwnedServerName, RoomId,
|
CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, OwnedServerName,
|
||||||
RoomVersionId, UserId,
|
OwnedUserId, RoomId, UserId,
|
||||||
api::{
|
api::{
|
||||||
client::knock::knock_room,
|
client::knock::knock_room,
|
||||||
federation::{self},
|
federation::{self},
|
||||||
@@ -73,7 +73,6 @@ pub(crate) async fn knock_room_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.servers_invite_via(&room_id)
|
.servers_invite_via(&room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await,
|
.await,
|
||||||
);
|
);
|
||||||
@@ -113,11 +112,7 @@ pub(crate) async fn knock_room_route(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let addl_via_servers = services
|
let addl_via_servers = services.rooms.state_cache.servers_invite_via(&room_id);
|
||||||
.rooms
|
|
||||||
.state_cache
|
|
||||||
.servers_invite_via(&room_id)
|
|
||||||
.map(ToOwned::to_owned);
|
|
||||||
|
|
||||||
let addl_state_servers = services
|
let addl_state_servers = services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -130,7 +125,7 @@ pub(crate) async fn knock_room_route(
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|event| event.get_field("sender"))
|
.map(|event| event.get_field("sender"))
|
||||||
.filter_map(FlatOk::flat_ok)
|
.filter_map(FlatOk::flat_ok)
|
||||||
.map(|user: &UserId| user.server_name().to_owned())
|
.map(|user: OwnedUserId| user.server_name().to_owned())
|
||||||
.stream()
|
.stream()
|
||||||
.chain(addl_via_servers)
|
.chain(addl_via_servers)
|
||||||
.collect()
|
.collect()
|
||||||
@@ -188,7 +183,7 @@ async fn knock_room_by_id_helper(
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
debug_warn!("{sender_user} is already knocked in {room_id}");
|
debug_warn!("{sender_user} is already knocked in {room_id}");
|
||||||
return Ok(knock_room::v3::Response { room_id: room_id.into() });
|
return Ok(knock_room::v3::Response::new(room_id.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(membership) = services
|
if let Ok(membership) = services
|
||||||
@@ -339,34 +334,27 @@ async fn knock_room_helper_local(
|
|||||||
) -> Result {
|
) -> Result {
|
||||||
debug_info!("We can knock locally");
|
debug_info!("We can knock locally");
|
||||||
|
|
||||||
let room_version_id = services.rooms.state.get_room_version(room_id).await?;
|
let room_version = services.rooms.state.get_room_version(room_id).await?;
|
||||||
|
let room_version_rules = room_version
|
||||||
|
.rules()
|
||||||
|
.expect("room version should have defined rules");
|
||||||
|
|
||||||
if matches!(
|
if !room_version_rules.authorization.knocking {
|
||||||
room_version_id,
|
|
||||||
RoomVersionId::V1
|
|
||||||
| RoomVersionId::V2
|
|
||||||
| RoomVersionId::V3
|
|
||||||
| RoomVersionId::V4
|
|
||||||
| RoomVersionId::V5
|
|
||||||
| RoomVersionId::V6
|
|
||||||
) {
|
|
||||||
return Err!(Request(Forbidden("This room does not support knocking.")));
|
return Err!(Request(Forbidden("This room does not support knocking.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = RoomMemberEventContent {
|
let mut content = RoomMemberEventContent::new(MembershipState::Knock);
|
||||||
displayname: services.users.displayname(sender_user).await.ok(),
|
content.displayname = services.users.displayname(sender_user).await.ok();
|
||||||
avatar_url: services.users.avatar_url(sender_user).await.ok(),
|
content.avatar_url = services.users.avatar_url(sender_user).await.ok();
|
||||||
blurhash: services.users.blurhash(sender_user).await.ok(),
|
content.blurhash = services.users.blurhash(sender_user).await.ok();
|
||||||
reason: reason.clone(),
|
content.reason.clone_from(&reason.clone());
|
||||||
..RoomMemberEventContent::new(MembershipState::Knock)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Try normal knock first
|
// Try normal knock first
|
||||||
let Err(error) = services
|
let Err(error) = services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PduBuilder::state(sender_user.to_string(), &content),
|
PartialPdu::state(sender_user.to_string(), &content),
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(room_id),
|
Some(room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -381,19 +369,18 @@ async fn knock_room_helper_local(
|
|||||||
return Err(error);
|
return Err(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
warn!("We couldn't do the knock locally, maybe federation can help to satisfy the knock");
|
|
||||||
|
|
||||||
let (make_knock_response, remote_server) =
|
let (make_knock_response, remote_server) =
|
||||||
make_knock_request(services, sender_user, room_id, servers).await?;
|
make_knock_request(services, sender_user, room_id, servers).await?;
|
||||||
|
|
||||||
info!("make_knock finished");
|
info!("make_knock finished");
|
||||||
|
|
||||||
let room_version_id = make_knock_response.room_version;
|
let room_version = make_knock_response.room_version;
|
||||||
|
let room_version_rules = room_version
|
||||||
|
.rules()
|
||||||
|
.expect("room version should have defined rules");
|
||||||
|
|
||||||
if !services.server.supported_room_version(&room_version_id) {
|
if !services.server.supported_room_version(&room_version) {
|
||||||
return Err!(BadServerResponse(
|
return Err!(BadServerResponse("Remote room version {room_version} is not supported"));
|
||||||
"Remote room version {room_version_id} is not supported by conduwuit"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut knock_event_stub = serde_json::from_str::<CanonicalJsonObject>(
|
let mut knock_event_stub = serde_json::from_str::<CanonicalJsonObject>(
|
||||||
@@ -424,24 +411,17 @@ async fn knock_room_helper_local(
|
|||||||
);
|
);
|
||||||
knock_event_stub.insert(
|
knock_event_stub.insert(
|
||||||
"content".to_owned(),
|
"content".to_owned(),
|
||||||
to_canonical_value(RoomMemberEventContent {
|
to_canonical_value(content).expect("event is valid, we just created it"),
|
||||||
displayname: services.users.displayname(sender_user).await.ok(),
|
|
||||||
avatar_url: services.users.avatar_url(sender_user).await.ok(),
|
|
||||||
blurhash: services.users.blurhash(sender_user).await.ok(),
|
|
||||||
reason,
|
|
||||||
..RoomMemberEventContent::new(MembershipState::Knock)
|
|
||||||
})
|
|
||||||
.expect("event is valid, we just created it"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
||||||
// to be present
|
// to be present
|
||||||
services
|
services
|
||||||
.server_keys
|
.server_keys
|
||||||
.hash_and_sign_event(&mut knock_event_stub, &room_version_id)?;
|
.hash_and_sign_event(&mut knock_event_stub, &room_version_rules)?;
|
||||||
|
|
||||||
// Generate event id
|
// Generate event id
|
||||||
let event_id = gen_event_id(&knock_event_stub, &room_version_id)?;
|
let event_id = gen_event_id(&knock_event_stub, &room_version_rules)?;
|
||||||
|
|
||||||
// Add event_id
|
// Add event_id
|
||||||
knock_event_stub
|
knock_event_stub
|
||||||
@@ -451,14 +431,14 @@ async fn knock_room_helper_local(
|
|||||||
let knock_event = knock_event_stub;
|
let knock_event = knock_event_stub;
|
||||||
|
|
||||||
info!("Asking {remote_server} for send_knock in room {room_id}");
|
info!("Asking {remote_server} for send_knock in room {room_id}");
|
||||||
let send_knock_request = federation::knock::send_knock::v1::Request {
|
let send_knock_request = federation::membership::create_knock_event::v1::Request::new(
|
||||||
room_id: room_id.to_owned(),
|
room_id.to_owned(),
|
||||||
event_id: event_id.clone(),
|
event_id.clone(),
|
||||||
pdu: services
|
services
|
||||||
.sending
|
.sending
|
||||||
.convert_to_outgoing_federation_event(knock_event.clone())
|
.convert_to_outgoing_federation_event(knock_event.clone())
|
||||||
.await,
|
.await,
|
||||||
};
|
);
|
||||||
|
|
||||||
services
|
services
|
||||||
.sending
|
.sending
|
||||||
@@ -520,11 +500,14 @@ async fn knock_room_helper_remote(
|
|||||||
|
|
||||||
info!("make_knock finished");
|
info!("make_knock finished");
|
||||||
|
|
||||||
let room_version_id = make_knock_response.room_version;
|
let room_version = make_knock_response.room_version;
|
||||||
|
let room_version_rules = room_version
|
||||||
|
.rules()
|
||||||
|
.expect("room version should have defined rules");
|
||||||
|
|
||||||
if !services.server.supported_room_version(&room_version_id) {
|
if !services.server.supported_room_version(&room_version) {
|
||||||
return Err!(BadServerResponse(
|
return Err!(BadServerResponse(
|
||||||
"Remote room version {room_version_id} is not supported by conduwuit"
|
"Remote room version {room_version} is not supported by conduwuit"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,26 +528,26 @@ async fn knock_room_helper_remote(
|
|||||||
.expect("Timestamp is valid js_int value"),
|
.expect("Timestamp is valid js_int value"),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut knock_content = RoomMemberEventContent::new(MembershipState::Knock);
|
||||||
|
knock_content.displayname = services.users.displayname(sender_user).await.ok();
|
||||||
|
knock_content.avatar_url = services.users.avatar_url(sender_user).await.ok();
|
||||||
|
knock_content.blurhash = services.users.blurhash(sender_user).await.ok();
|
||||||
|
knock_content.reason = reason;
|
||||||
|
|
||||||
knock_event_stub.insert(
|
knock_event_stub.insert(
|
||||||
"content".to_owned(),
|
"content".to_owned(),
|
||||||
to_canonical_value(RoomMemberEventContent {
|
to_canonical_value(knock_content).expect("event is valid, we just created it"),
|
||||||
displayname: services.users.displayname(sender_user).await.ok(),
|
|
||||||
avatar_url: services.users.avatar_url(sender_user).await.ok(),
|
|
||||||
blurhash: services.users.blurhash(sender_user).await.ok(),
|
|
||||||
reason,
|
|
||||||
..RoomMemberEventContent::new(MembershipState::Knock)
|
|
||||||
})
|
|
||||||
.expect("event is valid, we just created it"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
||||||
// to be present
|
// to be present
|
||||||
services
|
services
|
||||||
.server_keys
|
.server_keys
|
||||||
.hash_and_sign_event(&mut knock_event_stub, &room_version_id)?;
|
.hash_and_sign_event(&mut knock_event_stub, &room_version_rules)?;
|
||||||
|
|
||||||
// Generate event id
|
// Generate event id
|
||||||
let event_id = gen_event_id(&knock_event_stub, &room_version_id)?;
|
let event_id = gen_event_id(&knock_event_stub, &room_version_rules)?;
|
||||||
|
|
||||||
// Add event_id
|
// Add event_id
|
||||||
knock_event_stub
|
knock_event_stub
|
||||||
@@ -574,18 +557,18 @@ async fn knock_room_helper_remote(
|
|||||||
let knock_event = knock_event_stub;
|
let knock_event = knock_event_stub;
|
||||||
|
|
||||||
info!("Asking {remote_server} for send_knock in room {room_id}");
|
info!("Asking {remote_server} for send_knock in room {room_id}");
|
||||||
let send_knock_request = federation::knock::send_knock::v1::Request {
|
let request = federation::membership::create_knock_event::v1::Request::new(
|
||||||
room_id: room_id.to_owned(),
|
room_id.to_owned(),
|
||||||
event_id: event_id.clone(),
|
event_id.clone(),
|
||||||
pdu: services
|
services
|
||||||
.sending
|
.sending
|
||||||
.convert_to_outgoing_federation_event(knock_event.clone())
|
.convert_to_outgoing_federation_event(knock_event.clone())
|
||||||
.await,
|
.await,
|
||||||
};
|
);
|
||||||
|
|
||||||
let send_knock_response = services
|
let send_knock_response = services
|
||||||
.sending
|
.sending
|
||||||
.send_federation_request(&remote_server, send_knock_request)
|
.send_federation_request(&remote_server, request)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
info!("send_knock finished");
|
info!("send_knock finished");
|
||||||
@@ -604,7 +587,17 @@ async fn knock_room_helper_remote(
|
|||||||
let state = send_knock_response
|
let state = send_knock_response
|
||||||
.knock_room_state
|
.knock_room_state
|
||||||
.iter()
|
.iter()
|
||||||
.map(|event| serde_json::from_str::<CanonicalJsonObject>(event.clone().into_json().get()))
|
.map(|event| {
|
||||||
|
#[allow(deprecated)]
|
||||||
|
let raw_value = match event {
|
||||||
|
| federation::membership::RawStrippedState::Stripped(raw_state) =>
|
||||||
|
&raw_state.clone().into_json(),
|
||||||
|
| federation::membership::RawStrippedState::Pdu(raw_value) => raw_value,
|
||||||
|
| _ => panic!("unknown raw stripped state type"),
|
||||||
|
};
|
||||||
|
|
||||||
|
serde_json::from_str::<CanonicalJsonObject>(raw_value.get())
|
||||||
|
})
|
||||||
.filter_map(Result::ok);
|
.filter_map(Result::ok);
|
||||||
|
|
||||||
let mut state_map: HashMap<u64, OwnedEventId> = HashMap::new();
|
let mut state_map: HashMap<u64, OwnedEventId> = HashMap::new();
|
||||||
@@ -629,7 +622,7 @@ async fn knock_room_helper_remote(
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let event_id = gen_event_id(&event, &room_version_id)?;
|
let event_id = gen_event_id(&event, &room_version_rules)?;
|
||||||
let shortstatekey = services
|
let shortstatekey = services
|
||||||
.rooms
|
.rooms
|
||||||
.short
|
.short
|
||||||
@@ -709,7 +702,7 @@ async fn make_knock_request(
|
|||||||
sender_user: &UserId,
|
sender_user: &UserId,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
servers: &[OwnedServerName],
|
servers: &[OwnedServerName],
|
||||||
) -> Result<(federation::knock::create_knock_event_template::v1::Response, OwnedServerName)> {
|
) -> Result<(federation::membership::prepare_knock_event::v1::Response, OwnedServerName)> {
|
||||||
let mut make_knock_response_and_server =
|
let mut make_knock_response_and_server =
|
||||||
Err!(BadServerResponse("No server available to assist in knocking."));
|
Err!(BadServerResponse("No server available to assist in knocking."));
|
||||||
|
|
||||||
@@ -722,16 +715,15 @@ async fn make_knock_request(
|
|||||||
|
|
||||||
info!("Asking {remote_server} for make_knock ({make_knock_counter})");
|
info!("Asking {remote_server} for make_knock ({make_knock_counter})");
|
||||||
|
|
||||||
|
let mut request = federation::membership::prepare_knock_event::v1::Request::new(
|
||||||
|
room_id.to_owned(),
|
||||||
|
sender_user.to_owned(),
|
||||||
|
);
|
||||||
|
request.ver = services.server.supported_room_versions().collect();
|
||||||
|
|
||||||
let make_knock_response = services
|
let make_knock_response = services
|
||||||
.sending
|
.sending
|
||||||
.send_federation_request(
|
.send_federation_request(remote_server, request)
|
||||||
remote_server,
|
|
||||||
federation::knock::create_knock_event_template::v1::Request {
|
|
||||||
room_id: room_id.to_owned(),
|
|
||||||
user_id: sender_user.to_owned(),
|
|
||||||
ver: services.server.supported_room_versions().collect(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
trace!("make_knock response: {make_knock_response:?}");
|
trace!("make_knock response: {make_knock_response:?}");
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ use std::collections::HashSet;
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Pdu, Result, debug_info, debug_warn, err,
|
Err, Pdu, Result, debug_info, debug_warn, err,
|
||||||
matrix::{event::gen_event_id, pdu::PduBuilder},
|
matrix::{event::gen_event_id, pdu::PartialPdu},
|
||||||
utils::{self, FutureBoolExt, future::ReadyEqExt},
|
utils::{self, FutureBoolExt, future::ReadyEqExt},
|
||||||
warn,
|
warn,
|
||||||
};
|
};
|
||||||
use futures::{FutureExt, StreamExt, pin_mut};
|
use futures::{FutureExt, StreamExt, pin_mut};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
CanonicalJsonObject, CanonicalJsonValue, OwnedServerName, RoomId, RoomVersionId, UserId,
|
CanonicalJsonObject, CanonicalJsonValue, OwnedServerName, RoomId, UserId,
|
||||||
api::{
|
api::{
|
||||||
client::membership::leave_room,
|
client::membership::leave_room,
|
||||||
federation::{self},
|
federation::{self},
|
||||||
@@ -42,11 +42,7 @@ pub(crate) async fn leave_room_route(
|
|||||||
// Make a user leave all their joined rooms, rescinds knocks, forgets all rooms,
|
// Make a user leave all their joined rooms, rescinds knocks, forgets all rooms,
|
||||||
// and ignores errors
|
// and ignores errors
|
||||||
pub async fn leave_all_rooms(services: &Services, user_id: &UserId) {
|
pub async fn leave_all_rooms(services: &Services, user_id: &UserId) {
|
||||||
let rooms_joined = services
|
let rooms_joined = services.rooms.state_cache.rooms_joined(user_id);
|
||||||
.rooms
|
|
||||||
.state_cache
|
|
||||||
.rooms_joined(user_id)
|
|
||||||
.map(ToOwned::to_owned);
|
|
||||||
|
|
||||||
let rooms_invited = services
|
let rooms_invited = services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -142,18 +138,17 @@ pub async fn leave_room(
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
match user_member_event_content {
|
match user_member_event_content {
|
||||||
| Ok(content) => {
|
| Ok(mut content) => {
|
||||||
|
content.membership = MembershipState::Leave;
|
||||||
|
content.reason = reason;
|
||||||
|
content.join_authorized_via_users_server = None;
|
||||||
|
content.is_direct = None;
|
||||||
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PduBuilder::state(user_id.to_string(), &RoomMemberEventContent {
|
PartialPdu::state(user_id.to_string(), &content),
|
||||||
membership: MembershipState::Leave,
|
|
||||||
reason,
|
|
||||||
join_authorized_via_users_server: None,
|
|
||||||
is_direct: None,
|
|
||||||
..content
|
|
||||||
}),
|
|
||||||
user_id,
|
user_id,
|
||||||
Some(room_id),
|
Some(room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -226,7 +221,6 @@ pub async fn remote_leave_room<S: ::std::hash::BuildHasher>(
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.servers_invite_via(room_id)
|
.servers_invite_via(room_id)
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect::<HashSet<OwnedServerName>>()
|
.collect::<HashSet<OwnedServerName>>()
|
||||||
.await,
|
.await,
|
||||||
);
|
);
|
||||||
@@ -260,7 +254,7 @@ pub async fn remote_leave_room<S: ::std::hash::BuildHasher>(
|
|||||||
.filter_map(|event| event.get_field("sender").ok().flatten())
|
.filter_map(|event| event.get_field("sender").ok().flatten())
|
||||||
.filter_map(|sender: &str| UserId::parse(sender).ok())
|
.filter_map(|sender: &str| UserId::parse(sender).ok())
|
||||||
.filter_map(|sender| {
|
.filter_map(|sender| {
|
||||||
if !services.globals.user_is_local(sender) {
|
if !services.globals.user_is_local(&sender) {
|
||||||
Some(sender.server_name().to_owned())
|
Some(sender.server_name().to_owned())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -289,10 +283,10 @@ pub async fn remote_leave_room<S: ::std::hash::BuildHasher>(
|
|||||||
.sending
|
.sending
|
||||||
.send_federation_request(
|
.send_federation_request(
|
||||||
remote_server.as_ref(),
|
remote_server.as_ref(),
|
||||||
federation::membership::prepare_leave_event::v1::Request {
|
federation::membership::prepare_leave_event::v1::Request::new(
|
||||||
room_id: room_id.to_owned(),
|
room_id.to_owned(),
|
||||||
user_id: user_id.to_owned(),
|
user_id.to_owned(),
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -329,6 +323,10 @@ pub async fn remote_leave_room<S: ::std::hash::BuildHasher>(
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let room_version_rules = room_version_id
|
||||||
|
.rules()
|
||||||
|
.expect("room version should have defined rules");
|
||||||
|
|
||||||
let mut leave_event_stub = serde_json::from_str::<CanonicalJsonObject>(
|
let mut leave_event_stub = serde_json::from_str::<CanonicalJsonObject>(
|
||||||
make_leave_response.event.get(),
|
make_leave_response.event.get(),
|
||||||
)
|
)
|
||||||
@@ -366,21 +364,16 @@ pub async fn remote_leave_room<S: ::std::hash::BuildHasher>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// room v3 and above removed the "event_id" field from remote PDU format
|
// room v3 and above removed the "event_id" field from remote PDU format
|
||||||
match room_version_id {
|
leave_event_stub.remove("event_id");
|
||||||
| RoomVersionId::V1 | RoomVersionId::V2 => {},
|
|
||||||
| _ => {
|
|
||||||
leave_event_stub.remove("event_id");
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
// In order to create a compatible ref hash (EventID) the `hashes` field needs
|
||||||
// to be present
|
// to be present
|
||||||
services
|
services
|
||||||
.server_keys
|
.server_keys
|
||||||
.hash_and_sign_event(&mut leave_event_stub, &room_version_id)?;
|
.hash_and_sign_event(&mut leave_event_stub, &room_version_rules)?;
|
||||||
|
|
||||||
// Generate event id
|
// Generate event id
|
||||||
let event_id = gen_event_id(&leave_event_stub, &room_version_id)?;
|
let event_id = gen_event_id(&leave_event_stub, &room_version_rules)?;
|
||||||
|
|
||||||
// Add event_id back
|
// Add event_id back
|
||||||
leave_event_stub
|
leave_event_stub
|
||||||
@@ -393,14 +386,14 @@ pub async fn remote_leave_room<S: ::std::hash::BuildHasher>(
|
|||||||
.sending
|
.sending
|
||||||
.send_federation_request(
|
.send_federation_request(
|
||||||
&remote_server,
|
&remote_server,
|
||||||
federation::membership::create_leave_event::v2::Request {
|
federation::membership::create_leave_event::v2::Request::new(
|
||||||
room_id: room_id.to_owned(),
|
room_id.to_owned(),
|
||||||
event_id: event_id.clone(),
|
event_id.clone(),
|
||||||
pdu: services
|
services
|
||||||
.sending
|
.sending
|
||||||
.convert_to_outgoing_federation_event(leave_event.clone())
|
.convert_to_outgoing_federation_event(leave_event.clone())
|
||||||
.await,
|
.await,
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use conduwuit::{
|
|||||||
use futures::{FutureExt, StreamExt, future::join};
|
use futures::{FutureExt, StreamExt, future::join};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::membership::{
|
api::client::membership::{
|
||||||
get_member_events::{self, v3::MembershipEventFilter},
|
get_member_events::{self},
|
||||||
joined_members::{self, v3::RoomMember},
|
joined_members::{self, v3::RoomMember},
|
||||||
},
|
},
|
||||||
events::{
|
events::{
|
||||||
@@ -43,20 +43,20 @@ pub(crate) async fn get_member_events_route(
|
|||||||
return Err!(Request(Forbidden("You don't have permission to view this room.")));
|
return Err!(Request(Forbidden("You don't have permission to view this room.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_member_events::v3::Response {
|
let chunk = services
|
||||||
chunk: services
|
.rooms
|
||||||
.rooms
|
.state_accessor
|
||||||
.state_accessor
|
.room_state_full(&body.room_id)
|
||||||
.room_state_full(&body.room_id)
|
.ready_filter_map(Result::ok)
|
||||||
.ready_filter_map(Result::ok)
|
.ready_filter(|((ty, _), _)| *ty == StateEventType::RoomMember)
|
||||||
.ready_filter(|((ty, _), _)| *ty == StateEventType::RoomMember)
|
.map(at!(1))
|
||||||
.map(at!(1))
|
.ready_filter_map(|pdu| membership_filter(pdu, membership, not_membership))
|
||||||
.ready_filter_map(|pdu| membership_filter(pdu, membership, not_membership))
|
.map(Event::into_format)
|
||||||
.map(Event::into_format)
|
.collect()
|
||||||
.collect()
|
.boxed()
|
||||||
.boxed()
|
.await;
|
||||||
.await,
|
|
||||||
})
|
Ok(get_member_events::v3::Response::new(chunk))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/joined_members`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/joined_members`
|
||||||
@@ -78,70 +78,46 @@ pub(crate) async fn joined_members_route(
|
|||||||
return Err!(Request(Forbidden("You don't have permission to view this room.")));
|
return Err!(Request(Forbidden("You don't have permission to view this room.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(joined_members::v3::Response {
|
let joined = services
|
||||||
joined: services
|
.rooms
|
||||||
.rooms
|
.state_cache
|
||||||
.state_cache
|
.room_members(&body.room_id)
|
||||||
.room_members(&body.room_id)
|
.broad_then(|user_id| async move {
|
||||||
.map(ToOwned::to_owned)
|
let mut member = RoomMember::new();
|
||||||
.broad_then(|user_id| async move {
|
let (display_name, avatar_url) = join(
|
||||||
let (display_name, avatar_url) = join(
|
services.users.displayname(&user_id).ok(),
|
||||||
services.users.displayname(&user_id).ok(),
|
services.users.avatar_url(&user_id).ok(),
|
||||||
services.users.avatar_url(&user_id).ok(),
|
)
|
||||||
)
|
.await;
|
||||||
.await;
|
member.display_name = display_name;
|
||||||
|
member.avatar_url = avatar_url;
|
||||||
|
|
||||||
(user_id, RoomMember { display_name, avatar_url })
|
(user_id, member)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
.await,
|
.await;
|
||||||
})
|
|
||||||
|
Ok(joined_members::v3::Response::new(joined))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn membership_filter<Pdu: Event>(
|
fn membership_filter<Pdu: Event>(
|
||||||
pdu: Pdu,
|
pdu: Pdu,
|
||||||
for_membership: Option<&MembershipEventFilter>,
|
membership_state_filter: Option<&MembershipState>,
|
||||||
not_membership: Option<&MembershipEventFilter>,
|
not_membership_state_filter: Option<&MembershipState>,
|
||||||
) -> Option<impl Event> {
|
) -> Option<impl Event> {
|
||||||
let membership_state_filter = match for_membership {
|
|
||||||
| Some(MembershipEventFilter::Ban) => MembershipState::Ban,
|
|
||||||
| Some(MembershipEventFilter::Invite) => MembershipState::Invite,
|
|
||||||
| Some(MembershipEventFilter::Knock) => MembershipState::Knock,
|
|
||||||
| Some(MembershipEventFilter::Leave) => MembershipState::Leave,
|
|
||||||
| Some(_) | None => MembershipState::Join,
|
|
||||||
};
|
|
||||||
|
|
||||||
let not_membership_state_filter = match not_membership {
|
|
||||||
| Some(MembershipEventFilter::Ban) => MembershipState::Ban,
|
|
||||||
| Some(MembershipEventFilter::Invite) => MembershipState::Invite,
|
|
||||||
| Some(MembershipEventFilter::Join) => MembershipState::Join,
|
|
||||||
| Some(MembershipEventFilter::Knock) => MembershipState::Knock,
|
|
||||||
| Some(_) | None => MembershipState::Leave,
|
|
||||||
};
|
|
||||||
|
|
||||||
let evt_membership = pdu.get_content::<RoomMemberEventContent>().ok()?.membership;
|
let evt_membership = pdu.get_content::<RoomMemberEventContent>().ok()?.membership;
|
||||||
|
|
||||||
if for_membership.is_some() && not_membership.is_some() {
|
if let Some(membership_state_filter) = membership_state_filter
|
||||||
if membership_state_filter != evt_membership
|
&& *membership_state_filter != evt_membership
|
||||||
|| not_membership_state_filter == evt_membership
|
{
|
||||||
{
|
return None;
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(pdu)
|
|
||||||
}
|
|
||||||
} else if for_membership.is_some() && not_membership.is_none() {
|
|
||||||
if membership_state_filter != evt_membership {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(pdu)
|
|
||||||
}
|
|
||||||
} else if not_membership.is_some() && for_membership.is_none() {
|
|
||||||
if not_membership_state_filter == evt_membership {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(pdu)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Some(pdu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(not_membership_state_filter) = not_membership_state_filter
|
||||||
|
&& *not_membership_state_filter == evt_membership
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(pdu)
|
||||||
}
|
}
|
||||||
@@ -47,15 +47,14 @@ pub(crate) async fn joined_rooms_route(
|
|||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
body: Ruma<joined_rooms::v3::Request>,
|
body: Ruma<joined_rooms::v3::Request>,
|
||||||
) -> Result<joined_rooms::v3::Response> {
|
) -> Result<joined_rooms::v3::Response> {
|
||||||
Ok(joined_rooms::v3::Response {
|
let joined_rooms = services
|
||||||
joined_rooms: services
|
.rooms
|
||||||
.rooms
|
.state_cache
|
||||||
.state_cache
|
.rooms_joined(body.sender_user())
|
||||||
.rooms_joined(body.sender_user())
|
.collect()
|
||||||
.map(ToOwned::to_owned)
|
.await;
|
||||||
.collect()
|
|
||||||
.await,
|
Ok(joined_rooms::v3::Response::new(joined_rooms))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if the room is banned in any way possible and the sender user is not
|
/// Checks if the room is banned in any way possible and the sender user is not
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result, matrix::pdu::PduBuilder};
|
use conduwuit::{Err, Result, matrix::pdu::PartialPdu};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::membership::unban_user,
|
api::client::membership::unban_user,
|
||||||
events::room::member::{MembershipState, RoomMemberEventContent},
|
events::room::member::{MembershipState, RoomMemberEventContent},
|
||||||
@@ -18,9 +18,9 @@ pub(crate) async fn unban_user_route(
|
|||||||
if services.users.is_suspended(sender_user).await? {
|
if services.users.is_suspended(sender_user).await? {
|
||||||
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
||||||
}
|
}
|
||||||
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
let state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
|
||||||
|
|
||||||
let current_member_content = services
|
let mut current_member_content = services
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.get_member(&body.room_id, &body.user_id)
|
.get_member(&body.room_id, &body.user_id)
|
||||||
@@ -34,18 +34,17 @@ pub(crate) async fn unban_user_route(
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current_member_content.membership = MembershipState::Leave;
|
||||||
|
current_member_content.reason.clone_from(&body.reason);
|
||||||
|
current_member_content.join_authorized_via_users_server = None;
|
||||||
|
current_member_content.third_party_invite = None;
|
||||||
|
current_member_content.is_direct = None;
|
||||||
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent {
|
PartialPdu::state(body.user_id.to_string(), ¤t_member_content),
|
||||||
membership: MembershipState::Leave,
|
|
||||||
reason: body.reason.clone(),
|
|
||||||
join_authorized_via_users_server: None,
|
|
||||||
third_party_invite: None,
|
|
||||||
is_direct: None,
|
|
||||||
..current_member_content
|
|
||||||
}),
|
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
|
|||||||
+13
-10
@@ -26,15 +26,17 @@ use ruma::{
|
|||||||
DeviceId, RoomId, UserId,
|
DeviceId, RoomId, UserId,
|
||||||
api::{
|
api::{
|
||||||
Direction,
|
Direction,
|
||||||
client::{error::ErrorKind, filter::RoomEventFilter, message::get_message_events},
|
client::{filter::RoomEventFilter, message::get_message_events},
|
||||||
|
error::{ErrorKind, SenderIgnoredErrorData},
|
||||||
},
|
},
|
||||||
|
assign,
|
||||||
events::{
|
events::{
|
||||||
AnyStateEvent, StateEventType,
|
AnyStateEvent, StateEventType,
|
||||||
TimelineEventType::{self, *},
|
TimelineEventType::{self, *},
|
||||||
invite_permission_config::FilterLevel,
|
|
||||||
},
|
},
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
};
|
};
|
||||||
|
use ruminuwuity::invite_permission_config::FilterLevel;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
@@ -74,7 +76,6 @@ pub(crate) async fn get_message_events_route(
|
|||||||
InsecureClientIp(client_ip): InsecureClientIp,
|
InsecureClientIp(client_ip): InsecureClientIp,
|
||||||
body: Ruma<get_message_events::v3::Request>,
|
body: Ruma<get_message_events::v3::Request>,
|
||||||
) -> Result<get_message_events::v3::Response> {
|
) -> Result<get_message_events::v3::Response> {
|
||||||
debug_assert!(IGNORED_MESSAGE_TYPES.is_sorted(), "IGNORED_MESSAGE_TYPES is not sorted");
|
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
let sender_device = body.sender_device.as_deref();
|
let sender_device = body.sender_device.as_deref();
|
||||||
let room_id = &body.room_id;
|
let room_id = &body.room_id;
|
||||||
@@ -199,12 +200,12 @@ pub(crate) async fn get_message_events_route(
|
|||||||
.map(Event::into_format)
|
.map(Event::into_format)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(get_message_events::v3::Response {
|
Ok(assign!(get_message_events::v3::Response::new(), {
|
||||||
start: from.to_string(),
|
start: from.to_string(),
|
||||||
end: next_token.as_ref().map(PduCount::to_string),
|
end: next_token.as_ref().map(PduCount::to_string),
|
||||||
chunk,
|
chunk: chunk,
|
||||||
state,
|
state: state,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn lazy_loading_witness<'a, I>(
|
pub(crate) async fn lazy_loading_witness<'a, I>(
|
||||||
@@ -301,7 +302,7 @@ where
|
|||||||
{
|
{
|
||||||
// exclude Synapse's dummy events from bloating up response bodies. clients
|
// exclude Synapse's dummy events from bloating up response bodies. clients
|
||||||
// don't need to see this.
|
// don't need to see this.
|
||||||
if event.kind().to_cow_str() == "org.matrix.dummy_event" {
|
if event.kind().to_string() == "org.matrix.dummy_event" {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +324,7 @@ where
|
|||||||
if server_ignored {
|
if server_ignored {
|
||||||
// the sender's server is ignored, so ignore this event
|
// the sender's server is ignored, so ignore this event
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::SenderIgnored { sender: None },
|
ErrorKind::SenderIgnored(SenderIgnoredErrorData::new()),
|
||||||
"The sender's server is ignored by this server.",
|
"The sender's server is ignored by this server.",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -332,7 +333,9 @@ where
|
|||||||
// the recipient of this PDU has the sender ignored, and we're not
|
// the recipient of this PDU has the sender ignored, and we're not
|
||||||
// configured to send ignored messages to clients
|
// configured to send ignored messages to clients
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::SenderIgnored { sender: Some(event.sender().to_owned()) },
|
ErrorKind::SenderIgnored(SenderIgnoredErrorData::with_sender(
|
||||||
|
event.sender().to_owned(),
|
||||||
|
)),
|
||||||
"You have ignored this sender.",
|
"You have ignored this sender.",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ pub(super) mod media;
|
|||||||
pub(super) mod media_legacy;
|
pub(super) mod media_legacy;
|
||||||
pub(super) mod membership;
|
pub(super) mod membership;
|
||||||
pub(super) mod message;
|
pub(super) mod message;
|
||||||
|
pub(super) mod mutual_rooms;
|
||||||
pub(super) mod openid;
|
pub(super) mod openid;
|
||||||
pub(super) mod presence;
|
pub(super) mod presence;
|
||||||
pub(super) mod profile;
|
pub(super) mod profile;
|
||||||
@@ -35,7 +36,6 @@ pub(super) mod thirdparty;
|
|||||||
pub(super) mod threads;
|
pub(super) mod threads;
|
||||||
pub(super) mod to_device;
|
pub(super) mod to_device;
|
||||||
pub(super) mod typing;
|
pub(super) mod typing;
|
||||||
pub(super) mod unstable;
|
|
||||||
pub(super) mod unversioned;
|
pub(super) mod unversioned;
|
||||||
pub(super) mod user_directory;
|
pub(super) mod user_directory;
|
||||||
pub(super) mod voip;
|
pub(super) mod voip;
|
||||||
@@ -60,10 +60,10 @@ pub(super) use media_legacy::*;
|
|||||||
pub(super) use membership::*;
|
pub(super) use membership::*;
|
||||||
pub use membership::{join_room_by_id_helper, leave_all_rooms, leave_room, remote_leave_room};
|
pub use membership::{join_room_by_id_helper, leave_all_rooms, leave_room, remote_leave_room};
|
||||||
pub(super) use message::*;
|
pub(super) use message::*;
|
||||||
|
pub(super) use mutual_rooms::*;
|
||||||
pub(super) use openid::*;
|
pub(super) use openid::*;
|
||||||
pub(super) use presence::*;
|
pub(super) use presence::*;
|
||||||
pub(super) use profile::*;
|
pub(super) use profile::*;
|
||||||
pub use profile::{update_all_rooms, update_avatar_url, update_displayname};
|
|
||||||
pub use push::recreate_push_rules_and_return;
|
pub use push::recreate_push_rules_and_return;
|
||||||
pub(super) use push::*;
|
pub(super) use push::*;
|
||||||
pub(super) use read_marker::*;
|
pub(super) use read_marker::*;
|
||||||
@@ -82,7 +82,6 @@ pub(super) use thirdparty::*;
|
|||||||
pub(super) use threads::*;
|
pub(super) use threads::*;
|
||||||
pub(super) use to_device::*;
|
pub(super) use to_device::*;
|
||||||
pub(super) use typing::*;
|
pub(super) use typing::*;
|
||||||
pub(super) use unstable::*;
|
|
||||||
pub(super) use unversioned::*;
|
pub(super) use unversioned::*;
|
||||||
pub(super) use user_directory::*;
|
pub(super) use user_directory::*;
|
||||||
pub(super) use voip::*;
|
pub(super) use voip::*;
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
use axum::extract::State;
|
||||||
|
use conduwuit::{Err, Result};
|
||||||
|
use futures::StreamExt;
|
||||||
|
use ruma::api::client::membership::mutual_rooms;
|
||||||
|
|
||||||
|
use crate::Ruma;
|
||||||
|
|
||||||
|
/// # `GET /_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms`
|
||||||
|
///
|
||||||
|
/// Gets all the rooms the sender shares with the specified user.
|
||||||
|
///
|
||||||
|
/// An implementation of [MSC2666](https://github.com/matrix-org/matrix-spec-proposals/pull/2666)
|
||||||
|
#[tracing::instrument(skip_all, name = "mutual_rooms", level = "info")]
|
||||||
|
pub(crate) async fn get_mutual_rooms_route(
|
||||||
|
State(services): State<crate::State>,
|
||||||
|
body: Ruma<mutual_rooms::unstable::Request>,
|
||||||
|
) -> Result<mutual_rooms::unstable::Response> {
|
||||||
|
let sender_user = body.sender_user();
|
||||||
|
|
||||||
|
if sender_user == body.user_id {
|
||||||
|
return Err!(Request(Unknown("You cannot request rooms in common with yourself.")));
|
||||||
|
}
|
||||||
|
|
||||||
|
if !services.users.exists(&body.user_id).await {
|
||||||
|
return Ok(mutual_rooms::unstable::Response::new(vec![]));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mutual_rooms = services
|
||||||
|
.rooms
|
||||||
|
.state_cache
|
||||||
|
.get_shared_rooms(sender_user, &body.user_id)
|
||||||
|
.collect()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
Ok(mutual_rooms::unstable::Response::new(mutual_rooms))
|
||||||
|
}
|
||||||
@@ -29,10 +29,10 @@ pub(crate) async fn create_openid_token_route(
|
|||||||
.users
|
.users
|
||||||
.create_openid_token(&body.user_id, &access_token)?;
|
.create_openid_token(&body.user_id, &access_token)?;
|
||||||
|
|
||||||
Ok(account::request_openid_token::v3::Response {
|
Ok(account::request_openid_token::v3::Response::new(
|
||||||
access_token,
|
access_token,
|
||||||
token_type: TokenType::Bearer,
|
TokenType::Bearer,
|
||||||
matrix_server_name: services.server.name.clone(),
|
services.server.name.clone(),
|
||||||
expires_in: Duration::from_secs(expires_in),
|
Duration::from_secs(expires_in),
|
||||||
})
|
))
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,10 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result};
|
use conduwuit::{Err, Result};
|
||||||
use ruma::api::client::presence::{get_presence, set_presence};
|
use ruma::{
|
||||||
|
api::client::presence::{get_presence, set_presence},
|
||||||
|
assign,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
@@ -26,7 +29,7 @@ pub(crate) async fn set_presence_route(
|
|||||||
.set_presence(body.sender_user(), &body.presence, None, None, body.status_msg.clone())
|
.set_presence(body.sender_user(), &body.presence, None, None, body.status_msg.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(set_presence::v3::Response {})
|
Ok(set_presence::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/presence/{userId}/status`
|
/// # `GET /_matrix/client/r0/presence/{userId}/status`
|
||||||
@@ -76,13 +79,11 @@ pub(crate) async fn get_presence_route(
|
|||||||
.map(|millis| Duration::from_millis(millis.into())),
|
.map(|millis| Duration::from_millis(millis.into())),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_presence::v3::Response {
|
Ok(assign!(get_presence::v3::Response::new(presence.content.presence), {
|
||||||
// TODO: Should ruma just use the presenceeventcontent type here?
|
|
||||||
status_msg,
|
status_msg,
|
||||||
currently_active: presence.content.currently_active,
|
currently_active: presence.content.currently_active,
|
||||||
last_active_ago,
|
last_active_ago,
|
||||||
presence: presence.content.presence,
|
}))
|
||||||
})
|
|
||||||
},
|
},
|
||||||
| _ => Err!(Request(NotFound("Presence state for this user was not found"))),
|
| _ => Err!(Request(NotFound("Presence state for this user was not found"))),
|
||||||
}
|
}
|
||||||
|
|||||||
+290
-379
@@ -1,227 +1,26 @@
|
|||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{
|
use conduwuit::{Err, Result, matrix::pdu::PartialPdu};
|
||||||
Err, Result,
|
|
||||||
matrix::pdu::PduBuilder,
|
|
||||||
utils::{IterStream, future::TryExtExt, stream::TryIgnore},
|
|
||||||
warn,
|
|
||||||
};
|
|
||||||
use conduwuit_service::Services;
|
use conduwuit_service::Services;
|
||||||
use futures::{
|
use futures::StreamExt;
|
||||||
StreamExt, TryStreamExt,
|
|
||||||
future::{join, join3, join4},
|
|
||||||
};
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedMxcUri, OwnedRoomId, UserId,
|
UserId,
|
||||||
api::{
|
api::{
|
||||||
client::profile::{
|
client::profile::{
|
||||||
get_avatar_url, get_display_name, get_profile, set_avatar_url, set_display_name,
|
delete_profile_field, get_profile, get_profile_field, set_profile_field,
|
||||||
},
|
},
|
||||||
federation,
|
federation,
|
||||||
},
|
},
|
||||||
|
assign,
|
||||||
events::room::member::{MembershipState, RoomMemberEventContent},
|
events::room::member::{MembershipState, RoomMemberEventContent},
|
||||||
presence::PresenceState,
|
presence::PresenceState,
|
||||||
|
profile::{ProfileFieldName, ProfileFieldValue},
|
||||||
};
|
};
|
||||||
|
use serde_json::{Value, to_value};
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/profile/{userId}/displayname`
|
|
||||||
///
|
|
||||||
/// Updates the displayname.
|
|
||||||
///
|
|
||||||
/// - Also makes sure other users receive the update using presence EDUs
|
|
||||||
pub(crate) async fn set_displayname_route(
|
|
||||||
State(services): State<crate::State>,
|
|
||||||
body: Ruma<set_display_name::v3::Request>,
|
|
||||||
) -> Result<set_display_name::v3::Response> {
|
|
||||||
let sender_user = body.sender_user();
|
|
||||||
if services.users.is_suspended(sender_user).await? {
|
|
||||||
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
|
||||||
}
|
|
||||||
|
|
||||||
if *sender_user != body.user_id && body.appservice_info.is_none() {
|
|
||||||
return Err!(Request(Forbidden("You cannot update the profile of another user")));
|
|
||||||
}
|
|
||||||
|
|
||||||
let all_joined_rooms: Vec<OwnedRoomId> = services
|
|
||||||
.rooms
|
|
||||||
.state_cache
|
|
||||||
.rooms_joined(&body.user_id)
|
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
update_displayname(&services, &body.user_id, body.displayname.clone(), &all_joined_rooms)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
if services.config.allow_local_presence {
|
|
||||||
// Presence update
|
|
||||||
services
|
|
||||||
.presence
|
|
||||||
.ping_presence(&body.user_id, &PresenceState::Online)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(set_display_name::v3::Response {})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// # `GET /_matrix/client/v3/profile/{userId}/displayname`
|
|
||||||
///
|
|
||||||
/// Returns the displayname of the user.
|
|
||||||
///
|
|
||||||
/// - If user is on another server and we do not have a local copy already fetch
|
|
||||||
/// displayname over federation
|
|
||||||
pub(crate) async fn get_displayname_route(
|
|
||||||
State(services): State<crate::State>,
|
|
||||||
body: Ruma<get_display_name::v3::Request>,
|
|
||||||
) -> Result<get_display_name::v3::Response> {
|
|
||||||
if !services.globals.user_is_local(&body.user_id) {
|
|
||||||
// Create and update our local copy of the user
|
|
||||||
if let Ok(response) = services
|
|
||||||
.sending
|
|
||||||
.send_federation_request(
|
|
||||||
body.user_id.server_name(),
|
|
||||||
federation::query::get_profile_information::v1::Request {
|
|
||||||
user_id: body.user_id.clone(),
|
|
||||||
field: None, // we want the full user's profile to update locally too
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
if !services.users.exists(&body.user_id).await {
|
|
||||||
services.users.create(&body.user_id, None, None).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
services
|
|
||||||
.users
|
|
||||||
.set_displayname(&body.user_id, response.displayname.clone());
|
|
||||||
services
|
|
||||||
.users
|
|
||||||
.set_avatar_url(&body.user_id, response.avatar_url.clone());
|
|
||||||
services
|
|
||||||
.users
|
|
||||||
.set_blurhash(&body.user_id, response.blurhash.clone());
|
|
||||||
|
|
||||||
return Ok(get_display_name::v3::Response { displayname: response.displayname });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !services.users.exists(&body.user_id).await {
|
|
||||||
// Return 404 if this user doesn't exist and we couldn't fetch it over
|
|
||||||
// federation
|
|
||||||
return Err!(Request(NotFound("Profile was not found.")));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(get_display_name::v3::Response {
|
|
||||||
displayname: services.users.displayname(&body.user_id).await.ok(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/v3/profile/{userId}/avatar_url`
|
|
||||||
///
|
|
||||||
/// Updates the `avatar_url` and `blurhash`.
|
|
||||||
///
|
|
||||||
/// - Also makes sure other users receive the update using presence EDUs
|
|
||||||
pub(crate) async fn set_avatar_url_route(
|
|
||||||
State(services): State<crate::State>,
|
|
||||||
body: Ruma<set_avatar_url::v3::Request>,
|
|
||||||
) -> Result<set_avatar_url::v3::Response> {
|
|
||||||
let sender_user = body.sender_user();
|
|
||||||
if services.users.is_suspended(sender_user).await? {
|
|
||||||
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
|
||||||
}
|
|
||||||
|
|
||||||
if *sender_user != body.user_id && body.appservice_info.is_none() {
|
|
||||||
return Err!(Request(Forbidden("You cannot update the profile of another user")));
|
|
||||||
}
|
|
||||||
|
|
||||||
let all_joined_rooms: Vec<OwnedRoomId> = services
|
|
||||||
.rooms
|
|
||||||
.state_cache
|
|
||||||
.rooms_joined(&body.user_id)
|
|
||||||
.map(ToOwned::to_owned)
|
|
||||||
.collect()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
update_avatar_url(
|
|
||||||
&services,
|
|
||||||
&body.user_id,
|
|
||||||
body.avatar_url.clone(),
|
|
||||||
body.blurhash.clone(),
|
|
||||||
&all_joined_rooms,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
if services.config.allow_local_presence {
|
|
||||||
// Presence update
|
|
||||||
services
|
|
||||||
.presence
|
|
||||||
.ping_presence(&body.user_id, &PresenceState::Online)
|
|
||||||
.await
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(set_avatar_url::v3::Response {})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// # `GET /_matrix/client/v3/profile/{userId}/avatar_url`
|
|
||||||
///
|
|
||||||
/// Returns the `avatar_url` and `blurhash` of the user.
|
|
||||||
///
|
|
||||||
/// - If user is on another server and we do not have a local copy already fetch
|
|
||||||
/// `avatar_url` and blurhash over federation
|
|
||||||
pub(crate) async fn get_avatar_url_route(
|
|
||||||
State(services): State<crate::State>,
|
|
||||||
body: Ruma<get_avatar_url::v3::Request>,
|
|
||||||
) -> Result<get_avatar_url::v3::Response> {
|
|
||||||
if !services.globals.user_is_local(&body.user_id) {
|
|
||||||
// Create and update our local copy of the user
|
|
||||||
if let Ok(response) = services
|
|
||||||
.sending
|
|
||||||
.send_federation_request(
|
|
||||||
body.user_id.server_name(),
|
|
||||||
federation::query::get_profile_information::v1::Request {
|
|
||||||
user_id: body.user_id.clone(),
|
|
||||||
field: None, // we want the full user's profile to update locally as well
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
if !services.users.exists(&body.user_id).await {
|
|
||||||
services.users.create(&body.user_id, None, None).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
services
|
|
||||||
.users
|
|
||||||
.set_displayname(&body.user_id, response.displayname.clone());
|
|
||||||
services
|
|
||||||
.users
|
|
||||||
.set_avatar_url(&body.user_id, response.avatar_url.clone());
|
|
||||||
services
|
|
||||||
.users
|
|
||||||
.set_blurhash(&body.user_id, response.blurhash.clone());
|
|
||||||
|
|
||||||
return Ok(get_avatar_url::v3::Response {
|
|
||||||
avatar_url: response.avatar_url,
|
|
||||||
blurhash: response.blurhash,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !services.users.exists(&body.user_id).await {
|
|
||||||
// Return 404 if this user doesn't exist and we couldn't fetch it over
|
|
||||||
// federation
|
|
||||||
return Err!(Request(NotFound("Profile was not found.")));
|
|
||||||
}
|
|
||||||
|
|
||||||
let (avatar_url, blurhash) = join(
|
|
||||||
services.users.avatar_url(&body.user_id).ok(),
|
|
||||||
services.users.blurhash(&body.user_id).ok(),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
Ok(get_avatar_url::v3::Response { avatar_url, blurhash })
|
|
||||||
}
|
|
||||||
|
|
||||||
/// # `GET /_matrix/client/v3/profile/{userId}`
|
/// # `GET /_matrix/client/v3/profile/{userId}`
|
||||||
///
|
///
|
||||||
/// Returns the displayname, avatar_url, blurhash, and custom profile fields of
|
/// Returns the displayname, avatar_url, blurhash, and custom profile fields of
|
||||||
@@ -233,184 +32,296 @@ pub(crate) async fn get_profile_route(
|
|||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
body: Ruma<get_profile::v3::Request>,
|
body: Ruma<get_profile::v3::Request>,
|
||||||
) -> Result<get_profile::v3::Response> {
|
) -> Result<get_profile::v3::Response> {
|
||||||
|
let Some(profile) = fetch_full_profile(&services, &body.user_id).await else {
|
||||||
|
return Err!(Request(NotFound("This user's profile could not be fetched.")));
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(get_profile::v3::Response::from_iter(profile))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get_profile_field_route(
|
||||||
|
State(services): State<crate::State>,
|
||||||
|
body: Ruma<get_profile_field::v3::Request>,
|
||||||
|
) -> Result<get_profile_field::v3::Response> {
|
||||||
|
let value = fetch_profile_field(&services, &body.user_id, body.field.clone()).await?;
|
||||||
|
|
||||||
|
Ok(assign!(get_profile_field::v3::Response::default(), { value }))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn set_profile_field_route(
|
||||||
|
State(services): State<crate::State>,
|
||||||
|
body: Ruma<set_profile_field::v3::Request>,
|
||||||
|
) -> Result<set_profile_field::v3::Response> {
|
||||||
|
if body.user_id != body.sender_user()
|
||||||
|
&& !(body.appservice_info.is_some()
|
||||||
|
|| services.admin.user_is_admin(body.sender_user()).await)
|
||||||
|
{
|
||||||
|
return Err!(Request(Forbidden("You may not change other users' profile data.")));
|
||||||
|
}
|
||||||
|
|
||||||
if !services.globals.user_is_local(&body.user_id) {
|
if !services.globals.user_is_local(&body.user_id) {
|
||||||
// Create and update our local copy of the user
|
return Err!(Request(InvalidParam("You may not change a remote user's profile data.")));
|
||||||
if let Ok(response) = services
|
}
|
||||||
.sending
|
|
||||||
.send_federation_request(
|
set_profile_field(&services, &body.user_id, ProfileFieldChange::Set(body.value.clone()))
|
||||||
body.user_id.server_name(),
|
.await;
|
||||||
federation::query::get_profile_information::v1::Request {
|
|
||||||
user_id: body.user_id.clone(),
|
Ok(set_profile_field::v3::Response::new())
|
||||||
field: None,
|
}
|
||||||
},
|
|
||||||
)
|
pub(crate) async fn delete_profile_field_route(
|
||||||
|
State(services): State<crate::State>,
|
||||||
|
body: Ruma<delete_profile_field::v3::Request>,
|
||||||
|
) -> Result<delete_profile_field::v3::Response> {
|
||||||
|
if body.user_id != body.sender_user()
|
||||||
|
&& !(body.appservice_info.is_some()
|
||||||
|
|| services.admin.user_is_admin(body.sender_user()).await)
|
||||||
|
{
|
||||||
|
return Err!(Request(Forbidden("You may not change other users' profile data.")));
|
||||||
|
}
|
||||||
|
|
||||||
|
if !services.globals.user_is_local(&body.user_id) {
|
||||||
|
return Err!(Request(InvalidParam("You may not change a remote user's profile data.")));
|
||||||
|
}
|
||||||
|
|
||||||
|
set_profile_field(&services, &body.user_id, ProfileFieldChange::Delete(body.field.clone()))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
Ok(delete_profile_field::v3::Response::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_full_profile(
|
||||||
|
services: &Services,
|
||||||
|
user_id: &UserId,
|
||||||
|
) -> Option<BTreeMap<String, Value>> {
|
||||||
|
// If the user exists locally, fetch their local profile
|
||||||
|
if services.users.exists(user_id).await {
|
||||||
|
return Some(get_local_profile(services, user_id).await);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise ask their homeserver
|
||||||
|
let Ok(response) = services
|
||||||
|
.sending
|
||||||
|
.send_federation_request(
|
||||||
|
user_id.server_name(),
|
||||||
|
federation::query::get_profile_information::v1::Request::new(user_id.to_owned()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update our local copies of their profile fields
|
||||||
|
services.users.clear_profile(user_id).await;
|
||||||
|
|
||||||
|
for (field, value) in response.iter() {
|
||||||
|
let Ok(value) = ProfileFieldValue::new(field, value.to_owned()) else {
|
||||||
|
// Skip malformed fields
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
set_profile_field(services, user_id, ProfileFieldChange::Set(value)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(BTreeMap::from_iter(response))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_profile_field(
|
||||||
|
services: &Services,
|
||||||
|
user_id: &UserId,
|
||||||
|
field: ProfileFieldName,
|
||||||
|
) -> Result<Option<ProfileFieldValue>> {
|
||||||
|
// If the user exists locally, fetch their local profile field
|
||||||
|
if services.globals.user_is_local(user_id) {
|
||||||
|
return Ok(get_local_profile_field(services, user_id, field).await);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise ask their homeserver
|
||||||
|
let Ok(response) = services
|
||||||
|
.sending
|
||||||
|
.send_federation_request(
|
||||||
|
user_id.server_name(),
|
||||||
|
assign!(federation::query::get_profile_information::v1::Request::new(user_id.to_owned()), {
|
||||||
|
field: Some(field.clone())
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
else {
|
||||||
|
return Err!(Request(NotFound(
|
||||||
|
"User's homeserver could not provide this profile field."
|
||||||
|
)));
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(value) = response.get(field.as_str()).map(ToOwned::to_owned) {
|
||||||
|
if let Ok(value) = ProfileFieldValue::new(field.as_str(), value) {
|
||||||
|
set_profile_field(services, user_id, ProfileFieldChange::Set(value.clone())).await;
|
||||||
|
|
||||||
|
Ok(Some(value))
|
||||||
|
} else {
|
||||||
|
Err!(Request(Unknown(
|
||||||
|
"User's homeserver returned malformed data for this profile field."
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
set_profile_field(services, user_id, ProfileFieldChange::Delete(field)).await;
|
||||||
|
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get_local_profile(
|
||||||
|
services: &Services,
|
||||||
|
user_id: &UserId,
|
||||||
|
) -> BTreeMap<String, Value> {
|
||||||
|
let mut profile = BTreeMap::new();
|
||||||
|
|
||||||
|
// Get displayname and avatar_url independently because `all_profile_keys`
|
||||||
|
// doesn't include them
|
||||||
|
for field in [ProfileFieldName::AvatarUrl, ProfileFieldName::DisplayName] {
|
||||||
|
let key = field.as_str().to_owned();
|
||||||
|
|
||||||
|
if let Some(value) = get_local_profile_field(services, user_id, field).await {
|
||||||
|
profile.insert(key, value.value().into_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert all other profile fields
|
||||||
|
let mut all_fields = services.users.all_profile_keys(user_id);
|
||||||
|
|
||||||
|
while let Some((key, value)) = all_fields.next().await {
|
||||||
|
profile.insert(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
profile
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get_local_profile_field(
|
||||||
|
services: &Services,
|
||||||
|
user_id: &UserId,
|
||||||
|
field: ProfileFieldName,
|
||||||
|
) -> Option<ProfileFieldValue> {
|
||||||
|
let value = match field.clone() {
|
||||||
|
| ProfileFieldName::AvatarUrl => services
|
||||||
|
.users
|
||||||
|
.avatar_url(user_id)
|
||||||
.await
|
.await
|
||||||
{
|
.ok()
|
||||||
if !services.users.exists(&body.user_id).await {
|
.map(to_value)
|
||||||
services.users.create(&body.user_id, None, None).await?;
|
.transpose()
|
||||||
}
|
.expect("converting avatar url to value should succeed"),
|
||||||
|
| ProfileFieldName::DisplayName => services
|
||||||
|
.users
|
||||||
|
.displayname(user_id)
|
||||||
|
.await
|
||||||
|
.ok()
|
||||||
|
.map(to_value)
|
||||||
|
.transpose()
|
||||||
|
.expect("converting displayname to value should succeed"),
|
||||||
|
| other => services
|
||||||
|
.users
|
||||||
|
.profile_key(user_id, other.as_str())
|
||||||
|
.await
|
||||||
|
.ok(),
|
||||||
|
}?;
|
||||||
|
|
||||||
services
|
Some(
|
||||||
.users
|
ProfileFieldValue::new(field.as_str(), value)
|
||||||
.set_displayname(&body.user_id, response.displayname.clone());
|
.expect("local profile field should be valid"),
|
||||||
services
|
)
|
||||||
.users
|
}
|
||||||
.set_avatar_url(&body.user_id, response.avatar_url.clone());
|
|
||||||
services
|
|
||||||
.users
|
|
||||||
.set_blurhash(&body.user_id, response.blurhash.clone());
|
|
||||||
|
|
||||||
for (profile_key, profile_key_value) in &response.custom_profile_fields {
|
enum ProfileFieldChange {
|
||||||
|
Set(ProfileFieldValue),
|
||||||
|
Delete(ProfileFieldName),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProfileFieldChange {
|
||||||
|
fn field_name(&self) -> ProfileFieldName {
|
||||||
|
match self {
|
||||||
|
| &Self::Delete(ref name) => name.clone(),
|
||||||
|
| &Self::Set(ref value) => value.field_name(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn value(&self) -> Option<Value> {
|
||||||
|
if let Self::Set(value) = self {
|
||||||
|
Some(value.value().into_owned())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn set_profile_field(services: &Services, user_id: &UserId, change: ProfileFieldChange) {
|
||||||
|
let field_name = change.field_name();
|
||||||
|
|
||||||
|
match change {
|
||||||
|
| ProfileFieldChange::Set(ProfileFieldValue::DisplayName(displayname)) => {
|
||||||
|
services
|
||||||
|
.users
|
||||||
|
.set_displayname(user_id, Some(displayname).filter(|dn| !dn.is_empty()));
|
||||||
|
},
|
||||||
|
| ProfileFieldChange::Set(ProfileFieldValue::AvatarUrl(avatar_url)) => {
|
||||||
|
services
|
||||||
|
.users
|
||||||
|
.set_avatar_url(user_id, Some(avatar_url).filter(|av| av.is_valid()));
|
||||||
|
},
|
||||||
|
| ProfileFieldChange::Delete(ProfileFieldName::DisplayName) => {
|
||||||
|
services.users.set_displayname(user_id, None);
|
||||||
|
},
|
||||||
|
| ProfileFieldChange::Delete(ProfileFieldName::AvatarUrl) => {
|
||||||
|
services.users.set_avatar_url(user_id, None);
|
||||||
|
},
|
||||||
|
| other =>
|
||||||
|
if other.field_name().as_str() == "blurhash" {
|
||||||
|
if let Some(Value::String(blurhash)) = other.value() {
|
||||||
|
services.users.set_blurhash(user_id, Some(blurhash));
|
||||||
|
} else {
|
||||||
|
services.users.set_blurhash(user_id, None);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
services.users.set_profile_key(
|
services.users.set_profile_key(
|
||||||
&body.user_id,
|
user_id,
|
||||||
profile_key,
|
other.field_name().as_str(),
|
||||||
Some(profile_key_value.clone()),
|
other.value(),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
}
|
||||||
|
|
||||||
return Ok(get_profile::v3::Response {
|
// If the user is local and changed their displayname or avatar_url, update it
|
||||||
displayname: response.displayname,
|
// in all their joined rooms
|
||||||
avatar_url: response.avatar_url,
|
if matches!(field_name, ProfileFieldName::AvatarUrl | ProfileFieldName::DisplayName)
|
||||||
blurhash: response.blurhash,
|
&& services.users.is_active_local(user_id).await
|
||||||
custom_profile_fields: response.custom_profile_fields,
|
{
|
||||||
});
|
let displayname = services.users.displayname(user_id).await.ok();
|
||||||
|
let avatar_url = services.users.avatar_url(user_id).await.ok();
|
||||||
|
let membership_content = assign!(
|
||||||
|
RoomMemberEventContent::new(MembershipState::Join), { displayname, avatar_url }
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut all_joined_rooms = services.rooms.state_cache.rooms_joined(user_id);
|
||||||
|
|
||||||
|
while let Some(room_id) = all_joined_rooms.next().await {
|
||||||
|
let state_lock = services.rooms.state.mutex.lock(room_id.as_str()).await;
|
||||||
|
|
||||||
|
let _ = services
|
||||||
|
.rooms
|
||||||
|
.timeline
|
||||||
|
.build_and_append_pdu(
|
||||||
|
PartialPdu::state(user_id.to_string(), &membership_content),
|
||||||
|
user_id,
|
||||||
|
Some(&room_id),
|
||||||
|
&state_lock,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if !services.users.exists(&body.user_id).await {
|
if services.config.allow_local_presence {
|
||||||
// Return 404 if this user doesn't exist and we couldn't fetch it over
|
// Send a presence EDU to indicate the profile changed
|
||||||
// federation
|
let _ = services
|
||||||
return Err!(Request(NotFound("Profile was not found.")));
|
.presence
|
||||||
}
|
.ping_presence(user_id, &PresenceState::Online)
|
||||||
|
.await;
|
||||||
let (avatar_url, blurhash, displayname, custom_profile_fields) = join4(
|
|
||||||
services.users.avatar_url(&body.user_id).ok(),
|
|
||||||
services.users.blurhash(&body.user_id).ok(),
|
|
||||||
services.users.displayname(&body.user_id).ok(),
|
|
||||||
services.users.all_profile_keys(&body.user_id).collect(),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
Ok(get_profile::v3::Response {
|
|
||||||
avatar_url,
|
|
||||||
blurhash,
|
|
||||||
displayname,
|
|
||||||
custom_profile_fields,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update_displayname(
|
|
||||||
services: &Services,
|
|
||||||
user_id: &UserId,
|
|
||||||
displayname: Option<String>,
|
|
||||||
all_joined_rooms: &[OwnedRoomId],
|
|
||||||
) {
|
|
||||||
let (current_avatar_url, current_blurhash, current_displayname) = join3(
|
|
||||||
services.users.avatar_url(user_id).ok(),
|
|
||||||
services.users.blurhash(user_id).ok(),
|
|
||||||
services.users.displayname(user_id).ok(),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
if displayname == current_displayname {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
services.users.set_displayname(user_id, displayname.clone());
|
|
||||||
|
|
||||||
// Send a new join membership event into all joined rooms
|
|
||||||
let avatar_url = ¤t_avatar_url;
|
|
||||||
let blurhash = ¤t_blurhash;
|
|
||||||
let displayname = &displayname;
|
|
||||||
let all_joined_rooms: Vec<_> = all_joined_rooms
|
|
||||||
.iter()
|
|
||||||
.try_stream()
|
|
||||||
.and_then(|room_id: &OwnedRoomId| async move {
|
|
||||||
let pdu = PduBuilder::state(user_id.to_string(), &RoomMemberEventContent {
|
|
||||||
displayname: displayname.clone(),
|
|
||||||
membership: MembershipState::Join,
|
|
||||||
avatar_url: avatar_url.clone(),
|
|
||||||
blurhash: blurhash.clone(),
|
|
||||||
join_authorized_via_users_server: None,
|
|
||||||
reason: None,
|
|
||||||
is_direct: None,
|
|
||||||
third_party_invite: None,
|
|
||||||
redact_events: None,
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok((pdu, room_id))
|
|
||||||
})
|
|
||||||
.ignore_err()
|
|
||||||
.collect()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
update_all_rooms(services, all_joined_rooms, user_id).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update_avatar_url(
|
|
||||||
services: &Services,
|
|
||||||
user_id: &UserId,
|
|
||||||
avatar_url: Option<OwnedMxcUri>,
|
|
||||||
blurhash: Option<String>,
|
|
||||||
all_joined_rooms: &[OwnedRoomId],
|
|
||||||
) {
|
|
||||||
let (current_avatar_url, current_blurhash, current_displayname) = join3(
|
|
||||||
services.users.avatar_url(user_id).ok(),
|
|
||||||
services.users.blurhash(user_id).ok(),
|
|
||||||
services.users.displayname(user_id).ok(),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
if current_avatar_url == avatar_url && current_blurhash == blurhash {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
services.users.set_avatar_url(user_id, avatar_url.clone());
|
|
||||||
services.users.set_blurhash(user_id, blurhash.clone());
|
|
||||||
|
|
||||||
// Send a new join membership event into all joined rooms
|
|
||||||
let avatar_url = &avatar_url;
|
|
||||||
let blurhash = &blurhash;
|
|
||||||
let displayname = ¤t_displayname;
|
|
||||||
let all_joined_rooms: Vec<_> = all_joined_rooms
|
|
||||||
.iter()
|
|
||||||
.try_stream()
|
|
||||||
.and_then(|room_id: &OwnedRoomId| async move {
|
|
||||||
let pdu = PduBuilder::state(user_id.to_string(), &RoomMemberEventContent {
|
|
||||||
avatar_url: avatar_url.clone(),
|
|
||||||
blurhash: blurhash.clone(),
|
|
||||||
membership: MembershipState::Join,
|
|
||||||
displayname: displayname.clone(),
|
|
||||||
join_authorized_via_users_server: None,
|
|
||||||
reason: None,
|
|
||||||
is_direct: None,
|
|
||||||
third_party_invite: None,
|
|
||||||
redact_events: None,
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok((pdu, room_id))
|
|
||||||
})
|
|
||||||
.ignore_err()
|
|
||||||
.collect()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
update_all_rooms(services, all_joined_rooms, user_id).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update_all_rooms(
|
|
||||||
services: &Services,
|
|
||||||
all_joined_rooms: Vec<(PduBuilder, &OwnedRoomId)>,
|
|
||||||
user_id: &UserId,
|
|
||||||
) {
|
|
||||||
for (pdu_builder, room_id) in all_joined_rooms {
|
|
||||||
let state_lock = services.rooms.state.mutex.lock(room_id).await;
|
|
||||||
if let Err(e) = services
|
|
||||||
.rooms
|
|
||||||
.timeline
|
|
||||||
.build_and_append_pdu(pdu_builder, user_id, Some(room_id), &state_lock)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
warn!(%user_id, %room_id, "Failed to update/send new profile join membership update in room: {e}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+36
-42
@@ -3,13 +3,13 @@ use conduwuit::{Err, Error, Result, err};
|
|||||||
use conduwuit_service::Services;
|
use conduwuit_service::Services;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
CanonicalJsonObject, CanonicalJsonValue,
|
CanonicalJsonObject, CanonicalJsonValue,
|
||||||
api::client::{
|
api::{
|
||||||
error::ErrorKind,
|
client::push::{
|
||||||
push::{
|
|
||||||
delete_pushrule, get_pushers, get_pushrule, get_pushrule_actions,
|
delete_pushrule, get_pushers, get_pushrule, get_pushrule_actions,
|
||||||
get_pushrule_enabled, get_pushrules_all, get_pushrules_global_scope, set_pusher,
|
get_pushrule_enabled, get_pushrules_all, get_pushrules_global_scope, set_pusher,
|
||||||
set_pushrule, set_pushrule_actions, set_pushrule_enabled,
|
set_pushrule, set_pushrule_actions, set_pushrule_enabled,
|
||||||
},
|
},
|
||||||
|
error::ErrorKind,
|
||||||
},
|
},
|
||||||
events::{
|
events::{
|
||||||
GlobalAccountDataEventType,
|
GlobalAccountDataEventType,
|
||||||
@@ -80,9 +80,7 @@ pub(crate) async fn get_pushrules_all_route(
|
|||||||
global_ruleset.update_with_server_default(Ruleset::server_default(sender_user));
|
global_ruleset.update_with_server_default(Ruleset::server_default(sender_user));
|
||||||
|
|
||||||
let ty = GlobalAccountDataEventType::PushRules;
|
let ty = GlobalAccountDataEventType::PushRules;
|
||||||
let event = PushRulesEvent {
|
let event = PushRulesEvent::new(PushRulesEventContent::new(global_ruleset.clone()));
|
||||||
content: PushRulesEventContent { global: global_ruleset.clone() },
|
|
||||||
};
|
|
||||||
|
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
@@ -91,7 +89,7 @@ pub(crate) async fn get_pushrules_all_route(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_pushrules_all::v3::Response { global: global_ruleset })
|
Ok(get_pushrules_all::v3::Response::new(global_ruleset))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/global/`
|
/// # `GET /_matrix/client/r0/pushrules/global/`
|
||||||
@@ -116,21 +114,20 @@ pub(crate) async fn get_pushrules_global_route(
|
|||||||
// user somehow has non-existent push rule event. recreate it and return server
|
// user somehow has non-existent push rule event. recreate it and return server
|
||||||
// default silently
|
// default silently
|
||||||
|
|
||||||
let ty = GlobalAccountDataEventType::PushRules;
|
let global_ruleset = Ruleset::server_default(sender_user);
|
||||||
let event = PushRulesEvent {
|
let event = PushRulesEvent::new(PushRulesEventContent::new(global_ruleset.clone()));
|
||||||
content: PushRulesEventContent {
|
|
||||||
global: Ruleset::server_default(sender_user),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(event)?)
|
.update(
|
||||||
|
None,
|
||||||
|
sender_user,
|
||||||
|
GlobalAccountDataEventType::PushRules.to_string().into(),
|
||||||
|
&serde_json::to_value(event)?,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(get_pushrules_global_scope::v3::Response {
|
return Ok(get_pushrules_global_scope::v3::Response::new(global_ruleset));
|
||||||
global: Ruleset::server_default(sender_user),
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let account_data_content =
|
let account_data_content =
|
||||||
@@ -173,16 +170,16 @@ pub(crate) async fn get_pushrules_global_route(
|
|||||||
None,
|
None,
|
||||||
sender_user,
|
sender_user,
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
GlobalAccountDataEventType::PushRules.to_string().into(),
|
||||||
&serde_json::to_value(PushRulesEvent {
|
&serde_json::to_value(PushRulesEvent::new(PushRulesEventContent::new(
|
||||||
content: PushRulesEventContent { global: global_ruleset.clone() },
|
global_ruleset.clone(),
|
||||||
})
|
)))
|
||||||
.expect("to json always works"),
|
.expect("to json always works"),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_pushrules_global_scope::v3::Response { global: global_ruleset })
|
Ok(get_pushrules_global_scope::v3::Response::new(global_ruleset))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
|
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
|
||||||
@@ -216,7 +213,7 @@ pub(crate) async fn get_pushrule_route(
|
|||||||
.map(Into::into);
|
.map(Into::into);
|
||||||
|
|
||||||
if let Some(rule) = rule {
|
if let Some(rule) = rule {
|
||||||
Ok(get_pushrule::v3::Response { rule })
|
Ok(get_pushrule::v3::Response::new(rule))
|
||||||
} else {
|
} else {
|
||||||
Err!(Request(NotFound("Push rule not found.")))
|
Err!(Request(NotFound("Push rule not found.")))
|
||||||
}
|
}
|
||||||
@@ -275,7 +272,7 @@ pub(crate) async fn set_pushrule_route(
|
|||||||
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?)
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(set_pushrule::v3::Response {})
|
Ok(set_pushrule::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/actions`
|
/// # `GET /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/actions`
|
||||||
@@ -309,7 +306,7 @@ pub(crate) async fn get_pushrule_actions_route(
|
|||||||
.map(|rule| rule.actions().to_owned())
|
.map(|rule| rule.actions().to_owned())
|
||||||
.ok_or_else(|| err!(Request(NotFound("Push rule not found."))))?;
|
.ok_or_else(|| err!(Request(NotFound("Push rule not found."))))?;
|
||||||
|
|
||||||
Ok(get_pushrule_actions::v3::Response { actions })
|
Ok(get_pushrule_actions::v3::Response::new(actions))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/actions`
|
/// # `PUT /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/actions`
|
||||||
@@ -342,7 +339,7 @@ pub(crate) async fn set_pushrule_actions_route(
|
|||||||
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?)
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(set_pushrule_actions::v3::Response {})
|
Ok(set_pushrule_actions::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/enabled`
|
/// # `GET /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/enabled`
|
||||||
@@ -360,7 +357,7 @@ pub(crate) async fn get_pushrule_enabled_route(
|
|||||||
|| body.rule_id.as_str() == PredefinedOverrideRuleId::ContainsDisplayName.as_str()
|
|| body.rule_id.as_str() == PredefinedOverrideRuleId::ContainsDisplayName.as_str()
|
||||||
|| body.rule_id.as_str() == PredefinedOverrideRuleId::RoomNotif.as_str()
|
|| body.rule_id.as_str() == PredefinedOverrideRuleId::RoomNotif.as_str()
|
||||||
{
|
{
|
||||||
return Ok(get_pushrule_enabled::v3::Response { enabled: false });
|
return Ok(get_pushrule_enabled::v3::Response::new(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
let event: PushRulesEvent = services
|
let event: PushRulesEvent = services
|
||||||
@@ -376,7 +373,7 @@ pub(crate) async fn get_pushrule_enabled_route(
|
|||||||
.map(ruma::push::AnyPushRuleRef::enabled)
|
.map(ruma::push::AnyPushRuleRef::enabled)
|
||||||
.ok_or_else(|| err!(Request(NotFound("Push rule not found."))))?;
|
.ok_or_else(|| err!(Request(NotFound("Push rule not found."))))?;
|
||||||
|
|
||||||
Ok(get_pushrule_enabled::v3::Response { enabled })
|
Ok(get_pushrule_enabled::v3::Response::new(enabled))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/enabled`
|
/// # `PUT /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/enabled`
|
||||||
@@ -409,7 +406,7 @@ pub(crate) async fn set_pushrule_enabled_route(
|
|||||||
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?)
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(set_pushrule_enabled::v3::Response {})
|
Ok(set_pushrule_enabled::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/pushrules/global/{kind}/{ruleId}`
|
/// # `DELETE /_matrix/client/r0/pushrules/global/{kind}/{ruleId}`
|
||||||
@@ -451,7 +448,7 @@ pub(crate) async fn delete_pushrule_route(
|
|||||||
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?)
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(delete_pushrule::v3::Response {})
|
Ok(delete_pushrule::v3::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushers`
|
/// # `GET /_matrix/client/r0/pushers`
|
||||||
@@ -463,9 +460,7 @@ pub(crate) async fn get_pushers_route(
|
|||||||
) -> Result<get_pushers::v3::Response> {
|
) -> Result<get_pushers::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
|
|
||||||
Ok(get_pushers::v3::Response {
|
Ok(get_pushers::v3::Response::new(services.pusher.get_pushers(sender_user).await))
|
||||||
pushers: services.pusher.get_pushers(sender_user).await,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/pushers/set`
|
/// # `POST /_matrix/client/r0/pushers/set`
|
||||||
@@ -493,19 +488,18 @@ pub async fn recreate_push_rules_and_return(
|
|||||||
services: &Services,
|
services: &Services,
|
||||||
sender_user: &ruma::UserId,
|
sender_user: &ruma::UserId,
|
||||||
) -> Result<get_pushrules_all::v3::Response> {
|
) -> Result<get_pushrules_all::v3::Response> {
|
||||||
let ty = GlobalAccountDataEventType::PushRules;
|
let global_ruleset = Ruleset::server_default(sender_user);
|
||||||
let event = PushRulesEvent {
|
let event = PushRulesEvent::new(PushRulesEventContent::new(global_ruleset.clone()));
|
||||||
content: PushRulesEventContent {
|
|
||||||
global: Ruleset::server_default(sender_user),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(event)?)
|
.update(
|
||||||
|
None,
|
||||||
|
sender_user,
|
||||||
|
GlobalAccountDataEventType::PushRules.to_string().into(),
|
||||||
|
&serde_json::to_value(event)?,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_pushrules_all::v3::Response {
|
Ok(get_pushrules_all::v3::Response::new(global_ruleset))
|
||||||
global: Ruleset::server_default(sender_user),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
Loaded 100 of 317 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user