Use Post::update_tags07() instead of update_tags()

This commit is contained in:
Kitaiti Makoto 2022-05-02 22:26:59 +09:00
parent 6cd68ab8b0
commit a8be31b177
3 changed files with 6 additions and 39 deletions

View File

@ -568,42 +568,6 @@ impl Post {
Ok(()) Ok(())
} }
pub fn update_tags(&self, conn: &Connection, tags: Vec<Hashtag>) -> Result<()> {
let tags_name = tags
.iter()
.filter_map(|t| t.name_string().ok())
.collect::<HashSet<_>>();
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::<HashSet<_>>();
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<Hashtag07>) -> Result<()> { pub fn update_tags07(&self, conn: &Connection, tags: Vec<Hashtag07>) -> Result<()> {
let tags_name = tags let tags_name = tags
.iter() .iter()

View File

@ -623,7 +623,10 @@ mod tests {
) )
.unwrap(); .unwrap();
gnu_post 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(); .unwrap();
PostAuthor::insert( PostAuthor::insert(
&conn, &conn,

View File

@ -325,9 +325,9 @@ pub fn update(
.filter(|t| !t.is_empty()) .filter(|t| !t.is_empty())
.collect::<HashSet<_>>() .collect::<HashSet<_>>()
.into_iter() .into_iter()
.filter_map(|t| Tag::build_activity(t.to_string()).ok()) .filter_map(|t| Tag::build_activity07(t.to_string()).ok())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
post.update_tags(&conn, tags) post.update_tags07(&conn, tags)
.expect("post::update: tags error"); .expect("post::update: tags error");
let hashtags = hashtags let hashtags = hashtags