Use Post::update_tags07() instead of update_tags()
This commit is contained in:
parent
6cd68ab8b0
commit
a8be31b177
@ -568,42 +568,6 @@ impl Post {
|
||||
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<()> {
|
||||
let tags_name = tags
|
||||
.iter()
|
||||
|
@ -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,
|
||||
|
@ -325,9 +325,9 @@ pub fn update(
|
||||
.filter(|t| !t.is_empty())
|
||||
.collect::<HashSet<_>>()
|
||||
.into_iter()
|
||||
.filter_map(|t| Tag::build_activity(t.to_string()).ok())
|
||||
.filter_map(|t| Tag::build_activity07(t.to_string()).ok())
|
||||
.collect::<Vec<_>>();
|
||||
post.update_tags(&conn, tags)
|
||||
post.update_tags07(&conn, tags)
|
||||
.expect("post::update: tags error");
|
||||
|
||||
let hashtags = hashtags
|
||||
|
Loading…
Reference in New Issue
Block a user