Compare commits

...
16 changed files with 207 additions and 59 deletions

No files matched your search

+1 -1
View File
@@ -24,7 +24,7 @@ repos:
- id: check-added-large-files
- repo: https://github.com/crate-ci/typos
rev: v1.52.2
rev: v1.53.0
hooks:
- id: typos
- id: typos
Generated
+11 -11
View File
@@ -5049,7 +5049,7 @@ dependencies = [
[[package]]
name = "ruma"
version = "0.18.0"
source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86"
source = "git+https://github.com/timedoutuk/ruma.git?rev=fd2bf57dfcc2acc30df86054996ce5988bf22d01#fd2bf57dfcc2acc30df86054996ce5988bf22d01"
dependencies = [
"assign",
"js_int",
@@ -5068,7 +5068,7 @@ dependencies = [
[[package]]
name = "ruma-appservice-api"
version = "0.18.0"
source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86"
source = "git+https://github.com/timedoutuk/ruma.git?rev=fd2bf57dfcc2acc30df86054996ce5988bf22d01#fd2bf57dfcc2acc30df86054996ce5988bf22d01"
dependencies = [
"http",
"js_int",
@@ -5081,7 +5081,7 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.26.0"
source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86"
source = "git+https://github.com/timedoutuk/ruma.git?rev=fd2bf57dfcc2acc30df86054996ce5988bf22d01#fd2bf57dfcc2acc30df86054996ce5988bf22d01"
dependencies = [
"as_variant",
"assign",
@@ -5103,7 +5103,7 @@ dependencies = [
[[package]]
name = "ruma-common"
version = "0.21.0"
source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86"
source = "git+https://github.com/timedoutuk/ruma.git?rev=fd2bf57dfcc2acc30df86054996ce5988bf22d01#fd2bf57dfcc2acc30df86054996ce5988bf22d01"
dependencies = [
"as_variant",
"base64 0.23.1",
@@ -5136,7 +5136,7 @@ dependencies = [
[[package]]
name = "ruma-events"
version = "0.36.0"
source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86"
source = "git+https://github.com/timedoutuk/ruma.git?rev=fd2bf57dfcc2acc30df86054996ce5988bf22d01#fd2bf57dfcc2acc30df86054996ce5988bf22d01"
dependencies = [
"as_variant",
"indexmap 2.14.2",
@@ -5157,7 +5157,7 @@ dependencies = [
[[package]]
name = "ruma-federation-api"
version = "0.17.0"
source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86"
source = "git+https://github.com/timedoutuk/ruma.git?rev=fd2bf57dfcc2acc30df86054996ce5988bf22d01#fd2bf57dfcc2acc30df86054996ce5988bf22d01"
dependencies = [
"bytes",
"http",
@@ -5179,7 +5179,7 @@ dependencies = [
[[package]]
name = "ruma-identifiers-validation"
version = "0.14.1"
source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86"
source = "git+https://github.com/timedoutuk/ruma.git?rev=fd2bf57dfcc2acc30df86054996ce5988bf22d01#fd2bf57dfcc2acc30df86054996ce5988bf22d01"
dependencies = [
"js_int",
"thiserror 2.0.21",
@@ -5188,7 +5188,7 @@ dependencies = [
[[package]]
name = "ruma-macros"
version = "0.20.3"
source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86"
source = "git+https://github.com/timedoutuk/ruma.git?rev=fd2bf57dfcc2acc30df86054996ce5988bf22d01#fd2bf57dfcc2acc30df86054996ce5988bf22d01"
dependencies = [
"as_variant",
"cfg-if",
@@ -5204,7 +5204,7 @@ dependencies = [
[[package]]
name = "ruma-push-gateway-api"
version = "0.17.0"
source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86"
source = "git+https://github.com/timedoutuk/ruma.git?rev=fd2bf57dfcc2acc30df86054996ce5988bf22d01#fd2bf57dfcc2acc30df86054996ce5988bf22d01"
dependencies = [
"js_int",
"ruma-common",
@@ -5216,7 +5216,7 @@ dependencies = [
[[package]]
name = "ruma-signatures"
version = "0.23.0"
source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86"
source = "git+https://github.com/timedoutuk/ruma.git?rev=fd2bf57dfcc2acc30df86054996ce5988bf22d01#fd2bf57dfcc2acc30df86054996ce5988bf22d01"
dependencies = [
"base64 0.23.1",
"ed25519-dalek",
@@ -5233,7 +5233,7 @@ dependencies = [
[[package]]
name = "ruma-state-res"
version = "0.19.0"
source = "git+https://github.com/ruma/ruma.git?rev=d6621e1355419c5ef9a7c260b28ae1c0e6722b86#d6621e1355419c5ef9a7c260b28ae1c0e6722b86"
source = "git+https://github.com/timedoutuk/ruma.git?rev=fd2bf57dfcc2acc30df86054996ce5988bf22d01#fd2bf57dfcc2acc30df86054996ce5988bf22d01"
dependencies = [
"js_int",
"ruma-common",
+4 -2
View File
@@ -356,8 +356,8 @@ version = "1.1.1"
# Used for matrix spec type definitions and helpers
[workspace.dependencies.ruma]
git = "https://github.com/ruma/ruma.git"
rev = "d6621e1355419c5ef9a7c260b28ae1c0e6722b86"
git = "https://github.com/timedoutuk/ruma.git"
rev = "fd2bf57dfcc2acc30df86054996ce5988bf22d01"
features = [
"appservice-api-c",
"client-api",
@@ -398,6 +398,8 @@ features = [
"unstable-msc4484",
"unstable-msc4540",
"unstable-msc4560",
"unstable-msc4563",
"unstable-msc4596",
"unstable-extensible-events",
]
+1
View File
@@ -0,0 +1 @@
Added server-side support for [MSC4563: direct_message push rule](https://github.com/matrix-org/matrix-spec-proposals/pull/4563). Contributed by @nex.
+1
View File
@@ -0,0 +1 @@
Implemented support for [MSC4596: Selective Ignores](https://github.com/matrix-org/matrix-spec-proposals/pull/4596).
+30
View File
@@ -2808,6 +2808,36 @@
# env: CONTINUWUITY_EXPERIMENTS__MSC4560
#msc4560 = false
# MSC4563: `direct_message` push rule
#
# Creates a new kind of push rule that creates a notification if a message
# is received in a room that is in the user's direct message list. This
# more accurately identifies direct messages, rather than relying on a "DM
# room" only consisting of two members.
#
# https://github.com/matrix-org/matrix-spec-proposals/pull/4563
#
# env: CONTINUWUITY_EXPERIMENTS__MSC4563
#msc4563 = false
# MSC4596: Selective Ignores
#
# Adds more granular control over ignoring users, introducing
# "soft-ignores", which instructs the server to send ignored messages to
# the client. Useful for moderators that want to see messages from ignored
# users in rooms they moderate, but nowhere else.
#
# Allows for per-room overrides.
#
# This will likely supersede the
# `send_messages_from_ignored_users_to_client` configuration option, which
# is a global setting that applies to all rooms and users.
#
# https://github.com/matrix-org/matrix-spec-proposals/pull/4596
#
# env: CONTINUWUITY_EXPERIMENTS__MSC4596
#msc4596 = false
#[global.experiments.msc2815]
# MSC2815: Proposal to allow room moderators to view redacted event content
#
+2 -1
View File
@@ -53,8 +53,9 @@ pub(crate) async fn invite_user_route(
// silently drop invites to users the sender has ignored
if services
.users
.user_is_ignored(recipient_user, sender_user)
.user_ignore_mode(recipient_user, sender_user, None)
.await
.is_some()
{
return Ok(invite_user::v3::Response::new());
}
+22 -19
View File
@@ -34,6 +34,7 @@ use ruma::{
events::{
AnyStateEvent, StateEventType, SyncEphemeralRoomEvent,
TimelineEventType::{self, *},
ignored_user_list::IgnoredUserMode,
receipt::ReceiptEventContent,
},
serde::Raw,
@@ -305,10 +306,6 @@ where
let server_ignored = services
.moderation
.is_remote_server_ignored(sender_user.server_name());
let user_ignored = services
.users
.user_is_ignored(sender_user, recipient_user)
.await;
if !type_ignored {
// We cannot safely ignore this type
@@ -327,22 +324,28 @@ where
};
}
if user_ignored && !services.config.send_messages_from_ignored_users_to_client {
// the recipient of this PDU has the sender ignored, and we're not
// configured to send ignored messages to clients
return if services.config.experiments.msc4406.is_enabled() {
Err(Error::BadRequest(
ErrorKind::SenderIgnored(SenderIgnoredErrorData::with_sender(
event.sender().to_owned(),
)),
"You have ignored this sender.",
))
} else {
Err!(Request(NotFound("You have ignored the sender of this event.")))
};
}
let user_ignore_mode = services
.users
.user_ignore_mode(sender_user, recipient_user, event.room_id())
.await;
Ok(false)
match user_ignore_mode {
| None | Some(IgnoredUserMode::Soft) => Ok(false),
| _ => {
// the recipient of this PDU has the sender ignored, and we're not
// configured to send ignored messages to clients
if services.config.experiments.msc4406.is_enabled() {
Err(Error::BadRequest(
ErrorKind::SenderIgnored(SenderIgnoredErrorData::with_sender(
event.sender().to_owned(),
)),
"You have ignored this sender.",
))
} else {
Err!(Request(NotFound("You have ignored the sender of this event.")))
}
},
}
}
#[inline]
+2 -1
View File
@@ -189,8 +189,9 @@ pub(crate) async fn create_room_route(
// silently drop invites to users the creator has ignored
if services
.users
.user_is_ignored(recipient_user, sender_user)
.user_ignore_mode(recipient_user, sender_user, None)
.await
.is_some()
{
continue;
}
+4 -2
View File
@@ -33,6 +33,7 @@ use ruma::{
events::{
StateEventType,
TimelineEventType::*,
ignored_user_list::IgnoredUserMode,
room::member::{MembershipState, RoomMemberEventContent},
},
serde::Raw,
@@ -162,8 +163,9 @@ async fn build_ephemeral(
.filter_map(async |(read_user, _, edu)| {
let is_ignored = services
.users
.user_is_ignored(&read_user, syncing_user)
.await;
.user_ignore_mode(&read_user, syncing_user, Some(room_id))
.await
.is_some_and(|mode| matches!(mode, IgnoredUserMode::Hard));
// filter out read receipts for ignored users
is_ignored.or_some(edu)
+5 -2
View File
@@ -42,6 +42,7 @@ use ruma::{
AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncStateEvent,
GlobalAccountDataEventType, StateEventType, TimelineEventType,
direct::DirectEvent,
ignored_user_list::IgnoredUserMode,
room::{
create::RoomCreateEventContent,
member::{MembershipState, RoomMemberEventContent},
@@ -902,8 +903,9 @@ where
.filter_map(|(read_user, _ts, v)| async move {
services
.users
.user_is_ignored(&read_user, sender_user)
.user_ignore_mode(&read_user, sender_user, Some(room_id))
.await
.is_none_or(|mode| matches!(mode, IgnoredUserMode::Soft))
.or_some(v)
})
.collect()
@@ -1173,8 +1175,9 @@ async fn collect_sticky_events(
}
if services
.users
.user_is_ignored(pdu.sender(), sender_user)
.user_ignore_mode(pdu.sender(), sender_user, pdu.room_id())
.await
.is_some_and(|mode| matches!(mode, IgnoredUserMode::Hard))
{
continue;
}
+31
View File
@@ -146,6 +146,37 @@ pub struct Experiments {
/// default: false
#[serde(default)]
pub msc4560: SimpleExperiment,
/// MSC4563: `direct_message` push rule
///
/// Creates a new kind of push rule that creates a notification if a message
/// is received in a room that is in the user's direct message list. This
/// more accurately identifies direct messages, rather than relying on a "DM
/// room" only consisting of two members.
///
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4563
///
/// default: false
#[serde(default)]
pub msc4563: SimpleExperiment,
/// MSC4596: Selective Ignores
///
/// Adds more granular control over ignoring users, introducing
/// "soft-ignores", which instructs the server to send ignored messages to
/// the client. Useful for moderators that want to see messages from ignored
/// users in rooms they moderate, but nowhere else.
///
/// Allows for per-room overrides.
///
/// This will likely supersede the
/// `send_messages_from_ignored_users_to_client` configuration option, which
/// is a global setting that applies to all rooms and users.
///
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4596
///
/// default: false
pub msc4596: SimpleExperiment,
}
/// Represents a "simple" experiment, which is either disabled or enabled.
+36 -7
View File
@@ -2,6 +2,7 @@ mod webpush;
use std::{fmt::Debug, mem, net::IpAddr, sync::Arc};
use assign::assign;
use bytes::BytesMut;
use conduwuit::{config::experiments::ToggledExperiment, utils::response::LimitReadExt};
use conduwuit_core::{
@@ -23,7 +24,10 @@ use ruma::{
v1::{Device, Notification, NotificationCounts, NotificationPriority},
},
},
events::{AnySyncTimelineEvent, TimelineEventType, room::power_levels::RoomPowerLevels},
events::{
AnySyncTimelineEvent, GlobalAccountDataEvent, GlobalAccountDataEventType,
TimelineEventType, direct::DirectEventContent, room::power_levels::RoomPowerLevels,
},
push::{
Action, HighlightTweakValue, PushConditionPowerLevelsCtx, PushConditionRoomCtx,
PushFormat, Ruleset, Tweak,
@@ -36,7 +40,7 @@ use url::Host;
pub use self::webpush::ActivationOutcome;
use self::webpush::Vapid;
use crate::{Dep, client, config, globals, rooms, sending, users};
use crate::{Dep, account_data, client, config, globals, rooms, sending, users};
const PUSH_GATEWAY_SCHEMES: &[&str] = &["http", "https"];
const WEBPUSH_SCHEMES: &[&str] = &["https"];
@@ -57,6 +61,7 @@ pub struct Service {
struct Services {
server: Arc<Server>,
globals: Dep<globals::Service>,
account_data: Dep<account_data::Service>,
config: Dep<config::Service>,
client: Dep<client::Service>,
state_accessor: Dep<rooms::state_accessor::Service>,
@@ -86,6 +91,7 @@ impl crate::Service for Service {
services: Services {
server: args.server.clone(),
globals: args.depend::<globals::Service>("globals"),
account_data: args.depend::<account_data::Service>("account_data"),
client: args.depend::<client::Service>("client"),
config: args.depend::<config::Service>("config"),
state_accessor: args
@@ -488,11 +494,34 @@ impl Service {
.await
.unwrap_or_else(|_| user.localpart().to_owned());
PushConditionRoomCtx::new(
room_id.to_owned(),
room_joined_count,
user.to_owned(),
user_display_name,
let is_direct = self.services.config.experiments.msc4563.is_enabled()
&& self
.services
.account_data
.get_global::<GlobalAccountDataEvent<DirectEventContent>>(
user,
GlobalAccountDataEventType::Direct,
)
.await
.ok()
.and_then(|direct| {
direct
.content
.values()
.flatten()
.any(|dm_room_id| dm_room_id == room_id)
.then_some(())
})
.is_some();
assign!(
PushConditionRoomCtx::new(
room_id.to_owned(),
room_joined_count,
user.to_owned(),
user_display_name,
),
{ is_direct }
)
.with_power_levels(power_levels)
}
+5 -4
View File
@@ -27,6 +27,7 @@ use ruma::{
RoomVersionId, ServerName, UserId,
events::{
AnySyncTimelineEvent, GlobalAccountDataEventType, TimelineEventType,
ignored_user_list::IgnoredUserMode,
push_rules::PushRulesEvent,
room::{
encrypted::Relation,
@@ -402,11 +403,11 @@ impl super::Service {
// Don't notify the sender of their own events, and don't send from ignored users
.ready_filter(|user| *user != pdu.sender())
.filter_map(|recipient_user| async move {
(!self
.services
self.services
.users
.user_is_ignored(pdu.sender(), &recipient_user)
.await)
.user_ignore_mode(pdu.sender(), &recipient_user, pdu.room_id())
.await
.is_none_or(|mode| matches!(mode, IgnoredUserMode::Soft))
.then_some(recipient_user)
})
.collect()
+8 -5
View File
@@ -12,7 +12,10 @@ use ruma::{
appservice::event::push_events::v1::EphemeralData,
federation::transactions::edu::{Edu, TypingContent},
},
events::{EphemeralRoomEvent, SyncEphemeralRoomEvent, typing::TypingEventContent},
events::{
EphemeralRoomEvent, SyncEphemeralRoomEvent, ignored_user_list::IgnoredUserMode,
typing::TypingEventContent,
},
};
use crate::{Dep, globals, sending, sending::EduBuf, sync, users};
@@ -206,11 +209,11 @@ impl Service {
.into_keys()
.stream()
.filter_map(|typing_user_id| async move {
(!self
.services
self.services
.users
.user_is_ignored(&typing_user_id, sender_user)
.await)
.user_ignore_mode(&typing_user_id, sender_user, Some(room_id))
.await
.is_none_or(|mode| matches!(mode, IgnoredUserMode::Soft))
.then_some(typing_user_id)
})
.collect()
+44 -4
View File
@@ -14,11 +14,13 @@ use database::{Deserialized, Json};
use futures::{FutureExt, Stream, StreamExt};
use lettre::Address;
use ruma::{
MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, UserId,
MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, RoomId, UserId,
api::client::profile::PropagateTo,
events::{
GlobalAccountDataEventType, ignored_user_list::IgnoredUserListEvent,
invite_permission_config::InvitePermissionAction, push_rules::PushRulesEvent,
GlobalAccountDataEventType,
ignored_user_list::{IgnoredUserListEvent, IgnoredUserMode},
invite_permission_config::InvitePermissionAction,
push_rules::PushRulesEvent,
room::message::RoomMessageEventContent,
},
profile::ProfileFieldValue,
@@ -65,6 +67,7 @@ impl AccountStatus {
impl super::Service {
/// Returns true/false based on whether the recipient/receiving user has
/// ignored the sender.
#[deprecated(note = "Use user_ignore_mode instead")]
pub async fn user_is_ignored(&self, sender_user: &UserId, recipient_user: &UserId) -> bool {
self.services
.account_data
@@ -79,6 +82,39 @@ impl super::Service {
})
}
/// Returns the recipient's ignore mode for the sender, if the sender is
/// ignored. `None` if the recipient is not ignored at all.
pub async fn user_ignore_mode(
&self,
sender_user: &UserId,
recipient_user: &UserId,
room_id: Option<&RoomId>,
) -> Option<IgnoredUserMode> {
self.services
.account_data
.get_global(recipient_user, GlobalAccountDataEventType::IgnoredUserList)
.await
.ok()
.and_then(|ignored: IgnoredUserListEvent| {
ignored
.content
.ignored_users
.get(sender_user)
.map(ToOwned::to_owned)
})
.map(|ignore_entry| {
if !self.services.config.experiments.msc4596.is_enabled() {
IgnoredUserMode::Hard
} else {
match room_id {
| Some(room_id) => ignore_entry.mode(room_id),
| None => &ignore_entry.mode,
}
.to_owned()
}
})
}
/// Returns the recipient's filter level for an invite from the sender.
///
/// If the sender is ignored by the recipient, `Ignore` is returned.
@@ -89,7 +125,11 @@ impl super::Service {
sender_user: &UserId,
recipient_user: &UserId,
) -> FilterLevel {
if self.user_is_ignored(sender_user, recipient_user).await {
if self
.user_ignore_mode(sender_user, recipient_user, None)
.await
.is_some()
{
FilterLevel::Ignore
} else {
let (stable, unstable) = tokio::join!(