Compare commits

...

7 Commits

Author SHA1 Message Date
Paul Makles
d9cfc9d0e1 chore: bump version to 0.7.12 2024-06-26 18:47:40 +01:00
Paul Makles
64a07d09f4 feat: silent messages and message flags 2024-06-26 18:46:05 +01:00
Paul Makles
00e881799f fix: replace user with target user when editing someone else 2024-06-26 18:24:38 +01:00
Paul Makles
fa598dd6f8 docs: update README.md
Signed-off-by: Paul Makles <me@insrt.uk>
2024-06-26 17:18:10 +01:00
Paul Makles
ac4e2cb10b ci: disable image builds if they're not tagged [skip ci]
(seems like a waste of CPU)
2024-06-26 15:08:12 +01:00
Paul Makles
ec578ab0ef chore: lessen restrictions on interacting with bot users as owner 2024-06-26 15:07:19 +01:00
Paul Makles
ea6ba59841 fix: add DisplayName back to user fields (prevented removing name) 2024-06-26 14:54:06 +01:00
19 changed files with 124 additions and 55 deletions

View File

@@ -2,8 +2,8 @@ name: Docker Test & Publish
on:
push:
branches:
- "main"
# branches:
# - "main"
tags:
- "*"
paths-ignore:

16
Cargo.lock generated
View File

@@ -3452,7 +3452,7 @@ dependencies = [
[[package]]
name = "revolt-bonfire"
version = "0.7.11"
version = "0.7.12"
dependencies = [
"async-channel 2.3.1",
"async-std",
@@ -3482,7 +3482,7 @@ dependencies = [
[[package]]
name = "revolt-config"
version = "0.7.11"
version = "0.7.12"
dependencies = [
"async-std",
"cached",
@@ -3498,7 +3498,7 @@ dependencies = [
[[package]]
name = "revolt-database"
version = "0.7.11"
version = "0.7.12"
dependencies = [
"async-lock",
"async-recursion",
@@ -3544,7 +3544,7 @@ dependencies = [
[[package]]
name = "revolt-delta"
version = "0.7.11"
version = "0.7.12"
dependencies = [
"async-channel 1.6.1",
"async-std",
@@ -3591,7 +3591,7 @@ dependencies = [
[[package]]
name = "revolt-models"
version = "0.7.11"
version = "0.7.12"
dependencies = [
"indexmap",
"iso8601-timestamp 0.2.11",
@@ -3608,7 +3608,7 @@ dependencies = [
[[package]]
name = "revolt-permissions"
version = "0.7.11"
version = "0.7.12"
dependencies = [
"async-std",
"async-trait",
@@ -3623,7 +3623,7 @@ dependencies = [
[[package]]
name = "revolt-presence"
version = "0.7.11"
version = "0.7.12"
dependencies = [
"async-std",
"log",
@@ -3634,7 +3634,7 @@ dependencies = [
[[package]]
name = "revolt-result"
version = "0.7.11"
version = "0.7.12"
dependencies = [
"revolt_okapi",
"revolt_rocket_okapi",

View File

@@ -21,6 +21,8 @@ Rust 1.70 or higher.
## Development Guide
Before contributing, make yourself familiar with [our contribution guidelines](https://developers.revolt.chat/contrib.html) and the [technical documentation for this project](https://revoltchat.github.io/backend/).
Before getting started, you'll want to install:
- Rust toolchain (rustup recommended)

View File

@@ -1,6 +1,6 @@
[package]
name = "revolt-bonfire"
version = "0.7.11"
version = "0.7.12"
license = "AGPL-3.0-or-later"
edition = "2021"
@@ -41,7 +41,7 @@ revolt-result = { path = "../core/result" }
revolt-models = { path = "../core/models" }
revolt-config = { path = "../core/config" }
revolt-database = { path = "../core/database" }
revolt-permissions = { version = "0.7.11", path = "../core/permissions" }
revolt-permissions = { version = "0.7.12", path = "../core/permissions" }
revolt-presence = { path = "../core/presence", features = ["redis-is-patched"] }
# redis

View File

@@ -1,6 +1,6 @@
[package]
name = "revolt-config"
version = "0.7.11"
version = "0.7.12"
edition = "2021"
license = "MIT"
authors = ["Paul Makles <me@insrt.uk>"]

View File

@@ -1,6 +1,6 @@
[package]
name = "revolt-database"
version = "0.7.11"
version = "0.7.12"
edition = "2021"
license = "AGPL-3.0-or-later"
authors = ["Paul Makles <me@insrt.uk>"]
@@ -23,13 +23,13 @@ default = ["mongodb", "async-std-runtime", "tasks"]
[dependencies]
# Core
revolt-config = { version = "0.7.11", path = "../config" }
revolt-result = { version = "0.7.11", path = "../result" }
revolt-models = { version = "0.7.11", path = "../models", features = [
revolt-config = { version = "0.7.12", path = "../config" }
revolt-result = { version = "0.7.12", path = "../result" }
revolt-models = { version = "0.7.12", path = "../models", features = [
"validator",
] }
revolt-presence = { version = "0.7.11", path = "../presence" }
revolt-permissions = { version = "0.7.11", path = "../permissions", features = [
revolt-presence = { version = "0.7.12", path = "../presence" }
revolt-permissions = { version = "0.7.12", path = "../permissions", features = [
"serde",
"bson",
] }

View File

@@ -4,8 +4,8 @@ use indexmap::{IndexMap, IndexSet};
use iso8601_timestamp::Timestamp;
use revolt_config::{config, FeaturesLimits};
use revolt_models::v0::{
self, BulkMessageResponse, DataMessageSend, Embed, MessageAuthor, MessageSort, MessageWebhook,
PushNotification, ReplyIntent, SendableEmbed, Text, RE_MENTION,
self, BulkMessageResponse, DataMessageSend, Embed, MessageAuthor, MessageFlags, MessageSort,
MessageWebhook, PushNotification, ReplyIntent, SendableEmbed, Text, RE_MENTION,
};
use revolt_permissions::{ChannelPermission, PermissionValue};
use revolt_result::Result;
@@ -65,6 +65,10 @@ auto_derived_partial!(
/// Name and / or avatar overrides for this message
#[serde(skip_serializing_if = "Option::is_none")]
pub masquerade: Option<Masquerade>,
/// Bitfield of message flags
#[serde(skip_serializing_if = "Option::is_none")]
pub flags: Option<i32>,
},
"PartialMessage"
);
@@ -200,6 +204,7 @@ impl Default for Message {
reactions: Default::default(),
interactions: Default::default(),
masquerade: None,
flags: None,
}
}
}
@@ -241,6 +246,13 @@ impl Message {
return Err(create_error!(EmptyMessage));
}
// Ensure flags are either not set or have permissible values
if let Some(flags) = &data.flags {
if flags != &0 && flags != &1 {
return Err(create_error!(InvalidProperty));
}
}
// Ensure restrict_reactions is not specified without reactions list
if let Some(interactions) = &data.interactions {
if interactions.restrict_reactions {
@@ -274,6 +286,7 @@ impl Message {
.unwrap_or_default(),
author: author_id,
webhook: webhook.map(|w| w.into()),
flags: data.flags.map(|v| v as i32),
..Default::default()
};
@@ -438,24 +451,26 @@ impl Message {
)
.await?;
// Push out Web Push notifications
crate::tasks::web_push::queue(
{
match channel {
Channel::DirectMessage { recipients, .. }
| Channel::Group { recipients, .. } => recipients.clone(),
Channel::TextChannel { .. } => self.mentions.clone().unwrap_or_default(),
_ => vec![],
}
},
PushNotification::from(
self.clone().into_model(None, None),
Some(author),
&channel.id(),
if !self.has_suppressed_notifications() {
// Push out Web Push notifications
crate::tasks::web_push::queue(
{
match channel {
Channel::DirectMessage { recipients, .. }
| Channel::Group { recipients, .. } => recipients.clone(),
Channel::TextChannel { .. } => self.mentions.clone().unwrap_or_default(),
_ => vec![],
}
},
PushNotification::from(
self.clone().into_model(None, None),
Some(author),
&channel.id(),
)
.await,
)
.await,
)
.await;
.await;
}
Ok(())
}
@@ -487,6 +502,16 @@ impl Message {
}))
}
/// Whether this message has suppressed notifications
pub fn has_suppressed_notifications(&self) -> bool {
if let Some(flags) = self.flags {
flags & MessageFlags::SupressNotifications as i32
== MessageFlags::SupressNotifications as i32
} else {
false
}
}
/// Update message data
pub async fn update(&mut self, db: &Database, partial: PartialMessage) -> Result<()> {
self.apply_options(partial.clone());

View File

@@ -61,6 +61,7 @@ auto_derived!(
StatusPresence,
ProfileContent,
ProfileBackground,
DisplayName,
}
/// User's relationship with another user (or themselves)
@@ -657,6 +658,7 @@ impl User {
x.background = None;
}
}
FieldsUser::DisplayName => self.display_name = None,
}
}

View File

@@ -326,6 +326,7 @@ impl IntoDocumentPath for FieldsUser {
FieldsUser::ProfileContent => "profile.content",
FieldsUser::StatusPresence => "status.presence",
FieldsUser::StatusText => "status.text",
FieldsUser::DisplayName => "display_name",
})
}
}

View File

@@ -470,7 +470,7 @@ impl crate::Message {
member,
webhook: self.webhook,
content: self.content,
system: self.system.map(|system| system.into()),
system: self.system.map(Into::into),
attachments: self
.attachments
.map(|v| v.into_iter().map(|f| f.into()).collect()),
@@ -480,7 +480,8 @@ impl crate::Message {
replies: self.replies,
reactions: self.reactions,
interactions: self.interactions.into(),
masquerade: self.masquerade.map(|masq| masq.into()),
masquerade: self.masquerade.map(Into::into),
flags: self.flags.map(|flags| flags as u32).unwrap_or_default(),
}
}
}
@@ -496,7 +497,7 @@ impl From<crate::PartialMessage> for PartialMessage {
member: None,
webhook: value.webhook,
content: value.content,
system: value.system.map(|system| system.into()),
system: value.system.map(Into::into),
attachments: value
.attachments
.map(|v| v.into_iter().map(|f| f.into()).collect()),
@@ -505,8 +506,9 @@ impl From<crate::PartialMessage> for PartialMessage {
mentions: value.mentions,
replies: value.replies,
reactions: value.reactions,
interactions: value.interactions.map(|interactions| interactions.into()),
masquerade: value.masquerade.map(|masq| masq.into()),
interactions: value.interactions.map(Into::into),
masquerade: value.masquerade.map(Into::into),
flags: value.flags.map(|flags| flags as u32),
}
}
}
@@ -1212,6 +1214,7 @@ impl From<FieldsUser> for crate::FieldsUser {
FieldsUser::ProfileContent => crate::FieldsUser::ProfileContent,
FieldsUser::StatusPresence => crate::FieldsUser::StatusPresence,
FieldsUser::StatusText => crate::FieldsUser::StatusText,
FieldsUser::DisplayName => crate::FieldsUser::DisplayName,
}
}
}
@@ -1224,6 +1227,7 @@ impl From<crate::FieldsUser> for FieldsUser {
crate::FieldsUser::ProfileContent => FieldsUser::ProfileContent,
crate::FieldsUser::StatusPresence => FieldsUser::StatusPresence,
crate::FieldsUser::StatusText => FieldsUser::StatusText,
crate::FieldsUser::DisplayName => FieldsUser::DisplayName,
}
}
}

View File

@@ -53,6 +53,12 @@ impl PermissionQuery for DatabasePermissionQuery<'_> {
if let Some(other_user) = &self.user {
if self.perspective.id == other_user.id {
return RelationshipStatus::User;
} else if let Some(bot) = &other_user.bot {
// For the purposes of permissions checks,
// assume owner is the same as bot
if self.perspective.id == bot.owner {
return RelationshipStatus::User;
}
}
if let Some(relations) = &self.perspective.relations {

View File

@@ -1,6 +1,6 @@
[package]
name = "revolt-models"
version = "0.7.11"
version = "0.7.12"
edition = "2021"
license = "MIT"
authors = ["Paul Makles <me@insrt.uk>"]
@@ -19,8 +19,8 @@ default = ["serde", "partials", "rocket"]
[dependencies]
# Core
revolt-config = { version = "0.7.11", path = "../config" }
revolt-permissions = { version = "0.7.11", path = "../permissions" }
revolt-config = { version = "0.7.12", path = "../config" }
revolt-permissions = { version = "0.7.12", path = "../permissions" }
# Utility
regex = "1"

View File

@@ -70,6 +70,15 @@ auto_derived_partial!(
/// Name and / or avatar overrides for this message
#[serde(skip_serializing_if = "Option::is_none")]
pub masquerade: Option<Masquerade>,
/// Bitfield of message flags
///
/// https://docs.rs/revolt-models/latest/revolt_models/v0/enum.MessageFlags.html
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "crate::if_zero_u32", default)
)]
pub flags: u32,
},
"PartialMessage"
);
@@ -247,6 +256,11 @@ auto_derived!(
pub masquerade: Option<Masquerade>,
/// Information about how this message should be interacted with
pub interactions: Option<Interactions>,
/// Bitfield of message flags
///
/// https://docs.rs/revolt-models/latest/revolt_models/v0/enum.MessageFlags.html
pub flags: Option<u32>,
}
/// Options for querying messages
@@ -334,6 +348,13 @@ auto_derived!(
/// Remove all reactions
pub remove_all: Option<bool>,
}
/// Message flag bitfield
#[repr(u32)]
pub enum MessageFlags {
/// Message will not send push / desktop notifications
SupressNotifications = 1,
}
);
/// Message Author Abstraction

View File

@@ -42,6 +42,8 @@ auto_derived_partial!(
pub relations: Vec<Relationship>,
/// Bitfield of user badges
///
/// https://docs.rs/revolt-models/latest/revolt_models/v0/enum.UserBadges.html
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "crate::if_zero_u32", default)
@@ -52,6 +54,8 @@ auto_derived_partial!(
pub status: Option<UserStatus>,
/// Enum of user flags
///
/// https://docs.rs/revolt-models/latest/revolt_models/v0/enum.UserFlags.html
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "crate::if_zero_u32", default)
@@ -83,6 +87,7 @@ auto_derived!(
StatusPresence,
ProfileContent,
ProfileBackground,
DisplayName,
}
/// User's relationship with another user (or themselves)

View File

@@ -1,6 +1,6 @@
[package]
name = "revolt-permissions"
version = "0.7.11"
version = "0.7.12"
edition = "2021"
license = "MIT"
authors = ["Paul Makles <me@insrt.uk>"]
@@ -21,7 +21,7 @@ async-std = { version = "1.8.0", features = ["attributes"] }
[dependencies]
# Core
revolt-result = { version = "0.7.11", path = "../result" }
revolt-result = { version = "0.7.12", path = "../result" }
# Utility
auto_ops = "0.3.0"

View File

@@ -1,6 +1,6 @@
[package]
name = "revolt-presence"
version = "0.7.11"
version = "0.7.12"
edition = "2021"
license = "AGPL-3.0-or-later"
authors = ["Paul Makles <me@insrt.uk>"]

View File

@@ -1,6 +1,6 @@
[package]
name = "revolt-result"
version = "0.7.11"
version = "0.7.12"
edition = "2021"
license = "MIT"
authors = ["Paul Makles <me@insrt.uk>"]

View File

@@ -1,6 +1,6 @@
[package]
name = "revolt-delta"
version = "0.7.11"
version = "0.7.12"
license = "AGPL-3.0-or-later"
authors = ["Paul Makles <paulmakles@gmail.com>"]
edition = "2018"

View File

@@ -24,23 +24,26 @@ pub async fn edit(
})
})?;
// Filter out invalid edit fields
if !user.privileged && (data.badges.is_some() || data.flags.is_some()) {
return Err(create_error!(NotPrivileged));
}
// If we want to edit a different user than self, ensure we have
// permissions and subsequently replace the user in question
if target.id != "@me" && target.id != user.id {
let target_user = target.as_user(db).await?;
let is_bot_owner = target_user
.bot
.as_ref()
.map(|bot| bot.owner == user.id)
.unwrap_or_default();
if !is_bot_owner && !user.privileged {
return Err(create_error!(NotPrivileged));
}
}
// Otherwise, filter out invalid edit fields
if !user.privileged && (data.badges.is_some() || data.flags.is_some()) {
return Err(create_error!(NotPrivileged));
user = target_user;
}
// Exit out early if nothing is changed