create_tombstone,
fetch_webfinger_url,
fetcher::get_or_fetch_and_upsert_remote_user,
+ shared_inbox::do_announce,
ActorType,
ApubLikeableType,
ApubObjectType,
context,
link::Mention,
object::{kind::NoteType, properties::ObjectProperties, Note, Tombstone},
+ Activity,
+ Base,
};
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 log::debug;
-use serde::Deserialize;
+use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
pub struct CommentQuery {
// TODO this failed because a mention on a post that wasn't on this server yet. Has to do with
// fetching replytos
+ dbg!(&post_ap_id);
let post = Post::read_from_apub_id(&conn, &post_ap_id)?;
Ok(CommentForm {
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- insert_activity(&conn, creator.id, &create, true)?;
-
- send_activity(&create, creator, maa.inboxes)?;
+ Comment::send_comment_activity(&creator, &conn, &community, create)?;
Ok(())
}
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- insert_activity(&conn, creator.id, &update, true)?;
-
- send_activity(&update, creator, maa.inboxes)?;
+ Comment::send_comment_activity(&creator, &conn, &community, update)?;
Ok(())
}
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- insert_activity(&conn, creator.id, &delete, true)?;
-
- send_activity(&delete, creator, community.get_follower_inboxes(&conn)?)?;
+ Comment::send_comment_activity(&creator, &conn, &community, delete)?;
Ok(())
}
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(delete)?;
- insert_activity(&conn, creator.id, &undo, true)?;
-
- send_activity(&undo, creator, community.get_follower_inboxes(&conn)?)?;
+ Comment::send_comment_activity(&creator, &conn, &community, undo)?;
Ok(())
}
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(note)?;
- insert_activity(&conn, mod_.id, &remove, true)?;
-
- send_activity(&remove, mod_, community.get_follower_inboxes(&conn)?)?;
+ Comment::send_comment_activity(&mod_, &conn, &community, remove)?;
Ok(())
}
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(remove)?;
- insert_activity(&conn, mod_.id, &undo, true)?;
-
- send_activity(&undo, mod_, community.get_follower_inboxes(&conn)?)?;
+ Comment::send_comment_activity(&mod_, &conn, &community, undo)?;
Ok(())
}
}
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- insert_activity(&conn, creator.id, &like, true)?;
-
- send_activity(&like, creator, community.get_follower_inboxes(&conn)?)?;
+ Comment::send_comment_activity(&creator, &conn, &community, like)?;
Ok(())
}
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(note)?;
- insert_activity(&conn, creator.id, &dislike, true)?;
-
- send_activity(&dislike, creator, community.get_follower_inboxes(&conn)?)?;
+ Comment::send_comment_activity(&creator, &conn, &community, dislike)?;
Ok(())
}
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(like)?;
- insert_activity(&conn, creator.id, &undo, true)?;
-
- send_activity(&undo, creator, community.get_follower_inboxes(&conn)?)?;
+ Comment::send_comment_activity(&creator, &conn, &community, undo)?;
Ok(())
}
}
tags,
})
}
+
+impl Comment {
+ fn send_comment_activity<A>(
+ creator: &User_,
+ conn: &PgConnection,
+ community: &Community,
+ activity: A,
+ ) -> Result<(), Error>
+ where
+ A: Activity + Base + Serialize + Debug,
+ {
+ insert_activity(&conn, creator.id, &activity, true)?;
+
+ // if this is a local community, we need to do an announce from the community instead
+ if community.local {
+ do_announce(activity, &community.actor_id, &creator.actor_id, conn)?;
+ } else {
+ send_activity(&activity, creator, vec![community.get_shared_inbox_url()])?;
+ }
+ Ok(())
+ }
+}
use crate::{
apub::{
+ activities::{populate_object_props, send_activity},
extensions::signatures::verify,
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
ActorType,
},
routes::{ChatServerParam, DbPoolParam},
};
-use activitystreams::activity::{Follow, Undo, Update, Create, Delete, Remove};
+use activitystreams::{
+ activity::{Activity, Announce, Create, Delete, Follow, Remove, Undo, Update},
+ Base,
+ BaseBox,
+};
use actix_web::{web, HttpRequest, HttpResponse, Result};
use diesel::PgConnection;
use failure::{Error, _core::fmt::Debug};
use log::debug;
use serde::{Deserialize, Serialize};
-use activitystreams::activity::{Activity, Announce};
-use activitystreams::Base;
-use crate::apub::activities::{populate_object_props, send_activity};
-use activitystreams::BaseBox;
#[serde(untagged)]
#[derive(Deserialize, Debug)]
.to_owned()
.into_concrete::<Follow>()?,
),
- _ => todo!()
+ _ => todo!(),
}
}
}
verify(&request, &user)?;
match input {
- CommunityAcceptedObjects::Follow(f) => {
- handle_follow(&f, &user, &community, &conn)
- }
+ CommunityAcceptedObjects::Follow(f) => handle_follow(&f, &user, &community, &conn),
CommunityAcceptedObjects::Undo(u) => {
// TODO: if this is an undo<remove> or undo<delete>, we need to announce it instead
- handle_undo_follow(&u, &user, &community, &conn)
+ handle_undo_follow(&u, &user, &community, &conn)
}
// TODO: we should be able to handle all this with a single wildcard match, but i dont see how
// to get the value from that
- CommunityAcceptedObjects::Create(c) => {
- do_announce(c, &request, &community, &conn, chat_server)
- }
- CommunityAcceptedObjects::Update(u) => {
- do_announce(u, &request, &community, &conn, chat_server)
- }
- CommunityAcceptedObjects::Delete(d) => {
- do_announce(d, &request, &community, &conn, chat_server)
- }
- CommunityAcceptedObjects::Remove(r) => {
- do_announce(r, &request, &community, &conn, chat_server)
- }
+ CommunityAcceptedObjects::Create(c) => do_announce(c, &request, &community, &conn, chat_server),
+ CommunityAcceptedObjects::Update(u) => do_announce(u, &request, &community, &conn, chat_server),
+ CommunityAcceptedObjects::Delete(d) => do_announce(d, &request, &community, &conn, chat_server),
+ CommunityAcceptedObjects::Remove(r) => do_announce(r, &request, &community, &conn, chat_server),
}
}
let mut announce = Announce::default();
populate_object_props(
&mut announce.object_props,
- vec!(community.get_followers_url()),
+ vec![community.get_followers_url()],
&format!("{}/announce/{}", community.actor_id, uuid::Uuid::new_v4()),
)?;
announce
insert_activity(&conn, -1, &announce, true)?;
- send_activity(
- &announce,
- community,
- community.get_follower_inboxes(&conn)?,
- )?;
+ send_activity(&announce, community, community.get_follower_inboxes(&conn)?)?;
Ok(HttpResponse::Ok().finish())
}
extensions::page_extension::PageExtension,
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
get_apub_protocol_string,
+ shared_inbox::do_announce,
ActorType,
ApubLikeableType,
ApubObjectType,
routes::DbPoolParam,
Settings,
};
-use activitystreams::{activity::{Create, Delete, Dislike, Like, Remove, Undo, Update}, context, object::{kind::PageType, properties::ObjectProperties, AnyImage, Image, Page, Tombstone}, BaseBox, Activity, Base};
+use activitystreams::{
+ activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
+ context,
+ object::{kind::PageType, properties::ObjectProperties, AnyImage, Image, Page, Tombstone},
+ Activity,
+ Base,
+ BaseBox,
+};
use activitystreams_ext::Ext1;
use actix_web::{body::Body, web::Path, HttpResponse, Result};
use diesel::PgConnection;
-use failure::Error;
+use failure::{Error, _core::fmt::Debug};
use serde::{Deserialize, Serialize};
-use crate::apub::shared_inbox::do_announce;
-use failure::_core::fmt::Debug;
#[derive(Deserialize)]
pub struct PostQuery {
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(BaseBox::from_concrete(page)?)?;
- insert_activity(&conn, creator.id, &create, true)?;
-
- Post::send_post(creator, conn, &community, create)?;
+ Post::send_post_activity(creator, conn, &community, create)?;
Ok(())
}
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(BaseBox::from_concrete(page)?)?;
- insert_activity(&conn, creator.id, &update, true)?;
-
- Post::send_post(creator, conn, &community, update)?;
+ Post::send_post_activity(creator, conn, &community, update)?;
Ok(())
}
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(BaseBox::from_concrete(page)?)?;
- insert_activity(&conn, self.creator_id, &delete, true)?;
-
let community = Community::read(conn, self.community_id)?;
- Post::send_post(creator, conn, &community, delete)?;
+ Post::send_post_activity(creator, conn, &community, delete)?;
Ok(())
}
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(delete)?;
- insert_activity(&conn, self.creator_id, &undo, true)?;
-
let community = Community::read(conn, self.community_id)?;
- Post::send_post(creator, conn, &community, undo)?;
+ Post::send_post_activity(creator, conn, &community, undo)?;
Ok(())
}
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(BaseBox::from_concrete(page)?)?;
- insert_activity(&conn, mod_.id, &remove, true)?;
-
let community = Community::read(conn, self.community_id)?;
- Post::send_post(mod_, conn, &community, remove)?;
+ Post::send_post_activity(mod_, conn, &community, remove)?;
Ok(())
}
fn send_undo_remove(&self, mod_: &User_, conn: &PgConnection) -> Result<(), Error> {
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(remove)?;
- insert_activity(&conn, mod_.id, &undo, true)?;
-
let community = Community::read(conn, self.community_id)?;
- Post::send_post(mod_, conn, &community, undo)?;
+ Post::send_post_activity(mod_, conn, &community, undo)?;
Ok(())
}
}
-
impl ApubLikeableType for Post {
fn send_like(&self, creator: &User_, conn: &PgConnection) -> Result<(), Error> {
let page = self.to_apub(conn)?;
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(BaseBox::from_concrete(page)?)?;
- insert_activity(&conn, creator.id, &like, true)?;
-
- send_activity(&like, creator, vec!(community.get_inbox_url()))?;
+ Post::send_post_activity(&creator, &conn, &community, like)?;
Ok(())
}
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(BaseBox::from_concrete(page)?)?;
- insert_activity(&conn, creator.id, &dislike, true)?;
-
- send_activity(&dislike, creator, vec!(community.get_inbox_url()))?;
+ Post::send_post_activity(&creator, &conn, &community, dislike)?;
Ok(())
}
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(like)?;
- insert_activity(&conn, creator.id, &undo, true)?;
-
- send_activity(&undo, creator, vec!(community.get_inbox_url()))?;
+ Post::send_post_activity(&creator, &conn, &community, undo)?;
Ok(())
}
}
impl Post {
- fn send_post<A>(creator: &User_, conn: &PgConnection, community: &Community, activity: A) -> Result<(), Error>
- where
- A: Activity + Base + Serialize + Debug {
+ fn send_post_activity<A>(
+ creator: &User_,
+ conn: &PgConnection,
+ community: &Community,
+ activity: A,
+ ) -> Result<(), Error>
+ where
+ A: Activity + Base + Serialize + Debug,
+ {
insert_activity(&conn, creator.id, &activity, true)?;
// if this is a local community, we need to do an announce from the community instead
if community.local {
do_announce(activity, &community.actor_id, &creator.actor_id, conn)?;
} else {
- send_activity(
- &activity,
- creator,
- vec![community.get_shared_inbox_url()],
- )?;
+ send_activity(&activity, creator, vec![community.get_shared_inbox_url()])?;
}
Ok(())
}
post::PostResponse,
},
apub::{
+ activities::{populate_object_props, send_activity},
extensions::signatures::verify,
- fetcher::get_or_fetch_and_upsert_remote_user,
+ fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
+ ActorType,
FromApub,
GroupExt,
PageExt,
UserOperation,
},
};
-use activitystreams::{activity::{Create, Delete, Dislike, Like, Remove, Undo, Update}, object::Note, BaseBox, Base, Activity};
+use activitystreams::{
+ activity::{Announce, Create, Delete, Dislike, Like, Remove, Undo, Update},
+ object::Note,
+ Activity,
+ Base,
+ BaseBox,
+};
use actix_web::{web, HttpRequest, HttpResponse, Result};
use diesel::PgConnection;
use failure::{Error, _core::fmt::Debug};
use log::debug;
use serde::{Deserialize, Serialize};
-use crate::apub::fetcher::get_or_fetch_and_upsert_remote_community;
-use crate::apub::activities::{populate_object_props, send_activity};
-use crate::apub::ActorType;
-use activitystreams::activity::Announce;
#[serde(untagged)]
#[derive(Serialize, Deserialize, Debug)]
SharedAcceptedObjects::Remove(r) => &r.object_props,
SharedAcceptedObjects::Announce(a) => &a.object_props,
};
- oprops.get_cc_xsd_any_uri().unwrap().to_owned().to_string()
+ oprops
+ .get_many_cc_xsd_any_uris()
+ .unwrap()
+ .next()
+ .unwrap()
+ .to_string()
}
}
let object = activity.object().cloned().unwrap();
let sender = &activity.sender();
let cc = &activity.cc();
+ // TODO: this is hacky, we should probably send the community id directly somehow
+ let to = cc.replace("/followers", "");
match get_or_fetch_and_upsert_remote_user(&sender.to_string(), &conn) {
Ok(u) => verify(&request, &u),
Err(_) => {
let c = get_or_fetch_and_upsert_remote_community(&sender.to_string(), &conn)?;
verify(&request, &c)
- },
+ }
}?;
match (activity, object.kind()) {
(SharedAcceptedObjects::Create(c), Some("Page")) => {
// TODO: first check that it is addressed to a local community
receive_create_post(&c, &conn, chat_server)?;
- do_announce(*c, cc, sender, conn)
+ do_announce(*c, &to, sender, conn)
}
(SharedAcceptedObjects::Update(u), Some("Page")) => {
receive_update_post(&u, &conn, chat_server)?;
- do_announce(*u, &cc, &sender, conn)
+ do_announce(*u, &to, &sender, conn)
}
(SharedAcceptedObjects::Like(l), Some("Page")) => {
receive_like_post(&l, &conn, chat_server)?;
- do_announce(*l, &cc, &sender, conn)
+ do_announce(*l, &to, &sender, conn)
}
(SharedAcceptedObjects::Dislike(d), Some("Page")) => {
receive_dislike_post(&d, &conn, chat_server)?;
- do_announce(*d, &cc, &sender, conn)
+ do_announce(*d, &to, &sender, conn)
}
(SharedAcceptedObjects::Delete(d), Some("Page")) => {
receive_delete_post(&d, &conn, chat_server)?;
- do_announce(*d, &cc, &sender, conn)
+ do_announce(*d, &to, &sender, conn)
}
(SharedAcceptedObjects::Remove(r), Some("Page")) => {
receive_remove_post(&r, &conn, chat_server)?;
- do_announce(*r, &cc, &sender, conn)
+ do_announce(*r, &to, &sender, conn)
}
(SharedAcceptedObjects::Create(c), Some("Note")) => {
receive_create_comment(&c, &conn, chat_server)
conn: &PgConnection,
) -> Result<HttpResponse, Error>
where
- A: Activity + Base + Serialize,
+ A: Activity + Base + Serialize + Debug,
{
dbg!(&community_uri);
// TODO: this fails for some reason
let community = Community::read_from_actor_id(conn, &community_uri)?;
- insert_activity(&conn, -1, &activity, false)?;
+ // TODO: need to add boolean param is_local_activity
+ //insert_activity(&conn, -1, &activity, false)?;
let mut announce = Announce::default();
populate_object_props(
&mut announce.object_props,
- vec!(community.get_followers_url()),
+ vec![community.get_followers_url()],
&format!("{}/announce/{}", community.actor_id, uuid::Uuid::new_v4()),
)?;
announce
dbg!(&announce);
dbg!(&to);
- send_activity(
- &announce,
- &community,
- to,
- )?;
+ send_activity(&announce, &community, to)?;
Ok(HttpResponse::Ok().finish())
}
apub::{
comment::get_apub_comment,
community::*,
+ community_inbox::community_inbox,
post::get_apub_post,
shared_inbox::shared_inbox,
user::*,
settings::Settings,
};
use actix_web::*;
-use crate::apub::community_inbox::community_inbox;
pub fn config(cfg: &mut web::ServiceConfig) {
if Settings::get().federation.enabled {