diff --git a/plume-common/src/activity_pub/inbox.rs b/plume-common/src/activity_pub/inbox.rs index e1a04eeb..f8ce6a7d 100644 --- a/plume-common/src/activity_pub/inbox.rs +++ b/plume-common/src/activity_pub/inbox.rs @@ -352,8 +352,8 @@ pub trait FromId: Sized { match Self::from_db07(ctx, id) { Ok(x) => Ok(x), _ => match object { - Some(o) => Self::from_activity07(ctx, o).map_err(|e| (None, e)), - None => Self::from_activity07(ctx, Self::deref(id, proxy.cloned())?) + Some(o) => Self::from_activity(ctx, o).map_err(|e| (None, e)), + None => Self::from_activity(ctx, Self::deref(id, proxy.cloned())?) .map_err(|e| (None, e)), }, } @@ -377,7 +377,7 @@ pub trait FromId: Sized { } /// Builds a `Self` from its ActivityPub representation - fn from_activity07(ctx: &C, activity: Self::Object) -> Result; + fn from_activity(ctx: &C, activity: Self::Object) -> Result; /// Tries to find a `Self` with a given ID (`id`), using `ctx` (a database) fn from_db07(ctx: &C, id: &str) -> Result; @@ -610,7 +610,7 @@ mod tests { Ok(Self) } - fn from_activity07(_: &(), _obj: Person07) -> Result { + fn from_activity(_: &(), _obj: Person07) -> Result { Ok(Self) } @@ -638,7 +638,7 @@ mod tests { Ok(Self) } - fn from_activity07(_: &(), _obj: Note07) -> Result { + fn from_activity(_: &(), _obj: Note07) -> Result { Ok(Self) } @@ -789,7 +789,7 @@ mod tests { Err(()) } - fn from_activity07(_: &(), _obj: Self::Object) -> Result { + fn from_activity(_: &(), _obj: Self::Object) -> Result { Err(()) } diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 94fafba2..0ffc38a9 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -369,7 +369,7 @@ impl FromId for Blog { Self::find_by_ap_url(conn, id) } - fn from_activity07(conn: &DbConn, acct: CustomGroup) -> Result { + fn from_activity(conn: &DbConn, acct: CustomGroup) -> Result { let (name, outbox_url, inbox_url) = { let actor = acct.ap_actor_ref(); let name = actor @@ -956,7 +956,7 @@ pub(crate) mod tests { let _: Blog = blogs[0].save_changes(&**conn).unwrap(); let ap_repr = blogs[0].to_activity07(&conn).unwrap(); blogs[0].delete(&conn).unwrap(); - let blog = Blog::from_activity07(&conn, ap_repr).unwrap(); + let blog = Blog::from_activity(&conn, ap_repr).unwrap(); assert_eq!(blog.actor_id, blogs[0].actor_id); assert_eq!(blog.title, blogs[0].title); diff --git a/plume-models/src/comments.rs b/plume-models/src/comments.rs index 0b546d65..18f63d6b 100644 --- a/plume-models/src/comments.rs +++ b/plume-models/src/comments.rs @@ -225,7 +225,7 @@ impl FromId for Comment { Self::find_by_ap_url(conn, id) } - fn from_activity07(conn: &DbConn, note: Note) -> Result { + fn from_activity(conn: &DbConn, note: Note) -> Result { let comm = { let previous_url = note .in_reply_to() @@ -299,7 +299,7 @@ impl FromId for Comment { } let m = m.unwrap(); let not_author = m.href().ok_or(Error::MissingApProperty)? != author_url; - let _ = Mention::from_activity07(conn, &m, comm.id, false, not_author); + let _ = Mention::from_activity(conn, &m, comm.id, false, not_author); } } comm diff --git a/plume-models/src/follows.rs b/plume-models/src/follows.rs index 7cca5f08..b3d5a07c 100644 --- a/plume-models/src/follows.rs +++ b/plume-models/src/follows.rs @@ -176,7 +176,7 @@ impl FromId for Follow { Follow::find_by_ap_url(conn, id) } - fn from_activity07(conn: &DbConn, follow: FollowAct) -> Result { + fn from_activity(conn: &DbConn, follow: FollowAct) -> Result { let actor = User::from_id( conn, follow diff --git a/plume-models/src/likes.rs b/plume-models/src/likes.rs index e7787e57..8fac8bc3 100644 --- a/plume-models/src/likes.rs +++ b/plume-models/src/likes.rs @@ -113,7 +113,7 @@ impl FromId for Like { Like::find_by_ap_url(conn, id) } - fn from_activity07(conn: &DbConn, act: LikeAct) -> Result { + fn from_activity(conn: &DbConn, act: LikeAct) -> Result { let res = Like::insert( conn, NewLike { diff --git a/plume-models/src/medias.rs b/plume-models/src/medias.rs index 52c06efb..da59044b 100644 --- a/plume-models/src/medias.rs +++ b/plume-models/src/medias.rs @@ -206,7 +206,7 @@ impl Media { } // TODO: merge with save_remote? - pub fn from_activity07(conn: &DbConn, image: &Image) -> Result { + pub fn from_activity(conn: &DbConn, image: &Image) -> Result { let remote_url = image .url() .and_then(|url| url.to_as_uri()) diff --git a/plume-models/src/mentions.rs b/plume-models/src/mentions.rs index 0e9a8ba0..56697dde 100644 --- a/plume-models/src/mentions.rs +++ b/plume-models/src/mentions.rs @@ -76,7 +76,7 @@ impl Mention { Ok(mention) } - pub fn from_activity07( + pub fn from_activity( conn: &Connection, ment: &link::Mention, inside: i32, diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 46c48007..8217e6b8 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -466,7 +466,7 @@ impl Post { .collect::>(); for (m, id) in &mentions { if !old_user_mentioned.contains(id) { - Mention::from_activity07(&*conn, m, self.id, true, true)?; + Mention::from_activity(&*conn, m, self.id, true, true)?; } } @@ -508,7 +508,7 @@ impl Post { .map(|n| old_tags_name.contains(n.as_str())) .unwrap_or(true) { - Tag::from_activity07(conn, &t, self.id, false)?; + Tag::from_activity(conn, &t, self.id, false)?; } } @@ -545,7 +545,7 @@ impl Post { .map(|n| old_tags_name.contains(n.as_str())) .unwrap_or(true) { - Tag::from_activity07(conn, &t, self.id, true)?; + Tag::from_activity(conn, &t, self.id, true)?; } } @@ -624,7 +624,7 @@ impl FromId for Post { Self::find_by_ap_url(conn, id) } - fn from_activity07(conn: &DbConn, article: LicensedArticle) -> Result { + fn from_activity(conn: &DbConn, article: LicensedArticle) -> Result { let license = article.ext_one.license.unwrap_or_default(); let source = article.ext_two.source.content; let article = article.inner; @@ -657,7 +657,7 @@ impl FromId for Post { let cover = article.icon().and_then(|icon| { icon.iter().next().and_then(|img| { let image = img.to_owned().extend::().ok()??; - Media::from_activity07(conn, &image).ok().map(|m| m.id) + Media::from_activity(conn, &image).ok().map(|m| m.id) }) }); @@ -781,7 +781,7 @@ impl FromId for Post { tag.clone() .extend::() // FIXME: Don't clone .map(|mention| { - mention.map(|m| Mention::from_activity07(conn, &m, post.id, true, true)) + mention.map(|m| Mention::from_activity(conn, &m, post.id, true, true)) }) .ok(); @@ -790,7 +790,7 @@ impl FromId for Post { .map(|hashtag| { hashtag.and_then(|t| { let tag_name = t.name.clone()?.as_str().to_string(); - Tag::from_activity07(conn, &t, post.id, hashtags.remove(&tag_name)).ok() + Tag::from_activity(conn, &t, post.id, hashtags.remove(&tag_name)).ok() }) }) .ok(); @@ -854,7 +854,7 @@ impl FromId for PostUpdate { Err(Error::NotFound) } - fn from_activity07(conn: &DbConn, updated: Self::Object) -> Result { + fn from_activity(conn: &DbConn, updated: Self::Object) -> Result { let mut post_update = PostUpdate { ap_url: updated .ap_object_ref() @@ -886,7 +886,7 @@ impl FromId for PostUpdate { .and_then(|img| { img.clone() .extend::() - .map(|img| img.and_then(|img| Media::from_activity07(conn, &img).ok())) + .map(|img| img.and_then(|img| Media::from_activity(conn, &img).ok())) .ok() }) .and_then(|m| m.map(|m| m.id)) diff --git a/plume-models/src/remote_fetch_actor.rs b/plume-models/src/remote_fetch_actor.rs index 2d794650..228671e3 100644 --- a/plume-models/src/remote_fetch_actor.rs +++ b/plume-models/src/remote_fetch_actor.rs @@ -80,7 +80,7 @@ fn fetch_and_cache_articles(user: &Arc, conn: &DbConn) { any_base.extend::().ok() }) { Some(Some(article)) => { - Post::from_activity07(conn, article) + Post::from_activity(conn, article) .expect("Article from remote user couldn't be saved"); info!("Fetched article from remote user"); } diff --git a/plume-models/src/reshares.rs b/plume-models/src/reshares.rs index 3c55658e..72628a0e 100644 --- a/plume-models/src/reshares.rs +++ b/plume-models/src/reshares.rs @@ -142,7 +142,7 @@ impl FromId for Reshare { Reshare::find_by_ap_url(conn, id) } - fn from_activity07(conn: &DbConn, act: Announce) -> Result { + fn from_activity(conn: &DbConn, act: Announce) -> Result { let res = Reshare::insert( conn, NewReshare { diff --git a/plume-models/src/tags.rs b/plume-models/src/tags.rs index eb24f0c0..2bf35edc 100644 --- a/plume-models/src/tags.rs +++ b/plume-models/src/tags.rs @@ -39,7 +39,7 @@ impl Tag { Ok(ht) } - pub fn from_activity07( + pub fn from_activity( conn: &Connection, tag: &Hashtag, post: i32, @@ -86,7 +86,7 @@ mod tests { use serde_json::to_value; #[test] - fn from_activity07() { + fn from_activity() { let conn = &db(); conn.test_transaction::<_, Error, _>(|| { let (posts, _users, _blogs) = fill_database(conn); @@ -94,7 +94,7 @@ mod tests { let mut ht = Hashtag::new(); ht.set_href(ap_url(&format!("https://plu.me/tag/a_tag")).parse::()?); ht.set_name("a_tag".to_string()); - let tag = Tag::from_activity07(conn, &ht, post_id, true)?; + let tag = Tag::from_activity(conn, &ht, post_id, true)?; assert_eq!(&tag.tag, "a_tag"); assert!(tag.is_hashtag); diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index ef32dfe1..b65b839a 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -264,7 +264,7 @@ impl User { } pub fn fetch_from_url(conn: &DbConn, url: &str) -> Result { - User::fetch(url).and_then(|json| User::from_activity07(conn, json)) + User::fetch(url).and_then(|json| User::from_activity(conn, json)) } pub fn refetch(&self, conn: &Connection) -> Result<()> { @@ -952,7 +952,7 @@ impl FromId for User { Self::find_by_ap_url(conn, id) } - fn from_activity07(conn: &DbConn, acct: CustomPerson) -> Result { + fn from_activity(conn: &DbConn, acct: CustomPerson) -> Result { let actor = acct.ap_actor_ref(); let username = actor .preferred_username() @@ -1428,7 +1428,7 @@ pub(crate) mod tests { let ap_repr = users[0].to_activity07(&conn).unwrap(); users[0].delete(&conn).unwrap(); - let user = User::from_activity07(&conn, ap_repr).unwrap(); + let user = User::from_activity(&conn, ap_repr).unwrap(); assert_eq!(user.username, users[0].username); assert_eq!(user.display_name, users[0].display_name); diff --git a/src/api/posts.rs b/src/api/posts.rs index 2de03517..d08d8d6a 100644 --- a/src/api/posts.rs +++ b/src/api/posts.rs @@ -191,7 +191,7 @@ pub fn create( if post.published { for m in mentions.into_iter() { - Mention::from_activity07( + Mention::from_activity( &conn, &Mention::build_activity07(&conn, &m)?, post.id, diff --git a/src/routes/comments.rs b/src/routes/comments.rs index 687665e6..5fd2cbcc 100644 --- a/src/routes/comments.rs +++ b/src/routes/comments.rs @@ -71,7 +71,7 @@ pub fn create( // save mentions for ment in mentions { - Mention::from_activity07( + Mention::from_activity( &conn, &Mention::build_activity07(&conn, &ment) .expect("comments::create: build mention error"), diff --git a/src/routes/posts.rs b/src/routes/posts.rs index a27d6f1d..39209824 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -530,7 +530,7 @@ pub fn create( if post.published { for m in mentions { - Mention::from_activity07( + Mention::from_activity( &conn, &Mention::build_activity07(&conn, &m) .expect("post::create: mention build error"),