Merge branch 'federation' into federated_mentions
This commit is contained in:
commit
1a4f7a1415
15 changed files with 276 additions and 789 deletions
|
@ -18,19 +18,12 @@ pub fn populate_object_props(
|
|||
}
|
||||
|
||||
/// Send an activity to a list of recipients, using the correct headers etc.
|
||||
pub fn send_activity<A>(
|
||||
activity: &A,
|
||||
private_key: &str,
|
||||
sender_id: &str,
|
||||
to: Vec<String>,
|
||||
) -> Result<(), Error>
|
||||
pub fn send_activity<A>(activity: &A, actor: &dyn ActorType, to: Vec<String>) -> Result<(), Error>
|
||||
where
|
||||
A: Serialize + Debug,
|
||||
{
|
||||
let json = serde_json::to_string(&activity)?;
|
||||
debug!("Sending activitypub activity {} to {:?}", json, to);
|
||||
// TODO it needs to expand, the to field needs to expand and dedup the followers urls
|
||||
// The inbox is determined by first retrieving the target actor's JSON-LD representation and then looking up the inbox property. If a recipient is a Collection or OrderedCollection, then the server MUST dereference the collection (with the user's credentials) and discover inboxes for each item in the collection. Servers MUST limit the number of layers of indirections through collections which will be performed, which MAY be one.
|
||||
for t in to {
|
||||
let to_url = Url::parse(&t)?;
|
||||
if !is_apub_id_valid(&to_url) {
|
||||
|
@ -38,7 +31,7 @@ where
|
|||
continue;
|
||||
}
|
||||
let request = Request::post(t).header("Host", to_url.domain().unwrap());
|
||||
let signature = sign(&request, private_key, sender_id)?;
|
||||
let signature = sign(&request, actor)?;
|
||||
let res = request
|
||||
.header("Signature", signature)
|
||||
.header("Content-Type", "application/json")
|
||||
|
|
|
@ -1,5 +1,24 @@
|
|||
use super::*;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CommentQuery {
|
||||
comment_id: String,
|
||||
}
|
||||
|
||||
/// Return the post json over HTTP.
|
||||
pub async fn get_apub_comment(
|
||||
info: Path<CommentQuery>,
|
||||
db: DbPoolParam,
|
||||
) -> Result<HttpResponse<Body>, Error> {
|
||||
let id = info.comment_id.parse::<i32>()?;
|
||||
let comment = Comment::read(&&db.get()?, id)?;
|
||||
if !comment.deleted {
|
||||
Ok(create_apub_response(&comment.to_apub(&db.get().unwrap())?))
|
||||
} else {
|
||||
Ok(create_apub_tombstone_response(&comment.to_tombstone()?))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToApub for Comment {
|
||||
type Response = Note;
|
||||
|
||||
|
@ -118,21 +137,9 @@ impl ApubObjectType for Comment {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(note)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&create)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &create, true)?;
|
||||
|
||||
send_activity(
|
||||
&create,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
maa.inboxes,
|
||||
)?;
|
||||
send_activity(&create, creator, maa.inboxes)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -157,21 +164,9 @@ impl ApubObjectType for Comment {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(note)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&update)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &update, true)?;
|
||||
|
||||
send_activity(
|
||||
&update,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
maa.inboxes,
|
||||
)?;
|
||||
send_activity(&update, creator, maa.inboxes)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -193,21 +188,9 @@ impl ApubObjectType for Comment {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(note)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&delete)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &delete, true)?;
|
||||
|
||||
send_activity(
|
||||
&delete,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&delete, creator, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -247,21 +230,9 @@ impl ApubObjectType for Comment {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(delete)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&undo)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &undo, true)?;
|
||||
|
||||
send_activity(
|
||||
&undo,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&undo, creator, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -283,21 +254,9 @@ impl ApubObjectType for Comment {
|
|||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||
.set_object_base_box(note)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: mod_.id,
|
||||
data: serde_json::to_value(&remove)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, mod_.id, &remove, true)?;
|
||||
|
||||
send_activity(
|
||||
&remove,
|
||||
&mod_.private_key.as_ref().unwrap(),
|
||||
&mod_.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&remove, mod_, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -336,21 +295,9 @@ impl ApubObjectType for Comment {
|
|||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||
.set_object_base_box(remove)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: mod_.id,
|
||||
data: serde_json::to_value(&undo)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, mod_.id, &undo, true)?;
|
||||
|
||||
send_activity(
|
||||
&undo,
|
||||
&mod_.private_key.as_ref().unwrap(),
|
||||
&mod_.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&undo, mod_, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -373,21 +320,9 @@ impl ApubLikeableType for Comment {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(note)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&like)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &like, true)?;
|
||||
|
||||
send_activity(
|
||||
&like,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&like, creator, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -408,21 +343,9 @@ impl ApubLikeableType for Comment {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(note)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&dislike)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &dislike, true)?;
|
||||
|
||||
send_activity(
|
||||
&dislike,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&dislike, creator, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -459,21 +382,9 @@ impl ApubLikeableType for Comment {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(like)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&undo)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &undo, true)?;
|
||||
|
||||
send_activity(
|
||||
&undo,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&undo, creator, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,6 +79,9 @@ impl ActorType for Community {
|
|||
fn public_key(&self) -> String {
|
||||
self.public_key.to_owned().unwrap()
|
||||
}
|
||||
fn private_key(&self) -> String {
|
||||
self.private_key.to_owned().unwrap()
|
||||
}
|
||||
|
||||
/// As a local community, accept the follow request from a remote user.
|
||||
fn send_accept_follow(&self, follow: &Follow, conn: &PgConnection) -> Result<(), Error> {
|
||||
|
@ -100,21 +103,9 @@ impl ActorType for Community {
|
|||
.set_object_base_box(BaseBox::from_concrete(follow.clone())?)?;
|
||||
let to = format!("{}/inbox", actor_uri);
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: self.creator_id,
|
||||
data: serde_json::to_value(&accept)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, self.creator_id, &accept, true)?;
|
||||
|
||||
send_activity(
|
||||
&accept,
|
||||
&self.private_key.to_owned().unwrap(),
|
||||
&self.actor_id,
|
||||
vec![to],
|
||||
)?;
|
||||
send_activity(&accept, self, vec![to])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -134,24 +125,12 @@ impl ActorType for Community {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(group)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: self.creator_id,
|
||||
data: serde_json::to_value(&delete)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, self.creator_id, &delete, true)?;
|
||||
|
||||
// Note: For an accept, since it was automatic, no one pushed a button,
|
||||
// the community was the actor.
|
||||
// But for delete, the creator is the actor, and does the signing
|
||||
send_activity(
|
||||
&delete,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
self.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&delete, creator, self.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -187,24 +166,12 @@ impl ActorType for Community {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(delete)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: self.creator_id,
|
||||
data: serde_json::to_value(&undo)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, self.creator_id, &undo, true)?;
|
||||
|
||||
// Note: For an accept, since it was automatic, no one pushed a button,
|
||||
// the community was the actor.
|
||||
// But for delete, the creator is the actor, and does the signing
|
||||
send_activity(
|
||||
&undo,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
self.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&undo, creator, self.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -224,24 +191,12 @@ impl ActorType for Community {
|
|||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||
.set_object_base_box(group)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: mod_.id,
|
||||
data: serde_json::to_value(&remove)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, mod_.id, &remove, true)?;
|
||||
|
||||
// Note: For an accept, since it was automatic, no one pushed a button,
|
||||
// the community was the actor.
|
||||
// But for delete, the creator is the actor, and does the signing
|
||||
send_activity(
|
||||
&remove,
|
||||
&mod_.private_key.as_ref().unwrap(),
|
||||
&mod_.actor_id,
|
||||
self.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&remove, mod_, self.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -276,24 +231,12 @@ impl ActorType for Community {
|
|||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||
.set_object_base_box(remove)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: mod_.id,
|
||||
data: serde_json::to_value(&undo)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, mod_.id, &undo, true)?;
|
||||
|
||||
// Note: For an accept, since it was automatic, no one pushed a button,
|
||||
// the community was the actor.
|
||||
// But for remove , the creator is the actor, and does the signing
|
||||
send_activity(
|
||||
&undo,
|
||||
&mod_.private_key.as_ref().unwrap(),
|
||||
&mod_.actor_id,
|
||||
self.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&undo, mod_, self.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -340,11 +283,6 @@ impl FromApub for CommunityForm {
|
|||
let aprops = &group.base.extension;
|
||||
let public_key: &PublicKey = &group.extension.public_key;
|
||||
|
||||
let _followers_uri = Url::parse(&aprops.get_followers().unwrap().to_string())?;
|
||||
let _outbox_uri = Url::parse(&aprops.get_outbox().to_string())?;
|
||||
// TODO don't do extra fetching here
|
||||
// let _outbox = fetch_remote_object::<OrderedCollection>(&outbox_uri)?;
|
||||
// let _followers = fetch_remote_object::<UnorderedCollection>(&followers_uri)?;
|
||||
let mut creator_and_moderator_uris = oprops.get_many_attributed_to_xsd_any_uris().unwrap();
|
||||
let creator = creator_and_moderator_uris
|
||||
.next()
|
||||
|
@ -392,8 +330,7 @@ pub async fn get_apub_community_http(
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns an empty followers collection, only populating the siz (for privacy).
|
||||
// TODO this needs to return the actual followers, and the to: field needs this
|
||||
/// Returns an empty followers collection, only populating the size (for privacy).
|
||||
pub async fn get_apub_community_followers(
|
||||
info: Path<CommunityQuery>,
|
||||
db: DbPoolParam,
|
||||
|
@ -415,34 +352,3 @@ pub async fn get_apub_community_followers(
|
|||
.set_total_items(community_followers.len() as u64)?;
|
||||
Ok(create_apub_response(&collection))
|
||||
}
|
||||
|
||||
// TODO should not be doing this
|
||||
// Returns an UnorderedCollection with the latest posts from the community.
|
||||
//pub async fn get_apub_community_outbox(
|
||||
// info: Path<CommunityQuery>,
|
||||
// db: DbPoolParam,
|
||||
// chat_server: ChatServerParam,
|
||||
//) -> Result<HttpResponse<Body>, Error> {
|
||||
// let community = Community::read_from_name(&&db.get()?, &info.community_name)?;
|
||||
|
||||
// let conn = establish_unpooled_connection();
|
||||
// //As we are an object, we validated that the community id was valid
|
||||
// let community_posts: Vec<Post> = Post::list_for_community(&conn, community.id)?;
|
||||
|
||||
// let mut collection = OrderedCollection::default();
|
||||
// let oprops: &mut ObjectProperties = collection.as_mut();
|
||||
// oprops
|
||||
// .set_context_xsd_any_uri(context())?
|
||||
// .set_id(community.actor_id)?;
|
||||
// collection
|
||||
// .collection_props
|
||||
// .set_many_items_base_boxes(
|
||||
// community_posts
|
||||
// .iter()
|
||||
// .map(|c| c.as_page(&conn).unwrap())
|
||||
// .collect(),
|
||||
// )?
|
||||
// .set_total_items(community_posts.len() as u64)?;
|
||||
|
||||
// Ok(create_apub_response(&collection))
|
||||
//}
|
||||
|
|
|
@ -7,6 +7,22 @@ pub enum CommunityAcceptedObjects {
|
|||
Undo(Undo),
|
||||
}
|
||||
|
||||
impl CommunityAcceptedObjects {
|
||||
fn follow(&self) -> Result<Follow, Error> {
|
||||
match self {
|
||||
CommunityAcceptedObjects::Follow(f) => Ok(f.to_owned()),
|
||||
CommunityAcceptedObjects::Undo(u) => Ok(
|
||||
u.undo_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
.unwrap()
|
||||
.to_owned()
|
||||
.into_concrete::<Follow>()?,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Consolidate community and user inboxes into a single shared one
|
||||
/// Handler for all incoming activities to community inboxes.
|
||||
pub async fn community_inbox(
|
||||
|
@ -14,7 +30,7 @@ pub async fn community_inbox(
|
|||
input: web::Json<CommunityAcceptedObjects>,
|
||||
path: web::Path<String>,
|
||||
db: DbPoolParam,
|
||||
chat_server: ChatServerParam,
|
||||
_chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let input = input.into_inner();
|
||||
let community_name = path.into_inner();
|
||||
|
@ -22,31 +38,13 @@ pub async fn community_inbox(
|
|||
"Community {} received activity {:?}",
|
||||
&community_name, &input
|
||||
);
|
||||
match input {
|
||||
CommunityAcceptedObjects::Follow(f) => {
|
||||
handle_follow(&f, &request, &community_name, db, chat_server)
|
||||
}
|
||||
CommunityAcceptedObjects::Undo(u) => {
|
||||
handle_undo_follow(&u, &request, &community_name, db, chat_server)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle a follow request from a remote user, adding it to the local database and returning an
|
||||
/// Accept activity.
|
||||
fn handle_follow(
|
||||
follow: &Follow,
|
||||
request: &HttpRequest,
|
||||
community_name: &str,
|
||||
db: DbPoolParam,
|
||||
_chat_server: ChatServerParam,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let follow = input.follow()?;
|
||||
let user_uri = follow
|
||||
.follow_props
|
||||
.get_actor_xsd_any_uri()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let _community_uri = follow
|
||||
let community_uri = follow
|
||||
.follow_props
|
||||
.get_object_xsd_any_uri()
|
||||
.unwrap()
|
||||
|
@ -55,18 +53,25 @@ fn handle_follow(
|
|||
let conn = db.get()?;
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
let community = Community::read_from_name(&conn, &community_name)?;
|
||||
let community = get_or_fetch_and_upsert_remote_community(&community_uri, &conn)?;
|
||||
|
||||
verify(&request, &user.public_key.unwrap())?;
|
||||
verify(&request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&follow)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
match input {
|
||||
CommunityAcceptedObjects::Follow(f) => handle_follow(&f, &user, &community, &conn),
|
||||
CommunityAcceptedObjects::Undo(u) => handle_undo_follow(&u, &user, &community, &conn),
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle a follow request from a remote user, adding it to the local database and returning an
|
||||
/// Accept activity.
|
||||
fn handle_follow(
|
||||
follow: &Follow,
|
||||
user: &User_,
|
||||
community: &Community,
|
||||
conn: &PgConnection,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
insert_activity(&conn, user.id, &follow, false)?;
|
||||
|
||||
let community_follower_form = CommunityFollowerForm {
|
||||
community_id: community.id,
|
||||
|
@ -83,46 +88,11 @@ fn handle_follow(
|
|||
|
||||
fn handle_undo_follow(
|
||||
undo: &Undo,
|
||||
request: &HttpRequest,
|
||||
community_name: &str,
|
||||
db: DbPoolParam,
|
||||
_chat_server: ChatServerParam,
|
||||
user: &User_,
|
||||
community: &Community,
|
||||
conn: &PgConnection,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let follow = undo
|
||||
.undo_props
|
||||
.get_object_base_box()
|
||||
.to_owned()
|
||||
.unwrap()
|
||||
.to_owned()
|
||||
.into_concrete::<Follow>()?;
|
||||
|
||||
let user_uri = follow
|
||||
.follow_props
|
||||
.get_actor_xsd_any_uri()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let _community_uri = follow
|
||||
.follow_props
|
||||
.get_object_xsd_any_uri()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let conn = db.get()?;
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
let community = Community::read_from_name(&conn, &community_name)?;
|
||||
|
||||
verify(&request, &user.public_key.unwrap())?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&follow)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &undo, false)?;
|
||||
|
||||
let community_follower_form = CommunityFollowerForm {
|
||||
community_id: community.id,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::apub::ActorType;
|
||||
use activitystreams::ext::Extension;
|
||||
use activitystreams::Actor;
|
||||
use actix_web::HttpRequest;
|
||||
use failure::Error;
|
||||
use http::request::Builder;
|
||||
|
@ -33,9 +33,8 @@ pub fn generate_actor_keypair() -> Result<Keypair, Error> {
|
|||
}
|
||||
|
||||
/// Signs request headers with the given keypair.
|
||||
/// TODO: would be nice to pass the sending actor in, instead of raw privatekey/id strings
|
||||
pub fn sign(request: &Builder, private_key: &str, sender_id: &str) -> Result<String, Error> {
|
||||
let signing_key_id = format!("{}#main-key", sender_id);
|
||||
pub fn sign(request: &Builder, actor: &dyn ActorType) -> Result<String, Error> {
|
||||
let signing_key_id = format!("{}#main-key", actor.actor_id());
|
||||
|
||||
let headers = request
|
||||
.headers_ref()
|
||||
|
@ -58,7 +57,7 @@ pub fn sign(request: &Builder, private_key: &str, sender_id: &str) -> Result<Str
|
|||
headers,
|
||||
)?
|
||||
.sign(signing_key_id, |signing_string| {
|
||||
let private_key = PKey::private_key_from_pem(private_key.as_bytes())?;
|
||||
let private_key = PKey::private_key_from_pem(actor.private_key().as_bytes())?;
|
||||
let mut signer = Signer::new(MessageDigest::sha256(), &private_key).unwrap();
|
||||
signer.update(signing_string.as_bytes()).unwrap();
|
||||
Ok(base64::encode(signer.sign_to_vec()?)) as Result<_, Error>
|
||||
|
@ -68,7 +67,7 @@ pub fn sign(request: &Builder, private_key: &str, sender_id: &str) -> Result<Str
|
|||
Ok(signature_header_value)
|
||||
}
|
||||
|
||||
pub fn verify(request: &HttpRequest, public_key: &str) -> Result<(), Error> {
|
||||
pub fn verify(request: &HttpRequest, actor: &dyn ActorType) -> Result<(), Error> {
|
||||
let headers = request
|
||||
.headers()
|
||||
.iter()
|
||||
|
@ -86,9 +85,10 @@ pub fn verify(request: &HttpRequest, public_key: &str) -> Result<(), Error> {
|
|||
.verify(|signature, signing_string| -> Result<bool, Error> {
|
||||
debug!(
|
||||
"Verifying with key {}, message {}",
|
||||
&public_key, &signing_string
|
||||
&actor.public_key(),
|
||||
&signing_string
|
||||
);
|
||||
let public_key = PKey::public_key_from_pem(public_key.as_bytes())?;
|
||||
let public_key = PKey::public_key_from_pem(actor.public_key().as_bytes())?;
|
||||
let mut verifier = Verifier::new(MessageDigest::sha256(), &public_key).unwrap();
|
||||
verifier.update(&signing_string.as_bytes()).unwrap();
|
||||
Ok(verifier.verify(&base64::decode(signature)?)?)
|
||||
|
@ -130,4 +130,4 @@ impl PublicKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Extension<T> for PublicKeyExtension where T: Actor {}
|
||||
impl<T> Extension<T> for PublicKeyExtension where T: activitystreams::Actor {}
|
||||
|
|
|
@ -40,6 +40,7 @@ pub enum SearchAcceptedObjects {
|
|||
Person(Box<PersonExt>),
|
||||
Group(Box<GroupExt>),
|
||||
Page(Box<PageExt>),
|
||||
Comment(Box<Note>),
|
||||
}
|
||||
|
||||
/// Attempt to parse the query as URL, and fetch an ActivityPub object from it.
|
||||
|
@ -47,7 +48,8 @@ pub enum SearchAcceptedObjects {
|
|||
/// Some working examples for use with the docker/federation/ setup:
|
||||
/// http://lemmy_alpha:8540/c/main, or !main@lemmy_alpha:8540
|
||||
/// http://lemmy_alpha:8540/u/lemmy_alpha, or @lemmy_alpha@lemmy_alpha:8540
|
||||
/// http://lemmy_alpha:8540/p/3
|
||||
/// http://lemmy_alpha:8540/post/3
|
||||
/// http://lemmy_alpha:8540/comment/2
|
||||
pub fn search_by_apub_id(query: &str, conn: &PgConnection) -> Result<SearchResponse, Error> {
|
||||
// Parse the shorthand query url
|
||||
let query_url = if query.contains('@') {
|
||||
|
@ -99,6 +101,20 @@ pub fn search_by_apub_id(query: &str, conn: &PgConnection) -> Result<SearchRespo
|
|||
let p = upsert_post(&PostForm::from_apub(&p, conn)?, conn)?;
|
||||
response.posts = vec![PostView::read(conn, p.id, None)?];
|
||||
}
|
||||
SearchAcceptedObjects::Comment(c) => {
|
||||
let post_url = c
|
||||
.object_props
|
||||
.get_many_in_reply_to_xsd_any_uris()
|
||||
.unwrap()
|
||||
.next()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
// TODO: also fetch parent comments if any
|
||||
let post = fetch_remote_object(&Url::parse(&post_url)?)?;
|
||||
upsert_post(&PostForm::from_apub(&post, conn)?, conn)?;
|
||||
let c = upsert_comment(&CommentForm::from_apub(&c, conn)?, conn)?;
|
||||
response.comments = vec![CommentView::read(conn, c.id, None)?];
|
||||
}
|
||||
}
|
||||
Ok(response)
|
||||
}
|
||||
|
@ -198,6 +214,15 @@ fn upsert_post(post_form: &PostForm, conn: &PgConnection) -> Result<Post, Error>
|
|||
}
|
||||
}
|
||||
|
||||
fn upsert_comment(comment_form: &CommentForm, conn: &PgConnection) -> Result<Comment, Error> {
|
||||
let existing = Comment::read_from_apub_id(conn, &comment_form.ap_id);
|
||||
match existing {
|
||||
Err(NotFound {}) => Ok(Comment::create(conn, &comment_form)?),
|
||||
Ok(p) => Ok(Comment::update(conn, p.id, &comment_form)?),
|
||||
Err(e) => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO It should not be fetching data from a community outbox.
|
||||
// All posts, comments, comment likes, etc should be posts to our community_inbox
|
||||
// The only data we should be periodically fetching (if it hasn't been fetched in the last day
|
||||
|
|
|
@ -10,6 +10,7 @@ pub mod shared_inbox;
|
|||
pub mod user;
|
||||
pub mod user_inbox;
|
||||
use crate::api::community::CommunityResponse;
|
||||
use crate::db::activity::insert_activity;
|
||||
use crate::websocket::server::SendCommunityRoomMessage;
|
||||
use activitystreams::object::kind::{NoteType, PageType};
|
||||
use activitystreams::{
|
||||
|
@ -54,7 +55,7 @@ use crate::db::private_message::{PrivateMessage, PrivateMessageForm};
|
|||
use crate::db::private_message_view::PrivateMessageView;
|
||||
use crate::db::user::{UserForm, User_};
|
||||
use crate::db::user_view::UserView;
|
||||
use crate::db::{activity, Crud, Followable, Joinable, Likeable, SearchType};
|
||||
use crate::db::{Crud, Followable, Joinable, Likeable, SearchType};
|
||||
use crate::routes::nodeinfo::{NodeInfo, NodeInfoWellKnown};
|
||||
use crate::routes::webfinger::WebFingerResponse;
|
||||
use crate::routes::{ChatServerParam, DbPoolParam};
|
||||
|
@ -106,18 +107,12 @@ where
|
|||
.json(data)
|
||||
}
|
||||
|
||||
/// Generates the ActivityPub ID for a given object type and name.
|
||||
///
|
||||
/// TODO: we will probably need to change apub endpoint urls so that html and activity+json content
|
||||
/// types are handled at the same endpoint, so that you can copy the url into mastodon search
|
||||
/// and have it fetch the object.
|
||||
/// Generates the ActivityPub ID for a given object type and ID.
|
||||
pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
|
||||
let point = match endpoint_type {
|
||||
EndpointType::Community => "c",
|
||||
EndpointType::User => "u",
|
||||
EndpointType::Post => "post",
|
||||
// TODO I have to change this else my update advanced_migrations crashes the
|
||||
// server if a comment exists.
|
||||
EndpointType::Comment => "comment",
|
||||
EndpointType::PrivateMessage => "private_message",
|
||||
};
|
||||
|
@ -158,7 +153,6 @@ fn is_apub_id_valid(apub_id: &Url) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO Not sure good names for these
|
||||
pub trait ToApub {
|
||||
type Response;
|
||||
fn to_apub(&self, conn: &PgConnection) -> Result<Self::Response, Error>;
|
||||
|
@ -233,6 +227,7 @@ pub trait ActorType {
|
|||
fn actor_id(&self) -> String;
|
||||
|
||||
fn public_key(&self) -> String;
|
||||
fn private_key(&self) -> String;
|
||||
|
||||
// These two have default impls, since currently a community can't follow anything,
|
||||
// and a user can't be followed (yet)
|
||||
|
|
|
@ -132,21 +132,9 @@ impl ApubObjectType for Post {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(page)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&create)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &create, true)?;
|
||||
|
||||
send_activity(
|
||||
&create,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&create, creator, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -167,21 +155,9 @@ impl ApubObjectType for Post {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(page)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&update)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &update, true)?;
|
||||
|
||||
send_activity(
|
||||
&update,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&update, creator, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -202,22 +178,10 @@ impl ApubObjectType for Post {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(page)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: self.creator_id,
|
||||
data: serde_json::to_value(&delete)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, self.creator_id, &delete, true)?;
|
||||
|
||||
let community = Community::read(conn, self.community_id)?;
|
||||
send_activity(
|
||||
&delete,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&delete, creator, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -254,22 +218,10 @@ impl ApubObjectType for Post {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(delete)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: self.creator_id,
|
||||
data: serde_json::to_value(&undo)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, self.creator_id, &undo, true)?;
|
||||
|
||||
let community = Community::read(conn, self.community_id)?;
|
||||
send_activity(
|
||||
&undo,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&undo, creator, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -290,22 +242,10 @@ impl ApubObjectType for Post {
|
|||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||
.set_object_base_box(page)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: mod_.id,
|
||||
data: serde_json::to_value(&remove)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, mod_.id, &remove, true)?;
|
||||
|
||||
let community = Community::read(conn, self.community_id)?;
|
||||
send_activity(
|
||||
&remove,
|
||||
&mod_.private_key.as_ref().unwrap(),
|
||||
&mod_.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&remove, mod_, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
fn send_undo_remove(&self, mod_: &User_, conn: &PgConnection) -> Result<(), Error> {
|
||||
|
@ -340,22 +280,10 @@ impl ApubObjectType for Post {
|
|||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||
.set_object_base_box(remove)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: mod_.id,
|
||||
data: serde_json::to_value(&undo)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, mod_.id, &undo, true)?;
|
||||
|
||||
let community = Community::read(conn, self.community_id)?;
|
||||
send_activity(
|
||||
&undo,
|
||||
&mod_.private_key.as_ref().unwrap(),
|
||||
&mod_.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&undo, mod_, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -377,21 +305,9 @@ impl ApubLikeableType for Post {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(page)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&like)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &like, true)?;
|
||||
|
||||
send_activity(
|
||||
&like,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&like, creator, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -411,21 +327,9 @@ impl ApubLikeableType for Post {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(page)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&dislike)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &dislike, true)?;
|
||||
|
||||
send_activity(
|
||||
&dislike,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&dislike, creator, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -461,21 +365,9 @@ impl ApubLikeableType for Post {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(like)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&undo)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &undo, true)?;
|
||||
|
||||
send_activity(
|
||||
&undo,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
community.get_follower_inboxes(&conn)?,
|
||||
)?;
|
||||
send_activity(&undo, creator, community.get_follower_inboxes(&conn)?)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,21 +85,9 @@ impl ApubObjectType for PrivateMessage {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(note)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&create)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &create, true)?;
|
||||
|
||||
send_activity(
|
||||
&create,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
vec![to],
|
||||
)?;
|
||||
send_activity(&create, creator, vec![to])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -121,21 +109,9 @@ impl ApubObjectType for PrivateMessage {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(note)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&update)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &update, true)?;
|
||||
|
||||
send_activity(
|
||||
&update,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
vec![to],
|
||||
)?;
|
||||
send_activity(&update, creator, vec![to])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -156,21 +132,9 @@ impl ApubObjectType for PrivateMessage {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(note)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&delete)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &delete, true)?;
|
||||
|
||||
send_activity(
|
||||
&delete,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
vec![to],
|
||||
)?;
|
||||
send_activity(&delete, creator, vec![to])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -206,21 +170,9 @@ impl ApubObjectType for PrivateMessage {
|
|||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(delete)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: creator.id,
|
||||
data: serde_json::to_value(&undo)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, creator.id, &undo, true)?;
|
||||
|
||||
send_activity(
|
||||
&undo,
|
||||
&creator.private_key.as_ref().unwrap(),
|
||||
&creator.actor_id,
|
||||
vec![to],
|
||||
)?;
|
||||
send_activity(&undo, creator, vec![to])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -119,16 +119,9 @@ fn receive_create_post(
|
|||
.to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&create)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &create, false)?;
|
||||
|
||||
let post = PostForm::from_apub(&page, &conn)?;
|
||||
let inserted_post = Post::create(conn, &post)?;
|
||||
|
@ -168,16 +161,9 @@ fn receive_create_comment(
|
|||
.to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.to_owned().unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&create)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &create, false)?;
|
||||
|
||||
let comment = CommentForm::from_apub(¬e, &conn)?;
|
||||
let inserted_comment = Comment::create(conn, &comment)?;
|
||||
|
@ -228,16 +214,9 @@ fn receive_update_post(
|
|||
.to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&update)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &update, false)?;
|
||||
|
||||
let post = PostForm::from_apub(&page, conn)?;
|
||||
let post_id = Post::read_from_apub_id(conn, &post.ap_id)?.id;
|
||||
|
@ -274,16 +253,9 @@ fn receive_like_post(
|
|||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&like)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &like, false)?;
|
||||
|
||||
let post = PostForm::from_apub(&page, conn)?;
|
||||
let post_id = Post::read_from_apub_id(conn, &post.ap_id)?.id;
|
||||
|
@ -331,16 +303,9 @@ fn receive_dislike_post(
|
|||
.to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&dislike)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &dislike, false)?;
|
||||
|
||||
let post = PostForm::from_apub(&page, conn)?;
|
||||
let post_id = Post::read_from_apub_id(conn, &post.ap_id)?.id;
|
||||
|
@ -388,16 +353,9 @@ fn receive_update_comment(
|
|||
.to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.to_owned().unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&update)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &update, false)?;
|
||||
|
||||
let comment = CommentForm::from_apub(¬e, &conn)?;
|
||||
let comment_id = Comment::read_from_apub_id(conn, &comment.ap_id)?.id;
|
||||
|
@ -441,16 +399,9 @@ fn receive_like_comment(
|
|||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&like)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &like, false)?;
|
||||
|
||||
let comment = CommentForm::from_apub(¬e, &conn)?;
|
||||
let comment_id = Comment::read_from_apub_id(conn, &comment.ap_id)?.id;
|
||||
|
@ -503,16 +454,9 @@ fn receive_dislike_comment(
|
|||
.to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&dislike)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &dislike, false)?;
|
||||
|
||||
let comment = CommentForm::from_apub(¬e, &conn)?;
|
||||
let comment_id = Comment::read_from_apub_id(conn, &comment.ap_id)?.id;
|
||||
|
@ -565,16 +509,9 @@ fn receive_delete_community(
|
|||
.into_concrete::<GroupExt>()?;
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&delete)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &delete, false)?;
|
||||
|
||||
let community_actor_id = CommunityForm::from_apub(&group, &conn)?.actor_id;
|
||||
let community = Community::read_from_actor_id(conn, &community_actor_id)?;
|
||||
|
@ -634,16 +571,9 @@ fn receive_remove_community(
|
|||
.into_concrete::<GroupExt>()?;
|
||||
|
||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||
verify(request, &mod_.public_key.unwrap())?;
|
||||
verify(request, &mod_)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: mod_.id,
|
||||
data: serde_json::to_value(&remove)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, mod_.id, &remove, false)?;
|
||||
|
||||
let community_actor_id = CommunityForm::from_apub(&group, &conn)?.actor_id;
|
||||
let community = Community::read_from_actor_id(conn, &community_actor_id)?;
|
||||
|
@ -703,16 +633,9 @@ fn receive_delete_post(
|
|||
.into_concrete::<PageExt>()?;
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&delete)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &delete, false)?;
|
||||
|
||||
let post_ap_id = PostForm::from_apub(&page, conn)?.ap_id;
|
||||
let post = Post::read_from_apub_id(conn, &post_ap_id)?;
|
||||
|
@ -774,16 +697,9 @@ fn receive_remove_post(
|
|||
.into_concrete::<PageExt>()?;
|
||||
|
||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||
verify(request, &mod_.public_key.unwrap())?;
|
||||
verify(request, &mod_)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: mod_.id,
|
||||
data: serde_json::to_value(&remove)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, mod_.id, &remove, false)?;
|
||||
|
||||
let post_ap_id = PostForm::from_apub(&page, conn)?.ap_id;
|
||||
let post = Post::read_from_apub_id(conn, &post_ap_id)?;
|
||||
|
@ -845,16 +761,9 @@ fn receive_delete_comment(
|
|||
.into_concrete::<Note>()?;
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&delete)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &delete, false)?;
|
||||
|
||||
let comment_ap_id = CommentForm::from_apub(¬e, &conn)?.ap_id;
|
||||
let comment = Comment::read_from_apub_id(conn, &comment_ap_id)?;
|
||||
|
@ -913,16 +822,9 @@ fn receive_remove_comment(
|
|||
.into_concrete::<Note>()?;
|
||||
|
||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||
verify(request, &mod_.public_key.unwrap())?;
|
||||
verify(request, &mod_)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: mod_.id,
|
||||
data: serde_json::to_value(&remove)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, mod_.id, &remove, false)?;
|
||||
|
||||
let comment_ap_id = CommentForm::from_apub(¬e, &conn)?.ap_id;
|
||||
let comment = Comment::read_from_apub_id(conn, &comment_ap_id)?;
|
||||
|
@ -1041,16 +943,9 @@ fn receive_undo_delete_comment(
|
|||
.into_concrete::<Note>()?;
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&delete)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &delete, false)?;
|
||||
|
||||
let comment_ap_id = CommentForm::from_apub(¬e, &conn)?.ap_id;
|
||||
let comment = Comment::read_from_apub_id(conn, &comment_ap_id)?;
|
||||
|
@ -1109,16 +1004,9 @@ fn receive_undo_remove_comment(
|
|||
.into_concrete::<Note>()?;
|
||||
|
||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||
verify(request, &mod_.public_key.unwrap())?;
|
||||
verify(request, &mod_)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: mod_.id,
|
||||
data: serde_json::to_value(&remove)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, mod_.id, &remove, false)?;
|
||||
|
||||
let comment_ap_id = CommentForm::from_apub(¬e, &conn)?.ap_id;
|
||||
let comment = Comment::read_from_apub_id(conn, &comment_ap_id)?;
|
||||
|
@ -1177,16 +1065,9 @@ fn receive_undo_delete_post(
|
|||
.into_concrete::<PageExt>()?;
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&delete)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &delete, false)?;
|
||||
|
||||
let post_ap_id = PostForm::from_apub(&page, conn)?.ap_id;
|
||||
let post = Post::read_from_apub_id(conn, &post_ap_id)?;
|
||||
|
@ -1248,16 +1129,9 @@ fn receive_undo_remove_post(
|
|||
.into_concrete::<PageExt>()?;
|
||||
|
||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||
verify(request, &mod_.public_key.unwrap())?;
|
||||
verify(request, &mod_)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: mod_.id,
|
||||
data: serde_json::to_value(&remove)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, mod_.id, &remove, false)?;
|
||||
|
||||
let post_ap_id = PostForm::from_apub(&page, conn)?.ap_id;
|
||||
let post = Post::read_from_apub_id(conn, &post_ap_id)?;
|
||||
|
@ -1319,16 +1193,9 @@ fn receive_undo_delete_community(
|
|||
.into_concrete::<GroupExt>()?;
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&delete)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &delete, false)?;
|
||||
|
||||
let community_actor_id = CommunityForm::from_apub(&group, &conn)?.actor_id;
|
||||
let community = Community::read_from_actor_id(conn, &community_actor_id)?;
|
||||
|
@ -1388,16 +1255,9 @@ fn receive_undo_remove_community(
|
|||
.into_concrete::<GroupExt>()?;
|
||||
|
||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||
verify(request, &mod_.public_key.unwrap())?;
|
||||
verify(request, &mod_)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: mod_.id,
|
||||
data: serde_json::to_value(&remove)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, mod_.id, &remove, false)?;
|
||||
|
||||
let community_actor_id = CommunityForm::from_apub(&group, &conn)?.actor_id;
|
||||
let community = Community::read_from_actor_id(conn, &community_actor_id)?;
|
||||
|
@ -1482,16 +1342,9 @@ fn receive_undo_like_comment(
|
|||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&like)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &like, false)?;
|
||||
|
||||
let comment = CommentForm::from_apub(¬e, &conn)?;
|
||||
let comment_id = Comment::read_from_apub_id(conn, &comment.ap_id)?.id;
|
||||
|
@ -1539,16 +1392,9 @@ fn receive_undo_like_post(
|
|||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&like)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &like, false)?;
|
||||
|
||||
let post = PostForm::from_apub(&page, conn)?;
|
||||
let post_id = Post::read_from_apub_id(conn, &post.ap_id)?.id;
|
||||
|
|
|
@ -57,6 +57,10 @@ impl ActorType for User_ {
|
|||
self.public_key.to_owned().unwrap()
|
||||
}
|
||||
|
||||
fn private_key(&self) -> String {
|
||||
self.private_key.to_owned().unwrap()
|
||||
}
|
||||
|
||||
/// As a given local user, send out a follow request to a remote community.
|
||||
fn send_follow(&self, follow_actor_id: &str, conn: &PgConnection) -> Result<(), Error> {
|
||||
let mut follow = Follow::new();
|
||||
|
@ -73,21 +77,9 @@ impl ActorType for User_ {
|
|||
.set_object_xsd_any_uri(follow_actor_id)?;
|
||||
let to = format!("{}/inbox", follow_actor_id);
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: self.id,
|
||||
data: serde_json::to_value(&follow)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, self.id, &follow, true)?;
|
||||
|
||||
send_activity(
|
||||
&follow,
|
||||
&self.private_key.as_ref().unwrap(),
|
||||
&follow_actor_id,
|
||||
vec![to],
|
||||
)?;
|
||||
send_activity(&follow, self, vec![to])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -121,21 +113,9 @@ impl ActorType for User_ {
|
|||
.set_actor_xsd_any_uri(self.actor_id.to_owned())?
|
||||
.set_object_base_box(follow)?;
|
||||
|
||||
// Insert the sent activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: self.id,
|
||||
data: serde_json::to_value(&undo)?,
|
||||
local: true,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, self.id, &undo, true)?;
|
||||
|
||||
send_activity(
|
||||
&undo,
|
||||
&self.private_key.as_ref().unwrap(),
|
||||
&follow_actor_id,
|
||||
vec![to],
|
||||
)?;
|
||||
send_activity(&undo, self, vec![to])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -55,18 +55,11 @@ fn receive_accept(
|
|||
.to_string();
|
||||
|
||||
let community = get_or_fetch_and_upsert_remote_community(&community_uri, conn)?;
|
||||
verify(request, &community.public_key.unwrap())?;
|
||||
verify(request, &community)?;
|
||||
|
||||
let user = User_::read_from_name(&conn, username)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: community.creator_id,
|
||||
data: serde_json::to_value(&accept)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, community.creator_id, &accept, false)?;
|
||||
|
||||
// Now you need to add this to the community follower
|
||||
let community_follower_form = CommunityFollowerForm {
|
||||
|
@ -78,7 +71,6 @@ fn receive_accept(
|
|||
CommunityFollower::follow(&conn, &community_follower_form)?;
|
||||
|
||||
// TODO: make sure that we actually requested a follow
|
||||
// TODO: at this point, indicate to the user that they are following the community
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
|
@ -103,16 +95,9 @@ fn receive_create_private_message(
|
|||
.to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&create)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &create, false)?;
|
||||
|
||||
let private_message = PrivateMessageForm::from_apub(¬e, &conn)?;
|
||||
let inserted_private_message = PrivateMessage::create(&conn, &private_message)?;
|
||||
|
@ -154,16 +139,9 @@ fn receive_update_private_message(
|
|||
.to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&update)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &update, false)?;
|
||||
|
||||
let private_message = PrivateMessageForm::from_apub(¬e, &conn)?;
|
||||
let private_message_id = PrivateMessage::read_from_apub_id(&conn, &private_message.ap_id)?.id;
|
||||
|
@ -206,16 +184,9 @@ fn receive_delete_private_message(
|
|||
.to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&delete)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &delete, false)?;
|
||||
|
||||
let private_message = PrivateMessageForm::from_apub(¬e, &conn)?;
|
||||
let private_message_id = PrivateMessage::read_from_apub_id(&conn, &private_message.ap_id)?.id;
|
||||
|
@ -277,16 +248,9 @@ fn receive_undo_delete_private_message(
|
|||
.to_string();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||
verify(request, &user.public_key.unwrap())?;
|
||||
verify(request, &user)?;
|
||||
|
||||
// Insert the received activity into the activity table
|
||||
let activity_form = activity::ActivityForm {
|
||||
user_id: user.id,
|
||||
data: serde_json::to_value(&delete)?,
|
||||
local: false,
|
||||
updated: None,
|
||||
};
|
||||
activity::Activity::create(&conn, &activity_form)?;
|
||||
insert_activity(&conn, user.id, &delete, false)?;
|
||||
|
||||
let private_message = PrivateMessageForm::from_apub(¬e, &conn)?;
|
||||
let private_message_id = PrivateMessage::read_from_apub_id(&conn, &private_message.ap_id)?.id;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use super::*;
|
||||
use crate::schema::activity;
|
||||
use crate::schema::activity::dsl::*;
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
|
||||
|
@ -25,14 +24,17 @@ pub struct ActivityForm {
|
|||
|
||||
impl Crud<ActivityForm> for Activity {
|
||||
fn read(conn: &PgConnection, activity_id: i32) -> Result<Self, Error> {
|
||||
use crate::schema::activity::dsl::*;
|
||||
activity.find(activity_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn delete(conn: &PgConnection, activity_id: i32) -> Result<usize, Error> {
|
||||
use crate::schema::activity::dsl::*;
|
||||
diesel::delete(activity.find(activity_id)).execute(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {
|
||||
use crate::schema::activity::dsl::*;
|
||||
insert_into(activity)
|
||||
.values(new_activity)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -43,12 +45,31 @@ impl Crud<ActivityForm> for Activity {
|
|||
activity_id: i32,
|
||||
new_activity: &ActivityForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::activity::dsl::*;
|
||||
diesel::update(activity.find(activity_id))
|
||||
.set(new_activity)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert_activity<T>(
|
||||
conn: &PgConnection,
|
||||
user_id: i32,
|
||||
data: &T,
|
||||
local: bool,
|
||||
) -> Result<Activity, failure::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let activity_form = ActivityForm {
|
||||
user_id,
|
||||
data: serde_json::to_value(&data)?,
|
||||
local,
|
||||
updated: None,
|
||||
};
|
||||
Ok(Activity::create(&conn, &activity_form)?)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::user::*;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use super::*;
|
||||
use crate::apub::comment::get_apub_comment;
|
||||
use crate::apub::community::*;
|
||||
use crate::apub::community_inbox::community_inbox;
|
||||
use crate::apub::post::get_apub_post;
|
||||
|
@ -28,7 +29,8 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
|||
// web::get().to(get_apub_community_outbox),
|
||||
// )
|
||||
.route("/u/{user_name}", web::get().to(get_apub_user_http))
|
||||
.route("/post/{post_id}", web::get().to(get_apub_post)),
|
||||
.route("/post/{post_id}", web::get().to(get_apub_post))
|
||||
.route("/comment/{comment_id}", web::get().to(get_apub_comment)),
|
||||
)
|
||||
// Inboxes dont work with the header guard for some reason.
|
||||
.route("/c/{community_name}/inbox", web::post().to(community_inbox))
|
||||
|
|
32
ui/src/api_tests/api.spec.ts
vendored
32
ui/src/api_tests/api.spec.ts
vendored
|
@ -69,7 +69,7 @@ describe('main', () => {
|
|||
lemmyBetaAuth = resB.jwt;
|
||||
});
|
||||
|
||||
describe('beta_fetch', () => {
|
||||
describe('post_search', () => {
|
||||
test('Create test post on alpha and fetch it on beta', async () => {
|
||||
let name = 'A jest test post';
|
||||
let postForm: PostForm = {
|
||||
|
@ -1146,6 +1146,36 @@ describe('main', () => {
|
|||
expect(getPrivateMessagesUnDeletedRes.messages[0].deleted).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('comment_search', () => {
|
||||
test('Create comment on alpha and search it', async () => {
|
||||
let content = 'A jest test federated comment for search';
|
||||
let commentForm: CommentForm = {
|
||||
content,
|
||||
post_id: 1,
|
||||
auth: lemmyAlphaAuth,
|
||||
};
|
||||
|
||||
let createResponse: CommentResponse = await fetch(
|
||||
`${lemmyAlphaApiUrl}/comment`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: wrapper(commentForm),
|
||||
}
|
||||
).then(d => d.json());
|
||||
|
||||
let searchUrl = `${lemmyBetaApiUrl}/search?q=${createResponse.comment.ap_id}&type_=All&sort=TopAll`;
|
||||
let searchResponse: SearchResponse = await fetch(searchUrl, {
|
||||
method: 'GET',
|
||||
}).then(d => d.json());
|
||||
|
||||
// TODO: check more fields
|
||||
expect(searchResponse.comments[0].content).toBe(content);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function wrapper(form: any): string {
|
||||
|
|
Loading…
Reference in a new issue