Allow to set visibility of new posts
This commit is contained in:
parent
bce194ebda
commit
5bdee5585a
3 changed files with 69 additions and 7 deletions
|
@ -236,6 +236,47 @@ paths:
|
||||||
$ref: '#/components/schemas/Relationship'
|
$ref: '#/components/schemas/Relationship'
|
||||||
404:
|
404:
|
||||||
description: Profile not found
|
description: Profile not found
|
||||||
|
/api/v1/statuses:
|
||||||
|
post:
|
||||||
|
summary: Create new post.
|
||||||
|
security:
|
||||||
|
- tokenAuth: []
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
description: Text content of the post.
|
||||||
|
type: string
|
||||||
|
'media_ids[]':
|
||||||
|
description: Array of Attachment ids to be attached as media.
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
in_reply_to_id:
|
||||||
|
description: ID of the post being replied to, if post is a reply.
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
visibility:
|
||||||
|
description: Visibility of the post.
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- public
|
||||||
|
- direct
|
||||||
|
required:
|
||||||
|
- status
|
||||||
|
responses:
|
||||||
|
201:
|
||||||
|
description: Post created
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Status'
|
||||||
|
400:
|
||||||
|
description: Invalid post data
|
||||||
/api/v1/statuses/{status_id}:
|
/api/v1/statuses/{status_id}:
|
||||||
delete:
|
delete:
|
||||||
summary: Delete post
|
summary: Delete post
|
||||||
|
@ -426,8 +467,14 @@ components:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
content:
|
content:
|
||||||
description: HTML-encoded status content.
|
description: HTML-encoded post content.
|
||||||
type: string
|
type: string
|
||||||
|
visibility:
|
||||||
|
description: Visibility of this post.
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- public
|
||||||
|
- direct
|
||||||
tags:
|
tags:
|
||||||
description: Hashtags used within the status content.
|
description: Hashtags used within the status content.
|
||||||
type: array
|
type: array
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::errors::ValidationError;
|
||||||
use crate::mastodon_api::accounts::types::Account;
|
use crate::mastodon_api::accounts::types::Account;
|
||||||
use crate::mastodon_api::media::types::Attachment;
|
use crate::mastodon_api::media::types::Attachment;
|
||||||
use crate::models::posts::types::{Post, PostCreateData, Visibility};
|
use crate::models::posts::types::{Post, PostCreateData, Visibility};
|
||||||
|
@ -128,22 +131,32 @@ pub struct StatusData {
|
||||||
pub media_ids: Option<Vec<Uuid>>,
|
pub media_ids: Option<Vec<Uuid>>,
|
||||||
|
|
||||||
pub in_reply_to_id: Option<Uuid>,
|
pub in_reply_to_id: Option<Uuid>,
|
||||||
|
pub visibility: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<StatusData> for PostCreateData {
|
impl TryFrom<StatusData> for PostCreateData {
|
||||||
|
|
||||||
fn from(value: StatusData) -> Self {
|
type Error = ValidationError;
|
||||||
Self {
|
|
||||||
|
fn try_from(value: StatusData) -> Result<Self, Self::Error> {
|
||||||
|
let visibility = match value.visibility.as_deref() {
|
||||||
|
Some("public") => Visibility::Public,
|
||||||
|
Some("direct") => Visibility::Direct,
|
||||||
|
Some(_) => return Err(ValidationError("invalid visibility parameter")),
|
||||||
|
None => Visibility::Public,
|
||||||
|
};
|
||||||
|
let post_data = Self {
|
||||||
content: value.status,
|
content: value.status,
|
||||||
in_reply_to_id: value.in_reply_to_id,
|
in_reply_to_id: value.in_reply_to_id,
|
||||||
repost_of_id: None,
|
repost_of_id: None,
|
||||||
visibility: Visibility::Public,
|
visibility: visibility,
|
||||||
attachments: value.media_ids.unwrap_or(vec![]),
|
attachments: value.media_ids.unwrap_or(vec![]),
|
||||||
mentions: vec![],
|
mentions: vec![],
|
||||||
tags: vec![],
|
tags: vec![],
|
||||||
object_id: None,
|
object_id: None,
|
||||||
created_at: None,
|
created_at: None,
|
||||||
}
|
};
|
||||||
|
Ok(post_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
/// https://docs.joinmastodon.org/methods/statuses/
|
/// https://docs.joinmastodon.org/methods/statuses/
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use actix_web::{delete, get, post, web, HttpResponse, Scope};
|
use actix_web::{delete, get, post, web, HttpResponse, Scope};
|
||||||
use actix_web_httpauth::extractors::bearer::BearerAuth;
|
use actix_web_httpauth::extractors::bearer::BearerAuth;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
@ -60,7 +62,7 @@ async fn create_status(
|
||||||
let db_client = &mut **get_database_client(&db_pool).await?;
|
let db_client = &mut **get_database_client(&db_pool).await?;
|
||||||
let current_user = get_current_user(db_client, auth.token()).await?;
|
let current_user = get_current_user(db_client, auth.token()).await?;
|
||||||
let instance = config.instance();
|
let instance = config.instance();
|
||||||
let mut post_data = PostCreateData::from(data.into_inner());
|
let mut post_data = PostCreateData::try_from(data.into_inner())?;
|
||||||
post_data.clean()?;
|
post_data.clean()?;
|
||||||
// Mentions
|
// Mentions
|
||||||
let mention_map = find_mentioned_profiles(
|
let mention_map = find_mentioned_profiles(
|
||||||
|
|
Loading…
Reference in a new issue