mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-25 10:27:20 +00:00
Take correct community uri in shared_inbox, rename fetch_remote* methods
This commit is contained in:
parent
b2d2553305
commit
a85873d294
|
@ -1,10 +1,14 @@
|
|||
use crate::{
|
||||
apub::{
|
||||
community::do_announce, extensions::signatures::sign, insert_activity, is_apub_id_valid,
|
||||
community::do_announce,
|
||||
extensions::signatures::sign,
|
||||
insert_activity,
|
||||
is_apub_id_valid,
|
||||
ActorType,
|
||||
},
|
||||
request::retry_custom,
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::base::AnyBase;
|
||||
use actix_web::client::Client;
|
||||
|
|
|
@ -1,21 +1,36 @@
|
|||
use crate::{
|
||||
apub::{
|
||||
activities::{generate_activity_id, send_activity_to_community},
|
||||
create_apub_response, create_apub_tombstone_response, create_tombstone, fetch_webfinger_url,
|
||||
create_apub_response,
|
||||
create_apub_tombstone_response,
|
||||
create_tombstone,
|
||||
fetch_webfinger_url,
|
||||
fetcher::{
|
||||
get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post,
|
||||
get_or_fetch_and_upsert_remote_user,
|
||||
get_or_fetch_and_insert_comment,
|
||||
get_or_fetch_and_insert_post,
|
||||
get_or_fetch_and_upsert_user,
|
||||
},
|
||||
ActorType, ApubLikeableType, ApubObjectType, FromApub, ToApub,
|
||||
ActorType,
|
||||
ApubLikeableType,
|
||||
ApubObjectType,
|
||||
FromApub,
|
||||
ToApub,
|
||||
},
|
||||
blocking,
|
||||
routes::DbPoolParam,
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{
|
||||
activity::{
|
||||
kind::{CreateType, DeleteType, DislikeType, LikeType, RemoveType, UndoType, UpdateType},
|
||||
Create, Delete, Dislike, Like, Remove, Undo, Update,
|
||||
Create,
|
||||
Delete,
|
||||
Dislike,
|
||||
Like,
|
||||
Remove,
|
||||
Undo,
|
||||
Update,
|
||||
},
|
||||
base::AnyBase,
|
||||
context,
|
||||
|
@ -124,7 +139,7 @@ impl FromApub for CommentForm {
|
|||
.as_single_xsd_any_uri()
|
||||
.unwrap();
|
||||
|
||||
let creator = get_or_fetch_and_upsert_remote_user(creator_actor_id, client, pool).await?;
|
||||
let creator = get_or_fetch_and_upsert_user(creator_actor_id, client, pool).await?;
|
||||
|
||||
let mut in_reply_tos = note
|
||||
.in_reply_to()
|
||||
|
@ -137,7 +152,7 @@ impl FromApub for CommentForm {
|
|||
let post_ap_id = in_reply_tos.next().unwrap();
|
||||
|
||||
// This post, or the parent comment might not yet exist on this server yet, fetch them.
|
||||
let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
|
||||
let post = get_or_fetch_and_insert_post(&post_ap_id, client, pool).await?;
|
||||
|
||||
// The 2nd item, if it exists, is the parent comment apub_id
|
||||
// For deeply nested comments, FromApub automatically gets called recursively
|
||||
|
@ -145,7 +160,7 @@ impl FromApub for CommentForm {
|
|||
Some(parent_comment_uri) => {
|
||||
let parent_comment_ap_id = &parent_comment_uri;
|
||||
let parent_comment =
|
||||
get_or_fetch_and_insert_remote_comment(&parent_comment_ap_id, client, pool).await?;
|
||||
get_or_fetch_and_insert_comment(&parent_comment_ap_id, client, pool).await?;
|
||||
|
||||
Some(parent_comment.id)
|
||||
}
|
||||
|
@ -558,7 +573,7 @@ async fn collect_non_local_mentions_and_addresses(
|
|||
debug!("mention actor_id: {}", actor_id);
|
||||
addressed_ccs.push(actor_id.to_owned().to_string());
|
||||
|
||||
let mention_user = get_or_fetch_and_upsert_remote_user(&actor_id, client, pool).await?;
|
||||
let mention_user = get_or_fetch_and_upsert_user(&actor_id, client, pool).await?;
|
||||
let shared_inbox = mention_user.get_shared_inbox_url();
|
||||
|
||||
mention_inboxes.push(shared_inbox);
|
||||
|
|
|
@ -1,20 +1,33 @@
|
|||
use crate::{
|
||||
apub::{
|
||||
activities::{generate_activity_id, send_activity},
|
||||
create_apub_response, create_apub_tombstone_response, create_tombstone,
|
||||
create_apub_response,
|
||||
create_apub_tombstone_response,
|
||||
create_tombstone,
|
||||
extensions::group_extensions::GroupExtension,
|
||||
fetcher::get_or_fetch_and_upsert_remote_user,
|
||||
get_shared_inbox, insert_activity, ActorType, FromApub, GroupExt, ToApub,
|
||||
fetcher::get_or_fetch_and_upsert_user,
|
||||
get_shared_inbox,
|
||||
insert_activity,
|
||||
ActorType,
|
||||
FromApub,
|
||||
GroupExt,
|
||||
ToApub,
|
||||
},
|
||||
blocking,
|
||||
routes::DbPoolParam,
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_ext::Ext2;
|
||||
use activitystreams_new::{
|
||||
activity::{
|
||||
kind::{AcceptType, AnnounceType, DeleteType, LikeType, RemoveType, UndoType},
|
||||
Accept, Announce, Delete, Follow, Remove, Undo,
|
||||
Accept,
|
||||
Announce,
|
||||
Delete,
|
||||
Follow,
|
||||
Remove,
|
||||
Undo,
|
||||
},
|
||||
actor::{kind::GroupType, ApActor, Endpoints, Group},
|
||||
base::{AnyBase, BaseExt},
|
||||
|
@ -324,7 +337,7 @@ impl FromApub for CommunityForm {
|
|||
.as_xsd_any_uri()
|
||||
.unwrap();
|
||||
|
||||
let creator = get_or_fetch_and_upsert_remote_user(creator_uri, client, pool).await?;
|
||||
let creator = get_or_fetch_and_upsert_user(creator_uri, client, pool).await?;
|
||||
|
||||
Ok(CommunityForm {
|
||||
name: group
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
use crate::{
|
||||
api::site::SearchResponse,
|
||||
apub::{
|
||||
is_apub_id_valid, ActorType, FromApub, GroupExt, PageExt, PersonExt, APUB_JSON_CONTENT_TYPE,
|
||||
is_apub_id_valid,
|
||||
ActorType,
|
||||
FromApub,
|
||||
GroupExt,
|
||||
PageExt,
|
||||
PersonExt,
|
||||
APUB_JSON_CONTENT_TYPE,
|
||||
},
|
||||
blocking,
|
||||
request::{retry, RecvError},
|
||||
routes::nodeinfo::{NodeInfo, NodeInfoWellKnown},
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{base::BaseExt, object::Note, prelude::*};
|
||||
use actix_web::client::Client;
|
||||
|
@ -22,7 +29,9 @@ use lemmy_db::{
|
|||
post_view::PostView,
|
||||
user::{UserForm, User_},
|
||||
user_view::UserView,
|
||||
Crud, Joinable, SearchType,
|
||||
Crud,
|
||||
Joinable,
|
||||
SearchType,
|
||||
};
|
||||
use lemmy_utils::get_apub_protocol_string;
|
||||
use log::debug;
|
||||
|
@ -140,7 +149,7 @@ pub async fn search_by_apub_id(
|
|||
SearchAcceptedObjects::Person(p) => {
|
||||
let user_uri = p.inner.id(domain)?.unwrap();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||
let user = get_or_fetch_and_upsert_user(&user_uri, client, pool).await?;
|
||||
|
||||
response.users = vec![blocking(pool, move |conn| UserView::read(conn, user.id)).await??];
|
||||
|
||||
|
@ -149,7 +158,7 @@ pub async fn search_by_apub_id(
|
|||
SearchAcceptedObjects::Group(g) => {
|
||||
let community_uri = g.inner.id(domain)?.unwrap();
|
||||
|
||||
let community = get_or_fetch_and_upsert_remote_community(community_uri, client, pool).await?;
|
||||
let community = get_or_fetch_and_upsert_community(community_uri, client, pool).await?;
|
||||
|
||||
// TODO Maybe at some point in the future, fetch all the history of a community
|
||||
// fetch_community_outbox(&c, conn)?;
|
||||
|
@ -191,21 +200,21 @@ pub async fn search_by_apub_id(
|
|||
Ok(response)
|
||||
}
|
||||
|
||||
pub async fn get_or_fetch_and_upsert_remote_actor(
|
||||
pub async fn get_or_fetch_and_upsert_actor(
|
||||
apub_id: &Url,
|
||||
client: &Client,
|
||||
pool: &DbPool,
|
||||
) -> Result<Box<dyn ActorType>, LemmyError> {
|
||||
let user = get_or_fetch_and_upsert_remote_user(apub_id, client, pool).await;
|
||||
let user = get_or_fetch_and_upsert_user(apub_id, client, pool).await;
|
||||
let actor: Box<dyn ActorType> = match user {
|
||||
Ok(u) => Box::new(u),
|
||||
Err(_) => Box::new(get_or_fetch_and_upsert_remote_community(apub_id, client, pool).await?),
|
||||
Err(_) => Box::new(get_or_fetch_and_upsert_community(apub_id, client, pool).await?),
|
||||
};
|
||||
Ok(actor)
|
||||
}
|
||||
|
||||
/// Check if a remote user exists, create if not found, if its too old update it.Fetch a user, insert/update it in the database and return the user.
|
||||
pub async fn get_or_fetch_and_upsert_remote_user(
|
||||
pub async fn get_or_fetch_and_upsert_user(
|
||||
apub_id: &Url,
|
||||
client: &Client,
|
||||
pool: &DbPool,
|
||||
|
@ -257,7 +266,7 @@ fn should_refetch_actor(last_refreshed: NaiveDateTime) -> bool {
|
|||
}
|
||||
|
||||
/// Check if a remote community exists, create if not found, if its too old update it.Fetch a community, insert/update it in the database and return the community.
|
||||
pub async fn get_or_fetch_and_upsert_remote_community(
|
||||
pub async fn get_or_fetch_and_upsert_community(
|
||||
apub_id: &Url,
|
||||
client: &Client,
|
||||
pool: &DbPool,
|
||||
|
@ -299,7 +308,7 @@ pub async fn get_or_fetch_and_upsert_remote_community(
|
|||
let mut creator_and_moderators = Vec::new();
|
||||
|
||||
for uri in creator_and_moderator_uris {
|
||||
let c_or_m = get_or_fetch_and_upsert_remote_user(uri, client, pool).await?;
|
||||
let c_or_m = get_or_fetch_and_upsert_user(uri, client, pool).await?;
|
||||
|
||||
creator_and_moderators.push(c_or_m);
|
||||
}
|
||||
|
@ -333,7 +342,7 @@ fn upsert_post(post_form: &PostForm, conn: &PgConnection) -> Result<Post, LemmyE
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn get_or_fetch_and_insert_remote_post(
|
||||
pub async fn get_or_fetch_and_insert_post(
|
||||
post_ap_id: &Url,
|
||||
client: &Client,
|
||||
pool: &DbPool,
|
||||
|
@ -368,7 +377,7 @@ fn upsert_comment(comment_form: &CommentForm, conn: &PgConnection) -> Result<Com
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn get_or_fetch_and_insert_remote_comment(
|
||||
pub async fn get_or_fetch_and_insert_comment(
|
||||
comment_ap_id: &Url,
|
||||
client: &Client,
|
||||
pool: &DbPool,
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
use crate::{
|
||||
apub::inbox::{
|
||||
activities::{
|
||||
create::receive_create, delete::receive_delete, dislike::receive_dislike, like::receive_like,
|
||||
remove::receive_remove, undo::receive_undo, update::receive_update,
|
||||
create::receive_create,
|
||||
delete::receive_delete,
|
||||
dislike::receive_dislike,
|
||||
like::receive_like,
|
||||
remove::receive_remove,
|
||||
undo::receive_undo,
|
||||
update::receive_update,
|
||||
},
|
||||
shared_inbox::receive_unhandled_activity,
|
||||
},
|
||||
routes::ChatServerParam,
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{activity::*, base::AnyBase, prelude::ExtendsExt};
|
||||
use actix_web::{client::Client, HttpResponse};
|
||||
|
|
|
@ -5,9 +5,13 @@ use crate::{
|
|||
},
|
||||
apub::{
|
||||
inbox::shared_inbox::{
|
||||
announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
|
||||
announce_if_community_is_local,
|
||||
get_user_from_activity,
|
||||
receive_unhandled_activity,
|
||||
},
|
||||
ActorType, FromApub, PageExt,
|
||||
ActorType,
|
||||
FromApub,
|
||||
PageExt,
|
||||
},
|
||||
blocking,
|
||||
routes::ChatServerParam,
|
||||
|
@ -15,7 +19,8 @@ use crate::{
|
|||
server::{SendComment, SendPost},
|
||||
UserOperation,
|
||||
},
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{activity::Create, base::AnyBase, object::Note, prelude::*};
|
||||
use actix_web::{client::Client, HttpResponse};
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
use crate::{
|
||||
api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
|
||||
apub::{
|
||||
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
|
||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||
inbox::shared_inbox::{
|
||||
announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
|
||||
announce_if_community_is_local,
|
||||
get_user_from_activity,
|
||||
receive_unhandled_activity,
|
||||
},
|
||||
ActorType, FromApub, GroupExt, PageExt,
|
||||
ActorType,
|
||||
FromApub,
|
||||
GroupExt,
|
||||
PageExt,
|
||||
},
|
||||
blocking,
|
||||
routes::ChatServerParam,
|
||||
|
@ -13,7 +18,8 @@ use crate::{
|
|||
server::{SendComment, SendCommunityRoomMessage, SendPost},
|
||||
UserOperation,
|
||||
},
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{activity::Delete, base::AnyBase, object::Note, prelude::*};
|
||||
use actix_web::{client::Client, HttpResponse};
|
||||
|
@ -56,7 +62,7 @@ async fn receive_delete_post(
|
|||
.await?
|
||||
.get_ap_id()?;
|
||||
|
||||
let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
|
||||
let post = get_or_fetch_and_insert_post(&post_ap_id, client, pool).await?;
|
||||
|
||||
let post_form = PostForm {
|
||||
name: post.name.to_owned(),
|
||||
|
@ -110,7 +116,7 @@ async fn receive_delete_comment(
|
|||
.await?
|
||||
.get_ap_id()?;
|
||||
|
||||
let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
|
||||
let comment = get_or_fetch_and_insert_comment(&comment_ap_id, client, pool).await?;
|
||||
|
||||
let comment_form = CommentForm {
|
||||
content: comment.content.to_owned(),
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
use crate::{
|
||||
api::{comment::CommentResponse, post::PostResponse},
|
||||
apub::{
|
||||
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
|
||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||
inbox::shared_inbox::{
|
||||
announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
|
||||
announce_if_community_is_local,
|
||||
get_user_from_activity,
|
||||
receive_unhandled_activity,
|
||||
},
|
||||
ActorType, FromApub, PageExt,
|
||||
ActorType,
|
||||
FromApub,
|
||||
PageExt,
|
||||
},
|
||||
blocking,
|
||||
routes::ChatServerParam,
|
||||
|
@ -13,7 +17,8 @@ use crate::{
|
|||
server::{SendComment, SendPost},
|
||||
UserOperation,
|
||||
},
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{activity::Dislike, base::AnyBase, object::Note, prelude::*};
|
||||
use actix_web::{client::Client, HttpResponse};
|
||||
|
@ -50,7 +55,7 @@ async fn receive_dislike_post(
|
|||
|
||||
let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
|
||||
|
||||
let post_id = get_or_fetch_and_insert_remote_post(&post.get_ap_id()?, client, pool)
|
||||
let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
|
||||
.await?
|
||||
.id;
|
||||
|
||||
|
@ -91,7 +96,7 @@ async fn receive_dislike_comment(
|
|||
|
||||
let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?;
|
||||
|
||||
let comment_id = get_or_fetch_and_insert_remote_comment(&comment.get_ap_id()?, client, pool)
|
||||
let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
|
||||
.await?
|
||||
.id;
|
||||
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
use crate::{
|
||||
api::{comment::CommentResponse, post::PostResponse},
|
||||
apub::{
|
||||
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
|
||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||
inbox::shared_inbox::{
|
||||
announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
|
||||
announce_if_community_is_local,
|
||||
get_user_from_activity,
|
||||
receive_unhandled_activity,
|
||||
},
|
||||
ActorType, FromApub, PageExt,
|
||||
ActorType,
|
||||
FromApub,
|
||||
PageExt,
|
||||
},
|
||||
blocking,
|
||||
routes::ChatServerParam,
|
||||
|
@ -13,7 +17,8 @@ use crate::{
|
|||
server::{SendComment, SendPost},
|
||||
UserOperation,
|
||||
},
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{activity::Like, base::AnyBase, object::Note, prelude::*};
|
||||
use actix_web::{client::Client, HttpResponse};
|
||||
|
@ -50,7 +55,7 @@ async fn receive_like_post(
|
|||
|
||||
let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
|
||||
|
||||
let post_id = get_or_fetch_and_insert_remote_post(&post.get_ap_id()?, client, pool)
|
||||
let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
|
||||
.await?
|
||||
.id;
|
||||
|
||||
|
@ -91,7 +96,7 @@ async fn receive_like_comment(
|
|||
|
||||
let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?;
|
||||
|
||||
let comment_id = get_or_fetch_and_insert_remote_comment(&comment.get_ap_id()?, client, pool)
|
||||
let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
|
||||
.await?
|
||||
.id;
|
||||
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
use crate::{
|
||||
api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
|
||||
apub::{
|
||||
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
|
||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||
inbox::shared_inbox::{
|
||||
announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
|
||||
announce_if_community_is_local,
|
||||
get_user_from_activity,
|
||||
receive_unhandled_activity,
|
||||
},
|
||||
ActorType, FromApub, GroupExt, PageExt,
|
||||
ActorType,
|
||||
FromApub,
|
||||
GroupExt,
|
||||
PageExt,
|
||||
},
|
||||
blocking,
|
||||
routes::ChatServerParam,
|
||||
|
@ -13,7 +18,8 @@ use crate::{
|
|||
server::{SendComment, SendCommunityRoomMessage, SendPost},
|
||||
UserOperation,
|
||||
},
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{activity::Remove, base::AnyBase, object::Note, prelude::*};
|
||||
use actix_web::{client::Client, HttpResponse};
|
||||
|
@ -56,7 +62,7 @@ async fn receive_remove_post(
|
|||
.await?
|
||||
.get_ap_id()?;
|
||||
|
||||
let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
|
||||
let post = get_or_fetch_and_insert_post(&post_ap_id, client, pool).await?;
|
||||
|
||||
let post_form = PostForm {
|
||||
name: post.name.to_owned(),
|
||||
|
@ -110,7 +116,7 @@ async fn receive_remove_comment(
|
|||
.await?
|
||||
.get_ap_id()?;
|
||||
|
||||
let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
|
||||
let comment = get_or_fetch_and_insert_comment(&comment_ap_id, client, pool).await?;
|
||||
|
||||
let comment_form = CommentForm {
|
||||
content: comment.content.to_owned(),
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
use crate::{
|
||||
api::{comment::CommentResponse, community::CommunityResponse, post::PostResponse},
|
||||
apub::{
|
||||
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
|
||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||
inbox::shared_inbox::{
|
||||
announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
|
||||
announce_if_community_is_local,
|
||||
get_user_from_activity,
|
||||
receive_unhandled_activity,
|
||||
},
|
||||
ActorType, FromApub, GroupExt, PageExt,
|
||||
ActorType,
|
||||
FromApub,
|
||||
GroupExt,
|
||||
PageExt,
|
||||
},
|
||||
blocking,
|
||||
routes::ChatServerParam,
|
||||
|
@ -13,7 +18,8 @@ use crate::{
|
|||
server::{SendComment, SendCommunityRoomMessage, SendPost},
|
||||
UserOperation,
|
||||
},
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{activity::*, base::AnyBase, object::Note, prelude::*};
|
||||
use actix_web::{client::Client, HttpResponse};
|
||||
|
@ -25,7 +31,8 @@ use lemmy_db::{
|
|||
naive_now,
|
||||
post::{Post, PostForm, PostLike, PostLikeForm},
|
||||
post_view::PostView,
|
||||
Crud, Likeable,
|
||||
Crud,
|
||||
Likeable,
|
||||
};
|
||||
|
||||
pub async fn receive_undo(
|
||||
|
@ -120,7 +127,7 @@ async fn receive_undo_delete_comment(
|
|||
.await?
|
||||
.get_ap_id()?;
|
||||
|
||||
let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
|
||||
let comment = get_or_fetch_and_insert_comment(&comment_ap_id, client, pool).await?;
|
||||
|
||||
let comment_form = CommentForm {
|
||||
content: comment.content.to_owned(),
|
||||
|
@ -178,7 +185,7 @@ async fn receive_undo_remove_comment(
|
|||
.await?
|
||||
.get_ap_id()?;
|
||||
|
||||
let comment = get_or_fetch_and_insert_remote_comment(&comment_ap_id, client, pool).await?;
|
||||
let comment = get_or_fetch_and_insert_comment(&comment_ap_id, client, pool).await?;
|
||||
|
||||
let comment_form = CommentForm {
|
||||
content: comment.content.to_owned(),
|
||||
|
@ -236,7 +243,7 @@ async fn receive_undo_delete_post(
|
|||
.await?
|
||||
.get_ap_id()?;
|
||||
|
||||
let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
|
||||
let post = get_or_fetch_and_insert_post(&post_ap_id, client, pool).await?;
|
||||
|
||||
let post_form = PostForm {
|
||||
name: post.name.to_owned(),
|
||||
|
@ -291,7 +298,7 @@ async fn receive_undo_remove_post(
|
|||
.await?
|
||||
.get_ap_id()?;
|
||||
|
||||
let post = get_or_fetch_and_insert_remote_post(&post_ap_id, client, pool).await?;
|
||||
let post = get_or_fetch_and_insert_post(&post_ap_id, client, pool).await?;
|
||||
|
||||
let post_form = PostForm {
|
||||
name: post.name.to_owned(),
|
||||
|
@ -472,7 +479,7 @@ async fn receive_undo_like_comment(
|
|||
|
||||
let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?;
|
||||
|
||||
let comment_id = get_or_fetch_and_insert_remote_comment(&comment.get_ap_id()?, client, pool)
|
||||
let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
|
||||
.await?
|
||||
.id;
|
||||
|
||||
|
@ -518,7 +525,7 @@ async fn receive_undo_like_post(
|
|||
|
||||
let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
|
||||
|
||||
let post_id = get_or_fetch_and_insert_remote_post(&post.get_ap_id()?, client, pool)
|
||||
let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
|
||||
.await?
|
||||
.id;
|
||||
|
||||
|
|
|
@ -4,11 +4,15 @@ use crate::{
|
|||
post::PostResponse,
|
||||
},
|
||||
apub::{
|
||||
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
|
||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||
inbox::shared_inbox::{
|
||||
announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
|
||||
announce_if_community_is_local,
|
||||
get_user_from_activity,
|
||||
receive_unhandled_activity,
|
||||
},
|
||||
ActorType, FromApub, PageExt,
|
||||
ActorType,
|
||||
FromApub,
|
||||
PageExt,
|
||||
},
|
||||
blocking,
|
||||
routes::ChatServerParam,
|
||||
|
@ -16,7 +20,8 @@ use crate::{
|
|||
server::{SendComment, SendPost},
|
||||
UserOperation,
|
||||
},
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{activity::Update, base::AnyBase, object::Note, prelude::*};
|
||||
use actix_web::{client::Client, HttpResponse};
|
||||
|
@ -54,7 +59,7 @@ async fn receive_update_post(
|
|||
|
||||
let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
|
||||
|
||||
let post_id = get_or_fetch_and_insert_remote_post(&post.get_ap_id()?, client, pool)
|
||||
let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
|
||||
.await?
|
||||
.id;
|
||||
|
||||
|
@ -86,7 +91,7 @@ async fn receive_update_comment(
|
|||
|
||||
let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?;
|
||||
|
||||
let comment_id = get_or_fetch_and_insert_remote_comment(&comment.get_ap_id()?, client, pool)
|
||||
let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
|
||||
.await?
|
||||
.id;
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use crate::{
|
||||
apub::{
|
||||
extensions::signatures::verify,
|
||||
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
|
||||
insert_activity, ActorType,
|
||||
fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user},
|
||||
insert_activity,
|
||||
ActorType,
|
||||
},
|
||||
blocking,
|
||||
routes::{ChatServerParam, DbPoolParam},
|
||||
|
@ -71,8 +72,8 @@ pub async fn community_inbox(
|
|||
let user_uri = follow.actor()?.as_single_xsd_any_uri().unwrap();
|
||||
let community_uri = follow.object().as_single_xsd_any_uri().unwrap();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &client, &db).await?;
|
||||
let community = get_or_fetch_and_upsert_remote_community(community_uri, &client, &db).await?;
|
||||
let user = get_or_fetch_and_upsert_user(&user_uri, &client, &db).await?;
|
||||
let community = get_or_fetch_and_upsert_community(community_uri, &client, &db).await?;
|
||||
|
||||
verify(&request, &user)?;
|
||||
|
||||
|
|
|
@ -3,18 +3,25 @@ use crate::{
|
|||
community::do_announce,
|
||||
extensions::signatures::verify,
|
||||
fetcher::{
|
||||
get_or_fetch_and_upsert_remote_actor, get_or_fetch_and_upsert_remote_community,
|
||||
get_or_fetch_and_upsert_remote_user,
|
||||
get_or_fetch_and_upsert_actor,
|
||||
get_or_fetch_and_upsert_community,
|
||||
get_or_fetch_and_upsert_user,
|
||||
},
|
||||
inbox::activities::{
|
||||
announce::receive_announce, create::receive_create, delete::receive_delete,
|
||||
dislike::receive_dislike, like::receive_like, remove::receive_remove, undo::receive_undo,
|
||||
announce::receive_announce,
|
||||
create::receive_create,
|
||||
delete::receive_delete,
|
||||
dislike::receive_dislike,
|
||||
like::receive_like,
|
||||
remove::receive_remove,
|
||||
undo::receive_undo,
|
||||
update::receive_update,
|
||||
},
|
||||
insert_activity,
|
||||
},
|
||||
routes::{ChatServerParam, DbPoolParam},
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{
|
||||
activity::{ActorAndObject, ActorAndObjectRef},
|
||||
|
@ -27,6 +34,7 @@ use lemmy_db::user::User_;
|
|||
use log::debug;
|
||||
use serde::Serialize;
|
||||
use std::fmt::Debug;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
|
@ -61,7 +69,7 @@ pub async fn shared_inbox(
|
|||
let sender = &activity.actor()?.to_owned().single_xsd_any_uri().unwrap();
|
||||
|
||||
// TODO: pass this actor in instead of using get_user_from_activity()
|
||||
let actor = get_or_fetch_and_upsert_remote_actor(sender, &client, &pool).await?;
|
||||
let actor = get_or_fetch_and_upsert_actor(sender, &client, &pool).await?;
|
||||
verify(&request, actor.as_ref())?;
|
||||
|
||||
insert_activity(actor.user_id(), activity.clone(), false, &pool).await?;
|
||||
|
@ -101,7 +109,7 @@ where
|
|||
{
|
||||
let actor = activity.actor()?;
|
||||
let user_uri = actor.as_single_xsd_any_uri().unwrap();
|
||||
get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await
|
||||
get_or_fetch_and_upsert_user(&user_uri, client, pool).await
|
||||
}
|
||||
|
||||
pub(in crate::apub::inbox) async fn announce_if_community_is_local<T, Kind>(
|
||||
|
@ -118,8 +126,13 @@ where
|
|||
{
|
||||
let cc = activity.cc().unwrap();
|
||||
let cc = cc.as_many().unwrap();
|
||||
let community_uri = cc.first().unwrap().as_xsd_any_uri().unwrap();
|
||||
let community = get_or_fetch_and_upsert_remote_community(&community_uri, client, pool).await?;
|
||||
let community_followers_uri = cc.first().unwrap().as_xsd_any_uri().unwrap();
|
||||
// TODO: this is hacky but seems to be the only way to get the community ID
|
||||
let community_uri = community_followers_uri
|
||||
.to_string()
|
||||
.replace("/followers", "");
|
||||
let community =
|
||||
get_or_fetch_and_upsert_community(&Url::parse(&community_uri)?, client, pool).await?;
|
||||
|
||||
if community.local {
|
||||
do_announce(activity.into_any_base()?, &community, &user, client, pool).await?;
|
||||
|
|
|
@ -2,13 +2,15 @@ use crate::{
|
|||
api::user::PrivateMessageResponse,
|
||||
apub::{
|
||||
extensions::signatures::verify,
|
||||
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
|
||||
insert_activity, FromApub,
|
||||
fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user},
|
||||
insert_activity,
|
||||
FromApub,
|
||||
},
|
||||
blocking,
|
||||
routes::{ChatServerParam, DbPoolParam},
|
||||
websocket::{server::SendUserRoomMessage, UserOperation},
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{
|
||||
activity::{Accept, Create, Delete, Undo, Update},
|
||||
|
@ -22,7 +24,8 @@ use lemmy_db::{
|
|||
private_message::{PrivateMessage, PrivateMessageForm},
|
||||
private_message_view::PrivateMessageView,
|
||||
user::User_,
|
||||
Crud, Followable,
|
||||
Crud,
|
||||
Followable,
|
||||
};
|
||||
use log::debug;
|
||||
use serde::Deserialize;
|
||||
|
@ -79,7 +82,7 @@ async fn receive_accept(
|
|||
) -> Result<HttpResponse, LemmyError> {
|
||||
let community_uri = accept.actor()?.to_owned().single_xsd_any_uri().unwrap();
|
||||
|
||||
let community = get_or_fetch_and_upsert_remote_community(&community_uri, client, pool).await?;
|
||||
let community = get_or_fetch_and_upsert_community(&community_uri, client, pool).await?;
|
||||
verify(request, &community)?;
|
||||
|
||||
let username = username.to_owned();
|
||||
|
@ -113,7 +116,7 @@ async fn receive_create_private_message(
|
|||
let user_uri = &create.actor()?.to_owned().single_xsd_any_uri().unwrap();
|
||||
let note = Note::from_any_base(create.object().as_one().unwrap().to_owned())?.unwrap();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(user_uri, client, pool).await?;
|
||||
let user = get_or_fetch_and_upsert_user(user_uri, client, pool).await?;
|
||||
verify(request, &user)?;
|
||||
|
||||
insert_activity(user.id, create, false, pool).await?;
|
||||
|
@ -154,7 +157,7 @@ async fn receive_update_private_message(
|
|||
let user_uri = &update.actor()?.to_owned().single_xsd_any_uri().unwrap();
|
||||
let note = Note::from_any_base(update.object().as_one().unwrap().to_owned())?.unwrap();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||
let user = get_or_fetch_and_upsert_user(&user_uri, client, pool).await?;
|
||||
verify(request, &user)?;
|
||||
|
||||
insert_activity(user.id, update, false, pool).await?;
|
||||
|
@ -203,7 +206,7 @@ async fn receive_delete_private_message(
|
|||
let user_uri = &delete.actor()?.to_owned().single_xsd_any_uri().unwrap();
|
||||
let note = Note::from_any_base(delete.object().as_one().unwrap().to_owned())?.unwrap();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||
let user = get_or_fetch_and_upsert_user(&user_uri, client, pool).await?;
|
||||
verify(request, &user)?;
|
||||
|
||||
insert_activity(user.id, delete, false, pool).await?;
|
||||
|
@ -265,7 +268,7 @@ async fn receive_undo_delete_private_message(
|
|||
let note = Note::from_any_base(delete.object().as_one().unwrap().to_owned())?.unwrap();
|
||||
let user_uri = &delete.actor()?.to_owned().single_xsd_any_uri().unwrap();
|
||||
|
||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||
let user = get_or_fetch_and_upsert_user(&user_uri, client, pool).await?;
|
||||
verify(request, &user)?;
|
||||
|
||||
insert_activity(user.id, delete, false, pool).await?;
|
||||
|
|
|
@ -17,7 +17,8 @@ use crate::{
|
|||
blocking,
|
||||
request::{retry, RecvError},
|
||||
routes::webfinger::WebFingerResponse,
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_ext::{Ext1, Ext2};
|
||||
use activitystreams_new::{
|
||||
|
|
|
@ -1,20 +1,34 @@
|
|||
use crate::{
|
||||
apub::{
|
||||
activities::{generate_activity_id, send_activity_to_community},
|
||||
create_apub_response, create_apub_tombstone_response, create_tombstone,
|
||||
create_apub_response,
|
||||
create_apub_tombstone_response,
|
||||
create_tombstone,
|
||||
extensions::page_extension::PageExtension,
|
||||
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
|
||||
ActorType, ApubLikeableType, ApubObjectType, FromApub, PageExt, ToApub,
|
||||
fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user},
|
||||
ActorType,
|
||||
ApubLikeableType,
|
||||
ApubObjectType,
|
||||
FromApub,
|
||||
PageExt,
|
||||
ToApub,
|
||||
},
|
||||
blocking,
|
||||
routes::DbPoolParam,
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_ext::Ext1;
|
||||
use activitystreams_new::{
|
||||
activity::{
|
||||
kind::{CreateType, DeleteType, DislikeType, LikeType, RemoveType, UndoType, UpdateType},
|
||||
Create, Delete, Dislike, Like, Remove, Undo, Update,
|
||||
Create,
|
||||
Delete,
|
||||
Dislike,
|
||||
Like,
|
||||
Remove,
|
||||
Undo,
|
||||
Update,
|
||||
},
|
||||
context,
|
||||
object::{kind::PageType, Image, Page, Tombstone},
|
||||
|
@ -151,7 +165,7 @@ impl FromApub for PostForm {
|
|||
.as_single_xsd_any_uri()
|
||||
.unwrap();
|
||||
|
||||
let creator = get_or_fetch_and_upsert_remote_user(creator_actor_id, client, pool).await?;
|
||||
let creator = get_or_fetch_and_upsert_user(creator_actor_id, client, pool).await?;
|
||||
|
||||
let community_actor_id = page
|
||||
.inner
|
||||
|
@ -161,8 +175,7 @@ impl FromApub for PostForm {
|
|||
.as_single_xsd_any_uri()
|
||||
.unwrap();
|
||||
|
||||
let community =
|
||||
get_or_fetch_and_upsert_remote_community(community_actor_id, client, pool).await?;
|
||||
let community = get_or_fetch_and_upsert_community(community_actor_id, client, pool).await?;
|
||||
|
||||
let thumbnail_url = match &page.inner.image() {
|
||||
Some(any_image) => Image::from_any_base(any_image.to_owned().as_one().unwrap().to_owned())?
|
||||
|
|
|
@ -2,15 +2,23 @@ use crate::{
|
|||
apub::{
|
||||
activities::{generate_activity_id, send_activity},
|
||||
create_tombstone,
|
||||
fetcher::get_or_fetch_and_upsert_remote_user,
|
||||
insert_activity, ApubObjectType, FromApub, ToApub,
|
||||
fetcher::get_or_fetch_and_upsert_user,
|
||||
insert_activity,
|
||||
ApubObjectType,
|
||||
FromApub,
|
||||
ToApub,
|
||||
},
|
||||
blocking, DbPool, LemmyError,
|
||||
blocking,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_new::{
|
||||
activity::{
|
||||
kind::{CreateType, DeleteType, UndoType, UpdateType},
|
||||
Create, Delete, Undo, Update,
|
||||
Create,
|
||||
Delete,
|
||||
Undo,
|
||||
Update,
|
||||
},
|
||||
context,
|
||||
object::{kind::NoteType, Note, Tombstone},
|
||||
|
@ -76,11 +84,11 @@ impl FromApub for PrivateMessageForm {
|
|||
.single_xsd_any_uri()
|
||||
.unwrap();
|
||||
|
||||
let creator = get_or_fetch_and_upsert_remote_user(&creator_actor_id, client, pool).await?;
|
||||
let creator = get_or_fetch_and_upsert_user(&creator_actor_id, client, pool).await?;
|
||||
|
||||
let recipient_actor_id = note.to().unwrap().clone().single_xsd_any_uri().unwrap();
|
||||
|
||||
let recipient = get_or_fetch_and_upsert_remote_user(&recipient_actor_id, client, pool).await?;
|
||||
let recipient = get_or_fetch_and_upsert_user(&recipient_actor_id, client, pool).await?;
|
||||
|
||||
Ok(PrivateMessageForm {
|
||||
creator_id: creator.id,
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
use crate::{
|
||||
apub::{
|
||||
activities::{generate_activity_id, send_activity},
|
||||
create_apub_response, insert_activity, ActorType, FromApub, PersonExt, ToApub,
|
||||
create_apub_response,
|
||||
insert_activity,
|
||||
ActorType,
|
||||
FromApub,
|
||||
PersonExt,
|
||||
ToApub,
|
||||
},
|
||||
blocking,
|
||||
routes::DbPoolParam,
|
||||
DbPool, LemmyError,
|
||||
DbPool,
|
||||
LemmyError,
|
||||
};
|
||||
use activitystreams_ext::Ext1;
|
||||
use activitystreams_new::{
|
||||
activity::{
|
||||
kind::{FollowType, UndoType},
|
||||
Follow, Undo,
|
||||
Follow,
|
||||
Undo,
|
||||
},
|
||||
actor::{ApActor, Endpoints, Person},
|
||||
context,
|
||||
|
|
Loading…
Reference in a new issue