diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 7123d36..59991be 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -248,6 +248,21 @@ impl Blog { } }) } + + pub fn get_fqn(&self, conn: &PgConnection) -> String { + if self.instance_id == Instance::local_id(conn) { + self.actor_id.clone() + } else { + format!("{}@{}", self.actor_id, self.get_instance(conn).public_domain) + } + } + + pub fn to_json(&self, conn: &PgConnection) -> serde_json::Value { + let mut json = serde_json::to_value(self).unwrap(); + let formatted = serde_json::Value::String(format!("/~/{}",self.get_fqn(conn))); + json["fqn"] = formatted; + json + } } impl IntoId for Blog { diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 22f0244..3c0f1eb 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -187,8 +187,7 @@ impl Post { "author": self.get_authors(conn)[0].to_json(conn), "url": format!("/~/{}/{}/", blog.actor_id, self.slug), "date": self.creation_date.timestamp(), - "blog": blog, - "blog_url": format!("/~/{}", blog.actor_id) + "blog": blog.to_json(conn) }) }