mark_post_as_read,
post::*,
};
-use lemmy_apub::{activities::post::update::UpdatePost, ApubLikeableType};
+use lemmy_apub::{
+ activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType},
+ ApubLikeableType,
+};
use lemmy_db_queries::{source::post::Post_, Crud, Likeable, Saveable};
use lemmy_db_schema::source::{moderator::*, post::*};
use lemmy_db_views::post_view::PostView;
blocking(context.pool(), move |conn| ModLockPost::create(conn, &form)).await??;
// apub updates
- UpdatePost::send(&updated_post, &local_user_view.person, context).await?;
+ CreateOrUpdatePost::send(
+ &updated_post,
+ &local_user_view.person,
+ CreateOrUpdateType::Update,
+ context,
+ )
+ .await?;
// Refetch the post
let post_id = data.post_id;
// Apub updates
// TODO stickied should pry work like locked for ease of use
- UpdatePost::send(&updated_post, &local_user_view.person, context).await?;
+ CreateOrUpdatePost::send(
+ &updated_post,
+ &local_user_view.person,
+ CreateOrUpdateType::Update,
+ context,
+ )
+ .await?;
// Refetch the post
let post_id = data.post_id;
send_local_notifs,
};
use lemmy_apub::{
- activities::comment::create_or_update::{CreateOrUpdateComment, CreateOrUpdateType},
+ activities::{comment::create_or_update::CreateOrUpdateComment, CreateOrUpdateType},
generate_apub_endpoint,
ApubLikeableType,
EndpointType,
get_local_user_view_from_jwt,
send_local_notifs,
};
-use lemmy_apub::activities::comment::create_or_update::{
- CreateOrUpdateComment,
+use lemmy_apub::activities::{
+ comment::create_or_update::CreateOrUpdateComment,
CreateOrUpdateType,
};
use lemmy_db_queries::{source::comment::Comment_, DeleteableOrRemoveable};
.await?
.map_err(|_| ApiError::err("couldnt_update_comment"))?;
+ // Send the apub update
CreateOrUpdateComment::send(
&updated_comment,
&local_user_view.person,
post::*,
};
use lemmy_apub::{
- activities::post::create::CreatePost as CreateApubPost,
+ activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType},
generate_apub_endpoint,
ApubLikeableType,
EndpointType,
.await?
.map_err(|_| ApiError::err("couldnt_create_post"))?;
- CreateApubPost::send(&updated_post, &local_user_view.person, context).await?;
+ CreateOrUpdatePost::send(
+ &updated_post,
+ &local_user_view.person,
+ CreateOrUpdateType::Create,
+ context,
+ )
+ .await?;
// They like their own post by default
let person_id = local_user_view.person.id;
use crate::PerformCrud;
use actix_web::web::Data;
use lemmy_api_common::{blocking, check_community_ban, get_local_user_view_from_jwt, post::*};
-use lemmy_apub::activities::post::update::UpdatePost;
+use lemmy_apub::activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType};
use lemmy_db_queries::{source::post::Post_, Crud, DeleteableOrRemoveable};
use lemmy_db_schema::{naive_now, source::post::*};
use lemmy_db_views::post_view::PostView;
};
// Send apub update
- UpdatePost::send(&updated_post, &local_user_view.person, context).await?;
+ CreateOrUpdatePost::send(
+ &updated_post,
+ &local_user_view.person,
+ CreateOrUpdateType::Update,
+ context,
+ )
+ .await?;
let post_id = data.post_id;
let mut post_view = blocking(context.pool(), move |conn| {
generate_activity_id,
verify_activity,
verify_person_in_community,
+ CreateOrUpdateType,
},
activity_queue::send_to_community_new,
extensions::context::lemmy_context,
objects::{comment::Note, FromApub, ToApub},
ActorType,
};
-use activitystreams::{activity::kind::CreateType, link::Mention};
+use activitystreams::link::Mention;
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
values::PublicUrl,
use serde::{Deserialize, Serialize};
use url::Url;
-#[derive(Clone, Debug, Deserialize, Serialize)]
-pub enum CreateOrUpdateType {
- Create,
- Update,
-}
-
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateOrUpdateComment {
})
.await??;
- let id = match kind {
- CreateOrUpdateType::Create => generate_activity_id(CreateType::Create),
- CreateOrUpdateType::Update => generate_activity_id(CreateType::Create),
- }?;
+ let id = generate_activity_id(kind.clone())?;
let maa = collect_non_local_mentions(comment, &community, context).await?;
let create_or_update = CreateOrUpdateComment {
undo_delete::UndoDeletePostCommentOrCommunity,
},
generate_activity_id,
- post::{create::CreatePost, update::UpdatePost},
+ post::create_or_update::CreateOrUpdatePost,
removal::{
remove::RemovePostCommentCommunityOrMod,
undo_remove::UndoRemovePostCommentOrCommunity,
#[serde(untagged)]
pub enum AnnouncableActivities {
CreateOrUpdateComment(CreateOrUpdateComment),
- CreatePost(CreatePost),
- UpdatePost(UpdatePost),
+ CreateOrUpdatePost(Box<CreateOrUpdatePost>),
LikePostOrComment(LikePostOrComment),
DislikePostOrComment(DislikePostOrComment),
UndoLikePostOrComment(UndoLikePostOrComment),
kind: AnnounceType::Announce,
common: ActivityCommonFields {
context: lemmy_context(),
- id: generate_activity_id(AnnounceType::Announce)?,
+ id: generate_activity_id(&AnnounceType::Announce)?,
actor: community.actor_id(),
unparsed: Default::default(),
},
use lemmy_db_views_actor::community_view::CommunityView;
use lemmy_utils::{settings::structs::Settings, LemmyError};
use lemmy_websocket::LemmyContext;
+use serde::{Deserialize, Serialize};
+use strum_macros::ToString;
use url::{ParseError, Url};
use uuid::Uuid;
pub mod send;
pub mod voting;
+#[derive(Clone, Debug, ToString, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub enum CreateOrUpdateType {
+ Create,
+ Update,
+}
+
/// Checks that the specified Url actually identifies a Person (by fetching it), and that the person
/// doesn't have a site ban.
async fn verify_person(
generate_activity_id,
post::send_websocket_message,
verify_activity,
+ verify_mod_action,
verify_person_in_community,
+ CreateOrUpdateType,
},
activity_queue::send_to_community_new,
extensions::context::lemmy_context,
objects::{post::Page, FromApub, ToApub},
ActorType,
};
-use activitystreams::activity::kind::CreateType;
use anyhow::anyhow;
use lemmy_api_common::blocking;
use lemmy_apub_lib::{
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
-pub struct CreatePost {
+pub struct CreateOrUpdatePost {
to: PublicUrl,
object: Page,
cc: [Url; 1],
- r#type: CreateType,
+ #[serde(rename = "type")]
+ kind: CreateOrUpdateType,
#[serde(flatten)]
common: ActivityCommonFields,
}
-impl CreatePost {
- pub async fn send(post: &Post, actor: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
+impl CreateOrUpdatePost {
+ pub async fn send(
+ post: &Post,
+ actor: &Person,
+ kind: CreateOrUpdateType,
+ context: &LemmyContext,
+ ) -> Result<(), LemmyError> {
let community_id = post.community_id;
let community = blocking(context.pool(), move |conn| {
Community::read(conn, community_id)
})
.await??;
- let id = generate_activity_id(CreateType::Create)?;
- let create = CreatePost {
+ let id = generate_activity_id(kind.clone())?;
+ let create_or_update = CreateOrUpdatePost {
to: PublicUrl::Public,
object: post.to_apub(context.pool()).await?,
cc: [community.actor_id()],
- r#type: Default::default(),
+ kind,
common: ActivityCommonFields {
context: lemmy_context(),
id: id.clone(),
},
};
- let activity = AnnouncableActivities::CreatePost(create);
+ let activity = AnnouncableActivities::CreateOrUpdatePost(Box::new(create_or_update));
send_to_community_new(activity, &id, actor, &community, vec![], context).await
}
}
#[async_trait::async_trait(?Send)]
-impl ActivityHandler for CreatePost {
+impl ActivityHandler for CreateOrUpdatePost {
async fn verify(
&self,
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- let community = extract_community(&self.cc, context, request_counter).await?;
- let community_id = &community.actor_id();
-
verify_activity(self.common())?;
- verify_person_in_community(&self.common.actor, community_id, context, request_counter).await?;
- verify_domains_match(&self.common.actor, &self.object.id)?;
- verify_urls_match(&self.common.actor, &self.object.attributed_to)?;
- // Check that the post isnt locked or stickied, as that isnt possible for newly created posts.
- // However, when fetching a remote post we generate a new create activity with the current
- // locked/stickied value, so this check may fail. So only check if its a local community,
- // because then we will definitely receive all create and update activities separately.
- let is_stickied_or_locked =
- self.object.stickied == Some(true) || self.object.comments_enabled == Some(false);
- if community.local && is_stickied_or_locked {
- return Err(anyhow!("New post cannot be stickied or locked").into());
+ let community = extract_community(&self.cc, context, request_counter).await?;
+ let community_id = community.actor_id();
+ verify_person_in_community(&self.common.actor, &community_id, context, request_counter).await?;
+ match self.kind {
+ CreateOrUpdateType::Create => {
+ verify_domains_match(&self.common.actor, &self.object.id)?;
+ verify_urls_match(&self.common.actor, &self.object.attributed_to)?;
+ // Check that the post isnt locked or stickied, as that isnt possible for newly created posts.
+ // However, when fetching a remote post we generate a new create activity with the current
+ // locked/stickied value, so this check may fail. So only check if its a local community,
+ // because then we will definitely receive all create and update activities separately.
+ let is_stickied_or_locked =
+ self.object.stickied == Some(true) || self.object.comments_enabled == Some(false);
+ if community.local && is_stickied_or_locked {
+ return Err(anyhow!("New post cannot be stickied or locked").into());
+ }
+ }
+ CreateOrUpdateType::Update => {
+ let is_mod_action = self.object.is_mod_action(context.pool()).await?;
+ if is_mod_action {
+ verify_mod_action(&self.common.actor, community_id, context).await?;
+ } else {
+ verify_domains_match(&self.common.actor, &self.object.id)?;
+ verify_urls_match(&self.common.actor, &self.object.attributed_to)?;
+ }
+ }
}
self.object.verify(context, request_counter).await?;
Ok(())
)
.await?;
- send_websocket_message(post.id, UserOperationCrud::CreatePost, context).await
+ let notif_type = match self.kind {
+ CreateOrUpdateType::Create => UserOperationCrud::CreatePost,
+ CreateOrUpdateType::Update => UserOperationCrud::EditPost,
+ };
+ send_websocket_message(post.id, notif_type, context).await
}
fn common(&self) -> &ActivityCommonFields {
use lemmy_utils::LemmyError;
use lemmy_websocket::{messages::SendPost, LemmyContext};
-pub mod create;
-pub mod update;
+pub mod create_or_update;
pub(crate) async fn send_websocket_message<
OP: ToString + Send + lemmy_websocket::OperationType + 'static,
+++ /dev/null
-use crate::{
- activities::{
- community::announce::AnnouncableActivities,
- generate_activity_id,
- post::send_websocket_message,
- verify_activity,
- verify_mod_action,
- verify_person_in_community,
- },
- activity_queue::send_to_community_new,
- extensions::context::lemmy_context,
- fetcher::community::get_or_fetch_and_upsert_community,
- objects::{post::Page, FromApub, ToApub},
- ActorType,
-};
-use activitystreams::activity::kind::UpdateType;
-use lemmy_api_common::blocking;
-use lemmy_apub_lib::{values::PublicUrl, verify_urls_match, ActivityCommonFields, ActivityHandler};
-use lemmy_db_queries::Crud;
-use lemmy_db_schema::source::{community::Community, person::Person, post::Post};
-use lemmy_utils::LemmyError;
-use lemmy_websocket::{LemmyContext, UserOperationCrud};
-use url::Url;
-
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct UpdatePost {
- to: PublicUrl,
- object: Page,
- cc: [Url; 1],
- r#type: UpdateType,
- #[serde(flatten)]
- common: ActivityCommonFields,
-}
-
-impl UpdatePost {
- pub async fn send(post: &Post, actor: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
- let community_id = post.community_id;
- let community = blocking(context.pool(), move |conn| {
- Community::read(conn, community_id)
- })
- .await??;
-
- let id = generate_activity_id(UpdateType::Update)?;
- let update = UpdatePost {
- to: PublicUrl::Public,
- object: post.to_apub(context.pool()).await?,
- cc: [community.actor_id()],
- r#type: Default::default(),
- common: ActivityCommonFields {
- context: lemmy_context(),
- id: id.clone(),
- actor: actor.actor_id(),
- unparsed: Default::default(),
- },
- };
- let activity = AnnouncableActivities::UpdatePost(update);
- send_to_community_new(activity, &id, actor, &community, vec![], context).await
- }
-}
-
-#[async_trait::async_trait(?Send)]
-impl ActivityHandler for UpdatePost {
- async fn verify(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<(), LemmyError> {
- let community_id = get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter)
- .await?
- .actor_id();
- let is_mod_action = self.object.is_mod_action(context.pool()).await?;
-
- verify_activity(self.common())?;
- verify_person_in_community(&self.common.actor, &community_id, context, request_counter).await?;
- if is_mod_action {
- verify_mod_action(&self.common.actor, community_id, context).await?;
- } else {
- verify_urls_match(&self.common.actor, &self.object.attributed_to)?;
- }
- self.object.verify(context, request_counter).await?;
- Ok(())
- }
-
- async fn receive(
- &self,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<(), LemmyError> {
- let post = Post::from_apub(
- &self.object,
- context,
- self.common.actor.clone(),
- request_counter,
- // TODO: we already check here if the mod action is valid, can remove that check param
- true,
- )
- .await?;
-
- send_websocket_message(post.id, UserOperationCrud::EditPost, context).await
- }
-
- fn common(&self) -> &ActivityCommonFields {
- &self.common
- }
-}
},
deletion::{delete::DeletePostCommentOrCommunity, undo_delete::UndoDeletePostCommentOrCommunity},
following::{accept::AcceptFollowCommunity, follow::FollowCommunity, undo::UndoFollowCommunity},
- post::{create::CreatePost, update::UpdatePost},
+ post::create_or_update::CreateOrUpdatePost,
private_message::{
create::CreatePrivateMessage,
delete::DeletePrivateMessage,
FollowCommunity(FollowCommunity),
UndoFollowCommunity(UndoFollowCommunity),
CreateOrUpdateComment(CreateOrUpdateComment),
- CreatePost(CreatePost),
- UpdatePost(UpdatePost),
+ CreateOrUpdatePost(Box<CreateOrUpdatePost>),
LikePostOrComment(LikePostOrComment),
DislikePostOrComment(DislikePostOrComment),
UndoLikePostOrComment(UndoLikePostOrComment),
FollowCommunity(FollowCommunity),
UndoFollowCommunity(UndoFollowCommunity),
CreateOrUpdateComment(CreateOrUpdateComment),
- CreatePost(CreatePost),
- UpdatePost(UpdatePost),
+ CreateOrUpdatePost(CreateOrUpdatePost),
LikePostOrComment(LikePostOrComment),
DislikePostOrComment(DislikePostOrComment),
UndoDislikePostOrComment(UndoDislikePostOrComment),