diff options
author | GeekCornerGH <[email protected]> | 2023-06-11 13:28:18 +0200 |
---|---|---|
committer | GeekCornerGH <[email protected]> | 2023-06-11 13:28:18 +0200 |
commit | 2d66292350d352c3ea41db08d4c2de33898e9806 (patch) | |
tree | d41f087f7a173c24f6d6f0da5eb378e69bd0d4c4 /src/db/models | |
parent | adf67a8ee887d21e104adfa8b6521d7971f5a1f1 (diff) | |
download | vaultwarden-2d66292350d352c3ea41db08d4c2de33898e9806.tar.gz vaultwarden-2d66292350d352c3ea41db08d4c2de33898e9806.zip |
feat: Push Notifications
Co-authored-by: samb-devel <[email protected]>
Co-authored-by: Zoruk <[email protected]>
Diffstat (limited to 'src/db/models')
-rw-r--r-- | src/db/models/device.rs | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/db/models/device.rs b/src/db/models/device.rs index e47ccadc..a1f4aee9 100644 --- a/src/db/models/device.rs +++ b/src/db/models/device.rs @@ -15,7 +15,8 @@ db_object! { pub user_uuid: String, pub name: String, - pub atype: i32, // https://github.com/bitwarden/server/blob/master/src/Core/Enums/DeviceType.cs + pub atype: i32, // https://github.com/bitwarden/server/blob/master/src/Core/Enums/DeviceType.cs + pub push_uuid: Option<String>, pub push_token: Option<String>, pub refresh_token: String, @@ -38,6 +39,7 @@ impl Device { name, atype, + push_uuid: None, push_token: None, refresh_token: String::new(), twofactor_remember: None, @@ -155,6 +157,35 @@ impl Device { }} } + pub async fn find_by_user(user_uuid: &str, conn: &mut DbConn) -> Vec<Self> { + db_run! { conn: { + devices::table + .filter(devices::user_uuid.eq(user_uuid)) + .load::<DeviceDb>(conn) + .expect("Error loading devices") + .from_db() + }} + } + + pub async fn find_by_uuid(uuid: &str, conn: &mut DbConn) -> Option<Self> { + db_run! { conn: { + devices::table + .filter(devices::uuid.eq(uuid)) + .first::<DeviceDb>(conn) + .ok() + .from_db() + }} + } + + pub async fn clear_push_token_by_uuid(uuid: &str, conn: &mut DbConn) -> EmptyResult { + db_run! { conn: { + diesel::update(devices::table) + .filter(devices::uuid.eq(uuid)) + .set(devices::push_token.eq::<Option<String>>(None)) + .execute(conn) + .map_res("Error removing push token") + }} + } pub async fn find_by_refresh_token(refresh_token: &str, conn: &mut DbConn) -> Option<Self> { db_run! { conn: { devices::table @@ -175,4 +206,14 @@ impl Device { .from_db() }} } + pub async fn find_push_device_by_user(user_uuid: &str, conn: &mut DbConn) -> Vec<Self> { + db_run! { conn: { + devices::table + .filter(devices::user_uuid.eq(user_uuid)) + .filter(devices::push_token.is_not_null()) + .load::<DeviceDb>(conn) + .expect("Error loading push devices") + .from_db() + }} + } } |