mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-23 04:53:06 +00:00
wip: add former_type to tombstone
This commit is contained in:
parent
c43f06124a
commit
770dcbdc49
5 changed files with 21 additions and 9 deletions
|
@ -39,7 +39,7 @@ impl ToApub for Comment {
|
|||
|
||||
impl ToTombstone for Comment {
|
||||
fn to_tombstone(&self) -> Result<Tombstone, Error> {
|
||||
create_tombstone(self.deleted, &self.ap_id, self.published, self.updated)
|
||||
create_tombstone(self.deleted, &self.ap_id, self.published, self.updated, NoteType.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use super::*;
|
||||
use activitystreams::actor::kind::GroupType;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CommunityQuery {
|
||||
|
@ -49,7 +50,7 @@ impl ToApub for Community {
|
|||
|
||||
impl ToTombstone for Community {
|
||||
fn to_tombstone(&self) -> Result<Tombstone, Error> {
|
||||
create_tombstone(self.deleted, &self.actor_id, self.published, self.updated)
|
||||
create_tombstone(self.deleted, &self.actor_id, self.published, self.updated, GroupType.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,9 @@ use activitystreams::{
|
|||
object::{properties::ObjectProperties, Note, Page, Tombstone},
|
||||
public, BaseBox,
|
||||
};
|
||||
use activitystreams::object::kind::{NoteType, PageType};
|
||||
use crate::api::community::CommunityResponse;
|
||||
use crate::websocket::server::SendCommunityRoomMessage;
|
||||
use actix_web::body::Body;
|
||||
use actix_web::web::Path;
|
||||
use actix_web::{web, HttpRequest, HttpResponse, Result};
|
||||
|
@ -64,6 +67,7 @@ use chrono::NaiveDateTime;
|
|||
use fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user};
|
||||
use signatures::verify;
|
||||
use signatures::{sign, PublicKey, PublicKeyExtension};
|
||||
use activitystreams::primitives::XsdString;
|
||||
|
||||
type GroupExt = Ext<Ext<Group, ApActorProperties>, PublicKeyExtension>;
|
||||
type PersonExt = Ext<Ext<Person, ApActorProperties>, PublicKeyExtension>;
|
||||
|
@ -87,6 +91,7 @@ where
|
|||
.content_type(APUB_JSON_CONTENT_TYPE)
|
||||
.json(data)
|
||||
}
|
||||
|
||||
fn create_apub_tombstone_response<T>(data: &T) -> HttpResponse<Body>
|
||||
where
|
||||
T: Serialize,
|
||||
|
@ -158,6 +163,7 @@ fn create_tombstone(
|
|||
object_id: &str,
|
||||
published: NaiveDateTime,
|
||||
updated: Option<NaiveDateTime>,
|
||||
former_type: String,
|
||||
) -> Result<Tombstone, Error> {
|
||||
if deleted {
|
||||
let mut tombstone = Tombstone::default();
|
||||
|
@ -165,12 +171,13 @@ fn create_tombstone(
|
|||
tombstone
|
||||
.object_props
|
||||
.set_id(object_id)?
|
||||
.set_published(convert_datetime(published))?;
|
||||
.set_published(convert_datetime(published));
|
||||
if let Some(updated) = updated {
|
||||
tombstone
|
||||
.object_props
|
||||
.set_updated(convert_datetime(updated))?;
|
||||
}
|
||||
tombstone.tombstone_props.set_former_type_object_box(XsdString::from_string(former_type))?;
|
||||
Ok(tombstone)
|
||||
} else {
|
||||
Err(format_err!(
|
||||
|
|
|
@ -61,7 +61,7 @@ impl ToApub for Post {
|
|||
|
||||
impl ToTombstone for Post {
|
||||
fn to_tombstone(&self) -> Result<Tombstone, Error> {
|
||||
create_tombstone(self.deleted, &self.ap_id, self.published, self.updated)
|
||||
create_tombstone(self.deleted, &self.ap_id, self.published, self.updated, PageType.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
use super::*;
|
||||
use crate::api::community::CommunityResponse;
|
||||
use crate::websocket::server::SendCommunityRoomMessage;
|
||||
|
||||
#[serde(untagged)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
@ -66,8 +64,7 @@ pub async fn shared_inbox(
|
|||
receive_dislike_comment(&d, &request, &conn, chat_server)
|
||||
}
|
||||
(SharedAcceptedObjects::Delete(d), Some("Tombstone")) => {
|
||||
// TODO: is this deleting a community, post, comment or what?
|
||||
receive_delete_community(&d, &request, &conn, chat_server)
|
||||
receive_delete(&d, &request, &conn, chat_server)
|
||||
}
|
||||
_ => Err(format_err!("Unknown incoming activity type.")),
|
||||
}
|
||||
|
@ -511,7 +508,7 @@ fn receive_dislike_comment(
|
|||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
fn receive_delete_community(
|
||||
fn receive_delete(
|
||||
delete: &Delete,
|
||||
request: &HttpRequest,
|
||||
conn: &PgConnection,
|
||||
|
@ -524,6 +521,13 @@ fn receive_delete_community(
|
|||
.unwrap()
|
||||
.to_owned()
|
||||
.to_concrete::<Tombstone>()?;
|
||||
// TODO: not sure how to handle formerType (should be a string)
|
||||
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-formertype
|
||||
let former_type: &str = tombstone.tombstone_props.get_former_type_object_box().unwrap().to_concrete::<String>();
|
||||
match former_type {
|
||||
"Group" => {},
|
||||
d => return Err(format_err!("Delete type {} not supported", d)),
|
||||
}
|
||||
let community_apub_id = tombstone.object_props.get_id().unwrap().to_string();
|
||||
|
||||
let community = Community::read_from_actor_id(conn, &community_apub_id)?;
|
||||
|
|
Loading…
Reference in a new issue