mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-12 15:34:00 +00:00
Merge branch 'federation' into add_activity_table
This commit is contained in:
commit
b60c7bbae7
4 changed files with 69 additions and 97 deletions
|
@ -23,9 +23,6 @@ impl ToApub for Comment {
|
||||||
// Not needed when the Post is embedded in a collection (like for community outbox)
|
// Not needed when the Post is embedded in a collection (like for community outbox)
|
||||||
.set_context_xsd_any_uri(context())?
|
.set_context_xsd_any_uri(context())?
|
||||||
.set_id(self.ap_id.to_owned())?
|
.set_id(self.ap_id.to_owned())?
|
||||||
// Use summary field to be consistent with mastodon content warning.
|
|
||||||
// https://mastodon.xyz/@Louisa/103987265222901387.json
|
|
||||||
// .set_summary_xsd_string(self.name.to_owned())?
|
|
||||||
.set_published(convert_datetime(self.published))?
|
.set_published(convert_datetime(self.published))?
|
||||||
.set_to_xsd_any_uri(community.actor_id)?
|
.set_to_xsd_any_uri(community.actor_id)?
|
||||||
.set_many_in_reply_to_xsd_any_uris(in_reply_to_vec)?
|
.set_many_in_reply_to_xsd_any_uris(in_reply_to_vec)?
|
||||||
|
|
|
@ -16,11 +16,7 @@ use activitystreams::{
|
||||||
context,
|
context,
|
||||||
endpoint::EndpointProperties,
|
endpoint::EndpointProperties,
|
||||||
ext::{Ext, Extensible, Extension},
|
ext::{Ext, Extensible, Extension},
|
||||||
object::{
|
object::{properties::ObjectProperties, Note, Page},
|
||||||
kind::{NoteType, PageType},
|
|
||||||
properties::ObjectProperties,
|
|
||||||
Note, Page,
|
|
||||||
},
|
|
||||||
public, BaseBox,
|
public, BaseBox,
|
||||||
};
|
};
|
||||||
use actix_web::body::Body;
|
use actix_web::body::Body;
|
||||||
|
@ -184,12 +180,12 @@ pub trait ActorType {
|
||||||
// and a user can't be followed (yet)
|
// and a user can't be followed (yet)
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn send_follow(&self, follow_actor_id: &str, conn: &PgConnection) -> Result<(), Error> {
|
fn send_follow(&self, follow_actor_id: &str, conn: &PgConnection) -> Result<(), Error> {
|
||||||
Ok(())
|
Err(format_err!("Follow not implemented."))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn send_accept_follow(&self, follow: &Follow, conn: &PgConnection) -> Result<(), Error> {
|
fn send_accept_follow(&self, follow: &Follow, conn: &PgConnection) -> Result<(), Error> {
|
||||||
Ok(())
|
Err(format_err!("Accept not implemented."))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO default because there is no user following yet.
|
// TODO default because there is no user following yet.
|
||||||
|
|
|
@ -7,6 +7,15 @@ pub enum SharedAcceptedObjects {
|
||||||
Update(Update),
|
Update(Update),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SharedAcceptedObjects {
|
||||||
|
fn object(&self) -> Option<&BaseBox> {
|
||||||
|
match self {
|
||||||
|
SharedAcceptedObjects::Create(c) => c.create_props.get_object_base_box(),
|
||||||
|
SharedAcceptedObjects::Update(u) => u.update_props.get_object_base_box(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Handler for all incoming activities to user inboxes.
|
/// Handler for all incoming activities to user inboxes.
|
||||||
pub async fn shared_inbox(
|
pub async fn shared_inbox(
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
|
@ -15,59 +24,45 @@ pub async fn shared_inbox(
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
// TODO: would be nice if we could do the signature check here, but we cant access the actor property
|
// TODO: would be nice if we could do the signature check here, but we cant access the actor property
|
||||||
let input = input.into_inner();
|
let activity = input.into_inner();
|
||||||
let conn = &db.get().unwrap();
|
let conn = &db.get().unwrap();
|
||||||
|
|
||||||
let json = serde_json::to_string(&input)?;
|
let json = serde_json::to_string(&activity)?;
|
||||||
debug!("Shared inbox received activity: {:?}", &json);
|
debug!("Shared inbox received activity: {}", json);
|
||||||
|
|
||||||
match input {
|
let object = activity.object().cloned().unwrap();
|
||||||
SharedAcceptedObjects::Create(c) => handle_create(&c, &request, &conn, chat_server),
|
|
||||||
SharedAcceptedObjects::Update(u) => handle_update(&u, &request, &conn, chat_server),
|
match (activity, object.kind()) {
|
||||||
|
(SharedAcceptedObjects::Create(c), Some("Note")) => {
|
||||||
|
receive_create_comment(&c, &request, &conn, chat_server)
|
||||||
|
}
|
||||||
|
(SharedAcceptedObjects::Create(c), Some("Page")) => {
|
||||||
|
receive_create_post(&c, &request, &conn, chat_server)
|
||||||
|
}
|
||||||
|
(SharedAcceptedObjects::Update(u), Some("Note")) => {
|
||||||
|
receive_update_comment(&u, &request, &conn, chat_server)
|
||||||
|
}
|
||||||
|
(SharedAcceptedObjects::Update(u), Some("Page")) => {
|
||||||
|
receive_update_post(&u, &request, &conn, chat_server)
|
||||||
|
}
|
||||||
|
_ => Err(format_err!("Unknown incoming activity type.")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle create activities and insert them in the database.
|
fn receive_create_post(
|
||||||
fn handle_create(
|
|
||||||
create: &Create,
|
create: &Create,
|
||||||
request: &HttpRequest,
|
request: &HttpRequest,
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
let base_box = create.create_props.get_object_base_box().unwrap();
|
let page = create
|
||||||
|
.create_props
|
||||||
|
.get_object_base_box()
|
||||||
|
.to_owned()
|
||||||
|
.unwrap()
|
||||||
|
.to_owned()
|
||||||
|
.to_concrete::<Page>()?;
|
||||||
|
|
||||||
if base_box.is_kind(PageType) {
|
|
||||||
let page = create
|
|
||||||
.create_props
|
|
||||||
.get_object_base_box()
|
|
||||||
.to_owned()
|
|
||||||
.unwrap()
|
|
||||||
.to_owned()
|
|
||||||
.to_concrete::<Page>()?;
|
|
||||||
receive_create_post(&create, &page, &request, &conn, chat_server)?;
|
|
||||||
} else if base_box.is_kind(NoteType) {
|
|
||||||
let note = create
|
|
||||||
.create_props
|
|
||||||
.get_object_base_box()
|
|
||||||
.to_owned()
|
|
||||||
.unwrap()
|
|
||||||
.to_owned()
|
|
||||||
.to_concrete::<Note>()?;
|
|
||||||
receive_create_comment(&create, ¬e, &request, &conn, chat_server)?;
|
|
||||||
} else {
|
|
||||||
return Err(format_err!("Unknown base box type"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().finish())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn receive_create_post(
|
|
||||||
create: &Create,
|
|
||||||
page: &Page,
|
|
||||||
request: &HttpRequest,
|
|
||||||
conn: &PgConnection,
|
|
||||||
chat_server: ChatServerParam,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let user_uri = create
|
let user_uri = create
|
||||||
.create_props
|
.create_props
|
||||||
.get_actor_xsd_any_uri()
|
.get_actor_xsd_any_uri()
|
||||||
|
@ -100,16 +95,23 @@ fn receive_create_post(
|
||||||
my_id: None,
|
my_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn receive_create_comment(
|
fn receive_create_comment(
|
||||||
create: &Create,
|
create: &Create,
|
||||||
note: &Note,
|
|
||||||
request: &HttpRequest,
|
request: &HttpRequest,
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<(), Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
|
let note = create
|
||||||
|
.create_props
|
||||||
|
.get_object_base_box()
|
||||||
|
.to_owned()
|
||||||
|
.unwrap()
|
||||||
|
.to_owned()
|
||||||
|
.to_concrete::<Note>()?;
|
||||||
|
|
||||||
let user_uri = create
|
let user_uri = create
|
||||||
.create_props
|
.create_props
|
||||||
.get_actor_xsd_any_uri()
|
.get_actor_xsd_any_uri()
|
||||||
|
@ -147,51 +149,23 @@ fn receive_create_comment(
|
||||||
my_id: None,
|
my_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handle create activities and insert them in the database.
|
|
||||||
fn handle_update(
|
|
||||||
update: &Update,
|
|
||||||
request: &HttpRequest,
|
|
||||||
conn: &PgConnection,
|
|
||||||
chat_server: ChatServerParam,
|
|
||||||
) -> Result<HttpResponse, Error> {
|
|
||||||
let base_box = update.update_props.get_object_base_box().unwrap();
|
|
||||||
|
|
||||||
if base_box.is_kind(PageType) {
|
|
||||||
let page = update
|
|
||||||
.update_props
|
|
||||||
.get_object_base_box()
|
|
||||||
.to_owned()
|
|
||||||
.unwrap()
|
|
||||||
.to_owned()
|
|
||||||
.to_concrete::<Page>()?;
|
|
||||||
|
|
||||||
receive_update_post(&update, &page, &request, &conn, chat_server)?;
|
|
||||||
} else if base_box.is_kind(NoteType) {
|
|
||||||
let note = update
|
|
||||||
.update_props
|
|
||||||
.get_object_base_box()
|
|
||||||
.to_owned()
|
|
||||||
.unwrap()
|
|
||||||
.to_owned()
|
|
||||||
.to_concrete::<Note>()?;
|
|
||||||
receive_update_comment(&update, ¬e, &request, &conn, chat_server)?;
|
|
||||||
} else {
|
|
||||||
return Err(format_err!("Unknown base box type"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn receive_update_post(
|
fn receive_update_post(
|
||||||
update: &Update,
|
update: &Update,
|
||||||
page: &Page,
|
|
||||||
request: &HttpRequest,
|
request: &HttpRequest,
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<(), Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
|
let page = update
|
||||||
|
.update_props
|
||||||
|
.get_object_base_box()
|
||||||
|
.to_owned()
|
||||||
|
.unwrap()
|
||||||
|
.to_owned()
|
||||||
|
.to_concrete::<Page>()?;
|
||||||
|
|
||||||
let user_uri = update
|
let user_uri = update
|
||||||
.update_props
|
.update_props
|
||||||
.get_actor_xsd_any_uri()
|
.get_actor_xsd_any_uri()
|
||||||
|
@ -225,16 +199,23 @@ fn receive_update_post(
|
||||||
my_id: None,
|
my_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn receive_update_comment(
|
fn receive_update_comment(
|
||||||
update: &Update,
|
update: &Update,
|
||||||
note: &Note,
|
|
||||||
request: &HttpRequest,
|
request: &HttpRequest,
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<(), Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
|
let note = update
|
||||||
|
.update_props
|
||||||
|
.get_object_base_box()
|
||||||
|
.to_owned()
|
||||||
|
.unwrap()
|
||||||
|
.to_owned()
|
||||||
|
.to_concrete::<Note>()?;
|
||||||
|
|
||||||
let user_uri = update
|
let user_uri = update
|
||||||
.update_props
|
.update_props
|
||||||
.get_actor_xsd_any_uri()
|
.get_actor_xsd_any_uri()
|
||||||
|
@ -273,5 +254,5 @@ fn receive_update_comment(
|
||||||
my_id: None,
|
my_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
2
ui/src/api_tests/api.spec.ts
vendored
2
ui/src/api_tests/api.spec.ts
vendored
|
@ -102,8 +102,6 @@ describe('main', () => {
|
||||||
|
|
||||||
expect(searchResponse.communities[0].name).toBe('main');
|
expect(searchResponse.communities[0].name).toBe('main');
|
||||||
|
|
||||||
// TODO
|
|
||||||
// Unfortunately the search is correctly
|
|
||||||
let followForm: FollowCommunityForm = {
|
let followForm: FollowCommunityForm = {
|
||||||
community_id: searchResponse.communities[0].id,
|
community_id: searchResponse.communities[0].id,
|
||||||
follow: true,
|
follow: true,
|
||||||
|
|
Loading…
Reference in a new issue