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