Change type of pm to ChatMessage from Pleroma, make pm.to array

breaking-apub-changes
Felix Ableitner 2021-10-22 12:49:15 +02:00
parent 779e48857d
commit ec52c2b71c
3 changed files with 18 additions and 9 deletions

View File

@ -27,6 +27,8 @@
"content": "test",
"mediaType": "text/markdown"
},
"to": "https://queer.hacktivis.me/users/lanodan",
"type": "Note"
"to": [
"https://queer.hacktivis.me/users/lanodan"
],
"type": "ChatMessage"
}

View File

@ -6,6 +6,7 @@ use anyhow::anyhow;
use chrono::NaiveDateTime;
use lemmy_apub_lib::values::MediaTypeMarkdown;
use lemmy_utils::{utils::convert_datetime, LemmyError};
use serde::{Deserialize, Serialize};
use url::Url;
pub mod comment;
@ -14,14 +15,14 @@ pub mod person;
pub mod post;
pub mod private_message;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Source {
content: String,
media_type: MediaTypeMarkdown,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ImageObject {
#[serde(rename = "type")]

View File

@ -39,10 +39,10 @@ use url::Url;
pub struct Note {
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
r#type: NoteType,
r#type: ChatMessageType,
id: Url,
pub(crate) attributed_to: ObjectId<ApubPerson>,
to: ObjectId<ApubPerson>,
to: [ObjectId<ApubPerson>; 1],
content: String,
media_type: MediaTypeHtml,
source: Source,
@ -52,6 +52,12 @@ pub struct Note {
unparsed: Unparsed,
}
/// https://docs.pleroma.social/backend/development/ap_extensions/#chatmessages
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum ChatMessageType {
ChatMessage,
}
impl Note {
pub(crate) fn id_unchecked(&self) -> &Url {
&self.id
@ -136,10 +142,10 @@ impl ToApub for ApubPrivateMessage {
let note = Note {
context: lemmy_context(),
r#type: NoteType::Note,
r#type: ChatMessageType::ChatMessage,
id: self.ap_id.clone().into(),
attributed_to: ObjectId::new(creator.actor_id),
to: ObjectId::new(recipient.actor_id),
to: [ObjectId::new(recipient.actor_id)],
content: self.content.clone(),
media_type: MediaTypeHtml::Html,
source: Source {
@ -179,7 +185,7 @@ impl FromApub for ApubPrivateMessage {
.attributed_to
.dereference(context, request_counter)
.await?;
let recipient = note.to.dereference(context, request_counter).await?;
let recipient = note.to[0].dereference(context, request_counter).await?;
let form = PrivateMessageForm {
creator_id: creator.id,