add functions to delete media from specific local users

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-08-25 11:46:47 -04:00 committed by Jason Volk
commit 6b65a8fc86
2 changed files with 51 additions and 5 deletions

View file

@ -6,7 +6,7 @@ use conduit::{
Err, Error, Result,
};
use database::{Database, Map};
use ruma::{api::client::error::ErrorKind, http_headers::ContentDisposition, Mxc, UserId};
use ruma::{api::client::error::ErrorKind, http_headers::ContentDisposition, Mxc, OwnedMxcUri, UserId};
use super::preview::UrlPreviewData;
@ -176,6 +176,23 @@ impl Data {
})
}
/// Gets all the MXCs associated with a user
pub(super) fn get_all_user_mxcs(&self, user_id: &UserId) -> Vec<OwnedMxcUri> {
let user_id = user_id.as_bytes().to_vec();
self.mediaid_user
.iter()
.filter_map(|(key, user)| {
if *user == user_id {
let mxc_s = string_from_bytes(&key).ok()?;
Some(OwnedMxcUri::from(mxc_s))
} else {
None
}
})
.collect()
}
/// Gets all the media keys in our database (this includes all the metadata
/// associated with it such as width, height, content-type, etc)
pub(crate) fn get_all_media_keys(&self) -> Vec<Vec<u8>> { self.mediaid_file.iter().map(|(key, _)| key).collect() }