refactor code to use Shrinkwraprs and diesel-derive-newtype (#598)
* add shrinkwraprs and implement Id thru it This also means we can automatically convert Id to String without using .into()! * cleanup with the help of clippy! * cleanup with the help of cargo fmt! * remove extra block * Shrinkwrap Page, ContentLen and RemoteForm * translations
This commit is contained in:
committed by
Baptiste Gelez
parent
59023e9602
commit
8c59c822b6
@@ -332,7 +332,7 @@ impl FromId<PlumeRocket> for Blog {
|
||||
.icon_image()
|
||||
.ok()
|
||||
.and_then(|icon| {
|
||||
let owner: String = icon.object_props.attributed_to_link::<Id>().ok()?.into();
|
||||
let owner = icon.object_props.attributed_to_link::<Id>().ok()?;
|
||||
Media::save_remote(
|
||||
&c.conn,
|
||||
icon.object_props.url_string().ok()?,
|
||||
@@ -348,7 +348,7 @@ impl FromId<PlumeRocket> for Blog {
|
||||
.image_image()
|
||||
.ok()
|
||||
.and_then(|banner| {
|
||||
let owner: String = banner.object_props.attributed_to_link::<Id>().ok()?.into();
|
||||
let owner = banner.object_props.attributed_to_link::<Id>().ok()?;
|
||||
Media::save_remote(
|
||||
&c.conn,
|
||||
banner.object_props.url_string().ok()?,
|
||||
|
||||
@@ -236,10 +236,7 @@ impl FromId<PlumeRocket> for Comment {
|
||||
})?,
|
||||
author_id: User::from_id(
|
||||
c,
|
||||
&{
|
||||
let res: String = note.object_props.attributed_to_link::<Id>()?.into();
|
||||
res
|
||||
},
|
||||
¬e.object_props.attributed_to_link::<Id>()?,
|
||||
None,
|
||||
)
|
||||
.map_err(|(_, e)| e)?
|
||||
|
||||
@@ -163,25 +163,11 @@ impl FromId<PlumeRocket> for Follow {
|
||||
}
|
||||
|
||||
fn from_activity(c: &PlumeRocket, follow: FollowAct) -> Result<Self> {
|
||||
let actor = User::from_id(
|
||||
c,
|
||||
&{
|
||||
let res: String = follow.follow_props.actor_link::<Id>()?.into();
|
||||
res
|
||||
},
|
||||
None,
|
||||
)
|
||||
.map_err(|(_, e)| e)?;
|
||||
let actor =
|
||||
User::from_id(c, &follow.follow_props.actor_link::<Id>()?, None).map_err(|(_, e)| e)?;
|
||||
|
||||
let target = User::from_id(
|
||||
c,
|
||||
&{
|
||||
let res: String = follow.follow_props.object_link::<Id>()?.into();
|
||||
res
|
||||
},
|
||||
None,
|
||||
)
|
||||
.map_err(|(_, e)| e)?;
|
||||
let target = User::from_id(c, &follow.follow_props.object_link::<Id>()?, None)
|
||||
.map_err(|(_, e)| e)?;
|
||||
Follow::accept_follow(&c.conn, &actor, &target, follow, actor.id, target.id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,26 +115,12 @@ impl FromId<PlumeRocket> for Like {
|
||||
let res = Like::insert(
|
||||
&c.conn,
|
||||
NewLike {
|
||||
post_id: Post::from_id(
|
||||
c,
|
||||
&{
|
||||
let res: String = act.like_props.object_link::<Id>()?.into();
|
||||
res
|
||||
},
|
||||
None,
|
||||
)
|
||||
.map_err(|(_, e)| e)?
|
||||
.id,
|
||||
user_id: User::from_id(
|
||||
c,
|
||||
&{
|
||||
let res: String = act.like_props.actor_link::<Id>()?.into();
|
||||
res
|
||||
},
|
||||
None,
|
||||
)
|
||||
.map_err(|(_, e)| e)?
|
||||
.id,
|
||||
post_id: Post::from_id(c, &act.like_props.object_link::<Id>()?, None)
|
||||
.map_err(|(_, e)| e)?
|
||||
.id,
|
||||
user_id: User::from_id(c, &act.like_props.actor_link::<Id>()?, None)
|
||||
.map_err(|(_, e)| e)?
|
||||
.id,
|
||||
ap_url: act.object_props.id_string()?,
|
||||
},
|
||||
)?;
|
||||
|
||||
@@ -642,7 +642,7 @@ impl FromId<PlumeRocket> for Post {
|
||||
.attributed_to_link_vec::<Id>()?
|
||||
.into_iter()
|
||||
.fold((None, vec![]), |(blog, mut authors), link| {
|
||||
let url: String = link.into();
|
||||
let url = link;
|
||||
match User::from_id(&c, &url, None) {
|
||||
Ok(u) => {
|
||||
authors.push(u);
|
||||
|
||||
@@ -140,26 +140,12 @@ impl FromId<PlumeRocket> for Reshare {
|
||||
let res = Reshare::insert(
|
||||
&c.conn,
|
||||
NewReshare {
|
||||
post_id: Post::from_id(
|
||||
c,
|
||||
&{
|
||||
let res: String = act.announce_props.object_link::<Id>()?.into();
|
||||
res
|
||||
},
|
||||
None,
|
||||
)
|
||||
.map_err(|(_, e)| e)?
|
||||
.id,
|
||||
user_id: User::from_id(
|
||||
c,
|
||||
&{
|
||||
let res: String = act.announce_props.actor_link::<Id>()?.into();
|
||||
res
|
||||
},
|
||||
None,
|
||||
)
|
||||
.map_err(|(_, e)| e)?
|
||||
.id,
|
||||
post_id: Post::from_id(c, &act.announce_props.object_link::<Id>()?, None)
|
||||
.map_err(|(_, e)| e)?
|
||||
.id,
|
||||
user_id: User::from_id(c, &act.announce_props.actor_link::<Id>()?, None)
|
||||
.map_err(|(_, e)| e)?
|
||||
.id,
|
||||
ap_url: act.object_props.id_string()?,
|
||||
},
|
||||
)?;
|
||||
|
||||
Reference in New Issue
Block a user