This commit is contained in:
Felix Ableitner 2024-04-10 11:03:29 +02:00
parent 5798eb35c6
commit 2739ebe3c3
2 changed files with 26 additions and 12 deletions

View file

@ -21,7 +21,6 @@ pub struct DbPost {
pub text: String, pub text: String,
pub ap_id: ObjectId<DbPost>, pub ap_id: ObjectId<DbPost>,
pub creator: ObjectId<DbUser>, pub creator: ObjectId<DbUser>,
pub local: bool,
} }
#[derive(Deserialize, Serialize, Debug)] #[derive(Deserialize, Serialize, Debug)]
@ -59,7 +58,15 @@ impl Object for DbPost {
} }
async fn into_json(self, _data: &Data<Self::DataType>) -> Result<Self::Kind, Self::Error> { async fn into_json(self, _data: &Data<Self::DataType>) -> Result<Self::Kind, Self::Error> {
unimplemented!() Ok(Note {
kind: NoteType::Note,
id: self.ap_id,
content: self.text,
attributed_to: self.creator,
to: vec![public()],
tag: vec![],
in_reply_to: None,
})
} }
async fn verify( async fn verify(
@ -81,7 +88,6 @@ impl Object for DbPost {
text: json.content, text: json.content,
ap_id: json.id.clone(), ap_id: json.id.clone(),
creator: json.attributed_to.clone(), creator: json.attributed_to.clone(),
local: false,
}; };
let mention = Mention { let mention = Mention {

View file

@ -343,20 +343,28 @@ impl<T: Clone> FederationMiddleware<T> {
} }
#[cfg(test)] #[cfg(test)]
#[allow(clippy::unwrap_used)]
mod test { mod test {
#[tokio::test] use super::*;
async fn test_url_is_local() -> Result<(), Error> {
let config = FederationConfig::builder() async fn config() -> FederationConfig<i32> {
FederationConfig::builder()
.domain("example.com") .domain("example.com")
.app_data(1) .app_data(1)
.build() .build()
.await .await
.unwrap(); .unwrap()
assert_eq!( }
true, #[tokio::test]
config.is_local_url(&Url::parse("http://example.com")?) async fn test_url_is_local() -> Result<(), Error> {
); let config = config().await;
assert_eq!(false, config.is_local_url(&Url::parse("http://other.com")?)); assert!(config.is_local_url(&Url::parse("http://example.com")?));
assert!(!config.is_local_url(&Url::parse("http://other.com")?));
Ok(()) Ok(())
} }
#[tokio::test]
async fn test_get_domain() {
let config = config().await;
assert_eq!("example.com", config.domain());
}
} }