ActorType,
};
use activitypub_federation::{
- core::{inbox::ActorPublicKey, object_id::ObjectId},
+ core::object_id::ObjectId,
deser::values::MediaTypeHtml,
- traits::ApubObject,
+ traits::{Actor, ApubObject},
utils::verify_domains_match,
};
use chrono::NaiveDateTime;
use lemmy_api_common::utils::blocking;
use lemmy_db_schema::{
source::site::{Site, SiteForm},
- utils::naive_now,
+ utils::{naive_now, DbPool},
};
use lemmy_utils::{
error::LemmyError,
data: &Self::DataType,
_request_counter: &mut i32,
) -> Result<(), LemmyError> {
- check_apub_id_valid_with_strictness(apub.id.inner(), true, &data.settings())?;
+ check_apub_id_valid_with_strictness(apub.id.inner(), true, data.settings())?;
verify_domains_match(expected_domain, apub.id.inner())?;
let slur_regex = &data.settings().slur_regex();
fn private_key(&self) -> Option<String> {
self.private_key.to_owned()
}
-
- fn inbox_url(&self) -> Url {
- self.inbox_url.clone().into()
- }
-
- fn shared_inbox_url(&self) -> Option<Url> {
- None
- }
}
-impl ActorPublicKey for ApubSite {
+impl Actor for ApubSite {
fn public_key(&self) -> &str {
&self.public_key
}
+
+ fn inbox(&self) -> Url {
+ self.inbox_url.clone().into()
+ }
}
/// Instance actor is at the root path, so we simply need to clear the path and other unnecessary
// try to fetch the instance actor (to make things like instance rules available)
let instance_id = instance_actor_id_from_url(object_id);
let site = ObjectId::<ApubSite>::new(instance_id.clone())
- .dereference::<LemmyError>(context, local_instance(context), request_counter)
+ .dereference(context, local_instance(context), request_counter)
.await;
if let Err(e) = site {
debug!("Failed to dereference site for {}: {}", instance_id, e);
}
}
+pub(crate) async fn remote_instance_inboxes(pool: &DbPool) -> Result<Vec<Url>, LemmyError> {
+ Ok(
+ blocking(pool, Site::read_remote_sites)
+ .await??
+ .into_iter()
+ .map(|s| ApubSite::from(s).shared_inbox_or_inbox())
+ .collect(),
+ )
+}
+
#[cfg(test)]
pub(crate) mod tests {
use super::*;
#[serial]
async fn test_parse_lemmy_instance() {
let context = init_context();
+ let conn = &mut context.pool().get().unwrap();
let site = parse_lemmy_instance(&context).await;
assert_eq!(site.name, "Enterprise");
assert_eq!(site.description.as_ref().unwrap().len(), 15);
- Site::delete(&*context.pool().get().unwrap(), site.id).unwrap();
+ Site::delete(conn, site.id).unwrap();
}
}