mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-15 00:43:59 +00:00
Activity.to should always be a vec (and unspecified size for public activities)
This commit is contained in:
parent
614490d29b
commit
03b8ae7215
22 changed files with 91 additions and 74 deletions
|
@ -6,6 +6,7 @@ use crate::{
|
||||||
extract_community,
|
extract_community,
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
|
verify_is_public,
|
||||||
verify_person_in_community,
|
verify_person_in_community,
|
||||||
CreateOrUpdateType,
|
CreateOrUpdateType,
|
||||||
},
|
},
|
||||||
|
@ -17,12 +18,17 @@ use crate::{
|
||||||
person::ApubPerson,
|
person::ApubPerson,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use activitystreams::{base::AnyBase, link::Mention, primitives::OneOrMany, unparsed::Unparsed};
|
use activitystreams::{
|
||||||
|
base::AnyBase,
|
||||||
|
link::Mention,
|
||||||
|
primitives::OneOrMany,
|
||||||
|
public,
|
||||||
|
unparsed::Unparsed,
|
||||||
|
};
|
||||||
use lemmy_api_common::{blocking, check_post_deleted_or_removed};
|
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, ApubObject},
|
traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
|
||||||
values::PublicUrl,
|
|
||||||
verify::verify_domains_match,
|
verify::verify_domains_match,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -38,7 +44,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: Vec<Url>,
|
||||||
object: Note,
|
object: Note,
|
||||||
cc: Vec<Url>,
|
cc: Vec<Url>,
|
||||||
tag: Vec<Mention>,
|
tag: Vec<Mention>,
|
||||||
|
@ -76,7 +82,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: vec![public()],
|
||||||
object: comment.to_apub(context).await?,
|
object: comment.to_apub(context).await?,
|
||||||
cc: maa.ccs,
|
cc: maa.ccs,
|
||||||
tag: maa.tags,
|
tag: maa.tags,
|
||||||
|
@ -100,6 +106,7 @@ impl ActivityHandler for CreateOrUpdateComment {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
verify_is_public(&self.to)?;
|
||||||
let community = extract_community(&self.cc, context, request_counter).await?;
|
let community = extract_community(&self.cc, context, request_counter).await?;
|
||||||
let community_id = ObjectId::new(community.actor_id());
|
let community_id = ObjectId::new(community.actor_id());
|
||||||
let post = self.object.get_parents(context, request_counter).await?.0;
|
let post = self.object.get_parents(context, request_counter).await?.0;
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::{
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
verify_add_remove_moderator_target,
|
verify_add_remove_moderator_target,
|
||||||
|
verify_is_public,
|
||||||
verify_mod_action,
|
verify_mod_action,
|
||||||
verify_person_in_community,
|
verify_person_in_community,
|
||||||
},
|
},
|
||||||
|
@ -16,13 +17,13 @@ use activitystreams::{
|
||||||
activity::kind::AddType,
|
activity::kind::AddType,
|
||||||
base::AnyBase,
|
base::AnyBase,
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
|
public,
|
||||||
unparsed::Unparsed,
|
unparsed::Unparsed,
|
||||||
};
|
};
|
||||||
use lemmy_api_common::blocking;
|
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 +38,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: Vec<Url>,
|
||||||
object: ObjectId<ApubPerson>,
|
object: ObjectId<ApubPerson>,
|
||||||
target: Url,
|
target: Url,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
|
@ -63,7 +64,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: vec![public()],
|
||||||
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())],
|
||||||
|
@ -88,6 +89,7 @@ impl ActivityHandler for AddMod {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
verify_is_public(&self.to)?;
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
|
|
|
@ -14,6 +14,7 @@ use crate::{
|
||||||
post::create_or_update::CreateOrUpdatePost,
|
post::create_or_update::CreateOrUpdatePost,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
verify_community,
|
verify_community,
|
||||||
|
verify_is_public,
|
||||||
voting::{undo_vote::UndoVote, vote::Vote},
|
voting::{undo_vote::UndoVote, vote::Vote},
|
||||||
},
|
},
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
|
@ -28,12 +29,12 @@ use activitystreams::{
|
||||||
activity::kind::AnnounceType,
|
activity::kind::AnnounceType,
|
||||||
base::AnyBase,
|
base::AnyBase,
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
|
public,
|
||||||
unparsed::Unparsed,
|
unparsed::Unparsed,
|
||||||
};
|
};
|
||||||
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;
|
||||||
|
@ -61,7 +62,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: Vec<Url>,
|
||||||
object: AnnouncableActivities,
|
object: AnnouncableActivities,
|
||||||
cc: Vec<Url>,
|
cc: Vec<Url>,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -82,7 +83,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: vec![public()],
|
||||||
object,
|
object,
|
||||||
cc: vec![community.followers_url()],
|
cc: vec![community.followers_url()],
|
||||||
kind: AnnounceType::Announce,
|
kind: AnnounceType::Announce,
|
||||||
|
@ -106,6 +107,7 @@ impl ActivityHandler for AnnounceActivity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
verify_is_public(&self.to)?;
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_community(&self.actor, context, request_counter).await?;
|
verify_community(&self.actor, context, request_counter).await?;
|
||||||
self.object.verify(context, request_counter).await?;
|
self.object.verify(context, request_counter).await?;
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::{
|
||||||
community::{announce::AnnouncableActivities, send_to_community},
|
community::{announce::AnnouncableActivities, send_to_community},
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
|
verify_is_public,
|
||||||
verify_mod_action,
|
verify_mod_action,
|
||||||
verify_person_in_community,
|
verify_person_in_community,
|
||||||
},
|
},
|
||||||
|
@ -14,13 +15,13 @@ use activitystreams::{
|
||||||
activity::kind::BlockType,
|
activity::kind::BlockType,
|
||||||
base::AnyBase,
|
base::AnyBase,
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
|
public,
|
||||||
unparsed::Unparsed,
|
unparsed::Unparsed,
|
||||||
};
|
};
|
||||||
use lemmy_api_common::blocking;
|
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 +41,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: Vec<Url>,
|
||||||
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 +62,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: vec![public()],
|
||||||
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,
|
||||||
|
@ -97,6 +98,7 @@ impl ActivityHandler for BlockUserFromCommunity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
verify_is_public(&self.to)?;
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::{
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
verify_add_remove_moderator_target,
|
verify_add_remove_moderator_target,
|
||||||
|
verify_is_public,
|
||||||
verify_mod_action,
|
verify_mod_action,
|
||||||
verify_person_in_community,
|
verify_person_in_community,
|
||||||
},
|
},
|
||||||
|
@ -16,13 +17,13 @@ use activitystreams::{
|
||||||
activity::kind::RemoveType,
|
activity::kind::RemoveType,
|
||||||
base::AnyBase,
|
base::AnyBase,
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
|
public,
|
||||||
unparsed::Unparsed,
|
unparsed::Unparsed,
|
||||||
};
|
};
|
||||||
use lemmy_api_common::blocking;
|
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 +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: Vec<Url>,
|
||||||
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")]
|
||||||
|
@ -64,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: vec![public()],
|
||||||
object: ObjectId::new(removed_mod.actor_id()),
|
object: ObjectId::new(removed_mod.actor_id()),
|
||||||
target: generate_moderators_url(&community.actor_id)?.into(),
|
target: generate_moderators_url(&community.actor_id)?.into(),
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
|
@ -88,6 +89,7 @@ impl ActivityHandler for RemoveMod {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
verify_is_public(&self.to)?;
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
|
verify_is_public,
|
||||||
verify_mod_action,
|
verify_mod_action,
|
||||||
verify_person_in_community,
|
verify_person_in_community,
|
||||||
},
|
},
|
||||||
|
@ -18,13 +19,13 @@ use activitystreams::{
|
||||||
activity::kind::UndoType,
|
activity::kind::UndoType,
|
||||||
base::AnyBase,
|
base::AnyBase,
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
|
public,
|
||||||
unparsed::Unparsed,
|
unparsed::Unparsed,
|
||||||
};
|
};
|
||||||
use lemmy_api_common::blocking;
|
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 +40,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: Vec<Url>,
|
||||||
object: BlockUserFromCommunity,
|
object: BlockUserFromCommunity,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -66,7 +67,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: vec![public()],
|
||||||
object: block,
|
object: block,
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind: UndoType::Undo,
|
kind: UndoType::Undo,
|
||||||
|
@ -89,6 +90,7 @@ impl ActivityHandler for UndoBlockUserFromCommunity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
verify_is_public(&self.to)?;
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::{
|
||||||
community::{announce::AnnouncableActivities, send_to_community},
|
community::{announce::AnnouncableActivities, send_to_community},
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
|
verify_is_public,
|
||||||
verify_mod_action,
|
verify_mod_action,
|
||||||
verify_person_in_community,
|
verify_person_in_community,
|
||||||
},
|
},
|
||||||
|
@ -17,13 +18,13 @@ use activitystreams::{
|
||||||
activity::kind::UpdateType,
|
activity::kind::UpdateType,
|
||||||
base::AnyBase,
|
base::AnyBase,
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
|
public,
|
||||||
unparsed::Unparsed,
|
unparsed::Unparsed,
|
||||||
};
|
};
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
|
traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
|
||||||
values::PublicUrl,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::community::{Community, CommunityForm},
|
source::community::{Community, CommunityForm},
|
||||||
|
@ -40,7 +41,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: Vec<Url>,
|
||||||
// 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 +66,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: vec![public()],
|
||||||
object: community.to_apub(context).await?,
|
object: community.to_apub(context).await?,
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind: UpdateType::Update,
|
kind: UpdateType::Update,
|
||||||
|
@ -87,6 +88,7 @@ impl ActivityHandler for UpdateCommunity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
verify_is_public(&self.to)?;
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
|
|
|
@ -9,6 +9,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
|
verify_is_public,
|
||||||
},
|
},
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
|
@ -18,6 +19,7 @@ use activitystreams::{
|
||||||
activity::kind::DeleteType,
|
activity::kind::DeleteType,
|
||||||
base::AnyBase,
|
base::AnyBase,
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
|
public,
|
||||||
unparsed::Unparsed,
|
unparsed::Unparsed,
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
@ -25,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::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -66,7 +67,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: Vec<Url>,
|
||||||
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")]
|
||||||
|
@ -89,6 +90,7 @@ impl ActivityHandler for Delete {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
verify_is_public(&self.to)?;
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_delete_activity(
|
verify_delete_activity(
|
||||||
&self.object,
|
&self.object,
|
||||||
|
@ -144,7 +146,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: vec![public()],
|
||||||
object: object_id,
|
object: object_id,
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind: DeleteType::Delete,
|
kind: DeleteType::Delete,
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
|
verify_is_public,
|
||||||
},
|
},
|
||||||
context::lemmy_context,
|
context::lemmy_context,
|
||||||
fetcher::object_id::ObjectId,
|
fetcher::object_id::ObjectId,
|
||||||
|
@ -19,6 +20,7 @@ use activitystreams::{
|
||||||
activity::kind::UndoType,
|
activity::kind::UndoType,
|
||||||
base::AnyBase,
|
base::AnyBase,
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
|
public,
|
||||||
unparsed::Unparsed,
|
unparsed::Unparsed,
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
@ -26,7 +28,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 +43,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: Vec<Url>,
|
||||||
object: Delete,
|
object: Delete,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -62,6 +63,7 @@ impl ActivityHandler for UndoDelete {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
verify_is_public(&self.to)?;
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
self.object.verify(context, request_counter).await?;
|
self.object.verify(context, request_counter).await?;
|
||||||
verify_delete_activity(
|
verify_delete_activity(
|
||||||
|
@ -117,7 +119,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: vec![public()],
|
||||||
object,
|
object,
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind: UndoType::Undo,
|
kind: UndoType::Undo,
|
||||||
|
|
|
@ -32,7 +32,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct AcceptFollowCommunity {
|
pub struct AcceptFollowCommunity {
|
||||||
actor: ObjectId<ApubCommunity>,
|
actor: ObjectId<ApubCommunity>,
|
||||||
to: ObjectId<ApubPerson>,
|
to: [ObjectId<ApubPerson>; 1],
|
||||||
object: FollowCommunity,
|
object: FollowCommunity,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
kind: AcceptType,
|
kind: AcceptType,
|
||||||
|
@ -57,7 +57,7 @@ impl AcceptFollowCommunity {
|
||||||
.await?;
|
.await?;
|
||||||
let accept = AcceptFollowCommunity {
|
let accept = AcceptFollowCommunity {
|
||||||
actor: ObjectId::new(community.actor_id()),
|
actor: ObjectId::new(community.actor_id()),
|
||||||
to: ObjectId::new(person.actor_id()),
|
to: [ObjectId::new(person.actor_id())],
|
||||||
object: follow,
|
object: follow,
|
||||||
kind: AcceptType::Accept,
|
kind: AcceptType::Accept,
|
||||||
id: generate_activity_id(
|
id: generate_activity_id(
|
||||||
|
@ -82,8 +82,8 @@ impl ActivityHandler for AcceptFollowCommunity {
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_urls_match(self.to.inner(), self.object.actor())?;
|
verify_urls_match(self.to[0].inner(), self.object.actor())?;
|
||||||
verify_urls_match(self.actor(), self.object.to.inner())?;
|
verify_urls_match(self.actor(), self.object.to[0].inner())?;
|
||||||
verify_community(&self.actor, context, request_counter).await?;
|
verify_community(&self.actor, context, request_counter).await?;
|
||||||
self.object.verify(context, request_counter).await?;
|
self.object.verify(context, request_counter).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -95,7 +95,7 @@ impl ActivityHandler for AcceptFollowCommunity {
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let actor = self.actor.dereference(context, request_counter).await?;
|
let actor = self.actor.dereference(context, request_counter).await?;
|
||||||
let to = self.to.dereference(context, request_counter).await?;
|
let to = self.to[0].dereference(context, request_counter).await?;
|
||||||
// This will throw an error if no follow was requested
|
// This will throw an error if no follow was requested
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
CommunityFollower::follow_accepted(conn, actor.id, to.id)
|
CommunityFollower::follow_accepted(conn, actor.id, to.id)
|
||||||
|
|
|
@ -35,8 +35,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct FollowCommunity {
|
pub struct FollowCommunity {
|
||||||
pub(in crate::activities::following) actor: ObjectId<ApubPerson>,
|
pub(in crate::activities::following) actor: ObjectId<ApubPerson>,
|
||||||
// TODO: is there any reason to put the same community id twice, in to and object?
|
pub(in crate::activities::following) to: [ObjectId<ApubCommunity>; 1],
|
||||||
pub(in crate::activities::following) to: ObjectId<ApubCommunity>,
|
|
||||||
pub(in crate::activities::following) object: ObjectId<ApubCommunity>,
|
pub(in crate::activities::following) object: ObjectId<ApubCommunity>,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
kind: FollowType,
|
kind: FollowType,
|
||||||
|
@ -55,7 +54,7 @@ impl FollowCommunity {
|
||||||
) -> Result<FollowCommunity, LemmyError> {
|
) -> Result<FollowCommunity, LemmyError> {
|
||||||
Ok(FollowCommunity {
|
Ok(FollowCommunity {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: ObjectId::new(community.actor_id()),
|
to: [ObjectId::new(community.actor_id())],
|
||||||
object: ObjectId::new(community.actor_id()),
|
object: ObjectId::new(community.actor_id()),
|
||||||
kind: FollowType::Follow,
|
kind: FollowType::Follow,
|
||||||
id: generate_activity_id(
|
id: generate_activity_id(
|
||||||
|
@ -96,7 +95,7 @@ impl ActivityHandler for FollowCommunity {
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_urls_match(self.to.inner(), self.object.inner())?;
|
verify_urls_match(self.to[0].inner(), self.object.inner())?;
|
||||||
verify_person(&self.actor, context, request_counter).await?;
|
verify_person(&self.actor, context, request_counter).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -107,7 +106,7 @@ impl ActivityHandler for FollowCommunity {
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let actor = self.actor.dereference(context, request_counter).await?;
|
let actor = self.actor.dereference(context, request_counter).await?;
|
||||||
let community = self.object.dereference(context, request_counter).await?;
|
let community = self.to[0].dereference(context, request_counter).await?;
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
person_id: actor.id,
|
person_id: actor.id,
|
||||||
|
|
|
@ -35,7 +35,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct UndoFollowCommunity {
|
pub struct UndoFollowCommunity {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: ObjectId<ApubCommunity>,
|
to: [ObjectId<ApubCommunity>; 1],
|
||||||
object: FollowCommunity,
|
object: FollowCommunity,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
kind: UndoType,
|
kind: UndoType,
|
||||||
|
@ -55,7 +55,7 @@ impl UndoFollowCommunity {
|
||||||
let object = FollowCommunity::new(actor, community, context)?;
|
let object = FollowCommunity::new(actor, community, context)?;
|
||||||
let undo = UndoFollowCommunity {
|
let undo = UndoFollowCommunity {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: ObjectId::new(community.actor_id()),
|
to: [ObjectId::new(community.actor_id())],
|
||||||
object,
|
object,
|
||||||
kind: UndoType::Undo,
|
kind: UndoType::Undo,
|
||||||
id: generate_activity_id(
|
id: generate_activity_id(
|
||||||
|
@ -79,7 +79,7 @@ impl ActivityHandler for UndoFollowCommunity {
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_urls_match(self.to.inner(), self.object.object.inner())?;
|
verify_urls_match(self.to[0].inner(), self.object.object.inner())?;
|
||||||
verify_urls_match(self.actor(), self.object.actor())?;
|
verify_urls_match(self.actor(), self.object.actor())?;
|
||||||
verify_person(&self.actor, context, request_counter).await?;
|
verify_person(&self.actor, context, request_counter).await?;
|
||||||
self.object.verify(context, request_counter).await?;
|
self.object.verify(context, request_counter).await?;
|
||||||
|
@ -92,7 +92,7 @@ impl ActivityHandler for UndoFollowCommunity {
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let actor = self.actor.dereference(context, request_counter).await?;
|
let actor = self.actor.dereference(context, request_counter).await?;
|
||||||
let community = self.to.dereference(context, request_counter).await?;
|
let community = self.to[0].dereference(context, request_counter).await?;
|
||||||
|
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::{
|
||||||
community::{announce::AnnouncableActivities, send_to_community},
|
community::{announce::AnnouncableActivities, send_to_community},
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
|
verify_is_public,
|
||||||
verify_mod_action,
|
verify_mod_action,
|
||||||
verify_person_in_community,
|
verify_person_in_community,
|
||||||
CreateOrUpdateType,
|
CreateOrUpdateType,
|
||||||
|
@ -16,13 +17,12 @@ use crate::{
|
||||||
post::{ApubPost, Page},
|
post::{ApubPost, Page},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use activitystreams::{base::AnyBase, primitives::OneOrMany, unparsed::Unparsed};
|
use activitystreams::{base::AnyBase, primitives::OneOrMany, public, unparsed::Unparsed};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
data::Data,
|
data::Data,
|
||||||
traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
|
traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
|
||||||
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: Vec<Url>,
|
||||||
object: Page,
|
object: Page,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -61,7 +61,7 @@ impl CreateOrUpdatePost {
|
||||||
)?;
|
)?;
|
||||||
Ok(CreateOrUpdatePost {
|
Ok(CreateOrUpdatePost {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: [PublicUrl::Public],
|
to: vec![public()],
|
||||||
object: post.to_apub(context).await?,
|
object: post.to_apub(context).await?,
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind,
|
kind,
|
||||||
|
@ -97,6 +97,7 @@ impl ActivityHandler for CreateOrUpdatePost {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
verify_is_public(&self.to)?;
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
let community = self.cc[0].dereference(context, request_counter).await?;
|
let community = self.cc[0].dereference(context, request_counter).await?;
|
||||||
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub struct CreateOrUpdatePrivateMessage {
|
||||||
pub context: OneOrMany<AnyBase>,
|
pub context: OneOrMany<AnyBase>,
|
||||||
id: Url,
|
id: Url,
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: ObjectId<ApubPerson>,
|
to: [ObjectId<ApubPerson>; 1],
|
||||||
object: Note,
|
object: Note,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
kind: CreateOrUpdateType,
|
kind: CreateOrUpdateType,
|
||||||
|
@ -57,7 +57,7 @@ impl CreateOrUpdatePrivateMessage {
|
||||||
context: lemmy_context(),
|
context: lemmy_context(),
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: ObjectId::new(recipient.actor_id()),
|
to: [ObjectId::new(recipient.actor_id())],
|
||||||
object: private_message.to_apub(context).await?,
|
object: private_message.to_apub(context).await?,
|
||||||
kind,
|
kind,
|
||||||
unparsed: Default::default(),
|
unparsed: Default::default(),
|
||||||
|
|
|
@ -30,7 +30,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct DeletePrivateMessage {
|
pub struct DeletePrivateMessage {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: ObjectId<ApubPerson>,
|
to: [ObjectId<ApubPerson>; 1],
|
||||||
pub(in crate::activities::private_message) object: ObjectId<ApubPrivateMessage>,
|
pub(in crate::activities::private_message) object: ObjectId<ApubPrivateMessage>,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
kind: DeleteType,
|
kind: DeleteType,
|
||||||
|
@ -49,7 +49,7 @@ impl DeletePrivateMessage {
|
||||||
) -> Result<DeletePrivateMessage, LemmyError> {
|
) -> Result<DeletePrivateMessage, LemmyError> {
|
||||||
Ok(DeletePrivateMessage {
|
Ok(DeletePrivateMessage {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: ObjectId::new(actor.actor_id()),
|
to: [ObjectId::new(actor.actor_id())],
|
||||||
object: ObjectId::new(pm.ap_id.clone()),
|
object: ObjectId::new(pm.ap_id.clone()),
|
||||||
kind: DeleteType::Delete,
|
kind: DeleteType::Delete,
|
||||||
id: generate_activity_id(
|
id: generate_activity_id(
|
||||||
|
|
|
@ -35,7 +35,7 @@ use url::Url;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct UndoDeletePrivateMessage {
|
pub struct UndoDeletePrivateMessage {
|
||||||
actor: ObjectId<ApubPerson>,
|
actor: ObjectId<ApubPerson>,
|
||||||
to: ObjectId<ApubPerson>,
|
to: [ObjectId<ApubPerson>; 1],
|
||||||
object: DeletePrivateMessage,
|
object: DeletePrivateMessage,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
kind: UndoType,
|
kind: UndoType,
|
||||||
|
@ -65,7 +65,7 @@ impl UndoDeletePrivateMessage {
|
||||||
)?;
|
)?;
|
||||||
let undo = UndoDeletePrivateMessage {
|
let undo = UndoDeletePrivateMessage {
|
||||||
actor: ObjectId::new(actor.actor_id()),
|
actor: ObjectId::new(actor.actor_id()),
|
||||||
to: ObjectId::new(recipient.actor_id()),
|
to: [ObjectId::new(recipient.actor_id())],
|
||||||
object,
|
object,
|
||||||
kind: UndoType::Undo,
|
kind: UndoType::Undo,
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::{
|
||||||
community::{announce::AnnouncableActivities, send_to_community},
|
community::{announce::AnnouncableActivities, send_to_community},
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
|
verify_is_public,
|
||||||
verify_person_in_community,
|
verify_person_in_community,
|
||||||
voting::{
|
voting::{
|
||||||
undo_vote_comment,
|
undo_vote_comment,
|
||||||
|
@ -19,13 +20,13 @@ use activitystreams::{
|
||||||
activity::kind::UndoType,
|
activity::kind::UndoType,
|
||||||
base::AnyBase,
|
base::AnyBase,
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
|
public,
|
||||||
unparsed::Unparsed,
|
unparsed::Unparsed,
|
||||||
};
|
};
|
||||||
use lemmy_api_common::blocking;
|
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 +40,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: Vec<Url>,
|
||||||
object: Vote,
|
object: Vote,
|
||||||
cc: [ObjectId<ApubCommunity>; 1],
|
cc: [ObjectId<ApubCommunity>; 1],
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
|
@ -72,7 +73,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: vec![public()],
|
||||||
object,
|
object,
|
||||||
cc: [ObjectId::new(community.actor_id())],
|
cc: [ObjectId::new(community.actor_id())],
|
||||||
kind: UndoType::Undo,
|
kind: UndoType::Undo,
|
||||||
|
@ -93,6 +94,7 @@ impl ActivityHandler for UndoVote {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
verify_is_public(&self.to)?;
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
verify_urls_match(self.actor(), self.object.actor())?;
|
verify_urls_match(self.actor(), self.object.actor())?;
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::{
|
||||||
community::{announce::AnnouncableActivities, send_to_community},
|
community::{announce::AnnouncableActivities, send_to_community},
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
|
verify_is_public,
|
||||||
verify_person_in_community,
|
verify_person_in_community,
|
||||||
voting::{vote_comment, vote_post},
|
voting::{vote_comment, vote_post},
|
||||||
},
|
},
|
||||||
|
@ -11,13 +12,12 @@ use crate::{
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
PostOrComment,
|
PostOrComment,
|
||||||
};
|
};
|
||||||
use activitystreams::{base::AnyBase, primitives::OneOrMany, unparsed::Unparsed};
|
use activitystreams::{base::AnyBase, primitives::OneOrMany, public, unparsed::Unparsed};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use lemmy_api_common::blocking;
|
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: Vec<Url>,
|
||||||
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: vec![public()],
|
||||||
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(),
|
||||||
|
@ -118,6 +118,7 @@ impl ActivityHandler for Vote {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
verify_is_public(&self.to)?;
|
||||||
verify_activity(self, &context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -32,7 +32,7 @@ use lemmy_db_schema::source::community::Community;
|
||||||
use lemmy_db_views_actor::community_follower_view::CommunityFollowerView;
|
use lemmy_db_views_actor::community_follower_view::CommunityFollowerView;
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use log::trace;
|
use log::info;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -78,7 +78,7 @@ pub async fn community_inbox(
|
||||||
context: web::Data<LemmyContext>,
|
context: web::Data<LemmyContext>,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let unparsed = payload_to_string(payload).await?;
|
let unparsed = payload_to_string(payload).await?;
|
||||||
trace!("Received community inbox activity {}", unparsed);
|
info!("Received community inbox activity {}", unparsed);
|
||||||
let activity = serde_json::from_str::<GroupInboxActivities>(&unparsed)?;
|
let activity = serde_json::from_str::<GroupInboxActivities>(&unparsed)?;
|
||||||
|
|
||||||
receive_group_inbox(activity.clone(), request, &context).await?;
|
receive_group_inbox(activity.clone(), request, &context).await?;
|
||||||
|
|
|
@ -27,7 +27,7 @@ use lemmy_apub_lib::{
|
||||||
use lemmy_db_schema::{source::activity::Activity, DbPool};
|
use lemmy_db_schema::{source::activity::Activity, DbPool};
|
||||||
use lemmy_utils::{location_info, LemmyError};
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use log::{info, trace};
|
use log::info;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fmt::Debug, io::Read};
|
use std::{fmt::Debug, io::Read};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -54,7 +54,7 @@ pub async fn shared_inbox(
|
||||||
context: web::Data<LemmyContext>,
|
context: web::Data<LemmyContext>,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let unparsed = payload_to_string(payload).await?;
|
let unparsed = payload_to_string(payload).await?;
|
||||||
trace!("Received shared inbox activity {}", unparsed);
|
info!("Received shared inbox activity {}", unparsed);
|
||||||
let activity = serde_json::from_str::<SharedInboxActivities>(&unparsed)?;
|
let activity = serde_json::from_str::<SharedInboxActivities>(&unparsed)?;
|
||||||
match activity {
|
match activity {
|
||||||
SharedInboxActivities::GroupInboxActivities(g) => {
|
SharedInboxActivities::GroupInboxActivities(g) => {
|
||||||
|
|
|
@ -28,7 +28,7 @@ use lemmy_apub_lib::traits::{ActivityFields, ActivityHandler, ApubObject};
|
||||||
use lemmy_db_schema::source::person::Person;
|
use lemmy_db_schema::source::person::Person;
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use log::trace;
|
use log::info;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ pub async fn person_inbox(
|
||||||
context: web::Data<LemmyContext>,
|
context: web::Data<LemmyContext>,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let unparsed = payload_to_string(payload).await?;
|
let unparsed = payload_to_string(payload).await?;
|
||||||
trace!("Received person inbox activity {}", unparsed);
|
info!("Received person inbox activity {}", unparsed);
|
||||||
let activity = serde_json::from_str::<PersonInboxActivities>(&unparsed)?;
|
let activity = serde_json::from_str::<PersonInboxActivities>(&unparsed)?;
|
||||||
receive_person_inbox(activity, request, &context).await
|
receive_person_inbox(activity, request, &context).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,15 +33,6 @@
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// The identifier used to address activities to the public.
|
|
||||||
///
|
|
||||||
/// <https://www.w3.org/TR/activitypub/#public-addressing>
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
||||||
pub enum PublicUrl {
|
|
||||||
#[serde(rename = "https://www.w3.org/ns/activitystreams#Public")]
|
|
||||||
Public,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Media type for markdown text.
|
/// Media type for markdown text.
|
||||||
///
|
///
|
||||||
/// <https://www.iana.org/assignments/media-types/media-types.xhtml>
|
/// <https://www.iana.org/assignments/media-types/media-types.xhtml>
|
||||||
|
|
Loading…
Reference in a new issue