|
|
|
@ -172,7 +172,7 @@ impl Blog {
|
|
|
|
|
let mut icon = Image::default();
|
|
|
|
|
icon.object_props.set_url_string(
|
|
|
|
|
self.icon_id
|
|
|
|
|
.and_then(|id| Media::get(conn, id).and_then(|m| m.url(conn)).ok())
|
|
|
|
|
.and_then(|id| Media::get(conn, id).and_then(|m| m.url()).ok())
|
|
|
|
|
.unwrap_or_default(),
|
|
|
|
|
)?;
|
|
|
|
|
icon.object_props.set_attributed_to_link(
|
|
|
|
@ -189,7 +189,7 @@ impl Blog {
|
|
|
|
|
let mut banner = Image::default();
|
|
|
|
|
banner.object_props.set_url_string(
|
|
|
|
|
self.banner_id
|
|
|
|
|
.and_then(|id| Media::get(conn, id).and_then(|m| m.url(conn)).ok())
|
|
|
|
|
.and_then(|id| Media::get(conn, id).and_then(|m| m.url()).ok())
|
|
|
|
|
.unwrap_or_default(),
|
|
|
|
|
)?;
|
|
|
|
|
banner.object_props.set_attributed_to_link(
|
|
|
|
@ -271,14 +271,14 @@ impl Blog {
|
|
|
|
|
|
|
|
|
|
pub fn icon_url(&self, conn: &Connection) -> String {
|
|
|
|
|
self.icon_id
|
|
|
|
|
.and_then(|id| Media::get(conn, id).and_then(|m| m.url(conn)).ok())
|
|
|
|
|
.and_then(|id| Media::get(conn, id).and_then(|m| m.url()).ok())
|
|
|
|
|
.unwrap_or_else(|| "/static/default-avatar.png".to_string())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn banner_url(&self, conn: &Connection) -> Option<String> {
|
|
|
|
|
self.banner_id
|
|
|
|
|
.and_then(|i| Media::get(conn, i).ok())
|
|
|
|
|
.and_then(|c| c.url(conn).ok())
|
|
|
|
|
.and_then(|c| c.url().ok())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn delete(&self, conn: &Connection, searcher: &Searcher) -> Result<()> {
|
|
|
|
@ -407,7 +407,9 @@ impl AsActor<&PlumeRocket> for Blog {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn is_local(&self) -> bool {
|
|
|
|
|
self.instance_id == 1 // TODO: this is not always true
|
|
|
|
|
Instance::get_local()
|
|
|
|
|
.map(|i| self.instance_id == i.id)
|
|
|
|
|
.unwrap_or(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -474,7 +476,7 @@ pub(crate) mod tests {
|
|
|
|
|
"BlogName".to_owned(),
|
|
|
|
|
"Blog name".to_owned(),
|
|
|
|
|
"This is a small blog".to_owned(),
|
|
|
|
|
Instance::get_local(conn).unwrap().id,
|
|
|
|
|
Instance::get_local().unwrap().id,
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
@ -485,7 +487,7 @@ pub(crate) mod tests {
|
|
|
|
|
"MyBlog".to_owned(),
|
|
|
|
|
"My blog".to_owned(),
|
|
|
|
|
"Welcome to my blog".to_owned(),
|
|
|
|
|
Instance::get_local(conn).unwrap().id,
|
|
|
|
|
Instance::get_local().unwrap().id,
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
@ -496,7 +498,7 @@ pub(crate) mod tests {
|
|
|
|
|
"WhyILikePlume".to_owned(),
|
|
|
|
|
"Why I like Plume".to_owned(),
|
|
|
|
|
"In this blog I will explay you why I like Plume so much".to_owned(),
|
|
|
|
|
Instance::get_local(conn).unwrap().id,
|
|
|
|
|
Instance::get_local().unwrap().id,
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
@ -556,7 +558,7 @@ pub(crate) mod tests {
|
|
|
|
|
"SomeName".to_owned(),
|
|
|
|
|
"Some name".to_owned(),
|
|
|
|
|
"This is some blog".to_owned(),
|
|
|
|
|
Instance::get_local(conn).unwrap().id,
|
|
|
|
|
Instance::get_local().unwrap().id,
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
@ -564,7 +566,7 @@ pub(crate) mod tests {
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
blog.get_instance(conn).unwrap().id,
|
|
|
|
|
Instance::get_local(conn).unwrap().id
|
|
|
|
|
Instance::get_local().unwrap().id
|
|
|
|
|
);
|
|
|
|
|
// TODO add tests for remote instance
|
|
|
|
|
|
|
|
|
@ -584,7 +586,7 @@ pub(crate) mod tests {
|
|
|
|
|
"SomeName".to_owned(),
|
|
|
|
|
"Some name".to_owned(),
|
|
|
|
|
"This is some blog".to_owned(),
|
|
|
|
|
Instance::get_local(conn).unwrap().id,
|
|
|
|
|
Instance::get_local().unwrap().id,
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
@ -595,7 +597,7 @@ pub(crate) mod tests {
|
|
|
|
|
"Blog".to_owned(),
|
|
|
|
|
"Blog".to_owned(),
|
|
|
|
|
"I've named my blog Blog".to_owned(),
|
|
|
|
|
Instance::get_local(conn).unwrap().id,
|
|
|
|
|
Instance::get_local().unwrap().id,
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
@ -687,7 +689,7 @@ pub(crate) mod tests {
|
|
|
|
|
"SomeName".to_owned(),
|
|
|
|
|
"Some name".to_owned(),
|
|
|
|
|
"This is some blog".to_owned(),
|
|
|
|
|
Instance::get_local(conn).unwrap().id,
|
|
|
|
|
Instance::get_local().unwrap().id,
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
@ -711,7 +713,7 @@ pub(crate) mod tests {
|
|
|
|
|
"SomeName".to_owned(),
|
|
|
|
|
"Some name".to_owned(),
|
|
|
|
|
"This is some blog".to_owned(),
|
|
|
|
|
Instance::get_local(conn).unwrap().id,
|
|
|
|
|
Instance::get_local().unwrap().id,
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
@ -749,7 +751,7 @@ pub(crate) mod tests {
|
|
|
|
|
"SomeName".to_owned(),
|
|
|
|
|
"Some name".to_owned(),
|
|
|
|
|
"This is some blog".to_owned(),
|
|
|
|
|
Instance::get_local(conn).unwrap().id,
|
|
|
|
|
Instance::get_local().unwrap().id,
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
@ -760,7 +762,7 @@ pub(crate) mod tests {
|
|
|
|
|
"Blog".to_owned(),
|
|
|
|
|
"Blog".to_owned(),
|
|
|
|
|
"I've named my blog Blog".to_owned(),
|
|
|
|
|
Instance::get_local(conn).unwrap().id,
|
|
|
|
|
Instance::get_local().unwrap().id,
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
|