mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-26 13:31:02 +00:00
Implement Post::update_tags07()
This commit is contained in:
parent
e0390cb105
commit
c1562f3868
1 changed files with 39 additions and 2 deletions
|
@ -25,8 +25,8 @@ use plume_common::{
|
||||||
activity_pub::{
|
activity_pub::{
|
||||||
inbox::{AsActor, AsObject, FromId},
|
inbox::{AsActor, AsObject, FromId},
|
||||||
sign::Signer,
|
sign::Signer,
|
||||||
Hashtag, Id, IntoId, Licensed, Licensed07, LicensedArticle as LicensedArticle07, Source,
|
Hashtag, Hashtag07, Id, IntoId, Licensed, Licensed07, LicensedArticle as LicensedArticle07,
|
||||||
SourceProperty, PUBLIC_VISIBILITY,
|
Source, SourceProperty, PUBLIC_VISIBILITY,
|
||||||
},
|
},
|
||||||
utils::{iri_percent_encode_seg, md_to_html},
|
utils::{iri_percent_encode_seg, md_to_html},
|
||||||
};
|
};
|
||||||
|
@ -674,6 +674,43 @@ impl Post {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_tags07(&self, conn: &Connection, tags: Vec<Hashtag07>) -> Result<()> {
|
||||||
|
let tags_name = tags
|
||||||
|
.iter()
|
||||||
|
.filter_map(|t| t.name.as_ref().map(|name| name.as_str().to_string()))
|
||||||
|
.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
|
||||||
|
.as_ref()
|
||||||
|
.map(|n| old_tags_name.contains(n.as_str()))
|
||||||
|
.unwrap_or(true)
|
||||||
|
{
|
||||||
|
Tag::from_activity07(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_hashtags(&self, conn: &Connection, tags: Vec<Hashtag>) -> Result<()> {
|
pub fn update_hashtags(&self, conn: &Connection, tags: Vec<Hashtag>) -> Result<()> {
|
||||||
let tags_name = tags
|
let tags_name = tags
|
||||||
.iter()
|
.iter()
|
||||||
|
|
Loading…
Reference in a new issue