Skip to content

Commit

Permalink
Add /activities endpoint (ref #1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Oct 26, 2020
1 parent 6d17d5e commit 99abc49
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lemmy_apub/src/activities/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ where
T: ToString,
{
let id = format!(
"{}/receive/{}/{}",
"{}/activities/{}/{}",
Settings::get().get_protocol_and_hostname(),
kind.to_string().to_lowercase(),
Uuid::new_v4()
Expand Down
34 changes: 32 additions & 2 deletions lemmy_apub/src/http/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::APUB_JSON_CONTENT_TYPE;
use actix_web::{body::Body, HttpResponse};
use serde::Serialize;
use actix_web::{body::Body, web, HttpResponse};
use lemmy_db::activity::Activity;
use lemmy_structs::blocking;
use lemmy_utils::{settings::Settings, LemmyError};
use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};

pub mod comment;
pub mod community;
Expand All @@ -26,3 +30,29 @@ where
.content_type(APUB_JSON_CONTENT_TYPE)
.json(data)
}

#[derive(Deserialize)]
pub struct CommunityQuery {
type_: String,
id: String,
}

/// Return the ActivityPub json representation of a local community over HTTP.
pub async fn get_activity(
info: web::Path<CommunityQuery>,
context: web::Data<LemmyContext>,
) -> Result<HttpResponse<Body>, LemmyError> {
let settings = Settings::get();
let activity_id = format!(
"{}/activities/{}/{}",
settings.get_protocol_and_hostname(),
info.type_,
info.id
);
let activity = blocking(context.pool(), move |conn| {
Activity::read_from_apub_id(&conn, &activity_id)
})
.await??;

Ok(create_apub_response(&activity.data))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE activity DROP COLUMN ap_id;
1 change: 1 addition & 0 deletions migrations/2020-10-23-115011_activity_ap_id_column/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE activity ADD COLUMN ap_id TEXT;
4 changes: 3 additions & 1 deletion src/routes/federation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use lemmy_apub::{
http::{
comment::get_apub_comment,
community::{get_apub_community_followers, get_apub_community_http, get_apub_community_outbox},
get_activity,
post::get_apub_post,
user::get_apub_user_http,
},
Expand Down Expand Up @@ -36,7 +37,8 @@ pub fn config(cfg: &mut web::ServiceConfig) {
)
.route("/u/{user_name}", web::get().to(get_apub_user_http))
.route("/post/{post_id}", web::get().to(get_apub_post))
.route("/comment/{comment_id}", web::get().to(get_apub_comment)),
.route("/comment/{comment_id}", web::get().to(get_apub_comment))
.route("/activities/{type_}/{id}", web::get().to(get_activity)),
)
// Inboxes dont work with the header guard for some reason.
.service(
Expand Down

0 comments on commit 99abc49

Please sign in to comment.