mirror of https://github.com/LemmyNet/lemmy.git
Rewrite tombstone
parent
b439cb36aa
commit
850ac6e495
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
cargo +nightly fmt -- --check
|
||||
cargo +nightly fmt
|
||||
|
||||
cargo +nightly clippy --workspace --tests --all-targets --all-features -- \
|
||||
-D warnings -D deprecated -D clippy::perf -D clippy::complexity -D clippy::dbg_macro
|
||||
|
|
|
@ -2,13 +2,13 @@ use crate::{
|
|||
activities::{verify_is_public, verify_person_in_community},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{create_tombstone, person::ApubPerson, post::ApubPost, Source},
|
||||
objects::{person::ApubPerson, post::ApubPost, tombstone::Tombstone, Source},
|
||||
PostOrComment,
|
||||
};
|
||||
use activitystreams::{
|
||||
base::AnyBase,
|
||||
chrono::NaiveDateTime,
|
||||
object::{kind::NoteType, Tombstone},
|
||||
object::kind::NoteType,
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
|
@ -223,12 +223,10 @@ impl ApubObject for ApubComment {
|
|||
}
|
||||
|
||||
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
|
||||
create_tombstone(
|
||||
self.deleted,
|
||||
self.ap_id.to_owned().into(),
|
||||
self.updated,
|
||||
Ok(Tombstone::new(
|
||||
NoteType::Note,
|
||||
)
|
||||
self.updated.unwrap_or(self.published),
|
||||
))
|
||||
}
|
||||
|
||||
/// Converts a `Note` to `Comment`.
|
||||
|
|
|
@ -9,14 +9,14 @@ use crate::{
|
|||
fetcher::object_id::ObjectId,
|
||||
generate_moderators_url,
|
||||
generate_outbox_url,
|
||||
objects::{create_tombstone, get_summary_from_string_or_source, ImageObject, Source},
|
||||
objects::{get_summary_from_string_or_source, tombstone::Tombstone, ImageObject, Source},
|
||||
CommunityType,
|
||||
};
|
||||
use activitystreams::{
|
||||
actor::{kind::GroupType, Endpoints},
|
||||
base::AnyBase,
|
||||
chrono::NaiveDateTime,
|
||||
object::{kind::ImageType, Tombstone},
|
||||
object::kind::ImageType,
|
||||
primitives::OneOrMany,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
|
@ -215,12 +215,10 @@ impl ApubObject for ApubCommunity {
|
|||
}
|
||||
|
||||
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
|
||||
create_tombstone(
|
||||
self.deleted,
|
||||
self.actor_id.to_owned().into(),
|
||||
self.updated,
|
||||
Ok(Tombstone::new(
|
||||
GroupType::Group,
|
||||
)
|
||||
self.updated.unwrap_or(self.published),
|
||||
))
|
||||
}
|
||||
|
||||
/// Converts a `Group` to `Community`, inserts it into the database and updates moderators.
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
use activitystreams::{
|
||||
base::BaseExt,
|
||||
object::{kind::ImageType, Tombstone, TombstoneExt},
|
||||
};
|
||||
use anyhow::anyhow;
|
||||
use chrono::NaiveDateTime;
|
||||
use activitystreams::object::kind::ImageType;
|
||||
use html2md::parse_html;
|
||||
use lemmy_apub_lib::values::MediaTypeMarkdown;
|
||||
use lemmy_utils::{utils::convert_datetime, LemmyError};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use url::Url;
|
||||
|
||||
|
@ -15,6 +9,7 @@ pub mod community;
|
|||
pub mod person;
|
||||
pub mod post;
|
||||
pub mod private_message;
|
||||
pub mod tombstone;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
@ -31,31 +26,6 @@ pub struct ImageObject {
|
|||
url: Url,
|
||||
}
|
||||
|
||||
/// Updated is actually the deletion time
|
||||
fn create_tombstone<T>(
|
||||
deleted: bool,
|
||||
object_id: Url,
|
||||
updated: Option<NaiveDateTime>,
|
||||
former_type: T,
|
||||
) -> Result<Tombstone, LemmyError>
|
||||
where
|
||||
T: ToString,
|
||||
{
|
||||
if deleted {
|
||||
if let Some(updated) = updated {
|
||||
let mut tombstone = Tombstone::new();
|
||||
tombstone.set_id(object_id);
|
||||
tombstone.set_former_type(former_type.to_string());
|
||||
tombstone.set_deleted(convert_datetime(updated));
|
||||
Ok(tombstone)
|
||||
} else {
|
||||
Err(anyhow!("Cant convert to tombstone because updated time was None.").into())
|
||||
}
|
||||
} else {
|
||||
Err(anyhow!("Cant convert object to tombstone if it wasnt deleted").into())
|
||||
}
|
||||
}
|
||||
|
||||
fn get_summary_from_string_or_source(
|
||||
raw: &Option<String>,
|
||||
source: &Option<Source>,
|
||||
|
@ -69,7 +39,6 @@ fn get_summary_from_string_or_source(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use actix::Actor;
|
||||
use diesel::{
|
||||
r2d2::{ConnectionManager, Pool},
|
||||
|
@ -85,6 +54,7 @@ mod tests {
|
|||
rate_limit::{rate_limiter::RateLimiter, RateLimit},
|
||||
request::build_user_agent,
|
||||
settings::structs::Settings,
|
||||
LemmyError,
|
||||
};
|
||||
use lemmy_websocket::{chat_server::ChatServer, LemmyContext};
|
||||
use reqwest::Client;
|
||||
|
|
|
@ -2,14 +2,11 @@ use crate::{
|
|||
activities::{extract_community, verify_is_public, verify_person_in_community},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{create_tombstone, person::ApubPerson, ImageObject, Source},
|
||||
objects::{person::ApubPerson, tombstone::Tombstone, ImageObject, Source},
|
||||
};
|
||||
use activitystreams::{
|
||||
base::AnyBase,
|
||||
object::{
|
||||
kind::{ImageType, PageType},
|
||||
Tombstone,
|
||||
},
|
||||
object::kind::{ImageType, PageType},
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
|
@ -202,12 +199,10 @@ impl ApubObject for ApubPost {
|
|||
}
|
||||
|
||||
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
|
||||
create_tombstone(
|
||||
self.deleted,
|
||||
self.ap_id.to_owned().into(),
|
||||
self.updated,
|
||||
Ok(Tombstone::new(
|
||||
PageType::Page,
|
||||
)
|
||||
self.updated.unwrap_or(self.published),
|
||||
))
|
||||
}
|
||||
|
||||
async fn from_apub(
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use crate::{
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{create_tombstone, person::ApubPerson, Source},
|
||||
objects::{person::ApubPerson, Source},
|
||||
};
|
||||
use activitystreams::{
|
||||
base::AnyBase,
|
||||
chrono::NaiveDateTime,
|
||||
object::{kind::NoteType, Tombstone},
|
||||
object::Tombstone,
|
||||
primitives::OneOrMany,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
|
@ -156,12 +156,7 @@ impl ApubObject for ApubPrivateMessage {
|
|||
}
|
||||
|
||||
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
|
||||
create_tombstone(
|
||||
self.deleted,
|
||||
self.ap_id.to_owned().into(),
|
||||
self.updated,
|
||||
NoteType::Note,
|
||||
)
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn from_apub(
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
use crate::context::lemmy_context;
|
||||
use activitystreams::{
|
||||
base::AnyBase,
|
||||
chrono::{DateTime, FixedOffset, NaiveDateTime},
|
||||
object::kind::TombstoneType,
|
||||
primitives::OneOrMany,
|
||||
};
|
||||
use lemmy_utils::utils::convert_datetime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::skip_serializing_none;
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Tombstone {
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(rename = "type")]
|
||||
kind: TombstoneType,
|
||||
former_type: String,
|
||||
deleted: DateTime<FixedOffset>,
|
||||
}
|
||||
|
||||
impl Tombstone {
|
||||
pub fn new<T: ToString>(former_type: T, updated_time: NaiveDateTime) -> Tombstone {
|
||||
Tombstone {
|
||||
context: lemmy_context(),
|
||||
kind: TombstoneType::Tombstone,
|
||||
former_type: former_type.to_string(),
|
||||
deleted: convert_datetime(updated_time),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue