mirror of https://github.com/LemmyNet/lemmy.git
Added test case for parsing community from apub json
- fixed a bug with objectid (de)serialization - fixed a bug with outbox fetching (ref #1582)pleroma-federation2
parent
748aa342f1
commit
366532c61a
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
{
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"sc": "http://schema.org#",
|
||||||
|
"matrixUserId": {
|
||||||
|
"type": "sc:Text",
|
||||||
|
"id": "as:alsoKnownAs"
|
||||||
|
},
|
||||||
|
"stickied": "as:stickied",
|
||||||
|
"pt": "https://join-lemmy.org#",
|
||||||
|
"comments_enabled": {
|
||||||
|
"type": "sc:Boolean",
|
||||||
|
"id": "pt:commentsEnabled"
|
||||||
|
},
|
||||||
|
"moderators": "as:moderators"
|
||||||
|
},
|
||||||
|
"https://w3id.org/security/v1"
|
||||||
|
],
|
||||||
|
"type": "Group",
|
||||||
|
"id": "https://lemmy.ml/c/meta",
|
||||||
|
"preferredUsername": "meta",
|
||||||
|
"name": "lemmy.ml meta",
|
||||||
|
"content": "<p>Anything about the lemmy.ml instance and its moderation.</p>\n<p>For discussion about the Lemmy software project, go to <a href=\"https://lemmy.ml/c/lemmy\">!lemmy@lemmy.ml</a>.</p>\n",
|
||||||
|
"mediaType": "text/html",
|
||||||
|
"source": {
|
||||||
|
"content": "Anything about the lemmy.ml instance and its moderation. \n\nFor discussion about the Lemmy software project, go to [!lemmy@lemmy.ml](https://lemmy.ml/c/lemmy).",
|
||||||
|
"mediaType": "text/markdown"
|
||||||
|
},
|
||||||
|
"sensitive": false,
|
||||||
|
"moderators": "https://lemmy.ml/c/meta/moderators",
|
||||||
|
"inbox": "https://lemmy.ml/c/meta/inbox",
|
||||||
|
"outbox": "https://lemmy.ml/c/meta/outbox",
|
||||||
|
"followers": "https://lemmy.ml/c/meta/followers",
|
||||||
|
"endpoints": {
|
||||||
|
"sharedInbox": "https://lemmy.ml/inbox"
|
||||||
|
},
|
||||||
|
"publicKey": {
|
||||||
|
"id": "https://lemmy.ml/c/meta#main-key",
|
||||||
|
"owner": "https://lemmy.ml/c/meta",
|
||||||
|
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApLImCO5LEXMWb6lPCfCI\necpxU17j8CFfrDJLUWcuCmKO9KxJFmsv9uY2sYr9YX9CD4o+jnJ4D/e+/D+UeJiD\naJ3aYLEjLm+u6KuAGVREjSLzp1Js/6F2k0MIIQueiO5BBiootEY6pv3CwqqMC9L4\npWvIjmd03dMBhU1DTAblrj61oGj3c5l0OPdjeW7XnTPSrCZvaQ/1PWwVyUj0y/SC\nHiUiUiqUD88aPB8c7s85Svzs5RFT8WHcelPXJ7ydhYlU8R2tE1Octjy9Gb1R38k4\ns62LiwlRUAIzvnpMWOBi60aRpL8+IuZXoB2cCEyX5SQ+ETVp5DobHDgI0zzBEjfD\nkQIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||||
|
},
|
||||||
|
"published": "2021-06-14T22:50:50.985762+00:00",
|
||||||
|
"updated": "2021-06-14T23:29:55.801468+00:00"
|
||||||
|
}
|
|
@ -2,18 +2,18 @@
|
||||||
"@context": [
|
"@context": [
|
||||||
"https://www.w3.org/ns/activitystreams",
|
"https://www.w3.org/ns/activitystreams",
|
||||||
{
|
{
|
||||||
"moderators": "as:moderators",
|
|
||||||
"sensitive": "as:sensitive",
|
|
||||||
"pt": "https://join-lemmy.org#",
|
|
||||||
"sc": "http://schema.org#",
|
"sc": "http://schema.org#",
|
||||||
"stickied": "as:stickied",
|
"pt": "https://join-lemmy.org#",
|
||||||
"matrixUserId": {
|
|
||||||
"type": "sc:Text",
|
|
||||||
"id": "as:alsoKnownAs"
|
|
||||||
},
|
|
||||||
"comments_enabled": {
|
"comments_enabled": {
|
||||||
"type": "sc:Boolean",
|
"type": "sc:Boolean",
|
||||||
"id": "pt:commentsEnabled"
|
"id": "pt:commentsEnabled"
|
||||||
|
},
|
||||||
|
"stickied": "as:stickied",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"moderators": "as:moderators",
|
||||||
|
"matrixUserId": {
|
||||||
|
"type": "sc:Text",
|
||||||
|
"id": "as:alsoKnownAs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"https://w3id.org/security/v1"
|
"https://w3id.org/security/v1"
|
||||||
|
|
|
@ -11,6 +11,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::{
|
objects::{
|
||||||
comment::{ApubComment, Note},
|
comment::{ApubComment, Note},
|
||||||
community::ApubCommunity,
|
community::ApubCommunity,
|
||||||
|
@ -22,7 +23,6 @@ use lemmy_api_common::{blocking, check_post_deleted_or_removed};
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType, FromApub, ToApub},
|
traits::{ActivityFields, ActivityHandler, ActorType, FromApub, ToApub},
|
||||||
values::PublicUrl,
|
|
||||||
verify::verify_domains_match,
|
verify::verify_domains_match,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -38,7 +38,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct CreateOrUpdateComment {
|
pub struct CreateOrUpdateComment {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
object: Note,
|
object: Note,
|
||||||
cc: Vec<Url>,
|
cc: Vec<Url>,
|
||||||
tag: Vec<Mention>,
|
tag: Vec<Mention>,
|
||||||
|
@ -76,7 +76,7 @@ impl CreateOrUpdateComment {
|
||||||
|
|
||||||
let create_or_update = CreateOrUpdateComment {
|
let create_or_update = CreateOrUpdateComment {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: PublicUrlMigration::create(),
|
||||||
object: comment.to_apub(context.pool()).await?,
|
object: comment.to_apub(context.pool()).await?,
|
||||||
cc: maa.ccs,
|
cc: maa.ccs,
|
||||||
tag: maa.tags,
|
tag: maa.tags,
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::{
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
generate_moderators_url,
|
generate_moderators_url,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -22,7 +23,6 @@ use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType},
|
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||||
values::PublicUrl,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::community::{CommunityModerator, CommunityModeratorForm},
|
source::community::{CommunityModerator, CommunityModeratorForm},
|
||||||
|
@ -37,7 +37,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct AddMod {
|
pub struct AddMod {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
object: ObjectId<ApubPerson>,
|
object: ObjectId<ApubPerson>,
|
||||||
target: Url,
|
target: Url,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
|
@ -63,7 +63,7 @@ impl AddMod {
|
||||||
)?;
|
)?;
|
||||||
let add = AddMod {
|
let add = AddMod {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: PublicUrlMigration::create(),
|
||||||
object: ObjectId::new(added_mod.actor_id()),
|
object: ObjectId::new(added_mod.actor_id()),
|
||||||
target: generate_moderators_url(&community.actor_id)?.into(),
|
target: generate_moderators_url(&community.actor_id)?.into(),
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
|
|
|
@ -21,6 +21,7 @@ use crate::{
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
http::is_activity_already_known,
|
http::is_activity_already_known,
|
||||||
insert_activity,
|
insert_activity,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::community::ApubCommunity,
|
objects::community::ApubCommunity,
|
||||||
send_lemmy_activity,
|
send_lemmy_activity,
|
||||||
CommunityType,
|
CommunityType,
|
||||||
|
@ -34,7 +35,6 @@ use activitystreams::{
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType},
|
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||||
values::PublicUrl,
|
|
||||||
};
|
};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
@ -63,7 +63,7 @@ pub enum AnnouncableActivities {
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct AnnounceActivity {
|
pub struct AnnounceActivity {
|
||||||
actor: ObjectId<ApubCommunity>,
|
actor: ObjectId<ApubCommunity>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
object: AnnouncableActivities,
|
object: AnnouncableActivities,
|
||||||
cc: Vec<Url>,
|
cc: Vec<Url>,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -84,7 +84,7 @@ impl AnnounceActivity {
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let announce = AnnounceActivity {
|
let announce = AnnounceActivity {
|
||||||
actor: ObjectId::new(community.actor_id()),
|
actor: ObjectId::new(community.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: PublicUrlMigration::create(),
|
||||||
object,
|
object,
|
||||||
cc: vec![community.followers_url()],
|
cc: vec![community.followers_url()],
|
||||||
kind: AnnounceType::Announce,
|
kind: AnnounceType::Announce,
|
||||||
|
|
|
@ -8,6 +8,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -20,7 +21,6 @@ use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType},
|
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||||
values::PublicUrl,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::community::{
|
source::community::{
|
||||||
|
@ -40,7 +40,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct BlockUserFromCommunity {
|
pub struct BlockUserFromCommunity {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
pub(in crate::activities::community) object: ObjectId<ApubPerson>,
|
pub(in crate::activities::community) object: ObjectId<ApubPerson>,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -61,7 +61,7 @@ impl BlockUserFromCommunity {
|
||||||
) -> Result<BlockUserFromCommunity, LemmyError> {
|
) -> Result<BlockUserFromCommunity, LemmyError> {
|
||||||
Ok(BlockUserFromCommunity {
|
Ok(BlockUserFromCommunity {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: PublicUrlMigration::create(),
|
||||||
object: ObjectId::new(target.actor_id()),
|
object: ObjectId::new(target.actor_id()),
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind: BlockType::Block,
|
kind: BlockType::Block,
|
||||||
|
|
|
@ -11,6 +11,7 @@ use crate::{
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
generate_moderators_url,
|
generate_moderators_url,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -23,7 +24,6 @@ use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType},
|
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||||
values::PublicUrl,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::community::{CommunityModerator, CommunityModeratorForm},
|
source::community::{CommunityModerator, CommunityModeratorForm},
|
||||||
|
@ -38,7 +38,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct RemoveMod {
|
pub struct RemoveMod {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
pub(in crate::activities) object: ObjectId<ApubPerson>,
|
pub(in crate::activities) object: ObjectId<ApubPerson>,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -65,7 +65,7 @@ impl RemoveMod {
|
||||||
)?;
|
)?;
|
||||||
let remove = RemoveMod {
|
let remove = RemoveMod {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: PublicUrlMigration::create(),
|
||||||
object: ObjectId::new(removed_mod.actor_id()),
|
object: ObjectId::new(removed_mod.actor_id()),
|
||||||
target: Some(generate_moderators_url(&community.actor_id)?.into()),
|
target: Some(generate_moderators_url(&community.actor_id)?.into()),
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
|
|
|
@ -12,6 +12,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -24,7 +25,6 @@ use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType},
|
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||||
values::PublicUrl,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::community::{CommunityPersonBan, CommunityPersonBanForm},
|
source::community::{CommunityPersonBan, CommunityPersonBanForm},
|
||||||
|
@ -39,7 +39,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct UndoBlockUserFromCommunity {
|
pub struct UndoBlockUserFromCommunity {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
object: BlockUserFromCommunity,
|
object: BlockUserFromCommunity,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -66,7 +66,7 @@ impl UndoBlockUserFromCommunity {
|
||||||
)?;
|
)?;
|
||||||
let undo = UndoBlockUserFromCommunity {
|
let undo = UndoBlockUserFromCommunity {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: PublicUrlMigration::create(),
|
||||||
object: block,
|
object: block,
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind: UndoType::Undo,
|
kind: UndoType::Undo,
|
||||||
|
|
|
@ -8,6 +8,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::{
|
objects::{
|
||||||
community::{ApubCommunity, Group},
|
community::{ApubCommunity, Group},
|
||||||
person::ApubPerson,
|
person::ApubPerson,
|
||||||
|
@ -23,7 +24,6 @@ use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType, ToApub},
|
traits::{ActivityFields, ActivityHandler, ActorType, ToApub},
|
||||||
values::PublicUrl,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::community::{Community, CommunityForm},
|
source::community::{Community, CommunityForm},
|
||||||
|
@ -40,7 +40,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct UpdateCommunity {
|
pub struct UpdateCommunity {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
// TODO: would be nice to use a separate struct here, which only contains the fields updated here
|
// TODO: would be nice to use a separate struct here, which only contains the fields updated here
|
||||||
object: Group,
|
object: Group,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
|
@ -65,7 +65,7 @@ impl UpdateCommunity {
|
||||||
)?;
|
)?;
|
||||||
let update = UpdateCommunity {
|
let update = UpdateCommunity {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: PublicUrlMigration::create(),
|
||||||
object: community.to_apub(context.pool()).await?,
|
object: community.to_apub(context.pool()).await?,
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind: UpdateType::Update,
|
kind: UpdateType::Update,
|
||||||
|
|
|
@ -12,6 +12,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -25,7 +26,6 @@ use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType},
|
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||||
values::PublicUrl,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -66,7 +66,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Delete {
|
pub struct Delete {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
pub(in crate::activities::deletion) object: Url,
|
pub(in crate::activities::deletion) object: Url,
|
||||||
pub(in crate::activities::deletion) cc: [ObjectId<ApubCommunity>; 1],
|
pub(in crate::activities::deletion) cc: [ObjectId<ApubCommunity>; 1],
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -144,7 +144,7 @@ impl Delete {
|
||||||
) -> Result<Delete, LemmyError> {
|
) -> Result<Delete, LemmyError> {
|
||||||
Ok(Delete {
|
Ok(Delete {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: PublicUrlMigration::create(),
|
||||||
object: object_id,
|
object: object_id,
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind: DeleteType::Delete,
|
kind: DeleteType::Delete,
|
||||||
|
|
|
@ -13,6 +13,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -26,7 +27,6 @@ use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType},
|
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||||
values::PublicUrl,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
|
use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
|
@ -42,7 +42,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct UndoDelete {
|
pub struct UndoDelete {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
object: Delete,
|
object: Delete,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -117,7 +117,7 @@ impl UndoDelete {
|
||||||
)?;
|
)?;
|
||||||
let undo = UndoDelete {
|
let undo = UndoDelete {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: PublicUrlMigration::create(),
|
||||||
object,
|
object,
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind: UndoType::Undo,
|
kind: UndoType::Undo,
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::{
|
objects::{
|
||||||
community::ApubCommunity,
|
community::ApubCommunity,
|
||||||
person::ApubPerson,
|
person::ApubPerson,
|
||||||
|
@ -22,7 +23,6 @@ use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType, FromApub, ToApub},
|
traits::{ActivityFields, ActivityHandler, ActorType, FromApub, ToApub},
|
||||||
values::PublicUrl,
|
|
||||||
verify::{verify_domains_match, verify_urls_match},
|
verify::{verify_domains_match, verify_urls_match},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::community::Community, traits::Crud};
|
use lemmy_db_schema::{source::community::Community, traits::Crud};
|
||||||
|
@ -35,7 +35,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct CreateOrUpdatePost {
|
pub struct CreateOrUpdatePost {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
object: Page,
|
object: Page,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -67,7 +67,7 @@ impl CreateOrUpdatePost {
|
||||||
)?;
|
)?;
|
||||||
let create_or_update = CreateOrUpdatePost {
|
let create_or_update = CreateOrUpdatePost {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: PublicUrlMigration::create(),
|
||||||
object: post.to_apub(context.pool()).await?,
|
object: post.to_apub(context.pool()).await?,
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind,
|
kind,
|
||||||
|
|
|
@ -5,6 +5,7 @@ use crate::{
|
||||||
verify_activity,
|
verify_activity,
|
||||||
},
|
},
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
|
@ -16,7 +17,6 @@ use activitystreams::{
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler},
|
traits::{ActivityFields, ActivityHandler},
|
||||||
values::PublicUrl,
|
|
||||||
};
|
};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
@ -27,7 +27,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct UndoRemovePostCommentOrCommunity {
|
pub struct UndoRemovePostCommentOrCommunity {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
// Note, there is no such thing as Undo/Remove/Mod, so we ignore that
|
// Note, there is no such thing as Undo/Remove/Mod, so we ignore that
|
||||||
object: RemoveMod,
|
object: RemoveMod,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
|
|
|
@ -12,6 +12,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
PostOrComment,
|
PostOrComment,
|
||||||
};
|
};
|
||||||
|
@ -25,7 +26,6 @@ use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType},
|
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||||
values::PublicUrl,
|
|
||||||
verify::verify_urls_match,
|
verify::verify_urls_match,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
|
use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
|
||||||
|
@ -39,7 +39,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct UndoVote {
|
pub struct UndoVote {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
object: Vote,
|
object: Vote,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -72,7 +72,7 @@ impl UndoVote {
|
||||||
)?;
|
)?;
|
||||||
let undo_vote = UndoVote {
|
let undo_vote = UndoVote {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: PublicUrlMigration::create(),
|
||||||
object,
|
object,
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind: UndoType::Undo,
|
kind: UndoType::Undo,
|
||||||
|
|
|
@ -8,6 +8,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
|
migrations::PublicUrlMigration,
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
PostOrComment,
|
PostOrComment,
|
||||||
};
|
};
|
||||||
|
@ -17,7 +18,6 @@ use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType},
|
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||||
values::PublicUrl,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
|
use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
|
@ -58,7 +58,7 @@ impl From<&VoteType> for i16 {
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Vote {
|
pub struct Vote {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: [PublicUrl; 1],
|
to: PublicUrlMigration,
|
||||||
pub(in crate::activities::voting) object: ObjectId<PostOrComment>,
|
pub(in crate::activities::voting) object: ObjectId<PostOrComment>,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -80,7 +80,7 @@ impl Vote {
|
||||||
) -> Result<Vote, LemmyError> {
|
) -> Result<Vote, LemmyError> {
|
||||||
Ok(Vote {
|
Ok(Vote {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: PublicUrlMigration::create(),
|
||||||
object: ObjectId::new(object.ap_id()),
|
object: ObjectId::new(object.ap_id()),
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind: kind.clone(),
|
kind: kind.clone(),
|
||||||
|
|
|
@ -22,6 +22,7 @@ use url::Url;
|
||||||
static REQUEST_LIMIT: i32 = 25;
|
static REQUEST_LIMIT: i32 = 25;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Serialize, Deserialize, Debug)]
|
#[derive(Clone, PartialEq, Serialize, Deserialize, Debug)]
|
||||||
|
#[serde(transparent)]
|
||||||
pub struct ObjectId<Kind>(Url, #[serde(skip)] PhantomData<Kind>)
|
pub struct ObjectId<Kind>(Url, #[serde(skip)] PhantomData<Kind>)
|
||||||
where
|
where
|
||||||
Kind: FromApub<DataType = LemmyContext> + ApubObject<DataType = LemmyContext> + Send + 'static,
|
Kind: FromApub<DataType = LemmyContext> + ApubObject<DataType = LemmyContext> + Send + 'static,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::fetcher::{object_id::ObjectId, post_or_comment::PostOrComment};
|
use crate::fetcher::{object_id::ObjectId, post_or_comment::PostOrComment};
|
||||||
|
use lemmy_apub_lib::values::PublicUrl;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -28,3 +29,21 @@ pub enum CommentInReplyToMigration {
|
||||||
//
|
//
|
||||||
// For v0.13, delete [`UndoRemovePostCommentOrCommunity`], and don't handle object deletion in
|
// For v0.13, delete [`UndoRemovePostCommentOrCommunity`], and don't handle object deletion in
|
||||||
// [`RemoveMod`] handler.
|
// [`RemoveMod`] handler.
|
||||||
|
|
||||||
|
/// Migrate value of field `to` from single value to vec.
|
||||||
|
///
|
||||||
|
/// v0.14: send as single value, accept both
|
||||||
|
/// v0.15: send as vec, accept both
|
||||||
|
/// v0.16: send and accept only vec
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum PublicUrlMigration {
|
||||||
|
Old(PublicUrl),
|
||||||
|
New([PublicUrl; 1]),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PublicUrlMigration {
|
||||||
|
pub(crate) fn create() -> PublicUrlMigration {
|
||||||
|
PublicUrlMigration::Old(PublicUrl::Public)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -304,3 +304,26 @@ impl CommunityType for Community {
|
||||||
Ok(inboxes)
|
Ok(inboxes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::objects::tests::{file_to_json_object, init_context};
|
||||||
|
use serial_test::serial;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
#[serial]
|
||||||
|
async fn test_fetch_lemmy_community() {
|
||||||
|
let json = file_to_json_object("assets/lemmy-community.json");
|
||||||
|
let url = Url::parse("https://lemmy.ml/c/meta").unwrap();
|
||||||
|
let community = ApubCommunity::from_apub(&json, &init_context(), &url, &mut 0)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(community.actor_id.clone().into_inner(), url);
|
||||||
|
assert_eq!(community.title, "lemmy.ml meta");
|
||||||
|
assert!(community.public_key.is_some());
|
||||||
|
assert!(!community.local);
|
||||||
|
assert_eq!(community.description.as_ref().unwrap().len(), 158);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
let chat_server = ChatServer::startup(
|
let chat_server = ChatServer::startup(
|
||||||
pool.clone(),
|
pool.clone(),
|
||||||
rate_limiter.clone(),
|
rate_limiter,
|
||||||
|_, _, _, _| Box::pin(x()),
|
|_, _, _, _| Box::pin(x()),
|
||||||
|_, _, _, _| Box::pin(x()),
|
|_, _, _, _| Box::pin(x()),
|
||||||
client.clone(),
|
client.clone(),
|
||||||
|
|
|
@ -285,7 +285,7 @@ mod tests {
|
||||||
assert_eq!(person.actor_id.clone().into_inner(), url);
|
assert_eq!(person.actor_id.clone().into_inner(), url);
|
||||||
assert_eq!(person.name, "nutomic");
|
assert_eq!(person.name, "nutomic");
|
||||||
assert!(person.public_key.is_some());
|
assert!(person.public_key.is_some());
|
||||||
assert_eq!(person.local, false);
|
assert!(!person.local);
|
||||||
assert!(person.bio.is_some());
|
assert!(person.bio.is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ mod tests {
|
||||||
assert_eq!(person.actor_id.clone().into_inner(), url);
|
assert_eq!(person.actor_id.clone().into_inner(), url);
|
||||||
assert_eq!(person.name, "lanodan");
|
assert_eq!(person.name, "lanodan");
|
||||||
assert!(person.public_key.is_some());
|
assert!(person.public_key.is_some());
|
||||||
assert_eq!(person.local, false);
|
assert!(!person.local);
|
||||||
// TODO: pleroma uses summary for user profile, while we use content
|
// TODO: pleroma uses summary for user profile, while we use content
|
||||||
//assert!(person.bio.is_some());
|
//assert!(person.bio.is_some());
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ pub struct Page {
|
||||||
to: [Url; 2],
|
to: [Url; 2],
|
||||||
name: String,
|
name: String,
|
||||||
content: Option<String>,
|
content: Option<String>,
|
||||||
media_type: MediaTypeHtml,
|
media_type: Option<MediaTypeHtml>,
|
||||||
source: Option<Source>,
|
source: Option<Source>,
|
||||||
url: Option<Url>,
|
url: Option<Url>,
|
||||||
image: Option<ImageObject>,
|
image: Option<ImageObject>,
|
||||||
|
@ -189,7 +189,7 @@ impl ToApub for ApubPost {
|
||||||
to: [community.actor_id.into(), public()],
|
to: [community.actor_id.into(), public()],
|
||||||
name: self.name.clone(),
|
name: self.name.clone(),
|
||||||
content: self.body.as_ref().map(|b| markdown_to_html(b)),
|
content: self.body.as_ref().map(|b| markdown_to_html(b)),
|
||||||
media_type: MediaTypeHtml::Html,
|
media_type: Some(MediaTypeHtml::Html),
|
||||||
source,
|
source,
|
||||||
url: self.url.clone().map(|u| u.into()),
|
url: self.url.clone().map(|u| u.into()),
|
||||||
image,
|
image,
|
||||||
|
|
|
@ -3,5 +3,7 @@ set -e
|
||||||
|
|
||||||
curl -H "Accept: application/activity+json" https://lemmy.ml/u/nutomic | jq \
|
curl -H "Accept: application/activity+json" https://lemmy.ml/u/nutomic | jq \
|
||||||
> crates/apub/assets/lemmy-person.json
|
> crates/apub/assets/lemmy-person.json
|
||||||
|
curl -H "Accept: application/activity+json" https://lemmy.ml/c/meta | jq \
|
||||||
|
> crates/apub/assets/lemmy-community.json
|
||||||
curl -H "Accept: application/activity+json" https://queer.hacktivis.me/users/lanodan | jq \
|
curl -H "Accept: application/activity+json" https://queer.hacktivis.me/users/lanodan | jq \
|
||||||
> crates/apub/assets/pleroma-person.json
|
> crates/apub/assets/pleroma-person.json
|
Loading…
Reference in New Issue