mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-06 19:25:59 +00:00
Compare commits
4 Commits
20250513-2
...
stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4728c696d | ||
|
|
8153f5f17a | ||
|
|
99a80f723d | ||
|
|
4f13f5899b |
37
Cargo.lock
generated
37
Cargo.lock
generated
@@ -446,9 +446,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "authifier"
|
||||
version = "1.0.13"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca26cb6b5ab776a1de5a8122fe6cc77fadd84fed30704c496f2aca451637877b"
|
||||
checksum = "b1a03b810b342b4c584cdc1cfc40d1ec763b1d653ef4086f7494740f35d9e1f0"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"async-trait",
|
||||
@@ -5954,7 +5954,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-autumn"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"axum-macros",
|
||||
@@ -5991,7 +5991,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-bonfire"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"async-channel 2.3.1",
|
||||
"async-std",
|
||||
@@ -6021,7 +6021,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-config"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"cached",
|
||||
@@ -6038,7 +6038,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-crond"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"log",
|
||||
"revolt-config",
|
||||
@@ -6050,7 +6050,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-database"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"amqprs",
|
||||
"async-lock 2.8.0",
|
||||
@@ -6100,7 +6100,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-delta"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"amqprs",
|
||||
"async-channel 1.9.0",
|
||||
@@ -6147,7 +6147,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-files"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"aes-gcm",
|
||||
"aws-config",
|
||||
@@ -6170,7 +6170,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-january"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"async-recursion",
|
||||
"axum",
|
||||
@@ -6198,7 +6198,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-models"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"indexmap 1.9.3",
|
||||
"iso8601-timestamp",
|
||||
@@ -6217,14 +6217,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-parser"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"logos",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "revolt-permissions"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"async-trait",
|
||||
@@ -6239,7 +6239,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-presence"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"log",
|
||||
@@ -6250,7 +6250,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-pushd"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"amqprs",
|
||||
"anyhow",
|
||||
@@ -6278,7 +6278,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt-result"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"revolt_okapi",
|
||||
@@ -6478,9 +6478,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rocket_authifier"
|
||||
version = "1.0.13"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0490f4a6f0a359a9ffff9acbdf4eddf49890ec94941b8ddd88163c16f6159f5a"
|
||||
checksum = "c1f98a5be96ac4144ee1adc809c1594e8212032b8a08d9bc4cef70735dfd976e"
|
||||
dependencies = [
|
||||
"authifier",
|
||||
"iso8601-timestamp",
|
||||
@@ -8294,6 +8294,7 @@ checksum = "220b18413e1fe5e85a5580b22f44241f82404a66c792c9f3c9eda74c52d9a22e"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"rand 0.8.5",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-bonfire"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
license = "AGPL-3.0-or-later"
|
||||
edition = "2021"
|
||||
|
||||
@@ -36,12 +36,12 @@ async-std = { version = "1.8.0", features = [
|
||||
] }
|
||||
|
||||
# core
|
||||
authifier = { version = "1.0.13" }
|
||||
authifier = { version = "1.0.15" }
|
||||
revolt-result = { path = "../core/result" }
|
||||
revolt-models = { path = "../core/models" }
|
||||
revolt-config = { path = "../core/config" }
|
||||
revolt-database = { path = "../core/database" }
|
||||
revolt-permissions = { version = "0.8.6", path = "../core/permissions" }
|
||||
revolt-permissions = { version = "0.8.7", path = "../core/permissions" }
|
||||
revolt-presence = { path = "../core/presence", features = ["redis-is-patched"] }
|
||||
|
||||
# redis
|
||||
|
||||
@@ -100,6 +100,18 @@ impl State {
|
||||
let user = self.clone_user();
|
||||
self.cache.is_bot = user.bot.is_some();
|
||||
|
||||
// Fetch pending policy changes.
|
||||
let policy_changes = if user.bot.is_some() {
|
||||
vec![]
|
||||
} else {
|
||||
db.fetch_policy_changes()
|
||||
.await?
|
||||
.into_iter()
|
||||
.filter(|policy| policy.created_time > user.last_acknowledged_policy_change)
|
||||
.map(Into::into)
|
||||
.collect()
|
||||
};
|
||||
|
||||
// Find all relationships to the user.
|
||||
let mut user_ids: HashSet<String> = user
|
||||
.relations
|
||||
@@ -227,6 +239,7 @@ impl State {
|
||||
for channel in &channels {
|
||||
self.insert_subscription(channel.id().to_string()).await;
|
||||
}
|
||||
|
||||
Ok(EventV1::Ready {
|
||||
users: if fields.contains(&ReadyPayloadFields::Users) {
|
||||
Some(users)
|
||||
@@ -252,6 +265,8 @@ impl State {
|
||||
|
||||
user_settings,
|
||||
channel_unreads: channel_unreads.map(|vec| vec.into_iter().map(Into::into).collect()),
|
||||
|
||||
policy_changes,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-config"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = ["Paul Makles <me@insrt.uk>"]
|
||||
@@ -36,4 +36,4 @@ sentry = "0.31.5"
|
||||
sentry-anyhow = { version = "0.38.1", optional = true }
|
||||
|
||||
# Core
|
||||
revolt-result = { version = "0.8.6", path = "../result", optional = true }
|
||||
revolt-result = { version = "0.8.7", path = "../result", optional = true }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-database"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
edition = "2021"
|
||||
license = "AGPL-3.0-or-later"
|
||||
authors = ["Paul Makles <me@insrt.uk>"]
|
||||
@@ -24,19 +24,19 @@ default = ["mongodb", "async-std-runtime", "tasks"]
|
||||
|
||||
[dependencies]
|
||||
# Core
|
||||
revolt-config = { version = "0.8.6", path = "../config", features = [
|
||||
revolt-config = { version = "0.8.7", path = "../config", features = [
|
||||
"report-macros",
|
||||
] }
|
||||
revolt-result = { version = "0.8.6", path = "../result" }
|
||||
revolt-models = { version = "0.8.6", path = "../models", features = [
|
||||
revolt-result = { version = "0.8.7", path = "../result" }
|
||||
revolt-models = { version = "0.8.7", path = "../models", features = [
|
||||
"validator",
|
||||
] }
|
||||
revolt-presence = { version = "0.8.6", path = "../presence" }
|
||||
revolt-permissions = { version = "0.8.6", path = "../permissions", features = [
|
||||
revolt-presence = { version = "0.8.7", path = "../presence" }
|
||||
revolt-permissions = { version = "0.8.7", path = "../permissions", features = [
|
||||
"serde",
|
||||
"bson",
|
||||
] }
|
||||
revolt-parser = { version = "0.8.6", path = "../parser" }
|
||||
revolt-parser = { version = "0.8.7", path = "../parser" }
|
||||
|
||||
# Utility
|
||||
log = "0.4"
|
||||
@@ -97,7 +97,7 @@ web-push = "0.10.0"
|
||||
revolt_a2 = { version = "0.10", default-features = false, features = ["ring"] }
|
||||
|
||||
# Authifier
|
||||
authifier = { version = "1.0.13", features = ["rocket_impl"] }
|
||||
authifier = { version = "1.0.15", features = ["rocket_impl"] }
|
||||
|
||||
# RabbitMQ
|
||||
amqprs = { version = "1.7.0" }
|
||||
|
||||
@@ -4,8 +4,8 @@ use futures::lock::Mutex;
|
||||
|
||||
use crate::{
|
||||
Bot, Channel, ChannelCompositeKey, ChannelUnread, Emoji, File, FileHash, Invite, Member,
|
||||
MemberCompositeKey, Message, RatelimitEvent, Report, Server, ServerBan, Snapshot, User,
|
||||
UserSettings, Webhook,
|
||||
MemberCompositeKey, Message, PolicyChange, RatelimitEvent, Report, Server, ServerBan, Snapshot,
|
||||
User, UserSettings, Webhook,
|
||||
};
|
||||
|
||||
database_derived!(
|
||||
@@ -21,6 +21,7 @@ database_derived!(
|
||||
pub file_hashes: Arc<Mutex<HashMap<String, FileHash>>>,
|
||||
pub files: Arc<Mutex<HashMap<String, File>>>,
|
||||
pub messages: Arc<Mutex<HashMap<String, Message>>>,
|
||||
pub policy_changes: Arc<Mutex<HashMap<String, PolicyChange>>>,
|
||||
pub ratelimit_events: Arc<Mutex<HashMap<String, RatelimitEvent>>>,
|
||||
pub user_settings: Arc<Mutex<HashMap<String, UserSettings>>>,
|
||||
pub users: Arc<Mutex<HashMap<String, User>>>,
|
||||
|
||||
@@ -6,7 +6,7 @@ use revolt_models::v0::{
|
||||
AppendMessage, Channel, ChannelUnread, Emoji, FieldsChannel, FieldsMember, FieldsMessage,
|
||||
FieldsRole, FieldsServer, FieldsUser, FieldsWebhook, Member, MemberCompositeKey, Message,
|
||||
PartialChannel, PartialMember, PartialMessage, PartialRole, PartialServer, PartialUser,
|
||||
PartialWebhook, RemovalIntention, Report, Server, User, UserSettings, Webhook,
|
||||
PartialWebhook, PolicyChange, RemovalIntention, Report, Server, User, UserSettings, Webhook,
|
||||
};
|
||||
|
||||
use crate::Database;
|
||||
@@ -62,6 +62,8 @@ pub enum EventV1 {
|
||||
user_settings: Option<UserSettings>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
channel_unreads: Option<Vec<ChannelUnread>>,
|
||||
|
||||
policy_changes: Vec<PolicyChange>,
|
||||
},
|
||||
|
||||
/// Ping response
|
||||
|
||||
@@ -64,6 +64,10 @@ pub async fn create_database(db: &MongoDb) {
|
||||
.await
|
||||
.expect("Failed to create user_settings collection.");
|
||||
|
||||
db.create_collection("policy_changes")
|
||||
.await
|
||||
.expect("Failed to create policy_changes collection.");
|
||||
|
||||
db.create_collection("safety_reports")
|
||||
.await
|
||||
.expect("Failed to create safety_reports collection.");
|
||||
|
||||
@@ -5,10 +5,11 @@ use crate::{
|
||||
bson::{doc, from_bson, from_document, to_document, Bson, DateTime, Document},
|
||||
options::FindOptions,
|
||||
},
|
||||
AbstractChannels, AbstractServers, Channel, Invite, MongoDb, DISCRIMINATOR_SEARCH_SPACE,
|
||||
AbstractChannels, AbstractServers, Channel, Invite, MongoDb, User, DISCRIMINATOR_SEARCH_SPACE,
|
||||
};
|
||||
use bson::oid::ObjectId;
|
||||
use bson::{oid::ObjectId, to_bson};
|
||||
use futures::StreamExt;
|
||||
use iso8601_timestamp::Timestamp;
|
||||
use rand::seq::SliceRandom;
|
||||
use revolt_permissions::DEFAULT_WEBHOOK_PERMISSIONS;
|
||||
use revolt_result::{Error, ErrorType};
|
||||
@@ -21,7 +22,7 @@ struct MigrationInfo {
|
||||
revision: i32,
|
||||
}
|
||||
|
||||
pub const LATEST_REVISION: i32 = 32;
|
||||
pub const LATEST_REVISION: i32 = 41; // MUST BE +1 to last migration
|
||||
|
||||
pub async fn migrate_database(db: &MongoDb) {
|
||||
let migrations = db.col::<Document>("migrations");
|
||||
@@ -1139,6 +1140,31 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
if revision <= 40 {
|
||||
info!(
|
||||
"Running migration [revision |> 40 / 30-05-2025]: Set last policy acknowlegement date to now and create policy changes collection."
|
||||
);
|
||||
|
||||
db.db()
|
||||
.create_collection("policy_changes")
|
||||
.await
|
||||
.expect("Failed to create policy_changes collection.");
|
||||
|
||||
db.db()
|
||||
.collection::<User>("users")
|
||||
.update_many(
|
||||
doc! {},
|
||||
doc! {
|
||||
"$set": {
|
||||
"last_acknowledged_policy_change": to_bson(&Timestamp::now_utc())
|
||||
.expect("failed to serialise timestamp")
|
||||
}
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("failed to update users");
|
||||
}
|
||||
|
||||
// Reminder to update LATEST_REVISION when adding new migrations.
|
||||
LATEST_REVISION.max(revision)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ mod emojis;
|
||||
mod file_hashes;
|
||||
mod files;
|
||||
mod messages;
|
||||
mod policy_changes;
|
||||
mod ratelimit_events;
|
||||
mod safety_reports;
|
||||
mod safety_snapshots;
|
||||
@@ -27,6 +28,7 @@ pub use emojis::*;
|
||||
pub use file_hashes::*;
|
||||
pub use files::*;
|
||||
pub use messages::*;
|
||||
pub use policy_changes::*;
|
||||
pub use ratelimit_events::*;
|
||||
pub use safety_reports::*;
|
||||
pub use safety_snapshots::*;
|
||||
@@ -51,6 +53,7 @@ pub trait AbstractDatabase:
|
||||
+ file_hashes::AbstractAttachmentHashes
|
||||
+ files::AbstractAttachments
|
||||
+ messages::AbstractMessages
|
||||
+ policy_changes::AbstractPolicyChange
|
||||
+ ratelimit_events::AbstractRatelimitEvents
|
||||
+ safety_reports::AbstractReport
|
||||
+ safety_snapshots::AbstractSnapshot
|
||||
|
||||
5
crates/core/database/src/models/policy_changes/mod.rs
Normal file
5
crates/core/database/src/models/policy_changes/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
mod model;
|
||||
mod ops;
|
||||
|
||||
pub use model::*;
|
||||
pub use ops::*;
|
||||
20
crates/core/database/src/models/policy_changes/model.rs
Normal file
20
crates/core/database/src/models/policy_changes/model.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use iso8601_timestamp::Timestamp;
|
||||
|
||||
auto_derived!(
|
||||
/// Platform policy change
|
||||
pub struct PolicyChange {
|
||||
/// Unique Id
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
|
||||
/// Time at which this policy was created
|
||||
pub created_time: Timestamp,
|
||||
/// Time at which this policy is effective
|
||||
pub effective_time: Timestamp,
|
||||
|
||||
/// Message shown to users
|
||||
pub description: String,
|
||||
/// URL with details about changes
|
||||
pub url: String,
|
||||
}
|
||||
);
|
||||
15
crates/core/database/src/models/policy_changes/ops.rs
Normal file
15
crates/core/database/src/models/policy_changes/ops.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use revolt_result::Result;
|
||||
|
||||
use crate::PolicyChange;
|
||||
|
||||
mod mongodb;
|
||||
mod reference;
|
||||
|
||||
#[async_trait]
|
||||
pub trait AbstractPolicyChange: Sync + Send {
|
||||
/// Fetch all policy changes
|
||||
async fn fetch_policy_changes(&self) -> Result<Vec<PolicyChange>>;
|
||||
|
||||
/// Acknowledge policy changes
|
||||
async fn acknowledge_policy_changes(&self, user_id: &str) -> Result<()>;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
use bson::to_bson;
|
||||
use iso8601_timestamp::Timestamp;
|
||||
use revolt_result::Result;
|
||||
|
||||
use crate::MongoDb;
|
||||
use crate::PolicyChange;
|
||||
use crate::User;
|
||||
|
||||
use super::AbstractPolicyChange;
|
||||
|
||||
static COL: &str = "policy_changes";
|
||||
|
||||
#[async_trait]
|
||||
impl AbstractPolicyChange for MongoDb {
|
||||
/// Fetch all policy changes
|
||||
async fn fetch_policy_changes(&self) -> Result<Vec<PolicyChange>> {
|
||||
query!(self, find, COL, doc! {})
|
||||
}
|
||||
|
||||
/// Acknowledge policy changes
|
||||
async fn acknowledge_policy_changes(&self, user_id: &str) -> Result<()> {
|
||||
let latest_policy = self
|
||||
.fetch_policy_changes()
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|policy| policy.created_time)
|
||||
.max()
|
||||
.unwrap_or(Timestamp::UNIX_EPOCH);
|
||||
|
||||
self.col::<User>("users")
|
||||
.update_one(
|
||||
doc! {
|
||||
"_id": user_id
|
||||
},
|
||||
doc! {
|
||||
"$set": {
|
||||
"last_acknowledged_policy_change": to_bson(&latest_policy)
|
||||
.map_err(|_| create_database_error!("to_bson", "timestamp"))?
|
||||
}
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map(|_| ())
|
||||
.map_err(|_| create_database_error!("update_one", COL))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
use iso8601_timestamp::Timestamp;
|
||||
use revolt_result::Result;
|
||||
|
||||
use crate::PolicyChange;
|
||||
use crate::ReferenceDb;
|
||||
|
||||
use super::AbstractPolicyChange;
|
||||
|
||||
#[async_trait]
|
||||
impl AbstractPolicyChange for ReferenceDb {
|
||||
/// Fetch all policy changes
|
||||
async fn fetch_policy_changes(&self) -> Result<Vec<PolicyChange>> {
|
||||
let policy_changes = self.policy_changes.lock().await;
|
||||
Ok(policy_changes.values().cloned().collect())
|
||||
}
|
||||
|
||||
/// Acknowledge policy changes
|
||||
async fn acknowledge_policy_changes(&self, user_id: &str) -> Result<()> {
|
||||
let mut users = self.users.lock().await;
|
||||
let user = users.get_mut(user_id).expect("user doesn't exist");
|
||||
user.last_acknowledged_policy_change = self
|
||||
.fetch_policy_changes()
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|policy| policy.created_time)
|
||||
.max()
|
||||
.unwrap_or(Timestamp::UNIX_EPOCH);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,8 @@ auto_derived_partial!(
|
||||
/// Time until user is unsuspended
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub suspended_until: Option<Timestamp>,
|
||||
/// Last acknowledged policy change
|
||||
pub last_acknowledged_policy_change: Timestamp,
|
||||
},
|
||||
"PartialUser"
|
||||
);
|
||||
@@ -178,6 +180,7 @@ impl Default for User {
|
||||
privileged: Default::default(),
|
||||
bot: Default::default(),
|
||||
suspended_until: Default::default(),
|
||||
last_acknowledged_policy_change: Timestamp::UNIX_EPOCH,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,6 +203,7 @@ impl User {
|
||||
id: account_id.into().unwrap_or_else(|| Ulid::new().to_string()),
|
||||
discriminator: User::find_discriminator(db, &username, None).await?,
|
||||
username,
|
||||
last_acknowledged_policy_change: Timestamp::now_utc(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::{Database, Message, AMQP};
|
||||
|
||||
use deadqueue::limited::Queue;
|
||||
use once_cell::sync::Lazy;
|
||||
use revolt_config::capture_message;
|
||||
use revolt_models::v0::PushNotification;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
@@ -64,6 +65,7 @@ pub async fn queue_ack(channel: String, user: String, event: AckEvent) {
|
||||
);
|
||||
}
|
||||
|
||||
/// Do not add more than one message per event.
|
||||
pub async fn queue_message(channel: String, event: AckEvent) {
|
||||
Q.try_push(Data {
|
||||
channel,
|
||||
@@ -113,7 +115,7 @@ pub async fn handle_ack_event(
|
||||
}
|
||||
AckEvent::ProcessMessage { messages } => {
|
||||
let mut users: HashSet<&String> = HashSet::new();
|
||||
debug!(
|
||||
info!(
|
||||
"Processing {} messages from channel {}",
|
||||
messages.len(),
|
||||
messages[0].1.channel
|
||||
@@ -124,7 +126,7 @@ pub async fn handle_ack_event(
|
||||
users.extend(recipents.iter());
|
||||
});
|
||||
|
||||
debug!("Found {} users to notify.", users.len());
|
||||
info!("Found {} users to notify.", users.len());
|
||||
|
||||
for user in users {
|
||||
let message_ids: Vec<String> = messages
|
||||
@@ -142,7 +144,7 @@ pub async fn handle_ack_event(
|
||||
db.add_mention_to_unread(channel, user, &message_ids)
|
||||
.await?;
|
||||
}
|
||||
debug!("Added {} mentions for user {}", message_ids.len(), &user);
|
||||
info!("Added {} mentions for user {}", message_ids.len(), &user);
|
||||
}
|
||||
|
||||
let mut mass_mentions = vec![];
|
||||
@@ -231,7 +233,7 @@ pub async fn worker(db: Database, amqp: AMQP) {
|
||||
revolt_config::capture_error(&err);
|
||||
error!("{err:?} for {event:?}. ({user:?}, {channel})");
|
||||
} else {
|
||||
debug!("User {user:?} ack in {channel} with {event:?}");
|
||||
info!("User {user:?} ack in {channel} with {event:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,6 +248,8 @@ pub async fn worker(db: Database, amqp: AMQP) {
|
||||
mut event,
|
||||
}) = Q.try_pop()
|
||||
{
|
||||
info!("Took next ack from queue, now {} remaining", Q.len());
|
||||
|
||||
let key: (Option<String>, String, u8) = (
|
||||
user,
|
||||
channel,
|
||||
@@ -260,24 +264,31 @@ pub async fn worker(db: Database, amqp: AMQP) {
|
||||
if let AckEvent::ProcessMessage { messages: existing } =
|
||||
&mut task.data.event
|
||||
{
|
||||
// add the new message to the list of messages to be processed.
|
||||
existing.append(new_data);
|
||||
if let Some(new_event) = new_data.pop() {
|
||||
// if the message contains a mass mention, do not delay it any further.
|
||||
if new_event.1.contains_mass_push_mention() {
|
||||
// add the new message to the list of messages to be processed.
|
||||
existing.push(new_event);
|
||||
task.run_immediately();
|
||||
continue;
|
||||
}
|
||||
|
||||
// if the message contains a mass mention, do not delay it any further.
|
||||
if new_data[0].1.contains_mass_push_mention() {
|
||||
task.run_immediately();
|
||||
continue;
|
||||
}
|
||||
existing.push(new_event);
|
||||
|
||||
// put a cap on the amount of messages that can be queued, for particularly active channels
|
||||
if (existing.length() as u16)
|
||||
< revolt_config::config()
|
||||
.await
|
||||
.features
|
||||
.advanced
|
||||
.process_message_delay_limit
|
||||
{
|
||||
task.delay();
|
||||
// put a cap on the amount of messages that can be queued, for particularly active channels
|
||||
if (existing.length() as u16)
|
||||
< revolt_config::config()
|
||||
.await
|
||||
.features
|
||||
.advanced
|
||||
.process_message_delay_limit
|
||||
{
|
||||
task.delay();
|
||||
}
|
||||
} else {
|
||||
let err_msg = format!("Got zero-length message event: {event:?}");
|
||||
capture_message(&err_msg, revolt_config::Level::Warning);
|
||||
info!("{err_msg}")
|
||||
}
|
||||
} else {
|
||||
panic!("Somehow got an ack message in the add mention arm");
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use iso8601_timestamp::Timestamp;
|
||||
use revolt_models::v0::*;
|
||||
use revolt_permissions::{calculate_user_permissions, UserPermission};
|
||||
|
||||
@@ -597,6 +598,17 @@ impl From<Masquerade> for crate::Masquerade {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::PolicyChange> for PolicyChange {
|
||||
fn from(value: crate::PolicyChange) -> Self {
|
||||
PolicyChange {
|
||||
created_time: value.created_time,
|
||||
effective_time: value.effective_time,
|
||||
description: value.description,
|
||||
url: value.url,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::Report> for Report {
|
||||
fn from(value: crate::Report) -> Self {
|
||||
Report {
|
||||
@@ -1188,6 +1200,7 @@ impl From<User> for crate::User {
|
||||
privileged: value.privileged,
|
||||
bot: value.bot.map(Into::into),
|
||||
suspended_until: None,
|
||||
last_acknowledged_policy_change: Timestamp::UNIX_EPOCH,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-files"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
edition = "2021"
|
||||
license = "AGPL-3.0-or-later"
|
||||
authors = ["Paul Makles <me@insrt.uk>"]
|
||||
@@ -20,10 +20,10 @@ typenum = "1.17.0"
|
||||
aws-config = "1.5.5"
|
||||
aws-sdk-s3 = { version = "1.46.0", features = ["behavior-version-latest"] }
|
||||
|
||||
revolt-config = { version = "0.8.6", path = "../config", features = [
|
||||
revolt-config = { version = "0.8.7", path = "../config", features = [
|
||||
"report-macros",
|
||||
] }
|
||||
revolt-result = { version = "0.8.6", path = "../result" }
|
||||
revolt-result = { version = "0.8.7", path = "../result" }
|
||||
|
||||
# image processing
|
||||
jxl-oxide = "0.8.1"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-models"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = ["Paul Makles <me@insrt.uk>"]
|
||||
@@ -20,8 +20,8 @@ default = ["serde", "partials", "rocket"]
|
||||
|
||||
[dependencies]
|
||||
# Core
|
||||
revolt-config = { version = "0.8.6", path = "../config" }
|
||||
revolt-permissions = { version = "0.8.6", path = "../permissions" }
|
||||
revolt-config = { version = "0.8.7", path = "../config" }
|
||||
revolt-permissions = { version = "0.8.7", path = "../permissions" }
|
||||
|
||||
# Utility
|
||||
regex = "1.11"
|
||||
|
||||
@@ -7,6 +7,7 @@ mod embeds;
|
||||
mod emojis;
|
||||
mod files;
|
||||
mod messages;
|
||||
mod policy_changes;
|
||||
mod safety_reports;
|
||||
mod server_bans;
|
||||
mod server_members;
|
||||
@@ -23,6 +24,7 @@ pub use embeds::*;
|
||||
pub use emojis::*;
|
||||
pub use files::*;
|
||||
pub use messages::*;
|
||||
pub use policy_changes::*;
|
||||
pub use safety_reports::*;
|
||||
pub use server_bans::*;
|
||||
pub use server_members::*;
|
||||
|
||||
16
crates/core/models/src/v0/policy_changes.rs
Normal file
16
crates/core/models/src/v0/policy_changes.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use iso8601_timestamp::Timestamp;
|
||||
|
||||
auto_derived!(
|
||||
/// Platform policy change
|
||||
pub struct PolicyChange {
|
||||
/// Time at which this policy was created
|
||||
pub created_time: Timestamp,
|
||||
/// Time at which this policy is effective
|
||||
pub effective_time: Timestamp,
|
||||
|
||||
/// Message shown to users
|
||||
pub description: String,
|
||||
/// URL with details about changes
|
||||
pub url: String,
|
||||
}
|
||||
);
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-parser"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
edition = "2021"
|
||||
license = "AGPL-3.0-or-later"
|
||||
description = "Revolt Backend: Message Parser"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-permissions"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
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.8.6", path = "../result" }
|
||||
revolt-result = { version = "0.8.7", path = "../result" }
|
||||
|
||||
# Utility
|
||||
auto_ops = "0.3.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-presence"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
edition = "2021"
|
||||
license = "AGPL-3.0-or-later"
|
||||
authors = ["Paul Makles <me@insrt.uk>"]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-result"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = ["Paul Makles <me@insrt.uk>"]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-crond"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
license = "AGPL-3.0-or-later"
|
||||
authors = ["Paul Makles <me@insrt.uk>"]
|
||||
edition = "2021"
|
||||
@@ -16,7 +16,7 @@ log = "0.4"
|
||||
tokio = { version = "1" }
|
||||
|
||||
# Core
|
||||
revolt-database = { version = "0.8.6", path = "../../core/database" }
|
||||
revolt-result = { version = "0.8.6", path = "../../core/result" }
|
||||
revolt-config = { version = "0.8.6", path = "../../core/config" }
|
||||
revolt-files = { version = "0.8.6", path = "../../core/files" }
|
||||
revolt-database = { version = "0.8.7", path = "../../core/database" }
|
||||
revolt-result = { version = "0.8.7", path = "../../core/result" }
|
||||
revolt-config = { version = "0.8.7", path = "../../core/config" }
|
||||
revolt-files = { version = "0.8.7", path = "../../core/files" }
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
[package]
|
||||
name = "revolt-pushd"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
edition = "2021"
|
||||
license = "AGPL-3.0-or-later"
|
||||
|
||||
[dependencies]
|
||||
revolt-result = { version = "0.8.6", path = "../../core/result" }
|
||||
revolt-config = { version = "0.8.6", path = "../../core/config", features = [
|
||||
revolt-result = { version = "0.8.7", path = "../../core/result" }
|
||||
revolt-config = { version = "0.8.7", path = "../../core/config", features = [
|
||||
"report-macros",
|
||||
] }
|
||||
revolt-database = { version = "0.8.6", path = "../../core/database" }
|
||||
revolt-models = { version = "0.8.6", path = "../../core/models", features = [
|
||||
revolt-database = { version = "0.8.7", path = "../../core/database" }
|
||||
revolt-models = { version = "0.8.7", path = "../../core/models", features = [
|
||||
"validator",
|
||||
] }
|
||||
revolt-presence = { version = "0.8.6", path = "../../core/presence", features = [
|
||||
revolt-presence = { version = "0.8.7", path = "../../core/presence", features = [
|
||||
"redis-is-patched",
|
||||
] }
|
||||
|
||||
@@ -28,7 +28,7 @@ tokio = "1.39.2"
|
||||
async-trait = "0.1.81"
|
||||
ulid = "1.0.0"
|
||||
|
||||
authifier = "1.0.10"
|
||||
authifier = "1.0.15"
|
||||
|
||||
log = "0.4.11"
|
||||
pretty_env_logger = "0.4.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-delta"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
license = "AGPL-3.0-or-later"
|
||||
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
||||
edition = "2018"
|
||||
@@ -56,7 +56,7 @@ lettre = "0.10.0-alpha.4"
|
||||
rocket = { version = "0.5.1", default-features = false, features = ["json"] }
|
||||
rocket_cors = { git = "https://github.com/lawliet89/rocket_cors", rev = "072d90359b23e9b291df6b672c07c93de9c46011" }
|
||||
rocket_empty = { version = "0.1.1", features = ["schema"] }
|
||||
rocket_authifier = { version = "1.0.13" }
|
||||
rocket_authifier = { version = "1.0.15" }
|
||||
rocket_prometheus = "0.10.0-rc.3"
|
||||
|
||||
# spec generation
|
||||
@@ -67,7 +67,7 @@ revolt_rocket_okapi = { version = "0.10.0", features = ["swagger"] }
|
||||
amqprs = { version = "1.7.0" }
|
||||
|
||||
# core
|
||||
authifier = "1.0.13"
|
||||
authifier = "1.0.15"
|
||||
revolt-config = { path = "../core/config" }
|
||||
revolt-database = { path = "../core/database", features = [
|
||||
"rocket-impl",
|
||||
|
||||
@@ -9,6 +9,7 @@ mod channels;
|
||||
mod customisation;
|
||||
mod invites;
|
||||
mod onboard;
|
||||
mod policy;
|
||||
mod push;
|
||||
mod root;
|
||||
mod safety;
|
||||
@@ -36,6 +37,7 @@ pub fn mount(config: Settings, mut rocket: Rocket<Build>) -> Rocket<Build> {
|
||||
"/auth/session" => rocket_authifier::routes::session::routes(),
|
||||
"/auth/mfa" => rocket_authifier::routes::mfa::routes(),
|
||||
"/onboard" => onboard::routes(),
|
||||
"/policy" => policy::routes(),
|
||||
"/push" => push::routes(),
|
||||
"/sync" => sync::routes(),
|
||||
"/webhooks" => webhooks::routes()
|
||||
@@ -56,6 +58,7 @@ pub fn mount(config: Settings, mut rocket: Rocket<Build>) -> Rocket<Build> {
|
||||
"/auth/session" => rocket_authifier::routes::session::routes(),
|
||||
"/auth/mfa" => rocket_authifier::routes::mfa::routes(),
|
||||
"/onboard" => onboard::routes(),
|
||||
"/policy" => policy::routes(),
|
||||
"/push" => push::routes(),
|
||||
"/sync" => sync::routes()
|
||||
};
|
||||
|
||||
17
crates/delta/src/routes/policy/acknowledge_policy_changes.rs
Normal file
17
crates/delta/src/routes/policy/acknowledge_policy_changes.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use revolt_database::{events::client::EventV1, Database, Report, Snapshot, SnapshotContent, User};
|
||||
use revolt_models::v0::{ReportStatus, ReportedContent};
|
||||
use revolt_result::{create_error, Result};
|
||||
use serde::Deserialize;
|
||||
use ulid::Ulid;
|
||||
use validator::Validate;
|
||||
|
||||
use rocket::{serde::json::Json, State};
|
||||
|
||||
/// # Acknowledge Policy Changes
|
||||
///
|
||||
/// Accept/acknowledge changes to platform policy.
|
||||
#[openapi(tag = "Policy")]
|
||||
#[post("/acknowledge")]
|
||||
pub async fn acknowledge_policy_changes(db: &State<Database>, user: User) -> Result<()> {
|
||||
db.acknowledge_policy_changes(&user.id).await
|
||||
}
|
||||
11
crates/delta/src/routes/policy/mod.rs
Normal file
11
crates/delta/src/routes/policy/mod.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use revolt_rocket_okapi::revolt_okapi::openapi3::OpenApi;
|
||||
use rocket::Route;
|
||||
|
||||
mod acknowledge_policy_changes;
|
||||
|
||||
pub fn routes() -> (Vec<Route>, OpenApi) {
|
||||
openapi_get_routes_spec![
|
||||
// Policy
|
||||
acknowledge_policy_changes::acknowledge_policy_changes,
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-autumn"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
edition = "2021"
|
||||
license = "AGPL-3.0-or-later"
|
||||
|
||||
@@ -43,12 +43,12 @@ tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
|
||||
# Core crates
|
||||
revolt-files = { version = "0.8.6", path = "../../core/files" }
|
||||
revolt-config = { version = "0.8.6", path = "../../core/config" }
|
||||
revolt-database = { version = "0.8.6", path = "../../core/database", features = [
|
||||
revolt-files = { version = "0.8.7", path = "../../core/files" }
|
||||
revolt-config = { version = "0.8.7", path = "../../core/config" }
|
||||
revolt-database = { version = "0.8.7", path = "../../core/database", features = [
|
||||
"axum-impl",
|
||||
] }
|
||||
revolt-result = { version = "0.8.6", path = "../../core/result", features = [
|
||||
revolt-result = { version = "0.8.7", path = "../../core/result", features = [
|
||||
"utoipa",
|
||||
"axum",
|
||||
] }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt-january"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
edition = "2021"
|
||||
license = "AGPL-3.0-or-later"
|
||||
|
||||
@@ -32,13 +32,13 @@ tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
|
||||
# Core crates
|
||||
revolt-config = { version = "0.8.6", path = "../../core/config" }
|
||||
revolt-models = { version = "0.8.6", path = "../../core/models" }
|
||||
revolt-result = { version = "0.8.6", path = "../../core/result", features = [
|
||||
revolt-config = { version = "0.8.7", path = "../../core/config" }
|
||||
revolt-models = { version = "0.8.7", path = "../../core/models" }
|
||||
revolt-result = { version = "0.8.7", path = "../../core/result", features = [
|
||||
"utoipa",
|
||||
"axum",
|
||||
] }
|
||||
revolt-files = { version = "0.8.6", path = "../../core/files" }
|
||||
revolt-files = { version = "0.8.7", path = "../../core/files" }
|
||||
|
||||
# Axum / web server
|
||||
axum = { version = "0.7.5" }
|
||||
|
||||
Reference in New Issue
Block a user