mirror of
https://forgejo.ellis.link/continuwuation/continuwuity/
synced 2026-07-15 23:48:49 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 51c9828c0a | |||
| c77aa1cb1f | |||
| 68c5bef5f5 | |||
| 8b9e80c69a |
@@ -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 @@
|
|||||||
/// 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 @@
|
|||||||
/// - 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 @@
|
|||||||
/// 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_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 @@
|
|||||||
/// 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 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 @@ fn lazy_loading_enabled(&self) -> bool {
|
|||||||
)]
|
)]
|
||||||
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 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 @@
|
|||||||
/// [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 @@
|
|||||||
/// 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.")));
|
||||||
|
|||||||
@@ -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 @@
|
|||||||
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 @@ pub async fn remove_to_device_events<Until>(
|
|||||||
.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 @@ pub async fn update_device_metadata(
|
|||||||
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