mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-12-04 06:11:47 +00:00
Compare commits
64
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0514491189 | ||
|
|
a30c355c03 | ||
|
|
1cc9dbf2a4 | ||
|
|
2cf28baf03 | ||
|
|
f3fb218652 | ||
|
|
0924b7d27e | ||
|
|
8575f191a0 | ||
|
|
fe7cfd96e7 | ||
|
|
8b0e86a05d | ||
|
|
8b8fef998c | ||
|
|
decd6083a0 | ||
|
|
06184d8c9f | ||
|
|
7c20e22b75 | ||
|
|
3f862b58cb | ||
|
|
046a6356f3 | ||
|
|
3af0240ff5 | ||
|
|
5dcfff51cf | ||
|
|
b9989f1713 | ||
|
|
1d3e3e7e62 | ||
|
|
0adf3aa956 | ||
|
|
7b1aabda9f | ||
|
|
e31c5997b7 | ||
|
|
7ca0d137c4 | ||
|
|
0344bf71d8 | ||
|
|
a07d3e24ea | ||
|
|
1bc7950748 | ||
|
|
0fd43ff6fa | ||
|
|
796136f1a6 | ||
|
|
447608985b | ||
|
|
5f4cd47d88 | ||
|
|
a7244bdb68 | ||
|
|
91f2900463 | ||
|
|
e44ae3bac9 | ||
|
|
b692f9e6e7 | ||
|
|
695333fe5b | ||
|
|
bc7a6c148f | ||
|
|
bd3944573b | ||
|
|
21ac3c5a86 | ||
|
|
3976849b97 | ||
|
|
a1e3619291 | ||
|
|
a92fc78a90 | ||
|
|
fc429ea564 | ||
|
|
69c931e18a | ||
|
|
284e0ce1e5 | ||
|
|
a13779a051 | ||
|
|
7163714697 | ||
|
|
3998a14c32 | ||
|
|
c79f2a3057 | ||
|
|
17837c51a0 | ||
|
|
99a7be0222 | ||
|
|
41ed2eb167 | ||
|
|
2b08460b16 | ||
|
|
4cf8f6e05b | ||
|
|
ae37acb228 | ||
|
|
10c3045f5f | ||
|
|
8242718571 | ||
|
|
03db067aab | ||
|
|
b28ddde1eb | ||
|
|
0134f69bf9 | ||
|
|
15878371bf | ||
|
|
980bd475b6 | ||
|
|
19204b097d | ||
|
|
567d809efe | ||
|
|
8171e3d614 |
No files matched your search
@@ -71,7 +71,7 @@ runs:
|
|||||||
|
|
||||||
- name: Install timelord-cli and git-warp-time
|
- name: Install timelord-cli and git-warp-time
|
||||||
if: steps.check-binaries.outputs.need-install == 'true'
|
if: steps.check-binaries.outputs.need-install == 'true'
|
||||||
uses: https://github.com/taiki-e/install-action@a2352fc6ce487f030a3aa709482d57823eadfb37 # v2
|
uses: https://github.com/taiki-e/install-action@787505cde8a44ea468a00478fe52baf23b15bccd # v2
|
||||||
with:
|
with:
|
||||||
tool: git-warp-time,timelord-cli@3.0.1
|
tool: git-warp-time,timelord-cli@3.0.1
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ jobs:
|
|||||||
if (file.startsWith('pkg/') || file.startsWith('nix/') || file === 'flake.nix' || file === 'flake.lock' || file.startsWith('docker/')) {
|
if (file.startsWith('pkg/') || file.startsWith('nix/') || file === 'flake.nix' || file === 'flake.lock' || file.startsWith('docker/')) {
|
||||||
labelsToAdd.add('Meta/Packaging');
|
labelsToAdd.add('Meta/Packaging');
|
||||||
}
|
}
|
||||||
|
if (file === 'Cargo.lock') {
|
||||||
|
labelsToAdd.add('Dependencies');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (labelsToAdd.size > 0) {
|
if (labelsToAdd.size > 0) {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ jobs:
|
|||||||
if [[ ${{ forge.ref_name }} =~ ^v+[0-9]\.+[0-9]\.+[0-9]$ ]]; then
|
if [[ ${{ forge.ref_name }} =~ ^v+[0-9]\.+[0-9]\.+[0-9]$ ]]; then
|
||||||
# Use the "stable" component for tagged semver releases
|
# Use the "stable" component for tagged semver releases
|
||||||
COMPONENT="stable"
|
COMPONENT="stable"
|
||||||
elif [[ ${{ forge.ref }} =~ ^refs/tags/^v+[0-9]\.+[0-9]\.+[0-9] ]]; then
|
elif [[ ${{ forge.ref_name }} =~ ^v+[0-9]\.+[0-9]\.+[0-9] ]]; then
|
||||||
# Use the "unstable" component for tagged semver pre-releases
|
# Use the "unstable" component for tagged semver pre-releases
|
||||||
COMPONENT="unstable"
|
COMPONENT="unstable"
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ jobs:
|
|||||||
RELEASE_SUFFIX=""
|
RELEASE_SUFFIX=""
|
||||||
TAG_NAME="${{ github.ref_name }}"
|
TAG_NAME="${{ github.ref_name }}"
|
||||||
# Extract version from tag (remove v prefix if present)
|
# Extract version from tag (remove v prefix if present)
|
||||||
TAG_VERSION=$(echo "$TAG_NAME" | sed 's/^v//')
|
TAG_VERSION=$(echo "$TAG_NAME" | sed 's/^v//' | tr '-' '~')
|
||||||
|
|
||||||
# Create spec file with tag version
|
# Create spec file with tag version
|
||||||
sed -e "s/^Version:.*$/Version: $TAG_VERSION/" \
|
sed -e "s/^Version:.*$/Version: $TAG_VERSION/" \
|
||||||
@@ -270,9 +270,13 @@ jobs:
|
|||||||
|
|
||||||
# Determine the group based on ref type and branch
|
# Determine the group based on ref type and branch
|
||||||
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
|
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
|
||||||
GROUP="stable"
|
|
||||||
# For tags, extract the tag name for version info
|
# For tags, extract the tag name for version info
|
||||||
TAG_NAME="${{ github.ref_name }}"
|
TAG_NAME="${{ github.ref_name }}"
|
||||||
|
if [[ "$TAG_NAME" == *"-"* ]]; then
|
||||||
|
GROUP="unstable"
|
||||||
|
else
|
||||||
|
GROUP="stable"
|
||||||
|
fi
|
||||||
elif [ "${{ github.ref_name }}" = "main" ]; then
|
elif [ "${{ github.ref_name }}" = "main" ]; then
|
||||||
GROUP="dev"
|
GROUP="dev"
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
if: steps.runner-env.outputs.node_major == '' || steps.runner-env.outputs.node_major < '20'
|
if: steps.runner-env.outputs.node_major == '' || steps.runner-env.outputs.node_major < '20'
|
||||||
uses: https://github.com/actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
|
uses: https://github.com/actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
|
||||||
with:
|
with:
|
||||||
node-version: 22
|
node-version: 22
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: 📦 Setup Node.js
|
- name: 📦 Setup Node.js
|
||||||
uses: https://github.com/actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
|
uses: https://github.com/actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
|
||||||
with:
|
with:
|
||||||
node-version: "22"
|
node-version: "22"
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ on:
|
|||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
pull-requests: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
fast-checks:
|
fast-checks:
|
||||||
@@ -40,10 +41,32 @@ jobs:
|
|||||||
cargo +nightly fmt --all -- --check && \
|
cargo +nightly fmt --all -- --check && \
|
||||||
echo "✅ Formatting check passed" || \
|
echo "✅ Formatting check passed" || \
|
||||||
exit 1
|
exit 1
|
||||||
|
check-changes:
|
||||||
|
name: Check changed files
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
rust: ${{ steps.filter.outputs.rust }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Check for file changes
|
||||||
|
uses: https://github.com/dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4
|
||||||
|
id: filter
|
||||||
|
with:
|
||||||
|
filters: |
|
||||||
|
rust:
|
||||||
|
- '**/*.rs'
|
||||||
|
- '**/Cargo.toml'
|
||||||
|
- '**/Cargo.lock'
|
||||||
|
|
||||||
clippy-and-tests:
|
clippy-and-tests:
|
||||||
name: Clippy and Cargo Tests
|
name: Clippy and Cargo Tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
needs: check-changes
|
||||||
|
if: needs.check-changes.outputs.rust == 'true'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
|
|||||||
@@ -199,6 +199,28 @@ jobs:
|
|||||||
registry_user: ${{ vars.BUILTIN_REGISTRY_USER || github.actor }}
|
registry_user: ${{ vars.BUILTIN_REGISTRY_USER || github.actor }}
|
||||||
registry_password: ${{ secrets.BUILTIN_REGISTRY_PASSWORD || secrets.GITHUB_TOKEN }}
|
registry_password: ${{ secrets.BUILTIN_REGISTRY_PASSWORD || secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
release-binaries:
|
||||||
|
name: "Release Binaries"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- build-release
|
||||||
|
- build-maxperf
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
steps:
|
||||||
|
- name: Download binary artifacts
|
||||||
|
uses: forgejo/download-artifact@v4
|
||||||
|
with:
|
||||||
|
pattern: conduwuit*
|
||||||
|
path: binaries
|
||||||
|
merge-multiple: true
|
||||||
|
- name: Create Release and Upload
|
||||||
|
uses: https://github.com/softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
draft: true
|
||||||
|
files: binaries/*
|
||||||
|
|
||||||
mirror_images:
|
mirror_images:
|
||||||
name: "Mirror Images"
|
name: "Mirror Images"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ jobs:
|
|||||||
name: Renovate
|
name: Renovate
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: ghcr.io/renovatebot/renovate:43.111.0@sha256:da5fcac20c48d9792aac9c61fd234531bfa8df61263a39387cd8920263ca4768
|
image: ghcr.io/renovatebot/renovate:43.140.0@sha256:61303c28b10a491c559529fb6f41745850e4755a43a54c04c3ae6848d6eaf5cc
|
||||||
options: --tmpfs /tmp:exec
|
options: --tmpfs /tmp:exec
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
@@ -90,12 +90,12 @@ jobs:
|
|||||||
RENOVATE_PLATFORM: forgejo
|
RENOVATE_PLATFORM: forgejo
|
||||||
RENOVATE_ENDPOINT: ${{ github.server_url }}
|
RENOVATE_ENDPOINT: ${{ github.server_url }}
|
||||||
RENOVATE_AUTODISCOVER: 'false'
|
RENOVATE_AUTODISCOVER: 'false'
|
||||||
RENOVATE_REPOSITORIES: '["${{ github.repository }}"]'
|
RENOVATE_REPOSITORIES: '["${{ github.repository }}", "continuwuation/resolvematrix"]'
|
||||||
|
|
||||||
RENOVATE_GIT_TIMEOUT: 60000
|
RENOVATE_GIT_TIMEOUT: 60000
|
||||||
|
|
||||||
RENOVATE_REQUIRE_CONFIG: 'required'
|
RENOVATE_REQUIRE_CONFIG: 'required'
|
||||||
RENOVATE_ONBOARDING: 'false'
|
# RENOVATE_ONBOARDING: 'false'
|
||||||
RENOVATE_INHERIT_CONFIG: 'true'
|
RENOVATE_INHERIT_CONFIG: 'true'
|
||||||
|
|
||||||
RENOVATE_GITHUB_TOKEN_WARN: 'false'
|
RENOVATE_GITHUB_TOKEN_WARN: 'false'
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ repos:
|
|||||||
- id: check-added-large-files
|
- id: check-added-large-files
|
||||||
|
|
||||||
- repo: https://github.com/crate-ci/typos
|
- repo: https://github.com/crate-ci/typos
|
||||||
rev: v1.45.1
|
rev: v1.45.2
|
||||||
hooks:
|
hooks:
|
||||||
- id: typos
|
- id: typos
|
||||||
- id: typos
|
- id: typos
|
||||||
|
|||||||
@@ -1,3 +1,31 @@
|
|||||||
|
# Continuwuity 0.5.9 (2026-05-07)
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
- Fixed a bug that caused the server to drop events during processing if several events for the same room were sent in a
|
||||||
|
singular transaction. Contributed by @nex. (#1711)
|
||||||
|
- Fixed a bug that caused the server to panic while handling transactions with malformed events, resulting in a
|
||||||
|
deadlock that prevented the remote server from federating with us until the server was restarted. Contributed by @nex.
|
||||||
|
- Fixed a bug that resulted in the `m.federate` field of `m.room.create` being ignored in v12 rooms, allowing remote
|
||||||
|
servers to participate in local-only rooms. Contributed by @nex, reported by [@mat:emzee.ee](matrix:u/mat:emzee.ee?action=chat).
|
||||||
|
|
||||||
|
# Continuwuity 0.5.8 (2026-04-24)
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- LDAP can now optionally be connected to using StartTLS, and you may unsafely skip verification. Contributed by @getz (#1389)
|
||||||
|
- Users will now be prevented from removing their email if the server is configured to require an email when registering an account.
|
||||||
|
|
||||||
|
## Bugfixes
|
||||||
|
|
||||||
|
- Fixed a situation where multiple email addresses could be associated with one user when that user changes their email address.
|
||||||
|
|
||||||
|
## Improved Documentation
|
||||||
|
|
||||||
|
- Updated config docs to state we support room version 12, and set it as default. Contributed by @ezera. (#1622)
|
||||||
|
- Improve instructions for generic deployments, removing unnecessary parts and documenting the new initial registration token flow. Contributed by @stratself (#1677)
|
||||||
|
|
||||||
|
|
||||||
# Continuwuity v0.5.7 (2026-04-17)
|
# Continuwuity v0.5.7 (2026-04-17)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|||||||
Generated
+465
-339
File diff suppressed because it is too large.
Load diff
+41
-42
@@ -12,7 +12,7 @@ license = "Apache-2.0"
|
|||||||
# See also `rust-toolchain.toml`
|
# See also `rust-toolchain.toml`
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://forgejo.ellis.link/continuwuation/continuwuity"
|
repository = "https://forgejo.ellis.link/continuwuation/continuwuity"
|
||||||
version = "0.5.7"
|
version = "0.5.9"
|
||||||
|
|
||||||
[workspace.metadata.crane]
|
[workspace.metadata.crane]
|
||||||
name = "conduwuit"
|
name = "conduwuit"
|
||||||
@@ -36,7 +36,7 @@ version = "0.3"
|
|||||||
features = ["ffi", "std", "union"]
|
features = ["ffi", "std", "union"]
|
||||||
|
|
||||||
[workspace.dependencies.const-str]
|
[workspace.dependencies.const-str]
|
||||||
version = "0.7.0"
|
version = "1.1.0"
|
||||||
|
|
||||||
[workspace.dependencies.ctor]
|
[workspace.dependencies.ctor]
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
@@ -47,7 +47,7 @@ default-features = false
|
|||||||
features = ["features"]
|
features = ["features"]
|
||||||
|
|
||||||
[workspace.dependencies.toml]
|
[workspace.dependencies.toml]
|
||||||
version = "1.0.0"
|
version = "1.1.2"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["parse", "serde"]
|
features = ["parse", "serde"]
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ default-features = false
|
|||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
|
|
||||||
[workspace.dependencies.rand]
|
[workspace.dependencies.rand]
|
||||||
version = "0.10.1"
|
version = "0.10.0"
|
||||||
|
|
||||||
# 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]
|
||||||
@@ -102,15 +102,18 @@ default-features = false
|
|||||||
features = ["typed-header", "tracing", "cookie"]
|
features = ["typed-header", "tracing", "cookie"]
|
||||||
|
|
||||||
[workspace.dependencies.axum-server]
|
[workspace.dependencies.axum-server]
|
||||||
version = "0.7.2"
|
version = "0.8.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
# to listen on both HTTP and HTTPS if listening on TLS dierctly from conduwuit for complement or sytest
|
# to listen on both HTTP and HTTPS if listening on TLS dierctly from conduwuit for complement or sytest
|
||||||
[workspace.dependencies.axum-server-dual-protocol]
|
[workspace.dependencies.axum-server-dual-protocol]
|
||||||
version = "0.7"
|
# version = "0.7"
|
||||||
|
git = "https://github.com/vinchona/axum-server-dual-protocol.git"
|
||||||
|
rev = "ca6db055254255b74238673ce4135698e347d71c" # feat!: bump axum_server to 0.8.0
|
||||||
|
default-features = false
|
||||||
|
|
||||||
[workspace.dependencies.axum-client-ip]
|
[workspace.dependencies.axum-client-ip]
|
||||||
version = "0.7"
|
version = "1.3"
|
||||||
|
|
||||||
[workspace.dependencies.tower]
|
[workspace.dependencies.tower]
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
@@ -134,13 +137,12 @@ features = [
|
|||||||
[workspace.dependencies.rustls]
|
[workspace.dependencies.rustls]
|
||||||
version = "0.23.25"
|
version = "0.23.25"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["aws_lc_rs"]
|
|
||||||
|
|
||||||
[workspace.dependencies.reqwest]
|
[workspace.dependencies.reqwest]
|
||||||
version = "0.12.15"
|
version = "0.13.2"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = [
|
features = [
|
||||||
"rustls-tls-native-roots",
|
"rustls-no-provider",
|
||||||
"socks",
|
"socks",
|
||||||
"hickory-dns",
|
"hickory-dns",
|
||||||
"http2",
|
"http2",
|
||||||
@@ -159,7 +161,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.23"
|
version = "0.0.24"
|
||||||
|
|
||||||
# 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]
|
||||||
@@ -251,7 +253,7 @@ features = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[workspace.dependencies.tokio-metrics]
|
[workspace.dependencies.tokio-metrics]
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
|
|
||||||
[workspace.dependencies.libloading]
|
[workspace.dependencies.libloading]
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
@@ -340,49 +342,51 @@ 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]
|
||||||
# version = "0.14.1"
|
git = "https://forgejo.ellis.link/continuwuation/ruwuma"
|
||||||
git = "https://github.com/ruma/ruma.git"
|
#branch = "conduwuit-changes"
|
||||||
rev = "985dec87f235f169b3adddf3a7d37f590403e6e9"
|
rev = "d00b51a8669b21689c4eb47fb81f3a8b27c3e371"
|
||||||
features = [
|
features = [
|
||||||
|
"compat",
|
||||||
|
"rand",
|
||||||
"appservice-api-c",
|
"appservice-api-c",
|
||||||
"client-api",
|
"client-api",
|
||||||
"federation-api",
|
"federation-api",
|
||||||
"push-gateway-api-c",
|
|
||||||
"state-res",
|
|
||||||
"rand",
|
|
||||||
"markdown",
|
"markdown",
|
||||||
|
"push-gateway-api-c",
|
||||||
|
"unstable-exhaustive-types",
|
||||||
"ring-compat",
|
"ring-compat",
|
||||||
"compat-upload-signatures",
|
"compat-upload-signatures",
|
||||||
"compat-optional-txn-pdus",
|
"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-msc3381",
|
"unstable-msc3266",
|
||||||
"unstable-msc3489",
|
"unstable-msc3381", # polls
|
||||||
"unstable-msc3930",
|
"unstable-msc3489", # beacon / live location
|
||||||
|
"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-msc4195",
|
"unstable-msc4203", # sending to-device events to appservices
|
||||||
"unstable-msc4203",
|
"unstable-msc4210", # remove legacy mentions
|
||||||
"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",
|
||||||
|
"unstable-msc4439", # pgp_key in .well_known/matrix/support
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.dependencies.rust-rocksdb]
|
[workspace.dependencies.rust-rocksdb]
|
||||||
@@ -427,14 +431,13 @@ features = ["http", "grpc-tonic", "trace", "logs", "metrics"]
|
|||||||
|
|
||||||
# optional sentry metrics for crash/panic reporting
|
# optional sentry metrics for crash/panic reporting
|
||||||
[workspace.dependencies.sentry]
|
[workspace.dependencies.sentry]
|
||||||
version = "0.46.0"
|
version = "0.47.0"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = [
|
features = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"contexts",
|
"contexts",
|
||||||
"debug-images",
|
"debug-images",
|
||||||
"panic",
|
"panic",
|
||||||
"rustls",
|
|
||||||
"tower",
|
"tower",
|
||||||
"tower-http",
|
"tower-http",
|
||||||
"tracing",
|
"tracing",
|
||||||
@@ -443,9 +446,9 @@ features = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[workspace.dependencies.sentry-tracing]
|
[workspace.dependencies.sentry-tracing]
|
||||||
version = "0.46.0"
|
version = "0.47.0"
|
||||||
[workspace.dependencies.sentry-tower]
|
[workspace.dependencies.sentry-tower]
|
||||||
version = "0.46.0"
|
version = "0.47.0"
|
||||||
|
|
||||||
# jemalloc usage
|
# jemalloc usage
|
||||||
[workspace.dependencies.tikv-jemalloc-sys]
|
[workspace.dependencies.tikv-jemalloc-sys]
|
||||||
@@ -558,7 +561,7 @@ version = "0.15.0"
|
|||||||
[workspace.dependencies.lettre]
|
[workspace.dependencies.lettre]
|
||||||
version = "0.11.19"
|
version = "0.11.19"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["smtp-transport", "pool", "hostname", "builder", "rustls", "rustls-native-certs", "tokio1", "ring", "tokio1-rustls", "tracing", "serde"]
|
features = ["smtp-transport", "pool", "hostname", "builder", "rustls", "rustls-native-certs", "tokio1", "rustls-no-provider", "tokio1-rustls", "tracing", "serde"]
|
||||||
|
|
||||||
[workspace.dependencies.governor]
|
[workspace.dependencies.governor]
|
||||||
version = "0.10.4"
|
version = "0.10.4"
|
||||||
@@ -655,10 +658,6 @@ 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
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
Switched from Continuwuity's fork of Ruma back to upstream Ruma, unblocking exciting new features such as OAuth login. Contributed by @ginger.
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Updated config docs to state we support room version 12, and set it as default. Contributed by @ezera.
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Explain accessing Continuwuity's server console when deployed via Docker.
|
||||||
@@ -573,6 +573,18 @@
|
|||||||
#
|
#
|
||||||
#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.
|
||||||
@@ -1954,6 +1966,14 @@
|
|||||||
#
|
#
|
||||||
#uri = ""
|
#uri = ""
|
||||||
|
|
||||||
|
# StartTLS for LDAP connections.
|
||||||
|
#
|
||||||
|
#use_starttls = false
|
||||||
|
|
||||||
|
# Skip TLS certificate verification, possibly dangerous.
|
||||||
|
#
|
||||||
|
#disable_tls_verification = false
|
||||||
|
|
||||||
# Root of the searches.
|
# Root of the searches.
|
||||||
#
|
#
|
||||||
# example: "ou=users,dc=example,dc=org"
|
# example: "ou=users,dc=example,dc=org"
|
||||||
@@ -2092,6 +2112,9 @@
|
|||||||
# Whether to require that users provide an email address when they
|
# Whether to require that users provide an email address when they
|
||||||
# register.
|
# register.
|
||||||
#
|
#
|
||||||
|
# If either this option or `require_email_for_token_registration` are set,
|
||||||
|
# users will not be allowed to remove their email address.
|
||||||
|
#
|
||||||
#require_email_for_registration = false
|
#require_email_for_registration = false
|
||||||
|
|
||||||
# Whether to require that users who register with a registration token
|
# Whether to require that users who register with a registration token
|
||||||
|
|||||||
+3
-1
@@ -17,12 +17,14 @@ ARG LLVM_VERSION=21
|
|||||||
# Line one: compiler tools
|
# Line one: compiler tools
|
||||||
# Line two: curl, for downloading binaries and wget because llvm.sh is broken with curl
|
# 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
|
||||||
|
# golang, cmake: For aws-lc-rs bindgen
|
||||||
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 \
|
||||||
wget curl git software-properties-common \
|
wget curl git software-properties-common \
|
||||||
file
|
file
|
||||||
|
# golang cmake
|
||||||
|
|
||||||
# LLVM packages
|
# LLVM packages
|
||||||
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||||
@@ -162,7 +164,7 @@ ENV CONDUWUIT_VERSION_EXTRA=$CONDUWUIT_VERSION_EXTRA
|
|||||||
ENV CONTINUWUITY_VERSION_EXTRA=$CONTINUWUITY_VERSION_EXTRA
|
ENV CONTINUWUITY_VERSION_EXTRA=$CONTINUWUITY_VERSION_EXTRA
|
||||||
|
|
||||||
ARG RUST_PROFILE=release
|
ARG RUST_PROFILE=release
|
||||||
ARG CARGO_FEATURES="default,http3"
|
ARG CARGO_FEATURES="default"
|
||||||
|
|
||||||
# Build the binary
|
# Build the binary
|
||||||
RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
||||||
|
|||||||
@@ -50,8 +50,6 @@ services:
|
|||||||
# CONTINUWUITY_WELL_KNOWN__SERVER: matrix.example.com:443
|
# CONTINUWUITY_WELL_KNOWN__SERVER: matrix.example.com:443
|
||||||
```
|
```
|
||||||
|
|
||||||
## Reverse proxying well-known files to Continuwuity
|
|
||||||
|
|
||||||
After doing the steps above, Continuwuity will serve these 3 JSON files:
|
After doing the steps above, Continuwuity will serve these 3 JSON files:
|
||||||
|
|
||||||
- `/.well-known/matrix/client`: for Client-Server discovery
|
- `/.well-known/matrix/client`: for Client-Server discovery
|
||||||
@@ -60,9 +58,11 @@ After doing the steps above, Continuwuity will serve these 3 JSON files:
|
|||||||
|
|
||||||
To enable full discovery, you will need to reverse proxy these paths from the base domain back to Continuwuity.
|
To enable full discovery, you will need to reverse proxy these paths from the base domain back to Continuwuity.
|
||||||
|
|
||||||
|
## Reverse proxying well-known files to Continuwuity
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
||||||
<summary>For Caddy</summary>
|
<summary>For **Caddy**</summary>
|
||||||
|
|
||||||
```
|
```
|
||||||
matrix.example.com:443 {
|
matrix.example.com:443 {
|
||||||
@@ -78,7 +78,7 @@ example.com:443 {
|
|||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
||||||
<summary>For Traefik (via Docker labels)</summary>
|
<summary>For **Traefik** (via Docker labels)</summary>
|
||||||
|
|
||||||
```
|
```
|
||||||
services:
|
services:
|
||||||
@@ -93,7 +93,10 @@ services:
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
Restart Continuwuity and your reverse proxy. Once that's done, visit these routes and check that the responses match the examples below:
|
|
||||||
|
For **Docker** users, consult the compose files in the [Appendix section](#docker-compose-examples).
|
||||||
|
|
||||||
|
After applying these changes, restart Continuwuity and your reverse proxy.Visit these routes and check that the responses match the examples below:
|
||||||
|
|
||||||
<details open>
|
<details open>
|
||||||
|
|
||||||
@@ -253,3 +256,45 @@ See the following Matrix Specs for full details on client/server resolution mech
|
|||||||
- [Server-to-Server resolution](https://spec.matrix.org/v1.17/server-server-api/#resolving-server-names) (see this for more information on SRV records)
|
- [Server-to-Server resolution](https://spec.matrix.org/v1.17/server-server-api/#resolving-server-names) (see this for more information on SRV records)
|
||||||
- [Client-to-Server resolution](https://spec.matrix.org/v1.17/client-server-api/#server-discovery)
|
- [Client-to-Server resolution](https://spec.matrix.org/v1.17/client-server-api/#server-discovery)
|
||||||
- [MSC1929: Homeserver Admin Contact and Support page](https://github.com/matrix-org/matrix-spec-proposals/pull/1929)
|
- [MSC1929: Homeserver Admin Contact and Support page](https://github.com/matrix-org/matrix-spec-proposals/pull/1929)
|
||||||
|
|
||||||
|
## Appendix
|
||||||
|
|
||||||
|
### Docker Compose examples
|
||||||
|
|
||||||
|
The following Compose files are taken from [Docker instructions](../deploying/docker.mdx) and reconfigured to support split-domain delegation. Note the updated `CONTINUWUITY_WELL_KNOWN` variable and relevant changes in reverse proxy rules.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Caddy (using Caddyfile) - delegated.docker-compose.with-caddy.yml ([view raw](/advanced/delegated.docker-compose.with-caddy.yml))</summary>
|
||||||
|
|
||||||
|
```yaml file="../public/advanced/delegated.docker-compose.with-caddy.yml"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Caddy (using labels) - delegated.docker-compose.with-caddy-labels.yml ([view raw](/advanced/delegated.docker-compose.with-caddy-labels.yml))</summary>
|
||||||
|
|
||||||
|
```yaml file="../public/advanced/delegated.docker-compose.with-caddy-labels.yml"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Traefik (for existing setup) - delegated.docker-compose.for-traefik.yml ([view raw](/advanced/delegated.docker-compose.for-traefik.yml))</summary>
|
||||||
|
|
||||||
|
```yaml file="../public/advanced/delegated.docker-compose.for-traefik.yml"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Traefik included - delegated.docker-compose.with-traefik.yml ([view raw](/advanced/delegated.docker-compose.with-traefik.yml))</summary>
|
||||||
|
|
||||||
|
```yaml file="../public/advanced/delegated.docker-compose.with-traefik.yml"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
+36
-8
@@ -91,7 +91,7 @@ You will need to allow ports `7881/tcp` and `50100:50200/udp` through your firew
|
|||||||
|
|
||||||
To tell clients where to find LiveKit, you need to add the address of your `lk-jwt-service` to the `[global.matrix_rtc]` config section using the `foci` option.
|
To tell clients where to find LiveKit, you need to add the address of your `lk-jwt-service` to the `[global.matrix_rtc]` config section using the `foci` option.
|
||||||
|
|
||||||
The variable should be a list of servers serving as MatrixRTC endpoints. Clients discover these via the `/_matrix/client/v1/rtc/transports` endpoint (MSC4143).
|
The variable should be a list of servers serving as MatrixRTC endpoints. Replace the URL with the address you are deploying your instance of lk-jwt-service to:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[global.matrix_rtc]
|
[global.matrix_rtc]
|
||||||
@@ -100,7 +100,10 @@ foci = [
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
Remember to replace the URL with the address you are deploying your instance of lk-jwt-service to.
|
This will expose LiveKit information on the following endpoints for clients to discover:
|
||||||
|
|
||||||
|
- `/_matrix/client/unstable/org.matrix.msc4143/rtc/transports` (MSC4143 unstable, behind auth)
|
||||||
|
- `/.well-known/matrix/client` (fallback, not behind auth. Only enabled if `[global.well_known].client` is set)
|
||||||
|
|
||||||
### 4. Configure your Reverse Proxy
|
### 4. Configure your Reverse Proxy
|
||||||
|
|
||||||
@@ -114,6 +117,7 @@ All paths should be forwarded to LiveKit by default, with the exception of the f
|
|||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Example caddy config</summary>
|
<summary>Example caddy config</summary>
|
||||||
|
|
||||||
```
|
```
|
||||||
livekit.example.com {
|
livekit.example.com {
|
||||||
|
|
||||||
@@ -127,10 +131,12 @@ All paths should be forwarded to LiveKit by default, with the exception of the f
|
|||||||
reverse_proxy 127.0.0.1:7880
|
reverse_proxy 127.0.0.1:7880
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Example nginx config</summary>
|
<summary>Example nginx config</summary>
|
||||||
|
|
||||||
```
|
```
|
||||||
server {
|
server {
|
||||||
server_name livekit.example.com;
|
server_name livekit.example.com;
|
||||||
@@ -167,16 +173,19 @@ All paths should be forwarded to LiveKit by default, with the exception of the f
|
|||||||
'' close;
|
'' close;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Example traefik router</summary>
|
<summary>Example traefik router</summary>
|
||||||
|
|
||||||
```
|
```
|
||||||
# on LiveKit itself
|
# on LiveKit itself
|
||||||
traefik.http.routers.livekit.rule=Host(`livekit.example.com`)
|
traefik.http.routers.livekit.rule=Host(`livekit.example.com`)
|
||||||
# on the JWT service
|
# on the JWT service
|
||||||
traefik.http.routers.livekit-jwt.rule=Host(`livekit.example.com`) && (PathPrefix(`/sfu/get`) || PathPrefix(`/healthz`) || PathPrefix(`/get_token`))
|
traefik.http.routers.livekit-jwt.rule=Host(`livekit.example.com`) && (PathPrefix(`/sfu/get`) || PathPrefix(`/healthz`) || PathPrefix(`/get_token`))
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|
||||||
@@ -210,7 +219,7 @@ ports:
|
|||||||
### if you're using `network_mode: host`, you can skip this part
|
### if you're using `network_mode: host`, you can skip this part
|
||||||
```
|
```
|
||||||
|
|
||||||
Recreate the LiveKit container (with `docker-compose up -d livekit`) to apply these changes. Remember to allow the new `3478/udp` and `50100:50200/udp` ports through your firewall.
|
Recreate the LiveKit container (with `docker-compose up -d livekit`) to apply these changes. Remember to allow the new `3478/udp` and `50300:50400/udp` ports through your firewall.
|
||||||
|
|
||||||
### Integration with an external TURN server
|
### Integration with an external TURN server
|
||||||
|
|
||||||
@@ -257,11 +266,25 @@ To test that LiveKit is successfully integrated with Continuwuity, you will need
|
|||||||
|
|
||||||
First, you will need an access token for your current login session. These can be found in your client's settings or obtained via [this website](https://timedout.uk/mxtoken.html).
|
First, you will need an access token for your current login session. These can be found in your client's settings or obtained via [this website](https://timedout.uk/mxtoken.html).
|
||||||
|
|
||||||
Then, using that token, request another OpenID token for use with the lk-jwt-service:
|
Then, using that token, fetch the discovery endpoints for MatrixRTC services
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
~$ curl -X POST -H "Authorization: Bearer <session-access-token>" \
|
curl -X POST -H "Authorization: Bearer <session-access-token>" \
|
||||||
|
https://matrix.example.com/_matrix/client/unstable/org.matrix.msc4143/rtc/transports
|
||||||
|
```
|
||||||
|
|
||||||
|
In the output, you should see the LiveKit URL matching the one [configured above](#3-telling-clients-where-to-find-livekit).
|
||||||
|
|
||||||
|
With the same token, request another OpenID token for use with the lk-jwt-service:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST -H "Authorization: Bearer <session-access-token>" \
|
||||||
https://matrix.example.com/_matrix/client/v3/user/@user:example.com/openid/request_token
|
https://matrix.example.com/_matrix/client/v3/user/@user:example.com/openid/request_token
|
||||||
|
```
|
||||||
|
|
||||||
|
You will see a response as below:
|
||||||
|
|
||||||
|
```json
|
||||||
{"access_token":"<openid_access_token>","token_type":"Bearer","matrix_server_name":"example.com","expires_in":3600}
|
{"access_token":"<openid_access_token>","token_type":"Bearer","matrix_server_name":"example.com","expires_in":3600}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -296,10 +319,15 @@ You can then send this payload to the lk-jwt-service:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
~$ curl -X POST -d @payload.json https://livekit.example.com/get_token
|
~$ curl -X POST -d @payload.json https://livekit.example.com/get_token
|
||||||
|
```
|
||||||
|
|
||||||
|
The lk-jwt-service will, after checking against Continuwuity, answer with a `jwt` token to create a LiveKit media room:
|
||||||
|
|
||||||
|
```json
|
||||||
{"url":"wss://livekit.example.com","jwt":"a_really_really_long_string"}
|
{"url":"wss://livekit.example.com","jwt":"a_really_really_long_string"}
|
||||||
```
|
```
|
||||||
|
|
||||||
The lk-jwt-service will, after checking against Continuwuity, answer with a `jwt` token to create a LiveKit media room. Use this token to test at the [LiveKit Connection Tester](https://livekit.io/connection-test). If everything works there, then you have set up LiveKit successfully!
|
Use this token to test at the [LiveKit Connection Tester](https://livekit.io/connection-test). If everything works there, then you have set up LiveKit successfully!
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
@@ -363,8 +391,8 @@ Guides:
|
|||||||
|
|
||||||
Specifications:
|
Specifications:
|
||||||
|
|
||||||
- [MatrixRTC proposal](https://github.com/matrix-org/matrix-spec-proposals/pull/4143)
|
- [MSC4143 - MatrixRTC proposal](https://github.com/matrix-org/matrix-spec-proposals/pull/4143)
|
||||||
- [LiveKit proposal](https://github.com/matrix-org/matrix-spec-proposals/pull/4195)
|
- [MSC4195 - LiveKit proposal](https://github.com/matrix-org/matrix-spec-proposals/pull/4195)
|
||||||
|
|
||||||
Source code:
|
Source code:
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,11 @@
|
|||||||
"name": "kubernetes",
|
"name": "kubernetes",
|
||||||
"label": "Kubernetes"
|
"label": "Kubernetes"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "file",
|
||||||
|
"name": "nomad",
|
||||||
|
"label": "Nomad"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "file",
|
"type": "file",
|
||||||
"name": "freebsd",
|
"name": "freebsd",
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ Consult the [**DNS tuning guide (recommended)**](../advanced/dns.mdx) for full s
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
You will then need to point your reverse proxy towards Continuwuity at `127.0.0.1:8008`. See the [Other reverse proxies](generic.mdx#setting-up-the-reverse-proxy) section of the Generic page for further routing details.
|
See the [Other reverse proxies](generic.mdx#setting-up-the-reverse-proxy) section of the Generic page for further routing details.
|
||||||
|
|
||||||
### Starting Your Server
|
### Starting Your Server
|
||||||
|
|
||||||
@@ -243,9 +243,30 @@ For information on building your own Continuwuity Docker images, see the
|
|||||||
[Building Docker Images](../development/index.mdx#building-docker-images)
|
[Building Docker Images](../development/index.mdx#building-docker-images)
|
||||||
section in the development documentation.
|
section in the development documentation.
|
||||||
|
|
||||||
|
### Accessing the Server's Console
|
||||||
|
|
||||||
|
Before you can access the server's console and [send admin commands](../reference/admin/index.md) from the CLI, you will need to make the container interactive and allocate a pseudo-tty. Make sure you set `admin_console_automatic` to `true` in [the config](../reference/config.mdx) as well for Continuwuity to activate the CLI on startup.
|
||||||
|
|
||||||
|
For Docker Compose deployments this means adding `stdin_open: true` and `tty: true` to the container's declaration:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
homeserver:
|
||||||
|
stdin_open: true
|
||||||
|
tty: true
|
||||||
|
# ...
|
||||||
|
```
|
||||||
|
|
||||||
|
If you choose to deploy via `docker run`, add the flags `-i`/`--interactive` and `-t`/`--tty` to the command.
|
||||||
|
|
||||||
|
From there you can access the server's console by running `docker attach <container-name>`, which will show the server's prompt `uwu> `. To exit `docker attach`, press `CTRL+p` then `CTRL+q`.
|
||||||
|
|
||||||
|
Note that using `CTRL+c` within `docker attach`'s context will forward the signal to the server, stopping it. See [Docker's reference][docker-attach-reference] for more information.
|
||||||
|
|
||||||
|
[docker-attach-reference]: https://docs.docker.com/reference/cli/docker/container/attach/
|
||||||
|
|
||||||
## Next steps
|
## Next steps
|
||||||
|
|
||||||
- For smooth federation, set up a caching resolver according to the [**DNS tuning guide**](../advanced/dns.mdx) (recommended)
|
- For smooth federation, set up a caching resolver according to the [**DNS tuning guide**](../advanced/dns.mdx) (recommended)
|
||||||
- To set up Audio/Video communication, see the [**Calls**](../calls.mdx) page.
|
- To set up Audio/Video communication, see the [**Calls**](../calls.mdx) page.
|
||||||
- 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.mdx).
|
||||||
Guide**](../appservices.mdx).
|
|
||||||
+105
-105
@@ -1,10 +1,12 @@
|
|||||||
# Generic deployment documentation
|
# Generic deployment documentation
|
||||||
|
|
||||||
> ### Getting help
|
:::tip Getting help
|
||||||
>
|
If you run into any problems while setting up Continuwuity, ask us in
|
||||||
> If you run into any problems while setting up Continuwuity, ask us in
|
`#continuwuity:continuwuity.org` or [open an issue on
|
||||||
> `#continuwuity:continuwuity.org` or [open an issue on
|
Forgejo][forgejo-new-issue].
|
||||||
> Forgejo](https://forgejo.ellis.link/continuwuation/continuwuity/issues/new).
|
:::
|
||||||
|
|
||||||
|
[forgejo-new-issue]: https://forgejo.ellis.link/continuwuation/continuwuity/issues/new
|
||||||
|
|
||||||
## Installing Continuwuity
|
## Installing Continuwuity
|
||||||
|
|
||||||
@@ -15,17 +17,16 @@ 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**: [see Release page][release-page]
|
||||||
- **Development builds**: CI artifacts from the `main` branch
|
- **Development builds**: CI artifacts from the `main` branch,
|
||||||
(includes Debian/Ubuntu packages)
|
[see `release-image.yml` for details][release-image]
|
||||||
|
|
||||||
When browsing CI artifacts, `ci-bins` contains binaries organised
|
|
||||||
by commit hash, while `releases` contains tagged versions. Sort
|
|
||||||
by last modified date to find the most recent builds.
|
|
||||||
|
|
||||||
The binaries require jemalloc and io_uring on the host system. Currently
|
The binaries require jemalloc and io_uring on the host system. Currently
|
||||||
we can't cross-build static binaries - contributions are welcome here.
|
we can't cross-build static binaries - contributions are welcome here.
|
||||||
|
|
||||||
|
[release-page]: https://forgejo.ellis.link/continuwuation/continuwuity/releases/
|
||||||
|
[release-image]: https://forgejo.ellis.link/continuwuation/continuwuity/actions/?workflow=release-image.yml
|
||||||
|
|
||||||
#### Performance-optimised builds
|
#### Performance-optimised builds
|
||||||
|
|
||||||
For x86_64 systems with CPUs from the last ~15 years, use the
|
For x86_64 systems with CPUs from the last ~15 years, use the
|
||||||
@@ -38,11 +39,12 @@ compatibility and speed.
|
|||||||
If you're using Docker instead, equivalent performance-optimised
|
If you're using Docker instead, equivalent performance-optimised
|
||||||
images are available with the `-maxperf` suffix (e.g.
|
images are available with the `-maxperf` suffix (e.g.
|
||||||
`forgejo.ellis.link/continuwuation/continuwuity:latest-maxperf`).
|
`forgejo.ellis.link/continuwuation/continuwuity:latest-maxperf`).
|
||||||
These images use the `release-max-perf`
|
These images use the `release-max-perf` build profile with
|
||||||
build profile with
|
[link-time optimisation (LTO)][lto-rust-docs]
|
||||||
[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.
|
||||||
|
|
||||||
|
[lto-rust-docs]: https://doc.rust-lang.org/cargo/reference/profiles.html#lto
|
||||||
|
|
||||||
### Nix
|
### 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.
|
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.
|
||||||
@@ -55,7 +57,8 @@ Alternatively, you may compile the binary yourself.
|
|||||||
|
|
||||||
#### Using Docker
|
#### Using Docker
|
||||||
|
|
||||||
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.
|
See the [Building Docker Images](../development/index.mdx#building-docker-images)
|
||||||
|
section in the development documentation.
|
||||||
|
|
||||||
#### Manual
|
#### Manual
|
||||||
|
|
||||||
@@ -69,7 +72,7 @@ If you would like to build using docker, you can run the command `docker build -
|
|||||||
|
|
||||||
##### Build
|
##### Build
|
||||||
|
|
||||||
You can build Continuwuity using `cargo build --release`.
|
You can now 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.
|
||||||
|
|
||||||
@@ -91,27 +94,6 @@ For distros without `adduser` (or where it's a symlink to `useradd`):
|
|||||||
sudo useradd -r --shell /usr/bin/nologin --no-create-home continuwuity
|
sudo useradd -r --shell /usr/bin/nologin --no-create-home continuwuity
|
||||||
```
|
```
|
||||||
|
|
||||||
## Forwarding ports in the firewall or the router
|
|
||||||
|
|
||||||
Matrix's default federation port is 8448, and clients must use port 443.
|
|
||||||
If you would like to use only port 443 or a different port, you will need to set up
|
|
||||||
delegation. Continuwuity has configuration options for delegation, or you can configure
|
|
||||||
your reverse proxy to manually serve the necessary JSON files for delegation
|
|
||||||
(see the `[global.well_known]` config section).
|
|
||||||
|
|
||||||
If Continuwuity runs behind a router or in a container and has a different public
|
|
||||||
IP address than the host system, you need to forward these public ports directly
|
|
||||||
or indirectly to the port mentioned in the configuration.
|
|
||||||
|
|
||||||
Note for NAT users: if you have trouble connecting to your server from inside
|
|
||||||
your network, check if your router supports "NAT
|
|
||||||
hairpinning" or "NAT loopback".
|
|
||||||
|
|
||||||
If your router does not support this feature, you need to research doing local
|
|
||||||
DNS overrides and force your Matrix DNS records to use your local IP internally.
|
|
||||||
This can be done at the host level using `/etc/hosts`. If you need this to be
|
|
||||||
on the network level, consider something like NextDNS or Pi-Hole.
|
|
||||||
|
|
||||||
## Setting up a systemd service
|
## Setting up a systemd service
|
||||||
|
|
||||||
You can find an example unit for continuwuity below.
|
You can find an example unit for continuwuity below.
|
||||||
@@ -123,7 +105,7 @@ and OpenSUSE), put `$EscapeControlCharactersOnReceive off` inside
|
|||||||
`/etc/rsyslog.conf` to allow color in logs.
|
`/etc/rsyslog.conf` to allow color in logs.
|
||||||
|
|
||||||
If you are using a different `database_path` than the systemd unit's
|
If you are using a different `database_path` than the systemd unit's
|
||||||
configured default `/var/lib/conduwuit`, you need to add your path to the
|
configured default (`/var/lib/conduwuit`), you need to add your path to the
|
||||||
systemd unit's `ReadWritePaths=`. You can do this by either directly editing
|
systemd unit's `ReadWritePaths=`. You can do this by either directly editing
|
||||||
`conduwuit.service` and reloading systemd, or by running `systemctl edit conduwuit.service`
|
`conduwuit.service` and reloading systemd, or by running `systemctl edit conduwuit.service`
|
||||||
and entering the following:
|
and entering the following:
|
||||||
@@ -144,7 +126,9 @@ ReadWritePaths=/path/to/custom/database/path
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
You can also [view the file on Foregejo](https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/pkg/conduwuit.service).
|
You can also [view the file on Foregejo][systemd-file].
|
||||||
|
|
||||||
|
[systemd-file]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/pkg/conduwuit.service
|
||||||
|
|
||||||
## Creating the Continuwuity configuration file
|
## Creating the Continuwuity configuration file
|
||||||
|
|
||||||
@@ -155,9 +139,7 @@ Now you need to create the Continuwuity configuration file in
|
|||||||
**Please take a moment to read the config. You need to change at least the
|
**Please take a moment to read the config. You need to change at least the
|
||||||
server name.**
|
server name.**
|
||||||
|
|
||||||
RocksDB is the only supported database backend.
|
### Setting the correct file permissions
|
||||||
|
|
||||||
## Setting the correct file permissions
|
|
||||||
|
|
||||||
If you are using a dedicated user for Continuwuity, you need to allow it to
|
If you are using a dedicated user for Continuwuity, you need to allow it to
|
||||||
read the configuration. To do this, run:
|
read the configuration. To do this, run:
|
||||||
@@ -175,22 +157,29 @@ sudo chown -R continuwuity:continuwuity /var/lib/conduwuit/
|
|||||||
sudo chmod 700 /var/lib/conduwuit/
|
sudo chmod 700 /var/lib/conduwuit/
|
||||||
```
|
```
|
||||||
|
|
||||||
## Setting up the Reverse Proxy
|
## Exposing ports in the firewall or the router
|
||||||
|
|
||||||
We recommend Caddy as a reverse proxy because it is trivial to use and handles TLS certificates, reverse proxy headers, etc. transparently with proper defaults.
|
Matrix's default federation port is **:8448**, and clients use port **:443**. You will need to
|
||||||
For other software, please refer to their respective documentation or online guides.
|
expose these ports on your firewall or router. If you use UFW, the commands to allow them
|
||||||
|
are: `ufw allow 8448/tcp` and `ufw allow 443/tcp`.
|
||||||
|
|
||||||
|
:::tip Alternative port/domain setups
|
||||||
|
If you would like to use only port 443, a different port, or a subdomain for the homeserver, you will need to set up `.well-known` delegation. Consult the `[global.well_known]` section of the config file, and the [**Delegation/Split-domain**](../advanced/delegation) page to learn more about these kinds of deployments.
|
||||||
|
:::
|
||||||
|
|
||||||
|
## Setting up the Reverse Proxy
|
||||||
|
|
||||||
### Caddy
|
### Caddy
|
||||||
|
|
||||||
After installing Caddy via your preferred method, create `/etc/caddy/conf.d/conduwuit_caddyfile`
|
Caddy is the recommended reverse proxy as it is easy to use, has good defaults,
|
||||||
and enter the following (substitute your actual server name):
|
and handle TLS certificates automatically. After installing Caddy via your preferred
|
||||||
|
method, create `/etc/caddy/conf.d/conduwuit_caddyfile` and enter the following
|
||||||
|
(substitute `example.com` with your actual server name):
|
||||||
|
|
||||||
```
|
```
|
||||||
your.server.name, your.server.name:8448 {
|
example.com, example.com:8448 {
|
||||||
# TCP reverse_proxy
|
# TCP reverse_proxy
|
||||||
reverse_proxy 127.0.0.1:6167
|
reverse_proxy 127.0.0.1:8008
|
||||||
# UNIX socket
|
|
||||||
#reverse_proxy unix//run/conduwuit/conduwuit.sock
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -202,51 +191,45 @@ sudo systemctl enable --now caddy
|
|||||||
|
|
||||||
### Other Reverse Proxies
|
### Other Reverse Proxies
|
||||||
|
|
||||||
As we prefer our users to use Caddy, we do not provide configuration files for other proxies.
|
Normally, your reverse proxy should route everything from port :8448 and :443 back to Continuwuity.
|
||||||
|
|
||||||
You will need to reverse proxy everything under the following routes:
|
For more granular controls, you will need to proxy everything under these following routes:
|
||||||
|
|
||||||
- `/_matrix/` - core Matrix C-S and S-S APIs
|
- `/_matrix/` - core Matrix APIs, which includes:
|
||||||
- `/_conduwuit/` and/or `/_continuwuity/` - ad-hoc Continuwuity routes such as `/local_user_count` and
|
|
||||||
`/server_version`
|
- `/_matrix/federation` and `/_matrix/key` - core Server-Server APIs. These should be available on port :8448
|
||||||
|
|
||||||
|
- `/_matrix/client` - core Client-Server APIs. These should be available on port :443
|
||||||
|
|
||||||
|
- `/_conduwuit/` and `/_continuwuity/` - ad-hoc Continuwuity routes for password resets, email verification, and server details such as `/local_user_count` and `/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][well-known-support]
|
||||||
- `/` if you would like to see `hewwo from conduwuit woof!` at the root
|
- `/` and `/_continuwuity/logo.svg` if you would like to see the Continuwuity landing page
|
||||||
|
|
||||||
See the following spec pages for more details on these files:
|
Refer to the respective software's documentation and online guides on how to do so.
|
||||||
|
|
||||||
- [`/.well-known/matrix/server`](https://spec.matrix.org/latest/client-server-api/#getwell-knownmatrixserver)
|
[well-known-support]: https://spec.matrix.org/v1.18/client-server-api/#getwell-knownmatrixsupport
|
||||||
- [`/.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)
|
|
||||||
|
|
||||||
Examples of delegation:
|
#### Caveats for specific reverse proxies
|
||||||
|
|
||||||
- https://continuwuity.org/.well-known/matrix/server
|
- Lighttpd is not supported as it appears to interfere with the `X-Matrix` Authorization
|
||||||
- https://continuwuity.org/.well-known/matrix/client
|
|
||||||
- https://ellis.link/.well-known/matrix/server
|
|
||||||
- https://ellis.link/.well-known/matrix/client
|
|
||||||
|
|
||||||
For Apache and Nginx there are many examples available online.
|
|
||||||
|
|
||||||
Lighttpd is not supported as it appears to interfere with the `X-Matrix` Authorization
|
|
||||||
header, making federation non-functional. If you find a workaround, please share it so we can add it to this documentation.
|
header, making federation non-functional. If you find a workaround, please share it so we can add it to this documentation.
|
||||||
|
|
||||||
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;`
|
||||||
|
|
||||||
Nginx users need to increase the `client_max_body_size` setting (default is 1M) to match the
|
Furthermore, Nginx users need to increase the `client_max_body_size` setting (default is 1M) to match the `max_request_size` defined in conduwuit.toml.
|
||||||
`max_request_size` defined in conduwuit.toml.
|
|
||||||
|
|
||||||
## You're done
|
## Starting Your Server
|
||||||
|
|
||||||
Now you can start Continuwuity with:
|
Now you can start Continuwuity with:
|
||||||
|
|
||||||
@@ -260,36 +243,53 @@ Set it to start automatically when your system boots with:
|
|||||||
sudo systemctl enable conduwuit
|
sudo systemctl enable conduwuit
|
||||||
```
|
```
|
||||||
|
|
||||||
## How do I know it works?
|
Check Continuwuity logs with the following command:
|
||||||
|
|
||||||
You can open [a Matrix client](https://matrix.org/ecosystem/clients), enter your
|
|
||||||
homeserver address, and try to register.
|
|
||||||
|
|
||||||
You can also use these commands as a quick health check (replace
|
|
||||||
`your.server.name`).
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl https://your.server.name/_conduwuit/server_version
|
sudo journalctl -u conduwuit.service
|
||||||
|
|
||||||
# If using port 8448
|
|
||||||
curl https://your.server.name:8448/_conduwuit/server_version
|
|
||||||
|
|
||||||
# If federation is enabled
|
|
||||||
curl https://your.server.name:8448/_matrix/federation/v1/version
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- To check if your server can communicate with other homeservers, use the
|
If Continuwuity has successfully initialized, you'll see output as below.
|
||||||
[Matrix Federation Tester](https://federationtester.mtrnord.blog/). If you can
|
|
||||||
register but cannot join federated rooms, check your configuration and verify
|
```
|
||||||
that port 8448 is open and forwarded correctly.
|
In order to use your new homeserver, you need to create its
|
||||||
|
first user account.
|
||||||
|
Open your Matrix client of choice and register an account
|
||||||
|
on example.com using registration token x5keUZ811RqvLsNa .
|
||||||
|
Pick your own username and password!
|
||||||
|
```
|
||||||
|
|
||||||
|
You can then open [a Matrix client][matrix-clients],
|
||||||
|
enter your homeserver address, and try to register with the provided token.
|
||||||
|
By default, the first user is the instance's first admin. They will be added
|
||||||
|
to the `#admin:example.com` room and be able to [issue admin commands](../reference/admin/index.md).
|
||||||
|
|
||||||
|
[matrix-clients]: https://matrix.org/ecosystem/clients
|
||||||
|
|
||||||
|
## How do I know it works?
|
||||||
|
|
||||||
|
To check if your server can communicate with other homeservers, use the
|
||||||
|
[Matrix Federation Tester](https://federationtester.mtrnord.blog/). If you can
|
||||||
|
register your account but cannot join federated rooms, check your configuration
|
||||||
|
and verify that your federation endpoints are opened and forwarded correctly.
|
||||||
|
|
||||||
|
As a quick health check, you can also use these cURL commands:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl https://example.com/_conduwuit/server_version
|
||||||
|
|
||||||
|
# If using port 8448
|
||||||
|
curl https://example.com:8448/_conduwuit/server_version
|
||||||
|
|
||||||
|
# If federation is enabled
|
||||||
|
curl https://example.com:8448/_matrix/federation/v1/version
|
||||||
|
|
||||||
|
# For client-server endpoints
|
||||||
|
curl https://example.com/_matrix/client/versions
|
||||||
|
```
|
||||||
|
|
||||||
## What's next?
|
## What's next?
|
||||||
|
|
||||||
### Audio/Video calls
|
- For smooth federation, set up a caching resolver according to the [**DNS tuning guide**](../advanced/dns.mdx) (recommended)
|
||||||
|
- For Audio/Video call functionality see the [**Calls**](../calls.md) page.
|
||||||
For Audio/Video call functionality see the [Calls](../calls.md) page.
|
- If you want to set up an appservice, take a look at the [**Appservice Guide**](../appservices.md).
|
||||||
|
|
||||||
### Appservices
|
|
||||||
|
|
||||||
If you want to set up an appservice, take a look at the [Appservice
|
|
||||||
Guide](../appservices.md).
|
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
# Continuwuity for Nomad
|
||||||
|
|
||||||
|
You can either pass the configuration as environment variables or mount a file containing the configuration from consul.
|
||||||
|
This given configuration assumes that you have a traefik reverse proxy running.
|
||||||
|
|
||||||
|
## Persistence
|
||||||
|
The database being a RockDB file, it is recommended to use a volume to persist the data.
|
||||||
|
The example below uses a volume, you need to configure the CSI driver on your cluster.
|
||||||
|
|
||||||
|
| Volume Name | Mount Path | Purpose |
|
||||||
|
|-------------|------------|---------|
|
||||||
|
| continuwuity-volume | `/var/lib/continuwuity` | Store the database |
|
||||||
|
| continuwuity-media-volume | `/var/lib/continuwuity/media` | Store uploaded media |
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
### Using environment variables
|
||||||
|
```hcl
|
||||||
|
job "continuwuity" {
|
||||||
|
datacenters = ["dc1"]
|
||||||
|
type = "service"
|
||||||
|
node_pool = "default"
|
||||||
|
|
||||||
|
group "continuwuity" {
|
||||||
|
count = 1
|
||||||
|
|
||||||
|
network {
|
||||||
|
port "http" {
|
||||||
|
static = 6167
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
service {
|
||||||
|
name = "continuwuity"
|
||||||
|
port = "http"
|
||||||
|
tags = [
|
||||||
|
"traefik.enable=true",
|
||||||
|
"traefik.http.routers.continuwuity.rule=(Host(`matrix.example.com`) || (Host(`example.com`) && PathPrefix(`/.well-known/matrix`)))",
|
||||||
|
"traefik.http.routers.continuwuity.entrypoints=https",
|
||||||
|
"traefik.http.routers.continuwuity.tls=true",
|
||||||
|
"traefik.http.routers.continuwuity.tls.certresolver=letsencrypt",
|
||||||
|
"traefik.http.routers.continuwuity-http.rule=(Host(`matrix.example.com`) || (Host(`example.com`) && PathPrefix(`/.well-known/matrix`)))",
|
||||||
|
"traefik.http.routers.continuwuity-http.entrypoints=http",
|
||||||
|
"traefik.http.routers.continuwuity-http.middlewares=continuwuity-redirect",
|
||||||
|
"traefik.http.middlewares.continuwuity-redirect.redirectscheme.scheme=https",
|
||||||
|
"traefik.http.middlewares.continuwuity-redirect.redirectscheme.permanent=true",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
volume "continuwuity-volume" {
|
||||||
|
type = "csi"
|
||||||
|
read_only = false
|
||||||
|
source = "continuwuity-volume"
|
||||||
|
attachment_mode = "file-system"
|
||||||
|
access_mode = "single-node-writer"
|
||||||
|
per_alloc = false
|
||||||
|
}
|
||||||
|
|
||||||
|
volume "continuwuity-media-volume" {
|
||||||
|
type = "csi"
|
||||||
|
read_only = false
|
||||||
|
source = "continuwuity-media-volume"
|
||||||
|
attachment_mode = "file-system"
|
||||||
|
access_mode = "single-node-writer"
|
||||||
|
per_alloc = false
|
||||||
|
|
||||||
|
mount_options {
|
||||||
|
mount_flags = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task "continuwuity" {
|
||||||
|
driver = "docker"
|
||||||
|
|
||||||
|
env {
|
||||||
|
CONTINUWUITY_SERVER_NAME = "matrix.example.com"
|
||||||
|
CONTINUWUITY_TRUSTED_SERVERS = "[\"matrix.org\", \"mozilla.org\"]"
|
||||||
|
CONTINUWUITY_ALLOW_REGISTRATION = false
|
||||||
|
CONTINUWUITY_ADDRESS = "0.0.0.0"
|
||||||
|
CONTINUWUITY_PORT = 6167
|
||||||
|
CONTINUWUITY_DATABASE_PATH = "/var/lib/continuwuity"
|
||||||
|
CONTINUWUITY_WELL_KNOWN = <<EOF
|
||||||
|
{
|
||||||
|
client=https://matrix.example.com,
|
||||||
|
server=matrix.example.com:443
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
config {
|
||||||
|
image = "forgejo.ellis.link/continuwuation/continuwuity:latest"
|
||||||
|
ports = ["http"]
|
||||||
|
}
|
||||||
|
|
||||||
|
volume_mount {
|
||||||
|
volume = "continuwuity-volume"
|
||||||
|
destination = "/var/lib/continuwuity"
|
||||||
|
}
|
||||||
|
|
||||||
|
volume_mount {
|
||||||
|
volume = "continuwuity-media-volume"
|
||||||
|
destination = "/var/lib/continuwuity/media"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using consul
|
||||||
|
```hcl
|
||||||
|
...
|
||||||
|
template {
|
||||||
|
data = <<EOF
|
||||||
|
{{key "config/continuwuity"}}
|
||||||
|
EOF
|
||||||
|
destination = "local/conduwuit.toml"
|
||||||
|
}
|
||||||
|
...
|
||||||
|
```
|
||||||
@@ -6,10 +6,10 @@
|
|||||||
"message": "Welcome to Continuwuity! Important announcements about the project will appear here."
|
"message": "Welcome to Continuwuity! Important announcements about the project will appear here."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 11,
|
"id": 12,
|
||||||
"mention_room": false,
|
"mention_room": false,
|
||||||
"date": "2026-04-17",
|
"date": "2026-04-24",
|
||||||
"message": "[v0.5.7](https://forgejo.ellis.link/continuwuation/continuwuity/releases/tag/v0.5.7) is out! Email verification! Terms and Conditions! Deleting notification pushers! So much good stuff. Go grab the release and read the changelog!"
|
"message": "[v0.5.8](https://forgejo.ellis.link/continuwuation/continuwuity/releases/tag/v0.5.8) is out! This is a patch release which fixes a bug in 0.5.7's email support -- upgrade soon if you use that feature."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# Continuwuity - Behind Traefik Reverse Proxy
|
||||||
|
|
||||||
|
services:
|
||||||
|
homeserver:
|
||||||
|
image: "forgejo.ellis.link/continuwuation/continuwuity:latest"
|
||||||
|
restart: unless-stopped
|
||||||
|
command: /sbin/conduwuit
|
||||||
|
volumes:
|
||||||
|
- db:/var/lib/continuwuity
|
||||||
|
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
|
||||||
|
#- ./continuwuity.toml:/etc/continuwuity.toml
|
||||||
|
networks:
|
||||||
|
- proxy
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.continuwuity.rule=(Host(`matrix.example.com`) || (Host(`example.com`) && PathPrefix(`/.well-known/matrix`)))"
|
||||||
|
- "traefik.http.routers.continuwuity.entrypoints=websecure" # your HTTPS entry point
|
||||||
|
- "traefik.http.routers.continuwuity.tls=true"
|
||||||
|
- "traefik.http.routers.continuwuity.service=continuwuity"
|
||||||
|
- "traefik.http.services.continuwuity.loadbalancer.server.port=8008"
|
||||||
|
# possibly, depending on your config:
|
||||||
|
# - "traefik.http.routers.continuwuity.tls.certresolver=letsencrypt"
|
||||||
|
environment:
|
||||||
|
CONTINUWUITY_SERVER_NAME: example.com # EDIT THIS
|
||||||
|
CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity
|
||||||
|
CONTINUWUITY_ADDRESS: 0.0.0.0
|
||||||
|
CONTINUWUITY_PORT: 8008 # This must match with traefik's loadbalancer label
|
||||||
|
#CONTINUWUITY_CONFIG: '/etc/continuwuity.toml' # Uncomment if you mapped config toml above
|
||||||
|
|
||||||
|
# Serve .well-known files to tell others to reach Continuwuity on port :443
|
||||||
|
CONTINUWUITY_WELL_KNOWN: |
|
||||||
|
{
|
||||||
|
client=https://matrix.example.com,
|
||||||
|
server=matrix.example.com:443
|
||||||
|
}
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
# This must match the network name that Traefik listens on
|
||||||
|
proxy:
|
||||||
|
external: true
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
# Continuwuity - With Caddy Labels
|
||||||
|
|
||||||
|
services:
|
||||||
|
caddy:
|
||||||
|
# This compose file uses caddy-docker-proxy as the reverse proxy for Continuwuity!
|
||||||
|
# For more info, visit https://github.com/lucaslorentz/caddy-docker-proxy
|
||||||
|
image: "docker.io/lucaslorentz/caddy-docker-proxy:ci-alpine"
|
||||||
|
ports:
|
||||||
|
- 80:80
|
||||||
|
- 443:443
|
||||||
|
environment:
|
||||||
|
- CADDY_INGRESS_NETWORKS=caddy
|
||||||
|
networks:
|
||||||
|
- caddy
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
- ./data:/data
|
||||||
|
restart: unless-stopped
|
||||||
|
labels:
|
||||||
|
caddy: example.com
|
||||||
|
caddy.reverse_proxy: /.well-known/matrix/* homeserver:8008
|
||||||
|
|
||||||
|
homeserver:
|
||||||
|
image: "forgejo.ellis.link/continuwuation/continuwuity:latest"
|
||||||
|
restart: unless-stopped
|
||||||
|
command: /sbin/conduwuit
|
||||||
|
volumes:
|
||||||
|
- db:/var/lib/continuwuity
|
||||||
|
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
|
||||||
|
#- ./continuwuity.toml:/etc/continuwuity.toml
|
||||||
|
environment:
|
||||||
|
CONTINUWUITY_SERVER_NAME: example.com # EDIT THIS
|
||||||
|
CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity
|
||||||
|
CONTINUWUITY_ADDRESS: 0.0.0.0
|
||||||
|
CONTINUWUITY_PORT: 8008
|
||||||
|
#CONTINUWUITY_CONFIG: '/etc/continuwuity.toml' # Uncomment if you mapped config toml above
|
||||||
|
|
||||||
|
# Serve .well-known files to tell others to reach Continuwuity on port :443
|
||||||
|
CONTINUWUITY_WELL_KNOWN: |
|
||||||
|
{
|
||||||
|
client=https://matrix.example.com,
|
||||||
|
server=matrix.example.com:443
|
||||||
|
}
|
||||||
|
|
||||||
|
networks:
|
||||||
|
- caddy
|
||||||
|
labels:
|
||||||
|
caddy: matrix.example.com
|
||||||
|
caddy.reverse_proxy: "{{upstreams 8008}}"
|
||||||
|
volumes:
|
||||||
|
db:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
caddy:
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# Continuwuity - Using Caddy Docker Image
|
||||||
|
|
||||||
|
services:
|
||||||
|
caddy:
|
||||||
|
image: "docker.io/caddy:latest"
|
||||||
|
ports:
|
||||||
|
- 80:80
|
||||||
|
- 443:443
|
||||||
|
networks:
|
||||||
|
- caddy
|
||||||
|
volumes:
|
||||||
|
- ./data:/data
|
||||||
|
restart: unless-stopped
|
||||||
|
configs:
|
||||||
|
- source: Caddyfile
|
||||||
|
target: /etc/caddy/Caddyfile
|
||||||
|
|
||||||
|
homeserver:
|
||||||
|
image: "forgejo.ellis.link/continuwuation/continuwuity:latest"
|
||||||
|
restart: unless-stopped
|
||||||
|
command: /sbin/conduwuit
|
||||||
|
volumes:
|
||||||
|
- db:/var/lib/continuwuity
|
||||||
|
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
|
||||||
|
#- ./continuwuity.toml:/etc/continuwuity.toml
|
||||||
|
environment:
|
||||||
|
CONTINUWUITY_SERVER_NAME: example.com
|
||||||
|
CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity
|
||||||
|
CONTINUWUITY_ADDRESS: 0.0.0.0
|
||||||
|
CONTINUWUITY_PORT: 8008
|
||||||
|
#CONTINUWUITY_CONFIG: '/etc/continuwuity.toml' # Uncomment if you mapped config toml above
|
||||||
|
|
||||||
|
## Serve .well-known files to tell others to reach Continuwuity on port :443
|
||||||
|
CONTINUWUITY_WELL_KNOWN: |
|
||||||
|
{
|
||||||
|
client=https://matrix.example.com,
|
||||||
|
server=matrix.example.com:443
|
||||||
|
}
|
||||||
|
|
||||||
|
networks:
|
||||||
|
- caddy
|
||||||
|
|
||||||
|
networks:
|
||||||
|
caddy:
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db:
|
||||||
|
|
||||||
|
configs:
|
||||||
|
Caddyfile:
|
||||||
|
content: |
|
||||||
|
https://matrix.example.com:443 {
|
||||||
|
reverse_proxy http://homeserver:8008
|
||||||
|
}
|
||||||
|
https://example.com:443 {
|
||||||
|
reverse_proxy /.well-known/matrix* http://homeserver:8008
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
# Continuwuity - With Traefik Reverse Proxy
|
||||||
|
|
||||||
|
services:
|
||||||
|
homeserver:
|
||||||
|
image: "forgejo.ellis.link/continuwuation/continuwuity:latest"
|
||||||
|
restart: unless-stopped
|
||||||
|
command: /sbin/conduwuit
|
||||||
|
volumes:
|
||||||
|
- db:/var/lib/continuwuity
|
||||||
|
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
|
||||||
|
#- ./continuwuity.toml:/etc/continuwuity.toml
|
||||||
|
networks:
|
||||||
|
- proxy
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.continuwuity.rule=(Host(`matrix.example.com`) || (Host(`example.com`) && PathPrefix(`/.well-known/matrix`)))"
|
||||||
|
- "traefik.http.routers.continuwuity.entrypoints=websecure"
|
||||||
|
- "traefik.http.routers.continuwuity.tls.certresolver=letsencrypt"
|
||||||
|
- "traefik.http.services.continuwuity.loadbalancer.server.port=8008"
|
||||||
|
environment:
|
||||||
|
CONTINUWUITY_SERVER_NAME: example.com # EDIT THIS
|
||||||
|
CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity
|
||||||
|
CONTINUWUITY_ADDRESS: 0.0.0.0
|
||||||
|
CONTINUWUITY_PORT: 8008 # This must match with traefik's loadbalancer label
|
||||||
|
#CONTINUWUITY_CONFIG: '/etc/continuwuity.toml' # Uncomment if you mapped config toml above
|
||||||
|
|
||||||
|
# Serve .well-known files to tell others to reach Continuwuity on port :443
|
||||||
|
CONTINUWUITY_WELL_KNOWN: |
|
||||||
|
{
|
||||||
|
client=https://matrix.example.com,
|
||||||
|
server=matrix.example.com:443
|
||||||
|
}
|
||||||
|
|
||||||
|
traefik:
|
||||||
|
image: "docker.io/traefik:latest"
|
||||||
|
container_name: "traefik"
|
||||||
|
restart: "unless-stopped"
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
- "443:443"
|
||||||
|
volumes:
|
||||||
|
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
||||||
|
- "acme:/etc/traefik/acme"
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
|
||||||
|
# middleware redirect
|
||||||
|
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
|
||||||
|
# global redirect to https
|
||||||
|
- "traefik.http.routers.redirs.rule=hostregexp(`{host:.+}`)"
|
||||||
|
- "traefik.http.routers.redirs.entrypoints=web"
|
||||||
|
- "traefik.http.routers.redirs.middlewares=redirect-to-https"
|
||||||
|
|
||||||
|
environment:
|
||||||
|
|
||||||
|
TRAEFIK_LOG_LEVEL: DEBUG
|
||||||
|
TRAEFIK_ENTRYPOINTS_WEB: true
|
||||||
|
TRAEFIK_ENTRYPOINTS_WEB_ADDRESS: ":80"
|
||||||
|
TRAEFIK_ENTRYPOINTS_WEB_HTTP_REDIRECTIONS_ENTRYPOINT_TO: websecure
|
||||||
|
|
||||||
|
TRAEFIK_ENTRYPOINTS_WEBSECURE: true
|
||||||
|
TRAEFIK_ENTRYPOINTS_WEBSECURE_ADDRESS: ":443"
|
||||||
|
TRAEFIK_ENTRYPOINTS_WEBSECURE_HTTP_TLS_CERTRESOLVER: letsencrypt
|
||||||
|
|
||||||
|
TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT: true
|
||||||
|
# CHANGE THIS to desired email for ACME
|
||||||
|
TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_EMAIL: user@example.com
|
||||||
|
TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_HTTPCHALLENGE: true
|
||||||
|
TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_HTTPCHALLENGE_ENTRYPOINT: web
|
||||||
|
TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_STORAGE: "/etc/traefik/acme/acme.json"
|
||||||
|
|
||||||
|
# Since Traefik 3.6.3, paths with certain "encoded characters" are now blocked by default; we need a couple, or else things *will* break
|
||||||
|
TRAEFIK_ENTRYPOINTS_WEBSECURE_HTTP_ENCODEDCHARACTERS_ALLOWENCODEDSLASH: true
|
||||||
|
TRAEFIK_ENTRYPOINTS_WEBSECURE_HTTP_ENCODEDCHARACTERS_ALLOWENCODEDHASH: true
|
||||||
|
|
||||||
|
TRAEFIK_PROVIDERS_DOCKER: true
|
||||||
|
TRAEFIK_PROVIDERS_DOCKER_ENDPOINT: "unix:///var/run/docker.sock"
|
||||||
|
TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT: false
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db:
|
||||||
|
acme:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
proxy:
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
homeserver:
|
homeserver:
|
||||||
image: forgejo.ellis.link/continuwuation/continuwuity:latest
|
image: "forgejo.ellis.link/continuwuation/continuwuity:latest"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
command: /sbin/conduwuit
|
command: /sbin/conduwuit
|
||||||
volumes:
|
volumes:
|
||||||
@@ -38,7 +38,6 @@ volumes:
|
|||||||
db:
|
db:
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
# This is the network Traefik listens to, if your network has a different
|
# This must match the network name that Traefik listens on
|
||||||
# name, don't forget to change it here and in the docker-compose.override.yml
|
|
||||||
proxy:
|
proxy:
|
||||||
external: true
|
external: true
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
# Continuwuity - Traefik Reverse Proxy Labels
|
# Continuwuity - Traefik Reverse Proxy Labels (override file)
|
||||||
|
|
||||||
services:
|
services:
|
||||||
homeserver:
|
homeserver:
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
- "traefik.docker.network=proxy" # Change this to the name of your Traefik docker proxy network
|
- "traefik.docker.network=proxy" # Change this to the name of your Traefik docker proxy network
|
||||||
|
|
||||||
- "traefik.http.routers.to-continuwuity.rule=Host(`example.com`)" # Change to the address on which Continuwuity is hosted
|
- "traefik.http.routers.to-continuwuity.rule=Host(`example.com`)" # Change to the address on which Continuwuity is hosted
|
||||||
- "traefik.http.routers.to-continuwuity.tls=true"
|
- "traefik.http.routers.to-continuwuity.tls=true"
|
||||||
@@ -14,13 +14,10 @@ services:
|
|||||||
# This must match with CONTINUWUITY_PORT (default: 8008)
|
# This must match with CONTINUWUITY_PORT (default: 8008)
|
||||||
- "traefik.http.services.to_continuwuity.loadbalancer.server.port=8008"
|
- "traefik.http.services.to_continuwuity.loadbalancer.server.port=8008"
|
||||||
|
|
||||||
- "traefik.http.middlewares.cors-headers.headers.accessControlAllowOriginList=*"
|
|
||||||
- "traefik.http.middlewares.cors-headers.headers.accessControlAllowHeaders=Origin, X-Requested-With, Content-Type, Accept, Authorization"
|
|
||||||
- "traefik.http.middlewares.cors-headers.headers.accessControlAllowMethods=GET, POST, PUT, DELETE, OPTIONS"
|
|
||||||
|
|
||||||
# If you want to have your account on <DOMAIN>, but host Continuwuity on a subdomain,
|
# If you want to have your account on <DOMAIN>, but host Continuwuity on a subdomain,
|
||||||
# you can let it only handle the well known file on that domain instead
|
# you can let it only handle the well known file on the base domain instead
|
||||||
#- "traefik.http.routers.to-matrix-wellknown.rule=Host(`example.com`) && PathPrefix(`/.well-known/matrix`)"
|
#
|
||||||
|
# - "traefik.http.routers.to-matrix-wellknown.rule=Host(`example.com`) && PathPrefix(`/.well-known/matrix`)"
|
||||||
#- "traefik.http.routers.to-matrix-wellknown.tls=true"
|
#- "traefik.http.routers.to-matrix-wellknown.tls=true"
|
||||||
#- "traefik.http.routers.to-matrix-wellknown.tls.certresolver=letsencrypt"
|
#- "traefik.http.routers.to-matrix-wellknown.tls.certresolver=letsencrypt"
|
||||||
#- "traefik.http.routers.to-matrix-wellknown.middlewares=cors-headers@docker"
|
#- "traefik.http.routers.to-matrix-wellknown.middlewares=cors-headers@docker"
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
|
# Continuwuity - With Caddy Labels
|
||||||
|
|
||||||
services:
|
services:
|
||||||
caddy:
|
caddy:
|
||||||
# This compose file uses caddy-docker-proxy as the reverse proxy for Continuwuity!
|
# This compose file uses caddy-docker-proxy as the reverse proxy for Continuwuity!
|
||||||
# For more info, visit https://github.com/lucaslorentz/caddy-docker-proxy
|
# For more info, visit https://github.com/lucaslorentz/caddy-docker-proxy
|
||||||
image: lucaslorentz/caddy-docker-proxy:ci-alpine
|
image: "docker.io/lucaslorentz/caddy-docker-proxy:ci-alpine"
|
||||||
ports:
|
ports:
|
||||||
- 80:80
|
- 80:80
|
||||||
- 443:443
|
- 443:443
|
||||||
@@ -16,7 +18,7 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
homeserver:
|
homeserver:
|
||||||
image: forgejo.ellis.link/continuwuation/continuwuity:latest
|
image: "forgejo.ellis.link/continuwuation/continuwuity:latest"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
command: /sbin/conduwuit
|
command: /sbin/conduwuit
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# Continuwuity - Using Caddy Docker Image
|
||||||
|
|
||||||
services:
|
services:
|
||||||
caddy:
|
caddy:
|
||||||
image: docker.io/caddy:latest
|
image: "docker.io/caddy:latest"
|
||||||
ports:
|
ports:
|
||||||
- 80:80
|
- 80:80
|
||||||
- 443:443
|
- 443:443
|
||||||
@@ -15,7 +17,7 @@ services:
|
|||||||
target: /etc/caddy/Caddyfile
|
target: /etc/caddy/Caddyfile
|
||||||
|
|
||||||
homeserver:
|
homeserver:
|
||||||
image: forgejo.ellis.link/continuwuation/continuwuity:latest
|
image: "forgejo.ellis.link/continuwuation/continuwuity:latest"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
command: /sbin/conduwuit
|
command: /sbin/conduwuit
|
||||||
volumes:
|
volumes:
|
||||||
@@ -37,7 +39,6 @@ services:
|
|||||||
# server=example.com:443
|
# server=example.com:443
|
||||||
# }
|
# }
|
||||||
|
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
- caddy
|
- caddy
|
||||||
|
|
||||||
@@ -48,8 +49,8 @@ volumes:
|
|||||||
db:
|
db:
|
||||||
|
|
||||||
configs:
|
configs:
|
||||||
dynamic.yml:
|
Caddyfile:
|
||||||
content: |
|
content: |
|
||||||
https://example.com, https://example.com:8448 {
|
https://example.com:443, https://example.com:8448 {
|
||||||
reverse_proxy http://homeserver:8008
|
reverse_proxy http://homeserver:8008
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
# Continuwuity - Behind Traefik Reverse Proxy
|
# Continuwuity - With Traefik Reverse Proxy
|
||||||
|
|
||||||
services:
|
services:
|
||||||
homeserver:
|
homeserver:
|
||||||
image: forgejo.ellis.link/continuwuation/continuwuity:latest
|
image: "forgejo.ellis.link/continuwuation/continuwuity:latest"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
command: /sbin/conduwuit
|
command: /sbin/conduwuit
|
||||||
volumes:
|
volumes:
|
||||||
@@ -32,14 +32,14 @@ services:
|
|||||||
}
|
}
|
||||||
|
|
||||||
traefik:
|
traefik:
|
||||||
image: "traefik:latest"
|
image: "docker.io/traefik:latest"
|
||||||
container_name: "traefik"
|
container_name: "traefik"
|
||||||
restart: "unless-stopped"
|
restart: "unless-stopped"
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80"
|
||||||
- "443:443"
|
- "443:443"
|
||||||
volumes:
|
volumes:
|
||||||
- "/var/run/docker.sock:/var/run/docker.sock:z"
|
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
||||||
- "acme:/etc/traefik/acme"
|
- "acme:/etc/traefik/acme"
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
@@ -52,6 +52,7 @@ services:
|
|||||||
- "traefik.http.routers.redirs.middlewares=redirect-to-https"
|
- "traefik.http.routers.redirs.middlewares=redirect-to-https"
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
|
||||||
TRAEFIK_LOG_LEVEL: DEBUG
|
TRAEFIK_LOG_LEVEL: DEBUG
|
||||||
TRAEFIK_ENTRYPOINTS_WEB: true
|
TRAEFIK_ENTRYPOINTS_WEB: true
|
||||||
TRAEFIK_ENTRYPOINTS_WEB_ADDRESS: ":80"
|
TRAEFIK_ENTRYPOINTS_WEB_ADDRESS: ":80"
|
||||||
|
|||||||
@@ -1,12 +1,23 @@
|
|||||||
# Continuwuity
|
# Continuwuity - Bare Configuration (for other reverse proxies)
|
||||||
|
|
||||||
services:
|
services:
|
||||||
homeserver:
|
homeserver:
|
||||||
image: forgejo.ellis.link/continuwuation/continuwuity:latest
|
image: "forgejo.ellis.link/continuwuation/continuwuity:latest"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
command: /sbin/conduwuit
|
command: /sbin/conduwuit
|
||||||
ports:
|
ports:
|
||||||
|
|
||||||
|
# If your reverse proxy is on the host, use this
|
||||||
|
# and configure it to connect to `127.0.0.1:8008`
|
||||||
- 127.0.0.1:8008:8008
|
- 127.0.0.1:8008:8008
|
||||||
|
|
||||||
|
# If your reverse proxy is on another machine, use this
|
||||||
|
# and configure it to connect to <this-machine-ip>:8008
|
||||||
|
# - 8008:8008
|
||||||
|
|
||||||
|
# If your reverse proxy is a docker container on the same network,
|
||||||
|
# comment out the entire `ports` section, and configure it to connect to `continuwuity:8008`
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- db:/var/lib/continuwuity
|
- db:/var/lib/continuwuity
|
||||||
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
|
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
|
||||||
@@ -26,6 +37,5 @@ services:
|
|||||||
# server=example.com:443
|
# server=example.com:443
|
||||||
# }
|
# }
|
||||||
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
db:
|
db:
|
||||||
@@ -7,7 +7,7 @@ Admin commands allow server administrators to manage the server from within thei
|
|||||||
|
|
||||||
* All commands listed here may be used by server administrators in the admin room by sending them as messages.
|
* All commands listed here may be used by server administrators in the admin room by sending them as messages.
|
||||||
* If the `admin_escape_commands` configuration option is enabled, server administrators may run certain commands in public rooms by prefixing them with a single backslash. These commands will only run on _their_ homeserver, even if they are a member of another homeserver's admin room. Some sensitive commands cannot be used outside the admin room and will return an error.
|
* If the `admin_escape_commands` configuration option is enabled, server administrators may run certain commands in public rooms by prefixing them with a single backslash. These commands will only run on _their_ homeserver, even if they are a member of another homeserver's admin room. Some sensitive commands cannot be used outside the admin room and will return an error.
|
||||||
* All commands listed here may be used in the server's console, if it is enabled. Commands entered in the console do not require the `!admin` prefix.
|
* All commands listed here may be used in the server's console, if it is enabled. Commands entered in the console do not require the `!admin` prefix. If Continuwuity is deployed via Docker, be sure to set the appropriate options detailed in [the Docker deployment guide](../../deploying/docker.mdx#accessing-the-servers-console) to enable access to the server's console.
|
||||||
|
|
||||||
## Categories
|
## Categories
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -20,7 +20,11 @@ export default defineConfig({
|
|||||||
'/deploying/docker-compose.for-traefik.yml',
|
'/deploying/docker-compose.for-traefik.yml',
|
||||||
'/deploying/docker-compose.with-traefik.yml',
|
'/deploying/docker-compose.with-traefik.yml',
|
||||||
`/deploying/docker-compose.override.yml`,
|
`/deploying/docker-compose.override.yml`,
|
||||||
`/deploying/docker-compose.yml`
|
`/deploying/docker-compose.yml`,
|
||||||
|
'/advanced/delegated.docker-compose.with-caddy.yml',
|
||||||
|
'/advanced/delegated.docker-compose.with-caddy-labels.yml',
|
||||||
|
'/advanced/delegated.docker-compose.for-traefik.yml',
|
||||||
|
'/advanced/delegated.docker-compose.with-traefik.yml',
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ 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.stream().collect::<Vec<_>>().await;
|
let users = self.services.users.iter().collect::<Vec<_>>().await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|
||||||
let total = users.len();
|
let total = users.len();
|
||||||
|
|||||||
+24
-37
@@ -79,14 +79,12 @@ 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, &room_version_rules) {
|
| Ok(value) => match ruma::signatures::reference_hash(&value, &RoomVersionId::V6) {
|
||||||
| 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 = EventId::parse(format!("${hash}"));
|
let event_id = OwnedEventId::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:#?}"),
|
||||||
@@ -121,7 +119,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
|
||||||
@@ -189,7 +187,10 @@ 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.get_remote_pdu(event_id.clone(), server.clone()).await {
|
match self
|
||||||
|
.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
|
||||||
@@ -204,7 +205,7 @@ pub(super) async fn get_remote_pdu_list(&self, server: OwnedServerName, force: b
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.get_remote_pdu(event_id.clone(), server.clone())
|
self.get_remote_pdu(event_id.to_owned(), server.clone())
|
||||||
.await?;
|
.await?;
|
||||||
success_count = success_count.saturating_add(1);
|
success_count = success_count.saturating_add(1);
|
||||||
}
|
}
|
||||||
@@ -236,10 +237,10 @@ pub(super) async fn get_remote_pdu(
|
|||||||
match self
|
match self
|
||||||
.services
|
.services
|
||||||
.sending
|
.sending
|
||||||
.send_federation_request(
|
.send_federation_request(&server, ruma::api::federation::event::get_event::v1::Request {
|
||||||
&server,
|
event_id: event_id.clone(),
|
||||||
ruma::api::federation::event::get_event::v1::Request::new(event_id.clone()),
|
include_unredacted_content: None,
|
||||||
)
|
})
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
@@ -329,9 +330,9 @@ pub(super) async fn ping(&self, server: OwnedServerName) -> Result {
|
|||||||
match self
|
match self
|
||||||
.services
|
.services
|
||||||
.sending
|
.sending
|
||||||
.send_unauthenticated_request(
|
.send_federation_request(
|
||||||
&server,
|
&server,
|
||||||
ruma::api::federation::discovery::get_server_version::v1::Request::new(),
|
ruma::api::federation::discovery::get_server_version::v1::Request {},
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -360,7 +361,7 @@ pub(super) async fn force_device_list_updates(&self) -> Result {
|
|||||||
self.services
|
self.services
|
||||||
.users
|
.users
|
||||||
.stream()
|
.stream()
|
||||||
.for_each(async |user_id| self.services.users.mark_device_key_update(&user_id).await)
|
.for_each(|user_id| self.services.users.mark_device_key_update(user_id))
|
||||||
.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
|
||||||
@@ -429,16 +430,9 @@ 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
|
| Ok(value) => match self.services.server_keys.verify_json(&value, None).await {
|
||||||
.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"),
|
||||||
},
|
},
|
||||||
@@ -451,15 +445,9 @@ 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
|
let msg = match self.services.server_keys.verify_event(&event, None).await {
|
||||||
.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.",
|
||||||
@@ -556,17 +544,16 @@ 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(
|
.send_federation_request(&server_name, get_room_state::v1::Request {
|
||||||
&server_name,
|
room_id: room_id.clone(),
|
||||||
get_room_state::v1::Request::new(at_event_id, room_id.clone()),
|
event_id: at_event_id,
|
||||||
)
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for pdu in remote_state_response.pdus.clone() {
|
for pdu in remote_state_response.pdus.clone() {
|
||||||
@@ -589,7 +576,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_rules)
|
.validate_and_add_event_id(pdu, &room_version)
|
||||||
}) {
|
}) {
|
||||||
let Ok((event_id, value)) = result.await else {
|
let Ok((event_id, value)) = result.await else {
|
||||||
continue;
|
continue;
|
||||||
@@ -621,7 +608,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_rules)
|
.validate_and_add_event_id(pdu, &room_version)
|
||||||
}) {
|
}) {
|
||||||
let Ok((event_id, value)) = result.await else {
|
let Ok((event_id, value)) = result.await else {
|
||||||
continue;
|
continue;
|
||||||
@@ -638,7 +625,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_rules, state)
|
.resolve_state(&room_id, &room_version, 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(async |room_id| get_room_info(self.services, &room_id).await)
|
.then(|room_id| get_room_info(self.services, room_id))
|
||||||
.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,8 +6,7 @@ use conduwuit::{
|
|||||||
warn,
|
warn,
|
||||||
};
|
};
|
||||||
use conduwuit_service::media::Dim;
|
use conduwuit_service::media::Dim;
|
||||||
use ruma::{OwnedEventId, OwnedMxcUri, OwnedServerName};
|
use ruma::{Mxc, 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};
|
||||||
|
|
||||||
@@ -262,7 +261,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +271,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,7 +330,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ use futures::{AsyncWriteExt, future::FutureExt, io::BufWriter};
|
|||||||
use ruma::{
|
use ruma::{
|
||||||
EventId,
|
EventId,
|
||||||
events::{
|
events::{
|
||||||
relation::{InReplyTo, Reply},
|
relation::InReplyTo,
|
||||||
room::message::{Relation, RoomMessageEventContent},
|
room::message::{Relation::Reply, RoomMessageEventContent},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use service::{
|
use service::{
|
||||||
@@ -38,7 +38,6 @@ 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()
|
||||||
@@ -278,8 +277,9 @@ fn reply(
|
|||||||
mut content: RoomMessageEventContent,
|
mut content: RoomMessageEventContent,
|
||||||
reply_id: Option<&EventId>,
|
reply_id: Option<&EventId>,
|
||||||
) -> RoomMessageEventContent {
|
) -> RoomMessageEventContent {
|
||||||
content.relates_to =
|
content.relates_to = reply_id.map(|event_id| Reply {
|
||||||
reply_id.map(|event_id| Relation::Reply(Reply::new(InReplyTo::new(event_id.to_owned()))));
|
in_reply_to: InReplyTo { event_id: 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,6 +41,7 @@ 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();
|
||||||
@@ -53,7 +54,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, alias.to_owned()))
|
.map(|(room_id, alias)| (room_id.to_owned(), alias.to_owned()))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ 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();
|
||||||
@@ -117,6 +118,7 @@ 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();
|
||||||
@@ -133,6 +135,7 @@ 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();
|
||||||
@@ -149,6 +152,7 @@ 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();
|
||||||
@@ -165,6 +169,7 @@ 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();
|
||||||
@@ -207,6 +212,7 @@ 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();
|
||||||
@@ -223,6 +229,7 @@ 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();
|
||||||
@@ -269,6 +276,7 @@ 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,6 +104,7 @@ 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();
|
||||||
@@ -216,7 +217,8 @@ 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(|user_id| String::from_utf8_lossy(user_id.as_bytes()).into_owned())
|
.map(ruma::UserId::as_bytes)
|
||||||
|
.map(String::from_utf8_lossy)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
@@ -252,6 +254,7 @@ 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, RoomAliasId};
|
use ruma::{OwnedRoomAliasId, OwnedRoomId};
|
||||||
|
|
||||||
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 RoomAliasId::parse(room_alias_str) {
|
let room_alias = match OwnedRoomAliasId::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, localpart.into()))
|
.map(|(room_id, localpart)| (room_id.into(), 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(async |room_id| get_room_info(self.services, &room_id).await)
|
.then(|room_id| get_room_info(self.services, room_id))
|
||||||
.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(async |room_id| get_room_info(services, &room_id).await)
|
.then(|room_id| get_room_info(services, room_id))
|
||||||
.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,6 +46,7 @@ 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
|
||||||
@@ -66,7 +67,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.clone()
|
room_id.to_owned()
|
||||||
} 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,6 +116,7 @@ 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();
|
||||||
|
|
||||||
@@ -139,6 +140,7 @@ 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
|
||||||
@@ -203,7 +205,7 @@ async fn ban_list_of_rooms(&self) -> Result {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
room_ids.push(room_id.clone());
|
room_ids.push(room_id.to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
if room_alias_or_id.is_room_alias_id() {
|
if room_alias_or_id.is_room_alias_id() {
|
||||||
@@ -213,7 +215,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,
|
||||||
@@ -227,7 +229,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)) => {
|
||||||
@@ -282,6 +284,7 @@ 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();
|
||||||
|
|
||||||
@@ -306,6 +309,7 @@ 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
|
||||||
@@ -344,9 +348,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.clone()
|
room_id.to_owned()
|
||||||
} 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,
|
||||||
@@ -368,7 +372,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,
|
||||||
@@ -378,7 +382,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,
|
||||||
@@ -449,6 +453,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
|
||||||
}
|
}
|
||||||
@@ -159,8 +159,8 @@ pub(super) async fn list_features(&self) -> Result {
|
|||||||
let mut enabled_features = conduwuit::info::introspection::ENABLED_FEATURES
|
let mut enabled_features = conduwuit::info::introspection::ENABLED_FEATURES
|
||||||
.lock()
|
.lock()
|
||||||
.expect("locked")
|
.expect("locked")
|
||||||
.values()
|
.iter()
|
||||||
.flat_map(|f| f.iter())
|
.flat_map(|(_, f)| f.iter())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
enabled_features.sort_unstable();
|
enabled_features.sort_unstable();
|
||||||
|
|||||||
+63
-55
@@ -9,18 +9,20 @@ use api::client::{
|
|||||||
};
|
};
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, debug_warn, error, info,
|
Err, Result, debug_warn, error, info,
|
||||||
matrix::{Event, pdu::PartialPdu},
|
matrix::{Event, pdu::PduBuilder},
|
||||||
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, ServerName,
|
OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, UserId,
|
||||||
UserId, assign,
|
|
||||||
events::{
|
events::{
|
||||||
RoomAccountDataEventType,
|
RoomAccountDataEventType, StateEventType,
|
||||||
room::{power_levels::RoomPowerLevelsEventContent, redaction::RoomRedactionEventContent},
|
room::{
|
||||||
|
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
|
||||||
|
redaction::RoomRedactionEventContent,
|
||||||
|
},
|
||||||
tag::{TagEvent, TagEventContent, TagInfo},
|
tag::{TagEvent, TagEventContent, TagInfo},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -39,7 +41,7 @@ pub(super) async fn list_users(&self) -> Result {
|
|||||||
.services
|
.services
|
||||||
.users
|
.users
|
||||||
.list_local_users()
|
.list_local_users()
|
||||||
.map(|id| id.as_str().to_owned())
|
.map(ToString::to_string)
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -101,12 +103,11 @@ 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::new(
|
&serde_json::to_value(ruma::events::push_rules::PushRulesEvent {
|
||||||
ruma::events::push_rules::PushRulesEventContent::new(
|
content: ruma::events::push_rules::PushRulesEventContent {
|
||||||
ruma::push::Ruleset::server_default(&user_id),
|
global: ruma::push::Ruleset::server_default(&user_id),
|
||||||
),
|
},
|
||||||
))
|
})?,
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -291,12 +292,7 @@ pub(super) async fn reset_password(
|
|||||||
self.services
|
self.services
|
||||||
.users
|
.users
|
||||||
.all_device_ids(&user_id)
|
.all_device_ids(&user_id)
|
||||||
.for_each(async |device_id| {
|
.for_each(|device_id| self.services.users.remove_device(&user_id, 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?;
|
||||||
}
|
}
|
||||||
@@ -441,7 +437,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(async |room_id| get_room_info(self.services, &room_id).await)
|
.then(|room_id| get_room_info(self.services, room_id))
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -458,7 +454,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,7 +506,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))
|
.ready_any(|user_id| server_admins.contains(&user_id.to_owned()))
|
||||||
.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.",);
|
||||||
@@ -624,7 +620,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))
|
.ready_any(|user_id| server_admins.contains(&user_id.to_owned()))
|
||||||
.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.",);
|
||||||
@@ -637,6 +633,7 @@ 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
|
||||||
{
|
{
|
||||||
@@ -687,7 +684,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -719,7 +716,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -733,34 +730,42 @@ 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.as_str()).await;
|
let state_lock = self.services.rooms.state.mutex.lock(&room_id).await;
|
||||||
|
|
||||||
let mut room_power_levels = self
|
let room_power_levels: Option<RoomPowerLevelsEventContent> = self
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.get_room_power_levels(&room_id)
|
.room_state_get_content(&room_id, &StateEventType::RoomPowerLevels, "")
|
||||||
.await;
|
.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)
|
||||||
|
}) || 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.",);
|
||||||
}
|
}
|
||||||
|
|
||||||
room_power_levels.users.remove(&user_id);
|
let mut power_levels_content = room_power_levels.unwrap_or_default();
|
||||||
|
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(
|
||||||
PartialPdu::state(
|
PduBuilder::state(String::new(), &power_levels_content),
|
||||||
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,
|
||||||
@@ -788,7 +793,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -806,7 +811,9 @@ 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_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
.unwrap_or(TagEvent {
|
||||||
|
content: TagEventContent { tags: BTreeMap::new() },
|
||||||
|
});
|
||||||
|
|
||||||
tags_event
|
tags_event
|
||||||
.content
|
.content
|
||||||
@@ -843,7 +850,9 @@ 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_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
.unwrap_or(TagEvent {
|
||||||
|
content: TagEventContent { tags: BTreeMap::new() },
|
||||||
|
});
|
||||||
|
|
||||||
tags_event.content.tags.remove(&tag.clone().into());
|
tags_event.content.tags.remove(&tag.clone().into());
|
||||||
|
|
||||||
@@ -873,7 +882,9 @@ 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_else(|_| TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
.unwrap_or(TagEvent {
|
||||||
|
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
|
||||||
@@ -910,19 +921,19 @@ pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result {
|
|||||||
.rooms
|
.rooms
|
||||||
.state
|
.state
|
||||||
.mutex
|
.mutex
|
||||||
.lock(event.room_id_or_hash().as_str())
|
.lock(&event.room_id_or_hash())
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
self.services
|
self.services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu {
|
PduBuilder {
|
||||||
redacts: Some(event.event_id().to_owned()),
|
redacts: Some(event.event_id().to_owned()),
|
||||||
..PartialPdu::timeline(&assign!(RoomRedactionEventContent::new_v1(), {
|
..PduBuilder::timeline(&RoomRedactionEventContent {
|
||||||
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()),
|
||||||
@@ -952,7 +963,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![ServerName::parse(v)?])
|
Some(vec![OwnedServerName::parse(v)?])
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
@@ -965,7 +976,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(ServerName::parse(via)?);
|
vias.insert(OwnedServerName::parse(via)?);
|
||||||
}
|
}
|
||||||
for server in vias_raw {
|
for server in vias_raw {
|
||||||
vias.insert(server);
|
vias.insert(server);
|
||||||
@@ -1040,12 +1051,7 @@ 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(async |device_id| {
|
.for_each(|device_id| self.services.users.remove_device(&user_id, 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
|
||||||
@@ -1123,9 +1129,11 @@ 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 =
|
let user_id = OwnedUserId::parse(format!(
|
||||||
UserId::parse(format!("@{localpart}:{}", self.services.globals.server_name()))
|
"@{localpart}:{}",
|
||||||
.unwrap();
|
self.services.globals.server_name()
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
self.write_str(&format!("{email} belongs to {user_id}."))
|
self.write_str(&format!("{email} belongs to {user_id}."))
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -29,10 +29,6 @@ gzip_compression = [
|
|||||||
"conduwuit-service/gzip_compression",
|
"conduwuit-service/gzip_compression",
|
||||||
"reqwest/gzip",
|
"reqwest/gzip",
|
||||||
]
|
]
|
||||||
http3 = [
|
|
||||||
"conduwuit-core/http3",
|
|
||||||
"conduwuit-service/http3",
|
|
||||||
]
|
|
||||||
io_uring = [
|
io_uring = [
|
||||||
"conduwuit-service/io_uring",
|
"conduwuit-service/io_uring",
|
||||||
]
|
]
|
||||||
@@ -92,9 +88,7 @@ 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,8 +1,10 @@
|
|||||||
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::{OwnedRoomAliasId, events::room::message::RoomMessageEventContent};
|
use ruma::{
|
||||||
use ruminuwuity::admin::continuwuity::rooms;
|
OwnedRoomAliasId, continuwuity_admin_api::rooms,
|
||||||
|
events::room::message::RoomMessageEventContent,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{Ruma, client::leave_room};
|
use crate::{Ruma, client::leave_room};
|
||||||
|
|
||||||
@@ -34,6 +36,7 @@ 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();
|
||||||
@@ -60,9 +63,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)
|
||||||
.collect()
|
.map(ToOwned::to_owned)
|
||||||
|
.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,8 +1,7 @@
|
|||||||
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;
|
use ruma::{OwnedRoomId, continuwuity_admin_api::rooms};
|
||||||
use ruminuwuity::admin::continuwuity::rooms;
|
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
@@ -23,8 +22,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.clone())
|
Some(room_id.to_owned())
|
||||||
} 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::ClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, err, info,
|
Err, Event, Result, err, info,
|
||||||
pdu::PartialPdu,
|
pdu::PduBuilder,
|
||||||
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, UserId,
|
OwnedRoomId, OwnedUserId, UserId,
|
||||||
api::client::{
|
api::client::{
|
||||||
account::{
|
account::{
|
||||||
ThirdPartyIdRemovalStatus, change_password, check_registration_token_validity,
|
ThirdPartyIdRemovalStatus, change_password, check_registration_token_validity,
|
||||||
@@ -18,10 +18,12 @@ use ruma::{
|
|||||||
},
|
},
|
||||||
uiaa::{AuthFlow, AuthType},
|
uiaa::{AuthFlow, AuthType},
|
||||||
},
|
},
|
||||||
assign,
|
events::{
|
||||||
events::room::{
|
StateEventType,
|
||||||
member::{MembershipState, RoomMemberEventContent},
|
room::{
|
||||||
power_levels::RoomPowerLevelsEventContent,
|
member::{MembershipState, RoomMemberEventContent},
|
||||||
|
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use service::{mailer::messages, uiaa::Identity};
|
use service::{mailer::messages, uiaa::Identity};
|
||||||
@@ -46,7 +48,7 @@ pub(crate) mod threepid;
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "register_available", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "register_available", level = "info")]
|
||||||
pub(crate) async fn get_register_available_route(
|
pub(crate) async fn get_register_available_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_username_availability::v3::Request>,
|
body: Ruma<get_username_availability::v3::Request>,
|
||||||
) -> Result<get_username_availability::v3::Response> {
|
) -> Result<get_username_availability::v3::Response> {
|
||||||
// Validate user id
|
// Validate user id
|
||||||
@@ -85,7 +87,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::new(true))
|
Ok(get_username_availability::v3::Response { available: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/account/password`
|
/// # `POST /_matrix/client/r0/account/password`
|
||||||
@@ -108,7 +110,7 @@ pub(crate) async fn get_register_available_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "change_password", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "change_password", level = "info")]
|
||||||
pub(crate) async fn change_password_route(
|
pub(crate) async fn change_password_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<change_password::v3::Request>,
|
body: Ruma<change_password::v3::Request>,
|
||||||
) -> Result<change_password::v3::Response> {
|
) -> Result<change_password::v3::Response> {
|
||||||
let identity = if let Some(ref user_id) = body.sender_user {
|
let identity = if let Some(ref user_id) = body.sender_user {
|
||||||
@@ -141,7 +143,7 @@ pub(crate) async fn change_password_route(
|
|||||||
.await?
|
.await?
|
||||||
};
|
};
|
||||||
|
|
||||||
let sender_user = UserId::parse(format!(
|
let sender_user = OwnedUserId::parse(format!(
|
||||||
"@{}:{}",
|
"@{}:{}",
|
||||||
identity.localpart.expect("localpart should be known"),
|
identity.localpart.expect("localpart should be known"),
|
||||||
services.globals.server_name()
|
services.globals.server_name()
|
||||||
@@ -159,7 +161,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(async |id| services.users.remove_device(&sender_user, &id).await)
|
.for_each(|id| services.users.remove_device(&sender_user, id))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Remove all pushers except the ones associated with this session
|
// Remove all pushers except the ones associated with this session
|
||||||
@@ -173,8 +175,8 @@ pub(crate) async fn change_password_route(
|
|||||||
.get_pusher_device(&pushkey)
|
.get_pusher_device(&pushkey)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.as_ref()
|
.filter(|pusher_device| pusher_device != body.sender_device())
|
||||||
.is_some_and(|pusher_device| pusher_device != body.sender_device())
|
.is_some()
|
||||||
.then_some(pushkey)
|
.then_some(pushkey)
|
||||||
})
|
})
|
||||||
.for_each(async |pushkey| {
|
.for_each(async |pushkey| {
|
||||||
@@ -192,7 +194,7 @@ pub(crate) async fn change_password_route(
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(change_password::v3::Response::new())
|
Ok(change_password::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/v3/account/password/email/requestToken`
|
/// # `POST /_matrix/client/v3/account/password/email/requestToken`
|
||||||
@@ -213,7 +215,7 @@ pub(crate) async fn request_password_change_token_via_email_route(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let user_id =
|
let user_id =
|
||||||
UserId::parse(format!("@{localpart}:{}", services.globals.server_name())).unwrap();
|
OwnedUserId::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
|
||||||
@@ -249,10 +251,11 @@ 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 {
|
||||||
Ok(assign!(whoami::v3::Response::new(body.sender_user().to_owned(), is_guest), {
|
user_id: body.sender_user().to_owned(),
|
||||||
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`
|
||||||
@@ -269,7 +272,7 @@ pub(crate) async fn whoami_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "deactivate", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "deactivate", level = "info")]
|
||||||
pub(crate) async fn deactivate_route(
|
pub(crate) async fn deactivate_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<deactivate::v3::Request>,
|
body: Ruma<deactivate::v3::Request>,
|
||||||
) -> Result<deactivate::v3::Response> {
|
) -> Result<deactivate::v3::Response> {
|
||||||
// Authentication for this endpoint is technically optional,
|
// Authentication for this endpoint is technically optional,
|
||||||
@@ -307,7 +310,9 @@ pub(crate) async fn deactivate_route(
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(deactivate::v3::Response::new(ThirdPartyIdRemovalStatus::Success))
|
Ok(deactivate::v3::Response {
|
||||||
|
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`
|
||||||
@@ -325,7 +330,7 @@ pub(crate) async fn check_registration_token_validity(
|
|||||||
.await
|
.await
|
||||||
.is_some();
|
.is_some();
|
||||||
|
|
||||||
Ok(check_registration_token_validity::v1::Response::new(valid))
|
Ok(check_registration_token_validity::v1::Response { valid })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs through all the deactivation steps:
|
/// Runs through all the deactivation steps:
|
||||||
@@ -349,7 +354,13 @@ pub async fn full_user_deactivate(
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
services.users.clear_profile(user_id).await;
|
services
|
||||||
|
.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
|
||||||
@@ -361,49 +372,62 @@ pub async fn full_user_deactivate(
|
|||||||
|
|
||||||
// TODO: Rescind all user invites
|
// TODO: Rescind all user invites
|
||||||
|
|
||||||
let mut pdu_queue: Vec<(PartialPdu, &OwnedRoomId)> = Vec::new();
|
let mut pdu_queue: Vec<(PduBuilder, &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
|
||||||
.get_room_power_levels(room_id)
|
.room_state_get_content::<RoomPowerLevelsEventContent>(
|
||||||
.await;
|
room_id,
|
||||||
|
&StateEventType::RoomPowerLevels,
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
|
||||||
let user_can_demote_self =
|
let user_can_demote_self =
|
||||||
room_power_levels.user_can_change_user_power_level(user_id, user_id);
|
room_power_levels
|
||||||
|
.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 Ok(mut power_levels_content) =
|
let mut power_levels_content = room_power_levels.unwrap_or_default();
|
||||||
RoomPowerLevelsEventContent::try_from(room_power_levels)
|
|
||||||
{
|
|
||||||
power_levels_content.users.remove(user_id);
|
power_levels_content.users.remove(user_id);
|
||||||
let pl_evt = PartialPdu::state(String::new(), &power_levels_content);
|
let pl_evt = PduBuilder::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((
|
||||||
PartialPdu::state(
|
PduBuilder::state(user_id.to_string(), &RoomMemberEventContent {
|
||||||
user_id.to_string(),
|
avatar_url: None,
|
||||||
&RoomMemberEventContent::new(MembershipState::Leave),
|
blurhash: None,
|
||||||
),
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
for (pdu, room_id) in pdu_queue {
|
super::update_all_rooms(services, pdu_queue, user_id)
|
||||||
let state_lock = services.rooms.state.mutex.lock(room_id.as_str()).await;
|
.boxed()
|
||||||
|
.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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{collections::HashMap, fmt::Write};
|
use std::{collections::HashMap, fmt::Write};
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, debug_info, error, info,
|
Err, Result, debug_info, error, info,
|
||||||
utils::{self},
|
utils::{self},
|
||||||
@@ -20,11 +20,7 @@ use ruma::{
|
|||||||
},
|
},
|
||||||
uiaa::{AuthFlow, AuthType},
|
uiaa::{AuthFlow, AuthType},
|
||||||
},
|
},
|
||||||
assign,
|
events::{GlobalAccountDataEventType, room::message::RoomMessageEventContent},
|
||||||
events::{
|
|
||||||
GlobalAccountDataEventType, push_rules::PushRulesEvent,
|
|
||||||
room::message::RoomMessageEventContent,
|
|
||||||
},
|
|
||||||
push,
|
push,
|
||||||
};
|
};
|
||||||
use serde_json::value::RawValue;
|
use serde_json::value::RawValue;
|
||||||
@@ -56,7 +52,7 @@ const RANDOM_USER_ID_LENGTH: usize = 10;
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "register", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "register", level = "info")]
|
||||||
pub(crate) async fn register_route(
|
pub(crate) async fn register_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<register::v3::Request>,
|
body: Ruma<register::v3::Request>,
|
||||||
) -> Result<register::v3::Response> {
|
) -> Result<register::v3::Response> {
|
||||||
let is_guest = body.kind == RegistrationKind::Guest;
|
let is_guest = body.kind == RegistrationKind::Guest;
|
||||||
@@ -213,15 +209,23 @@ 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(PushRulesEvent::new(
|
&serde_json::to_value(ruma::events::push_rules::PushRulesEvent {
|
||||||
push::Ruleset::server_default(&user_id).into(),
|
content: ruma::events::push_rules::PushRulesEventContent {
|
||||||
))
|
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 (token, device) = if !body.inhibit_login {
|
let no_device = 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());
|
||||||
|
|
||||||
@@ -239,14 +243,12 @@ 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
|
||||||
@@ -391,12 +393,13 @@ pub(crate) async fn register_route(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(assign!(register::v3::Response::new(user_id), {
|
Ok(register::v3::Response {
|
||||||
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
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ pub(crate) async fn request_3pid_management_token_via_email_route(
|
|||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
body: Ruma<request_3pid_management_token_via_email::v3::Request>,
|
body: Ruma<request_3pid_management_token_via_email::v3::Request>,
|
||||||
) -> Result<request_3pid_management_token_via_email::v3::Response> {
|
) -> Result<request_3pid_management_token_via_email::v3::Response> {
|
||||||
|
if !services.threepid.email_requirement().may_change() {
|
||||||
|
return Err!(Request(Forbidden("You may not change your email address.")));
|
||||||
|
}
|
||||||
|
|
||||||
let Ok(email) = Address::try_from(body.email.clone()) else {
|
let Ok(email) = Address::try_from(body.email.clone()) else {
|
||||||
return Err!(Request(InvalidParam("Invalid email address.")));
|
return Err!(Request(InvalidParam("Invalid email address.")));
|
||||||
};
|
};
|
||||||
@@ -105,6 +109,10 @@ pub(crate) async fn add_3pid_route(
|
|||||||
) -> Result<add_3pid::v3::Response> {
|
) -> Result<add_3pid::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
|
|
||||||
|
if !services.threepid.email_requirement().may_change() {
|
||||||
|
return Err!(Request(Forbidden("You may not change your email address.")));
|
||||||
|
}
|
||||||
|
|
||||||
// Require password auth to add an email
|
// Require password auth to add an email
|
||||||
let _ = services
|
let _ = services
|
||||||
.uiaa
|
.uiaa
|
||||||
@@ -133,7 +141,13 @@ 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::new(ThirdPartyIdRemovalStatus::NoSupport));
|
return Ok(delete_3pid::v3::Response {
|
||||||
|
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if !services.threepid.email_requirement().may_remove() {
|
||||||
|
return Err!(Request(Forbidden("You may not remove your email address.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if services
|
if services
|
||||||
@@ -145,5 +159,7 @@ 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::new(ThirdPartyIdRemovalStatus::Success))
|
Ok(delete_3pid::v3::Response {
|
||||||
|
id_server_unbind_result: ThirdPartyIdRemovalStatus::Success,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,10 @@ 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::{AnyGlobalAccountDataEventContent, AnyRoomAccountDataEventContent},
|
events::{
|
||||||
|
AnyGlobalAccountDataEventContent, AnyRoomAccountDataEventContent,
|
||||||
|
RoomAccountDataEventType,
|
||||||
|
},
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -37,7 +40,7 @@ pub(crate) async fn set_global_account_data_route(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(set_global_account_data::v3::Response::new())
|
Ok(set_global_account_data::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
||||||
@@ -62,7 +65,7 @@ pub(crate) async fn set_room_account_data_route(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(set_room_account_data::v3::Response::new())
|
Ok(set_room_account_data::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}`
|
/// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}`
|
||||||
@@ -84,7 +87,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::new(account_data.content))
|
Ok(get_global_account_data::v3::Response { account_data: 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}`
|
||||||
@@ -106,7 +109,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::new(account_data.content))
|
Ok(get_room_account_data::v3::Response { account_data: account_data.content })
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn set_account_data(
|
async fn set_account_data(
|
||||||
@@ -116,7 +119,7 @@ async fn set_account_data(
|
|||||||
event_type_s: &str,
|
event_type_s: &str,
|
||||||
data: &RawJsonValue,
|
data: &RawJsonValue,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
if event_type_s == "m.fully_read" {
|
if event_type_s == RoomAccountDataEventType::FullyRead.to_cow_str() {
|
||||||
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 ruminuwuity::admin::{get_suspended, set_suspended};
|
use ruma::api::client::admin::{get_suspended, set_suspended};
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result, err};
|
use conduwuit::{Err, Result, err};
|
||||||
use ruma::{
|
use ruma::api::{appservice::ping, client::appservice::request_ping};
|
||||||
api::{appservice::ping, client::appservice::request_ping},
|
|
||||||
assign,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
@@ -43,12 +40,12 @@ pub(crate) async fn appservice_ping(
|
|||||||
.sending
|
.sending
|
||||||
.send_appservice_request(
|
.send_appservice_request(
|
||||||
appservice_info.registration.clone(),
|
appservice_info.registration.clone(),
|
||||||
assign!(ping::send_ping::v1::Request::new(), {
|
ping::send_ping::v1::Request {
|
||||||
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::new(timer.elapsed()))
|
Ok(request_ping::v1::Response { duration: timer.elapsed() })
|
||||||
}
|
}
|
||||||
+33
-29
@@ -3,6 +3,7 @@ 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::{
|
||||||
@@ -27,7 +28,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::new(version))
|
Ok(create_backup_version::v3::Response { version })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/version/{version}`
|
/// # `PUT /_matrix/client/r0/room_keys/version/{version}`
|
||||||
@@ -43,7 +44,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::new())
|
Ok(update_backup_version::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/version`
|
/// # `GET /_matrix/client/r0/room_keys/version`
|
||||||
@@ -59,9 +60,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::new(algorithm, count, etag, version))
|
Ok(get_latest_backup_info::v3::Response { algorithm, count, etag, version })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/v3/room_keys/version/{version}`
|
/// # `GET /_matrix/client/v3/room_keys/version/{version}`
|
||||||
@@ -79,9 +80,14 @@ 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::new(algorithm, count, etag, body.version.clone()))
|
Ok(get_backup_info::v3::Response {
|
||||||
|
algorithm,
|
||||||
|
count,
|
||||||
|
etag,
|
||||||
|
version: body.version.clone(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/version/{version}`
|
/// # `DELETE /_matrix/client/r0/room_keys/version/{version}`
|
||||||
@@ -99,7 +105,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::new())
|
Ok(delete_backup_version::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/keys`
|
/// # `PUT /_matrix/client/r0/room_keys/keys`
|
||||||
@@ -134,9 +140,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::new(etag, count))
|
Ok(add_backup_keys::v3::Response { count, etag })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}`
|
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}`
|
||||||
@@ -169,9 +175,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::new(etag, count))
|
Ok(add_backup_keys_for_room::v3::Response { count, etag })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
||||||
@@ -269,9 +275,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::new(etag, count))
|
Ok(add_backup_keys_for_session::v3::Response { count, etag })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/keys`
|
/// # `GET /_matrix/client/r0/room_keys/keys`
|
||||||
@@ -286,7 +292,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::new(rooms))
|
Ok(get_backup_keys::v3::Response { rooms })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}`
|
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}`
|
||||||
@@ -301,7 +307,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::new(sessions))
|
Ok(get_backup_keys_for_room::v3::Response { sessions })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
||||||
@@ -319,7 +325,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::new(key_data))
|
Ok(get_backup_keys_for_session::v3::Response { key_data })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/keys`
|
/// # `DELETE /_matrix/client/r0/room_keys/keys`
|
||||||
@@ -334,9 +340,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::new(etag, count))
|
Ok(delete_backup_keys::v3::Response { count, etag })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}`
|
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}`
|
||||||
@@ -351,9 +357,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::new(etag, count))
|
Ok(delete_backup_keys_for_room::v3::Response { count, etag })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
||||||
@@ -368,24 +374,22 @@ 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::new(etag, count))
|
Ok(delete_backup_keys_for_session::v3::Response { count, etag })
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_count_etag(
|
async fn get_count_etag(
|
||||||
services: &Services,
|
services: &Services,
|
||||||
sender_user: &UserId,
|
sender_user: &UserId,
|
||||||
version: &str,
|
version: &str,
|
||||||
) -> (UInt, String) {
|
) -> Result<(UInt, String)> {
|
||||||
let count: UInt = services
|
let count = services
|
||||||
.key_backups
|
.key_backups
|
||||||
.count_keys(sender_user, version)
|
.count_keys(sender_user, version)
|
||||||
.await
|
.map(TryInto::try_into);
|
||||||
.try_into()
|
|
||||||
.expect("number of keys should fit into a UInt");
|
|
||||||
|
|
||||||
let etag = services.key_backups.get_etag(sender_user, version).await;
|
let etag = services.key_backups.get_etag(sender_user, version).map(Ok);
|
||||||
|
|
||||||
(count, etag)
|
Ok(try_join(count, etag).await?)
|
||||||
}
|
}
|
||||||
@@ -5,11 +5,8 @@ use conduwuit::{Result, Server};
|
|||||||
use ruma::{
|
use ruma::{
|
||||||
RoomVersionId,
|
RoomVersionId,
|
||||||
api::client::discovery::get_capabilities::{
|
api::client::discovery::get_capabilities::{
|
||||||
self,
|
self, Capabilities, GetLoginTokenCapability, RoomVersionStability,
|
||||||
v3::{
|
RoomVersionsCapability, ThirdPartyIdChangesCapability,
|
||||||
Capabilities, GetLoginTokenCapability, RoomVersionStability, RoomVersionsCapability,
|
|
||||||
ThirdPartyIdChangesCapability,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@@ -28,17 +25,19 @@ 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::new(
|
capabilities.room_versions = RoomVersionsCapability {
|
||||||
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 =
|
capabilities.thirdparty_id_changes = ThirdPartyIdChangesCapability {
|
||||||
ThirdPartyIdChangesCapability::new(services.mailer.mailer().is_some());
|
enabled: services.threepid.email_requirement().may_change(),
|
||||||
|
};
|
||||||
|
|
||||||
capabilities.get_login_token =
|
capabilities.get_login_token = GetLoginTokenCapability {
|
||||||
GetLoginTokenCapability::new(services.server.config.login_via_existing_session);
|
enabled: 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}))?;
|
||||||
@@ -57,5 +56,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::new(capabilities))
|
Ok(get_capabilities::v3::Response { capabilities })
|
||||||
}
|
}
|
||||||
@@ -12,9 +12,7 @@ use futures::{
|
|||||||
FutureExt, StreamExt, TryFutureExt, TryStreamExt,
|
FutureExt, StreamExt, TryFutureExt, TryStreamExt,
|
||||||
future::{OptionFuture, join, join3, try_join3},
|
future::{OptionFuture, join, join3, try_join3},
|
||||||
};
|
};
|
||||||
use ruma::{
|
use ruma::{OwnedEventId, UserId, api::client::context::get_context, events::StateEventType};
|
||||||
OwnedEventId, UserId, api::client::context::get_context, assign, events::StateEventType,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Ruma,
|
Ruma,
|
||||||
@@ -215,7 +213,7 @@ pub(crate) async fn get_context_route(
|
|||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(assign!(get_context::v3::Response::new(), {
|
Ok(get_context::v3::Response {
|
||||||
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
|
||||||
@@ -245,5 +243,5 @@ pub(crate) async fn get_context_route(
|
|||||||
.collect(),
|
.collect(),
|
||||||
|
|
||||||
state,
|
state,
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{Err, Result, at};
|
use conduwuit::{Err, Result, at};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::{
|
use ruma::api::client::dehydrated_device::{
|
||||||
api::client::dehydrated_device::{
|
delete_dehydrated_device::unstable as delete_dehydrated_device,
|
||||||
delete_dehydrated_device::unstable as delete_dehydrated_device,
|
get_dehydrated_device::unstable as get_dehydrated_device, get_events::unstable as get_events,
|
||||||
get_dehydrated_device::unstable as get_dehydrated_device,
|
put_dehydrated_device::unstable as put_dehydrated_device,
|
||||||
get_events::unstable as get_events,
|
|
||||||
put_dehydrated_device::unstable as put_dehydrated_device,
|
|
||||||
},
|
|
||||||
assign,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
@@ -22,7 +18,7 @@ const MAX_BATCH_EVENTS: usize = 50;
|
|||||||
#[tracing::instrument(skip_all, fields(%client))]
|
#[tracing::instrument(skip_all, fields(%client))]
|
||||||
pub(crate) async fn put_dehydrated_device_route(
|
pub(crate) async fn put_dehydrated_device_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<put_dehydrated_device::Request>,
|
body: Ruma<put_dehydrated_device::Request>,
|
||||||
) -> Result<put_dehydrated_device::Response> {
|
) -> Result<put_dehydrated_device::Response> {
|
||||||
let sender_user = body
|
let sender_user = body
|
||||||
@@ -37,7 +33,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::new(device_id))
|
Ok(put_dehydrated_device::Response { device_id })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/../dehydrated_device`
|
/// # `DELETE /_matrix/client/../dehydrated_device`
|
||||||
@@ -46,7 +42,7 @@ pub(crate) async fn put_dehydrated_device_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client))]
|
#[tracing::instrument(skip_all, fields(%client))]
|
||||||
pub(crate) async fn delete_dehydrated_device_route(
|
pub(crate) async fn delete_dehydrated_device_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<delete_dehydrated_device::Request>,
|
body: Ruma<delete_dehydrated_device::Request>,
|
||||||
) -> Result<delete_dehydrated_device::Response> {
|
) -> Result<delete_dehydrated_device::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -55,7 +51,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::new(device_id))
|
Ok(delete_dehydrated_device::Response { device_id })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/../dehydrated_device`
|
/// # `GET /_matrix/client/../dehydrated_device`
|
||||||
@@ -64,14 +60,17 @@ pub(crate) async fn delete_dehydrated_device_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client))]
|
#[tracing::instrument(skip_all, fields(%client))]
|
||||||
pub(crate) async fn get_dehydrated_device_route(
|
pub(crate) async fn get_dehydrated_device_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_dehydrated_device::Request>,
|
body: Ruma<get_dehydrated_device::Request>,
|
||||||
) -> Result<get_dehydrated_device::Response> {
|
) -> Result<get_dehydrated_device::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
|
|
||||||
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::new(device.device_id, device.device_data))
|
Ok(get_dehydrated_device::Response {
|
||||||
|
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`
|
||||||
@@ -80,7 +79,7 @@ pub(crate) async fn get_dehydrated_device_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client))]
|
#[tracing::instrument(skip_all, fields(%client))]
|
||||||
pub(crate) async fn get_dehydrated_events_route(
|
pub(crate) async fn get_dehydrated_events_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_events::Request>,
|
body: Ruma<get_events::Request>,
|
||||||
) -> Result<get_events::Response> {
|
) -> Result<get_events::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -115,7 +114,8 @@ pub(crate) async fn get_dehydrated_events_route(
|
|||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(assign!(get_events::Response::new(events), {
|
Ok(get_events::Response {
|
||||||
|
events,
|
||||||
next_batch: next_batch.as_ref().map(ToString::to_string),
|
next_batch: next_batch.as_ref().map(ToString::to_string),
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
+48
-25
@@ -1,5 +1,5 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{Err, Result, debug, err, utils};
|
use conduwuit::{Err, Result, debug, err, utils};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
@@ -25,7 +25,7 @@ pub(crate) async fn get_devices_route(
|
|||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(get_devices::v3::Response::new(devices))
|
Ok(get_devices::v3::Response { 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::new(device))
|
Ok(get_device::v3::Response { device })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
|
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
|
||||||
@@ -50,7 +50,7 @@ pub(crate) async fn get_device_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "update_device", level = "debug")]
|
#[tracing::instrument(skip_all, fields(%client), name = "update_device", level = "debug")]
|
||||||
pub(crate) async fn update_device_route(
|
pub(crate) async fn update_device_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<update_device::v3::Request>,
|
body: Ruma<update_device::v3::Request>,
|
||||||
) -> Result<update_device::v3::Response> {
|
) -> Result<update_device::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -73,16 +73,19 @@ 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::new())
|
Ok(update_device::v3::Response {})
|
||||||
},
|
},
|
||||||
| 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 device ID does not \
|
"Creating new device for {sender_user} from appservice {} as MSC4190 is enabled \
|
||||||
exist",
|
and device ID does not exist",
|
||||||
appservice.registration.id
|
appservice.registration.id
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -99,7 +102,7 @@ pub(crate) async fn update_device_route(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(update_device::v3::Response::new());
|
return Ok(update_device::v3::Response {});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,28 +124,39 @@ 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();
|
||||||
|
|
||||||
// Appservices get to skip UIAA for this endpoint
|
if appservice.is_some_and(|appservice| appservice.registration.device_management) {
|
||||||
if appservice.is_none() {
|
debug!(
|
||||||
// Prompt the user to confirm with their password using UIAA
|
"Skipping UIAA for {sender_user} as this is from an appservice and MSC4190 is \
|
||||||
let _ = services
|
enabled"
|
||||||
.uiaa
|
);
|
||||||
.authenticate_password(&body.auth, Some(Identity::from_user_id(sender_user)))
|
services
|
||||||
.await?;
|
.users
|
||||||
|
.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::new())
|
Ok(delete_device::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `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.
|
/// - Requires UIAA to verify user password unless from an appservice with
|
||||||
|
/// MSC4190 enabled.
|
||||||
///
|
///
|
||||||
/// For each device:
|
/// For each device:
|
||||||
/// - Invalidates access token
|
/// - Invalidates access token
|
||||||
@@ -157,18 +171,27 @@ 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();
|
||||||
|
|
||||||
// Appservices get to skip UIAA for this endpoint
|
if appservice.is_some_and(|appservice| appservice.registration.device_management) {
|
||||||
if appservice.is_none() {
|
debug!(
|
||||||
// Prompt the user to confirm with their password using UIAA
|
"Skipping UIAA for {sender_user} as this is from an appservice and MSC4190 is \
|
||||||
let _ = services
|
enabled"
|
||||||
.uiaa
|
);
|
||||||
.authenticate_password(&body.auth, Some(Identity::from_user_id(sender_user)))
|
for device_id in &body.devices {
|
||||||
.await?;
|
services.users.remove_device(sender_user, device_id).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::new())
|
Ok(delete_devices::v3::Response {})
|
||||||
}
|
}
|
||||||
+144
-54
@@ -1,16 +1,23 @@
|
|||||||
|
use std::iter::once;
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, err, info,
|
Err, Event, Result, RoomVersion, 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::StreamExt;
|
use futures::{
|
||||||
|
FutureExt, StreamExt, TryFutureExt,
|
||||||
|
future::{join, join4, join5},
|
||||||
|
};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
RoomId, ServerName, UInt, UserId,
|
OwnedRoomId, RoomId, ServerName, UInt, UserId,
|
||||||
api::{
|
api::{
|
||||||
client::{
|
client::{
|
||||||
directory::{
|
directory::{
|
||||||
@@ -21,9 +28,15 @@ use ruma::{
|
|||||||
},
|
},
|
||||||
federation,
|
federation,
|
||||||
},
|
},
|
||||||
assign,
|
directory::{Filter, PublicRoomJoinRule, PublicRoomsChunk, RoomNetwork, RoomTypeFilter},
|
||||||
directory::{Filter, PublicRoomsChunk, RoomNetwork, RoomTypeFilter},
|
events::{
|
||||||
events::StateEventType,
|
StateEventType,
|
||||||
|
room::{
|
||||||
|
create::RoomCreateEventContent,
|
||||||
|
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||||
|
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
|
||||||
|
},
|
||||||
|
},
|
||||||
uint,
|
uint,
|
||||||
};
|
};
|
||||||
use tokio::join;
|
use tokio::join;
|
||||||
@@ -38,7 +51,7 @@ use crate::Ruma;
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "publicrooms", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "publicrooms", level = "info")]
|
||||||
pub(crate) async fn get_public_rooms_filtered_route(
|
pub(crate) async fn get_public_rooms_filtered_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_public_rooms_filtered::v3::Request>,
|
body: Ruma<get_public_rooms_filtered::v3::Request>,
|
||||||
) -> Result<get_public_rooms_filtered::v3::Response> {
|
) -> Result<get_public_rooms_filtered::v3::Response> {
|
||||||
if let Some(server) = &body.server {
|
if let Some(server) = &body.server {
|
||||||
@@ -74,7 +87,7 @@ pub(crate) async fn get_public_rooms_filtered_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "publicrooms", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "publicrooms", level = "info")]
|
||||||
pub(crate) async fn get_public_rooms_route(
|
pub(crate) async fn get_public_rooms_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_public_rooms::v3::Request>,
|
body: Ruma<get_public_rooms::v3::Request>,
|
||||||
) -> Result<get_public_rooms::v3::Response> {
|
) -> Result<get_public_rooms::v3::Response> {
|
||||||
if let Some(server) = &body.server {
|
if let Some(server) = &body.server {
|
||||||
@@ -96,11 +109,12 @@ 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(assign!(get_public_rooms::v3::Response::new(response.chunk), {
|
Ok(get_public_rooms::v3::Response {
|
||||||
|
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}`
|
||||||
@@ -109,7 +123,7 @@ pub(crate) async fn get_public_rooms_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "room_directory", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "room_directory", level = "info")]
|
||||||
pub(crate) async fn set_room_visibility_route(
|
pub(crate) async fn set_room_visibility_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<set_room_visibility::v3::Request>,
|
body: Ruma<set_room_visibility::v3::Request>,
|
||||||
) -> Result<set_room_visibility::v3::Response> {
|
) -> Result<set_room_visibility::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -183,7 +197,7 @@ pub(crate) async fn set_room_visibility_route(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(set_room_visibility::v3::Response::new())
|
Ok(set_room_visibility::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/directory/list/room/{roomId}`
|
/// # `GET /_matrix/client/r0/directory/list/room/{roomId}`
|
||||||
@@ -198,13 +212,13 @@ pub(crate) async fn get_room_visibility_route(
|
|||||||
return Err!(Request(NotFound("Room not found")));
|
return Err!(Request(NotFound("Room not found")));
|
||||||
}
|
}
|
||||||
|
|
||||||
let visibility = if services.rooms.directory.is_public_room(&body.room_id).await {
|
Ok(get_room_visibility::v3::Response {
|
||||||
room::Visibility::Public
|
visibility: if services.rooms.directory.is_public_room(&body.room_id).await {
|
||||||
} else {
|
room::Visibility::Public
|
||||||
room::Visibility::Private
|
} else {
|
||||||
};
|
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(
|
||||||
@@ -222,24 +236,24 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||||||
.sending
|
.sending
|
||||||
.send_federation_request(
|
.send_federation_request(
|
||||||
other_server,
|
other_server,
|
||||||
assign!(federation::directory::get_public_rooms_filtered::v1::Request::new(), {
|
federation::directory::get_public_rooms_filtered::v1::Request {
|
||||||
limit,
|
limit,
|
||||||
since: since.map(ToOwned::to_owned),
|
since: since.map(ToOwned::to_owned),
|
||||||
filter: assign!(Filter::new(), {
|
filter: Filter {
|
||||||
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(assign!(get_public_rooms_filtered::v3::Response::new(), {
|
return Ok(get_public_rooms_filtered::v3::Response {
|
||||||
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
|
||||||
@@ -270,24 +284,16 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||||||
.rooms
|
.rooms
|
||||||
.directory
|
.directory
|
||||||
.public_rooms()
|
.public_rooms()
|
||||||
.wide_then(async |room_id| {
|
.map(ToOwned::to_owned)
|
||||||
let summary = services
|
.wide_then(|room_id| public_rooms_chunk(services, room_id))
|
||||||
.rooms
|
.ready_filter_map(|chunk| {
|
||||||
.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.to_lowercase().contains(&query) {
|
if name.as_str().to_lowercase().contains(&query) {
|
||||||
return Some(chunk);
|
return Some(chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,7 +320,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
all_rooms.sort_by_key(|r| std::cmp::Reverse(r.num_joined_members));
|
all_rooms.sort_by(|l, r| r.num_joined_members.cmp(&l.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))
|
||||||
@@ -329,12 +335,12 @@ 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(assign!(get_public_rooms_filtered::v3::Response::new(), {
|
Ok(get_public_rooms_filtered::v3::Response {
|
||||||
chunk,
|
chunk,
|
||||||
prev_batch,
|
prev_batch,
|
||||||
next_batch,
|
next_batch,
|
||||||
total_room_count_estimate,
|
total_room_count_estimate,
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks whether the given user ID is allowed to publish the target room to
|
/// Checks whether the given user ID is allowed to publish the target room to
|
||||||
@@ -350,25 +356,109 @@ async fn user_can_publish_room(
|
|||||||
// Server admins can always publish to their own room directory.
|
// Server admins can always publish to their own room directory.
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
let (create_event, room_version, power_levels_content) = join!(
|
||||||
let (room_version, room_creators, power_levels) = join!(
|
services
|
||||||
|
.rooms
|
||||||
|
.state_accessor
|
||||||
|
.room_state_get(room_id, &StateEventType::RoomCreate, ""),
|
||||||
services.rooms.state.get_room_version(room_id),
|
services.rooms.state.get_room_version(room_id),
|
||||||
services.rooms.state_accessor.get_room_creators(room_id),
|
services
|
||||||
services.rooms.state_accessor.get_room_power_levels(room_id),
|
.rooms
|
||||||
|
.state_accessor
|
||||||
|
.room_state_get_content::<RoomPowerLevelsEventContent>(
|
||||||
|
room_id,
|
||||||
|
&StateEventType::RoomPowerLevels,
|
||||||
|
""
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
let room_version = room_version
|
let room_version = room_version
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(|_| err!(Request(NotFound("Unknown room"))))?;
|
.map_err(|_| err!(Request(NotFound("Unknown room"))))?;
|
||||||
let room_version_rules = room_version.rules().unwrap();
|
let create_event = create_event.map_err(|_| err!(Request(NotFound("Unknown room"))))?;
|
||||||
|
if RoomVersion::new(room_version)
|
||||||
if room_version_rules
|
.expect("room version must be supported")
|
||||||
.authorization
|
|
||||||
.explicitly_privilege_room_creators
|
.explicitly_privilege_room_creators
|
||||||
&& room_creators.contains(user_id)
|
|
||||||
{
|
{
|
||||||
return Ok(true);
|
let create_content: RoomCreateEventContent =
|
||||||
|
serde_json::from_str(create_event.content().get())
|
||||||
|
.map_err(|_| err!(Database("Invalid event content for m.room.create")))?;
|
||||||
|
let is_creator = create_content
|
||||||
|
.additional_creators
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into_iter()
|
||||||
|
.chain(once(create_event.sender().to_owned()))
|
||||||
|
.any(|sender| sender == user_id);
|
||||||
|
if is_creator {
|
||||||
|
return Ok(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match power_levels_content.map(RoomPowerLevels::from) {
|
||||||
|
| Ok(pl) => Ok(pl.user_can_send_state(user_id, StateEventType::RoomCanonicalAlias)),
|
||||||
|
| Err(e) =>
|
||||||
|
if e.is_not_found() {
|
||||||
|
Ok(create_event.sender() == user_id)
|
||||||
|
} else {
|
||||||
|
Err!(Database("Invalid event content for m.room.power_levels: {e}"))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
|
||||||
}
|
}
|
||||||
+118
-78
@@ -5,23 +5,25 @@ use std::{
|
|||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, debug, debug_warn, err,
|
Err, Error, Result, debug, debug_warn, err,
|
||||||
result::FlatOk,
|
result::NotFound,
|
||||||
utils::{IterStream, TryFutureExtExt, stream::WidebandExt},
|
utils::{IterStream, stream::WidebandExt},
|
||||||
};
|
};
|
||||||
use conduwuit_service::{Services, users::parse_master_key};
|
use conduwuit_service::{Services, users::parse_master_key};
|
||||||
use futures::{StreamExt, stream::FuturesUnordered};
|
use futures::{StreamExt, stream::FuturesUnordered};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId,
|
OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId,
|
||||||
api::{
|
api::{
|
||||||
client::keys::{
|
client::{
|
||||||
claim_keys, get_key_changes, get_keys, upload_keys,
|
error::ErrorKind,
|
||||||
upload_signatures::{self},
|
keys::{
|
||||||
upload_signing_keys,
|
claim_keys, get_key_changes, get_keys, upload_keys,
|
||||||
|
upload_signatures::{self},
|
||||||
|
upload_signing_keys,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
federation,
|
federation,
|
||||||
},
|
},
|
||||||
assign,
|
|
||||||
encryption::CrossSigningKey,
|
encryption::CrossSigningKey,
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
};
|
};
|
||||||
@@ -113,12 +115,12 @@ pub(crate) async fn upload_keys_route(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let one_time_key_counts = services
|
Ok(upload_keys::v3::Response {
|
||||||
.users
|
one_time_key_counts: services
|
||||||
.count_one_time_keys(sender_user, sender_device)
|
.users
|
||||||
.await;
|
.count_one_time_keys(sender_user, sender_device)
|
||||||
|
.await,
|
||||||
Ok(upload_keys::v3::Response::new(one_time_key_counts))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/query`
|
/// # `POST /_matrix/client/r0/keys/query`
|
||||||
@@ -172,7 +174,7 @@ pub(crate) async fn upload_signing_keys_route(
|
|||||||
) -> Result<upload_signing_keys::v3::Response> {
|
) -> Result<upload_signing_keys::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
|
|
||||||
if uiaa_needed_to_upload_keys(
|
match check_for_new_keys(
|
||||||
services,
|
services,
|
||||||
sender_user,
|
sender_user,
|
||||||
body.self_signing_key.as_ref(),
|
body.self_signing_key.as_ref(),
|
||||||
@@ -180,11 +182,25 @@ pub(crate) async fn upload_signing_keys_route(
|
|||||||
body.master_key.as_ref(),
|
body.master_key.as_ref(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
.inspect_err(|e| debug!(?e))
|
||||||
{
|
{
|
||||||
let _ = services
|
| Ok(exists) => {
|
||||||
.uiaa
|
if let Some(result) = exists {
|
||||||
.authenticate_password(&body.auth, Some(Identity::from_user_id(sender_user)))
|
// No-op, they tried to reupload the same set of keys
|
||||||
.await?;
|
// (lost connection for example)
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
debug!(
|
||||||
|
"Skipping UIA in accordance with MSC3967, the user didn't have any existing keys"
|
||||||
|
);
|
||||||
|
// Some of the keys weren't found, so we let them upload
|
||||||
|
},
|
||||||
|
| _ => {
|
||||||
|
let _ = services
|
||||||
|
.uiaa
|
||||||
|
.authenticate_password(&body.auth, Some(Identity::from_user_id(sender_user)))
|
||||||
|
.await?;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
services
|
services
|
||||||
@@ -198,56 +214,77 @@ pub(crate) async fn upload_signing_keys_route(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(upload_signing_keys::v3::Response::new())
|
Ok(upload_signing_keys::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn uiaa_needed_to_upload_keys(
|
async fn check_for_new_keys(
|
||||||
services: crate::State,
|
services: crate::State,
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
self_signing_key: Option<&Raw<CrossSigningKey>>,
|
self_signing_key: Option<&Raw<CrossSigningKey>>,
|
||||||
user_signing_key: Option<&Raw<CrossSigningKey>>,
|
user_signing_key: Option<&Raw<CrossSigningKey>>,
|
||||||
master_signing_key: Option<&Raw<CrossSigningKey>>,
|
master_signing_key: Option<&Raw<CrossSigningKey>>,
|
||||||
) -> bool {
|
) -> Result<Option<upload_signing_keys::v3::Response>> {
|
||||||
let (self_signing_key, user_signing_key, master_signing_key) = (
|
debug!("checking for existing keys");
|
||||||
self_signing_key.map(Raw::deserialize).flat_ok(),
|
let mut empty = false;
|
||||||
user_signing_key.map(Raw::deserialize).flat_ok(),
|
if let Some(master_signing_key) = master_signing_key {
|
||||||
master_signing_key.map(Raw::deserialize).flat_ok(),
|
let (key, value) = parse_master_key(user_id, master_signing_key)?;
|
||||||
);
|
let result = services
|
||||||
|
.users
|
||||||
let (existing_self_signing_key, existing_user_signing_key, existing_master_signing_key) = futures::join!(
|
.get_master_key(None, user_id, &|_| true)
|
||||||
services
|
.await;
|
||||||
|
if result.is_not_found() {
|
||||||
|
empty = true;
|
||||||
|
} else {
|
||||||
|
let existing_master_key = result?;
|
||||||
|
let (existing_key, existing_value) = parse_master_key(user_id, &existing_master_key)?;
|
||||||
|
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 {
|
||||||
|
let key = services.users.get_user_signing_key(user_id).await;
|
||||||
|
if key.is_not_found() && !empty {
|
||||||
|
return Err!(Request(Forbidden(
|
||||||
|
"Tried to update an existing user signing key, UIA required"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if !key.is_not_found() {
|
||||||
|
let existing_signing_key = key?.deserialize()?;
|
||||||
|
if existing_signing_key != user_signing_key.deserialize()? {
|
||||||
|
return Err!(Request(Forbidden(
|
||||||
|
"Tried to change an existing user signing key, UIA required"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(self_signing_key) = self_signing_key {
|
||||||
|
let key = services
|
||||||
.users
|
.users
|
||||||
.get_self_signing_key(None, user_id, &|_| true)
|
.get_self_signing_key(None, user_id, &|_| true)
|
||||||
.ok(),
|
.await;
|
||||||
services.users.get_user_signing_key(user_id).ok(),
|
if key.is_not_found() && !empty {
|
||||||
services.users.get_master_key(None, user_id, &|_| true).ok(),
|
debug!(?key);
|
||||||
);
|
return Err!(Request(Forbidden(
|
||||||
|
"Tried to add a new signing key independently from the master key"
|
||||||
let (existing_self_signing_key, existing_user_signing_key, existing_master_signing_key) = (
|
)));
|
||||||
existing_self_signing_key
|
}
|
||||||
.as_ref()
|
if !key.is_not_found() {
|
||||||
.map(Raw::deserialize)
|
let existing_signing_key = key?.deserialize()?;
|
||||||
.flat_ok(),
|
if existing_signing_key != self_signing_key.deserialize()? {
|
||||||
existing_user_signing_key
|
return Err!(Request(Forbidden(
|
||||||
.as_ref()
|
"Tried to update an existing self signing key, UIA required"
|
||||||
.map(Raw::deserialize)
|
)));
|
||||||
.flat_ok(),
|
}
|
||||||
existing_master_signing_key
|
}
|
||||||
.as_ref()
|
|
||||||
.map(Raw::deserialize)
|
|
||||||
.flat_ok(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(existing_master_signing_key) = existing_master_signing_key {
|
|
||||||
// If a master key exists, UIAA is required if any of the keys are different.
|
|
||||||
|
|
||||||
master_signing_key != Some(existing_master_signing_key)
|
|
||||||
|| user_signing_key != existing_user_signing_key
|
|
||||||
|| self_signing_key != existing_self_signing_key
|
|
||||||
} else {
|
|
||||||
// If no master key exists, UIAA is not required.
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
if empty {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Some(upload_signing_keys::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/signatures/upload`
|
/// # `POST /_matrix/client/r0/keys/signatures/upload`
|
||||||
@@ -306,7 +343,7 @@ pub(crate) async fn upload_signatures_route(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(upload_signatures::v3::Response::new())
|
Ok(upload_signatures::v3::Response { failures: BTreeMap::new() })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/changes`
|
/// # `POST /_matrix/client/r0/keys/changes`
|
||||||
@@ -326,17 +363,18 @@ pub(crate) async fn get_key_changes_route(
|
|||||||
let from = body
|
let from = body
|
||||||
.from
|
.from
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| err!(Request(InvalidParam("Invalid `from`."))))?;
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from`."))?;
|
||||||
|
|
||||||
let to = body
|
let to = body
|
||||||
.to
|
.to
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| err!(Request(InvalidParam("Invalid `to`."))))?;
|
.map_err(|_| Error::BadRequest(ErrorKind::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,
|
||||||
);
|
);
|
||||||
@@ -347,18 +385,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::new(
|
Ok(get_key_changes::v3::Response {
|
||||||
device_list_updates.into_iter().collect(),
|
changed: device_list_updates.into_iter().collect(),
|
||||||
// TODO
|
left: Vec::new(), // TODO
|
||||||
vec![],
|
})
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_keys_helper<F>(
|
pub(crate) async fn get_keys_helper<F>(
|
||||||
@@ -395,10 +433,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."))
|
||||||
@@ -407,7 +445,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.clone(), keys);
|
container.insert(device_id.to_owned(), keys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,7 +506,8 @@ 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 = federation::keys::get_keys::v1::Request::new(device_keys_input_fed);
|
let request =
|
||||||
|
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),
|
||||||
@@ -522,13 +561,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(assign!(get_keys::v3::Response::new(), {
|
Ok(get_keys::v3::Response {
|
||||||
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(
|
||||||
@@ -537,8 +576,7 @@ 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 =
|
let mut object = keys.deserialize_as::<serde_json::Map<String, serde_json::Value>>()?;
|
||||||
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 {
|
||||||
@@ -604,7 +642,9 @@ 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::new(one_time_keys_input_fed),
|
federation::keys::claim_keys::v1::Request {
|
||||||
|
one_time_keys: one_time_keys_input_fed,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -627,5 +667,5 @@ pub(crate) async fn claim_keys_helper(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(assign!(claim_keys::v3::Response::new(one_time_keys), { failures: failures }))
|
Ok(claim_keys::v3::Response { failures, one_time_keys })
|
||||||
}
|
}
|
||||||
+87
-42
@@ -1,7 +1,7 @@
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, err,
|
Err, Result, err,
|
||||||
utils::{self, content_disposition::make_content_disposition, math::ruma_from_usize},
|
utils::{self, content_disposition::make_content_disposition, math::ruma_from_usize},
|
||||||
@@ -9,11 +9,11 @@ use conduwuit::{
|
|||||||
use conduwuit_core::error;
|
use conduwuit_core::error;
|
||||||
use conduwuit_service::{
|
use conduwuit_service::{
|
||||||
Services,
|
Services,
|
||||||
media::{Dim, FileMeta, MXC_LENGTH},
|
media::{CACHE_CONTROL_IMMUTABLE, CORP_CROSS_ORIGIN, Dim, FileMeta, MXC_LENGTH},
|
||||||
};
|
};
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
UserId,
|
Mxc, 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,9 +21,7 @@ use ruma::{
|
|||||||
},
|
},
|
||||||
media::create_content,
|
media::create_content,
|
||||||
},
|
},
|
||||||
assign,
|
|
||||||
};
|
};
|
||||||
use service::media::mxc::Mxc;
|
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
@@ -32,9 +30,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::new(ruma_from_usize(
|
Ok(get_media_config::v1::Response {
|
||||||
services.server.config.max_request_size,
|
upload_size: ruma_from_usize(services.server.config.max_request_size),
|
||||||
)))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/media/v3/upload`
|
/// # `POST /_matrix/media/v3/upload`
|
||||||
@@ -51,7 +49,7 @@ pub(crate) async fn get_media_config_route(
|
|||||||
)]
|
)]
|
||||||
pub(crate) async fn create_content_route(
|
pub(crate) async fn create_content_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<create_content::v3::Request>,
|
body: Ruma<create_content::v3::Request>,
|
||||||
) -> Result<create_content::v3::Response> {
|
) -> Result<create_content::v3::Response> {
|
||||||
let user = body.sender_user();
|
let user = body.sender_user();
|
||||||
@@ -84,9 +82,10 @@ pub(crate) async fn create_content_route(
|
|||||||
.flatten()
|
.flatten()
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(assign!(create_content::v3::Response::new(mxc.to_string().into()), {
|
Ok(create_content::v3::Response {
|
||||||
|
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}`
|
||||||
@@ -100,7 +99,7 @@ pub(crate) async fn create_content_route(
|
|||||||
)]
|
)]
|
||||||
pub(crate) async fn get_content_thumbnail_route(
|
pub(crate) async fn get_content_thumbnail_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_content_thumbnail::v1::Request>,
|
body: Ruma<get_content_thumbnail::v1::Request>,
|
||||||
) -> Result<get_content_thumbnail::v1::Response> {
|
) -> Result<get_content_thumbnail::v1::Response> {
|
||||||
let user = body.sender_user();
|
let user = body.sender_user();
|
||||||
@@ -115,7 +114,7 @@ pub(crate) async fn get_content_thumbnail_route(
|
|||||||
content,
|
content,
|
||||||
content_type,
|
content_type,
|
||||||
content_disposition,
|
content_disposition,
|
||||||
} = match fetch_thumbnail_meta(&services, &mxc, user, body.timeout_ms, &dim).await {
|
} = match fetch_thumbnail(&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 =>
|
||||||
@@ -129,14 +128,13 @@ 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."))),
|
||||||
};
|
};
|
||||||
|
|
||||||
let content_disposition =
|
Ok(get_content_thumbnail::v1::Response {
|
||||||
make_content_disposition(content_disposition.as_ref(), content_type.as_deref(), None);
|
file: content.expect("entire file contents"),
|
||||||
|
content_type: content_type.map(Into::into),
|
||||||
Ok(get_content_thumbnail::v1::Response::new(
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
content.expect("entire file contents"),
|
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
||||||
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}`
|
||||||
@@ -150,7 +148,7 @@ pub(crate) async fn get_content_thumbnail_route(
|
|||||||
)]
|
)]
|
||||||
pub(crate) async fn get_content_route(
|
pub(crate) async fn get_content_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_content::v1::Request>,
|
body: Ruma<get_content::v1::Request>,
|
||||||
) -> Result<get_content::v1::Response> {
|
) -> Result<get_content::v1::Response> {
|
||||||
let user = body.sender_user();
|
let user = body.sender_user();
|
||||||
@@ -163,7 +161,7 @@ pub(crate) async fn get_content_route(
|
|||||||
content,
|
content,
|
||||||
content_type,
|
content_type,
|
||||||
content_disposition,
|
content_disposition,
|
||||||
} = match fetch_file_meta(&services, &mxc, user, body.timeout_ms).await {
|
} = match fetch_file(&services, &mxc, user, body.timeout_ms, None).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."))),
|
||||||
@@ -176,14 +174,13 @@ 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."))),
|
||||||
};
|
};
|
||||||
|
|
||||||
let content_disposition =
|
Ok(get_content::v1::Response {
|
||||||
make_content_disposition(content_disposition.as_ref(), content_type.as_deref(), None);
|
file: content.expect("entire file contents"),
|
||||||
|
content_type: content_type.map(Into::into),
|
||||||
Ok(get_content::v1::Response::new(
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
content.expect("entire file contents"),
|
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
||||||
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}`
|
||||||
@@ -197,7 +194,7 @@ pub(crate) async fn get_content_route(
|
|||||||
)]
|
)]
|
||||||
pub(crate) async fn get_content_as_filename_route(
|
pub(crate) async fn get_content_as_filename_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_content_as_filename::v1::Request>,
|
body: Ruma<get_content_as_filename::v1::Request>,
|
||||||
) -> Result<get_content_as_filename::v1::Response> {
|
) -> Result<get_content_as_filename::v1::Response> {
|
||||||
let user = body.sender_user();
|
let user = body.sender_user();
|
||||||
@@ -211,7 +208,7 @@ pub(crate) async fn get_content_as_filename_route(
|
|||||||
content,
|
content,
|
||||||
content_type,
|
content_type,
|
||||||
content_disposition,
|
content_disposition,
|
||||||
} = match fetch_file_meta(&services, &mxc, user, body.timeout_ms).await {
|
} = match fetch_file(&services, &mxc, user, body.timeout_ms, None).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."))),
|
||||||
@@ -224,17 +221,13 @@ 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."))),
|
||||||
};
|
};
|
||||||
|
|
||||||
let content_disposition = make_content_disposition(
|
Ok(get_content_as_filename::v1::Response {
|
||||||
content_disposition.as_ref(),
|
file: content.expect("entire file contents"),
|
||||||
content_type.as_deref(),
|
content_type: content_type.map(Into::into),
|
||||||
Some(&body.filename),
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
);
|
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`
|
||||||
@@ -248,7 +241,7 @@ pub(crate) async fn get_content_as_filename_route(
|
|||||||
)]
|
)]
|
||||||
pub(crate) async fn get_media_preview_route(
|
pub(crate) async fn get_media_preview_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_media_preview::v1::Request>,
|
body: Ruma<get_media_preview::v1::Request>,
|
||||||
) -> Result<get_media_preview::v1::Response> {
|
) -> Result<get_media_preview::v1::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -285,6 +278,58 @@ 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<'_>,
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
#![allow(deprecated)]
|
#![allow(deprecated)]
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{
|
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::{CORP_CROSS_ORIGIN, Dim, FileMeta};
|
use conduwuit_service::media::{CACHE_CONTROL_IMMUTABLE, 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};
|
||||||
|
|
||||||
@@ -26,9 +25,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::new(ruma_from_usize(
|
Ok(get_media_config::v3::Response {
|
||||||
services.server.config.max_request_size,
|
upload_size: ruma_from_usize(services.server.config.max_request_size),
|
||||||
)))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/media/v1/config`
|
/// # `GET /_matrix/media/v1/config`
|
||||||
@@ -53,7 +52,7 @@ pub(crate) async fn get_media_config_legacy_legacy_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "url_preview_legacy", level = "debug")]
|
#[tracing::instrument(skip_all, fields(%client), name = "url_preview_legacy", level = "debug")]
|
||||||
pub(crate) async fn get_media_preview_legacy_route(
|
pub(crate) async fn get_media_preview_legacy_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_media_preview::v3::Request>,
|
body: Ruma<get_media_preview::v3::Request>,
|
||||||
) -> Result<get_media_preview::v3::Response> {
|
) -> Result<get_media_preview::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -95,10 +94,10 @@ pub(crate) async fn get_media_preview_legacy_route(
|
|||||||
/// Returns URL preview.
|
/// Returns URL preview.
|
||||||
pub(crate) async fn get_media_preview_legacy_legacy_route(
|
pub(crate) async fn get_media_preview_legacy_legacy_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_media_preview::v3::Request>,
|
body: Ruma<get_media_preview::v3::Request>,
|
||||||
) -> Result<RumaResponse<get_media_preview::v3::Response>> {
|
) -> Result<RumaResponse<get_media_preview::v3::Response>> {
|
||||||
get_media_preview_legacy_route(State(services), InsecureClientIp(client), body)
|
get_media_preview_legacy_route(State(services), ClientIp(client), body)
|
||||||
.await
|
.await
|
||||||
.map(RumaResponse)
|
.map(RumaResponse)
|
||||||
}
|
}
|
||||||
@@ -115,10 +114,10 @@ pub(crate) async fn get_media_preview_legacy_legacy_route(
|
|||||||
/// - Media will be saved in the media/ directory
|
/// - Media will be saved in the media/ directory
|
||||||
pub(crate) async fn create_content_legacy_route(
|
pub(crate) async fn create_content_legacy_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<create_content::v3::Request>,
|
body: Ruma<create_content::v3::Request>,
|
||||||
) -> Result<RumaResponse<create_content::v3::Response>> {
|
) -> Result<RumaResponse<create_content::v3::Response>> {
|
||||||
create_content_route(State(services), InsecureClientIp(client), body)
|
create_content_route(State(services), ClientIp(client), body)
|
||||||
.await
|
.await
|
||||||
.map(RumaResponse)
|
.map(RumaResponse)
|
||||||
}
|
}
|
||||||
@@ -134,7 +133,7 @@ pub(crate) async fn create_content_legacy_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "media_get_legacy", level = "debug")]
|
#[tracing::instrument(skip_all, fields(%client), name = "media_get_legacy", level = "debug")]
|
||||||
pub(crate) async fn get_content_legacy_route(
|
pub(crate) async fn get_content_legacy_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_content::v3::Request>,
|
body: Ruma<get_content::v3::Request>,
|
||||||
) -> Result<get_content::v3::Response> {
|
) -> Result<get_content::v3::Response> {
|
||||||
let mxc = Mxc {
|
let mxc = Mxc {
|
||||||
@@ -154,16 +153,13 @@ pub(crate) async fn get_content_legacy_route(
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(assign!(
|
Ok(get_content::v3::Response {
|
||||||
get_content::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 {
|
||||||
@@ -181,16 +177,13 @@ pub(crate) async fn get_content_legacy_route(
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(assign!(
|
Ok(get_content::v3::Response {
|
||||||
get_content::v3::Response::new(
|
file: response.file,
|
||||||
response.file,
|
content_type: response.content_type,
|
||||||
response.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()),
|
|
||||||
}
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
Err!(Request(NotFound("Media not found.")))
|
Err!(Request(NotFound("Media not found.")))
|
||||||
},
|
},
|
||||||
@@ -212,10 +205,10 @@ pub(crate) async fn get_content_legacy_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "media_get_legacy", level = "debug")]
|
#[tracing::instrument(skip_all, fields(%client), name = "media_get_legacy", level = "debug")]
|
||||||
pub(crate) async fn get_content_legacy_legacy_route(
|
pub(crate) async fn get_content_legacy_legacy_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_content::v3::Request>,
|
body: Ruma<get_content::v3::Request>,
|
||||||
) -> Result<RumaResponse<get_content::v3::Response>> {
|
) -> Result<RumaResponse<get_content::v3::Response>> {
|
||||||
get_content_legacy_route(State(services), InsecureClientIp(client), body)
|
get_content_legacy_route(State(services), ClientIp(client), body)
|
||||||
.await
|
.await
|
||||||
.map(RumaResponse)
|
.map(RumaResponse)
|
||||||
}
|
}
|
||||||
@@ -231,7 +224,7 @@ pub(crate) async fn get_content_legacy_legacy_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "media_get_legacy", level = "debug")]
|
#[tracing::instrument(skip_all, fields(%client), name = "media_get_legacy", level = "debug")]
|
||||||
pub(crate) async fn get_content_as_filename_legacy_route(
|
pub(crate) async fn get_content_as_filename_legacy_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_content_as_filename::v3::Request>,
|
body: Ruma<get_content_as_filename::v3::Request>,
|
||||||
) -> Result<get_content_as_filename::v3::Response> {
|
) -> Result<get_content_as_filename::v3::Response> {
|
||||||
let mxc = Mxc {
|
let mxc = Mxc {
|
||||||
@@ -251,15 +244,13 @@ pub(crate) async fn get_content_as_filename_legacy_route(
|
|||||||
Some(&body.filename),
|
Some(&body.filename),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(assign!(get_content_as_filename::v3::Response::new(
|
Ok(get_content_as_filename::v3::Response {
|
||||||
content.expect("entire file contents"),
|
file: content.expect("entire file contents"),
|
||||||
content_type.unwrap_or_default(),
|
content_type: content_type.map(Into::into),
|
||||||
content_disposition,
|
content_disposition: Some(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 {
|
||||||
@@ -277,16 +268,13 @@ pub(crate) async fn get_content_as_filename_legacy_route(
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(assign!(
|
Ok(get_content_as_filename::v3::Response {
|
||||||
get_content_as_filename::v3::Response::new(
|
content_disposition: Some(content_disposition),
|
||||||
response.file,
|
content_type: response.content_type,
|
||||||
response.content_type.unwrap_or_default(),
|
file: response.file,
|
||||||
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()),
|
|
||||||
}
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
Err!(Request(NotFound("Media not found.")))
|
Err!(Request(NotFound("Media not found.")))
|
||||||
},
|
},
|
||||||
@@ -307,10 +295,10 @@ pub(crate) async fn get_content_as_filename_legacy_route(
|
|||||||
/// seconds
|
/// seconds
|
||||||
pub(crate) async fn get_content_as_filename_legacy_legacy_route(
|
pub(crate) async fn get_content_as_filename_legacy_legacy_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_content_as_filename::v3::Request>,
|
body: Ruma<get_content_as_filename::v3::Request>,
|
||||||
) -> Result<RumaResponse<get_content_as_filename::v3::Response>> {
|
) -> Result<RumaResponse<get_content_as_filename::v3::Response>> {
|
||||||
get_content_as_filename_legacy_route(State(services), InsecureClientIp(client), body)
|
get_content_as_filename_legacy_route(State(services), ClientIp(client), body)
|
||||||
.await
|
.await
|
||||||
.map(RumaResponse)
|
.map(RumaResponse)
|
||||||
}
|
}
|
||||||
@@ -326,7 +314,7 @@ pub(crate) async fn get_content_as_filename_legacy_legacy_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "media_thumbnail_get_legacy", level = "debug")]
|
#[tracing::instrument(skip_all, fields(%client), name = "media_thumbnail_get_legacy", level = "debug")]
|
||||||
pub(crate) async fn get_content_thumbnail_legacy_route(
|
pub(crate) async fn get_content_thumbnail_legacy_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_content_thumbnail::v3::Request>,
|
body: Ruma<get_content_thumbnail::v3::Request>,
|
||||||
) -> Result<get_content_thumbnail::v3::Response> {
|
) -> Result<get_content_thumbnail::v3::Response> {
|
||||||
let mxc = Mxc {
|
let mxc = Mxc {
|
||||||
@@ -347,16 +335,13 @@ pub(crate) async fn get_content_thumbnail_legacy_route(
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(assign!(
|
Ok(get_content_thumbnail::v3::Response {
|
||||||
get_content_thumbnail::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(),
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
content_disposition,
|
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
||||||
),
|
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 {
|
||||||
@@ -374,16 +359,13 @@ pub(crate) async fn get_content_thumbnail_legacy_route(
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(assign!(
|
Ok(get_content_thumbnail::v3::Response {
|
||||||
get_content_thumbnail::v3::Response::new(
|
file: response.file,
|
||||||
response.file,
|
content_type: response.content_type,
|
||||||
response.content_type.unwrap_or_default(),
|
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||||
content_disposition,
|
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
|
||||||
),
|
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.")))
|
||||||
},
|
},
|
||||||
@@ -404,10 +386,10 @@ pub(crate) async fn get_content_thumbnail_legacy_route(
|
|||||||
/// seconds
|
/// seconds
|
||||||
pub(crate) async fn get_content_thumbnail_legacy_legacy_route(
|
pub(crate) async fn get_content_thumbnail_legacy_legacy_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_content_thumbnail::v3::Request>,
|
body: Ruma<get_content_thumbnail::v3::Request>,
|
||||||
) -> Result<RumaResponse<get_content_thumbnail::v3::Response>> {
|
) -> Result<RumaResponse<get_content_thumbnail::v3::Response>> {
|
||||||
get_content_thumbnail_legacy_route(State(services), InsecureClientIp(client), body)
|
get_content_thumbnail_legacy_route(State(services), ClientIp(client), body)
|
||||||
.await
|
.await
|
||||||
.map(RumaResponse)
|
.map(RumaResponse)
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result, matrix::pdu::PartialPdu};
|
use conduwuit::{Err, Result, matrix::pdu::PduBuilder};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::membership::ban_user,
|
api::client::membership::ban_user,
|
||||||
assign,
|
|
||||||
events::room::member::{MembershipState, RoomMemberEventContent},
|
events::room::member::{MembershipState, RoomMemberEventContent},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,19 +24,30 @@ 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.as_str()).await;
|
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
||||||
|
|
||||||
|
let current_member_content = services
|
||||||
|
.rooms
|
||||||
|
.state_accessor
|
||||||
|
.get_member(&body.room_id, &body.user_id)
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|_| RoomMemberEventContent::new(MembershipState::Ban));
|
||||||
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(
|
PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent {
|
||||||
body.user_id.to_string(),
|
membership: MembershipState::Ban,
|
||||||
&assign!(RoomMemberEventContent::new(MembershipState::Ban), {
|
reason: body.reason.clone(),
|
||||||
reason: body.reason.clone()
|
displayname: None, // display name may be offensive
|
||||||
// TODO(upstream): MSC4293
|
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,
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, debug_error, err, info,
|
Err, Result, debug_error, err, info,
|
||||||
matrix::{event::gen_event_id_canonical_json, pdu::PartialPdu},
|
matrix::{event::gen_event_id_canonical_json, pdu::PduBuilder},
|
||||||
warn,
|
warn,
|
||||||
};
|
};
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
RoomId, UserId,
|
RoomId, UserId,
|
||||||
api::{
|
api::{client::membership::invite_user, federation::membership::create_invite},
|
||||||
client::membership::invite_user::{self, v3::InviteUserId},
|
events::{
|
||||||
federation::membership::create_invite,
|
invite_permission_config::FilterLevel,
|
||||||
|
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;
|
||||||
@@ -26,7 +25,7 @@ use crate::Ruma;
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "invite", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "invite", level = "info")]
|
||||||
pub(crate) async fn invite_user_route(
|
pub(crate) async fn invite_user_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<invite_user::v3::Request>,
|
body: Ruma<invite_user::v3::Request>,
|
||||||
) -> Result<invite_user::v3::Response> {
|
) -> Result<invite_user::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -52,11 +51,7 @@ pub(crate) async fn invite_user_route(
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
match &body.recipient {
|
match &body.recipient {
|
||||||
| invite_user::v3::InvitationRecipient::UserId(InviteUserId {
|
| invite_user::v3::InvitationRecipient::UserId { user_id: recipient_user } => {
|
||||||
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)
|
||||||
@@ -64,7 +59,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::new());
|
return Ok(invite_user::v3::Response {});
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(target_user_membership) = services
|
if let Ok(target_user_membership) = services
|
||||||
@@ -100,13 +95,13 @@ pub(crate) async fn invite_user_route(
|
|||||||
sender_user,
|
sender_user,
|
||||||
recipient_user,
|
recipient_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
reason.clone(),
|
body.reason.clone(),
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(invite_user::v3::Response::new())
|
Ok(invite_user::v3::Response {})
|
||||||
},
|
},
|
||||||
| _ => {
|
| _ => {
|
||||||
Err!(Request(NotFound("User not found.")))
|
Err!(Request(NotFound("User not found.")))
|
||||||
@@ -146,17 +141,18 @@ 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 mut content = RoomMemberEventContent::new(MembershipState::Invite);
|
let content = RoomMemberEventContent {
|
||||||
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();
|
is_direct: Some(is_direct),
|
||||||
content.is_direct = Some(is_direct);
|
reason,
|
||||||
content.reason = reason;
|
..RoomMemberEventContent::new(MembershipState::Invite)
|
||||||
|
};
|
||||||
|
|
||||||
let (pdu, pdu_json) = services
|
let (pdu, pdu_json) = services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.create_hash_and_sign_event(
|
.create_hash_and_sign_event(
|
||||||
PartialPdu::state(recipient_user.to_string(), &content),
|
PduBuilder::state(recipient_user.to_string(), &content),
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(room_id),
|
Some(room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -172,39 +168,32 @@ 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(), request)
|
.send_federation_request(recipient_user.server_name(), create_invite::v2::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(
|
let (event_id, value) = gen_event_id_canonical_json(&response.event, &room_version_id)
|
||||||
&response.event,
|
.map_err(|e| {
|
||||||
&room_version_id
|
err!(Request(BadJson(warn!("Could not convert event to canonical JSON: {e}"))))
|
||||||
.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!(
|
||||||
@@ -240,18 +229,20 @@ 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 mut content = RoomMemberEventContent::new(MembershipState::Invite);
|
let content = RoomMemberEventContent {
|
||||||
content.displayname = services.users.displayname(recipient_user).await.ok();
|
displayname: services.users.displayname(recipient_user).await.ok(),
|
||||||
content.avatar_url = services.users.avatar_url(recipient_user).await.ok();
|
avatar_url: services.users.avatar_url(recipient_user).await.ok(),
|
||||||
content.blurhash = services.users.blurhash(recipient_user).await.ok();
|
blurhash: services.users.blurhash(recipient_user).await.ok(),
|
||||||
content.is_direct = Some(is_direct);
|
is_direct: Some(is_direct),
|
||||||
content.reason = reason;
|
reason,
|
||||||
|
..RoomMemberEventContent::new(MembershipState::Invite)
|
||||||
|
};
|
||||||
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(recipient_user.to_string(), &content),
|
PduBuilder::state(recipient_user.to_string(), &content),
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(room_id),
|
Some(room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
use std::{borrow::Borrow, collections::HashMap, iter::once, sync::Arc};
|
use std::{borrow::Borrow, collections::HashMap, iter::once, sync::Arc};
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, debug, debug_info, debug_warn, err, error, info, is_true,
|
Err, Result, debug, debug_info, debug_warn, err, error, info, is_true,
|
||||||
matrix::{
|
matrix::{
|
||||||
StateKey,
|
StateKey,
|
||||||
event::{gen_event_id, gen_event_id_canonical_json},
|
event::{gen_event_id, gen_event_id_canonical_json},
|
||||||
pdu::{PartialPdu, PduEvent},
|
pdu::{PduBuilder, PduEvent},
|
||||||
state_res,
|
state_res,
|
||||||
},
|
},
|
||||||
result::FlatOk,
|
result::FlatOk,
|
||||||
@@ -24,8 +24,10 @@ use ruma::{
|
|||||||
CanonicalJsonObject, CanonicalJsonValue, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId,
|
CanonicalJsonObject, CanonicalJsonValue, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId,
|
||||||
RoomVersionId, UserId,
|
RoomVersionId, UserId,
|
||||||
api::{
|
api::{
|
||||||
client::membership::{join_room_by_id, join_room_by_id_or_alias},
|
client::{
|
||||||
error::{ErrorKind, IncompatibleRoomVersionErrorData},
|
error::ErrorKind,
|
||||||
|
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,
|
||||||
@@ -65,7 +67,7 @@ use crate::{
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "join", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "join", level = "info")]
|
||||||
pub(crate) async fn join_room_by_id_route(
|
pub(crate) async fn join_room_by_id_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<join_room_by_id::v3::Request>,
|
body: Ruma<join_room_by_id::v3::Request>,
|
||||||
) -> Result<join_room_by_id::v3::Response> {
|
) -> Result<join_room_by_id::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -87,6 +89,7 @@ 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;
|
||||||
|
|
||||||
@@ -136,7 +139,7 @@ pub(crate) async fn join_room_by_id_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "join", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "join", level = "info")]
|
||||||
pub(crate) async fn join_room_by_id_or_alias_route(
|
pub(crate) async fn join_room_by_id_or_alias_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<join_room_by_id_or_alias::v3::Request>,
|
body: Ruma<join_room_by_id_or_alias::v3::Request>,
|
||||||
) -> Result<join_room_by_id_or_alias::v3::Response> {
|
) -> Result<join_room_by_id_or_alias::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -166,6 +169,7 @@ 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,
|
||||||
);
|
);
|
||||||
@@ -206,7 +210,11 @@ pub(crate) async fn join_room_by_id_or_alias_route(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let addl_via_servers = services.rooms.state_cache.servers_invite_via(&room_id);
|
let addl_via_servers = services
|
||||||
|
.rooms
|
||||||
|
.state_cache
|
||||||
|
.servers_invite_via(&room_id)
|
||||||
|
.map(ToOwned::to_owned);
|
||||||
|
|
||||||
let addl_state_servers = services
|
let addl_state_servers = services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -219,7 +227,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: OwnedUserId| user.server_name().to_owned())
|
.map(|user: &UserId| user.server_name().to_owned())
|
||||||
.stream()
|
.stream()
|
||||||
.chain(addl_via_servers)
|
.chain(addl_via_servers)
|
||||||
.collect()
|
.collect()
|
||||||
@@ -246,7 +254,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::new(join_room_response.room_id))
|
Ok(join_room_by_id_or_alias::v3::Response { room_id: join_room_response.room_id })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn join_room_by_id_helper(
|
pub async fn join_room_by_id_helper(
|
||||||
@@ -277,7 +285,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::new(room_id.to_owned()));
|
return Ok(join_room_by_id::v3::Response { room_id: room_id.into() });
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = services
|
if let Err(e) = services
|
||||||
@@ -377,14 +385,13 @@ async fn join_room_by_id_helper_remote(
|
|||||||
|
|
||||||
info!("make_join finished");
|
info!("make_join finished");
|
||||||
|
|
||||||
let room_version = make_join_response.room_version.unwrap_or(RoomVersionId::V1);
|
let room_version_id = 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) {
|
if !services.server.supported_room_version(&room_version_id) {
|
||||||
// How did we get here?
|
// How did we get here?
|
||||||
return Err!(BadServerResponse("Remote room version {room_version} is not supported"));
|
return Err!(BadServerResponse(
|
||||||
|
"Remote room version {room_version_id} is not supported by conduwuit"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut join_event_stub: CanonicalJsonObject =
|
let mut join_event_stub: CanonicalJsonObject =
|
||||||
@@ -396,7 +403,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, V1 | V2 | V3 | V4 | V5 | V6 | V7) {
|
if !matches!(room_version_id, V1 | V2 | V3 | V4 | V5 | V6 | V7) {
|
||||||
join_event_stub
|
join_event_stub
|
||||||
.get("content")
|
.get("content")
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
@@ -418,32 +425,36 @@ 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(join_content).expect("event is valid, we just created it"),
|
to_canonical_value(RoomMemberEventContent {
|
||||||
|
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"),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove event id if it exists
|
// We keep the "event_id" in the pdu only in v1 or
|
||||||
join_event_stub.remove("event_id");
|
// v2 rooms
|
||||||
|
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_rules)?;
|
.hash_and_sign_event(&mut join_event_stub, &room_version_id)?;
|
||||||
|
|
||||||
// Generate event id
|
// Generate event id
|
||||||
let event_id = gen_event_id(&join_event_stub, &room_version_rules)?;
|
let event_id = gen_event_id(&join_event_stub, &room_version_id)?;
|
||||||
|
|
||||||
// Add event_id back
|
// Add event_id back
|
||||||
join_event_stub
|
join_event_stub
|
||||||
@@ -453,14 +464,15 @@ 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::new(
|
let send_join_request = federation::membership::create_join_event::v2::Request {
|
||||||
room_id.to_owned(),
|
room_id: room_id.to_owned(),
|
||||||
event_id.clone(),
|
event_id: event_id.clone(),
|
||||||
services
|
omit_members: false,
|
||||||
|
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
|
||||||
@@ -484,7 +496,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_rules).map_err(|e| {
|
gen_event_id_canonical_json(signed_raw, &room_version_id).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}"
|
||||||
))))
|
))))
|
||||||
@@ -559,7 +571,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_rules)
|
.validate_and_add_event_id_no_fetch(pdu, &room_version_id)
|
||||||
.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:?}");
|
||||||
})
|
})
|
||||||
@@ -607,7 +619,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_rules)
|
.validate_and_add_event_id_no_fetch(pdu, &room_version_id)
|
||||||
})
|
})
|
||||||
.ready_filter_map(Result::ok)
|
.ready_filter_map(Result::ok)
|
||||||
.ready_for_each(|(event_id, value)| {
|
.ready_for_each(|(event_id, value)| {
|
||||||
@@ -628,7 +640,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(
|
||||||
&room_version.rules().unwrap(),
|
&state_res::RoomVersion::new(&room_version_id)?,
|
||||||
&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()),
|
||||||
@@ -735,7 +747,8 @@ 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).await;
|
user_can_perform_restricted_join(services, sender_user, room_id, &room_version)
|
||||||
|
.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.
|
||||||
@@ -748,19 +761,21 @@ async fn join_room_by_id_helper_local(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut content = RoomMemberEventContent::new(MembershipState::Join);
|
let content = RoomMemberEventContent {
|
||||||
content.displayname = services.users.displayname(sender_user).await.ok();
|
displayname: services.users.displayname(sender_user).await.ok(),
|
||||||
content.avatar_url = services.users.avatar_url(sender_user).await.ok();
|
avatar_url: services.users.avatar_url(sender_user).await.ok(),
|
||||||
content.blurhash = services.users.blurhash(sender_user).await.ok();
|
blurhash: services.users.blurhash(sender_user).await.ok(),
|
||||||
content.reason.clone_from(&reason);
|
reason: reason.clone(),
|
||||||
content.join_authorized_via_users_server = auth_user;
|
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(
|
||||||
PartialPdu::state(sender_user.to_string(), &content),
|
PduBuilder::state(sender_user.to_string(), &content),
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(room_id),
|
Some(room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -809,16 +824,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(remote_server, request)
|
.send_federation_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);
|
||||||
@@ -851,17 +866,14 @@ 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(IncompatibleRoomVersionErrorData {
|
| ErrorKind::IncompatibleRoomVersion { room_version } => {
|
||||||
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,8 +1,7 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result, matrix::pdu::PartialPdu};
|
use conduwuit::{Err, Result, matrix::pdu::PduBuilder};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::membership::kick_user,
|
api::client::membership::kick_user,
|
||||||
assign,
|
|
||||||
events::room::member::{MembershipState, RoomMemberEventContent},
|
events::room::member::{MembershipState, RoomMemberEventContent},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -19,28 +18,41 @@ 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.as_str()).await;
|
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
||||||
|
|
||||||
if !services
|
let Ok(event) = services
|
||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_accessor
|
||||||
.is_joined(&body.user_id, &body.room_id)
|
.get_member(&body.room_id, &body.user_id)
|
||||||
.await
|
.await
|
||||||
{
|
else {
|
||||||
return Err!(Request(Forbidden("You cannot kick users who are not in the room.")));
|
// copy synapse's behaviour of returning 200 without any change to the state
|
||||||
|
// instead of erroring on left users
|
||||||
|
return Ok(kick_user::v3::Response::new());
|
||||||
|
};
|
||||||
|
|
||||||
|
if !matches!(
|
||||||
|
event.membership,
|
||||||
|
MembershipState::Invite | MembershipState::Knock | MembershipState::Join,
|
||||||
|
) {
|
||||||
|
return Err!(Request(Forbidden(
|
||||||
|
"Cannot kick a user who is not apart of the room (current membership: {})",
|
||||||
|
event.membership
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(
|
PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent {
|
||||||
body.user_id.to_string(),
|
membership: MembershipState::Leave,
|
||||||
&assign!(RoomMemberEventContent::new(MembershipState::Leave), {
|
reason: body.reason.clone(),
|
||||||
reason: body.reason.clone(),
|
is_direct: None,
|
||||||
// TODO(upstream): MSC4293
|
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,
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use std::{borrow::Borrow, collections::HashMap, iter::once, sync::Arc};
|
use std::{borrow::Borrow, collections::HashMap, iter::once, sync::Arc};
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{
|
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::{PartialPdu, PduEvent},
|
pdu::{PduBuilder, 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,
|
CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, OwnedServerName, RoomId,
|
||||||
OwnedUserId, RoomId, UserId,
|
RoomVersionId, UserId,
|
||||||
api::{
|
api::{
|
||||||
client::knock::knock_room,
|
client::knock::knock_room,
|
||||||
federation::{self},
|
federation::{self},
|
||||||
@@ -47,7 +47,7 @@ use crate::Ruma;
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "knock", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "knock", level = "info")]
|
||||||
pub(crate) async fn knock_room_route(
|
pub(crate) async fn knock_room_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<knock_room::v3::Request>,
|
body: Ruma<knock_room::v3::Request>,
|
||||||
) -> Result<knock_room::v3::Response> {
|
) -> Result<knock_room::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -73,6 +73,7 @@ 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,
|
||||||
);
|
);
|
||||||
@@ -112,7 +113,11 @@ pub(crate) async fn knock_room_route(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let addl_via_servers = services.rooms.state_cache.servers_invite_via(&room_id);
|
let addl_via_servers = services
|
||||||
|
.rooms
|
||||||
|
.state_cache
|
||||||
|
.servers_invite_via(&room_id)
|
||||||
|
.map(ToOwned::to_owned);
|
||||||
|
|
||||||
let addl_state_servers = services
|
let addl_state_servers = services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -125,7 +130,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: OwnedUserId| user.server_name().to_owned())
|
.map(|user: &UserId| user.server_name().to_owned())
|
||||||
.stream()
|
.stream()
|
||||||
.chain(addl_via_servers)
|
.chain(addl_via_servers)
|
||||||
.collect()
|
.collect()
|
||||||
@@ -183,7 +188,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::new(room_id.into()));
|
return Ok(knock_room::v3::Response { room_id: room_id.into() });
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(membership) = services
|
if let Ok(membership) = services
|
||||||
@@ -334,27 +339,34 @@ async fn knock_room_helper_local(
|
|||||||
) -> Result {
|
) -> Result {
|
||||||
debug_info!("We can knock locally");
|
debug_info!("We can knock locally");
|
||||||
|
|
||||||
let room_version = services.rooms.state.get_room_version(room_id).await?;
|
let room_version_id = services.rooms.state.get_room_version(room_id).await?;
|
||||||
let room_version_rules = room_version
|
|
||||||
.rules()
|
|
||||||
.expect("room version should have defined rules");
|
|
||||||
|
|
||||||
if !room_version_rules.authorization.knocking {
|
if matches!(
|
||||||
|
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 mut content = RoomMemberEventContent::new(MembershipState::Knock);
|
let content = RoomMemberEventContent {
|
||||||
content.displayname = services.users.displayname(sender_user).await.ok();
|
displayname: services.users.displayname(sender_user).await.ok(),
|
||||||
content.avatar_url = services.users.avatar_url(sender_user).await.ok();
|
avatar_url: services.users.avatar_url(sender_user).await.ok(),
|
||||||
content.blurhash = services.users.blurhash(sender_user).await.ok();
|
blurhash: services.users.blurhash(sender_user).await.ok(),
|
||||||
content.reason.clone_from(&reason.clone());
|
reason: 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(
|
||||||
PartialPdu::state(sender_user.to_string(), &content),
|
PduBuilder::state(sender_user.to_string(), &content),
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(room_id),
|
Some(room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -369,18 +381,19 @@ 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 = make_knock_response.room_version;
|
let room_version_id = 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) {
|
if !services.server.supported_room_version(&room_version_id) {
|
||||||
return Err!(BadServerResponse("Remote room version {room_version} is not supported"));
|
return Err!(BadServerResponse(
|
||||||
|
"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>(
|
||||||
@@ -411,17 +424,24 @@ async fn knock_room_helper_local(
|
|||||||
);
|
);
|
||||||
knock_event_stub.insert(
|
knock_event_stub.insert(
|
||||||
"content".to_owned(),
|
"content".to_owned(),
|
||||||
to_canonical_value(content).expect("event is valid, we just created it"),
|
to_canonical_value(RoomMemberEventContent {
|
||||||
|
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_rules)?;
|
.hash_and_sign_event(&mut knock_event_stub, &room_version_id)?;
|
||||||
|
|
||||||
// Generate event id
|
// Generate event id
|
||||||
let event_id = gen_event_id(&knock_event_stub, &room_version_rules)?;
|
let event_id = gen_event_id(&knock_event_stub, &room_version_id)?;
|
||||||
|
|
||||||
// Add event_id
|
// Add event_id
|
||||||
knock_event_stub
|
knock_event_stub
|
||||||
@@ -431,14 +451,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::membership::create_knock_event::v1::Request::new(
|
let send_knock_request = federation::knock::send_knock::v1::Request {
|
||||||
room_id.to_owned(),
|
room_id: room_id.to_owned(),
|
||||||
event_id.clone(),
|
event_id: event_id.clone(),
|
||||||
services
|
pdu: 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
|
||||||
@@ -500,13 +520,12 @@ async fn knock_room_helper_remote(
|
|||||||
|
|
||||||
info!("make_knock finished");
|
info!("make_knock finished");
|
||||||
|
|
||||||
let room_version = make_knock_response.room_version;
|
let room_version_id = 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) {
|
if !services.server.supported_room_version(&room_version_id) {
|
||||||
return Err!(BadServerResponse("Remote room version {room_version} is not supported"));
|
return Err!(BadServerResponse(
|
||||||
|
"Remote room version {room_version_id} is not supported by conduwuit"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut knock_event_stub: CanonicalJsonObject =
|
let mut knock_event_stub: CanonicalJsonObject =
|
||||||
@@ -526,26 +545,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(knock_content).expect("event is valid, we just created it"),
|
to_canonical_value(RoomMemberEventContent {
|
||||||
|
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_rules)?;
|
.hash_and_sign_event(&mut knock_event_stub, &room_version_id)?;
|
||||||
|
|
||||||
// Generate event id
|
// Generate event id
|
||||||
let event_id = gen_event_id(&knock_event_stub, &room_version_rules)?;
|
let event_id = gen_event_id(&knock_event_stub, &room_version_id)?;
|
||||||
|
|
||||||
// Add event_id
|
// Add event_id
|
||||||
knock_event_stub
|
knock_event_stub
|
||||||
@@ -555,18 +574,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 request = federation::membership::create_knock_event::v1::Request::new(
|
let send_knock_request = federation::knock::send_knock::v1::Request {
|
||||||
room_id.to_owned(),
|
room_id: room_id.to_owned(),
|
||||||
event_id.clone(),
|
event_id: event_id.clone(),
|
||||||
services
|
pdu: 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, request)
|
.send_federation_request(&remote_server, send_knock_request)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
info!("send_knock finished");
|
info!("send_knock finished");
|
||||||
@@ -585,17 +604,7 @@ 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| {
|
.map(|event| serde_json::from_str::<CanonicalJsonObject>(event.clone().into_json().get()))
|
||||||
#[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();
|
||||||
@@ -620,7 +629,7 @@ async fn knock_room_helper_remote(
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let event_id = gen_event_id(&event, &room_version_rules)?;
|
let event_id = gen_event_id(&event, &room_version_id)?;
|
||||||
let shortstatekey = services
|
let shortstatekey = services
|
||||||
.rooms
|
.rooms
|
||||||
.short
|
.short
|
||||||
@@ -700,7 +709,7 @@ async fn make_knock_request(
|
|||||||
sender_user: &UserId,
|
sender_user: &UserId,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
servers: &[OwnedServerName],
|
servers: &[OwnedServerName],
|
||||||
) -> Result<(federation::membership::prepare_knock_event::v1::Response, OwnedServerName)> {
|
) -> Result<(federation::knock::create_knock_event_template::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."));
|
||||||
|
|
||||||
@@ -713,15 +722,16 @@ 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(remote_server, request)
|
.send_federation_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::PartialPdu},
|
matrix::{event::gen_event_id, pdu::PduBuilder},
|
||||||
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, UserId,
|
CanonicalJsonObject, CanonicalJsonValue, OwnedServerName, RoomId, RoomVersionId, UserId,
|
||||||
api::{
|
api::{
|
||||||
client::membership::leave_room,
|
client::membership::leave_room,
|
||||||
federation::{self},
|
federation::{self},
|
||||||
@@ -42,7 +42,11 @@ 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.rooms.state_cache.rooms_joined(user_id);
|
let rooms_joined = services
|
||||||
|
.rooms
|
||||||
|
.state_cache
|
||||||
|
.rooms_joined(user_id)
|
||||||
|
.map(ToOwned::to_owned);
|
||||||
|
|
||||||
let rooms_invited = services
|
let rooms_invited = services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -138,17 +142,18 @@ pub async fn leave_room(
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
match user_member_event_content {
|
match user_member_event_content {
|
||||||
| Ok(mut content) => {
|
| Ok(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(
|
||||||
PartialPdu::state(user_id.to_string(), &content),
|
PduBuilder::state(user_id.to_string(), &RoomMemberEventContent {
|
||||||
|
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,
|
||||||
@@ -221,6 +226,7 @@ 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,
|
||||||
);
|
);
|
||||||
@@ -254,7 +260,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
|
||||||
@@ -283,10 +289,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::new(
|
federation::membership::prepare_leave_event::v1::Request {
|
||||||
room_id.to_owned(),
|
room_id: room_id.to_owned(),
|
||||||
user_id.to_owned(),
|
user_id: user_id.to_owned(),
|
||||||
),
|
},
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -323,10 +329,6 @@ 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(),
|
||||||
)
|
)
|
||||||
@@ -364,16 +366,21 @@ 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
|
||||||
leave_event_stub.remove("event_id");
|
match room_version_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_rules)?;
|
.hash_and_sign_event(&mut leave_event_stub, &room_version_id)?;
|
||||||
|
|
||||||
// Generate event id
|
// Generate event id
|
||||||
let event_id = gen_event_id(&leave_event_stub, &room_version_rules)?;
|
let event_id = gen_event_id(&leave_event_stub, &room_version_id)?;
|
||||||
|
|
||||||
// Add event_id back
|
// Add event_id back
|
||||||
leave_event_stub
|
leave_event_stub
|
||||||
@@ -386,14 +393,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::new(
|
federation::membership::create_leave_event::v2::Request {
|
||||||
room_id.to_owned(),
|
room_id: room_id.to_owned(),
|
||||||
event_id.clone(),
|
event_id: event_id.clone(),
|
||||||
services
|
pdu: 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},
|
get_member_events::{self, v3::MembershipEventFilter},
|
||||||
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.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
let chunk = services
|
Ok(get_member_events::v3::Response {
|
||||||
.rooms
|
chunk: services
|
||||||
.state_accessor
|
.rooms
|
||||||
.room_state_full(&body.room_id)
|
.state_accessor
|
||||||
.ready_filter_map(Result::ok)
|
.room_state_full(&body.room_id)
|
||||||
.ready_filter(|((ty, _), _)| *ty == StateEventType::RoomMember)
|
.ready_filter_map(Result::ok)
|
||||||
.map(at!(1))
|
.ready_filter(|((ty, _), _)| *ty == StateEventType::RoomMember)
|
||||||
.ready_filter_map(|pdu| membership_filter(pdu, membership, not_membership))
|
.map(at!(1))
|
||||||
.map(Event::into_format)
|
.ready_filter_map(|pdu| membership_filter(pdu, membership, not_membership))
|
||||||
.collect()
|
.map(Event::into_format)
|
||||||
.boxed()
|
.collect()
|
||||||
.await;
|
.boxed()
|
||||||
|
.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,46 +78,70 @@ 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.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
let joined = services
|
Ok(joined_members::v3::Response {
|
||||||
.rooms
|
joined: services
|
||||||
.state_cache
|
.rooms
|
||||||
.room_members(&body.room_id)
|
.state_cache
|
||||||
.broad_then(|user_id| async move {
|
.room_members(&body.room_id)
|
||||||
let mut member = RoomMember::new();
|
.map(ToOwned::to_owned)
|
||||||
let (display_name, avatar_url) = join(
|
.broad_then(|user_id| async move {
|
||||||
services.users.displayname(&user_id).ok(),
|
let (display_name, avatar_url) = join(
|
||||||
services.users.avatar_url(&user_id).ok(),
|
services.users.displayname(&user_id).ok(),
|
||||||
)
|
services.users.avatar_url(&user_id).ok(),
|
||||||
.await;
|
)
|
||||||
member.display_name = display_name;
|
.await;
|
||||||
member.avatar_url = avatar_url;
|
|
||||||
|
|
||||||
(user_id, member)
|
(user_id, RoomMember { display_name, avatar_url })
|
||||||
})
|
})
|
||||||
.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,
|
||||||
membership_state_filter: Option<&MembershipState>,
|
for_membership: Option<&MembershipEventFilter>,
|
||||||
not_membership_state_filter: Option<&MembershipState>,
|
not_membership: Option<&MembershipEventFilter>,
|
||||||
) -> 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 let Some(membership_state_filter) = membership_state_filter
|
if for_membership.is_some() && not_membership.is_some() {
|
||||||
&& *membership_state_filter != evt_membership
|
if 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,14 +47,15 @@ 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> {
|
||||||
let joined_rooms = services
|
Ok(joined_rooms::v3::Response {
|
||||||
.rooms
|
joined_rooms: services
|
||||||
.state_cache
|
.rooms
|
||||||
.rooms_joined(body.sender_user())
|
.state_cache
|
||||||
.collect()
|
.rooms_joined(body.sender_user())
|
||||||
.await;
|
.map(ToOwned::to_owned)
|
||||||
|
.collect()
|
||||||
Ok(joined_rooms::v3::Response::new(joined_rooms))
|
.await,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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::PartialPdu};
|
use conduwuit::{Err, Result, matrix::pdu::PduBuilder};
|
||||||
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.as_str()).await;
|
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
||||||
|
|
||||||
let mut current_member_content = services
|
let 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,17 +34,18 @@ 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(
|
||||||
PartialPdu::state(body.user_id.to_string(), ¤t_member_content),
|
PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent {
|
||||||
|
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,
|
||||||
|
|||||||
+12
-15
@@ -1,5 +1,5 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Error, Result, at, debug_warn,
|
Err, Error, Result, at, debug_warn,
|
||||||
matrix::{
|
matrix::{
|
||||||
@@ -26,17 +26,15 @@ use ruma::{
|
|||||||
DeviceId, RoomId, UserId,
|
DeviceId, RoomId, UserId,
|
||||||
api::{
|
api::{
|
||||||
Direction,
|
Direction,
|
||||||
client::{filter::RoomEventFilter, message::get_message_events},
|
client::{error::ErrorKind, 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;
|
||||||
@@ -73,9 +71,10 @@ const LIMIT_DEFAULT: usize = 10;
|
|||||||
/// where the user was joined, depending on `history_visibility`)
|
/// where the user was joined, depending on `history_visibility`)
|
||||||
pub(crate) async fn get_message_events_route(
|
pub(crate) async fn get_message_events_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client_ip): InsecureClientIp,
|
ClientIp(client_ip): ClientIp,
|
||||||
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;
|
||||||
@@ -200,12 +199,12 @@ pub(crate) async fn get_message_events_route(
|
|||||||
.map(Event::into_format)
|
.map(Event::into_format)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(assign!(get_message_events::v3::Response::new(), {
|
Ok(get_message_events::v3::Response {
|
||||||
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>(
|
||||||
@@ -302,7 +301,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_string() == "org.matrix.dummy_event" {
|
if event.kind().to_cow_str() == "org.matrix.dummy_event" {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,7 +323,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(SenderIgnoredErrorData::new()),
|
ErrorKind::SenderIgnored { sender: None },
|
||||||
"The sender's server is ignored by this server.",
|
"The sender's server is ignored by this server.",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -333,9 +332,7 @@ 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(SenderIgnoredErrorData::with_sender(
|
ErrorKind::SenderIgnored { sender: Some(event.sender().to_owned()) },
|
||||||
event.sender().to_owned(),
|
|
||||||
)),
|
|
||||||
"You have ignored this sender.",
|
"You have ignored this sender.",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ 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;
|
||||||
@@ -36,6 +35,7 @@ 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,6 +82,7 @@ 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::*;
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
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::new(
|
Ok(account::request_openid_token::v3::Response {
|
||||||
access_token,
|
access_token,
|
||||||
TokenType::Bearer,
|
token_type: TokenType::Bearer,
|
||||||
services.server.name.clone(),
|
matrix_server_name: services.server.name.clone(),
|
||||||
Duration::from_secs(expires_in),
|
expires_in: Duration::from_secs(expires_in),
|
||||||
))
|
})
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result};
|
use conduwuit::{Err, Result};
|
||||||
use ruma::{
|
use ruma::api::client::presence::{get_presence, set_presence};
|
||||||
api::client::presence::{get_presence, set_presence},
|
|
||||||
assign,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
@@ -29,7 +26,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::new())
|
Ok(set_presence::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/presence/{userId}/status`
|
/// # `GET /_matrix/client/r0/presence/{userId}/status`
|
||||||
@@ -79,11 +76,13 @@ pub(crate) async fn get_presence_route(
|
|||||||
.map(|millis| Duration::from_millis(millis.into())),
|
.map(|millis| Duration::from_millis(millis.into())),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(assign!(get_presence::v3::Response::new(presence.content.presence), {
|
Ok(get_presence::v3::Response {
|
||||||
|
// 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"))),
|
||||||
}
|
}
|
||||||
|
|||||||
+381
-337
@@ -1,26 +1,229 @@
|
|||||||
use std::collections::BTreeMap;
|
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{Err, Result, matrix::pdu::PartialPdu, utils::to_canonical_object};
|
use conduwuit::{
|
||||||
|
Err, Result,
|
||||||
|
matrix::pdu::PduBuilder,
|
||||||
|
utils::{IterStream, future::TryExtExt, stream::TryIgnore},
|
||||||
|
warn,
|
||||||
|
};
|
||||||
use conduwuit_service::Services;
|
use conduwuit_service::Services;
|
||||||
use futures::StreamExt;
|
use futures::{
|
||||||
|
FutureExt, StreamExt, TryStreamExt,
|
||||||
|
future::{join, join3, join4},
|
||||||
|
};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
UserId,
|
OwnedMxcUri, OwnedRoomId, UserId,
|
||||||
api::{
|
api::{
|
||||||
client::profile::{
|
client::profile::{
|
||||||
delete_profile_field, get_profile, get_profile_field, set_profile_field,
|
get_avatar_url, get_display_name, get_profile, set_avatar_url, set_display_name,
|
||||||
},
|
},
|
||||||
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)
|
||||||
|
.boxed()
|
||||||
|
.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,
|
||||||
|
)
|
||||||
|
.boxed()
|
||||||
|
.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
|
||||||
@@ -32,347 +235,188 @@ 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) {
|
||||||
return Err!(Request(InvalidParam("You may not change a remote user's profile data.")));
|
// Create and update our local copy of the user
|
||||||
}
|
if let Ok(response) = services
|
||||||
|
.sending
|
||||||
set_profile_field(&services, &body.user_id, ProfileFieldChange::Set(body.value.clone()))
|
.send_federation_request(
|
||||||
.await?;
|
body.user_id.server_name(),
|
||||||
|
federation::query::get_profile_information::v1::Request {
|
||||||
Ok(set_profile_field::v3::Response::new())
|
user_id: body.user_id.clone(),
|
||||||
}
|
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
let _ = 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) {
|
|
||||||
let _ = 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 {
|
|
||||||
let _ = 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()
|
{
|
||||||
.map(to_value)
|
if !services.users.exists(&body.user_id).await {
|
||||||
.transpose()
|
services.users.create(&body.user_id, None, None).await?;
|
||||||
.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(),
|
|
||||||
}?;
|
|
||||||
|
|
||||||
Some(
|
services
|
||||||
ProfileFieldValue::new(field.as_str(), value)
|
.users
|
||||||
.expect("local profile field should be valid"),
|
.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());
|
||||||
|
|
||||||
enum ProfileFieldChange {
|
for (profile_key, profile_key_value) in &response.custom_profile_fields {
|
||||||
Set(ProfileFieldValue),
|
services.users.set_profile_key(
|
||||||
Delete(ProfileFieldName),
|
&body.user_id,
|
||||||
}
|
profile_key,
|
||||||
|
Some(profile_key_value.clone()),
|
||||||
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,
|
|
||||||
) -> Result<()> {
|
|
||||||
const MAX_KEY_LENGTH_BYTES: usize = 255;
|
|
||||||
const MAX_PROFILE_LENGTH_BYTES: usize = 65536;
|
|
||||||
|
|
||||||
let field_name = change.field_name();
|
|
||||||
|
|
||||||
// TODO: The spec mentions special error codes (M_PROFILE_TOO_LARGE,
|
|
||||||
// M_KEY_TOO_LARGE) for profile field size limits, but they're not in its list
|
|
||||||
// of error codes and Ruma doesn't have them. Should we return those, or is
|
|
||||||
// M_TOO_LARGE okay?
|
|
||||||
if field_name.as_str().len() > MAX_KEY_LENGTH_BYTES {
|
|
||||||
return Err!(Request(TooLarge(
|
|
||||||
"Individual profile keys must not exceed {MAX_KEY_LENGTH_BYTES} bytes in length."
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Serialize the entire profile as canonical JSON, including the new change,
|
|
||||||
// to check if it exceeds 64 KiB
|
|
||||||
{
|
|
||||||
let mut full_profile = get_local_profile(services, user_id).await;
|
|
||||||
|
|
||||||
match &change {
|
|
||||||
| ProfileFieldChange::Set(value) => {
|
|
||||||
full_profile.insert(
|
|
||||||
value.field_name().as_str().to_owned(),
|
|
||||||
value.value().clone().into_owned(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
| ProfileFieldChange::Delete(key) => {
|
|
||||||
full_profile.remove(key.as_str());
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(canonical_profile) = to_canonical_object(full_profile) {
|
|
||||||
if serde_json::to_string(&canonical_profile)
|
|
||||||
.expect("should be able to serialize to string")
|
|
||||||
.len() > MAX_PROFILE_LENGTH_BYTES
|
|
||||||
{
|
|
||||||
return Err!(
|
|
||||||
"Profile data must not exceed {MAX_PROFILE_LENGTH_BYTES} bytes in length."
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return Err!(Request(BadJson("Failed to canonicalize profile.")));
|
return Ok(get_profile::v3::Response {
|
||||||
|
displayname: response.displayname,
|
||||||
|
avatar_url: response.avatar_url,
|
||||||
|
blurhash: response.blurhash,
|
||||||
|
custom_profile_fields: response.custom_profile_fields,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match change {
|
if !services.users.exists(&body.user_id).await {
|
||||||
| ProfileFieldChange::Set(ProfileFieldValue::DisplayName(displayname)) => {
|
// Return 404 if this user doesn't exist and we couldn't fetch it over
|
||||||
services
|
// federation
|
||||||
.users
|
return Err!(Request(NotFound("Profile was not found.")));
|
||||||
.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(
|
|
||||||
user_id,
|
|
||||||
other.field_name().as_str(),
|
|
||||||
other.value(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user is local and changed their displayname or avatar_url, update it
|
let (avatar_url, blurhash, displayname, custom_profile_fields) = join4(
|
||||||
// in all their joined rooms
|
services.users.avatar_url(&body.user_id).ok(),
|
||||||
if matches!(field_name, ProfileFieldName::AvatarUrl | ProfileFieldName::DisplayName)
|
services.users.blurhash(&body.user_id).ok(),
|
||||||
&& services.users.is_active_local(user_id).await
|
services.users.displayname(&body.user_id).ok(),
|
||||||
{
|
services.users.all_profile_keys(&body.user_id).collect(),
|
||||||
let displayname = services.users.displayname(user_id).await.ok();
|
)
|
||||||
let avatar_url = services.users.avatar_url(user_id).await.ok();
|
.await;
|
||||||
let membership_content = assign!(
|
|
||||||
RoomMemberEventContent::new(MembershipState::Join), { displayname, avatar_url }
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut all_joined_rooms = services.rooms.state_cache.rooms_joined(user_id);
|
Ok(get_profile::v3::Response {
|
||||||
|
avatar_url,
|
||||||
while let Some(room_id) = all_joined_rooms.next().await {
|
blurhash,
|
||||||
let state_lock = services.rooms.state.mutex.lock(room_id.as_str()).await;
|
displayname,
|
||||||
|
custom_profile_fields,
|
||||||
let _ = services
|
})
|
||||||
.rooms
|
}
|
||||||
.timeline
|
|
||||||
.build_and_append_pdu(
|
pub async fn update_displayname(
|
||||||
PartialPdu::state(user_id.to_string(), &membership_content),
|
services: &Services,
|
||||||
user_id,
|
user_id: &UserId,
|
||||||
Some(&room_id),
|
displayname: Option<String>,
|
||||||
&state_lock,
|
all_joined_rooms: &[OwnedRoomId],
|
||||||
)
|
) {
|
||||||
.await;
|
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)
|
||||||
|
.boxed()
|
||||||
|
.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)
|
||||||
|
.boxed()
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
if services.config.allow_local_presence {
|
pub async fn update_all_rooms(
|
||||||
// Send a presence EDU to indicate the profile changed
|
services: &Services,
|
||||||
let _ = services
|
all_joined_rooms: Vec<(PduBuilder, &OwnedRoomId)>,
|
||||||
.presence
|
user_id: &UserId,
|
||||||
.ping_presence(user_id, &PresenceState::Online)
|
) {
|
||||||
.await;
|
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}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
+42
-36
@@ -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::{
|
api::client::{
|
||||||
client::push::{
|
error::ErrorKind,
|
||||||
|
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,7 +80,9 @@ 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::new(PushRulesEventContent::new(global_ruleset.clone()));
|
let event = PushRulesEvent {
|
||||||
|
content: PushRulesEventContent { global: global_ruleset.clone() },
|
||||||
|
};
|
||||||
|
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
@@ -89,7 +91,7 @@ pub(crate) async fn get_pushrules_all_route(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_pushrules_all::v3::Response::new(global_ruleset))
|
Ok(get_pushrules_all::v3::Response { global: global_ruleset })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/global/`
|
/// # `GET /_matrix/client/r0/pushrules/global/`
|
||||||
@@ -114,20 +116,21 @@ 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 global_ruleset = Ruleset::server_default(sender_user);
|
let ty = GlobalAccountDataEventType::PushRules;
|
||||||
let event = PushRulesEvent::new(PushRulesEventContent::new(global_ruleset.clone()));
|
let event = PushRulesEvent {
|
||||||
|
content: PushRulesEventContent {
|
||||||
|
global: Ruleset::server_default(sender_user),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
.update(
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(event)?)
|
||||||
None,
|
|
||||||
sender_user,
|
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
|
||||||
&serde_json::to_value(event)?,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(get_pushrules_global_scope::v3::Response::new(global_ruleset));
|
return Ok(get_pushrules_global_scope::v3::Response {
|
||||||
|
global: Ruleset::server_default(sender_user),
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let account_data_content =
|
let account_data_content =
|
||||||
@@ -170,16 +173,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::new(PushRulesEventContent::new(
|
&serde_json::to_value(PushRulesEvent {
|
||||||
global_ruleset.clone(),
|
content: PushRulesEventContent { global: global_ruleset.clone() },
|
||||||
)))
|
})
|
||||||
.expect("to json always works"),
|
.expect("to json always works"),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_pushrules_global_scope::v3::Response::new(global_ruleset))
|
Ok(get_pushrules_global_scope::v3::Response { global: global_ruleset })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
|
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
|
||||||
@@ -213,7 +216,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::new(rule))
|
Ok(get_pushrule::v3::Response { rule })
|
||||||
} else {
|
} else {
|
||||||
Err!(Request(NotFound("Push rule not found.")))
|
Err!(Request(NotFound("Push rule not found.")))
|
||||||
}
|
}
|
||||||
@@ -272,7 +275,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::new())
|
Ok(set_pushrule::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/actions`
|
/// # `GET /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/actions`
|
||||||
@@ -306,7 +309,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::new(actions))
|
Ok(get_pushrule_actions::v3::Response { actions })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/actions`
|
/// # `PUT /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/actions`
|
||||||
@@ -339,7 +342,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::new())
|
Ok(set_pushrule_actions::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/enabled`
|
/// # `GET /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/enabled`
|
||||||
@@ -357,7 +360,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::new(false));
|
return Ok(get_pushrule_enabled::v3::Response { enabled: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
let event: PushRulesEvent = services
|
let event: PushRulesEvent = services
|
||||||
@@ -373,7 +376,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::new(enabled))
|
Ok(get_pushrule_enabled::v3::Response { enabled })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/enabled`
|
/// # `PUT /_matrix/client/r0/pushrules/global/{kind}/{ruleId}/enabled`
|
||||||
@@ -406,7 +409,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::new())
|
Ok(set_pushrule_enabled::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/pushrules/global/{kind}/{ruleId}`
|
/// # `DELETE /_matrix/client/r0/pushrules/global/{kind}/{ruleId}`
|
||||||
@@ -448,7 +451,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::new())
|
Ok(delete_pushrule::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushers`
|
/// # `GET /_matrix/client/r0/pushers`
|
||||||
@@ -460,7 +463,9 @@ 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::new(services.pusher.get_pushers(sender_user).await))
|
Ok(get_pushers::v3::Response {
|
||||||
|
pushers: services.pusher.get_pushers(sender_user).await,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/pushers/set`
|
/// # `POST /_matrix/client/r0/pushers/set`
|
||||||
@@ -488,18 +493,19 @@ 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 global_ruleset = Ruleset::server_default(sender_user);
|
let ty = GlobalAccountDataEventType::PushRules;
|
||||||
let event = PushRulesEvent::new(PushRulesEventContent::new(global_ruleset.clone()));
|
let event = PushRulesEvent {
|
||||||
|
content: PushRulesEventContent {
|
||||||
|
global: Ruleset::server_default(sender_user),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
.update(
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(event)?)
|
||||||
None,
|
|
||||||
sender_user,
|
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
|
||||||
&serde_json::to_value(event)?,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_pushrules_all::v3::Response::new(global_ruleset))
|
Ok(get_pushrules_all::v3::Response {
|
||||||
|
global: Ruleset::server_default(sender_user),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{Err, PduCount, Result, err};
|
use conduwuit::{Err, PduCount, Result, err};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
MilliSecondsSinceUnixEpoch,
|
MilliSecondsSinceUnixEpoch,
|
||||||
api::client::{read_marker::set_read_marker, receipt::create_receipt},
|
api::client::{read_marker::set_read_marker, receipt::create_receipt},
|
||||||
events::{
|
events::{
|
||||||
RoomAccountDataEventType,
|
RoomAccountDataEventType,
|
||||||
fully_read::{FullyReadEvent, FullyReadEventContent},
|
receipt::{ReceiptThread, ReceiptType},
|
||||||
receipt::{Receipt, ReceiptEvent, ReceiptEventContent, ReceiptType},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -29,7 +28,9 @@ pub(crate) async fn set_read_marker_route(
|
|||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
|
|
||||||
if let Some(event) = &body.fully_read {
|
if let Some(event) = &body.fully_read {
|
||||||
let fully_read_event = FullyReadEvent::new(FullyReadEventContent::new(event.to_owned()));
|
let fully_read_event = ruma::events::fully_read::FullyReadEvent {
|
||||||
|
content: ruma::events::fully_read::FullyReadEventContent { event_id: event.clone() },
|
||||||
|
};
|
||||||
|
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
@@ -61,16 +62,19 @@ pub(crate) async fn set_read_marker_route(
|
|||||||
if services.config.allow_local_read_receipts
|
if services.config.allow_local_read_receipts
|
||||||
&& !services.users.is_suspended(sender_user).await?
|
&& !services.users.is_suspended(sender_user).await?
|
||||||
{
|
{
|
||||||
let receipt_content = [(
|
let receipt_content = BTreeMap::from_iter([(
|
||||||
event.to_owned(),
|
event.to_owned(),
|
||||||
BTreeMap::from_iter([(
|
BTreeMap::from_iter([(
|
||||||
ReceiptType::Read,
|
ReceiptType::Read,
|
||||||
BTreeMap::from_iter([(
|
BTreeMap::from_iter([(
|
||||||
sender_user.to_owned(),
|
sender_user.to_owned(),
|
||||||
Receipt::new(MilliSecondsSinceUnixEpoch::now()),
|
ruma::events::receipt::Receipt {
|
||||||
|
ts: Some(MilliSecondsSinceUnixEpoch::now()),
|
||||||
|
thread: ReceiptThread::Unthreaded,
|
||||||
|
},
|
||||||
)]),
|
)]),
|
||||||
)]),
|
)]),
|
||||||
)];
|
)]);
|
||||||
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -78,10 +82,10 @@ pub(crate) async fn set_read_marker_route(
|
|||||||
.readreceipt_update(
|
.readreceipt_update(
|
||||||
sender_user,
|
sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&ReceiptEvent::new(
|
&ruma::events::receipt::ReceiptEvent {
|
||||||
body.room_id.clone(),
|
content: ruma::events::receipt::ReceiptEventContent(receipt_content),
|
||||||
ReceiptEventContent::from_iter(receipt_content),
|
room_id: body.room_id.clone(),
|
||||||
),
|
},
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
@@ -107,7 +111,7 @@ pub(crate) async fn set_read_marker_route(
|
|||||||
.private_read_set(&body.room_id, sender_user, count);
|
.private_read_set(&body.room_id, sender_user, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(set_read_marker::v3::Response::new())
|
Ok(set_read_marker::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}`
|
||||||
@@ -115,7 +119,7 @@ pub(crate) async fn set_read_marker_route(
|
|||||||
/// Sets private read marker and public read receipt EDU.
|
/// Sets private read marker and public read receipt EDU.
|
||||||
pub(crate) async fn create_receipt_route(
|
pub(crate) async fn create_receipt_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client_ip): InsecureClientIp,
|
ClientIp(client_ip): ClientIp,
|
||||||
body: Ruma<create_receipt::v3::Request>,
|
body: Ruma<create_receipt::v3::Request>,
|
||||||
) -> Result<create_receipt::v3::Response> {
|
) -> Result<create_receipt::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -144,8 +148,11 @@ pub(crate) async fn create_receipt_route(
|
|||||||
|
|
||||||
match body.receipt_type {
|
match body.receipt_type {
|
||||||
| create_receipt::v3::ReceiptType::FullyRead => {
|
| create_receipt::v3::ReceiptType::FullyRead => {
|
||||||
let fully_read_event =
|
let fully_read_event = ruma::events::fully_read::FullyReadEvent {
|
||||||
FullyReadEvent::new(FullyReadEventContent::new(body.event_id.clone()));
|
content: ruma::events::fully_read::FullyReadEventContent {
|
||||||
|
event_id: body.event_id.clone(),
|
||||||
|
},
|
||||||
|
};
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
.update(
|
.update(
|
||||||
@@ -157,16 +164,19 @@ pub(crate) async fn create_receipt_route(
|
|||||||
.await?;
|
.await?;
|
||||||
},
|
},
|
||||||
| create_receipt::v3::ReceiptType::Read => {
|
| create_receipt::v3::ReceiptType::Read => {
|
||||||
let receipt_content = [(
|
let receipt_content = BTreeMap::from_iter([(
|
||||||
body.event_id.clone(),
|
body.event_id.clone(),
|
||||||
BTreeMap::from_iter([(
|
BTreeMap::from_iter([(
|
||||||
ReceiptType::Read,
|
ReceiptType::Read,
|
||||||
BTreeMap::from_iter([(
|
BTreeMap::from_iter([(
|
||||||
sender_user.to_owned(),
|
sender_user.to_owned(),
|
||||||
Receipt::new(MilliSecondsSinceUnixEpoch::now()),
|
ruma::events::receipt::Receipt {
|
||||||
|
ts: Some(MilliSecondsSinceUnixEpoch::now()),
|
||||||
|
thread: ReceiptThread::Unthreaded,
|
||||||
|
},
|
||||||
)]),
|
)]),
|
||||||
)]),
|
)]),
|
||||||
)];
|
)]);
|
||||||
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
@@ -174,10 +184,10 @@ pub(crate) async fn create_receipt_route(
|
|||||||
.readreceipt_update(
|
.readreceipt_update(
|
||||||
sender_user,
|
sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&ReceiptEvent::new(
|
&ruma::events::receipt::ReceiptEvent {
|
||||||
body.room_id.clone(),
|
content: ruma::events::receipt::ReceiptEventContent(receipt_content),
|
||||||
ReceiptEventContent::from_iter(receipt_content),
|
room_id: body.room_id.clone(),
|
||||||
),
|
},
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
},
|
},
|
||||||
@@ -208,5 +218,5 @@ pub(crate) async fn create_receipt_route(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(create_receipt::v3::Response::new())
|
Ok(create_receipt::v3::Response {})
|
||||||
}
|
}
|
||||||
+11
-12
@@ -1,8 +1,8 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{Err, Result, matrix::pdu::PartialPdu};
|
use conduwuit::{Err, Result, matrix::pdu::PduBuilder};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::redact::redact_event, assign, events::room::redaction::RoomRedactionEventContent,
|
api::client::redact::redact_event, events::room::redaction::RoomRedactionEventContent,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
@@ -14,7 +14,7 @@ use crate::Ruma;
|
|||||||
/// - TODO: Handle txn id
|
/// - TODO: Handle txn id
|
||||||
pub(crate) async fn redact_event_route(
|
pub(crate) async fn redact_event_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client_ip): InsecureClientIp,
|
ClientIp(client_ip): ClientIp,
|
||||||
body: Ruma<redact_event::v3::Request>,
|
body: Ruma<redact_event::v3::Request>,
|
||||||
) -> Result<redact_event::v3::Response> {
|
) -> Result<redact_event::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -28,19 +28,18 @@ pub(crate) async fn redact_event_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.as_str()).await;
|
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
||||||
|
|
||||||
let event_id = services
|
let event_id = services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu {
|
PduBuilder {
|
||||||
redacts: Some(body.event_id.clone()),
|
redacts: Some(body.event_id.clone()),
|
||||||
..PartialPdu::timeline(
|
..PduBuilder::timeline(&RoomRedactionEventContent {
|
||||||
&assign!(RoomRedactionEventContent::new_v11(body.event_id.clone()), {
|
redacts: Some(body.event_id.clone()),
|
||||||
reason: body.reason.clone()
|
reason: body.reason.clone(),
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
},
|
},
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
@@ -50,5 +49,5 @@ pub(crate) async fn redact_event_route(
|
|||||||
|
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
Ok(redact_event::v3::Response::new(event_id))
|
Ok(redact_event::v3::Response { event_id })
|
||||||
}
|
}
|
||||||
+13
-15
@@ -15,7 +15,6 @@ use ruma::{
|
|||||||
get_relating_events_with_rel_type_and_event_type,
|
get_relating_events_with_rel_type_and_event_type,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
assign,
|
|
||||||
events::{TimelineEventType, relation::RelationType},
|
events::{TimelineEventType, relation::RelationType},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -40,12 +39,11 @@ pub(crate) async fn get_relating_events_with_rel_type_and_event_type_route(
|
|||||||
body.dir,
|
body.dir,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map(|res| {
|
.map(|res| get_relating_events_with_rel_type_and_event_type::v1::Response {
|
||||||
assign!(get_relating_events_with_rel_type_and_event_type::v1::Response::new(res.chunk), {
|
chunk: res.chunk,
|
||||||
next_batch: res.next_batch,
|
next_batch: res.next_batch,
|
||||||
prev_batch: res.prev_batch,
|
prev_batch: res.prev_batch,
|
||||||
recursion_depth: res.recursion_depth,
|
recursion_depth: res.recursion_depth,
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,12 +66,11 @@ pub(crate) async fn get_relating_events_with_rel_type_route(
|
|||||||
body.dir,
|
body.dir,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map(|res| {
|
.map(|res| get_relating_events_with_rel_type::v1::Response {
|
||||||
assign!(get_relating_events_with_rel_type::v1::Response::new(res.chunk), {
|
chunk: res.chunk,
|
||||||
next_batch: res.next_batch,
|
next_batch: res.next_batch,
|
||||||
prev_batch: res.prev_batch,
|
prev_batch: res.prev_batch,
|
||||||
recursion_depth: res.recursion_depth,
|
recursion_depth: res.recursion_depth,
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,11 +201,12 @@ async fn paginate_relations_with_filter(
|
|||||||
.map(Event::into_format)
|
.map(Event::into_format)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(assign!(get_relating_events::v1::Response::new(chunk), {
|
Ok(get_relating_events::v1::Response {
|
||||||
next_batch,
|
next_batch,
|
||||||
prev_batch: from.map(Into::into),
|
prev_batch: from.map(Into::into),
|
||||||
recursion_depth: recurse.then_some(depth.into()),
|
recursion_depth: recurse.then_some(depth.into()),
|
||||||
}))
|
chunk,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn visibility_filter<Pdu: Event + Send + Sync>(
|
async fn visibility_filter<Pdu: Event + Send + Sync>(
|
||||||
|
|||||||
+43
-37
@@ -1,13 +1,13 @@
|
|||||||
use std::{fmt::Write as _, time::Duration};
|
use std::{fmt::Write as _, time::Duration};
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{Err, Event, Result, debug_info, info, matrix::pdu::PduEvent, utils::ReadyExt};
|
use conduwuit::{Err, Event, Result, debug_info, info, matrix::pdu::PduEvent, utils::ReadyExt};
|
||||||
use conduwuit_service::Services;
|
use conduwuit_service::Services;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
EventId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId,
|
EventId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId,
|
||||||
api::client::{
|
api::client::{
|
||||||
reporting::report_user,
|
report_user,
|
||||||
room::{report_content, report_room},
|
room::{report_content, report_room},
|
||||||
},
|
},
|
||||||
events::{Mentions, room::message::RoomMessageEventContent},
|
events::{Mentions, room::message::RoomMessageEventContent},
|
||||||
@@ -22,18 +22,16 @@ struct Report {
|
|||||||
event_id: Option<OwnedEventId>,
|
event_id: Option<OwnedEventId>,
|
||||||
user_id: Option<OwnedUserId>,
|
user_id: Option<OwnedUserId>,
|
||||||
report_type: String,
|
report_type: String,
|
||||||
reason: String,
|
reason: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_REASON_LENGTH: usize = 2000;
|
|
||||||
|
|
||||||
/// # `POST /_matrix/client/v3/rooms/{roomId}/report`
|
/// # `POST /_matrix/client/v3/rooms/{roomId}/report`
|
||||||
///
|
///
|
||||||
/// Reports an abusive room to homeserver admins
|
/// Reports an abusive room to homeserver admins
|
||||||
#[tracing::instrument(skip_all, fields(%client), name = "report_room", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "report_room", level = "info")]
|
||||||
pub(crate) async fn report_room_route(
|
pub(crate) async fn report_room_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<report_room::v3::Request>,
|
body: Ruma<report_room::v3::Request>,
|
||||||
) -> Result<report_room::v3::Response> {
|
) -> Result<report_room::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -41,10 +39,10 @@ pub(crate) async fn report_room_route(
|
|||||||
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if body.reason.len() > MAX_REASON_LENGTH {
|
if body.reason.as_ref().is_some_and(|s| s.len() > 750) {
|
||||||
return Err!(Request(InvalidParam(
|
return Err!(Request(
|
||||||
"Reason too long, should be {MAX_REASON_LENGTH} bytes or fewer",
|
InvalidParam("Reason too long, should be 750 characters or fewer",)
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
delay_response().await;
|
delay_response().await;
|
||||||
@@ -54,7 +52,8 @@ pub(crate) async fn report_room_route(
|
|||||||
// their discretion.
|
// their discretion.
|
||||||
info!(
|
info!(
|
||||||
"Received room report by user {sender_user} for room {} with reason: \"{}\"",
|
"Received room report by user {sender_user} for room {} with reason: \"{}\"",
|
||||||
body.room_id, body.reason
|
body.room_id,
|
||||||
|
body.reason.as_deref().unwrap_or("")
|
||||||
);
|
);
|
||||||
|
|
||||||
if !services
|
if !services
|
||||||
@@ -79,7 +78,7 @@ pub(crate) async fn report_room_route(
|
|||||||
|
|
||||||
services.admin.send_message(build_report(report)).await.ok();
|
services.admin.send_message(build_report(report)).await.ok();
|
||||||
|
|
||||||
Ok(report_room::v3::Response::new())
|
Ok(report_room::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/v3/rooms/{roomId}/report/{eventId}`
|
/// # `POST /_matrix/client/v3/rooms/{roomId}/report/{eventId}`
|
||||||
@@ -88,7 +87,7 @@ pub(crate) async fn report_room_route(
|
|||||||
#[tracing::instrument(skip_all, fields(%client), name = "report_event", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "report_event", level = "info")]
|
||||||
pub(crate) async fn report_event_route(
|
pub(crate) async fn report_event_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<report_content::v3::Request>,
|
body: Ruma<report_content::v3::Request>,
|
||||||
) -> Result<report_content::v3::Response> {
|
) -> Result<report_content::v3::Response> {
|
||||||
// user authentication
|
// user authentication
|
||||||
@@ -99,22 +98,26 @@ pub(crate) async fn report_event_route(
|
|||||||
|
|
||||||
delay_response().await;
|
delay_response().await;
|
||||||
|
|
||||||
let reason = body
|
|
||||||
.reason
|
|
||||||
.clone()
|
|
||||||
.unwrap_or_else(|| "<no reason provided>".to_owned());
|
|
||||||
|
|
||||||
// check if we know about the reported event ID or if it's invalid
|
// check if we know about the reported event ID or if it's invalid
|
||||||
let Ok(pdu) = services.rooms.timeline.get_pdu(&body.event_id).await else {
|
let Ok(pdu) = services.rooms.timeline.get_pdu(&body.event_id).await else {
|
||||||
return Err!(Request(NotFound("Event ID is not known to us or Event ID is invalid")));
|
return Err!(Request(NotFound("Event ID is not known to us or Event ID is invalid")));
|
||||||
};
|
};
|
||||||
|
|
||||||
is_event_report_valid(&services, &pdu.event_id, &body.room_id, sender_user, &reason, &pdu)
|
is_event_report_valid(
|
||||||
.await?;
|
&services,
|
||||||
|
&pdu.event_id,
|
||||||
|
&body.room_id,
|
||||||
|
sender_user,
|
||||||
|
body.reason.as_ref(),
|
||||||
|
&pdu,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
info!(
|
info!(
|
||||||
"Received event report by user {sender_user} for room {} and event ID {}, with reason: \
|
"Received event report by user {sender_user} for room {} and event ID {}, with reason: \
|
||||||
\"{}\"",
|
\"{}\"",
|
||||||
body.room_id, body.event_id, reason
|
body.room_id,
|
||||||
|
body.event_id,
|
||||||
|
body.reason.as_deref().unwrap_or("")
|
||||||
);
|
);
|
||||||
let report = Report {
|
let report = Report {
|
||||||
sender: sender_user.to_owned(),
|
sender: sender_user.to_owned(),
|
||||||
@@ -122,17 +125,17 @@ pub(crate) async fn report_event_route(
|
|||||||
event_id: Some(body.event_id.clone()),
|
event_id: Some(body.event_id.clone()),
|
||||||
user_id: None,
|
user_id: None,
|
||||||
report_type: "event".to_owned(),
|
report_type: "event".to_owned(),
|
||||||
reason,
|
reason: body.reason.clone(),
|
||||||
};
|
};
|
||||||
services.admin.send_message(build_report(report)).await.ok();
|
services.admin.send_message(build_report(report)).await.ok();
|
||||||
|
|
||||||
Ok(report_content::v3::Response::new())
|
Ok(report_content::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(%client), name = "report_user", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "report_user", level = "info")]
|
||||||
pub(crate) async fn report_user_route(
|
pub(crate) async fn report_user_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<report_user::v3::Request>,
|
body: Ruma<report_user::v3::Request>,
|
||||||
) -> Result<report_user::v3::Response> {
|
) -> Result<report_user::v3::Response> {
|
||||||
// user authentication
|
// user authentication
|
||||||
@@ -141,17 +144,17 @@ pub(crate) async fn report_user_route(
|
|||||||
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if body.reason.len() > MAX_REASON_LENGTH {
|
if body.reason.as_ref().is_some_and(|s| s.len() > 750) {
|
||||||
return Err!(Request(InvalidParam(
|
return Err!(Request(
|
||||||
"Reason too long, should be {MAX_REASON_LENGTH} bytes or fewer",
|
InvalidParam("Reason too long, should be 750 characters or fewer",)
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
delay_response().await;
|
delay_response().await;
|
||||||
|
|
||||||
if !services.users.is_active_local(&body.user_id).await {
|
if !services.users.is_active_local(&body.user_id).await {
|
||||||
// return 200 as to not reveal if the user exists. Recommended by spec.
|
// return 200 as to not reveal if the user exists. Recommended by spec.
|
||||||
return Ok(report_user::v3::Response::new());
|
return Ok(report_user::v3::Response {});
|
||||||
}
|
}
|
||||||
|
|
||||||
let report = Report {
|
let report = Report {
|
||||||
@@ -165,12 +168,13 @@ pub(crate) async fn report_user_route(
|
|||||||
|
|
||||||
info!(
|
info!(
|
||||||
"Received room report from {sender_user} for user {} with reason: \"{}\"",
|
"Received room report from {sender_user} for user {} with reason: \"{}\"",
|
||||||
body.user_id, body.reason
|
body.user_id,
|
||||||
|
body.reason.as_deref().unwrap_or("")
|
||||||
);
|
);
|
||||||
|
|
||||||
services.admin.send_message(build_report(report)).await.ok();
|
services.admin.send_message(build_report(report)).await.ok();
|
||||||
|
|
||||||
Ok(report_user::v3::Response::new())
|
Ok(report_user::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// in the following order:
|
/// in the following order:
|
||||||
@@ -184,7 +188,7 @@ async fn is_event_report_valid(
|
|||||||
event_id: &EventId,
|
event_id: &EventId,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
sender_user: &UserId,
|
sender_user: &UserId,
|
||||||
reason: &str,
|
reason: Option<&String>,
|
||||||
pdu: &PduEvent,
|
pdu: &PduEvent,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
debug_info!(
|
debug_info!(
|
||||||
@@ -196,10 +200,10 @@ async fn is_event_report_valid(
|
|||||||
return Err!(Request(NotFound("Event ID does not belong to the reported room",)));
|
return Err!(Request(NotFound("Event ID does not belong to the reported room",)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if reason.len() > MAX_REASON_LENGTH {
|
if reason.as_ref().is_some_and(|s| s.len() > 750) {
|
||||||
return Err!(Request(InvalidParam(
|
return Err!(Request(
|
||||||
"Reason too long, should be {MAX_REASON_LENGTH} bytes or fewer",
|
InvalidParam("Reason too long, should be 750 characters or fewer",)
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !services
|
if !services
|
||||||
@@ -228,7 +232,9 @@ fn build_report(report: Report) -> RoomMessageEventContent {
|
|||||||
if report.event_id.is_some() {
|
if report.event_id.is_some() {
|
||||||
let _ = writeln!(text, "- Reported Event ID: `{}`", report.event_id.unwrap());
|
let _ = writeln!(text, "- Reported Event ID: `{}`", report.event_id.unwrap());
|
||||||
}
|
}
|
||||||
let _ = writeln!(text, "- Report Reason: {}", report.reason);
|
if let Some(reason) = report.reason {
|
||||||
|
let _ = writeln!(text, "- Report Reason: {reason}");
|
||||||
|
}
|
||||||
|
|
||||||
RoomMessageEventContent::text_markdown(text).add_mentions(Mentions::with_room_mention())
|
RoomMessageEventContent::text_markdown(text).add_mentions(Mentions::with_room_mention())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,13 @@ pub(crate) async fn get_room_aliases_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.",)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let aliases = services
|
Ok(aliases::v3::Response {
|
||||||
.rooms
|
aliases: services
|
||||||
.alias
|
.rooms
|
||||||
.local_aliases_for_room(&body.room_id)
|
.alias
|
||||||
.collect()
|
.local_aliases_for_room(&body.room_id)
|
||||||
.await;
|
.map(ToOwned::to_owned)
|
||||||
|
.collect()
|
||||||
Ok(aliases::v3::Response::new(aliases))
|
.await,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
+126
-90
@@ -2,19 +2,18 @@ use std::collections::{BTreeMap, BTreeSet};
|
|||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, debug, debug_info, err, info,
|
Err, Result, RoomVersion, debug, debug_info, debug_warn, err, info,
|
||||||
matrix::{StateKey, pdu::PartialPdu},
|
matrix::{StateKey, pdu::PduBuilder},
|
||||||
trace, warn,
|
trace, warn,
|
||||||
};
|
};
|
||||||
use conduwuit_service::{Services, appservice::RegistrationInfo};
|
use conduwuit_service::{Services, appservice::RegistrationInfo};
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
CanonicalJsonObject, CanonicalJsonValue, Int, MilliSecondsSinceUnixEpoch, OwnedRoomAliasId,
|
CanonicalJsonObject, Int, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomId, RoomVersionId,
|
||||||
OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, RoomVersionId, UserId,
|
|
||||||
api::client::room::{self, create_room},
|
api::client::room::{self, create_room},
|
||||||
assign,
|
|
||||||
events::{
|
events::{
|
||||||
TimelineEventType,
|
TimelineEventType,
|
||||||
|
invite_permission_config::FilterLevel,
|
||||||
room::{
|
room::{
|
||||||
canonical_alias::RoomCanonicalAliasEventContent,
|
canonical_alias::RoomCanonicalAliasEventContent,
|
||||||
create::RoomCreateEventContent,
|
create::RoomCreateEventContent,
|
||||||
@@ -28,10 +27,8 @@ use ruma::{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
int,
|
int,
|
||||||
room_version_rules::{AuthorizationRules, RoomIdFormatVersion},
|
|
||||||
serde::{JsonObject, Raw},
|
serde::{JsonObject, Raw},
|
||||||
};
|
};
|
||||||
use ruminuwuity::invite_permission_config::FilterLevel;
|
|
||||||
use serde_json::{json, value::to_raw_value};
|
use serde_json::{json, value::to_raw_value};
|
||||||
|
|
||||||
use crate::{Ruma, client::invite_helper};
|
use crate::{Ruma, client::invite_helper};
|
||||||
@@ -84,23 +81,15 @@ pub(crate) async fn create_room_route(
|
|||||||
},
|
},
|
||||||
| None => services.server.config.default_room_version.clone(),
|
| None => services.server.config.default_room_version.clone(),
|
||||||
};
|
};
|
||||||
let room_version_rules = room_version.rules().unwrap();
|
let room_features = RoomVersion::new(&room_version)?;
|
||||||
|
|
||||||
let room_id: Option<OwnedRoomId> = match room_version_rules.room_id_format {
|
let room_id: Option<OwnedRoomId> = if !room_features.room_ids_as_hashes {
|
||||||
| RoomIdFormatVersion::V1 => {
|
match &body.room_id {
|
||||||
// Check for custom room ID field
|
| Some(custom_room_id) => Some(custom_room_id_check(&services, custom_room_id)?),
|
||||||
if let Some(CanonicalJsonValue::String(room_id)) =
|
| None => Some(RoomId::new(services.globals.server_name())),
|
||||||
body.json_body.as_ref().unwrap().get("room_id")
|
}
|
||||||
{
|
} else {
|
||||||
Some(
|
None
|
||||||
RoomId::parse(room_id)
|
|
||||||
.map_err(|_| err!(Request(BadJson("Malformed custom room ID"))))?,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Some(RoomId::new_v1(services.globals.server_name()))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
| _ => None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// check if room ID doesn't already exist instead of erroring on auth check
|
// check if room ID doesn't already exist instead of erroring on auth check
|
||||||
@@ -178,7 +167,7 @@ pub(crate) async fn create_room_route(
|
|||||||
use RoomVersionId::*;
|
use RoomVersionId::*;
|
||||||
|
|
||||||
let mut content = content
|
let mut content = content
|
||||||
.deserialize_as_unchecked::<CanonicalJsonObject>()
|
.deserialize_as::<CanonicalJsonObject>()
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
err!(Request(BadJson(error!(
|
err!(Request(BadJson(error!(
|
||||||
"Failed to deserialise content as canonical JSON: {e}"
|
"Failed to deserialise content as canonical JSON: {e}"
|
||||||
@@ -212,7 +201,8 @@ pub(crate) async fn create_room_route(
|
|||||||
let content = match room_version {
|
let content = match room_version {
|
||||||
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 =>
|
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 =>
|
||||||
RoomCreateEventContent::new_v1(sender_user.to_owned()),
|
RoomCreateEventContent::new_v1(sender_user.to_owned()),
|
||||||
| _ => RoomCreateEventContent::new_v11(),
|
| V11 => RoomCreateEventContent::new_v11(),
|
||||||
|
| _ => RoomCreateEventContent::new_v12(),
|
||||||
};
|
};
|
||||||
let mut content =
|
let mut content =
|
||||||
serde_json::from_str::<CanonicalJsonObject>(to_raw_value(&content)?.get())?;
|
serde_json::from_str::<CanonicalJsonObject>(to_raw_value(&content)?.get())?;
|
||||||
@@ -228,40 +218,27 @@ pub(crate) async fn create_room_route(
|
|||||||
.short
|
.short
|
||||||
.get_or_create_shortroomid(&room_id)
|
.get_or_create_shortroomid(&room_id)
|
||||||
.await;
|
.await;
|
||||||
services.rooms.state.mutex.lock(room_id.as_str()).await
|
services.rooms.state.mutex.lock(&room_id).await
|
||||||
},
|
},
|
||||||
| None => {
|
| None => {
|
||||||
let temp_room_id = RoomId::new_v1(services.globals.server_name());
|
let temp_room_id = RoomId::new(services.globals.server_name());
|
||||||
trace!("Locking temporary room state mutex for {temp_room_id}");
|
trace!("Locking temporary room state mutex for {temp_room_id}");
|
||||||
services.rooms.state.mutex.lock(temp_room_id.as_str()).await
|
services.rooms.state.mutex.lock(&temp_room_id).await
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 1. The room create event
|
// 1. The room create event
|
||||||
debug!("Creating room create event for {sender_user} in room {room_id:?}");
|
debug!("Creating room create event for {sender_user} in room {room_id:?}");
|
||||||
let tmp_id = room_id.as_deref();
|
let tmp_id = room_id.as_deref();
|
||||||
|
|
||||||
// Allow requesters to override the `origin_server_ts` to customize room ids
|
|
||||||
// from v12 onwards
|
|
||||||
let custom_origin_server_ts = body
|
|
||||||
.json_body
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.get("origin_server_ts")
|
|
||||||
.and_then(CanonicalJsonValue::as_integer)
|
|
||||||
.map(Into::into)
|
|
||||||
.and_then(|value: i64| value.try_into().ok())
|
|
||||||
.map(MilliSecondsSinceUnixEpoch);
|
|
||||||
|
|
||||||
let create_event_id = services
|
let create_event_id = services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu {
|
PduBuilder {
|
||||||
event_type: TimelineEventType::RoomCreate,
|
event_type: TimelineEventType::RoomCreate,
|
||||||
content: to_raw_value(&create_content)?,
|
content: to_raw_value(&create_content)?,
|
||||||
state_key: Some(StateKey::new()),
|
state_key: Some(StateKey::new()),
|
||||||
timestamp: custom_origin_server_ts,
|
timestamp: body.origin_server_ts,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
sender_user,
|
sender_user,
|
||||||
@@ -276,27 +253,34 @@ pub(crate) async fn create_room_route(
|
|||||||
| None => {
|
| None => {
|
||||||
let as_room_id = create_event_id.as_str().replace('$', "!");
|
let as_room_id = create_event_id.as_str().replace('$', "!");
|
||||||
trace!("Creating room with v12 room ID {as_room_id}");
|
trace!("Creating room with v12 room ID {as_room_id}");
|
||||||
RoomId::parse(&as_room_id)?.clone()
|
RoomId::parse(&as_room_id)?.to_owned()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
if let Some(expected_room_id) = body.room_id.as_ref() {
|
||||||
|
if expected_room_id.as_str() != room_id.as_str() {
|
||||||
|
return Err!(Request(InvalidParam(
|
||||||
|
"Custom room ID {expected_room_id} does not match the generated room ID \
|
||||||
|
{room_id}.",
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
debug!("Room created with ID {room_id}");
|
debug!("Room created with ID {room_id}");
|
||||||
let state_lock = services.rooms.state.mutex.lock(room_id.as_str()).await;
|
let state_lock = services.rooms.state.mutex.lock(&room_id).await;
|
||||||
|
|
||||||
// 2. Let the room creator join
|
// 2. Let the room creator join
|
||||||
|
|
||||||
let mut join_event = RoomMemberEventContent::new(MembershipState::Join);
|
|
||||||
join_event.displayname = services.users.displayname(sender_user).await.ok();
|
|
||||||
join_event.avatar_url = services.users.avatar_url(sender_user).await.ok();
|
|
||||||
join_event.blurhash = services.users.blurhash(sender_user).await.ok();
|
|
||||||
join_event.is_direct = Some(body.is_direct);
|
|
||||||
|
|
||||||
debug_info!("Joining {sender_user} to room {room_id}");
|
debug_info!("Joining {sender_user} to room {room_id}");
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(sender_user.to_string(), &join_event),
|
PduBuilder::state(sender_user.to_string(), &RoomMemberEventContent {
|
||||||
|
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(),
|
||||||
|
is_direct: Some(body.is_direct),
|
||||||
|
..RoomMemberEventContent::new(MembershipState::Join)
|
||||||
|
}),
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&room_id),
|
Some(&room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -322,10 +306,7 @@ pub(crate) async fn create_room_route(
|
|||||||
|
|
||||||
let mut creators: Vec<OwnedUserId> = vec![sender_user.to_owned()];
|
let mut creators: Vec<OwnedUserId> = vec![sender_user.to_owned()];
|
||||||
// Do we care about additional_creators?
|
// Do we care about additional_creators?
|
||||||
if room_version_rules
|
if room_features.explicitly_privilege_room_creators {
|
||||||
.authorization
|
|
||||||
.explicitly_privilege_room_creators
|
|
||||||
{
|
|
||||||
// Have they been specified?
|
// Have they been specified?
|
||||||
if let Some(additional_creators) = create_content.get("additional_creators") {
|
if let Some(additional_creators) = create_content.get("additional_creators") {
|
||||||
// Are they a real array?
|
// Are they a real array?
|
||||||
@@ -335,9 +316,9 @@ pub(crate) async fn create_room_route(
|
|||||||
// Are they a string?
|
// Are they a string?
|
||||||
if let Some(creator) = creator.as_str() {
|
if let Some(creator) = creator.as_str() {
|
||||||
// Do they parse into a real user ID?
|
// Do they parse into a real user ID?
|
||||||
if let Ok(creator) = UserId::parse(creator) {
|
if let Ok(creator) = OwnedUserId::parse(creator) {
|
||||||
// Add them to the power levels and creators
|
// Add them to the power levels and creators
|
||||||
creators.push(creator);
|
creators.push(creator.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -350,20 +331,17 @@ pub(crate) async fn create_room_route(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let power_levels_content = default_power_levels_content(
|
let power_levels_content = default_power_levels_content(
|
||||||
body.power_level_content_override
|
body.power_level_content_override.as_ref(),
|
||||||
.as_ref()
|
|
||||||
.map(Raw::cast_ref),
|
|
||||||
&body.visibility,
|
&body.visibility,
|
||||||
power_levels_to_grant,
|
power_levels_to_grant,
|
||||||
creators,
|
creators,
|
||||||
&room_version_rules.authorization,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu {
|
PduBuilder {
|
||||||
event_type: TimelineEventType::RoomPowerLevels,
|
event_type: TimelineEventType::RoomPowerLevels,
|
||||||
content: to_raw_value(&power_levels_content)?,
|
content: to_raw_value(&power_levels_content)?,
|
||||||
state_key: Some(StateKey::new()),
|
state_key: Some(StateKey::new()),
|
||||||
@@ -382,13 +360,10 @@ pub(crate) async fn create_room_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(
|
PduBuilder::state(String::new(), &RoomCanonicalAliasEventContent {
|
||||||
String::new(),
|
alias: Some(room_alias_id.to_owned()),
|
||||||
&assign!(RoomCanonicalAliasEventContent::new(), {
|
alt_aliases: vec![],
|
||||||
alias: Some(room_alias_id.to_owned()),
|
}),
|
||||||
alt_aliases: vec![],
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&room_id),
|
Some(&room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -404,7 +379,7 @@ pub(crate) async fn create_room_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(
|
PduBuilder::state(
|
||||||
String::new(),
|
String::new(),
|
||||||
&RoomJoinRulesEventContent::new(match preset {
|
&RoomJoinRulesEventContent::new(match preset {
|
||||||
| RoomPreset::PublicChat => JoinRule::Public,
|
| RoomPreset::PublicChat => JoinRule::Public,
|
||||||
@@ -424,7 +399,7 @@ pub(crate) async fn create_room_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(
|
PduBuilder::state(
|
||||||
String::new(),
|
String::new(),
|
||||||
&RoomHistoryVisibilityEventContent::new(HistoryVisibility::Shared),
|
&RoomHistoryVisibilityEventContent::new(HistoryVisibility::Shared),
|
||||||
),
|
),
|
||||||
@@ -440,7 +415,7 @@ pub(crate) async fn create_room_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(
|
PduBuilder::state(
|
||||||
String::new(),
|
String::new(),
|
||||||
&RoomGuestAccessEventContent::new(match preset {
|
&RoomGuestAccessEventContent::new(match preset {
|
||||||
| RoomPreset::PublicChat => GuestAccess::Forbidden,
|
| RoomPreset::PublicChat => GuestAccess::Forbidden,
|
||||||
@@ -456,19 +431,26 @@ pub(crate) async fn create_room_route(
|
|||||||
|
|
||||||
// 6. Events listed in initial_state
|
// 6. Events listed in initial_state
|
||||||
for event in &body.initial_state {
|
for event in &body.initial_state {
|
||||||
let mut partial_pdu = event
|
let mut pdu_builder = event.deserialize_as::<PduBuilder>().map_err(|e| {
|
||||||
.deserialize_as_unchecked::<PartialPdu>()
|
err!(Request(InvalidParam(warn!("Invalid initial state event: {e:?}"))))
|
||||||
.map_err(|e| {
|
})?;
|
||||||
err!(Request(InvalidParam(warn!("Invalid initial state event: {e:?}"))))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
debug_info!("Room creation initial state event: {event:?}");
|
debug_info!("Room creation initial state event: {event:?}");
|
||||||
|
|
||||||
|
// client/appservice workaround: if a user sends an initial_state event with a
|
||||||
|
// state event in there with the content of literally `{}` (not null or empty
|
||||||
|
// string), let's just skip it over and warn.
|
||||||
|
if pdu_builder.content.get().eq("{}") {
|
||||||
|
debug_warn!("skipping empty initial state event with content of `{{}}`: {event:?}");
|
||||||
|
debug_warn!("content: {}", pdu_builder.content.get());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Implicit state key defaults to ""
|
// Implicit state key defaults to ""
|
||||||
partial_pdu.state_key.get_or_insert_with(StateKey::new);
|
pdu_builder.state_key.get_or_insert_with(StateKey::new);
|
||||||
|
|
||||||
// Silently skip encryption events if they are not allowed
|
// Silently skip encryption events if they are not allowed
|
||||||
if partial_pdu.event_type == TimelineEventType::RoomEncryption
|
if pdu_builder.event_type == TimelineEventType::RoomEncryption
|
||||||
&& !services.config.allow_encryption
|
&& !services.config.allow_encryption
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -477,7 +459,7 @@ pub(crate) async fn create_room_route(
|
|||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(partial_pdu, sender_user, Some(&room_id), &state_lock)
|
.build_and_append_pdu(pdu_builder, sender_user, Some(&room_id), &state_lock)
|
||||||
.boxed()
|
.boxed()
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@@ -488,7 +470,7 @@ pub(crate) async fn create_room_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(String::new(), &RoomNameEventContent::new(name.clone())),
|
PduBuilder::state(String::new(), &RoomNameEventContent::new(name.clone())),
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&room_id),
|
Some(&room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -502,7 +484,7 @@ pub(crate) async fn create_room_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(String::new(), &RoomTopicEventContent::new(topic.clone())),
|
PduBuilder::state(String::new(), &RoomTopicEventContent { topic: topic.clone() }),
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&room_id),
|
Some(&room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -557,13 +539,10 @@ fn default_power_levels_content(
|
|||||||
visibility: &room::Visibility,
|
visibility: &room::Visibility,
|
||||||
users: BTreeMap<OwnedUserId, Int>,
|
users: BTreeMap<OwnedUserId, Int>,
|
||||||
creators: Vec<OwnedUserId>,
|
creators: Vec<OwnedUserId>,
|
||||||
authorization_rules: &AuthorizationRules,
|
|
||||||
) -> Result<serde_json::Value> {
|
) -> Result<serde_json::Value> {
|
||||||
let mut power_levels_content =
|
let mut power_levels_content =
|
||||||
serde_json::to_value(assign!(RoomPowerLevelsEventContent::new(authorization_rules), {
|
serde_json::to_value(RoomPowerLevelsEventContent { users, ..Default::default() })
|
||||||
users
|
.expect("event is valid, we just created it");
|
||||||
}))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// secure proper defaults of sensitive/dangerous permissions that moderators
|
// secure proper defaults of sensitive/dangerous permissions that moderators
|
||||||
// (power level 50) should not have easy access to
|
// (power level 50) should not have easy access to
|
||||||
@@ -653,7 +632,7 @@ async fn room_alias_check(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let server_name = services.globals.server_name();
|
let server_name = services.globals.server_name();
|
||||||
let full_room_alias = RoomAliasId::parse(format!("#{room_alias_name}:{server_name}"))
|
let full_room_alias = OwnedRoomAliasId::parse(format!("#{room_alias_name}:{server_name}"))
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
err!(Request(InvalidParam(debug_error!(
|
err!(Request(InvalidParam(debug_error!(
|
||||||
?e,
|
?e,
|
||||||
@@ -688,3 +667,60 @@ async fn room_alias_check(
|
|||||||
|
|
||||||
Ok(full_room_alias)
|
Ok(full_room_alias)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// if a room is being created with a custom room ID, run our checks against it
|
||||||
|
fn custom_room_id_check(services: &Services, custom_room_id: &str) -> Result<OwnedRoomId> {
|
||||||
|
// apply forbidden room alias checks to custom room IDs too
|
||||||
|
if services
|
||||||
|
.globals
|
||||||
|
.forbidden_alias_names()
|
||||||
|
.is_match(custom_room_id)
|
||||||
|
{
|
||||||
|
return Err!(Request(Unknown("Custom room ID is forbidden.")));
|
||||||
|
}
|
||||||
|
|
||||||
|
if custom_room_id.contains(':') {
|
||||||
|
return Err!(Request(InvalidParam(
|
||||||
|
"Custom room ID contained `:` which is not allowed. Please note that this expects a \
|
||||||
|
localpart, not the full room ID.",
|
||||||
|
)));
|
||||||
|
} else if custom_room_id.contains(char::is_whitespace) {
|
||||||
|
return Err!(Request(InvalidParam(
|
||||||
|
"Custom room ID contained spaces which is not valid."
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
let server_name = services.globals.server_name();
|
||||||
|
let mut room_id = custom_room_id.to_owned();
|
||||||
|
if custom_room_id.contains(':') {
|
||||||
|
if !custom_room_id.starts_with('!') {
|
||||||
|
return Err!(Request(InvalidParam(
|
||||||
|
"Custom room ID contains an unexpected `:` which is not allowed.",
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
} else if custom_room_id.starts_with('!') {
|
||||||
|
return Err!(Request(InvalidParam(
|
||||||
|
"Room ID is prefixed with !, but is not fully qualified. You likely did not want \
|
||||||
|
this.",
|
||||||
|
)));
|
||||||
|
} else {
|
||||||
|
room_id = format!("!{custom_room_id}:{server_name}");
|
||||||
|
}
|
||||||
|
OwnedRoomId::parse(room_id)
|
||||||
|
.map_err(Into::into)
|
||||||
|
.and_then(|full_room_id| {
|
||||||
|
if full_room_id
|
||||||
|
.server_name()
|
||||||
|
.expect("failed to extract server name from room ID")
|
||||||
|
!= server_name
|
||||||
|
{
|
||||||
|
Err!(Request(InvalidParam("Custom room ID must be on this server.",)))
|
||||||
|
} else {
|
||||||
|
Ok(full_room_id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.inspect(|full_room_id| {
|
||||||
|
debug_info!(%full_room_id, "Full custom room ID");
|
||||||
|
})
|
||||||
|
.inspect_err(|e| warn!(?e, %custom_room_id, "Failed to create room with custom room ID",))
|
||||||
|
}
|
||||||
@@ -44,5 +44,5 @@ pub(crate) async fn get_room_event_route(
|
|||||||
|
|
||||||
event.set_unsigned(body.sender_user.as_deref());
|
event.set_unsigned(body.sender_user.as_deref());
|
||||||
|
|
||||||
Ok(get_room_event::v3::Response::new(event.into_format()))
|
Ok(get_room_event::v3::Response { event: event.into_format() })
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,7 @@ use conduwuit::{
|
|||||||
utils::{BoolExt, stream::TryTools},
|
utils::{BoolExt, stream::TryTools},
|
||||||
};
|
};
|
||||||
use futures::{FutureExt, TryStreamExt, future::try_join4};
|
use futures::{FutureExt, TryStreamExt, future::try_join4};
|
||||||
use ruma::{
|
use ruma::api::client::room::initial_sync::v3::{PaginationChunk, Request, Response};
|
||||||
api::client::peeking::get_current_state::v3::{PaginationChunk, Request, Response},
|
|
||||||
assign,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
@@ -72,27 +69,29 @@ pub(crate) async fn room_initial_sync_route(
|
|||||||
.boxed()
|
.boxed()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let end = events
|
let messages = PaginationChunk {
|
||||||
.first()
|
start: events.last().map(at!(0)).as_ref().map(ToString::to_string),
|
||||||
.map(at!(0))
|
|
||||||
.as_ref()
|
|
||||||
.map(ToString::to_string)
|
|
||||||
.unwrap_or_default();
|
|
||||||
let start = events.last().map(at!(0)).as_ref().map(ToString::to_string);
|
|
||||||
|
|
||||||
let chunk = events
|
end: events
|
||||||
.into_iter()
|
.first()
|
||||||
.map(at!(1))
|
.map(at!(0))
|
||||||
.map(Event::into_format)
|
.as_ref()
|
||||||
.collect();
|
.map(ToString::to_string)
|
||||||
|
.unwrap_or_default(),
|
||||||
|
|
||||||
let messages = assign!(PaginationChunk::new(chunk, end), { start });
|
chunk: events
|
||||||
|
.into_iter()
|
||||||
|
.map(at!(1))
|
||||||
|
.map(Event::into_format)
|
||||||
|
.collect(),
|
||||||
|
};
|
||||||
|
|
||||||
Ok(assign!(Response::new(room_id.to_owned()), {
|
Ok(Response {
|
||||||
account_data: vec![],
|
room_id: room_id.to_owned(),
|
||||||
state: state,
|
account_data: None,
|
||||||
|
state: state.into(),
|
||||||
messages: messages.chunk.is_empty().or_some(messages),
|
messages: messages.chunk.is_empty().or_some(messages),
|
||||||
visibility: visibility.into(),
|
visibility: visibility.into(),
|
||||||
membership,
|
membership,
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,10 @@ mod summary;
|
|||||||
mod upgrade;
|
mod upgrade;
|
||||||
|
|
||||||
pub(crate) use self::{
|
pub(crate) use self::{
|
||||||
aliases::get_room_aliases_route, create::create_room_route, event::get_room_event_route,
|
aliases::get_room_aliases_route,
|
||||||
initial_sync::room_initial_sync_route, summary::get_room_summary,
|
create::create_room_route,
|
||||||
|
event::get_room_event_route,
|
||||||
|
initial_sync::room_initial_sync_route,
|
||||||
|
summary::{get_room_summary, get_room_summary_legacy},
|
||||||
upgrade::upgrade_room_route,
|
upgrade::upgrade_room_route,
|
||||||
};
|
};
|
||||||
+322
-19
@@ -1,20 +1,57 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::ClientIp;
|
||||||
use conduwuit::{Err, Result};
|
use conduwuit::{
|
||||||
use ruma::api::client::room::get_summary;
|
Err, Result, debug, debug_warn, info, trace,
|
||||||
use service::rooms::summary::Accessibility;
|
utils::{IterStream, future::TryExtExt},
|
||||||
|
};
|
||||||
|
use futures::{
|
||||||
|
FutureExt, StreamExt, TryFutureExt,
|
||||||
|
future::{OptionFuture, join3},
|
||||||
|
stream::FuturesUnordered,
|
||||||
|
};
|
||||||
|
use ruma::{
|
||||||
|
OwnedServerName, RoomId, UserId,
|
||||||
|
api::{
|
||||||
|
client::room::get_summary,
|
||||||
|
federation::space::{SpaceHierarchyParentSummary, get_hierarchy},
|
||||||
|
},
|
||||||
|
events::room::member::MembershipState,
|
||||||
|
space::SpaceRoomJoinRule::{self, *},
|
||||||
|
};
|
||||||
|
use service::Services;
|
||||||
|
|
||||||
use crate::Ruma;
|
use crate::{Ruma, RumaResponse};
|
||||||
|
|
||||||
|
/// # `GET /_matrix/client/unstable/im.nheko.summary/rooms/{roomIdOrAlias}/summary`
|
||||||
|
///
|
||||||
|
/// Returns a short description of the state of a room.
|
||||||
|
///
|
||||||
|
/// This is the "wrong" endpoint that some implementations/clients may use
|
||||||
|
/// according to the MSC. Request and response bodies are the same as
|
||||||
|
/// `get_room_summary`.
|
||||||
|
///
|
||||||
|
/// An implementation of [MSC3266](https://github.com/matrix-org/matrix-spec-proposals/pull/3266)
|
||||||
|
pub(crate) async fn get_room_summary_legacy(
|
||||||
|
State(services): State<crate::State>,
|
||||||
|
ClientIp(client): ClientIp,
|
||||||
|
body: Ruma<get_summary::msc3266::Request>,
|
||||||
|
) -> Result<RumaResponse<get_summary::msc3266::Response>> {
|
||||||
|
get_room_summary(State(services), ClientIp(client), body)
|
||||||
|
.boxed()
|
||||||
|
.await
|
||||||
|
.map(RumaResponse)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # `GET /_matrix/client/unstable/im.nheko.summary/summary/{roomIdOrAlias}`
|
||||||
/// # `GET /_matrix/client/v1/room_summary/{roomIdOrAlias}`
|
/// # `GET /_matrix/client/v1/room_summary/{roomIdOrAlias}`
|
||||||
///
|
///
|
||||||
/// Returns a short description of the state of a room.
|
/// Returns a short description of the state of a room.
|
||||||
#[tracing::instrument(skip_all, fields(%client), name = "room_summary", level = "info")]
|
#[tracing::instrument(skip_all, fields(%client), name = "room_summary", level = "info")]
|
||||||
pub(crate) async fn get_room_summary(
|
pub(crate) async fn get_room_summary(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
InsecureClientIp(client): InsecureClientIp,
|
ClientIp(client): ClientIp,
|
||||||
body: Ruma<get_summary::v1::Request>,
|
body: Ruma<get_summary::msc3266::Request>,
|
||||||
) -> Result<get_summary::v1::Response> {
|
) -> Result<get_summary::msc3266::Response> {
|
||||||
let (room_id, servers) = services
|
let (room_id, servers) = services
|
||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
@@ -25,19 +62,285 @@ pub(crate) async fn get_room_summary(
|
|||||||
return Err!(Request(Forbidden("This room is banned on this homeserver.")));
|
return Err!(Request(Forbidden("This room is banned on this homeserver.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
let summary = services
|
room_summary_response(&services, &room_id, &servers, body.sender_user.as_deref())
|
||||||
.rooms
|
.boxed()
|
||||||
.summary
|
.await
|
||||||
.get_room_summary_for_user(body.sender_user.as_deref(), &room_id, &servers)
|
}
|
||||||
.await?;
|
|
||||||
|
|
||||||
match summary {
|
async fn room_summary_response(
|
||||||
| Accessibility::Accessible(summary) => Ok(get_summary::v1::Response::new(summary)),
|
services: &Services,
|
||||||
| Accessibility::Inaccessible => {
|
room_id: &RoomId,
|
||||||
Err!(Request(Forbidden("You may not preview this room."), FORBIDDEN))
|
servers: &[OwnedServerName],
|
||||||
|
sender_user: Option<&UserId>,
|
||||||
|
) -> Result<get_summary::msc3266::Response> {
|
||||||
|
if services
|
||||||
|
.rooms
|
||||||
|
.state_cache
|
||||||
|
.server_in_room(services.globals.server_name(), room_id)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
match local_room_summary_response(services, room_id, sender_user)
|
||||||
|
.boxed()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
| Ok(response) => return Ok(response),
|
||||||
|
| Err(e) => {
|
||||||
|
debug_warn!("Failed to get local room summary: {e:?}, falling back to remote");
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let room =
|
||||||
|
remote_room_summary_hierarchy_response(services, room_id, servers, sender_user).await?;
|
||||||
|
|
||||||
|
Ok(get_summary::msc3266::Response {
|
||||||
|
room_id: room_id.to_owned(),
|
||||||
|
canonical_alias: room.canonical_alias,
|
||||||
|
avatar_url: room.avatar_url,
|
||||||
|
guest_can_join: room.guest_can_join,
|
||||||
|
name: room.name,
|
||||||
|
num_joined_members: room.num_joined_members,
|
||||||
|
topic: room.topic,
|
||||||
|
world_readable: room.world_readable,
|
||||||
|
join_rule: room.join_rule,
|
||||||
|
room_type: room.room_type,
|
||||||
|
room_version: room.room_version,
|
||||||
|
encryption: room.encryption,
|
||||||
|
allowed_room_ids: room.allowed_room_ids,
|
||||||
|
membership: sender_user.is_some().then_some(MembershipState::Leave),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn local_room_summary_response(
|
||||||
|
services: &Services,
|
||||||
|
room_id: &RoomId,
|
||||||
|
sender_user: Option<&UserId>,
|
||||||
|
) -> Result<get_summary::msc3266::Response> {
|
||||||
|
trace!(
|
||||||
|
sender_user = sender_user.map(tracing::field::display),
|
||||||
|
"Sending local room summary response for {room_id:?}"
|
||||||
|
);
|
||||||
|
let (join_rule, world_readable, guest_can_join) = join3(
|
||||||
|
services.rooms.state_accessor.get_join_rules(room_id),
|
||||||
|
services.rooms.state_accessor.is_world_readable(room_id),
|
||||||
|
services.rooms.state_accessor.guest_can_join(room_id),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
// Synapse allows server admins to bypass visibility checks.
|
||||||
|
// That seems neat so we'll copy that behaviour.
|
||||||
|
if sender_user.is_none() || !services.users.is_admin(sender_user.unwrap()).await {
|
||||||
|
user_can_see_summary(
|
||||||
|
services,
|
||||||
|
room_id,
|
||||||
|
&join_rule.clone().into(),
|
||||||
|
guest_can_join,
|
||||||
|
world_readable,
|
||||||
|
join_rule.allowed_rooms(),
|
||||||
|
sender_user,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let canonical_alias = services
|
||||||
|
.rooms
|
||||||
|
.state_accessor
|
||||||
|
.get_canonical_alias(room_id)
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
let name = services.rooms.state_accessor.get_name(room_id).ok();
|
||||||
|
|
||||||
|
let topic = services.rooms.state_accessor.get_room_topic(room_id).ok();
|
||||||
|
|
||||||
|
let room_type = services.rooms.state_accessor.get_room_type(room_id).ok();
|
||||||
|
|
||||||
|
let avatar_url = services
|
||||||
|
.rooms
|
||||||
|
.state_accessor
|
||||||
|
.get_avatar(room_id)
|
||||||
|
.map(|res| res.into_option().unwrap_or_default().url);
|
||||||
|
|
||||||
|
let room_version = services.rooms.state.get_room_version(room_id).ok();
|
||||||
|
|
||||||
|
let encryption = services
|
||||||
|
.rooms
|
||||||
|
.state_accessor
|
||||||
|
.get_room_encryption(room_id)
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
let num_joined_members = services
|
||||||
|
.rooms
|
||||||
|
.state_cache
|
||||||
|
.room_joined_count(room_id)
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
let membership: OptionFuture<_> = sender_user
|
||||||
|
.map(|sender_user| {
|
||||||
|
services
|
||||||
|
.rooms
|
||||||
|
.state_accessor
|
||||||
|
.get_member(room_id, sender_user)
|
||||||
|
.map_ok_or(MembershipState::Leave, |content| content.membership)
|
||||||
|
})
|
||||||
|
.into();
|
||||||
|
|
||||||
|
let (
|
||||||
|
canonical_alias,
|
||||||
|
name,
|
||||||
|
num_joined_members,
|
||||||
|
topic,
|
||||||
|
avatar_url,
|
||||||
|
room_type,
|
||||||
|
room_version,
|
||||||
|
encryption,
|
||||||
|
membership,
|
||||||
|
) = futures::join!(
|
||||||
|
canonical_alias,
|
||||||
|
name,
|
||||||
|
num_joined_members,
|
||||||
|
topic,
|
||||||
|
avatar_url,
|
||||||
|
room_type,
|
||||||
|
room_version,
|
||||||
|
encryption,
|
||||||
|
membership,
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(get_summary::msc3266::Response {
|
||||||
|
room_id: room_id.to_owned(),
|
||||||
|
canonical_alias,
|
||||||
|
avatar_url,
|
||||||
|
guest_can_join,
|
||||||
|
name,
|
||||||
|
num_joined_members: num_joined_members.try_into().unwrap_or_default(),
|
||||||
|
topic,
|
||||||
|
world_readable,
|
||||||
|
room_type,
|
||||||
|
room_version,
|
||||||
|
encryption,
|
||||||
|
membership,
|
||||||
|
allowed_room_ids: join_rule.allowed_rooms().map(Into::into).collect(),
|
||||||
|
join_rule: join_rule.into(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// used by MSC3266 to fetch a room's info if we do not know about it
|
||||||
|
async fn remote_room_summary_hierarchy_response(
|
||||||
|
services: &Services,
|
||||||
|
room_id: &RoomId,
|
||||||
|
servers: &[OwnedServerName],
|
||||||
|
sender_user: Option<&UserId>,
|
||||||
|
) -> Result<SpaceHierarchyParentSummary> {
|
||||||
|
trace!(sender_user = ?sender_user.map(tracing::field::display), ?servers, "Sending remote room summary response for {room_id:?}");
|
||||||
|
if !services.config.allow_federation {
|
||||||
|
return Err!(Request(Forbidden("Federation is disabled.")));
|
||||||
|
}
|
||||||
|
|
||||||
|
if services.rooms.metadata.is_disabled(room_id).await {
|
||||||
|
return Err!(Request(Forbidden(
|
||||||
|
"Federaton of room {room_id} is currently disabled on this server."
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if servers.is_empty() {
|
||||||
|
return Err!(Request(MissingParam(
|
||||||
|
"No servers were provided to fetch the room over federation"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
let request = get_hierarchy::v1::Request::new(room_id.to_owned());
|
||||||
|
|
||||||
|
let mut requests: FuturesUnordered<_> = servers
|
||||||
|
.iter()
|
||||||
|
.map(|server| {
|
||||||
|
info!("Fetching room summary for {room_id} from server {server}");
|
||||||
|
services
|
||||||
|
.sending
|
||||||
|
.send_federation_request(server, request.clone())
|
||||||
|
.inspect_ok(move |v| {
|
||||||
|
debug!("Fetched room summary for {room_id} from server {server}: {v:?}");
|
||||||
|
})
|
||||||
|
.inspect_err(move |e| {
|
||||||
|
info!("Failed to fetch room summary for {room_id} from server {server}: {e}");
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
while let Some(Ok(response)) = requests.next().await {
|
||||||
|
trace!("{response:?}");
|
||||||
|
let room = response.room.clone();
|
||||||
|
if room.room_id != room_id {
|
||||||
|
debug_warn!(
|
||||||
|
"Room ID {} returned does not belong to the requested room ID {}",
|
||||||
|
room.room_id,
|
||||||
|
room_id
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if sender_user.is_none() || !services.users.is_admin(sender_user.unwrap()).await {
|
||||||
|
return user_can_see_summary(
|
||||||
|
services,
|
||||||
|
room_id,
|
||||||
|
&room.join_rule,
|
||||||
|
room.guest_can_join,
|
||||||
|
room.world_readable,
|
||||||
|
room.allowed_room_ids.iter().map(AsRef::as_ref),
|
||||||
|
sender_user,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map(|()| room);
|
||||||
|
}
|
||||||
|
return Ok(room);
|
||||||
|
}
|
||||||
|
|
||||||
|
Err!(Request(NotFound("Room not found or is not accessible")))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn user_can_see_summary<'a, I>(
|
||||||
|
services: &Services,
|
||||||
|
room_id: &RoomId,
|
||||||
|
join_rule: &SpaceRoomJoinRule,
|
||||||
|
guest_can_join: bool,
|
||||||
|
world_readable: bool,
|
||||||
|
allowed_room_ids: I,
|
||||||
|
sender_user: Option<&UserId>,
|
||||||
|
) -> Result
|
||||||
|
where
|
||||||
|
I: Iterator<Item = &'a RoomId> + Send,
|
||||||
|
{
|
||||||
|
let is_public_room = matches!(join_rule, Public | Knock | KnockRestricted);
|
||||||
|
match sender_user {
|
||||||
|
| Some(sender_user) => {
|
||||||
|
let user_can_see_state_events = services
|
||||||
|
.rooms
|
||||||
|
.state_accessor
|
||||||
|
.user_can_see_state_events(sender_user, room_id);
|
||||||
|
let is_guest = services.users.is_deactivated(sender_user).unwrap_or(false);
|
||||||
|
let user_in_allowed_restricted_room = allowed_room_ids
|
||||||
|
.stream()
|
||||||
|
.any(|room| services.rooms.state_cache.is_joined(sender_user, room));
|
||||||
|
|
||||||
|
let (user_can_see_state_events, is_guest, user_in_allowed_restricted_room) =
|
||||||
|
join3(user_can_see_state_events, is_guest, user_in_allowed_restricted_room)
|
||||||
|
.boxed()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
if user_can_see_state_events
|
||||||
|
|| (is_guest && guest_can_join)
|
||||||
|
|| is_public_room
|
||||||
|
|| user_in_allowed_restricted_room
|
||||||
|
{
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
Err!(Request(Forbidden("Room is not accessible")))
|
||||||
},
|
},
|
||||||
| Accessibility::NotFound => {
|
| None => {
|
||||||
Err!(Request(Forbidden("This room does not exist."), FORBIDDEN))
|
if is_public_room || world_readable {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
Err!(Request(Forbidden("Room is not accessible")))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+91
-106
@@ -2,18 +2,16 @@ use std::cmp::max;
|
|||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Error, Event, Result, debug, err, info,
|
Err, Error, Event, Result, RoomVersion, debug, err, info,
|
||||||
matrix::{StateKey, pdu::PartialPdu},
|
matrix::{StateKey, pdu::PduBuilder},
|
||||||
};
|
};
|
||||||
use futures::{FutureExt, StreamExt};
|
use futures::{FutureExt, StreamExt};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
CanonicalJsonObject, RoomId, RoomVersionId,
|
CanonicalJsonObject, RoomId, RoomVersionId,
|
||||||
api::{client::room::upgrade_room, error::ErrorKind},
|
api::client::{error::ErrorKind, room::upgrade_room},
|
||||||
assign,
|
|
||||||
events::{
|
events::{
|
||||||
StateEventType, TimelineEventType,
|
StateEventType, TimelineEventType,
|
||||||
room::{
|
room::{
|
||||||
create::PreviousRoom,
|
|
||||||
member::{MembershipState, RoomMemberEventContent},
|
member::{MembershipState, RoomMemberEventContent},
|
||||||
power_levels::RoomPowerLevelsEventContent,
|
power_levels::RoomPowerLevelsEventContent,
|
||||||
tombstone::RoomTombstoneEventContent,
|
tombstone::RoomTombstoneEventContent,
|
||||||
@@ -21,7 +19,6 @@ use ruma::{
|
|||||||
space::child::{RedactedSpaceChildEventContent, SpaceChildEventContent},
|
space::child::{RedactedSpaceChildEventContent, SpaceChildEventContent},
|
||||||
},
|
},
|
||||||
int,
|
int,
|
||||||
room_version_rules::RoomIdFormatVersion,
|
|
||||||
};
|
};
|
||||||
use serde_json::{json, value::to_raw_value};
|
use serde_json::{json, value::to_raw_value};
|
||||||
|
|
||||||
@@ -79,7 +76,7 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
|
|
||||||
// First, check if the user has permission to upgrade the room (send tombstone
|
// First, check if the user has permission to upgrade the room (send tombstone
|
||||||
// event)
|
// event)
|
||||||
let old_room_state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
|
let old_room_state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
||||||
|
|
||||||
// Check tombstone permission by attempting to create (but not send) the event
|
// Check tombstone permission by attempting to create (but not send) the event
|
||||||
// Note that this does internally call the policy server with a fake room ID,
|
// Note that this does internally call the policy server with a fake room ID,
|
||||||
@@ -88,13 +85,10 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.create_hash_and_sign_event(
|
.create_hash_and_sign_event(
|
||||||
PartialPdu::state(
|
PduBuilder::state(StateKey::new(), &RoomTombstoneEventContent {
|
||||||
StateKey::new(),
|
body: "This room has been replaced".to_owned(),
|
||||||
&RoomTombstoneEventContent::new(
|
replacement_room: RoomId::new(services.globals.server_name()),
|
||||||
String::new(),
|
}),
|
||||||
RoomId::new_v1(services.globals.server_name()),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
&old_room_state_lock,
|
&old_room_state_lock,
|
||||||
@@ -108,19 +102,16 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
drop(old_room_state_lock);
|
drop(old_room_state_lock);
|
||||||
|
|
||||||
// Create a replacement room
|
// Create a replacement room
|
||||||
let room_version_rules = body
|
let room_features = RoomVersion::new(&body.new_version)?;
|
||||||
.new_version
|
let replacement_room_owned = if !room_features.room_ids_as_hashes {
|
||||||
.rules()
|
Some(RoomId::new(services.globals.server_name()))
|
||||||
.expect("new room version should have defined rules");
|
|
||||||
let replacement_room_owned = if room_version_rules.room_id_format == RoomIdFormatVersion::V2 {
|
|
||||||
Some(RoomId::new_v1(services.globals.server_name()))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let replacement_room: Option<&RoomId> = replacement_room_owned.as_ref().map(AsRef::as_ref);
|
let replacement_room: Option<&RoomId> = replacement_room_owned.as_ref().map(AsRef::as_ref);
|
||||||
let replacement_room_tmp = match replacement_room {
|
let replacement_room_tmp = match replacement_room {
|
||||||
| Some(v) => v,
|
| Some(v) => v,
|
||||||
| None => &RoomId::new_v1(services.globals.server_name()),
|
| None => &RoomId::new(services.globals.server_name()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let _short_id = services
|
let _short_id = services
|
||||||
@@ -130,21 +121,18 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
// For pre-v12 rooms, send tombstone before creating replacement room
|
// For pre-v12 rooms, send tombstone before creating replacement room
|
||||||
let tombstone_event_id = if room_version_rules.room_id_format != RoomIdFormatVersion::V2 {
|
let tombstone_event_id = if !room_features.room_ids_as_hashes {
|
||||||
let state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
|
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
||||||
// Send a m.room.tombstone event to the old room to indicate that it is not
|
// Send a m.room.tombstone event to the old room to indicate that it is not
|
||||||
// intended to be used any further
|
// intended to be used any further
|
||||||
let tombstone_event_id = services
|
let tombstone_event_id = services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(
|
PduBuilder::state(StateKey::new(), &RoomTombstoneEventContent {
|
||||||
StateKey::new(),
|
body: "This room has been replaced".to_owned(),
|
||||||
&RoomTombstoneEventContent::new(
|
replacement_room: replacement_room.unwrap().to_owned(),
|
||||||
"This room has been replaced".to_owned(),
|
}),
|
||||||
replacement_room.unwrap().to_owned(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -157,12 +145,7 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let state_lock = services
|
let state_lock = services.rooms.state.mutex.lock(replacement_room_tmp).await;
|
||||||
.rooms
|
|
||||||
.state
|
|
||||||
.mutex
|
|
||||||
.lock(replacement_room_tmp.as_str())
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// Get the old room creation event
|
// Get the old room creation event
|
||||||
let mut create_event_content: CanonicalJsonObject = services
|
let mut create_event_content: CanonicalJsonObject = services
|
||||||
@@ -173,13 +156,10 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
.map_err(|_| err!(Database("Found room without m.room.create event.")))?;
|
.map_err(|_| err!(Database("Found room without m.room.create event.")))?;
|
||||||
|
|
||||||
// Use the m.room.tombstone event as the predecessor
|
// Use the m.room.tombstone event as the predecessor
|
||||||
|
let predecessor = Some(ruma::events::room::create::PreviousRoom::new(
|
||||||
let predecessor = {
|
body.room_id.clone(),
|
||||||
#[allow(deprecated, reason = "Clients still use event_id even though it's deprecated")]
|
tombstone_event_id,
|
||||||
Some(assign!(PreviousRoom::new(body.room_id.clone()), {
|
));
|
||||||
event_id: tombstone_event_id,
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
|
|
||||||
// Send a m.room.create event containing a predecessor field and the applicable
|
// Send a m.room.create event containing a predecessor field and the applicable
|
||||||
// room_version
|
// room_version
|
||||||
@@ -231,7 +211,7 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu {
|
PduBuilder {
|
||||||
event_type: TimelineEventType::RoomCreate,
|
event_type: TimelineEventType::RoomCreate,
|
||||||
content: to_raw_value(&create_event_content)
|
content: to_raw_value(&create_event_content)
|
||||||
.expect("event is valid, we just created it"),
|
.expect("event is valid, we just created it"),
|
||||||
@@ -247,35 +227,39 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
.boxed()
|
.boxed()
|
||||||
.await?;
|
.await?;
|
||||||
let create_id = create_event_id.as_str().replace('$', "!");
|
let create_id = create_event_id.as_str().replace('$', "!");
|
||||||
let (replacement_room, state_lock) =
|
let (replacement_room, state_lock) = if room_features.room_ids_as_hashes {
|
||||||
if room_version_rules.room_id_format == RoomIdFormatVersion::V2 {
|
let parsed_room_id = RoomId::parse(&create_id)?;
|
||||||
let parsed_room_id = RoomId::parse(&create_id)?;
|
(Some(parsed_room_id), services.rooms.state.mutex.lock(parsed_room_id).await)
|
||||||
let lock = services
|
} else {
|
||||||
.rooms
|
(replacement_room, state_lock)
|
||||||
.state
|
};
|
||||||
.mutex
|
|
||||||
.lock(parsed_room_id.as_str())
|
|
||||||
.await;
|
|
||||||
(Some(parsed_room_id), lock)
|
|
||||||
} else {
|
|
||||||
(replacement_room.map(ToOwned::to_owned), state_lock)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Join the new room
|
// Join the new room
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(
|
PduBuilder {
|
||||||
sender_user.as_str(),
|
event_type: TimelineEventType::RoomMember,
|
||||||
&assign!(RoomMemberEventContent::new(MembershipState::Join), {
|
content: to_raw_value(&RoomMemberEventContent {
|
||||||
|
membership: MembershipState::Join,
|
||||||
displayname: services.users.displayname(sender_user).await.ok(),
|
displayname: services.users.displayname(sender_user).await.ok(),
|
||||||
avatar_url: services.users.avatar_url(sender_user).await.ok(),
|
avatar_url: services.users.avatar_url(sender_user).await.ok(),
|
||||||
|
is_direct: None,
|
||||||
|
third_party_invite: None,
|
||||||
blurhash: services.users.blurhash(sender_user).await.ok(),
|
blurhash: services.users.blurhash(sender_user).await.ok(),
|
||||||
}),
|
reason: None,
|
||||||
),
|
join_authorized_via_users_server: None,
|
||||||
|
redact_events: None,
|
||||||
|
})
|
||||||
|
.expect("event is valid, we just created it"),
|
||||||
|
unsigned: None,
|
||||||
|
state_key: Some(sender_user.as_str().into()),
|
||||||
|
redacts: None,
|
||||||
|
timestamp: None,
|
||||||
|
},
|
||||||
sender_user,
|
sender_user,
|
||||||
replacement_room.as_deref(),
|
replacement_room,
|
||||||
&state_lock,
|
&state_lock,
|
||||||
)
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
@@ -322,14 +306,14 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu {
|
PduBuilder {
|
||||||
event_type: event_type.to_string().into(),
|
event_type: event_type.to_string().into(),
|
||||||
content: event_content,
|
content: event_content,
|
||||||
state_key: Some(StateKey::from(state_key)),
|
state_key: Some(StateKey::from(state_key)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
sender_user,
|
sender_user,
|
||||||
replacement_room.as_deref(),
|
replacement_room,
|
||||||
&state_lock,
|
&state_lock,
|
||||||
)
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
@@ -348,27 +332,27 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.remove_alias(&alias, sender_user)
|
.remove_alias(alias, sender_user)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
services.rooms.alias.set_alias(
|
services
|
||||||
&alias,
|
.rooms
|
||||||
replacement_room.as_ref().unwrap(),
|
.alias
|
||||||
sender_user,
|
.set_alias(alias, replacement_room.unwrap(), sender_user)?;
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the old room power levels
|
// Get the old room power levels
|
||||||
let mut power_levels = services
|
let power_levels_event_content: RoomPowerLevelsEventContent = services
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.get_room_power_levels(&body.room_id)
|
.room_state_get_content(&body.room_id, &StateEventType::RoomPowerLevels, "")
|
||||||
.await;
|
.await
|
||||||
|
.map_err(|_| err!(Database("Found room without m.room.power_levels event.")))?;
|
||||||
|
|
||||||
// Setting events_default and invite to the greater of 50 and users_default + 1
|
// Setting events_default and invite to the greater of 50 and users_default + 1
|
||||||
let new_level = max(
|
let new_level = max(
|
||||||
int!(50),
|
int!(50),
|
||||||
power_levels
|
power_levels_event_content
|
||||||
.users_default
|
.users_default
|
||||||
.checked_add(int!(1))
|
.checked_add(int!(1))
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
@@ -376,19 +360,17 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
})?,
|
})?,
|
||||||
);
|
);
|
||||||
|
|
||||||
power_levels.events_default = new_level;
|
|
||||||
power_levels.invite = new_level;
|
|
||||||
|
|
||||||
// Modify the power levels in the old room to prevent sending of events and
|
// Modify the power levels in the old room to prevent sending of events and
|
||||||
// inviting new users
|
// inviting new users
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(
|
PduBuilder::state(StateKey::new(), &RoomPowerLevelsEventContent {
|
||||||
StateKey::new(),
|
events_default: new_level,
|
||||||
&RoomPowerLevelsEventContent::try_from(power_levels).unwrap(),
|
invite: new_level,
|
||||||
),
|
..power_levels_event_content
|
||||||
|
}),
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
@@ -399,21 +381,18 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
// For v12 rooms, send tombstone AFTER creating replacement room
|
// For v12 rooms, send tombstone AFTER creating replacement room
|
||||||
if room_version_rules.room_id_format == RoomIdFormatVersion::V2 {
|
if room_features.room_ids_as_hashes {
|
||||||
let old_room_state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
|
let old_room_state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
||||||
// For v12 rooms, no event reference in predecessor due to cyclic dependency -
|
// For v12 rooms, no event reference in predecessor due to cyclic dependency -
|
||||||
// could best effort one maybe?
|
// could best effort one maybe?
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(
|
PduBuilder::state(StateKey::new(), &RoomTombstoneEventContent {
|
||||||
StateKey::new(),
|
body: "This room has been replaced".to_owned(),
|
||||||
&RoomTombstoneEventContent::new(
|
replacement_room: replacement_room.unwrap().to_owned(),
|
||||||
"This room has been replaced".to_owned(),
|
}),
|
||||||
replacement_room.as_ref().unwrap().to_owned(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
&old_room_state_lock,
|
&old_room_state_lock,
|
||||||
@@ -436,7 +415,7 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.room_state_get_content::<SpaceChildEventContent>(
|
.room_state_get_content::<SpaceChildEventContent>(
|
||||||
&space_id,
|
space_id,
|
||||||
&StateEventType::SpaceChild,
|
&StateEventType::SpaceChild,
|
||||||
body.room_id.as_str(),
|
body.room_id.as_str(),
|
||||||
)
|
)
|
||||||
@@ -448,24 +427,24 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
debug!(
|
debug!(
|
||||||
"Updating space {space_id} child event for room {} to {}",
|
"Updating space {space_id} child event for room {} to {}",
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
replacement_room.as_ref().unwrap()
|
replacement_room.unwrap()
|
||||||
);
|
);
|
||||||
// First, drop the space's child event
|
// First, drop the space's child event
|
||||||
let state_lock = services.rooms.state.mutex.lock(space_id.as_str()).await;
|
let state_lock = services.rooms.state.mutex.lock(space_id).await;
|
||||||
debug!("Removing space child event for room {} in space {space_id}", &body.room_id);
|
debug!("Removing space child event for room {} in space {space_id}", &body.room_id);
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu {
|
PduBuilder {
|
||||||
event_type: StateEventType::SpaceChild.into(),
|
event_type: StateEventType::SpaceChild.into(),
|
||||||
content: to_raw_value(&RedactedSpaceChildEventContent::new())
|
content: to_raw_value(&RedactedSpaceChildEventContent {})
|
||||||
.expect("event is valid, we just created it"),
|
.expect("event is valid, we just created it"),
|
||||||
state_key: Some(body.room_id.clone().as_str().into()),
|
state_key: Some(body.room_id.clone().as_str().into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&space_id),
|
Some(space_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
)
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
@@ -474,21 +453,25 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
// Now, add a new child event for the replacement room
|
// Now, add a new child event for the replacement room
|
||||||
debug!(
|
debug!(
|
||||||
"Adding space child event for room {} in space {space_id}",
|
"Adding space child event for room {} in space {space_id}",
|
||||||
replacement_room.as_ref().unwrap()
|
replacement_room.unwrap()
|
||||||
);
|
);
|
||||||
services
|
services
|
||||||
.rooms
|
.rooms
|
||||||
.timeline
|
.timeline
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(
|
PduBuilder {
|
||||||
replacement_room.as_ref().unwrap().as_str(),
|
event_type: StateEventType::SpaceChild.into(),
|
||||||
&assign!(SpaceChildEventContent::new(vec![sender_user.server_name().to_owned()]), {
|
content: to_raw_value(&SpaceChildEventContent {
|
||||||
|
via: vec![sender_user.server_name().to_owned()],
|
||||||
order: child.order,
|
order: child.order,
|
||||||
suggested: child.suggested,
|
suggested: child.suggested,
|
||||||
}),
|
})
|
||||||
),
|
.expect("event is valid, we just created it"),
|
||||||
|
state_key: Some(replacement_room.unwrap().as_str().into()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
sender_user,
|
sender_user,
|
||||||
Some(&space_id),
|
Some(space_id),
|
||||||
&state_lock,
|
&state_lock,
|
||||||
)
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
@@ -497,11 +480,13 @@ pub(crate) async fn upgrade_room_route(
|
|||||||
debug!(
|
debug!(
|
||||||
"Finished updating space {space_id} child event for room {} to {}",
|
"Finished updating space {space_id} child event for room {} to {}",
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
replacement_room.as_ref().unwrap()
|
replacement_room.unwrap()
|
||||||
);
|
);
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the replacement room id
|
// Return the replacement room id
|
||||||
Ok(upgrade_room::v3::Response::new(replacement_room.as_ref().unwrap().to_owned()))
|
Ok(upgrade_room::v3::Response {
|
||||||
|
replacement_room: replacement_room.unwrap().to_owned(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
+37
-26
@@ -8,17 +8,13 @@ use conduwuit::{
|
|||||||
utils::{IterStream, stream::ReadyExt},
|
utils::{IterStream, stream::ReadyExt},
|
||||||
};
|
};
|
||||||
use conduwuit_service::{Services, rooms::search::RoomQuery};
|
use conduwuit_service::{Services, rooms::search::RoomQuery};
|
||||||
use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt};
|
use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, future::OptionFuture};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedRoomId, RoomId, UInt, UserId,
|
OwnedRoomId, RoomId, UInt, UserId,
|
||||||
api::client::search::search_events::{
|
api::client::search::search_events::{
|
||||||
self,
|
self,
|
||||||
v3::{
|
v3::{Criteria, EventContextResult, ResultCategories, ResultRoomEvents, SearchResult},
|
||||||
Criteria, EventContextResult, ResultCategories, ResultGroupMapsByGroupingKey,
|
|
||||||
ResultRoomEvents, SearchResult,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
assign,
|
|
||||||
events::AnyStateEvent,
|
events::AnyStateEvent,
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
};
|
};
|
||||||
@@ -45,15 +41,20 @@ pub(crate) async fn search_events_route(
|
|||||||
) -> Result<Response> {
|
) -> Result<Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
let next_batch = body.next_batch.as_deref();
|
let next_batch = body.next_batch.as_deref();
|
||||||
|
let room_events_result: OptionFuture<_> = body
|
||||||
|
.search_categories
|
||||||
|
.room_events
|
||||||
|
.as_ref()
|
||||||
|
.map(|criteria| category_room_events(&services, sender_user, next_batch, criteria))
|
||||||
|
.into();
|
||||||
|
|
||||||
let mut result_categories = ResultCategories::new();
|
Ok(Response {
|
||||||
|
search_categories: ResultCategories {
|
||||||
if let Some(criteria) = &body.search_categories.room_events {
|
room_events: Box::pin(room_events_result)
|
||||||
result_categories.room_events =
|
.await
|
||||||
category_room_events(&services, sender_user, next_batch, criteria).await?;
|
.unwrap_or_else(|| Ok(ResultRoomEvents::default()))?,
|
||||||
}
|
},
|
||||||
|
})
|
||||||
Ok(Response::new(result_categories))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::map_unwrap_or)]
|
#[allow(clippy::map_unwrap_or)]
|
||||||
@@ -84,7 +85,14 @@ async fn category_room_events(
|
|||||||
.map(IntoIterator::into_iter)
|
.map(IntoIterator::into_iter)
|
||||||
.map(IterStream::stream)
|
.map(IterStream::stream)
|
||||||
.map(StreamExt::boxed)
|
.map(StreamExt::boxed)
|
||||||
.unwrap_or_else(|| services.rooms.state_cache.rooms_joined(sender_user).boxed());
|
.unwrap_or_else(|| {
|
||||||
|
services
|
||||||
|
.rooms
|
||||||
|
.state_cache
|
||||||
|
.rooms_joined(sender_user)
|
||||||
|
.map(ToOwned::to_owned)
|
||||||
|
.boxed()
|
||||||
|
});
|
||||||
|
|
||||||
let results: Vec<_> = rooms
|
let results: Vec<_> = rooms
|
||||||
.filter_map(|room_id| async move {
|
.filter_map(|room_id| async move {
|
||||||
@@ -121,8 +129,7 @@ async fn category_room_events(
|
|||||||
let total: UInt = results
|
let total: UInt = results
|
||||||
.iter()
|
.iter()
|
||||||
.fold(0, |a: usize, (_, count, _)| a.saturating_add(*count))
|
.fold(0, |a: usize, (_, count, _)| a.saturating_add(*count))
|
||||||
.try_into()
|
.try_into()?;
|
||||||
.expect("total results should fit into a UInt");
|
|
||||||
|
|
||||||
let state: RoomStates = results
|
let state: RoomStates = results
|
||||||
.iter()
|
.iter()
|
||||||
@@ -154,12 +161,16 @@ async fn category_room_events(
|
|||||||
pdu
|
pdu
|
||||||
})
|
})
|
||||||
.map(Event::into_format)
|
.map(Event::into_format)
|
||||||
.map(|result| {
|
.map(|result| SearchResult {
|
||||||
assign!(SearchResult::new(), {
|
rank: None,
|
||||||
rank: None,
|
result: Some(result),
|
||||||
result: Some(result),
|
context: EventContextResult {
|
||||||
context: EventContextResult::default() // TODO
|
profile_info: BTreeMap::new(), //TODO
|
||||||
})
|
events_after: Vec::new(), //TODO
|
||||||
|
events_before: Vec::new(), //TODO
|
||||||
|
start: None, //TODO
|
||||||
|
end: None, //TODO
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
@@ -175,14 +186,14 @@ async fn category_room_events(
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.map(ToString::to_string);
|
.map(ToString::to_string);
|
||||||
|
|
||||||
Ok(assign!(ResultRoomEvents::new(), {
|
Ok(ResultRoomEvents {
|
||||||
count: Some(total),
|
count: Some(total),
|
||||||
next_batch,
|
next_batch,
|
||||||
results,
|
results,
|
||||||
state,
|
state,
|
||||||
highlights,
|
highlights,
|
||||||
groups: ResultGroupMapsByGroupingKey::default(), // TODO
|
groups: BTreeMap::new(), // TODO
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn procure_room_state(services: &Services, room_id: &RoomId) -> Result<RoomState> {
|
async fn procure_room_state(services: &Services, room_id: &RoomId) -> Result<RoomState> {
|
||||||
|
|||||||
Loaded 100 of 295 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user