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