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::{
|
activity_pub::{
|
||||||
inbox::{AsActor, AsObject, FromId},
|
inbox::{AsActor, AsObject, FromId},
|
||||||
sign::Signer,
|
sign::Signer,
|
||||||
Hashtag, Hashtag07, HashtagType07, Id, IntoId, Licensed, Licensed07,
|
Hashtag07, HashtagType07, Id, IntoId, Licensed, Licensed07,
|
||||||
LicensedArticle as LicensedArticle07, Source, SourceProperty, ToAsString, ToAsUri,
|
LicensedArticle as LicensedArticle07, Source, SourceProperty, ToAsString, ToAsUri,
|
||||||
PUBLIC_VISIBILITY,
|
PUBLIC_VISIBILITY,
|
||||||
},
|
},
|
||||||
|
@ -605,42 +605,6 @@ impl Post {
|
||||||
Ok(())
|
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<()> {
|
pub fn update_hashtags07(&self, conn: &Connection, tags: Vec<Hashtag07>) -> Result<()> {
|
||||||
let tags_name = tags
|
let tags_name = tags
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -334,9 +334,9 @@ pub fn update(
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect::<HashSet<_>>()
|
.collect::<HashSet<_>>()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|t| Tag::build_activity(t).ok())
|
.filter_map(|t| Tag::build_activity07(t).ok())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
post.update_hashtags(&conn, hashtags)
|
post.update_hashtags07(&conn, hashtags)
|
||||||
.expect("post::update: hashtags error");
|
.expect("post::update: hashtags error");
|
||||||
|
|
||||||
if post.published {
|
if post.published {
|
||||||
|
|
Loading…
Reference in a new issue