Allow to create posts with multiple object links
This commit is contained in:
parent
22d4695614
commit
1f713d536e
1 changed files with 37 additions and 33 deletions
|
@ -89,39 +89,43 @@ async fn create_status(
|
||||||
&post_data.tags,
|
&post_data.tags,
|
||||||
);
|
);
|
||||||
// Links
|
// Links
|
||||||
let linked = match &post_data.links[..] {
|
post_data.links.sort();
|
||||||
[] => vec![],
|
post_data.links.dedup();
|
||||||
[linked_id] => {
|
let mut linked = vec![];
|
||||||
if post_data.in_reply_to_id.is_some() {
|
for linked_id in &post_data.links {
|
||||||
return Err(ValidationError("can't add links to reply").into());
|
let post = match get_post_by_id(db_client, linked_id).await {
|
||||||
};
|
|
||||||
if post_data.visibility != Visibility::Public {
|
|
||||||
return Err(ValidationError("can't add links to non-public posts").into());
|
|
||||||
};
|
|
||||||
let linked = match get_post_by_id(db_client, linked_id).await {
|
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
Err(DatabaseError::NotFound(_)) => {
|
Err(DatabaseError::NotFound(_)) => {
|
||||||
return Err(ValidationError("referenced post does't exist").into());
|
return Err(ValidationError("referenced post does't exist").into());
|
||||||
},
|
},
|
||||||
Err(other_error) => return Err(other_error.into()),
|
Err(other_error) => return Err(other_error.into()),
|
||||||
};
|
};
|
||||||
if linked.repost_of_id.is_some() {
|
if post.repost_of_id.is_some() {
|
||||||
return Err(ValidationError("can't reference repost").into());
|
return Err(ValidationError("can't reference repost").into());
|
||||||
};
|
};
|
||||||
if linked.visibility != Visibility::Public {
|
if post.visibility != Visibility::Public {
|
||||||
return Err(ValidationError("can't reference non-public post").into());
|
return Err(ValidationError("can't reference non-public post").into());
|
||||||
};
|
};
|
||||||
// Append inline quote and add author to mentions
|
if post.author.id != current_user.id {
|
||||||
|
post_data.mentions.push(post.author.id);
|
||||||
|
};
|
||||||
|
// Append inline quote
|
||||||
post_data.content += &format!(
|
post_data.content += &format!(
|
||||||
r#"<p class="inline-quote">RE: <a href="{0}">{0}</a></p>"#,
|
r#"<p class="inline-quote">RE: <a href="{0}">{0}</a></p>"#,
|
||||||
linked.object_id(&instance.url()),
|
post.object_id(&instance.url()),
|
||||||
);
|
);
|
||||||
if linked.author.id != current_user.id {
|
linked.push(post);
|
||||||
post_data.mentions.push(linked.author.id);
|
|
||||||
};
|
};
|
||||||
vec![linked]
|
if post_data.links.len() > 0 {
|
||||||
},
|
if post_data.in_reply_to_id.is_some() {
|
||||||
_ => return Err(ValidationError("too many links").into()),
|
return Err(ValidationError("can't add links to reply").into());
|
||||||
|
};
|
||||||
|
if post_data.visibility != Visibility::Public {
|
||||||
|
return Err(ValidationError("can't add links to non-public posts").into());
|
||||||
|
};
|
||||||
|
};
|
||||||
|
if post_data.links.len() > 3 {
|
||||||
|
return Err(ValidationError("too many links").into());
|
||||||
};
|
};
|
||||||
// Reply validation
|
// Reply validation
|
||||||
let maybe_in_reply_to = if let Some(in_reply_to_id) = post_data.in_reply_to_id.as_ref() {
|
let maybe_in_reply_to = if let Some(in_reply_to_id) = post_data.in_reply_to_id.as_ref() {
|
||||||
|
|
Loading…
Reference in a new issue