diff options
author | nutomic <nutomic@noreply.yerbamate.dev> | 2020-07-10 18:15:41 +0000 |
---|---|---|
committer | dessalines <dessalines@noreply.yerbamate.dev> | 2020-07-10 18:15:41 +0000 |
commit | 80aef61aed29d25099835ee4769bb8e1e363eb47 (patch) | |
tree | 8c83a360256c615db2ab749aeb29d73ae30895a0 /server/src/apub/community.rs | |
parent | debbd316c271f8867917a9eb8c4caa5c26093d66 (diff) |
Split code into cargo workspaces (#67)
More fixes
- fixed docker builds
- fixed mentions regex test
- fixed DATABASE_URL stuff
- change schema path in diesel.toml
Address review comments
- add jsonb column back into activity table
- remove authors field from cargo.toml
- adjust LEMMY_DATABASE_URL env var usage
- rename all occurences of LEMMY_DATABASE_URL to DATABASE_URL
Decouple utils and db
Split code into cargo workspaces
Co-authored-by: Felix Ableitner <me@nutomic.com>
Reviewed-on: https://yerbamate.dev/LemmyNet/lemmy/pulls/67
Diffstat (limited to 'server/src/apub/community.rs')
-rw-r--r-- | server/src/apub/community.rs | 84 |
1 files changed, 41 insertions, 43 deletions
diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs index bfc896af..8b623e71 100644 --- a/server/src/apub/community.rs +++ b/server/src/apub/community.rs @@ -7,20 +7,13 @@ use crate::{ extensions::group_extensions::GroupExtension, fetcher::get_or_fetch_and_upsert_remote_user, get_shared_inbox, + insert_activity, ActorType, FromApub, GroupExt, ToApub, }, blocking, - convert_datetime, - db::{ - activity::insert_activity, - community::{Community, CommunityForm}, - community_view::{CommunityFollowerView, CommunityModeratorView}, - user::User_, - }, - naive_now, routes::DbPoolParam, DbPool, LemmyError, @@ -44,6 +37,13 @@ use activitystreams_new::{ }; use actix_web::{body::Body, client::Client, web, HttpResponse}; use itertools::Itertools; +use lemmy_db::{ + community::{Community, CommunityForm}, + community_view::{CommunityFollowerView, CommunityModeratorView}, + naive_now, + user::User_, +}; +use lemmy_utils::convert_datetime; use serde::{Deserialize, Serialize}; use std::{fmt::Debug, str::FromStr}; @@ -462,39 +462,37 @@ pub async fn get_apub_community_followers( Ok(create_apub_response(&collection)) } -impl Community { - pub async fn do_announce<A>( - activity: A, - community: &Community, - sender: &dyn ActorType, - client: &Client, - pool: &DbPool, - ) -> Result<HttpResponse, LemmyError> - where - A: Activity + Base + Serialize + Debug, - { - let mut announce = Announce::default(); - populate_object_props( - &mut announce.object_props, - vec![community.get_followers_url()], - &format!("{}/announce/{}", community.actor_id, uuid::Uuid::new_v4()), - )?; - announce - .announce_props - .set_actor_xsd_any_uri(community.actor_id.to_owned())? - .set_object_base_box(BaseBox::from_concrete(activity)?)?; - - insert_activity(community.creator_id, announce.clone(), true, pool).await?; - - // dont send to the instance where the activity originally came from, because that would result - // in a database error (same data inserted twice) - let mut to = community.get_follower_inboxes(pool).await?; - - // this seems to be the "easiest" stable alternative for remove_item() - to.retain(|x| *x != sender.get_shared_inbox_url()); - - send_activity(client, &announce, community, to).await?; - - Ok(HttpResponse::Ok().finish()) - } +pub async fn do_announce<A>( + activity: A, + community: &Community, + sender: &dyn ActorType, + client: &Client, + pool: &DbPool, +) -> Result<HttpResponse, LemmyError> +where + A: Activity + Base + Serialize + Debug, +{ + let mut announce = Announce::default(); + populate_object_props( + &mut announce.object_props, + vec![community.get_followers_url()], + &format!("{}/announce/{}", community.actor_id, uuid::Uuid::new_v4()), + )?; + announce + .announce_props + .set_actor_xsd_any_uri(community.actor_id.to_owned())? + .set_object_base_box(BaseBox::from_concrete(activity)?)?; + + insert_activity(community.creator_id, announce.clone(), true, pool).await?; + + // dont send to the instance where the activity originally came from, because that would result + // in a database error (same data inserted twice) + let mut to = community.get_follower_inboxes(pool).await?; + + // this seems to be the "easiest" stable alternative for remove_item() + to.retain(|x| *x != sender.get_shared_inbox_url()); + + send_activity(client, &announce, community, to).await?; + + Ok(HttpResponse::Ok().finish()) } |