Rename: from_activity07() -> from_activity()
This commit is contained in:
parent
9a640b3438
commit
06d2f68ecd
@ -352,8 +352,8 @@ pub trait FromId<C>: 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<C>: Sized {
|
||||
}
|
||||
|
||||
/// Builds a `Self` from its ActivityPub representation
|
||||
fn from_activity07(ctx: &C, activity: Self::Object) -> Result<Self, Self::Error>;
|
||||
fn from_activity(ctx: &C, activity: Self::Object) -> Result<Self, Self::Error>;
|
||||
|
||||
/// Tries to find a `Self` with a given ID (`id`), using `ctx` (a database)
|
||||
fn from_db07(ctx: &C, id: &str) -> Result<Self, Self::Error>;
|
||||
@ -610,7 +610,7 @@ mod tests {
|
||||
Ok(Self)
|
||||
}
|
||||
|
||||
fn from_activity07(_: &(), _obj: Person07) -> Result<Self, Self::Error> {
|
||||
fn from_activity(_: &(), _obj: Person07) -> Result<Self, Self::Error> {
|
||||
Ok(Self)
|
||||
}
|
||||
|
||||
@ -638,7 +638,7 @@ mod tests {
|
||||
Ok(Self)
|
||||
}
|
||||
|
||||
fn from_activity07(_: &(), _obj: Note07) -> Result<Self, Self::Error> {
|
||||
fn from_activity(_: &(), _obj: Note07) -> Result<Self, Self::Error> {
|
||||
Ok(Self)
|
||||
}
|
||||
|
||||
@ -789,7 +789,7 @@ mod tests {
|
||||
Err(())
|
||||
}
|
||||
|
||||
fn from_activity07(_: &(), _obj: Self::Object) -> Result<Self, Self::Error> {
|
||||
fn from_activity(_: &(), _obj: Self::Object) -> Result<Self, Self::Error> {
|
||||
Err(())
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,7 @@ impl FromId<DbConn> for Blog {
|
||||
Self::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity07(conn: &DbConn, acct: CustomGroup) -> Result<Self> {
|
||||
fn from_activity(conn: &DbConn, acct: CustomGroup) -> Result<Self> {
|
||||
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);
|
||||
|
@ -225,7 +225,7 @@ impl FromId<DbConn> for Comment {
|
||||
Self::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity07(conn: &DbConn, note: Note) -> Result<Self> {
|
||||
fn from_activity(conn: &DbConn, note: Note) -> Result<Self> {
|
||||
let comm = {
|
||||
let previous_url = note
|
||||
.in_reply_to()
|
||||
@ -299,7 +299,7 @@ impl FromId<DbConn> 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
|
||||
|
@ -176,7 +176,7 @@ impl FromId<DbConn> for Follow {
|
||||
Follow::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity07(conn: &DbConn, follow: FollowAct) -> Result<Self> {
|
||||
fn from_activity(conn: &DbConn, follow: FollowAct) -> Result<Self> {
|
||||
let actor = User::from_id(
|
||||
conn,
|
||||
follow
|
||||
|
@ -113,7 +113,7 @@ impl FromId<DbConn> for Like {
|
||||
Like::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity07(conn: &DbConn, act: LikeAct) -> Result<Self> {
|
||||
fn from_activity(conn: &DbConn, act: LikeAct) -> Result<Self> {
|
||||
let res = Like::insert(
|
||||
conn,
|
||||
NewLike {
|
||||
|
@ -206,7 +206,7 @@ impl Media {
|
||||
}
|
||||
|
||||
// TODO: merge with save_remote?
|
||||
pub fn from_activity07(conn: &DbConn, image: &Image) -> Result<Media> {
|
||||
pub fn from_activity(conn: &DbConn, image: &Image) -> Result<Media> {
|
||||
let remote_url = image
|
||||
.url()
|
||||
.and_then(|url| url.to_as_uri())
|
||||
|
@ -76,7 +76,7 @@ impl Mention {
|
||||
Ok(mention)
|
||||
}
|
||||
|
||||
pub fn from_activity07(
|
||||
pub fn from_activity(
|
||||
conn: &Connection,
|
||||
ment: &link::Mention,
|
||||
inside: i32,
|
||||
|
@ -466,7 +466,7 @@ impl Post {
|
||||
.collect::<HashSet<_>>();
|
||||
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<DbConn> for Post {
|
||||
Self::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity07(conn: &DbConn, article: LicensedArticle) -> Result<Self> {
|
||||
fn from_activity(conn: &DbConn, article: LicensedArticle) -> Result<Self> {
|
||||
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<DbConn> for Post {
|
||||
let cover = article.icon().and_then(|icon| {
|
||||
icon.iter().next().and_then(|img| {
|
||||
let image = img.to_owned().extend::<Image, ImageType>().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<DbConn> for Post {
|
||||
tag.clone()
|
||||
.extend::<link::Mention, MentionType>() // 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<DbConn> 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<DbConn> for PostUpdate {
|
||||
Err(Error::NotFound)
|
||||
}
|
||||
|
||||
fn from_activity07(conn: &DbConn, updated: Self::Object) -> Result<Self> {
|
||||
fn from_activity(conn: &DbConn, updated: Self::Object) -> Result<Self> {
|
||||
let mut post_update = PostUpdate {
|
||||
ap_url: updated
|
||||
.ap_object_ref()
|
||||
@ -886,7 +886,7 @@ impl FromId<DbConn> for PostUpdate {
|
||||
.and_then(|img| {
|
||||
img.clone()
|
||||
.extend::<Image, ImageType>()
|
||||
.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))
|
||||
|
@ -80,7 +80,7 @@ fn fetch_and_cache_articles(user: &Arc<User>, conn: &DbConn) {
|
||||
any_base.extend::<LicensedArticle, ArticleType>().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");
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ impl FromId<DbConn> for Reshare {
|
||||
Reshare::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity07(conn: &DbConn, act: Announce) -> Result<Self> {
|
||||
fn from_activity(conn: &DbConn, act: Announce) -> Result<Self> {
|
||||
let res = Reshare::insert(
|
||||
conn,
|
||||
NewReshare {
|
||||
|
@ -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::<IriString>()?);
|
||||
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);
|
||||
|
@ -264,7 +264,7 @@ impl User {
|
||||
}
|
||||
|
||||
pub fn fetch_from_url(conn: &DbConn, url: &str) -> Result<User> {
|
||||
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<DbConn> for User {
|
||||
Self::find_by_ap_url(conn, id)
|
||||
}
|
||||
|
||||
fn from_activity07(conn: &DbConn, acct: CustomPerson) -> Result<Self> {
|
||||
fn from_activity(conn: &DbConn, acct: CustomPerson) -> Result<Self> {
|
||||
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);
|
||||
|
@ -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,
|
||||
|
@ -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"),
|
||||
|
@ -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"),
|
||||
|
Loading…
Reference in New Issue
Block a user