Add uri attribute to Status object
This commit is contained in:
parent
ac834fa99a
commit
1d1618d6a2
3 changed files with 16 additions and 5 deletions
|
@ -41,8 +41,8 @@ pub fn get_instance_actor_url(instance_url: &str) -> String {
|
||||||
format!("{}/actor", instance_url)
|
format!("{}/actor", instance_url)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_object_url(instance_url: &str, object_uuid: &Uuid) -> String {
|
pub fn get_object_url(instance_url: &str, internal_object_id: &Uuid) -> String {
|
||||||
format!("{}/objects/{}", instance_url, object_uuid)
|
format!("{}/objects/{}", instance_url, internal_object_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_activitypub_request(request: &HttpRequest) -> bool {
|
fn is_activitypub_request(request: &HttpRequest) -> bool {
|
||||||
|
@ -180,13 +180,13 @@ pub async fn object_view(
|
||||||
config: web::Data<Config>,
|
config: web::Data<Config>,
|
||||||
db_pool: web::Data<Pool>,
|
db_pool: web::Data<Pool>,
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
web::Path(object_id): web::Path<Uuid>,
|
web::Path(internal_object_id): web::Path<Uuid>,
|
||||||
) -> Result<HttpResponse, HttpError> {
|
) -> Result<HttpResponse, HttpError> {
|
||||||
let db_client = &**get_database_client(&db_pool).await?;
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
// Try to find local post by ID, return 404 if not found
|
// Try to find local post by ID, return 404 if not found
|
||||||
let thread = get_thread(db_client, &object_id, None).await?;
|
let thread = get_thread(db_client, &internal_object_id, None).await?;
|
||||||
let post = thread.iter()
|
let post = thread.iter()
|
||||||
.find(|post| post.id == object_id && post.author.is_local())
|
.find(|post| post.id == internal_object_id && post.author.is_local())
|
||||||
.ok_or(HttpError::NotFoundError("post"))?;
|
.ok_or(HttpError::NotFoundError("post"))?;
|
||||||
if !is_activitypub_request(&request) {
|
if !is_activitypub_request(&request) {
|
||||||
let page_url = get_post_page_url(&post.id, &config.instance_url());
|
let page_url = get_post_page_url(&post.id, &config.instance_url());
|
||||||
|
|
|
@ -31,6 +31,7 @@ impl Mention {
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Status {
|
pub struct Status {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
|
pub uri: String,
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
pub account: Account,
|
pub account: Account,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
|
@ -52,6 +53,7 @@ pub struct Status {
|
||||||
|
|
||||||
impl Status {
|
impl Status {
|
||||||
pub fn from_post(post: Post, instance_url: &str) -> Self {
|
pub fn from_post(post: Post, instance_url: &str) -> Self {
|
||||||
|
let object_id = post.get_object_id(instance_url);
|
||||||
let attachments: Vec<Attachment> = post.attachments.into_iter()
|
let attachments: Vec<Attachment> = post.attachments.into_iter()
|
||||||
.map(|item| Attachment::from_db(item, instance_url))
|
.map(|item| Attachment::from_db(item, instance_url))
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -65,6 +67,7 @@ impl Status {
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
id: post.id,
|
id: post.id,
|
||||||
|
uri: object_id,
|
||||||
created_at: post.created_at,
|
created_at: post.created_at,
|
||||||
account: account,
|
account: account,
|
||||||
content: post.content,
|
content: post.content,
|
||||||
|
|
|
@ -5,6 +5,7 @@ use postgres_types::FromSql;
|
||||||
use tokio_postgres::Row;
|
use tokio_postgres::Row;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::activitypub::views::get_object_url;
|
||||||
use crate::database::int_enum::{int_enum_from_sql, int_enum_to_sql};
|
use crate::database::int_enum::{int_enum_from_sql, int_enum_to_sql};
|
||||||
use crate::errors::{ConversionError, DatabaseError, ValidationError};
|
use crate::errors::{ConversionError, DatabaseError, ValidationError};
|
||||||
use crate::models::attachments::types::DbMediaAttachment;
|
use crate::models::attachments::types::DbMediaAttachment;
|
||||||
|
@ -119,6 +120,13 @@ impl Post {
|
||||||
pub fn is_public(&self) -> bool {
|
pub fn is_public(&self) -> bool {
|
||||||
matches!(self.visibility, Visibility::Public)
|
matches!(self.visibility, Visibility::Public)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_object_id(&self, instance_url: &str) -> String {
|
||||||
|
match &self.object_id {
|
||||||
|
Some(object_id) => object_id.to_string(),
|
||||||
|
None => get_object_url(instance_url, &self.id),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue