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) {
|
match Self::from_db07(ctx, id) {
|
||||||
Ok(x) => Ok(x),
|
Ok(x) => Ok(x),
|
||||||
_ => match object {
|
_ => match object {
|
||||||
Some(o) => Self::from_activity07(ctx, o).map_err(|e| (None, e)),
|
Some(o) => Self::from_activity(ctx, o).map_err(|e| (None, e)),
|
||||||
None => Self::from_activity07(ctx, Self::deref(id, proxy.cloned())?)
|
None => Self::from_activity(ctx, Self::deref(id, proxy.cloned())?)
|
||||||
.map_err(|e| (None, e)),
|
.map_err(|e| (None, e)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -377,7 +377,7 @@ pub trait FromId<C>: Sized {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a `Self` from its ActivityPub representation
|
/// 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)
|
/// 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>;
|
fn from_db07(ctx: &C, id: &str) -> Result<Self, Self::Error>;
|
||||||
@ -610,7 +610,7 @@ mod tests {
|
|||||||
Ok(Self)
|
Ok(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity07(_: &(), _obj: Person07) -> Result<Self, Self::Error> {
|
fn from_activity(_: &(), _obj: Person07) -> Result<Self, Self::Error> {
|
||||||
Ok(Self)
|
Ok(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,7 +638,7 @@ mod tests {
|
|||||||
Ok(Self)
|
Ok(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity07(_: &(), _obj: Note07) -> Result<Self, Self::Error> {
|
fn from_activity(_: &(), _obj: Note07) -> Result<Self, Self::Error> {
|
||||||
Ok(Self)
|
Ok(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -789,7 +789,7 @@ mod tests {
|
|||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity07(_: &(), _obj: Self::Object) -> Result<Self, Self::Error> {
|
fn from_activity(_: &(), _obj: Self::Object) -> Result<Self, Self::Error> {
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ impl FromId<DbConn> for Blog {
|
|||||||
Self::find_by_ap_url(conn, id)
|
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 (name, outbox_url, inbox_url) = {
|
||||||
let actor = acct.ap_actor_ref();
|
let actor = acct.ap_actor_ref();
|
||||||
let name = actor
|
let name = actor
|
||||||
@ -956,7 +956,7 @@ pub(crate) mod tests {
|
|||||||
let _: Blog = blogs[0].save_changes(&**conn).unwrap();
|
let _: Blog = blogs[0].save_changes(&**conn).unwrap();
|
||||||
let ap_repr = blogs[0].to_activity07(&conn).unwrap();
|
let ap_repr = blogs[0].to_activity07(&conn).unwrap();
|
||||||
blogs[0].delete(&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.actor_id, blogs[0].actor_id);
|
||||||
assert_eq!(blog.title, blogs[0].title);
|
assert_eq!(blog.title, blogs[0].title);
|
||||||
|
@ -225,7 +225,7 @@ impl FromId<DbConn> for Comment {
|
|||||||
Self::find_by_ap_url(conn, id)
|
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 comm = {
|
||||||
let previous_url = note
|
let previous_url = note
|
||||||
.in_reply_to()
|
.in_reply_to()
|
||||||
@ -299,7 +299,7 @@ impl FromId<DbConn> for Comment {
|
|||||||
}
|
}
|
||||||
let m = m.unwrap();
|
let m = m.unwrap();
|
||||||
let not_author = m.href().ok_or(Error::MissingApProperty)? != author_url;
|
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
|
comm
|
||||||
|
@ -176,7 +176,7 @@ impl FromId<DbConn> for Follow {
|
|||||||
Follow::find_by_ap_url(conn, id)
|
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(
|
let actor = User::from_id(
|
||||||
conn,
|
conn,
|
||||||
follow
|
follow
|
||||||
|
@ -113,7 +113,7 @@ impl FromId<DbConn> for Like {
|
|||||||
Like::find_by_ap_url(conn, id)
|
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(
|
let res = Like::insert(
|
||||||
conn,
|
conn,
|
||||||
NewLike {
|
NewLike {
|
||||||
|
@ -206,7 +206,7 @@ impl Media {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: merge with save_remote?
|
// 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
|
let remote_url = image
|
||||||
.url()
|
.url()
|
||||||
.and_then(|url| url.to_as_uri())
|
.and_then(|url| url.to_as_uri())
|
||||||
|
@ -76,7 +76,7 @@ impl Mention {
|
|||||||
Ok(mention)
|
Ok(mention)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_activity07(
|
pub fn from_activity(
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
ment: &link::Mention,
|
ment: &link::Mention,
|
||||||
inside: i32,
|
inside: i32,
|
||||||
|
@ -466,7 +466,7 @@ impl Post {
|
|||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
for (m, id) in &mentions {
|
for (m, id) in &mentions {
|
||||||
if !old_user_mentioned.contains(id) {
|
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()))
|
.map(|n| old_tags_name.contains(n.as_str()))
|
||||||
.unwrap_or(true)
|
.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()))
|
.map(|n| old_tags_name.contains(n.as_str()))
|
||||||
.unwrap_or(true)
|
.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)
|
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 license = article.ext_one.license.unwrap_or_default();
|
||||||
let source = article.ext_two.source.content;
|
let source = article.ext_two.source.content;
|
||||||
let article = article.inner;
|
let article = article.inner;
|
||||||
@ -657,7 +657,7 @@ impl FromId<DbConn> for Post {
|
|||||||
let cover = article.icon().and_then(|icon| {
|
let cover = article.icon().and_then(|icon| {
|
||||||
icon.iter().next().and_then(|img| {
|
icon.iter().next().and_then(|img| {
|
||||||
let image = img.to_owned().extend::<Image, ImageType>().ok()??;
|
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()
|
tag.clone()
|
||||||
.extend::<link::Mention, MentionType>() // FIXME: Don't clone
|
.extend::<link::Mention, MentionType>() // FIXME: Don't clone
|
||||||
.map(|mention| {
|
.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();
|
.ok();
|
||||||
|
|
||||||
@ -790,7 +790,7 @@ impl FromId<DbConn> for Post {
|
|||||||
.map(|hashtag| {
|
.map(|hashtag| {
|
||||||
hashtag.and_then(|t| {
|
hashtag.and_then(|t| {
|
||||||
let tag_name = t.name.clone()?.as_str().to_string();
|
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();
|
.ok();
|
||||||
@ -854,7 +854,7 @@ impl FromId<DbConn> for PostUpdate {
|
|||||||
Err(Error::NotFound)
|
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 {
|
let mut post_update = PostUpdate {
|
||||||
ap_url: updated
|
ap_url: updated
|
||||||
.ap_object_ref()
|
.ap_object_ref()
|
||||||
@ -886,7 +886,7 @@ impl FromId<DbConn> for PostUpdate {
|
|||||||
.and_then(|img| {
|
.and_then(|img| {
|
||||||
img.clone()
|
img.clone()
|
||||||
.extend::<Image, ImageType>()
|
.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()
|
.ok()
|
||||||
})
|
})
|
||||||
.and_then(|m| m.map(|m| m.id))
|
.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()
|
any_base.extend::<LicensedArticle, ArticleType>().ok()
|
||||||
}) {
|
}) {
|
||||||
Some(Some(article)) => {
|
Some(Some(article)) => {
|
||||||
Post::from_activity07(conn, article)
|
Post::from_activity(conn, article)
|
||||||
.expect("Article from remote user couldn't be saved");
|
.expect("Article from remote user couldn't be saved");
|
||||||
info!("Fetched article from remote user");
|
info!("Fetched article from remote user");
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ impl FromId<DbConn> for Reshare {
|
|||||||
Reshare::find_by_ap_url(conn, id)
|
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(
|
let res = Reshare::insert(
|
||||||
conn,
|
conn,
|
||||||
NewReshare {
|
NewReshare {
|
||||||
|
@ -39,7 +39,7 @@ impl Tag {
|
|||||||
Ok(ht)
|
Ok(ht)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_activity07(
|
pub fn from_activity(
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
tag: &Hashtag,
|
tag: &Hashtag,
|
||||||
post: i32,
|
post: i32,
|
||||||
@ -86,7 +86,7 @@ mod tests {
|
|||||||
use serde_json::to_value;
|
use serde_json::to_value;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_activity07() {
|
fn from_activity() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, Error, _>(|| {
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
let (posts, _users, _blogs) = fill_database(conn);
|
let (posts, _users, _blogs) = fill_database(conn);
|
||||||
@ -94,7 +94,7 @@ mod tests {
|
|||||||
let mut ht = Hashtag::new();
|
let mut ht = Hashtag::new();
|
||||||
ht.set_href(ap_url(&format!("https://plu.me/tag/a_tag")).parse::<IriString>()?);
|
ht.set_href(ap_url(&format!("https://plu.me/tag/a_tag")).parse::<IriString>()?);
|
||||||
ht.set_name("a_tag".to_string());
|
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_eq!(&tag.tag, "a_tag");
|
||||||
assert!(tag.is_hashtag);
|
assert!(tag.is_hashtag);
|
||||||
|
@ -264,7 +264,7 @@ impl User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch_from_url(conn: &DbConn, url: &str) -> Result<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<()> {
|
pub fn refetch(&self, conn: &Connection) -> Result<()> {
|
||||||
@ -952,7 +952,7 @@ impl FromId<DbConn> for User {
|
|||||||
Self::find_by_ap_url(conn, id)
|
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 actor = acct.ap_actor_ref();
|
||||||
let username = actor
|
let username = actor
|
||||||
.preferred_username()
|
.preferred_username()
|
||||||
@ -1428,7 +1428,7 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
let ap_repr = users[0].to_activity07(&conn).unwrap();
|
let ap_repr = users[0].to_activity07(&conn).unwrap();
|
||||||
users[0].delete(&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.username, users[0].username);
|
||||||
assert_eq!(user.display_name, users[0].display_name);
|
assert_eq!(user.display_name, users[0].display_name);
|
||||||
|
@ -191,7 +191,7 @@ pub fn create(
|
|||||||
|
|
||||||
if post.published {
|
if post.published {
|
||||||
for m in mentions.into_iter() {
|
for m in mentions.into_iter() {
|
||||||
Mention::from_activity07(
|
Mention::from_activity(
|
||||||
&conn,
|
&conn,
|
||||||
&Mention::build_activity07(&conn, &m)?,
|
&Mention::build_activity07(&conn, &m)?,
|
||||||
post.id,
|
post.id,
|
||||||
|
@ -71,7 +71,7 @@ pub fn create(
|
|||||||
|
|
||||||
// save mentions
|
// save mentions
|
||||||
for ment in mentions {
|
for ment in mentions {
|
||||||
Mention::from_activity07(
|
Mention::from_activity(
|
||||||
&conn,
|
&conn,
|
||||||
&Mention::build_activity07(&conn, &ment)
|
&Mention::build_activity07(&conn, &ment)
|
||||||
.expect("comments::create: build mention error"),
|
.expect("comments::create: build mention error"),
|
||||||
|
@ -530,7 +530,7 @@ pub fn create(
|
|||||||
|
|
||||||
if post.published {
|
if post.published {
|
||||||
for m in mentions {
|
for m in mentions {
|
||||||
Mention::from_activity07(
|
Mention::from_activity(
|
||||||
&conn,
|
&conn,
|
||||||
&Mention::build_activity07(&conn, &m)
|
&Mention::build_activity07(&conn, &m)
|
||||||
.expect("post::create: mention build error"),
|
.expect("post::create: mention build error"),
|
||||||
|
Loading…
Reference in New Issue
Block a user