diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index bd87714d..422f4b7d 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -747,6 +747,43 @@ impl Post { Ok(()) } + pub fn update_hashtags07(&self, conn: &Connection, tags: Vec) -> Result<()> { + let tags_name = tags + .iter() + .filter_map(|t| t.name.as_ref().map(|name| name.as_str().to_string())) + .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 + .as_ref() + .map(|n| old_tags_name.contains(n.as_str())) + .unwrap_or(true) + { + Tag::from_activity07(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 url(&self, conn: &Connection) -> Result { let blog = self.get_blog(conn)?; Ok(format!("/~/{}/{}", blog.fqn, self.slug))