lemmy/crates/apub/src/http/site.rs
Nutomic 2ef0f8f5f8
implement language tags for site/community in db and api (#2434)
* implement language tags for site/community in db and api

* add api checks for valid languages

* during db migration, update existing users, sites, communities to have all languages enabled

* init new users/communities with site languages (not all languages)

* federate site/community languages

* fix tests

* when updating site languages, limit community languages to this subset

also, when making a new post and subset of user lang, community lang
contains only one item, use that as post lang

* add tests for actor_language db functions

* include language list in siteview/communityview

* Fix some of the review comments

* Some more review changes

* Add todo about boxed query

* Add default_post_language to GetCommunityResponse
2022-10-06 14:27:58 -04:00

45 lines
1.4 KiB
Rust

use crate::{
activity_lists::SiteInboxActivities,
http::{create_apub_response, receive_lemmy_activity},
objects::{instance::ApubSite, person::ApubPerson},
protocol::collections::empty_outbox::EmptyOutbox,
};
use activitypub_federation::{deser::context::WithContext, traits::ApubObject};
use actix_web::{web, HttpRequest, HttpResponse};
use lemmy_api_common::utils::blocking;
use lemmy_db_schema::source::site::Site;
use lemmy_utils::error::LemmyError;
use lemmy_websocket::LemmyContext;
use url::Url;
pub(crate) async fn get_apub_site_http(
context: web::Data<LemmyContext>,
) -> Result<HttpResponse, LemmyError> {
let site: ApubSite = blocking(context.pool(), Site::read_local).await??.into();
let apub = site.into_apub(&context).await?;
Ok(create_apub_response(&apub))
}
#[tracing::instrument(skip_all)]
pub(crate) async fn get_apub_site_outbox(
context: web::Data<LemmyContext>,
) -> Result<HttpResponse, LemmyError> {
let outbox_id = format!(
"{}/site_outbox",
context.settings().get_protocol_and_hostname()
);
let outbox = EmptyOutbox::new(Url::parse(&outbox_id)?).await?;
Ok(create_apub_response(&outbox))
}
#[tracing::instrument(skip_all)]
pub async fn get_apub_site_inbox(
request: HttpRequest,
payload: String,
context: web::Data<LemmyContext>,
) -> Result<HttpResponse, LemmyError> {
receive_lemmy_activity::<WithContext<SiteInboxActivities>, ApubPerson>(request, payload, context)
.await
}