Check mention and link counts when creating post

This commit is contained in:
silverpill 2023-04-08 00:16:40 +00:00 committed by Rafael Caricio
parent 8533a892bf
commit 533ef48393
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947
2 changed files with 9 additions and 0 deletions

View file

@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed ### Changed
- Added emoji count check to profile data validator. - Added emoji count check to profile data validator.
- Check mention and link counts when creating post.
## [1.20.0] - 2023-03-07 ## [1.20.0] - 2023-03-07

View file

@ -59,6 +59,8 @@ use crate::validators::posts::{
clean_content, clean_content,
ATTACHMENT_LIMIT, ATTACHMENT_LIMIT,
EMOJI_LIMIT, EMOJI_LIMIT,
MENTION_LIMIT,
LINK_LIMIT,
}; };
use super::helpers::{ use super::helpers::{
build_status, build_status,
@ -129,11 +131,17 @@ async fn create_status(
// Remove duplicate mentions // Remove duplicate mentions
mentions.sort(); mentions.sort();
mentions.dedup(); mentions.dedup();
if mentions.len() > MENTION_LIMIT {
return Err(ValidationError("too many mentions").into());
};
// Links validation // Links validation
if links.len() > 0 && visibility != Visibility::Public { if links.len() > 0 && visibility != Visibility::Public {
return Err(ValidationError("can't add links to non-public posts").into()); return Err(ValidationError("can't add links to non-public posts").into());
}; };
if links.len() > LINK_LIMIT {
return Err(ValidationError("too many links").into());
};
// Emoji validation // Emoji validation
let emojis: Vec<_> = emojis.iter().map(|emoji| emoji.id).collect(); let emojis: Vec<_> = emojis.iter().map(|emoji| emoji.id).collect();