diff --git a/src/federation/activities/accept.rs b/src/federation/activities/accept.rs index 7b8aa6b..9dc6b11 100644 --- a/src/federation/activities/accept.rs +++ b/src/federation/activities/accept.rs @@ -20,7 +20,7 @@ pub struct Accept { impl Accept { pub fn new(actor: ObjectId, object: Follow) -> MyResult { - let id = generate_object_id(actor.inner().domain().unwrap())?; + let id = generate_object_id(actor.inner())?; Ok(Accept { actor, object, diff --git a/src/federation/activities/follow.rs b/src/federation/activities/follow.rs index 90d5089..07fc85f 100644 --- a/src/federation/activities/follow.rs +++ b/src/federation/activities/follow.rs @@ -22,7 +22,7 @@ pub struct Follow { impl Follow { pub fn new(actor: ObjectId, object: ObjectId) -> MyResult { - let id = generate_object_id(actor.inner().domain().unwrap())?; + let id = generate_object_id(actor.inner())?; Ok(Follow { actor, object, diff --git a/src/federation/activities/update.rs b/src/federation/activities/update.rs index ebba508..29ae0fa 100644 --- a/src/federation/activities/update.rs +++ b/src/federation/activities/update.rs @@ -25,7 +25,7 @@ pub struct Update { impl Update { pub fn new(actor: ObjectId, object: ObjectId) -> MyResult { - let id = generate_object_id(actor.inner().domain().unwrap())?; + let id = generate_object_id(actor.inner())?; Ok(Update { actor, object, diff --git a/src/federation/objects/article.rs b/src/federation/objects/article.rs index 0598327..83fb7b8 100644 --- a/src/federation/objects/article.rs +++ b/src/federation/objects/article.rs @@ -21,7 +21,7 @@ pub struct DbArticle { impl DbArticle { pub fn new(text: String, attributed_to: ObjectId) -> Result { - let ap_id = generate_object_id(attributed_to.inner().domain().unwrap())?.into(); + let ap_id = generate_object_id(attributed_to.inner())?.into(); Ok(DbArticle { text, ap_id, diff --git a/src/utils.rs b/src/utils.rs index 6b5f9d0..dc21bf5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -3,7 +3,8 @@ use url::{ParseError, Url}; /// Just generate random url as object id. In a real project, you probably want to use /// an url which contains the database id for easy retrieval (or store the random id in db). -pub fn generate_object_id(domain: &str) -> Result { +pub fn generate_object_id(domain: &Url) -> Result { + let domain = domain.domain().unwrap(); let id: String = thread_rng() .sample_iter(&Alphanumeric) .take(7)