Validate emoji tags

This commit is contained in:
silverpill 2023-01-14 21:51:25 +00:00
parent 143879caf9
commit 4d29c83365
2 changed files with 30 additions and 2 deletions

View file

@ -16,7 +16,7 @@ use crate::activitypub::{
},
identifiers::parse_local_actor_id,
receiver::{parse_array, parse_property_value, HandlerError},
types::{Attachment, Link, LinkTag, Object, Tag},
types::{Attachment, EmojiTag, Link, LinkTag, Object, Tag},
vocabulary::*,
};
use crate::config::{Config, Instance};
@ -336,7 +336,13 @@ pub async fn handle_note(
links.push(linked.id);
};
} else if tag_type == EMOJI {
log::info!("found emoji tag: {}", tag_value);
let _tag: EmojiTag = match serde_json::from_value(tag_value.clone()) {
Ok(tag) => tag,
Err(_) => {
log::warn!("invalid emoji tag");
continue;
},
};
} else {
log::warn!(
"skipping tag of type {}",

View file

@ -54,6 +54,28 @@ pub struct LinkTag {
pub name: Option<String>,
}
#[allow(dead_code)]
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct EmojiImage {
#[serde(rename = "type")]
object_type: String,
url: String,
media_type: Option<String>,
}
#[allow(dead_code)]
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EmojiTag {
#[serde(rename = "type")]
tag_type: String,
icon: EmojiImage,
id: String,
name: String,
updated: DateTime<Utc>,
}
#[derive(Deserialize)]
#[cfg_attr(test, derive(Default))]
#[serde(rename_all = "camelCase")]