mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-09-30 07:12:04 +00:00
Also accept document attachments from mobilizon
This commit is contained in:
parent
6b4f27fb46
commit
07c27298c2
2 changed files with 29 additions and 9 deletions
|
@ -167,12 +167,9 @@ impl ApubObject for ApubPost {
|
||||||
let community = page.extract_community(context, request_counter).await?;
|
let community = page.extract_community(context, request_counter).await?;
|
||||||
|
|
||||||
let form = if !page.is_mod_action(context).await? {
|
let form = if !page.is_mod_action(context).await? {
|
||||||
let url = if let Some(Attachment::Link(link)) = page.attachment.first() {
|
let first_attachment = page.attachment.into_iter().map(|a| a.url()).next();
|
||||||
// url as sent by Lemmy (new)
|
let url = if first_attachment.is_some() {
|
||||||
Some(link.href.clone())
|
first_attachment
|
||||||
} else if let Some(Attachment::Image(image)) = page.attachment.first() {
|
|
||||||
// image sent by lotide
|
|
||||||
Some(image.url.clone())
|
|
||||||
} else if page.kind == PageType::Video {
|
} else if page.kind == PageType::Video {
|
||||||
// we cant display videos directly, so insert a link to external video page
|
// we cant display videos directly, so insert a link to external video page
|
||||||
Some(page.id.inner().clone())
|
Some(page.id.inner().clone())
|
||||||
|
|
|
@ -13,14 +13,16 @@ use activitypub_federation::{
|
||||||
},
|
},
|
||||||
traits::{ActivityHandler, ApubObject},
|
traits::{ActivityHandler, ApubObject},
|
||||||
};
|
};
|
||||||
use activitystreams_kinds::{link::LinkType, object::ImageType};
|
use activitystreams_kinds::{
|
||||||
|
link::LinkType,
|
||||||
|
object::{DocumentType, ImageType},
|
||||||
|
};
|
||||||
use chrono::{DateTime, FixedOffset};
|
use chrono::{DateTime, FixedOffset};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use lemmy_db_schema::newtypes::DbUrl;
|
use lemmy_db_schema::newtypes::DbUrl;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -82,12 +84,33 @@ pub(crate) struct Image {
|
||||||
pub(crate) url: Url,
|
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)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub(crate) enum Attachment {
|
pub(crate) enum Attachment {
|
||||||
Link(Link),
|
Link(Link),
|
||||||
Image(Image),
|
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)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
|
Loading…
Reference in a new issue