Skip to content

Commit

Permalink
Merge pull request #198 from LemmyNet/main
Browse files Browse the repository at this point in the history
[pull] master from LemmyNet:main
  • Loading branch information
pull[bot] authored Nov 28, 2024
2 parents 2578a85 + 5a403bc commit ce3da7d
Show file tree
Hide file tree
Showing 26 changed files with 137 additions and 325 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/apub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ html2md = "0.2.14"
html2text = "0.12.6"
stringreader = "0.1.1"
enum_delegate = "0.2.0"
semver = "1.0.23"

[dev-dependencies]
serial_test = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"actor": "http://enterprise.lemmy.ml/u/lemmy_beta",
"to": ["http://ds9.lemmy.ml/u/lemmy_alpha"],
"object": {
"type": "Note",
"type": "ChatMessage",
"id": "http://enterprise.lemmy.ml/private_message/1",
"attributedTo": "http://enterprise.lemmy.ml/u/lemmy_beta",
"to": ["http://ds9.lemmy.ml/u/lemmy_alpha"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "https://enterprise.lemmy.ml/private_message/1621",
"type": "Note",
"type": "ChatMessage",
"attributedTo": "https://enterprise.lemmy.ml/u/picard",
"to": ["https://queer.hacktivis.me/users/lanodan"],
"content": "<p>Hello hello, testing</p>\n",
Expand Down
File renamed without changes.
49 changes: 0 additions & 49 deletions crates/apub/assets/mastodon/activities/private_message.json

This file was deleted.

15 changes: 15 additions & 0 deletions crates/apub/assets/pleroma/objects/chat_message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://queer.hacktivis.me/schemas/litepub-0.1.jsonld",
{
"@language": "und"
}
],
"attributedTo": "https://queer.hacktivis.me/users/lanodan",
"content": "Hi!",
"id": "https://queer.hacktivis.me/objects/2",
"published": "2020-02-12T14:08:20Z",
"to": ["https://enterprise.lemmy.ml/u/picard"],
"type": "ChatMessage"
}
5 changes: 2 additions & 3 deletions crates/apub/src/activities/community/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,16 @@ impl ActivityHandler for RawAnnouncableActivities {

// verify and receive activity
activity.verify(context).await?;
let actor_id = activity.actor().clone().into();
activity.receive(context).await?;
activity.clone().receive(context).await?;

// if community is local, send activity to followers
if let Some(community) = community {
if community.local {
let actor_id = activity.actor().clone().into();
verify_person_in_community(&actor_id, &community, context).await?;
AnnounceActivity::send(self, &community, context).await?;
}
}

Ok(())
}
}
Expand Down
4 changes: 1 addition & 3 deletions crates/apub/src/activities/create_or_update/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ use lemmy_utils::{
error::{LemmyError, LemmyResult},
utils::mention::scrape_text_for_mentions,
};
use serde_json::{from_value, to_value};
use url::Url;

