From a24e3c46e6dad26bd4a237c7e4f9a4f471a9a8ef Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Tue, 3 May 2022 01:07:52 +0900 Subject: [PATCH] Remove trailing 07 in posts.rs --- plume-models/src/posts.rs | 61 +++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 647d3c02..1096bcfe 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -4,14 +4,11 @@ use crate::{ Connection, Error, PostEvent::*, Result, CONFIG, POST_CHAN, }; use activitystreams::{ - activity::{Create as Create07, Delete as Delete07, Update as Update07}, + activity::{Create, Delete, Update}, base::{AnyBase, Base}, iri_string::types::IriString, - link::{self as link07, kind::MentionType}, - object::{ - kind::ImageType, ApObject, Article as Article07, AsApObject, Image as Image07, - Tombstone as Tombstone07, - }, + link::{self, kind::MentionType}, + object::{kind::ImageType, ApObject, Article, AsApObject, Image, Tombstone}, prelude::*, time::OffsetDateTime, }; @@ -22,8 +19,8 @@ use plume_common::{ activity_pub::{ inbox::{AsActor, AsObject, FromId}, sign::Signer, - Hashtag, HashtagType, Id, IntoId, Licensed07, LicensedArticle as LicensedArticle07, Source, - SourceProperty, ToAsString, ToAsUri, PUBLIC_VISIBILITY, + Hashtag, HashtagType, Id, IntoId, Licensed07, LicensedArticle, Source, SourceProperty, + ToAsString, ToAsUri, PUBLIC_VISIBILITY, }, utils::{iri_percent_encode_seg, md_to_html}, }; @@ -344,7 +341,7 @@ impl Post { })) } - pub fn to_activity07(&self, conn: &Connection) -> Result { + pub fn to_activity07(&self, conn: &Connection) -> Result { let cc = self.get_receivers_urls(conn)?; let to = vec![PUBLIC_VISIBILITY.to_string()]; @@ -358,7 +355,7 @@ impl Post { .collect::>(); mentions_json.append(&mut tags_json); - let mut article = ApObject::new(Article07::new()); + let mut article = ApObject::new(Article::new()); article.set_name(self.title.clone()); article.set_id(self.ap_url.parse::()?); @@ -389,7 +386,7 @@ impl Post { if let Some(media_id) = self.cover_id { let media = Media::get(conn, media_id)?; - let mut cover = Image07::new(); + let mut cover = Image::new(); cover.set_url(media.url()?); if media.sensitive { cover.set_summary(media.content_warning.unwrap_or_default()); @@ -415,14 +412,14 @@ impl Post { let license = Licensed07 { license: Some(self.license.clone()), }; - Ok(LicensedArticle07::new(article, license, source)) + Ok(LicensedArticle::new(article, license, source)) } - pub fn create_activity07(&self, conn: &Connection) -> Result { + pub fn create_activity07(&self, conn: &Connection) -> Result { let article = self.to_activity07(conn)?; let to = article.to().ok_or(Error::MissingApProperty)?.clone(); let cc = article.cc().ok_or(Error::MissingApProperty)?.clone(); - let mut act = Create07::new( + let mut act = Create::new( self.get_authors(conn)?[0].ap_url.parse::()?, Base::retract(article)?.into_generic()?, ); @@ -432,11 +429,11 @@ impl Post { Ok(act) } - pub fn update_activity07(&self, conn: &Connection) -> Result { + pub fn update_activity07(&self, conn: &Connection) -> Result { let article = self.to_activity07(conn)?; let to = article.to().ok_or(Error::MissingApProperty)?.clone(); let cc = article.cc().ok_or(Error::MissingApProperty)?.clone(); - let mut act = Update07::new( + let mut act = Update::new( self.get_authors(conn)?[0].ap_url.parse::()?, Base::retract(article)?.into_generic()?, ); @@ -448,11 +445,7 @@ impl Post { Ok(act) } - pub fn update_mentions07( - &self, - conn: &Connection, - mentions: Vec, - ) -> Result<()> { + pub fn update_mentions07(&self, conn: &Connection, mentions: Vec) -> Result<()> { let mentions = mentions .into_iter() .map(|m| { @@ -575,11 +568,11 @@ impl Post { .and_then(|c| c.url().ok()) } - pub fn build_delete07(&self, conn: &Connection) -> Result { - let mut tombstone = Tombstone07::new(); + pub fn build_delete07(&self, conn: &Connection) -> Result { + let mut tombstone = Tombstone::new(); tombstone.set_id(self.ap_url.parse()?); - let mut act = Delete07::new( + let mut act = Delete::new( self.get_authors(conn)?[0] .clone() .into_id() @@ -625,13 +618,13 @@ impl Post { impl FromId for Post { type Error = Error; - type Object = LicensedArticle07; + type Object = LicensedArticle; fn from_db07(conn: &DbConn, id: &str) -> Result { Self::find_by_ap_url(conn, id) } - fn from_activity07(conn: &DbConn, article: LicensedArticle07) -> Result { + fn from_activity07(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; @@ -663,7 +656,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()??; + let image = img.to_owned().extend::().ok()??; Media::from_activity07(conn, &image).ok().map(|m| m.id) }) }); @@ -786,7 +779,7 @@ impl FromId for Post { if let Some(tags) = article.tag() { for tag in tags.iter() { tag.clone() - .extend::() // FIXME: Don't clone + .extend::() // FIXME: Don't clone .map(|mention| { mention.map(|m| Mention::from_activity07(conn, &m, post.id, true, true)) }) @@ -814,7 +807,7 @@ impl FromId for Post { } } -impl AsObject for Post { +impl AsObject for Post { type Error = Error; type Output = Self; @@ -824,7 +817,7 @@ impl AsObject for Post { } } -impl AsObject for Post { +impl AsObject for Post { type Error = Error; type Output = (); @@ -854,7 +847,7 @@ pub struct PostUpdate { impl FromId for PostUpdate { type Error = Error; - type Object = LicensedArticle07; + type Object = LicensedArticle; fn from_db07(_: &DbConn, _: &str) -> Result { // Always fail because we always want to deserialize the AP object @@ -892,7 +885,7 @@ impl FromId for PostUpdate { .next() .and_then(|img| { img.clone() - .extend::() + .extend::() .map(|img| img.and_then(|img| Media::from_activity07(conn, &img).ok())) .ok() }) @@ -909,7 +902,7 @@ impl FromId for PostUpdate { } } -impl AsObject for PostUpdate { +impl AsObject for PostUpdate { type Error = Error; type Output = (); @@ -954,7 +947,7 @@ impl AsObject for PostUpdate { let mut tags = vec![]; let mut hashtags = vec![]; for tag in mention_tags { - serde_json::from_value::(tag.clone()) + serde_json::from_value::(tag.clone()) .map(|m| mentions.push(m)) .ok();