feat: support rauth events

feat: add platform user wipe event
This commit is contained in:
Paul Makles
2023-01-20 15:43:45 +00:00
parent cf9c0bc5e1
commit fed1da72fd
8 changed files with 58 additions and 14 deletions

14
Cargo.lock generated
View File

@@ -2580,8 +2580,8 @@ dependencies = [
[[package]]
name = "rauth"
version = "1.0.0"
source = "git+https://github.com/insertish/rauth?rev=195f1703cc4c57be01a39f465296cab4e22524b3#195f1703cc4c57be01a39f465296cab4e22524b3"
version = "1.0.2"
source = "git+https://github.com/insertish/rauth?tag=1.0.2#d466718bb4f1c8ca03f4a17265a646a52e07dff5"
dependencies = [
"async-std",
"async-trait",
@@ -2790,7 +2790,7 @@ dependencies = [
[[package]]
name = "revolt-bonfire"
version = "0.5.5"
version = "0.5.6"
dependencies = [
"async-std",
"async-tungstenite",
@@ -2806,7 +2806,7 @@ dependencies = [
[[package]]
name = "revolt-delta"
version = "0.5.5"
version = "0.5.6"
dependencies = [
"async-channel",
"async-std",
@@ -2846,7 +2846,7 @@ dependencies = [
[[package]]
name = "revolt-quark"
version = "0.1.0"
version = "0.5.6"
dependencies = [
"async-recursion",
"async-std",
@@ -3080,8 +3080,8 @@ dependencies = [
[[package]]
name = "rocket_rauth"
version = "1.0.0"
source = "git+https://github.com/insertish/rauth?rev=195f1703cc4c57be01a39f465296cab4e22524b3#195f1703cc4c57be01a39f465296cab4e22524b3"
version = "1.0.2"
source = "git+https://github.com/insertish/rauth?tag=1.0.2#d466718bb4f1c8ca03f4a17265a646a52e07dff5"
dependencies = [
"iso8601-timestamp",
"rauth",

View File

@@ -1,6 +1,6 @@
[package]
name = "revolt-bonfire"
version = "0.5.5"
version = "0.5.6"
license = "AGPL-3.0-or-later"
edition = "2021"

View File

@@ -1,6 +1,6 @@
[package]
name = "revolt-delta"
version = "0.5.5"
version = "0.5.6"
license = "AGPL-3.0-or-later"
authors = ["Paul Makles <paulmakles@gmail.com>"]
edition = "2018"
@@ -52,7 +52,7 @@ mobc-redis = { version = "0.7.0", default-features = false, features = ["async-s
# web
rocket = { version = "0.5.0-rc.2", default-features = false, features = ["json"] }
rocket_empty = { version = "0.1.1", features = ["schema"] }
rocket_rauth = { git = "https://github.com/insertish/rauth", rev = "195f1703cc4c57be01a39f465296cab4e22524b3" }
rocket_rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.2" }
# spec generation
schemars = "0.8.8"

View File

@@ -10,7 +10,9 @@ extern crate lazy_static;
pub mod routes;
pub mod util;
use revolt_quark::rauth::RAuth;
use async_std::channel::unbounded;
use revolt_quark::events::client::EventV1;
use revolt_quark::rauth::{RAuth, RAuthEvent};
use revolt_quark::DatabaseInfo;
#[launch]
@@ -25,13 +27,33 @@ async fn rocket() -> _ {
let db = DatabaseInfo::Auto.connect().await.unwrap();
db.migrate_database().await.unwrap();
// Setup rAuth event channel
let (sender, receiver) = unbounded();
// Setup rAuth
let rauth = RAuth {
database: db.clone().into(),
config: revolt_quark::util::rauth::config(),
event_channel: Some(sender),
};
// Launch background task workers.
// Launch a listener for rAuth events
async_std::task::spawn(async move {
while let Ok(event) = receiver.recv().await {
match &event {
RAuthEvent::CreateSession { .. } | RAuthEvent::CreateAccount { .. } => {
EventV1::Auth(event).global().await
}
RAuthEvent::DeleteSession { user_id, .. }
| RAuthEvent::DeleteAllSessions { user_id, .. } => {
let id = user_id.to_string();
EventV1::Auth(event).private(id).await
}
}
}
});
// Launch background task workers
async_std::task::spawn(revolt_quark::tasks::start_workers(db.clone()));
// Configure CORS

View File

@@ -1,6 +1,6 @@
[package]
name = "revolt-quark"
version = "0.1.0"
version = "0.5.6"
license = "AGPL-3.0-or-later"
edition = "2021"
@@ -84,7 +84,7 @@ rocket_empty = { version = "0.1.1", optional = true, features = [ "schema" ] }
rocket_cors = { optional = true, git = "https://github.com/lawliet89/rocket_cors", rev = "c17e8145baa4790319fdb6a473e465b960f55e7c" }
# rAuth
rauth = { git = "https://github.com/insertish/rauth", rev = "195f1703cc4c57be01a39f465296cab4e22524b3", features = [ "async-std-runtime" ] }
rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.2", features = [ "async-std-runtime" ] }
# Sentry
sentry = "0.25.0"

View File

@@ -1,3 +1,4 @@
use rauth::RAuthEvent;
use serde::{Deserialize, Serialize};
use crate::models::channel::{FieldsChannel, PartialChannel};
@@ -195,9 +196,23 @@ pub enum EventV1 {
/// Settings updated remotely
UserSettingsUpdate { id: String, update: UserSettings },
/// User has been platform banned or deleted their account
///
/// Clients should remove the following associated data:
/// - Messages
/// - DM Channels
/// - Relationships
/// - Server Memberships
///
/// User flags are specified to explain why a wipe is occurring though not all reasons will necessarily ever appear.
UserPlatformWipe { user_id: String, flags: i32 },
/// New emoji
EmojiCreate(Emoji),
/// Delete emoji
EmojiDelete { id: String },
/// Auth events
Auth(RAuthEvent),
}

View File

@@ -559,4 +559,9 @@ impl EventV1 {
pub async fn private(self, id: String) {
self.p(format!("{}!", id)).await;
}
/// Publish internal global event
pub async fn global(self) {
self.p("global".to_string()).await;
}
}

View File

@@ -105,6 +105,8 @@ pub enum Flags {
Deleted = 2,
/// User was banned off the platform
Banned = 4,
/// User was marked as spam and removed from platform
Spam = 8,
}
/// Bot information for if the user is a bot