summaryrefslogtreecommitdiffstats
path: root/server/src/apub/community.rs
diff options
context:
space:
mode:
authorFelix Ableitner <me@nutomic.com>2020-05-30 19:44:50 +0200
committerFelix Ableitner <me@nutomic.com>2020-05-30 19:44:50 +0200
commitc34cc46c2df4c44060d8badb74a8fb578933a1fd (patch)
tree1f26baa07d7f562832557371b71935a8d787c4dc /server/src/apub/community.rs
parent52206998aaff0a32e97c250cadd537c11699398f (diff)
get it working (mostly)
Diffstat (limited to 'server/src/apub/community.rs')
-rw-r--r--server/src/apub/community.rs50
1 files changed, 47 insertions, 3 deletions
diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs
index 1ba41da4..6ed10f3b 100644
--- a/server/src/apub/community.rs
+++ b/server/src/apub/community.rs
@@ -23,20 +23,22 @@ use crate::{
routes::DbPoolParam,
};
use activitystreams::{
- activity::{Accept, Delete, Follow, Remove, Undo},
+ activity::{Accept, Announce, Delete, Follow, Remove, Undo},
actor::{kind::GroupType, properties::ApActorProperties, Group},
collection::UnorderedCollection,
context,
endpoint::EndpointProperties,
object::{properties::ObjectProperties, Tombstone},
+ Activity,
+ Base,
BaseBox,
};
use activitystreams_ext::Ext3;
use actix_web::{body::Body, web::Path, HttpResponse, Result};
use diesel::PgConnection;
-use failure::Error;
+use failure::{Error, _core::fmt::Debug};
use itertools::Itertools;
-use serde::Deserialize;
+use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
pub struct CommunityQuery {
@@ -378,3 +380,45 @@ pub async fn get_apub_community_followers(
.set_total_items(community_followers.len() as u64)?;
Ok(create_apub_response(&collection))
}
+
+impl Community {
+ pub fn do_announce<A>(
+ activity: A,
+ // TODO: maybe pass in the community object
+ community_uri: &str,
+ sender: &str,
+ conn: &PgConnection,
+ is_local_activity: bool,
+ ) -> Result<HttpResponse, Error>
+ where
+ A: Activity + Base + Serialize + Debug,
+ {
+ let community = Community::read_from_actor_id(conn, &community_uri)?;
+
+ insert_activity(&conn, -1, &activity, is_local_activity)?;
+
+ 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(&conn, -1, &announce, true)?;
+
+ // 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(&conn)?;
+ let sending_user = get_or_fetch_and_upsert_remote_user(&sender, conn)?;
+ // this seems to be the "easiest" stable alternative for remove_item()
+ to.retain(|x| *x != sending_user.get_shared_inbox_url());
+
+ send_activity(&announce, &community, to)?;
+
+ Ok(HttpResponse::Ok().finish())
+ }
+}