Skip to content

Commit

Permalink
Merge pull request #197 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 26, 2024
2 parents 6cc6f34 + 7304ef3 commit 2578a85
Show file tree
Hide file tree
Showing 27 changed files with 355 additions and 167 deletions.
60 changes: 30 additions & 30 deletions .woodpecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,36 @@ steps:
when:
- event: pull_request

cargo_clippy:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
commands:
- rustup component add clippy
- cargo clippy --workspace --tests --all-targets -- -D warnings
when: *slow_check_paths

cargo_test:
image: *rust_image
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: "1"
CARGO_HOME: .cargo_home
LEMMY_TEST_FAST_FEDERATION: "1"
LEMMY_CONFIG_LOCATION: ../../config/config.hjson
commands:
- cargo test --workspace --no-fail-fast
when: *slow_check_paths

check_ts_bindings:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
commands:
- ./scripts/ts_bindings_check.sh
when:
- event: pull_request

# make sure api builds with default features (used by other crates relying on lemmy api)
check_api_common_default_features:
image: *rust_image
Expand Down Expand Up @@ -138,15 +168,6 @@ steps:
- diff tmp.schema crates/db_schema/src/schema.rs
when: *slow_check_paths

cargo_clippy:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
commands:
- rustup component add clippy
- cargo clippy --workspace --tests --all-targets -- -D warnings
when: *slow_check_paths

cargo_build:
image: *rust_image
environment:
Expand All @@ -156,27 +177,6 @@ steps:
- mv target/debug/lemmy_server target/lemmy_server
when: *slow_check_paths

cargo_test:
image: *rust_image
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: "1"
CARGO_HOME: .cargo_home
LEMMY_TEST_FAST_FEDERATION: "1"
LEMMY_CONFIG_LOCATION: ../../config/config.hjson
commands:
- cargo test --workspace --no-fail-fast
when: *slow_check_paths

check_ts_bindings:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
commands:
- ./scripts/ts_bindings_check.sh
when:
- event: pull_request

check_diesel_migration:
# TODO: use willsquire/diesel-cli image when shared libraries become optional in lemmy_server
image: *rust_image
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/apub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ 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": "ChatMessage",
"type": "Note",
"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
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "https://enterprise.lemmy.ml/private_message/1621",
"type": "ChatMessage",
"type": "Note",
"attributedTo": "https://enterprise.lemmy.ml/u/picard",
"to": ["https://queer.hacktivis.me/users/lanodan"],
"content": "<p>Hello hello, testing</p>\n",
Expand Down
49 changes: 49 additions & 0 deletions crates/apub/assets/mastodon/activities/private_message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"ostatus": "http://ostatus.org#",
"atomUri": "ostatus:atomUri",
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
"conversation": "ostatus:conversation",
"sensitive": "as:sensitive",
"toot": "http://joinmastodon.org/ns#",
"votersCount": "toot:votersCount"
}
],
"id": "https://mastodon.world/users/nutomic/statuses/110854468010322301",
"type": "Note",
"summary": null,
"inReplyTo": "https://mastodon.world/users/nutomic/statuses/110854464248188528",
"published": "2023-08-08T14:29:04Z",
"url": "https://mastodon.world/@nutomic/110854468010322301",
"attributedTo": "https://mastodon.world/users/nutomic",
"to": ["https://ds9.lemmy.ml/u/nutomic"],
"cc": [],
"sensitive": false,
"atomUri": "https://mastodon.world/users/nutomic/statuses/110854468010322301",
"inReplyToAtomUri": "https://mastodon.world/users/nutomic/statuses/110854464248188528",
"conversation": "tag:mastodon.world,2023-08-08:objectId=121377096:objectType=Conversation",
"content": "<p><span class=\"h-card\" translate=\"no\"><a href=\"https://ds9.lemmy.ml/u/nutomic\" class=\"u-url mention\">@<span>[email protected]</span></a></span> 444</p>",
"contentMap": {
"es": "<p><span class=\"h-card\" translate=\"no\"><a href=\"https://ds9.lemmy.ml/u/nutomic\" class=\"u-url mention\">@<span>[email protected]</span></a></span> 444</p>"
},
"attachment": [],
"tag": [
{
"type": "Mention",
"href": "https://ds9.lemmy.ml/u/nutomic",
"name": "@[email protected]"
}
],
"replies": {
"id": "https://mastodon.world/users/nutomic/statuses/110854468010322301/replies",
"type": "Collection",
"first": {
"type": "CollectionPage",
"next": "https://mastodon.world/users/nutomic/statuses/110854468010322301/replies?only_other_accounts=true&page=true",
"partOf": "https://mastodon.world/users/nutomic/statuses/110854468010322301/replies",
"items": []
}
}
}
15 changes: 0 additions & 15 deletions crates/apub/assets/pleroma/objects/chat_message.json

