From ae2194cce81cfcd154e73a95cf88968c8f7e045f Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Thu, 29 Aug 2024 20:17:35 +0100 Subject: [PATCH] chore: (wip) suspend bindings --- crates/bindings/node/src/lib.rs | 24 +++++++++++++++++-- .../core/database/src/models/users/model.rs | 8 +++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/crates/bindings/node/src/lib.rs b/crates/bindings/node/src/lib.rs index 4fb2975f..7a01f743 100644 --- a/crates/bindings/node/src/lib.rs +++ b/crates/bindings/node/src/lib.rs @@ -89,11 +89,19 @@ struct ResultBinding { } macro_rules! shim { - ($cx: ident, $name: ident, $( $variable: ident $type: ident $id: expr )+, | $db: ident | $closure: expr, $( $arg: expr, )+) => { + ($cx: ident, $name: ident, $( $variable: ident $type: ident $id: expr )*, $( $model: ident $modelType: ident $modelId: expr )*, | $db: ident | $closure: expr, $( $arg: expr, )+) => { fn $name(mut cx: FunctionContext) -> JsResult { $( let $variable = cx.argument::<$type>($id)?.value(&mut cx); - )+ + )* + + $( + let mut $model = if let Model::$modelType(value) = cx.argument::>($modelId)?.give() { + value + } else { + unreachable!() + }; + )* let (db, channel) = cx.this::>()?.take(); let (deferred, promise) = cx.promise(); @@ -158,6 +166,7 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> { proc_channels_create_dm, user_a JsString 0 user_b JsString 1, + , |db| async move { let user_a = db.fetch_user(&user_a).await?; let user_b = db.fetch_user(&user_b).await?; @@ -166,5 +175,16 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> { &userA, &userB, ); + shim!( + cx, + proc_users_suspend, + , + user User 0, + |db| async move { + user.suspend(&db).await + }, + &user, + ); + Ok(()) } diff --git a/crates/core/database/src/models/users/model.rs b/crates/core/database/src/models/users/model.rs index 2639504a..6a2557ac 100644 --- a/crates/core/database/src/models/users/model.rs +++ b/crates/core/database/src/models/users/model.rs @@ -662,6 +662,14 @@ impl User { } } + /// Suspend the user + pub async fn suspend(&mut self, db: &Database) -> Result<()> { + // Remove sessions (logout all) + // Mark user as suspended + // Disable account + Ok(()) + } + /// Mark as deleted pub async fn mark_deleted(&mut self, db: &Database) -> Result<()> { self.update(