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)
let actor = match A::from_id07(
let actor = match A::from_id(
ctx,
&actor_id,
serde_json::from_value(act["actor"].clone()).ok(),
@ -244,7 +244,7 @@ where
Some(x) => x,
None => return Self::NotHandled(ctx, act, InboxError::InvalidObject(None)),
};
let obj = match M::from_id07(
let obj = match M::from_id(
ctx,
&obj_id,
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
/// - `object`: optional object that will be used if the object was not found in the database
/// If absent, the ID will be dereferenced.
fn from_id07(
fn from_id(
ctx: &C,
id: &str,
object: Option<Self::Object>,

View File

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

View File

@ -349,7 +349,7 @@ impl FromId<DbConn> for Comment {
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>
})?,
author_id: User::from_id07(
author_id: User::from_id(
conn,
&note
.attributed_to()
@ -402,7 +402,7 @@ impl FromId<DbConn> for Comment {
let receivers_ap_url = receiver_ids
.into_iter()
.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]
} else {
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> {
let actor = User::from_id07(
let actor = User::from_id(
conn,
follow
.actor_field_ref()
@ -277,7 +277,7 @@ impl FromId<DbConn> for Follow {
)
.map_err(|(_, e)| e)?;
let target = User::from_id07(
let target = User::from_id(
conn,
follow
.object_field_ref()

View File

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

View File

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

View File

@ -883,14 +883,14 @@ impl FromId<DbConn> for Post {
.iter()
.fold((None, vec![]), |(blog, mut authors), link| {
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) => {
authors.push(u);
(blog, authors)
}
Err(_) => (
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,
),
@ -1155,7 +1155,7 @@ impl AsObject<User, Update07, &DbConn> for PostUpdate {
fn activity07(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> {
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)? {
// 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 {
Ok(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 {
Ok(follower) => {
let inserted = follows::Follow::insert(

View File

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

View File

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

View File

@ -26,7 +26,7 @@ pub fn handle_incoming(
.or_else(|| activity["actor"]["id"].as_str())
.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");
if !verify_http_headers(&actor, &headers.0, &sig).is_secure() && !act.clone().verify(&actor) {
// 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)));
}
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!(
super::posts::details: blog = post.get_blog(&conn).expect("Can't retrieve blog").fqn,
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()) {
let post = comment.get_post(&conn).expect("Can't retrieve post");
return Some(Redirect::to(uri!(