Rename: FromId::from_id07 -> from_id

This commit is contained in:
Kitaiti Makoto 2022-05-02 19:24:36 +09:00
parent 0ab7774e29
commit 28440271bb
12 changed files with 24 additions and 24 deletions

View File

@ -223,7 +223,7 @@ where
} }
// Transform this actor to a model (see FromId for details about the from_id function) // Transform this actor to a model (see FromId for details about the from_id function)
let actor = match A::from_id07( let actor = match A::from_id(
ctx, ctx,
&actor_id, &actor_id,
serde_json::from_value(act["actor"].clone()).ok(), serde_json::from_value(act["actor"].clone()).ok(),
@ -244,7 +244,7 @@ where
Some(x) => x, Some(x) => x,
None => return Self::NotHandled(ctx, act, InboxError::InvalidObject(None)), None => return Self::NotHandled(ctx, act, InboxError::InvalidObject(None)),
}; };
let obj = match M::from_id07( let obj = match M::from_id(
ctx, ctx,
&obj_id, &obj_id,
serde_json::from_value(act["object"].clone()).ok(), serde_json::from_value(act["object"].clone()).ok(),
@ -343,7 +343,7 @@ pub trait FromId<C>: Sized {
/// - `id`: the ActivityPub ID of the object to find /// - `id`: the ActivityPub ID of the object to find
/// - `object`: optional object that will be used if the object was not found in the database /// - `object`: optional object that will be used if the object was not found in the database
/// If absent, the ID will be dereferenced. /// If absent, the ID will be dereferenced.
fn from_id07( fn from_id(
ctx: &C, ctx: &C,
id: &str, id: &str,
object: Option<Self::Object>, object: Option<Self::Object>,

View File

@ -160,7 +160,7 @@ impl Blog {
.find(|l| l.mime_type == Some(String::from("application/activity+json"))) .find(|l| l.mime_type == Some(String::from("application/activity+json")))
.ok_or(Error::Webfinger) .ok_or(Error::Webfinger)
.and_then(|l| { .and_then(|l| {
Blog::from_id07( Blog::from_id(
conn, conn,
&l.href.ok_or(Error::MissingApProperty)?, &l.href.ok_or(Error::MissingApProperty)?,
None, None,
@ -526,7 +526,7 @@ impl FromId<DbConn> for Blog {
Media::save_remote( Media::save_remote(
conn, conn,
icon.url()?.to_as_uri()?, icon.url()?.to_as_uri()?,
&User::from_id07(conn, &owner, None, CONFIG.proxy()).ok()?, &User::from_id(conn, &owner, None, CONFIG.proxy()).ok()?,
) )
.ok() .ok()
}) })
@ -543,7 +543,7 @@ impl FromId<DbConn> for Blog {
Media::save_remote( Media::save_remote(
conn, conn,
banner.url()?.to_as_uri()?, banner.url()?.to_as_uri()?,
&User::from_id07(conn, &owner, None, CONFIG.proxy()).ok()?, &User::from_id(conn, &owner, None, CONFIG.proxy()).ok()?,
) )
.ok() .ok()
}) })

View File

@ -349,7 +349,7 @@ impl FromId<DbConn> for Comment {
post_id: previous_comment.map(|c| c.post_id).or_else(|_| { post_id: previous_comment.map(|c| c.post_id).or_else(|_| {
Ok(Post::find_by_ap_url(conn, previous_url.as_str())?.id) as Result<i32> Ok(Post::find_by_ap_url(conn, previous_url.as_str())?.id) as Result<i32>
})?, })?,
author_id: User::from_id07( author_id: User::from_id(
conn, conn,
&note &note
.attributed_to() .attributed_to()
@ -402,7 +402,7 @@ impl FromId<DbConn> for Comment {
let receivers_ap_url = receiver_ids let receivers_ap_url = receiver_ids
.into_iter() .into_iter()
.flat_map(|v| { .flat_map(|v| {
if let Ok(user) = User::from_id07(conn, v.as_ref(), None, CONFIG.proxy()) { if let Ok(user) = User::from_id(conn, v.as_ref(), None, CONFIG.proxy()) {
vec![user] vec![user]
} else { } else {
vec![] // TODO try to fetch collection vec![] // TODO try to fetch collection

View File

@ -265,7 +265,7 @@ impl FromId<DbConn> for Follow {
} }
fn from_activity07(conn: &DbConn, follow: FollowAct07) -> Result<Self> { fn from_activity07(conn: &DbConn, follow: FollowAct07) -> Result<Self> {
let actor = User::from_id07( let actor = User::from_id(
conn, conn,
follow follow
.actor_field_ref() .actor_field_ref()
@ -277,7 +277,7 @@ impl FromId<DbConn> for Follow {
) )
.map_err(|(_, e)| e)?; .map_err(|(_, e)| e)?;
let target = User::from_id07( let target = User::from_id(
conn, conn,
follow follow
.object_field_ref() .object_field_ref()

View File

@ -150,7 +150,7 @@ impl FromId<DbConn> for Like {
let res = Like::insert( let res = Like::insert(
conn, conn,
NewLike { NewLike {
post_id: Post::from_id07( post_id: Post::from_id(
conn, conn,
act.object_field_ref() act.object_field_ref()
.as_single_id() .as_single_id()
@ -161,7 +161,7 @@ impl FromId<DbConn> for Like {
) )
.map_err(|(_, e)| e)? .map_err(|(_, e)| e)?
.id, .id,
user_id: User::from_id07( user_id: User::from_id(
conn, conn,
act.actor_field_ref() act.actor_field_ref()
.as_single_id() .as_single_id()

View File

@ -275,7 +275,7 @@ impl Media {
remote_url: None, remote_url: None,
sensitive: image.object_props.summary_string().is_ok(), sensitive: image.object_props.summary_string().is_ok(),
content_warning: image.object_props.summary_string().ok(), content_warning: image.object_props.summary_string().ok(),
owner_id: User::from_id07( owner_id: User::from_id(
conn, conn,
image image
.object_props .object_props
@ -362,7 +362,7 @@ impl Media {
remote_url: None, remote_url: None,
sensitive: summary.is_some(), sensitive: summary.is_some(),
content_warning: summary, content_warning: summary,
owner_id: User::from_id07( owner_id: User::from_id(
conn, conn,
&image &image
.attributed_to() .attributed_to()

View File

@ -883,14 +883,14 @@ impl FromId<DbConn> for Post {
.iter() .iter()
.fold((None, vec![]), |(blog, mut authors), link| { .fold((None, vec![]), |(blog, mut authors), link| {
if let Some(url) = link.id() { if let Some(url) = link.id() {
match User::from_id07(conn, url.as_str(), None, CONFIG.proxy()) { match User::from_id(conn, url.as_str(), None, CONFIG.proxy()) {
Ok(u) => { Ok(u) => {
authors.push(u); authors.push(u);
(blog, authors) (blog, authors)
} }
Err(_) => ( Err(_) => (
blog.or_else(|| { blog.or_else(|| {
Blog::from_id07(conn, url.as_str(), None, CONFIG.proxy()).ok() Blog::from_id(conn, url.as_str(), None, CONFIG.proxy()).ok()
}), }),
authors, authors,
), ),
@ -1155,7 +1155,7 @@ impl AsObject<User, Update07, &DbConn> for PostUpdate {
fn activity07(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> { fn activity07(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> {
let mut post = let mut post =
Post::from_id07(conn, &self.ap_url, None, CONFIG.proxy()).map_err(|(_, e)| e)?; Post::from_id(conn, &self.ap_url, None, CONFIG.proxy()).map_err(|(_, e)| e)?;
if !post.is_author(conn, actor.id)? { if !post.is_author(conn, actor.id)? {
// TODO: maybe the author was added in the meantime // TODO: maybe the author was added in the meantime

View File

@ -99,7 +99,7 @@ fn fetch_and_cache_followers(user: &Arc<User>, conn: &DbConn) {
match follower_ids { match follower_ids {
Ok(user_ids) => { Ok(user_ids) => {
for user_id in user_ids { for user_id in user_ids {
let follower = User::from_id07(conn, &user_id, None, CONFIG.proxy()); let follower = User::from_id(conn, &user_id, None, CONFIG.proxy());
match follower { match follower {
Ok(follower) => { Ok(follower) => {
let inserted = follows::Follow::insert( let inserted = follows::Follow::insert(

View File

@ -177,7 +177,7 @@ impl FromId<DbConn> for Reshare {
let res = Reshare::insert( let res = Reshare::insert(
conn, conn,
NewReshare { NewReshare {
post_id: Post::from_id07( post_id: Post::from_id(
conn, conn,
act.object_field_ref() act.object_field_ref()
.as_single_id() .as_single_id()
@ -188,7 +188,7 @@ impl FromId<DbConn> for Reshare {
) )
.map_err(|(_, e)| e)? .map_err(|(_, e)| e)?
.id, .id,
user_id: User::from_id07( user_id: User::from_id(
conn, conn,
act.actor_field_ref() act.actor_field_ref()
.as_single_id() .as_single_id()

View File

@ -237,7 +237,7 @@ impl User {
.into_iter() .into_iter()
.find(|l| l.mime_type == Some(String::from("application/activity+json"))) .find(|l| l.mime_type == Some(String::from("application/activity+json")))
.ok_or(Error::Webfinger)?; .ok_or(Error::Webfinger)?;
User::from_id07( User::from_id(
conn, conn,
link.href.as_ref().ok_or(Error::Webfinger)?, link.href.as_ref().ok_or(Error::Webfinger)?,
None, None,

View File

@ -26,7 +26,7 @@ pub fn handle_incoming(
.or_else(|| activity["actor"]["id"].as_str()) .or_else(|| activity["actor"]["id"].as_str())
.ok_or(status::BadRequest(Some("Missing actor id for activity")))?; .ok_or(status::BadRequest(Some("Missing actor id for activity")))?;
let actor = User::from_id07(&conn, actor_id, None, CONFIG.proxy()) let actor = User::from_id(&conn, actor_id, None, CONFIG.proxy())
.expect("instance::shared_inbox: user error"); .expect("instance::shared_inbox: user error");
if !verify_http_headers(&actor, &headers.0, &sig).is_secure() && !act.clone().verify(&actor) { if !verify_http_headers(&actor, &headers.0, &sig).is_secure() && !act.clone().verify(&actor) {
// maybe we just know an old key? // maybe we just know an old key?

View File

@ -404,7 +404,7 @@ pub fn interact(conn: DbConn, user: Option<User>, target: String) -> Option<Redi
return Some(Redirect::to(uri!(super::user::details: name = target))); return Some(Redirect::to(uri!(super::user::details: name = target)));
} }
if let Ok(post) = Post::from_id07(&conn, &target, None, CONFIG.proxy()) { if let Ok(post) = Post::from_id(&conn, &target, None, CONFIG.proxy()) {
return Some(Redirect::to(uri!( return Some(Redirect::to(uri!(
super::posts::details: blog = post.get_blog(&conn).expect("Can't retrieve blog").fqn, super::posts::details: blog = post.get_blog(&conn).expect("Can't retrieve blog").fqn,
slug = &post.slug, slug = &post.slug,
@ -412,7 +412,7 @@ pub fn interact(conn: DbConn, user: Option<User>, target: String) -> Option<Redi
))); )));
} }
if let Ok(comment) = Comment::from_id07(&conn, &target, None, CONFIG.proxy()) { if let Ok(comment) = Comment::from_id(&conn, &target, None, CONFIG.proxy()) {
if comment.can_see(&conn, user.as_ref()) { if comment.can_see(&conn, user.as_ref()) {
let post = comment.get_post(&conn).expect("Can't retrieve post"); let post = comment.get_post(&conn).expect("Can't retrieve post");
return Some(Redirect::to(uri!( return Some(Redirect::to(uri!(