Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into featuredposts
Browse files Browse the repository at this point in the history
  • Loading branch information
makotech222 committed Dec 1, 2022
2 parents 2e3ef32 + 41d4852 commit 3a50f0c
Show file tree
Hide file tree
Showing 54 changed files with 391 additions and 190 deletions.
17 changes: 13 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ steps:
# when adding new clippy lints, make sure to also add them in scripts/fix-clippy.sh
- name: cargo clippy
image: rust:1.65-buster
environment:
CARGO_HOME: .cargo
commands:
- apt-get update
- apt-get -y install protobuf-compiler libprotobuf-dev
- rustup component add clippy
- cargo clippy --workspace --tests --all-targets --all-features --
-D warnings -D deprecated -D clippy::perf -D clippy::complexity
-D clippy::style -D clippy::correctness -D clippy::suspicious
-D clippy::dbg_macro -D clippy::inefficient_to_string
-D clippy::items-after-statements -D clippy::implicit_clone
-D clippy::wildcard_imports -D clippy::cast_lossless
-D clippy::manual_string_new -D clippy::redundant_closure_for_method_calls
-D clippy::manual_string_new -D clippy::redundant_closure_for_method_calls
-D clippy::unused_self
- cargo clippy --workspace --all-features -- -D clippy::unwrap_used

- name: cargo test
Expand All @@ -45,19 +47,24 @@ steps:
LEMMY_CONFIG_LOCATION: ../../config/config.hjson
RUST_BACKTRACE: 1
RUST_TEST_THREADS: 1
CARGO_HOME: .cargo
commands:
- apt-get update
- apt-get -y install --no-install-recommends postgresql-client protobuf-compiler libprotobuf-dev
- cargo test --workspace --no-fail-fast --all-features

- name: check defaults.hjson updated
image: clux/muslrust:1.64.0
environment:
CARGO_HOME: .cargo
commands:
- ./scripts/update_config_defaults.sh config/defaults_current.hjson
- diff config/defaults.hjson config/defaults_current.hjson

- name: check with different features
image: clux/muslrust:1.64.0
environment:
CARGO_HOME: .cargo
commands:
- cargo install cargo-workspaces
- cargo workspaces exec cargo check --no-default-features
Expand All @@ -70,6 +77,8 @@ steps:

- name: cargo build
image: clux/muslrust:1.64.0
environment:
CARGO_HOME: .cargo
commands:
- cargo build
- mv target/x86_64-unknown-linux-musl/debug/lemmy_server target/lemmy_server
Expand All @@ -89,7 +98,7 @@ steps:
- name: nightly build
image: plugins/docker
settings:
dockerfile: docker/dev/Dockerfile
dockerfile: docker/prod/Dockerfile
username:
from_secret: docker_username
password:
Expand Down
26 changes: 12 additions & 14 deletions Cargo.lock

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

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description = "A link aggregator for the fediverse"
license = "AGPL-3.0"
homepage = "https://join-lemmy.org/"
documentation = "https://join-lemmy.org/docs/en/index.html"
repository = "https://github.com/LemmyNet/lemmy"

[package]
name = "lemmy_server"
Expand All @@ -14,6 +15,7 @@ description.workspace = true
license.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true

[lib]
doctest = false
Expand Down Expand Up @@ -59,7 +61,7 @@ lemmy_routes = { version = "=0.16.5", path = "./crates/routes" }
lemmy_db_views = { version = "=0.16.5", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.16.5", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.16.5", path = "./crates/db_views_moderator" }
activitypub_federation = "0.3.2"
activitypub_federation = "0.3.4"
diesel = "2.0.2"
diesel_migrations = "2.0.0"
diesel-async = "0.1.1"
Expand All @@ -73,12 +75,12 @@ tracing-log = "0.1.3"
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
url = { version = "2.3.1", features = ["serde"] }
reqwest = { version = "0.11.12", features = ["json"] }
reqwest-middleware = "0.1.6"
reqwest-tracing = "0.3.1"
reqwest-middleware = "0.2.0"
reqwest-tracing = "0.4.0"
clokwerk = "0.3.5"
doku = { version = "0.20.0", features = ["url-2"] }
parking_lot = "0.12.1"
reqwest-retry = "0.1.5"
reqwest-retry = "0.2.0"
bcrypt = "0.13.0"
chrono = { version = "0.4.22", features = ["serde"], default-features = false }
serde_json = { version = "1.0.87", features = ["preserve_order"] }
Expand Down
1 change: 1 addition & 0 deletions crates/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description.workspace = true
license.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true

