From a958300a58fdbdd19365ae1e1ba05dda4389d83b Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Mon, 2 May 2022 22:28:36 +0900 Subject: [PATCH] Use Post::update_hashtags07() instead of update_hashtags() --- plume-models/src/posts.rs | 38 +------------------------------------- src/routes/posts.rs | 4 ++-- 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index f7d057ec..a4390dcb 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -27,7 +27,7 @@ use plume_common::{ activity_pub::{ inbox::{AsActor, AsObject, FromId}, sign::Signer, - Hashtag, Hashtag07, HashtagType07, Id, IntoId, Licensed, Licensed07, + Hashtag07, HashtagType07, Id, IntoId, Licensed, Licensed07, LicensedArticle as LicensedArticle07, Source, SourceProperty, ToAsString, ToAsUri, PUBLIC_VISIBILITY, }, @@ -605,42 +605,6 @@ impl Post { Ok(()) } - pub fn update_hashtags(&self, conn: &Connection, tags: Vec) -> Result<()> { - let tags_name = tags - .iter() - .filter_map(|t| t.name_string().ok()) - .collect::>(); - - let old_tags = Tag::for_post(&*conn, self.id)?; - let old_tags_name = old_tags - .iter() - .filter_map(|tag| { - if tag.is_hashtag { - Some(tag.tag.clone()) - } else { - None - } - }) - .collect::>(); - - for t in tags { - if !t - .name_string() - .map(|n| old_tags_name.contains(&n)) - .unwrap_or(true) - { - Tag::from_activity(conn, &t, self.id, true)?; - } - } - - for ot in old_tags.into_iter().filter(|t| t.is_hashtag) { - if !tags_name.contains(&ot.tag) { - ot.delete(conn)?; - } - } - Ok(()) - } - pub fn update_hashtags07(&self, conn: &Connection, tags: Vec) -> Result<()> { let tags_name = tags .iter() diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 1f65cbb6..6c973d4a 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -334,9 +334,9 @@ pub fn update( .into_iter() .collect::>() .into_iter() - .filter_map(|t| Tag::build_activity(t).ok()) + .filter_map(|t| Tag::build_activity07(t).ok()) .collect::>(); - post.update_hashtags(&conn, hashtags) + post.update_hashtags07(&conn, hashtags) .expect("post::update: hashtags error"); if post.published {