mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-25 09:57:34 +00:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dee936813c | ||
|
|
2cf0923386 | ||
|
|
26483e17ad | ||
|
|
6a8b988b36 | ||
|
|
f1d6536793 | ||
|
|
cf8d8e4ea6 | ||
|
|
393d341f07 | ||
|
|
ba55dffa0e | ||
|
|
f3115e14ab | ||
|
|
b3fa4705ef |
No files matched your search
@@ -54,7 +54,7 @@ runs:
|
|||||||
run: mv /tmp/binaries/sbin/conduwuit /tmp/binaries/conduwuit${{ inputs.cpu_suffix }}-${{ inputs.slug }}${{ inputs.artifact_suffix }}
|
run: mv /tmp/binaries/sbin/conduwuit /tmp/binaries/conduwuit${{ inputs.cpu_suffix }}-${{ inputs.slug }}${{ inputs.artifact_suffix }}
|
||||||
|
|
||||||
- name: Upload binary artifact
|
- name: Upload binary artifact
|
||||||
uses: forgejo/upload-artifact@v4
|
uses: forgejo/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: conduwuit${{ inputs.cpu_suffix }}-${{ inputs.slug }}${{ inputs.artifact_suffix }}
|
name: conduwuit${{ inputs.cpu_suffix }}-${{ inputs.slug }}${{ inputs.artifact_suffix }}
|
||||||
path: /tmp/binaries/conduwuit${{ inputs.cpu_suffix }}-${{ inputs.slug }}${{ inputs.artifact_suffix }}
|
path: /tmp/binaries/conduwuit${{ inputs.cpu_suffix }}-${{ inputs.slug }}${{ inputs.artifact_suffix }}
|
||||||
@@ -62,7 +62,7 @@ runs:
|
|||||||
|
|
||||||
- name: Upload digest
|
- name: Upload digest
|
||||||
if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }}
|
if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }}
|
||||||
uses: forgejo/upload-artifact@v4
|
uses: forgejo/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: digests${{ inputs.digest_suffix }}-${{ inputs.slug }}${{ inputs.cpu_suffix }}
|
name: digests${{ inputs.digest_suffix }}-${{ inputs.slug }}${{ inputs.cpu_suffix }}
|
||||||
path: /tmp/digests/*
|
path: /tmp/digests/*
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ jobs:
|
|||||||
[ -f /etc/conduwuit/conduwuit.toml ] && echo "✅ Config file installed"
|
[ -f /etc/conduwuit/conduwuit.toml ] && echo "✅ Config file installed"
|
||||||
|
|
||||||
- name: Upload deb artifact
|
- name: Upload deb artifact
|
||||||
uses: actions/upload-artifact@v5
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: continuwuity-${{ steps.debian-version.outputs.distribution }}
|
name: continuwuity-${{ steps.debian-version.outputs.distribution }}
|
||||||
path: ${{ steps.cargo-deb.outputs.path }}
|
path: ${{ steps.cargo-deb.outputs.path }}
|
||||||
|
|||||||
@@ -238,13 +238,13 @@ jobs:
|
|||||||
cp $BIN_RPM upload-bin/
|
cp $BIN_RPM upload-bin/
|
||||||
|
|
||||||
- name: Upload binary RPM
|
- name: Upload binary RPM
|
||||||
uses: actions/upload-artifact@v5
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: continuwuity
|
name: continuwuity
|
||||||
path: upload-bin/
|
path: upload-bin/
|
||||||
|
|
||||||
- name: Upload debug RPM artifact
|
- name: Upload debug RPM artifact
|
||||||
uses: actions/upload-artifact@v5
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: continuwuity-debug
|
name: continuwuity-debug
|
||||||
path: artifacts/*debuginfo*.rpm
|
path: artifacts/*debuginfo*.rpm
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ jobs:
|
|||||||
cat ./element-web/webapp/config.json
|
cat ./element-web/webapp/config.json
|
||||||
|
|
||||||
- name: 📤 Upload Artifact
|
- name: 📤 Upload Artifact
|
||||||
uses: forgejo/upload-artifact@v4
|
uses: forgejo/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: element-web
|
name: element-web
|
||||||
path: ./element-web/webapp/
|
path: ./element-web/webapp/
|
||||||
|
|||||||
@@ -586,10 +586,13 @@
|
|||||||
#allow_unstable_room_versions = true
|
#allow_unstable_room_versions = true
|
||||||
|
|
||||||
# Default room version continuwuity will create rooms with.
|
# Default room version continuwuity will create rooms with.
|
||||||
|
# Note that this has to be a string since the room version is a string
|
||||||
|
# rather than an integer. Forgetting the quotes will make the server fail
|
||||||
|
# to start!
|
||||||
#
|
#
|
||||||
# Per spec, room version 11 is the default.
|
# Per spec, room version "11" is the default.
|
||||||
#
|
#
|
||||||
#default_room_version = 11
|
#default_room_version = "11"
|
||||||
|
|
||||||
# Enable OpenTelemetry OTLP tracing export. This replaces the deprecated
|
# Enable OpenTelemetry OTLP tracing export. This replaces the deprecated
|
||||||
# Jaeger exporter. Traces will be sent via OTLP to a collector (such as
|
# Jaeger exporter. Traces will be sent via OTLP to a collector (such as
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"m.homeserver":{"base_url": "https://matrix.continuwuity.org"},"org.matrix.msc3575.proxy":{"url": "https://matrix.continuwuity.org"},"org.matrix.msc4143.rtc_foci":[{"type":"livekit","livekit_service_url":"https://livekit.ellis.link"}]}
|
{"m.homeserver":{"base_url": "https://matrix.continuwuity.org"},"org.matrix.msc3575.proxy":{"url": "https://matrix.continuwuity.org"},"org.matrix.msc4143.rtc_foci":[{"type":"livekit","livekit_service_url":"https://livekit.ellis.link"}]}
|
||||||
+118
-92
@@ -6,6 +6,69 @@
|
|||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
let
|
||||||
|
baseTestScript =
|
||||||
|
pkgs.writers.writePython3Bin "do_test" { libraries = [ pkgs.python3Packages.matrix-nio ]; }
|
||||||
|
''
|
||||||
|
import asyncio
|
||||||
|
import nio
|
||||||
|
|
||||||
|
|
||||||
|
async def main() -> None:
|
||||||
|
# Connect to continuwuity
|
||||||
|
client = nio.AsyncClient("http://continuwuity:6167", "alice")
|
||||||
|
|
||||||
|
# Register as user alice
|
||||||
|
response = await client.register("alice", "my-secret-password")
|
||||||
|
|
||||||
|
# Log in as user alice
|
||||||
|
response = await client.login("my-secret-password")
|
||||||
|
|
||||||
|
# Create a new room
|
||||||
|
response = await client.room_create(federate=False)
|
||||||
|
print("Matrix room create response:", response)
|
||||||
|
assert isinstance(response, nio.RoomCreateResponse)
|
||||||
|
room_id = response.room_id
|
||||||
|
|
||||||
|
# Join the room
|
||||||
|
response = await client.join(room_id)
|
||||||
|
print("Matrix join response:", response)
|
||||||
|
assert isinstance(response, nio.JoinResponse)
|
||||||
|
|
||||||
|
# Send a message to the room
|
||||||
|
response = await client.room_send(
|
||||||
|
room_id=room_id,
|
||||||
|
message_type="m.room.message",
|
||||||
|
content={
|
||||||
|
"msgtype": "m.text",
|
||||||
|
"body": "Hello continuwuity!"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
print("Matrix room send response:", response)
|
||||||
|
assert isinstance(response, nio.RoomSendResponse)
|
||||||
|
|
||||||
|
# Sync responses
|
||||||
|
response = await client.sync(timeout=30000)
|
||||||
|
print("Matrix sync response:", response)
|
||||||
|
assert isinstance(response, nio.SyncResponse)
|
||||||
|
|
||||||
|
# Check the message was received by continuwuity
|
||||||
|
last_message = response.rooms.join[room_id].timeline.events[-1].body
|
||||||
|
assert last_message == "Hello continuwuity!"
|
||||||
|
|
||||||
|
# Leave the room
|
||||||
|
response = await client.room_leave(room_id)
|
||||||
|
print("Matrix room leave response:", response)
|
||||||
|
assert isinstance(response, nio.RoomLeaveResponse)
|
||||||
|
|
||||||
|
# Close the client
|
||||||
|
await client.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
|
'';
|
||||||
|
in
|
||||||
{
|
{
|
||||||
# run some nixos tests as checks
|
# run some nixos tests as checks
|
||||||
checks = lib.pipe self'.packages [
|
checks = lib.pipe self'.packages [
|
||||||
@@ -18,106 +81,69 @@
|
|||||||
# this test was initially yoinked from
|
# this test was initially yoinked from
|
||||||
#
|
#
|
||||||
# https://github.com/NixOS/nixpkgs/blob/960ce26339661b1b69c6f12b9063ca51b688615f/nixos/tests/matrix/continuwuity.nix
|
# https://github.com/NixOS/nixpkgs/blob/960ce26339661b1b69c6f12b9063ca51b688615f/nixos/tests/matrix/continuwuity.nix
|
||||||
(builtins.map (name: {
|
(builtins.concatMap (
|
||||||
name = "test-${name}";
|
name:
|
||||||
value = pkgs.testers.runNixOSTest {
|
builtins.map
|
||||||
inherit name;
|
(
|
||||||
|
{ config, suffix }:
|
||||||
|
{
|
||||||
|
name = "test-${name}-${suffix}";
|
||||||
|
value = pkgs.testers.runNixOSTest {
|
||||||
|
inherit name;
|
||||||
|
|
||||||
nodes = {
|
nodes = {
|
||||||
continuwuity = {
|
continuwuity = {
|
||||||
services.matrix-continuwuity = {
|
services.matrix-continuwuity = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = self'.packages.${name};
|
package = self'.packages.${name};
|
||||||
settings.global = {
|
settings = config;
|
||||||
|
extraEnvironment.RUST_BACKTRACE = "yes";
|
||||||
|
};
|
||||||
|
networking.firewall.allowedTCPPorts = [ 6167 ];
|
||||||
|
};
|
||||||
|
client.environment.systemPackages = [ baseTestScript ];
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript = ''
|
||||||
|
start_all()
|
||||||
|
|
||||||
|
with subtest("start continuwuity"):
|
||||||
|
continuwuity.wait_for_unit("continuwuity.service")
|
||||||
|
continuwuity.wait_for_open_port(6167)
|
||||||
|
|
||||||
|
with subtest("ensure messages can be exchanged"):
|
||||||
|
client.succeed("${lib.getExe baseTestScript} >&2")
|
||||||
|
'';
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
[
|
||||||
|
{
|
||||||
|
suffix = "base";
|
||||||
|
config = {
|
||||||
|
global = {
|
||||||
server_name = name;
|
server_name = name;
|
||||||
address = [ "0.0.0.0" ];
|
address = [ "0.0.0.0" ];
|
||||||
allow_registration = true;
|
allow_registration = true;
|
||||||
yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true;
|
yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true;
|
||||||
};
|
};
|
||||||
extraEnvironment.RUST_BACKTRACE = "yes";
|
|
||||||
};
|
};
|
||||||
networking.firewall.allowedTCPPorts = [ 6167 ];
|
}
|
||||||
};
|
{
|
||||||
client =
|
suffix = "with-room-version";
|
||||||
{ pkgs, ... }:
|
config = {
|
||||||
{
|
global = {
|
||||||
environment.systemPackages = [
|
server_name = name;
|
||||||
(pkgs.writers.writePython3Bin "do_test" { libraries = [ pkgs.python3Packages.matrix-nio ]; } ''
|
address = [ "0.0.0.0" ];
|
||||||
import asyncio
|
allow_registration = true;
|
||||||
import nio
|
yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true;
|
||||||
|
default_room_version = "12";
|
||||||
|
};
|
||||||
async def main() -> None:
|
|
||||||
# Connect to continuwuity
|
|
||||||
client = nio.AsyncClient("http://continuwuity:6167", "alice")
|
|
||||||
|
|
||||||
# Register as user alice
|
|
||||||
response = await client.register("alice", "my-secret-password")
|
|
||||||
|
|
||||||
# Log in as user alice
|
|
||||||
response = await client.login("my-secret-password")
|
|
||||||
|
|
||||||
# Create a new room
|
|
||||||
response = await client.room_create(federate=False)
|
|
||||||
print("Matrix room create response:", response)
|
|
||||||
assert isinstance(response, nio.RoomCreateResponse)
|
|
||||||
room_id = response.room_id
|
|
||||||
|
|
||||||
# Join the room
|
|
||||||
response = await client.join(room_id)
|
|
||||||
print("Matrix join response:", response)
|
|
||||||
assert isinstance(response, nio.JoinResponse)
|
|
||||||
|
|
||||||
# Send a message to the room
|
|
||||||
response = await client.room_send(
|
|
||||||
room_id=room_id,
|
|
||||||
message_type="m.room.message",
|
|
||||||
content={
|
|
||||||
"msgtype": "m.text",
|
|
||||||
"body": "Hello continuwuity!"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
print("Matrix room send response:", response)
|
|
||||||
assert isinstance(response, nio.RoomSendResponse)
|
|
||||||
|
|
||||||
# Sync responses
|
|
||||||
response = await client.sync(timeout=30000)
|
|
||||||
print("Matrix sync response:", response)
|
|
||||||
assert isinstance(response, nio.SyncResponse)
|
|
||||||
|
|
||||||
# Check the message was received by continuwuity
|
|
||||||
last_message = response.rooms.join[room_id].timeline.events[-1].body
|
|
||||||
assert last_message == "Hello continuwuity!"
|
|
||||||
|
|
||||||
# Leave the room
|
|
||||||
response = await client.room_leave(room_id)
|
|
||||||
print("Matrix room leave response:", response)
|
|
||||||
assert isinstance(response, nio.RoomLeaveResponse)
|
|
||||||
|
|
||||||
# Close the client
|
|
||||||
await client.close()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
asyncio.run(main())
|
|
||||||
'')
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
]
|
||||||
testScript = ''
|
))
|
||||||
start_all()
|
|
||||||
|
|
||||||
with subtest("start continuwuity"):
|
|
||||||
continuwuity.wait_for_unit("continuwuity.service")
|
|
||||||
continuwuity.wait_for_open_port(6167)
|
|
||||||
|
|
||||||
with subtest("ensure messages can be exchanged"):
|
|
||||||
client.succeed("do_test >&2")
|
|
||||||
'';
|
|
||||||
|
|
||||||
};
|
|
||||||
}))
|
|
||||||
builtins.listToAttrs
|
builtins.listToAttrs
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_client_ip::InsecureClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, at,
|
Err, Result, at,
|
||||||
matrix::{
|
matrix::{
|
||||||
@@ -70,6 +71,7 @@ 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,
|
||||||
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");
|
debug_assert!(IGNORED_MESSAGE_TYPES.is_sorted(), "IGNORED_MESSAGE_TYPES is not sorted");
|
||||||
@@ -78,6 +80,11 @@ pub(crate) async fn get_message_events_route(
|
|||||||
let room_id = &body.room_id;
|
let room_id = &body.room_id;
|
||||||
let filter = &body.filter;
|
let filter = &body.filter;
|
||||||
|
|
||||||
|
services
|
||||||
|
.users
|
||||||
|
.update_device_last_seen(sender_user, sender_device, client_ip)
|
||||||
|
.await;
|
||||||
|
|
||||||
if !services.rooms.metadata.exists(room_id).await {
|
if !services.rooms.metadata.exists(room_id).await {
|
||||||
return Err!(Request(Forbidden("Room does not exist to this server")));
|
return Err!(Request(Forbidden("Room does not exist to this server")));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_client_ip::InsecureClientIp;
|
||||||
use conduwuit::{Err, PduCount, Result, err};
|
use conduwuit::{Err, PduCount, Result, err};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
MilliSecondsSinceUnixEpoch,
|
MilliSecondsSinceUnixEpoch,
|
||||||
@@ -118,9 +119,14 @@ 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,
|
||||||
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();
|
||||||
|
services
|
||||||
|
.users
|
||||||
|
.update_device_last_seen(sender_user, body.sender_device.as_deref(), client_ip)
|
||||||
|
.await;
|
||||||
|
|
||||||
if matches!(
|
if matches!(
|
||||||
&body.receipt_type,
|
&body.receipt_type,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_client_ip::InsecureClientIp;
|
||||||
use conduwuit::{Err, Result, matrix::pdu::PduBuilder};
|
use conduwuit::{Err, Result, matrix::pdu::PduBuilder};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::redact::redact_event, events::room::redaction::RoomRedactionEventContent,
|
api::client::redact::redact_event, events::room::redaction::RoomRedactionEventContent,
|
||||||
@@ -13,9 +14,14 @@ 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,
|
||||||
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();
|
||||||
|
services
|
||||||
|
.users
|
||||||
|
.update_device_last_seen(sender_user, body.sender_device.as_deref(), client_ip)
|
||||||
|
.await;
|
||||||
let body = &body.body;
|
let body = &body.body;
|
||||||
if services.users.is_suspended(sender_user).await? {
|
if services.users.is_suspended(sender_user).await? {
|
||||||
// TODO: Users can redact their own messages while suspended
|
// TODO: Users can redact their own messages while suspended
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_client_ip::InsecureClientIp;
|
||||||
use conduwuit::{Err, Result, err, matrix::pdu::PduBuilder, utils};
|
use conduwuit::{Err, Result, err, matrix::pdu::PduBuilder, utils};
|
||||||
use ruma::{api::client::message::send_message_event, events::MessageLikeEventType};
|
use ruma::{api::client::message::send_message_event, events::MessageLikeEventType};
|
||||||
use serde_json::from_str;
|
use serde_json::from_str;
|
||||||
@@ -18,6 +19,7 @@ use crate::Ruma;
|
|||||||
/// allowed
|
/// allowed
|
||||||
pub(crate) async fn send_message_event_route(
|
pub(crate) async fn send_message_event_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
|
InsecureClientIp(client_ip): InsecureClientIp,
|
||||||
body: Ruma<send_message_event::v3::Request>,
|
body: Ruma<send_message_event::v3::Request>,
|
||||||
) -> Result<send_message_event::v3::Response> {
|
) -> Result<send_message_event::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
@@ -27,6 +29,11 @@ pub(crate) async fn send_message_event_route(
|
|||||||
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
services
|
||||||
|
.users
|
||||||
|
.update_device_last_seen(sender_user, body.sender_device.as_deref(), client_ip)
|
||||||
|
.await;
|
||||||
|
|
||||||
// Forbid m.room.encrypted if encryption is disabled
|
// Forbid m.room.encrypted if encryption is disabled
|
||||||
if MessageLikeEventType::RoomEncrypted == body.event_type && !services.config.allow_encryption
|
if MessageLikeEventType::RoomEncrypted == body.event_type && !services.config.allow_encryption
|
||||||
{
|
{
|
||||||
|
|||||||
+10
-3
@@ -1,4 +1,5 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_client_ip::InsecureClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Result, err,
|
Err, Result, err,
|
||||||
matrix::{Event, pdu::PduBuilder},
|
matrix::{Event, pdu::PduBuilder},
|
||||||
@@ -7,7 +8,7 @@ use conduwuit::{
|
|||||||
use conduwuit_service::Services;
|
use conduwuit_service::Services;
|
||||||
use futures::{FutureExt, TryStreamExt};
|
use futures::{FutureExt, TryStreamExt};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedEventId, RoomId, UserId,
|
MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId,
|
||||||
api::client::state::{get_state_events, get_state_events_for_key, send_state_event},
|
api::client::state::{get_state_events, get_state_events_for_key, send_state_event},
|
||||||
events::{
|
events::{
|
||||||
AnyStateEventContent, StateEventType,
|
AnyStateEventContent, StateEventType,
|
||||||
@@ -30,9 +31,14 @@ use crate::{Ruma, RumaResponse};
|
|||||||
/// Sends a state event into the room.
|
/// Sends a state event into the room.
|
||||||
pub(crate) async fn send_state_event_for_key_route(
|
pub(crate) async fn send_state_event_for_key_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
body: Ruma<send_state_event::v3::Request>,
|
body: Ruma<send_state_event::v3::Request>,
|
||||||
) -> Result<send_state_event::v3::Response> {
|
) -> Result<send_state_event::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
|
services
|
||||||
|
.users
|
||||||
|
.update_device_last_seen(sender_user, body.sender_device.as_deref(), ip)
|
||||||
|
.await;
|
||||||
|
|
||||||
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.")));
|
||||||
@@ -61,9 +67,10 @@ pub(crate) async fn send_state_event_for_key_route(
|
|||||||
/// Sends a state event into the room.
|
/// Sends a state event into the room.
|
||||||
pub(crate) async fn send_state_event_for_empty_key_route(
|
pub(crate) async fn send_state_event_for_empty_key_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
body: Ruma<send_state_event::v3::Request>,
|
body: Ruma<send_state_event::v3::Request>,
|
||||||
) -> Result<RumaResponse<send_state_event::v3::Response>> {
|
) -> Result<RumaResponse<send_state_event::v3::Response>> {
|
||||||
send_state_event_for_key_route(State(services), body)
|
send_state_event_for_key_route(State(services), InsecureClientIp(ip), body)
|
||||||
.boxed()
|
.boxed()
|
||||||
.await
|
.await
|
||||||
.map(RumaResponse)
|
.map(RumaResponse)
|
||||||
@@ -185,7 +192,7 @@ async fn send_state_event_for_key_helper(
|
|||||||
event_type: &StateEventType,
|
event_type: &StateEventType,
|
||||||
json: &Raw<AnyStateEventContent>,
|
json: &Raw<AnyStateEventContent>,
|
||||||
state_key: &str,
|
state_key: &str,
|
||||||
timestamp: Option<ruma::MilliSecondsSinceUnixEpoch>,
|
timestamp: Option<MilliSecondsSinceUnixEpoch>,
|
||||||
) -> Result<OwnedEventId> {
|
) -> Result<OwnedEventId> {
|
||||||
allowed_to_send_state_event(services, room_id, event_type, state_key, json).await?;
|
allowed_to_send_state_event(services, room_id, event_type, state_key, json).await?;
|
||||||
let state_lock = services.rooms.state.mutex.lock(room_id).await;
|
let state_lock = services.rooms.state.mutex.lock(room_id).await;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_client_ip::InsecureClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Result, extract_variant,
|
Result, extract_variant,
|
||||||
utils::{
|
utils::{
|
||||||
@@ -180,6 +181,7 @@ type PresenceUpdates = HashMap<OwnedUserId, PresenceEventContent>;
|
|||||||
)]
|
)]
|
||||||
pub(crate) async fn sync_events_route(
|
pub(crate) async fn sync_events_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
|
InsecureClientIp(client_ip): InsecureClientIp,
|
||||||
body: Ruma<sync_events::v3::Request>,
|
body: Ruma<sync_events::v3::Request>,
|
||||||
) -> Result<sync_events::v3::Response, RumaResponse<UiaaResponse>> {
|
) -> Result<sync_events::v3::Response, RumaResponse<UiaaResponse>> {
|
||||||
let (sender_user, sender_device) = body.sender();
|
let (sender_user, sender_device) = body.sender();
|
||||||
@@ -192,6 +194,12 @@ pub(crate) async fn sync_events_route(
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Increment the "device last active" metadata
|
||||||
|
services
|
||||||
|
.users
|
||||||
|
.update_device_last_seen(sender_user, Some(sender_device), client_ip)
|
||||||
|
.await;
|
||||||
|
|
||||||
// Setup watchers, so if there's no response, we can wait for them
|
// Setup watchers, so if there's no response, we can wait for them
|
||||||
let watcher = services.sync.watch(sender_user, sender_device);
|
let watcher = services.sync.watch(sender_user, sender_device);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_client_ip::InsecureClientIp;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Error, Result, at, error, extract_variant, is_equal_to,
|
Err, Error, Result, at, error, extract_variant, is_equal_to,
|
||||||
matrix::{Event, TypeStateKey, pdu::PduCount},
|
matrix::{Event, TypeStateKey, pdu::PduCount},
|
||||||
@@ -61,11 +62,18 @@ type KnownRooms = BTreeMap<String, BTreeMap<OwnedRoomId, u64>>;
|
|||||||
/// [MSC4186]: https://github.com/matrix-org/matrix-spec-proposals/pull/4186
|
/// [MSC4186]: https://github.com/matrix-org/matrix-spec-proposals/pull/4186
|
||||||
pub(crate) async fn sync_events_v5_route(
|
pub(crate) async fn sync_events_v5_route(
|
||||||
State(ref services): State<crate::State>,
|
State(ref services): State<crate::State>,
|
||||||
|
InsecureClientIp(client_ip): InsecureClientIp,
|
||||||
body: Ruma<sync_events::v5::Request>,
|
body: Ruma<sync_events::v5::Request>,
|
||||||
) -> Result<sync_events::v5::Response> {
|
) -> Result<sync_events::v5::Response> {
|
||||||
debug_assert!(DEFAULT_BUMP_TYPES.is_sorted(), "DEFAULT_BUMP_TYPES is not sorted");
|
debug_assert!(DEFAULT_BUMP_TYPES.is_sorted(), "DEFAULT_BUMP_TYPES is not sorted");
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
|
services
|
||||||
|
.users
|
||||||
|
.update_device_last_seen(sender_user, Some(sender_device), client_ip)
|
||||||
|
.await;
|
||||||
|
|
||||||
let mut body = body.body;
|
let mut body = body.body;
|
||||||
|
|
||||||
// Setup watchers, so if there's no response, we can wait for them
|
// Setup watchers, so if there's no response, we can wait for them
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
|
use axum_client_ip::InsecureClientIp;
|
||||||
use conduwuit::{Err, Result, utils, utils::math::Tried};
|
use conduwuit::{Err, Result, utils, utils::math::Tried};
|
||||||
use ruma::api::client::typing::create_typing_event;
|
use ruma::api::client::typing::create_typing_event;
|
||||||
|
|
||||||
@@ -9,10 +10,15 @@ use crate::Ruma;
|
|||||||
/// Sets the typing state of the sender user.
|
/// Sets the typing state of the sender user.
|
||||||
pub(crate) async fn create_typing_event_route(
|
pub(crate) async fn create_typing_event_route(
|
||||||
State(services): State<crate::State>,
|
State(services): State<crate::State>,
|
||||||
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
body: Ruma<create_typing_event::v3::Request>,
|
body: Ruma<create_typing_event::v3::Request>,
|
||||||
) -> Result<create_typing_event::v3::Response> {
|
) -> Result<create_typing_event::v3::Response> {
|
||||||
use create_typing_event::v3::Typing;
|
use create_typing_event::v3::Typing;
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
|
services
|
||||||
|
.users
|
||||||
|
.update_device_last_seen(sender_user, body.sender_device.as_deref(), ip)
|
||||||
|
.await;
|
||||||
|
|
||||||
if sender_user != body.user_id && body.appservice_info.is_none() {
|
if sender_user != body.user_id && body.appservice_info.is_none() {
|
||||||
return Err!(Request(Forbidden("You cannot update typing status of other users.")));
|
return Err!(Request(Forbidden("You cannot update typing status of other users.")));
|
||||||
|
|||||||
@@ -703,10 +703,13 @@ pub struct Config {
|
|||||||
pub allow_unstable_room_versions: bool,
|
pub allow_unstable_room_versions: bool,
|
||||||
|
|
||||||
/// Default room version continuwuity will create rooms with.
|
/// Default room version continuwuity will create rooms with.
|
||||||
|
/// Note that this has to be a string since the room version is a string
|
||||||
|
/// rather than an integer. Forgetting the quotes will make the server fail
|
||||||
|
/// to start!
|
||||||
///
|
///
|
||||||
/// Per spec, room version 11 is the default.
|
/// Per spec, room version "11" is the default.
|
||||||
///
|
///
|
||||||
/// default: 11
|
/// default: "11"
|
||||||
#[serde(default = "default_default_room_version")]
|
#[serde(default = "default_default_room_version")]
|
||||||
pub default_room_version: RoomVersionId,
|
pub default_room_version: RoomVersionId,
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#[cfg(feature = "ldap")]
|
#[cfg(feature = "ldap")]
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::{collections::BTreeMap, mem, sync::Arc};
|
use std::{collections::BTreeMap, mem, net::IpAddr, sync::Arc};
|
||||||
|
|
||||||
#[cfg(feature = "ldap")]
|
#[cfg(feature = "ldap")]
|
||||||
use conduwuit::result::LogErr;
|
use conduwuit::result::LogErr;
|
||||||
@@ -25,6 +25,7 @@ use ruma::{
|
|||||||
invite_permission_config::{FilterLevel, InvitePermissionConfigEvent},
|
invite_permission_config::{FilterLevel, InvitePermissionConfigEvent},
|
||||||
},
|
},
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
|
uint,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@@ -980,6 +981,7 @@ impl Service {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates device metadata and increments the device list version.
|
||||||
pub async fn update_device_metadata(
|
pub async fn update_device_metadata(
|
||||||
&self,
|
&self,
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
@@ -987,13 +989,51 @@ impl Service {
|
|||||||
device: &Device,
|
device: &Device,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
increment(&self.db.userid_devicelistversion, user_id.as_bytes());
|
increment(&self.db.userid_devicelistversion, user_id.as_bytes());
|
||||||
|
self.update_device_metadata_no_increment(user_id, device_id, device)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
// Updates device metadata without incrementing the device list version.
|
||||||
|
// This is namely used for updating the last_seen_ip and last_seen_ts values,
|
||||||
|
// as those do not need a device list version bump due to them not being
|
||||||
|
// relevant to other consumers.
|
||||||
|
pub async fn update_device_metadata_no_increment(
|
||||||
|
&self,
|
||||||
|
user_id: &UserId,
|
||||||
|
device_id: &DeviceId,
|
||||||
|
device: &Device,
|
||||||
|
) -> Result<()> {
|
||||||
let key = (user_id, device_id);
|
let key = (user_id, device_id);
|
||||||
self.db.userdeviceid_metadata.put(key, Json(device));
|
self.db.userdeviceid_metadata.put(key, Json(device));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn update_device_last_seen(
|
||||||
|
&self,
|
||||||
|
user_id: &UserId,
|
||||||
|
device_id: Option<&DeviceId>,
|
||||||
|
ip: IpAddr,
|
||||||
|
) {
|
||||||
|
let now = MilliSecondsSinceUnixEpoch::now();
|
||||||
|
if let Some(device_id) = device_id {
|
||||||
|
if let Ok(mut device) = self.get_device_metadata(user_id, device_id).await {
|
||||||
|
device.last_seen_ip = Some(ip.to_string());
|
||||||
|
// If the last update was less than 10 seconds ago, don't update the timestamp
|
||||||
|
if let Some(prev) = device.last_seen_ts {
|
||||||
|
if now.get().saturating_sub(prev.get()) < uint!(10_000) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
device.last_seen_ts = Some(now);
|
||||||
|
|
||||||
|
self.update_device_metadata_no_increment(user_id, device_id, &device)
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get device metadata.
|
/// Get device metadata.
|
||||||
pub async fn get_device_metadata(
|
pub async fn get_device_metadata(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
Reference in new issue
Block a user