diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 7a58c328..896cb65a 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -5,7 +5,6 @@ use crate::{ }; use activitypub::{ activity::{Create, Delete, Update}, - link, object::{Article, Image, Tombstone}, CustomObject, }; @@ -560,46 +559,6 @@ impl Post { Ok(act) } - pub fn update_mentions(&self, conn: &Connection, mentions: Vec) -> Result<()> { - let mentions = mentions - .into_iter() - .map(|m| { - ( - m.link_props - .href_string() - .ok() - .and_then(|ap_url| User::find_by_ap_url(conn, &ap_url).ok()) - .map(|u| u.id), - m, - ) - }) - .filter_map(|(id, m)| id.map(|id| (m, id))) - .collect::>(); - - let old_mentions = Mention::list_for_post(conn, self.id)?; - let old_user_mentioned = old_mentions - .iter() - .map(|m| m.mentioned_id) - .collect::>(); - for (m, id) in &mentions { - if !old_user_mentioned.contains(id) { - Mention::from_activity(&*conn, m, self.id, true, true)?; - } - } - - let new_mentions = mentions - .into_iter() - .map(|(_m, id)| id) - .collect::>(); - for m in old_mentions - .iter() - .filter(|m| !new_mentions.contains(&m.mentioned_id)) - { - m.delete(conn)?; - } - Ok(()) - } - pub fn update_mentions07( &self, conn: &Connection, @@ -1194,15 +1153,19 @@ impl AsObject for PostUpdate { let mut tags = vec![]; let mut hashtags = vec![]; for tag in mention_tags { - serde_json::from_value::(tag.clone()) + serde_json::from_value::(tag.clone()) .map(|m| mentions.push(m)) .ok(); - serde_json::from_value::(tag.clone()) + serde_json::from_value::(tag.clone()) .map_err(Error::from) .and_then(|t| { - let tag_name = t.name_string()?; - if txt_hashtags.remove(&tag_name) { + let tag_name = t.name.as_ref().ok_or(Error::MissingApProperty)?; + let tag_name_str = tag_name + .as_xsd_string() + .or_else(|| tag_name.as_rdf_lang_string().map(|rls| &*rls.value)) + .ok_or(Error::MissingApProperty)?; + if txt_hashtags.remove(tag_name_str) { hashtags.push(t); } else { tags.push(t); @@ -1211,9 +1174,9 @@ impl AsObject for PostUpdate { }) .ok(); } - post.update_mentions(conn, mentions)?; - post.update_tags(conn, tags)?; - post.update_hashtags(conn, hashtags)?; + post.update_mentions07(conn, mentions)?; + post.update_tags07(conn, tags)?; + post.update_hashtags07(conn, hashtags)?; } post.update(conn)?; diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 854a5621..da48016f 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -306,11 +306,11 @@ pub fn update( post.update(&conn).expect("post::update: update error"); if post.published { - post.update_mentions( + post.update_mentions07( &conn, mentions .into_iter() - .filter_map(|m| Mention::build_activity(&conn, &m).ok()) + .filter_map(|m| Mention::build_activity07(&conn, &m).ok()) .collect(), ) .expect("post::update: mentions error");