impl CreateOrUpdateNote {
Expand Down Expand Up @@ -99,8 +98,7 @@ impl CreateOrUpdateNote {
inboxes.add_inbox(person.shared_inbox_or_inbox());
}

let activity =
AnnouncableActivities::CreateOrUpdateNoteWrapper(from_value(to_value(create_or_update)?)?);
let activity = AnnouncableActivities::CreateOrUpdateComment(create_or_update);
send_activity_in_community(activity, &person, &community, inboxes, false, &context).await
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/apub/src/activities/create_or_update/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod comment;
pub(crate) mod note_wrapper;
pub mod post;
pub mod private_message;
66 changes: 0 additions & 66 deletions crates/apub/src/activities/create_or_update/note_wrapper.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
insert_received_activity,
objects::{person::ApubPerson, private_message::ApubPrivateMessage},
protocol::activities::{
create_or_update::private_message::CreateOrUpdatePrivateMessage,
create_or_update::chat_message::CreateOrUpdateChatMessage,
CreateOrUpdateType,
},
};
Expand All @@ -30,7 +30,7 @@ pub(crate) async fn send_create_or_update_pm(
kind.clone(),
&context.settings().get_protocol_and_hostname(),
)?;
let create_or_update = CreateOrUpdatePrivateMessage {
let create_or_update = CreateOrUpdateChatMessage {
id: id.clone(),
actor: actor.id().into(),
to: [recipient.id().into()],
Expand All @@ -44,7 +44,7 @@ pub(crate) async fn send_create_or_update_pm(
}

#[async_trait::async_trait]
impl ActivityHandler for CreateOrUpdatePrivateMessage {
impl ActivityHandler for CreateOrUpdateChatMessage {
type DataType = LemmyContext;
type Error = LemmyError;

Expand Down
6 changes: 3 additions & 3 deletions crates/apub/src/activities/deletion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use lemmy_db_schema::{
community::{Community, CommunityUpdateForm},
person::Person,
post::{Post, PostUpdateForm},
private_message::{PrivateMessage as DbPrivateMessage, PrivateMessageUpdateForm},
private_message::{PrivateMessage, PrivateMessageUpdateForm},
},
traits::Crud,
};
Expand Down Expand Up @@ -82,7 +82,7 @@ pub(crate) async fn send_apub_delete_in_community(
#[tracing::instrument(skip_all)]
pub(crate) async fn send_apub_delete_private_message(
actor: &ApubPerson,
pm: DbPrivateMessage,
pm: PrivateMessage,
deleted: bool,
context: Data<LemmyContext>,
) -> LemmyResult<()> {
Expand Down Expand Up @@ -298,7 +298,7 @@ async fn receive_delete_action(
}
}
DeletableObjects::PrivateMessage(pm) => {
DbPrivateMessage::update(
PrivateMessage::update(
&mut context.pool(),
pm.id,
&PrivateMessageUpdateForm {
Expand Down
74 changes: 58 additions & 16 deletions crates/apub/src/activity_lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ use crate::{
report::Report,
update::UpdateCommunity,
},
create_or_update::{note_wrapper::CreateOrUpdateNoteWrapper, page::CreateOrUpdatePage},
create_or_update::{
chat_message::CreateOrUpdateChatMessage,
note::CreateOrUpdateNote,
page::CreateOrUpdatePage,
},
deletion::{delete::Delete, undo_delete::UndoDelete},
following::{
accept::AcceptFollow,
Expand Down Expand Up @@ -44,17 +48,47 @@ pub enum SharedInboxActivities {
AcceptFollow(AcceptFollow),
RejectFollow(RejectFollow),
UndoFollow(UndoFollow),
CreateOrUpdatePrivateMessage(CreateOrUpdateChatMessage),
Report(Report),
AnnounceActivity(AnnounceActivity),
/// This is a catch-all and needs to be last
RawAnnouncableActivities(RawAnnouncableActivities),
}

/// List of activities which the group inbox can handle.
#[derive(Debug, Deserialize, Serialize)]
#[serde(untagged)]
#[enum_delegate::implement(ActivityHandler)]
pub enum GroupInboxActivities {
Follow(Follow),
UndoFollow(UndoFollow),
Report(Report),
/// This is a catch-all and needs to be last
AnnouncableActivities(RawAnnouncableActivities),
}

/// List of activities which the person inbox can handle.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged)]
#[enum_delegate::implement(ActivityHandler)]
pub enum PersonInboxActivities {
Follow(Follow),
AcceptFollow(AcceptFollow),
RejectFollow(RejectFollow),
UndoFollow(UndoFollow),
CreateOrUpdatePrivateMessage(CreateOrUpdateChatMessage),
Delete(Delete),
UndoDelete(UndoDelete),
AnnounceActivity(AnnounceActivity),
/// User can also receive some "announcable" activities, eg a comment mention.
AnnouncableActivities(AnnouncableActivities),
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged)]
#[enum_delegate::implement(ActivityHandler)]
pub enum AnnouncableActivities {
CreateOrUpdateNoteWrapper(CreateOrUpdateNoteWrapper),
CreateOrUpdateComment(CreateOrUpdateNote),
CreateOrUpdatePost(CreateOrUpdatePage),
Vote(Vote),
UndoVote(UndoVote),
Expand All @@ -77,7 +111,7 @@ impl InCommunity for AnnouncableActivities {
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
use AnnouncableActivities::*;
match self {
CreateOrUpdateNoteWrapper(a) => a.community(context).await,
CreateOrUpdateComment(a) => a.community(context).await,
CreateOrUpdatePost(a) => a.community(context).await,
Vote(a) => a.community(context).await,
UndoVote(a) => a.community(context).await,
Expand All @@ -99,32 +133,40 @@ impl InCommunity for AnnouncableActivities {
mod tests {

use crate::{
activity_lists::SharedInboxActivities,
activity_lists::{GroupInboxActivities, PersonInboxActivities, SharedInboxActivities},
protocol::tests::{test_json, test_parse_lemmy_item},
};
use lemmy_utils::error::LemmyResult;

#[test]
fn test_shared_inbox() -> LemmyResult<()> {
test_parse_lemmy_item::<SharedInboxActivities>(
"assets/lemmy/activities/deletion/delete_user.json",
fn test_group_inbox() -> LemmyResult<()> {
test_parse_lemmy_item::<GroupInboxActivities>("assets/lemmy/activities/following/follow.json")?;
test_parse_lemmy_item::<GroupInboxActivities>(
"assets/lemmy/activities/create_or_update/create_note.json",
)?;
test_parse_lemmy_item::<SharedInboxActivities>(
Ok(())
}

#[test]
fn test_person_inbox() -> LemmyResult<()> {
test_parse_lemmy_item::<PersonInboxActivities>(
"assets/lemmy/activities/following/accept.json",
)?;
test_parse_lemmy_item::<SharedInboxActivities>(
"assets/lemmy/activities/create_or_update/create_comment.json",
test_parse_lemmy_item::<PersonInboxActivities>(
"assets/lemmy/activities/create_or_update/create_note.json",
)?;
test_parse_lemmy_item::<SharedInboxActivities>(
test_parse_lemmy_item::<PersonInboxActivities>(
"assets/lemmy/activities/create_or_update/create_private_message.json",
)?;
test_json::<PersonInboxActivities>("assets/mastodon/activities/follow.json")?;
Ok(())
}

#[test]
fn test_shared_inbox() -> LemmyResult<()> {
test_parse_lemmy_item::<SharedInboxActivities>(
"assets/lemmy/activities/following/follow.json",
)?;
test_parse_lemmy_item::<SharedInboxActivities>(
"assets/lemmy/activities/create_or_update/create_comment.json",
"assets/lemmy/activities/deletion/delete_user.json",
)?;
test_json::<SharedInboxActivities>("assets/mastodon/activities/follow.json")?;
Ok(())
}
}
2 changes: 1 addition & 1 deletion crates/apub/src/objects/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ pub(crate) mod tests {
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741")?;
let data = prepare_comment_test(&url, &context).await?;

let json: Note = file_to_json_object("assets/lemmy/objects/comment.json")?;
let json: Note = file_to_json_object("assets/lemmy/objects/note.json")?;
ApubComment::verify(&json, &url, &context).await?;
let comment = ApubComment::from_json(json.clone(), &context).await?;

Expand Down
Loading

0 comments on commit ce3da7d

Please sign in to comment.