Write tag value to log if tag type is Emoji
This commit is contained in:
parent
498be66d8b
commit
30857868a0
3 changed files with 23 additions and 6 deletions
|
@ -209,18 +209,20 @@ pub async fn handle_note(
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut mentions: Vec<Uuid> = Vec::new();
|
let mut mentions: Vec<Uuid> = Vec::new();
|
||||||
let mut tags = vec![];
|
let mut hashtags = vec![];
|
||||||
let mut links = vec![];
|
let mut links = vec![];
|
||||||
if let Some(value) = object.tag {
|
if let Some(value) = object.tag {
|
||||||
let list: Vec<Tag> = parse_property_value(&value)
|
let list: Vec<JsonValue> = parse_property_value(&value)
|
||||||
.map_err(|_| ValidationError("invalid tag property"))?;
|
.map_err(|_| ValidationError("invalid tag property"))?;
|
||||||
for tag in list {
|
for tag_value in list {
|
||||||
|
let tag: Tag = serde_json::from_value(tag_value.clone())
|
||||||
|
.map_err(|_| ValidationError("invalid tag"))?;
|
||||||
if tag.tag_type == HASHTAG {
|
if tag.tag_type == HASHTAG {
|
||||||
if let Some(tag_name) = tag.name {
|
if let Some(tag_name) = tag.name {
|
||||||
// Ignore invalid tags
|
// Ignore invalid tags
|
||||||
if let Ok(tag_name) = normalize_hashtag(&tag_name) {
|
if let Ok(tag_name) = normalize_hashtag(&tag_name) {
|
||||||
if !tags.contains(&tag_name) {
|
if !hashtags.contains(&tag_name) {
|
||||||
tags.push(tag_name);
|
hashtags.push(tag_name);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -320,6 +322,13 @@ pub async fn handle_note(
|
||||||
links.push(linked.id);
|
links.push(linked.id);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
} else if tag.tag_type == EMOJI {
|
||||||
|
log::info!("found emoji tag: {}", tag_value);
|
||||||
|
} else {
|
||||||
|
log::warn!(
|
||||||
|
"skipping tag of type {}",
|
||||||
|
tag.tag_type,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -380,7 +389,7 @@ pub async fn handle_note(
|
||||||
visibility,
|
visibility,
|
||||||
attachments: attachments,
|
attachments: attachments,
|
||||||
mentions: mentions,
|
mentions: mentions,
|
||||||
tags: tags,
|
tags: hashtags,
|
||||||
links: links,
|
links: links,
|
||||||
object_id: Some(object.id),
|
object_id: Some(object.id),
|
||||||
created_at,
|
created_at,
|
||||||
|
|
|
@ -367,6 +367,13 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_property_value_tag_list() {
|
||||||
|
let value = json!({"type": "Mention"});
|
||||||
|
let value_list: Vec<Value> = parse_property_value(&value).unwrap();
|
||||||
|
assert_eq!(value_list, vec![value]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_find_object_id_from_string() {
|
fn test_find_object_id_from_string() {
|
||||||
let value = json!("test_id");
|
let value = json!("test_id");
|
||||||
|
|
|
@ -37,6 +37,7 @@ pub const ORDERED_COLLECTION: &str = "OrderedCollection";
|
||||||
pub const ORDERED_COLLECTION_PAGE: &str = "OrderedCollectionPage";
|
pub const ORDERED_COLLECTION_PAGE: &str = "OrderedCollectionPage";
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
|
pub const EMOJI: &str = "Emoji";
|
||||||
pub const HASHTAG: &str = "Hashtag";
|
pub const HASHTAG: &str = "Hashtag";
|
||||||
pub const IDENTITY_PROOF: &str = "IdentityProof";
|
pub const IDENTITY_PROOF: &str = "IdentityProof";
|
||||||
pub const LINK: &str = "Link";
|
pub const LINK: &str = "Link";
|
||||||
|
|
Loading…
Reference in a new issue