From a8be31b177d713fd00d4efb0c5788701e8919de5 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Mon, 2 May 2022 22:26:59 +0900 Subject: [PATCH] Use Post::update_tags07() instead of update_tags() --- plume-models/src/posts.rs | 36 -------------------------------- plume-models/src/timeline/mod.rs | 5 ++++- src/routes/posts.rs | 4 ++-- 3 files changed, 6 insertions(+), 39 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 57f40df5..f7d057ec 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -568,42 +568,6 @@ impl Post { Ok(()) } - pub fn update_tags(&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, false)?; - } - } - - for ot in old_tags.iter().filter(|t| !t.is_hashtag) { - if !tags_name.contains(&ot.tag) { - ot.delete(conn)?; - } - } - Ok(()) - } - pub fn update_tags07(&self, conn: &Connection, tags: Vec) -> Result<()> { let tags_name = tags .iter() diff --git a/plume-models/src/timeline/mod.rs b/plume-models/src/timeline/mod.rs index d6b2a59d..db7e3602 100644 --- a/plume-models/src/timeline/mod.rs +++ b/plume-models/src/timeline/mod.rs @@ -623,7 +623,10 @@ mod tests { ) .unwrap(); gnu_post - .update_tags(&conn, vec![Tag::build_activity("free".to_owned()).unwrap()]) + .update_tags07( + &conn, + vec![Tag::build_activity07("free".to_owned()).unwrap()], + ) .unwrap(); PostAuthor::insert( &conn, diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 626b8be4..1f65cbb6 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -325,9 +325,9 @@ pub fn update( .filter(|t| !t.is_empty()) .collect::>() .into_iter() - .filter_map(|t| Tag::build_activity(t.to_string()).ok()) + .filter_map(|t| Tag::build_activity07(t.to_string()).ok()) .collect::>(); - post.update_tags(&conn, tags) + post.update_tags07(&conn, tags) .expect("post::update: tags error"); let hashtags = hashtags