mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-26 21:41:04 +00:00
Use Post::update_hashtags07() instead of update_hashtags()
This commit is contained in:
parent
a8be31b177
commit
a958300a58
2 changed files with 3 additions and 39 deletions
|
@ -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<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, 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<Hashtag07>) -> Result<()> {
|
||||
let tags_name = tags
|
||||
.iter()
|
||||
|
|
|
@ -334,9 +334,9 @@ pub fn update(
|
|||
.into_iter()
|
||||
.collect::<HashSet<_>>()
|
||||
.into_iter()
|
||||
.filter_map(|t| Tag::build_activity(t).ok())
|
||||
.filter_map(|t| Tag::build_activity07(t).ok())
|
||||
.collect::<Vec<_>>();
|
||||
post.update_hashtags(&conn, hashtags)
|
||||
post.update_hashtags07(&conn, hashtags)
|
||||
.expect("post::update: hashtags error");
|
||||
|
||||
if post.published {
|
||||
|
|
Loading…
Reference in a new issue