26 lines
911 B
Rust
26 lines
911 B
Rust
use super::User;
|
|
use owl::{db::model::file::File, dereference, get, prelude::*, update};
|
|
pub trait ProfilePic {
|
|
fn profile_pic(&self) -> impl std::future::Future<Output = Option<Vec<u8>>>;
|
|
fn set_profile_pic(&self, image: Vec<u8>) -> impl std::future::Future<Output = ()>;
|
|
}
|
|
|
|
impl ProfilePic for User {
|
|
/// Get a user's profile picture from the database
|
|
async fn profile_pic(&self) -> Option<Vec<u8>> {
|
|
self.profile_picture
|
|
.as_ref()
|
|
.map(|x| dereference!(x).read_file(&owl::DB.get().unwrap()))
|
|
}
|
|
|
|
/// Set a user's profile picture in the database
|
|
async fn set_profile_pic(&self, image: Vec<u8>) {
|
|
let mut target = vec![get!(self.id.clone()).unwrap()];
|
|
|
|
let file = File::new(image, None, &owl::DB.get().unwrap());
|
|
|
|
update!(&mut target, |u: &mut User| {
|
|
u.profile_picture = Some(file.reference());
|
|
})
|
|
}
|
|
}
|