"lazy_static",
"lemmy_api_common",
"lemmy_apub",
+ "lemmy_apub_lib",
"lemmy_db_schema",
"lemmy_db_views",
"lemmy_db_views_actor",
[dependencies]
lemmy_apub = { version = "=0.13.5-rc.7", path = "../apub" }
+lemmy_apub_lib = { version = "=0.13.5-rc.7", path = "../apub_lib" }
lemmy_utils = { version = "=0.13.5-rc.7", path = "../utils" }
lemmy_db_schema = { version = "=0.13.5-rc.7", path = "../db_schema" }
lemmy_db_views = { version = "=0.13.5-rc.7", path = "../db_views" }
site::*,
};
use lemmy_apub::{
- build_actor_id_from_shortname,
fetcher::search::{search_by_apub_id, SearchableObjects},
- EndpointType,
+ get_actor_id_from_name,
};
+use lemmy_apub_lib::webfinger::WebfingerType;
use lemmy_db_schema::{
from_opt_str_to_opt_enum,
newtypes::PersonId,
let listing_type: Option<ListingType> = from_opt_str_to_opt_enum(&data.listing_type);
let search_type: SearchType = from_opt_str_to_opt_enum(&data.type_).unwrap_or(SearchType::All);
let community_id = data.community_id;
- let community_actor_id = data
- .community_name
- .as_ref()
- .map(|t| build_actor_id_from_shortname(EndpointType::Community, t, &context.settings()).ok())
- .unwrap_or(None);
+ let community_actor_id = if let Some(name) = &data.community_name {
+ get_actor_id_from_name(WebfingerType::Group, name, context)
+ .await
+ .ok()
+ } else {
+ None
+ };
let creator_id = data.creator_id;
match search_type {
SearchType::Posts => {
CreateOrUpdateType,
},
fetcher::post_or_comment::PostOrComment,
- generate_apub_endpoint,
+ generate_local_apub_endpoint,
EndpointType,
};
use lemmy_db_schema::{
let updated_comment: Comment =
blocking(context.pool(), move |conn| -> Result<Comment, LemmyError> {
- let apub_id = generate_apub_endpoint(
+ let apub_id = generate_local_apub_endpoint(
EndpointType::Comment,
&inserted_comment_id.to_string(),
&protocol_and_hostname,
use crate::PerformCrud;
use actix_web::web::Data;
use lemmy_api_common::{blocking, comment::*, get_local_user_view_from_jwt_opt};
-use lemmy_apub::{build_actor_id_from_shortname, EndpointType};
+use lemmy_apub::get_actor_id_from_name;
+use lemmy_apub_lib::webfinger::WebfingerType;
use lemmy_db_schema::{
from_opt_str_to_opt_enum,
traits::DeleteableOrRemoveable,
let listing_type: Option<ListingType> = from_opt_str_to_opt_enum(&data.type_);
let community_id = data.community_id;
- let community_actor_id = data
- .community_name
- .as_ref()
- .map(|t| build_actor_id_from_shortname(EndpointType::Community, t, &context.settings()).ok())
- .unwrap_or(None);
+ let community_actor_id = if let Some(name) = &data.community_name {
+ get_actor_id_from_name(WebfingerType::Group, name, context)
+ .await
+ .ok()
+ } else {
+ None
+ };
let saved_only = data.saved_only;
let page = data.page;
let limit = data.limit;
};
use lemmy_apub::{
fetcher::object_id::ObjectId,
- generate_apub_endpoint,
generate_followers_url,
generate_inbox_url,
+ generate_local_apub_endpoint,
generate_shared_inbox_url,
objects::community::ApubCommunity,
EndpointType,
}
// Double check for duplicate community actor_ids
- let community_actor_id = generate_apub_endpoint(
+ let community_actor_id = generate_local_apub_endpoint(
EndpointType::Community,
&data.name,
&context.settings().get_protocol_and_hostname(),
use actix_web::web::Data;
use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt_opt};
use lemmy_apub::{
- build_actor_id_from_shortname,
fetcher::object_id::ObjectId,
+ get_actor_id_from_name,
objects::community::ApubCommunity,
- EndpointType,
};
+use lemmy_apub_lib::webfinger::WebfingerType;
use lemmy_db_schema::{
from_opt_str_to_opt_enum,
traits::DeleteableOrRemoveable,
None => {
let name = data.name.to_owned().unwrap_or_else(|| "main".to_string());
let community_actor_id =
- build_actor_id_from_shortname(EndpointType::Community, &name, &context.settings())?;
+ get_actor_id_from_name(WebfingerType::Group, &name, context).await?;
ObjectId::<ApubCommunity>::new(community_actor_id)
.dereference(context, &mut 0)
CreateOrUpdateType,
},
fetcher::post_or_comment::PostOrComment,
- generate_apub_endpoint,
+ generate_local_apub_endpoint,
EndpointType,
};
use lemmy_db_schema::{
let inserted_post_id = inserted_post.id;
let protocol_and_hostname = context.settings().get_protocol_and_hostname();
let updated_post = blocking(context.pool(), move |conn| -> Result<Post, LemmyError> {
- let apub_id = generate_apub_endpoint(
+ let apub_id = generate_local_apub_endpoint(
EndpointType::Post,
&inserted_post_id.to_string(),
&protocol_and_hostname,
use crate::PerformCrud;
use actix_web::web::Data;
use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, mark_post_as_read, post::*};
-use lemmy_apub::{build_actor_id_from_shortname, EndpointType};
+use lemmy_apub::get_actor_id_from_name;
+use lemmy_apub_lib::webfinger::WebfingerType;
use lemmy_db_schema::{
from_opt_str_to_opt_enum,
traits::DeleteableOrRemoveable,
let page = data.page;
let limit = data.limit;
let community_id = data.community_id;
- let community_actor_id = data
- .community_name
- .as_ref()
- .map(|t| build_actor_id_from_shortname(EndpointType::Community, t, &context.settings()).ok())
- .unwrap_or(None);
+ let community_actor_id = if let Some(name) = &data.community_name {
+ get_actor_id_from_name(WebfingerType::Group, name, context)
+ .await
+ .ok()
+ } else {
+ None
+ };
let saved_only = data.saved_only;
let mut posts = blocking(context.pool(), move |conn| {
private_message::create_or_update::CreateOrUpdatePrivateMessage,
CreateOrUpdateType,
},
- generate_apub_endpoint,
+ generate_local_apub_endpoint,
EndpointType,
};
use lemmy_db_schema::{
let updated_private_message = blocking(
context.pool(),
move |conn| -> Result<PrivateMessage, LemmyError> {
- let apub_id = generate_apub_endpoint(
+ let apub_id = generate_local_apub_endpoint(
EndpointType::PrivateMessage,
&inserted_private_message_id.to_string(),
&protocol_and_hostname,
use actix_web::web::Data;
use lemmy_api_common::{blocking, honeypot_check, password_length_check, person::*};
use lemmy_apub::{
- generate_apub_endpoint,
generate_followers_url,
generate_inbox_url,
+ generate_local_apub_endpoint,
generate_shared_inbox_url,
EndpointType,
};
if !is_valid_actor_name(&data.username, context.settings().actor_name_max_length) {
return Err(ApiError::err_plain("invalid_username").into());
}
- let actor_id = generate_apub_endpoint(
+ let actor_id = generate_local_apub_endpoint(
EndpointType::Person,
&data.username,
&context.settings().get_protocol_and_hostname(),
Ok(c) => c,
Err(_e) => {
let default_community_name = "main";
- let actor_id = generate_apub_endpoint(
+ let actor_id = generate_local_apub_endpoint(
EndpointType::Community,
default_community_name,
&protocol_and_hostname,
use actix_web::web::Data;
use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, person::*};
use lemmy_apub::{
- build_actor_id_from_shortname,
fetcher::object_id::ObjectId,
+ get_actor_id_from_name,
objects::person::ApubPerson,
- EndpointType,
};
+use lemmy_apub_lib::webfinger::WebfingerType;
use lemmy_db_schema::{from_opt_str_to_opt_enum, SortType};
use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder};
use lemmy_db_views_actor::{
.username
.to_owned()
.unwrap_or_else(|| "admin".to_string());
- let actor_id =
- build_actor_id_from_shortname(EndpointType::Person, &name, &context.settings())?;
+ let actor_id = get_actor_id_from_name(WebfingerType::Person, &name, context).await?;
let person = ObjectId::<ApubPerson>::new(actor_id)
.dereference(context, &mut 0)
use crate::fetcher::post_or_comment::PostOrComment;
use anyhow::{anyhow, Context};
use lemmy_api_common::blocking;
-use lemmy_apub_lib::{activity_queue::send_activity, traits::ActorType};
+use lemmy_apub_lib::{
+ activity_queue::send_activity,
+ traits::ActorType,
+ webfinger::{webfinger_resolve_actor, WebfingerType},
+};
use lemmy_db_schema::{
newtypes::{CommunityId, DbUrl},
source::{activity::Activity, person::Person},
}
/// Generates an apub endpoint for a given domain, IE xyz.tld
-fn generate_apub_endpoint_for_domain(
+pub fn generate_local_apub_endpoint(
endpoint_type: EndpointType,
name: &str,
domain: &str,
Ok(Url::parse(&format!("{}/{}/{}", domain, point, name))?.into())
}
-/// Generates the ActivityPub ID for a given object type and ID.
-pub fn generate_apub_endpoint(
- endpoint_type: EndpointType,
- name: &str,
- protocol_and_hostname: &str,
-) -> Result<DbUrl, ParseError> {
- generate_apub_endpoint_for_domain(endpoint_type, name, protocol_and_hostname)
-}
-
pub fn generate_followers_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
Ok(Url::parse(&format!("{}/followers", actor_id))?.into())
}
/// Takes in a shortname of the type dessalines@xyz.tld or dessalines (assumed to be local), and outputs the actor id.
/// Used in the API for communities and users.
-pub fn build_actor_id_from_shortname(
- endpoint_type: EndpointType,
+pub async fn get_actor_id_from_name(
+ webfinger_type: WebfingerType,
short_name: &str,
- settings: &Settings,
-) -> Result<DbUrl, ParseError> {
+ context: &LemmyContext,
+) -> Result<DbUrl, LemmyError> {
let split = short_name.split('@').collect::<Vec<&str>>();
let name = split[0];
// If there's no @, its local
- let domain = if split.len() == 1 {
- settings.get_protocol_and_hostname()
+ if split.len() == 1 {
+ let domain = context.settings().get_protocol_and_hostname();
+ let endpoint_type = match webfinger_type {
+ WebfingerType::Person => EndpointType::Person,
+ WebfingerType::Group => EndpointType::Community,
+ };
+ Ok(generate_local_apub_endpoint(endpoint_type, name, &domain)?)
} else {
- format!("{}://{}", settings.get_protocol_string(), split[1])
- };
-
- generate_apub_endpoint_for_domain(endpoint_type, name, &domain)
+ let protocol = context.settings().get_protocol_string();
+ Ok(
+ webfinger_resolve_actor(name, split[1], webfinger_type, context.client(), protocol)
+ .await?
+ .into(),
+ )
+ }
}
/// Store a sent or received activity in the database, for logging purposes. These records are not
*,
};
use lemmy_apub::{
- generate_apub_endpoint,
generate_followers_url,
generate_inbox_url,
+ generate_local_apub_endpoint,
generate_shared_inbox_url,
EndpointType,
};
let form = PersonForm {
name: cperson.name.to_owned(),
- actor_id: Some(generate_apub_endpoint(
+ actor_id: Some(generate_local_apub_endpoint(
EndpointType::Person,
&cperson.name,
protocol_and_hostname,
for ccommunity in &incorrect_communities {
let keypair = generate_actor_keypair()?;
- let community_actor_id = generate_apub_endpoint(
+ let community_actor_id = generate_local_apub_endpoint(
EndpointType::Community,
&ccommunity.name,
protocol_and_hostname,
.load::<Post>(conn)?;
for cpost in &incorrect_posts {
- let apub_id = generate_apub_endpoint(
+ let apub_id = generate_local_apub_endpoint(
EndpointType::Post,
&cpost.id.to_string(),
protocol_and_hostname,
.load::<Comment>(conn)?;
for ccomment in &incorrect_comments {
- let apub_id = generate_apub_endpoint(
+ let apub_id = generate_local_apub_endpoint(
EndpointType::Comment,
&ccomment.id.to_string(),
protocol_and_hostname,
.load::<PrivateMessage>(conn)?;
for cpm in &incorrect_pms {
- let apub_id = generate_apub_endpoint(
+ let apub_id = generate_local_apub_endpoint(
EndpointType::PrivateMessage,
&cpm.id.to_string(),
protocol_and_hostname,