Also accept document attachments from mobilizon

This commit is contained in:
Felix Ableitner 2022-11-10 12:54:20 +01:00 committed by Dessalines
parent 6b4f27fb46
commit 07c27298c2
2 changed files with 29 additions and 9 deletions

View file

@ -167,12 +167,9 @@ impl ApubObject for ApubPost {
let community = page.extract_community(context, request_counter).await?;
let form = if !page.is_mod_action(context).await? {
let url = if let Some(Attachment::Link(link)) = page.attachment.first() {
// url as sent by Lemmy (new)
Some(link.href.clone())
} else if let Some(Attachment::Image(image)) = page.attachment.first() {
// image sent by lotide
Some(image.url.clone())
let first_attachment = page.attachment.into_iter().map(|a| a.url()).next();
let url = if first_attachment.is_some() {
first_attachment
} else if page.kind == PageType::Video {
// we cant display videos directly, so insert a link to external video page
Some(page.id.inner().clone())

View file

@ -13,14 +13,16 @@ use activitypub_federation::{
},
traits::{ActivityHandler, ApubObject},
};
use activitystreams_kinds::{link::LinkType, object::ImageType};
use activitystreams_kinds::{
link::LinkType,
object::{DocumentType, ImageType},
};
use chrono::{DateTime, FixedOffset};
use itertools::Itertools;
use lemmy_db_schema::newtypes::DbUrl;
use lemmy_utils::error::LemmyError;
use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_with::skip_serializing_none;
use url::Url;
@ -82,12 +84,33 @@ pub(crate) struct Image {
pub(crate) url: Url,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct Document {
#[serde(rename = "type")]
pub(crate) kind: DocumentType,
pub(crate) url: Url,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub(crate) enum Attachment {
Link(Link),
Image(Image),
Other(Value),
Document(Document),
}
impl Attachment {
pub(crate) fn url(self) -> Url {
match self {
// url as sent by Lemmy (new)
Attachment::Link(l) => l.href,
// image sent by lotide
Attachment::Image(i) => i.url,
// sent by mobilizon
Attachment::Document(d) => d.url,
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]