[lib]
name = "lemmy_api"
Expand Down
4 changes: 2 additions & 2 deletions crates/api/src/community/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use lemmy_api_common::{
community::{BlockCommunity, BlockCommunityResponse},
utils::get_local_user_view_from_jwt,
};
use lemmy_apub::protocol::activities::following::undo_follow::UndoFollowCommunity;
use lemmy_apub::protocol::activities::following::undo_follow::UndoFollow;
use lemmy_db_schema::{
source::{
community::{Community, CommunityFollower, CommunityFollowerForm},
Expand Down Expand Up @@ -53,7 +53,7 @@ impl Perform for BlockCommunity {
.await
.ok();
let community = Community::read(context.pool(), community_id).await?;
UndoFollowCommunity::send(&local_user_view.person.into(), &community.into(), context).await?;
UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await?;
} else {
CommunityBlock::unblock(context.pool(), &community_block_form)
.await
Expand Down
7 changes: 3 additions & 4 deletions crates/api/src/community/follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use lemmy_api_common::{
use lemmy_apub::{
objects::community::ApubCommunity,
protocol::activities::following::{
follow::FollowCommunity as FollowCommunityApub,
undo_follow::UndoFollowCommunity,
follow::Follow as FollowCommunityApub,
undo_follow::UndoFollow,
},
};
use lemmy_db_schema::{
Expand Down Expand Up @@ -60,8 +60,7 @@ impl Perform for FollowCommunity {
FollowCommunityApub::send(&local_user_view.person.clone().into(), &community, context)
.await?;
} else {
UndoFollowCommunity::send(&local_user_view.person.clone().into(), &community, context)
.await?;
UndoFollow::send(&local_user_view.person.clone().into(), &community, context).await?;
CommunityFollower::unfollow(context.pool(), &community_follower_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
Expand Down
1 change: 1 addition & 0 deletions crates/api_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description.workspace = true
license.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true

[lib]
name = "lemmy_api_common"
Expand Down
1 change: 1 addition & 0 deletions crates/api_crud/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description.workspace = true
license.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true

[dependencies]
lemmy_apub = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/apub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description.workspace = true
license.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true

[lib]
name = "lemmy_apub"
Expand Down
1 change: 1 addition & 0 deletions crates/apub/assets/lemmy/objects/group.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"inbox": "https://enterprise.lemmy.ml/c/tenforward/inbox",
"followers": "https://enterprise.lemmy.ml/c/tenforward/followers",
"moderators": "https://enterprise.lemmy.ml/c/tenforward/moderators",
"attributedTo": "https://enterprise.lemmy.ml/c/tenforward/moderators",
"postingRestrictedToMods": false,
"endpoints": {
"sharedInbox": "https://enterprise.lemmy.ml/inbox"
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/block/block_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl BlockUser {
SiteOrCommunity::Community(c) => {
let activity = AnnouncableActivities::BlockUser(block);
let inboxes = vec![user.shared_inbox_or_inbox()];
send_activity_in_community(activity, mod_, c, inboxes, context).await
send_activity_in_community(activity, mod_, c, inboxes, true, context).await
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/block/undo_block_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl UndoBlockUser {
}
SiteOrCommunity::Community(c) => {
let activity = AnnouncableActivities::UndoBlockUser(undo);
send_activity_in_community(activity, mod_, c, inboxes, context).await
send_activity_in_community(activity, mod_, c, inboxes, true, context).await
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/community/add_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl AddMod {

let activity = AnnouncableActivities::AddMod(add);
let inboxes = vec![added_mod.shared_inbox_or_inbox()];
send_activity_in_community(activity, actor, community, inboxes, context).await
send_activity_in_community(activity, actor, community, inboxes, true, context).await
}
}

Expand Down
51 changes: 38 additions & 13 deletions crates/apub/src/activities/community/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use crate::{
activities::send_lemmy_activity,
activity_lists::AnnouncableActivities,
local_instance,
objects::community::ApubCommunity,
objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::community::announce::AnnounceActivity,
ActorType,
};
use activitypub_federation::{core::object_id::ObjectId, traits::Actor};
use lemmy_db_schema::source::person::PersonFollower;
use lemmy_utils::error::LemmyError;
use lemmy_websocket::LemmyContext;
use url::Url;
Expand All @@ -17,22 +17,47 @@ pub mod remove_mod;
pub mod report;
pub mod update;

#[tracing::instrument(skip_all)]
pub(crate) async fn send_activity_in_community<ActorT>(
/// This function sends all activities which are happening in a community to the right inboxes.
/// For example Create/Page, Add/Mod etc, but not private messages.
///
/// Activities are sent to the community itself if it lives on another instance. If the community
/// is local, the activity is directly wrapped into Announce and sent to community followers.
/// Activities are also sent to those who follow the actor (with exception of moderation activities).
///
/// * `activity` - The activity which is being sent
/// * `actor` - The user who is sending the activity
/// * `community` - Community inside which the activity is sent
/// * `inboxes` - Any additional inboxes the activity should be sent to (for example,
/// to the user who is being promoted to moderator)
/// * `is_mod_activity` - True for things like Add/Mod, these are not sent to user followers
pub(crate) async fn send_activity_in_community(
activity: AnnouncableActivities,
actor: &ActorT,
actor: &ApubPerson,
community: &ApubCommunity,
mut inboxes: Vec<Url>,
extra_inboxes: Vec<Url>,
is_mod_action: bool,
context: &LemmyContext,
) -> Result<(), LemmyError>
where
ActorT: Actor + ActorType,
{
inboxes.push(community.shared_inbox_or_inbox());
send_lemmy_activity(context, activity.clone(), actor, inboxes, false).await?;
) -> Result<(), LemmyError> {
// send to extra_inboxes
send_lemmy_activity(context, activity.clone(), actor, extra_inboxes, false).await?;

if community.local {
AnnounceActivity::send(activity.try_into()?, community, context).await?;
// send directly to community followers
AnnounceActivity::send(activity.clone().try_into()?, community, context).await?;
} else {
// send to the community, which will then forward to followers
let inbox = vec![community.shared_inbox_or_inbox()];
send_lemmy_activity(context, activity.clone(), actor, inbox, false).await?;
}

// send to those who follow `actor`
if !is_mod_action {
let inboxes = PersonFollower::list_followers(context.pool(), actor.id)
.await?
.into_iter()
.map(|p| ApubPerson(p).shared_inbox_or_inbox())
.collect();
send_lemmy_activity(context, activity, actor, inboxes, false).await?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/community/remove_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl RemoveMod {

let activity = AnnouncableActivities::RemoveMod(remove);
let inboxes = vec![removed_mod.shared_inbox_or_inbox()];
send_activity_in_community(activity, actor, community, inboxes, context).await
send_activity_in_community(activity, actor, community, inboxes, true, context).await
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/community/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl UpdateCommunity {
};

let activity = AnnouncableActivities::UpdateCommunity(update);
send_activity_in_community(activity, actor, &community, vec![], context).await
send_activity_in_community(activity, actor, &community, vec![], true, context).await
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/create_or_update/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl CreateOrUpdateComment {
}

let activity = AnnouncableActivities::CreateOrUpdateComment(create_or_update);
send_activity_in_community(activity, actor, &community, inboxes, context).await
send_activity_in_community(activity, actor, &community, inboxes, false, context).await
}
}

Expand Down
Loading

0 comments on commit 3a50f0c

Please sign in to comment.