mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-14 00:14:03 +00:00
get some more things working
This commit is contained in:
parent
ce0a37cdf1
commit
8f9bd1fef7
5 changed files with 112 additions and 120 deletions
|
@ -6,6 +6,7 @@ use crate::{
|
||||||
create_tombstone,
|
create_tombstone,
|
||||||
fetch_webfinger_url,
|
fetch_webfinger_url,
|
||||||
fetcher::get_or_fetch_and_upsert_remote_user,
|
fetcher::get_or_fetch_and_upsert_remote_user,
|
||||||
|
shared_inbox::do_announce,
|
||||||
ActorType,
|
ActorType,
|
||||||
ApubLikeableType,
|
ApubLikeableType,
|
||||||
ApubObjectType,
|
ApubObjectType,
|
||||||
|
@ -30,13 +31,15 @@ use activitystreams::{
|
||||||
context,
|
context,
|
||||||
link::Mention,
|
link::Mention,
|
||||||
object::{kind::NoteType, properties::ObjectProperties, Note, Tombstone},
|
object::{kind::NoteType, properties::ObjectProperties, Note, Tombstone},
|
||||||
|
Activity,
|
||||||
|
Base,
|
||||||
};
|
};
|
||||||
use actix_web::{body::Body, web::Path, HttpResponse, Result};
|
use actix_web::{body::Body, web::Path, HttpResponse, Result};
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use failure::Error;
|
use failure::{Error, _core::fmt::Debug};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct CommentQuery {
|
pub struct CommentQuery {
|
||||||
|
@ -128,6 +131,7 @@ impl FromApub for CommentForm {
|
||||||
|
|
||||||
// TODO this failed because a mention on a post that wasn't on this server yet. Has to do with
|
// TODO this failed because a mention on a post that wasn't on this server yet. Has to do with
|
||||||
// fetching replytos
|
// fetching replytos
|
||||||
|
dbg!(&post_ap_id);
|
||||||
let post = Post::read_from_apub_id(&conn, &post_ap_id)?;
|
let post = Post::read_from_apub_id(&conn, &post_ap_id)?;
|
||||||
|
|
||||||
Ok(CommentForm {
|
Ok(CommentForm {
|
||||||
|
@ -175,9 +179,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(note)?;
|
.set_object_base_box(note)?;
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &create, true)?;
|
Comment::send_comment_activity(&creator, &conn, &community, create)?;
|
||||||
|
|
||||||
send_activity(&create, creator, maa.inboxes)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,9 +204,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(note)?;
|
.set_object_base_box(note)?;
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &update, true)?;
|
Comment::send_comment_activity(&creator, &conn, &community, update)?;
|
||||||
|
|
||||||
send_activity(&update, creator, maa.inboxes)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,9 +226,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(note)?;
|
.set_object_base_box(note)?;
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &delete, true)?;
|
Comment::send_comment_activity(&creator, &conn, &community, delete)?;
|
||||||
|
|
||||||
send_activity(&delete, creator, community.get_follower_inboxes(&conn)?)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,9 +266,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(delete)?;
|
.set_object_base_box(delete)?;
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &undo, true)?;
|
Comment::send_comment_activity(&creator, &conn, &community, undo)?;
|
||||||
|
|
||||||
send_activity(&undo, creator, community.get_follower_inboxes(&conn)?)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,9 +288,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||||
.set_object_base_box(note)?;
|
.set_object_base_box(note)?;
|
||||||
|
|
||||||
insert_activity(&conn, mod_.id, &remove, true)?;
|
Comment::send_comment_activity(&mod_, &conn, &community, remove)?;
|
||||||
|
|
||||||
send_activity(&remove, mod_, community.get_follower_inboxes(&conn)?)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,9 +327,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||||
.set_object_base_box(remove)?;
|
.set_object_base_box(remove)?;
|
||||||
|
|
||||||
insert_activity(&conn, mod_.id, &undo, true)?;
|
Comment::send_comment_activity(&mod_, &conn, &community, undo)?;
|
||||||
|
|
||||||
send_activity(&undo, mod_, community.get_follower_inboxes(&conn)?)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -358,9 +350,7 @@ impl ApubLikeableType for Comment {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(note)?;
|
.set_object_base_box(note)?;
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &like, true)?;
|
Comment::send_comment_activity(&creator, &conn, &community, like)?;
|
||||||
|
|
||||||
send_activity(&like, creator, community.get_follower_inboxes(&conn)?)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,9 +371,7 @@ impl ApubLikeableType for Comment {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(note)?;
|
.set_object_base_box(note)?;
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &dislike, true)?;
|
Comment::send_comment_activity(&creator, &conn, &community, dislike)?;
|
||||||
|
|
||||||
send_activity(&dislike, creator, community.get_follower_inboxes(&conn)?)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,9 +408,7 @@ impl ApubLikeableType for Comment {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(like)?;
|
.set_object_base_box(like)?;
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &undo, true)?;
|
Comment::send_comment_activity(&creator, &conn, &community, undo)?;
|
||||||
|
|
||||||
send_activity(&undo, creator, community.get_follower_inboxes(&conn)?)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -480,3 +466,25 @@ fn collect_non_local_mentions_and_addresses(
|
||||||
tags,
|
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(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
apub::{
|
apub::{
|
||||||
|
activities::{populate_object_props, send_activity},
|
||||||
extensions::signatures::verify,
|
extensions::signatures::verify,
|
||||||
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
|
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
|
||||||
ActorType,
|
ActorType,
|
||||||
|
@ -12,16 +13,16 @@ use crate::{
|
||||||
},
|
},
|
||||||
routes::{ChatServerParam, DbPoolParam},
|
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 actix_web::{web, HttpRequest, HttpResponse, Result};
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use failure::{Error, _core::fmt::Debug};
|
use failure::{Error, _core::fmt::Debug};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
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)]
|
#[serde(untagged)]
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
|
@ -46,7 +47,7 @@ impl CommunityAcceptedObjects {
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Follow>()?,
|
.into_concrete::<Follow>()?,
|
||||||
),
|
),
|
||||||
_ => todo!()
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,27 +93,17 @@ pub async fn community_inbox(
|
||||||
verify(&request, &user)?;
|
verify(&request, &user)?;
|
||||||
|
|
||||||
match input {
|
match input {
|
||||||
CommunityAcceptedObjects::Follow(f) => {
|
CommunityAcceptedObjects::Follow(f) => handle_follow(&f, &user, &community, &conn),
|
||||||
handle_follow(&f, &user, &community, &conn)
|
|
||||||
}
|
|
||||||
CommunityAcceptedObjects::Undo(u) => {
|
CommunityAcceptedObjects::Undo(u) => {
|
||||||
// TODO: if this is an undo<remove> or undo<delete>, we need to announce it instead
|
// 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
|
// 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
|
// to get the value from that
|
||||||
CommunityAcceptedObjects::Create(c) => {
|
CommunityAcceptedObjects::Create(c) => do_announce(c, &request, &community, &conn, chat_server),
|
||||||
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::Update(u) => {
|
CommunityAcceptedObjects::Remove(r) => do_announce(r, &request, &community, &conn, chat_server),
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +176,7 @@ where
|
||||||
let mut announce = Announce::default();
|
let mut announce = Announce::default();
|
||||||
populate_object_props(
|
populate_object_props(
|
||||||
&mut announce.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()),
|
&format!("{}/announce/{}", community.actor_id, uuid::Uuid::new_v4()),
|
||||||
)?;
|
)?;
|
||||||
announce
|
announce
|
||||||
|
@ -195,11 +186,7 @@ where
|
||||||
|
|
||||||
insert_activity(&conn, -1, &announce, true)?;
|
insert_activity(&conn, -1, &announce, true)?;
|
||||||
|
|
||||||
send_activity(
|
send_activity(&announce, community, community.get_follower_inboxes(&conn)?)?;
|
||||||
&announce,
|
|
||||||
community,
|
|
||||||
community.get_follower_inboxes(&conn)?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::{
|
||||||
extensions::page_extension::PageExtension,
|
extensions::page_extension::PageExtension,
|
||||||
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
|
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
|
||||||
get_apub_protocol_string,
|
get_apub_protocol_string,
|
||||||
|
shared_inbox::do_announce,
|
||||||
ActorType,
|
ActorType,
|
||||||
ApubLikeableType,
|
ApubLikeableType,
|
||||||
ApubObjectType,
|
ApubObjectType,
|
||||||
|
@ -25,14 +26,19 @@ use crate::{
|
||||||
routes::DbPoolParam,
|
routes::DbPoolParam,
|
||||||
Settings,
|
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 activitystreams_ext::Ext1;
|
||||||
use actix_web::{body::Body, web::Path, HttpResponse, Result};
|
use actix_web::{body::Body, web::Path, HttpResponse, Result};
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use failure::Error;
|
use failure::{Error, _core::fmt::Debug};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use crate::apub::shared_inbox::do_announce;
|
|
||||||
use failure::_core::fmt::Debug;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct PostQuery {
|
pub struct PostQuery {
|
||||||
|
@ -236,9 +242,7 @@ impl ApubObjectType for Post {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &create, true)?;
|
Post::send_post_activity(creator, conn, &community, create)?;
|
||||||
|
|
||||||
Post::send_post(creator, conn, &community, create)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,9 +263,7 @@ impl ApubObjectType for Post {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &update, true)?;
|
Post::send_post_activity(creator, conn, &community, update)?;
|
||||||
|
|
||||||
Post::send_post(creator, conn, &community, update)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,11 +284,9 @@ impl ApubObjectType for Post {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||||
|
|
||||||
insert_activity(&conn, self.creator_id, &delete, true)?;
|
|
||||||
|
|
||||||
let community = Community::read(conn, self.community_id)?;
|
let community = Community::read(conn, self.community_id)?;
|
||||||
|
|
||||||
Post::send_post(creator, conn, &community, delete)?;
|
Post::send_post_activity(creator, conn, &community, delete)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,10 +323,8 @@ impl ApubObjectType for Post {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(delete)?;
|
.set_object_base_box(delete)?;
|
||||||
|
|
||||||
insert_activity(&conn, self.creator_id, &undo, true)?;
|
|
||||||
|
|
||||||
let community = Community::read(conn, self.community_id)?;
|
let community = Community::read(conn, self.community_id)?;
|
||||||
Post::send_post(creator, conn, &community, undo)?;
|
Post::send_post_activity(creator, conn, &community, undo)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,11 +345,9 @@ impl ApubObjectType for Post {
|
||||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||||
|
|
||||||
insert_activity(&conn, mod_.id, &remove, true)?;
|
|
||||||
|
|
||||||
let community = Community::read(conn, self.community_id)?;
|
let community = Community::read(conn, self.community_id)?;
|
||||||
|
|
||||||
Post::send_post(mod_, conn, &community, remove)?;
|
Post::send_post_activity(mod_, conn, &community, remove)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn send_undo_remove(&self, mod_: &User_, conn: &PgConnection) -> Result<(), Error> {
|
fn send_undo_remove(&self, mod_: &User_, conn: &PgConnection) -> Result<(), Error> {
|
||||||
|
@ -386,15 +382,12 @@ impl ApubObjectType for Post {
|
||||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||||
.set_object_base_box(remove)?;
|
.set_object_base_box(remove)?;
|
||||||
|
|
||||||
insert_activity(&conn, mod_.id, &undo, true)?;
|
|
||||||
|
|
||||||
let community = Community::read(conn, self.community_id)?;
|
let community = Community::read(conn, self.community_id)?;
|
||||||
Post::send_post(mod_, conn, &community, undo)?;
|
Post::send_post_activity(mod_, conn, &community, undo)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl ApubLikeableType for Post {
|
impl ApubLikeableType for Post {
|
||||||
fn send_like(&self, creator: &User_, conn: &PgConnection) -> Result<(), Error> {
|
fn send_like(&self, creator: &User_, conn: &PgConnection) -> Result<(), Error> {
|
||||||
let page = self.to_apub(conn)?;
|
let page = self.to_apub(conn)?;
|
||||||
|
@ -412,9 +405,7 @@ impl ApubLikeableType for Post {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &like, true)?;
|
Post::send_post_activity(&creator, &conn, &community, like)?;
|
||||||
|
|
||||||
send_activity(&like, creator, vec!(community.get_inbox_url()))?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,9 +425,7 @@ impl ApubLikeableType for Post {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &dislike, true)?;
|
Post::send_post_activity(&creator, &conn, &community, dislike)?;
|
||||||
|
|
||||||
send_activity(&dislike, creator, vec!(community.get_inbox_url()))?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,28 +461,28 @@ impl ApubLikeableType for Post {
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||||
.set_object_base_box(like)?;
|
.set_object_base_box(like)?;
|
||||||
|
|
||||||
insert_activity(&conn, creator.id, &undo, true)?;
|
Post::send_post_activity(&creator, &conn, &community, undo)?;
|
||||||
|
|
||||||
send_activity(&undo, creator, vec!(community.get_inbox_url()))?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Post {
|
impl Post {
|
||||||
fn send_post<A>(creator: &User_, conn: &PgConnection, community: &Community, activity: A) -> Result<(), Error>
|
fn send_post_activity<A>(
|
||||||
|
creator: &User_,
|
||||||
|
conn: &PgConnection,
|
||||||
|
community: &Community,
|
||||||
|
activity: A,
|
||||||
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
A: Activity + Base + Serialize + Debug {
|
A: Activity + Base + Serialize + Debug,
|
||||||
|
{
|
||||||
insert_activity(&conn, creator.id, &activity, true)?;
|
insert_activity(&conn, creator.id, &activity, true)?;
|
||||||
|
|
||||||
// if this is a local community, we need to do an announce from the community instead
|
// if this is a local community, we need to do an announce from the community instead
|
||||||
if community.local {
|
if community.local {
|
||||||
do_announce(activity, &community.actor_id, &creator.actor_id, conn)?;
|
do_announce(activity, &community.actor_id, &creator.actor_id, conn)?;
|
||||||
} else {
|
} else {
|
||||||
send_activity(
|
send_activity(&activity, creator, vec![community.get_shared_inbox_url()])?;
|
||||||
&activity,
|
|
||||||
creator,
|
|
||||||
vec![community.get_shared_inbox_url()],
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,10 @@ use crate::{
|
||||||
post::PostResponse,
|
post::PostResponse,
|
||||||
},
|
},
|
||||||
apub::{
|
apub::{
|
||||||
|
activities::{populate_object_props, send_activity},
|
||||||
extensions::signatures::verify,
|
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,
|
FromApub,
|
||||||
GroupExt,
|
GroupExt,
|
||||||
PageExt,
|
PageExt,
|
||||||
|
@ -30,16 +32,18 @@ use crate::{
|
||||||
UserOperation,
|
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 actix_web::{web, HttpRequest, HttpResponse, Result};
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use failure::{Error, _core::fmt::Debug};
|
use failure::{Error, _core::fmt::Debug};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
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)]
|
#[serde(untagged)]
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
@ -92,7 +96,12 @@ impl SharedAcceptedObjects {
|
||||||
SharedAcceptedObjects::Remove(r) => &r.object_props,
|
SharedAcceptedObjects::Remove(r) => &r.object_props,
|
||||||
SharedAcceptedObjects::Announce(a) => &a.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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,40 +121,42 @@ pub async fn shared_inbox(
|
||||||
let object = activity.object().cloned().unwrap();
|
let object = activity.object().cloned().unwrap();
|
||||||
let sender = &activity.sender();
|
let sender = &activity.sender();
|
||||||
let cc = &activity.cc();
|
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) {
|
match get_or_fetch_and_upsert_remote_user(&sender.to_string(), &conn) {
|
||||||
Ok(u) => verify(&request, &u),
|
Ok(u) => verify(&request, &u),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let c = get_or_fetch_and_upsert_remote_community(&sender.to_string(), &conn)?;
|
let c = get_or_fetch_and_upsert_remote_community(&sender.to_string(), &conn)?;
|
||||||
verify(&request, &c)
|
verify(&request, &c)
|
||||||
},
|
}
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
match (activity, object.kind()) {
|
match (activity, object.kind()) {
|
||||||
(SharedAcceptedObjects::Create(c), Some("Page")) => {
|
(SharedAcceptedObjects::Create(c), Some("Page")) => {
|
||||||
// TODO: first check that it is addressed to a local community
|
// TODO: first check that it is addressed to a local community
|
||||||
receive_create_post(&c, &conn, chat_server)?;
|
receive_create_post(&c, &conn, chat_server)?;
|
||||||
do_announce(*c, cc, sender, conn)
|
do_announce(*c, &to, sender, conn)
|
||||||
}
|
}
|
||||||
(SharedAcceptedObjects::Update(u), Some("Page")) => {
|
(SharedAcceptedObjects::Update(u), Some("Page")) => {
|
||||||
receive_update_post(&u, &conn, chat_server)?;
|
receive_update_post(&u, &conn, chat_server)?;
|
||||||
do_announce(*u, &cc, &sender, conn)
|
do_announce(*u, &to, &sender, conn)
|
||||||
}
|
}
|
||||||
(SharedAcceptedObjects::Like(l), Some("Page")) => {
|
(SharedAcceptedObjects::Like(l), Some("Page")) => {
|
||||||
receive_like_post(&l, &conn, chat_server)?;
|
receive_like_post(&l, &conn, chat_server)?;
|
||||||
do_announce(*l, &cc, &sender, conn)
|
do_announce(*l, &to, &sender, conn)
|
||||||
}
|
}
|
||||||
(SharedAcceptedObjects::Dislike(d), Some("Page")) => {
|
(SharedAcceptedObjects::Dislike(d), Some("Page")) => {
|
||||||
receive_dislike_post(&d, &conn, chat_server)?;
|
receive_dislike_post(&d, &conn, chat_server)?;
|
||||||
do_announce(*d, &cc, &sender, conn)
|
do_announce(*d, &to, &sender, conn)
|
||||||
}
|
}
|
||||||
(SharedAcceptedObjects::Delete(d), Some("Page")) => {
|
(SharedAcceptedObjects::Delete(d), Some("Page")) => {
|
||||||
receive_delete_post(&d, &conn, chat_server)?;
|
receive_delete_post(&d, &conn, chat_server)?;
|
||||||
do_announce(*d, &cc, &sender, conn)
|
do_announce(*d, &to, &sender, conn)
|
||||||
}
|
}
|
||||||
(SharedAcceptedObjects::Remove(r), Some("Page")) => {
|
(SharedAcceptedObjects::Remove(r), Some("Page")) => {
|
||||||
receive_remove_post(&r, &conn, chat_server)?;
|
receive_remove_post(&r, &conn, chat_server)?;
|
||||||
do_announce(*r, &cc, &sender, conn)
|
do_announce(*r, &to, &sender, conn)
|
||||||
}
|
}
|
||||||
(SharedAcceptedObjects::Create(c), Some("Note")) => {
|
(SharedAcceptedObjects::Create(c), Some("Note")) => {
|
||||||
receive_create_comment(&c, &conn, chat_server)
|
receive_create_comment(&c, &conn, chat_server)
|
||||||
|
@ -1505,18 +1516,19 @@ pub fn do_announce<A>(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
) -> Result<HttpResponse, Error>
|
) -> Result<HttpResponse, Error>
|
||||||
where
|
where
|
||||||
A: Activity + Base + Serialize,
|
A: Activity + Base + Serialize + Debug,
|
||||||
{
|
{
|
||||||
dbg!(&community_uri);
|
dbg!(&community_uri);
|
||||||
// TODO: this fails for some reason
|
// TODO: this fails for some reason
|
||||||
let community = Community::read_from_actor_id(conn, &community_uri)?;
|
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();
|
let mut announce = Announce::default();
|
||||||
populate_object_props(
|
populate_object_props(
|
||||||
&mut announce.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()),
|
&format!("{}/announce/{}", community.actor_id, uuid::Uuid::new_v4()),
|
||||||
)?;
|
)?;
|
||||||
announce
|
announce
|
||||||
|
@ -1536,11 +1548,7 @@ where
|
||||||
dbg!(&announce);
|
dbg!(&announce);
|
||||||
dbg!(&to);
|
dbg!(&to);
|
||||||
|
|
||||||
send_activity(
|
send_activity(&announce, &community, to)?;
|
||||||
&announce,
|
|
||||||
&community,
|
|
||||||
to,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::{
|
||||||
apub::{
|
apub::{
|
||||||
comment::get_apub_comment,
|
comment::get_apub_comment,
|
||||||
community::*,
|
community::*,
|
||||||
|
community_inbox::community_inbox,
|
||||||
post::get_apub_post,
|
post::get_apub_post,
|
||||||
shared_inbox::shared_inbox,
|
shared_inbox::shared_inbox,
|
||||||
user::*,
|
user::*,
|
||||||
|
@ -11,7 +12,6 @@ use crate::{
|
||||||
settings::Settings,
|
settings::Settings,
|
||||||
};
|
};
|
||||||
use actix_web::*;
|
use actix_web::*;
|
||||||
use crate::apub::community_inbox::community_inbox;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
if Settings::get().federation.enabled {
|
if Settings::get().federation.enabled {
|
||||||
|
|
Loading…
Reference in a new issue