This file was deleted.

5 changes: 3 additions & 2 deletions crates/apub/src/activities/community/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ impl ActivityHandler for RawAnnouncableActivities {

// verify and receive activity
activity.verify(context).await?;
activity.clone().receive(context).await?;
let actor_id = activity.actor().clone().into();
activity.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: 3 additions & 1 deletion crates/apub/src/activities/create_or_update/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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 @@ -98,7 +99,8 @@ impl CreateOrUpdateNote {
inboxes.add_inbox(person.shared_inbox_or_inbox());
}

let activity = AnnouncableActivities::CreateOrUpdateComment(create_or_update);
let activity =
AnnouncableActivities::CreateOrUpdateNoteWrapper(from_value(to_value(create_or_update)?)?);
send_activity_in_community(activity, &person, &community, inboxes, false, &context).await
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/apub/src/activities/create_or_update/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod comment;
pub(crate) mod note_wrapper;
pub mod post;
pub mod private_message;
66 changes: 66 additions & 0 deletions crates/apub/src/activities/create_or_update/note_wrapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use crate::{
objects::{community::ApubCommunity, note_wrapper::is_public},
protocol::{
activities::create_or_update::{
note::CreateOrUpdateNote,
note_wrapper::CreateOrUpdateNoteWrapper,
private_message::CreateOrUpdatePrivateMessage,
},
InCommunity,
},
};
use activitypub_federation::{config::Data, traits::ActivityHandler};
use lemmy_api_common::context::LemmyContext;
use lemmy_utils::error::{FederationError, LemmyError, LemmyResult};
use serde_json::{from_value, to_value};
use url::Url;

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

fn id(&self) -> &Url {
&self.id
}

fn actor(&self) -> &Url {
&self.actor
}

#[tracing::instrument(skip_all)]
async fn verify(&self, context: &Data<Self::DataType>) -> LemmyResult<()> {
let val = to_value(self)?;
if is_public(&self.to, &self.cc) {
CreateOrUpdateNote::verify(&from_value(val)?, context).await?;
} else {
CreateOrUpdatePrivateMessage::verify(&from_value(val)?, context).await?;
}
Ok(())
}

#[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<Self::DataType>) -> LemmyResult<()> {
let is_public = is_public(&self.to, &self.cc);
let val = to_value(self)?;
if is_public {
CreateOrUpdateNote::receive(from_value(val)?, context).await?;
} else {
CreateOrUpdatePrivateMessage::receive(from_value(val)?, context).await?;
}
Ok(())
}
}

#[async_trait::async_trait]
impl InCommunity for CreateOrUpdateNoteWrapper {
#[tracing::instrument(skip(self, context))]
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
if is_public(&self.to, &self.cc) {
let comment: CreateOrUpdateNote = from_value(to_value(self)?)?;
comment.community(context).await
} else {
Err(FederationError::ObjectIsNotPublic.into())
}
}
}
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::chat_message::CreateOrUpdateChatMessage,
create_or_update::private_message::CreateOrUpdatePrivateMessage,
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 = CreateOrUpdateChatMessage {
let create_or_update = CreateOrUpdatePrivateMessage {
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 CreateOrUpdateChatMessage {
impl ActivityHandler for CreateOrUpdatePrivateMessage {
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, PrivateMessageUpdateForm},
private_message::{PrivateMessage as DbPrivateMessage, 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: PrivateMessage,
pm: DbPrivateMessage,
deleted: bool,
context: Data<LemmyContext>,
) -> LemmyResult<()> {
Expand Down Expand Up @@ -298,7 +298,7 @@ async fn receive_delete_action(
}
}
DeletableObjects::PrivateMessage(pm) => {
PrivateMessage::update(
DbPrivateMessage::update(
&mut context.pool(),
pm.id,
&PrivateMessageUpdateForm {
Expand Down
Loading

0 comments on commit 2578a85

Please sign in to comment.