mirror of https://github.com/LemmyNet/lemmy.git
Change type of pm to ChatMessage from Pleroma, make pm.to array
parent
779e48857d
commit
ec52c2b71c
|
@ -27,6 +27,8 @@
|
||||||
"content": "test",
|
"content": "test",
|
||||||
"mediaType": "text/markdown"
|
"mediaType": "text/markdown"
|
||||||
},
|
},
|
||||||
"to": "https://queer.hacktivis.me/users/lanodan",
|
"to": [
|
||||||
"type": "Note"
|
"https://queer.hacktivis.me/users/lanodan"
|
||||||
|
],
|
||||||
|
"type": "ChatMessage"
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ use anyhow::anyhow;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use lemmy_apub_lib::values::MediaTypeMarkdown;
|
use lemmy_apub_lib::values::MediaTypeMarkdown;
|
||||||
use lemmy_utils::{utils::convert_datetime, LemmyError};
|
use lemmy_utils::{utils::convert_datetime, LemmyError};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub mod comment;
|
pub mod comment;
|
||||||
|
@ -14,14 +15,14 @@ pub mod person;
|
||||||
pub mod post;
|
pub mod post;
|
||||||
pub mod private_message;
|
pub mod private_message;
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Source {
|
pub struct Source {
|
||||||
content: String,
|
content: String,
|
||||||
media_type: MediaTypeMarkdown,
|
media_type: MediaTypeMarkdown,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct ImageObject {
|
pub struct ImageObject {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
|
|
@ -39,10 +39,10 @@ use url::Url;
|
||||||
pub struct Note {
|
pub struct Note {
|
||||||
#[serde(rename = "@context")]
|
#[serde(rename = "@context")]
|
||||||
context: OneOrMany<AnyBase>,
|
context: OneOrMany<AnyBase>,
|
||||||
r#type: NoteType,
|
r#type: ChatMessageType,
|
||||||
id: Url,
|
id: Url,
|
||||||
pub(crate) attributed_to: ObjectId<ApubPerson>,
|
pub(crate) attributed_to: ObjectId<ApubPerson>,
|
||||||
to: ObjectId<ApubPerson>,
|
to: [ObjectId<ApubPerson>; 1],
|
||||||
content: String,
|
content: String,
|
||||||
media_type: MediaTypeHtml,
|
media_type: MediaTypeHtml,
|
||||||
source: Source,
|
source: Source,
|
||||||
|
@ -52,6 +52,12 @@ pub struct Note {
|
||||||
unparsed: Unparsed,
|
unparsed: Unparsed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://docs.pleroma.social/backend/development/ap_extensions/#chatmessages
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub enum ChatMessageType {
|
||||||
|
ChatMessage,
|
||||||
|
}
|
||||||
|
|
||||||
impl Note {
|
impl Note {
|
||||||
pub(crate) fn id_unchecked(&self) -> &Url {
|
pub(crate) fn id_unchecked(&self) -> &Url {
|
||||||
&self.id
|
&self.id
|
||||||
|
@ -136,10 +142,10 @@ impl ToApub for ApubPrivateMessage {
|
||||||
|
|
||||||
let note = Note {
|
let note = Note {
|
||||||
context: lemmy_context(),
|
context: lemmy_context(),
|
||||||
r#type: NoteType::Note,
|
r#type: ChatMessageType::ChatMessage,
|
||||||
id: self.ap_id.clone().into(),
|
id: self.ap_id.clone().into(),
|
||||||
attributed_to: ObjectId::new(creator.actor_id),
|
attributed_to: ObjectId::new(creator.actor_id),
|
||||||
to: ObjectId::new(recipient.actor_id),
|
to: [ObjectId::new(recipient.actor_id)],
|
||||||
content: self.content.clone(),
|
content: self.content.clone(),
|
||||||
media_type: MediaTypeHtml::Html,
|
media_type: MediaTypeHtml::Html,
|
||||||
source: Source {
|
source: Source {
|
||||||
|
@ -179,7 +185,7 @@ impl FromApub for ApubPrivateMessage {
|
||||||
.attributed_to
|
.attributed_to
|
||||||
.dereference(context, request_counter)
|
.dereference(context, request_counter)
|
||||||
.await?;
|
.await?;
|
||||||
let recipient = note.to.dereference(context, request_counter).await?;
|
let recipient = note.to[0].dereference(context, request_counter).await?;
|
||||||
|
|
||||||
let form = PrivateMessageForm {
|
let form = PrivateMessageForm {
|
||||||
creator_id: creator.id,
|
creator_id: creator.id,
|
||||||
|
|
Loading…
Reference in New Issue