use super::User; use owl::{db::model::file::File, dereference, get, prelude::*, update}; pub trait ProfilePic { fn profile_pic(&self) -> impl std::future::Future>>; fn set_profile_pic(&self, image: Vec) -> impl std::future::Future; } impl ProfilePic for User { /// Get a user's profile picture from the database async fn profile_pic(&self) -> Option> { 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) { 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()); }) } }