mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-15 00:43:59 +00:00
Convert comments to new apub lib (including comment activities)
This commit is contained in:
parent
ef8118f40f
commit
2d4c41d2be
11 changed files with 241 additions and 388 deletions
|
@ -157,10 +157,28 @@ impl UserView {
|
||||||
|
|
||||||
pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> {
|
pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> {
|
||||||
use super::user_view::user_fast::dsl::*;
|
use super::user_view::user_fast::dsl::*;
|
||||||
use diesel::sql_types::{Text, Nullable};
|
use diesel::sql_types::{Nullable, Text};
|
||||||
user_fast
|
user_fast
|
||||||
// The select is necessary here to not get back emails
|
// The select is necessary here to not get back emails
|
||||||
.select((id, actor_id, name, avatar, "".into_sql::<Nullable<Text>>(), matrix_user_id, bio, local, admin, banned, show_avatars, send_notifications_to_email, published, number_of_posts, post_score, number_of_comments, comment_score))
|
.select((
|
||||||
|
id,
|
||||||
|
actor_id,
|
||||||
|
name,
|
||||||
|
avatar,
|
||||||
|
"".into_sql::<Nullable<Text>>(),
|
||||||
|
matrix_user_id,
|
||||||
|
bio,
|
||||||
|
local,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
show_avatars,
|
||||||
|
send_notifications_to_email,
|
||||||
|
published,
|
||||||
|
number_of_posts,
|
||||||
|
post_score,
|
||||||
|
number_of_comments,
|
||||||
|
comment_score,
|
||||||
|
))
|
||||||
.filter(admin.eq(true))
|
.filter(admin.eq(true))
|
||||||
.order_by(published)
|
.order_by(published)
|
||||||
.load::<Self>(conn)
|
.load::<Self>(conn)
|
||||||
|
@ -168,9 +186,28 @@ impl UserView {
|
||||||
|
|
||||||
pub fn banned(conn: &PgConnection) -> Result<Vec<Self>, Error> {
|
pub fn banned(conn: &PgConnection) -> Result<Vec<Self>, Error> {
|
||||||
use super::user_view::user_fast::dsl::*;
|
use super::user_view::user_fast::dsl::*;
|
||||||
use diesel::sql_types::{Text, Nullable};
|
use diesel::sql_types::{Nullable, Text};
|
||||||
user_fast
|
user_fast
|
||||||
.select((id, actor_id, name, avatar, "".into_sql::<Nullable<Text>>(), matrix_user_id, bio, local, admin, banned, show_avatars, send_notifications_to_email, published, number_of_posts, post_score, number_of_comments, comment_score))
|
.select((
|
||||||
.filter(banned.eq(true)).load::<Self>(conn)
|
id,
|
||||||
|
actor_id,
|
||||||
|
name,
|
||||||
|
avatar,
|
||||||
|
"".into_sql::<Nullable<Text>>(),
|
||||||
|
matrix_user_id,
|
||||||
|
bio,
|
||||||
|
local,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
show_avatars,
|
||||||
|
send_notifications_to_email,
|
||||||
|
published,
|
||||||
|
number_of_posts,
|
||||||
|
post_score,
|
||||||
|
number_of_comments,
|
||||||
|
comment_score,
|
||||||
|
))
|
||||||
|
.filter(banned.eq(true))
|
||||||
|
.load::<Self>(conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +1,27 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
apub::{
|
apub::{
|
||||||
activities::{populate_object_props, send_activity_to_community},
|
activities::send_activity_to_community,
|
||||||
create_apub_response,
|
create_apub_response, create_apub_tombstone_response, create_tombstone, fetch_webfinger_url,
|
||||||
create_apub_tombstone_response,
|
|
||||||
create_tombstone,
|
|
||||||
fetch_webfinger_url,
|
|
||||||
fetcher::{
|
fetcher::{
|
||||||
get_or_fetch_and_insert_remote_comment,
|
get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post,
|
||||||
get_or_fetch_and_insert_remote_post,
|
|
||||||
get_or_fetch_and_upsert_remote_user,
|
get_or_fetch_and_upsert_remote_user,
|
||||||
},
|
},
|
||||||
ActorType,
|
ActorType, ApubLikeableType, ApubObjectType, FromApub, ToApub,
|
||||||
ApubLikeableType,
|
|
||||||
ApubObjectType,
|
|
||||||
FromApub,
|
|
||||||
ToApub,
|
|
||||||
},
|
},
|
||||||
blocking,
|
blocking,
|
||||||
routes::DbPoolParam,
|
routes::DbPoolParam,
|
||||||
DbPool,
|
DbPool, LemmyError,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams_new::{
|
||||||
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
|
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
|
||||||
|
base::AnyBase,
|
||||||
context,
|
context,
|
||||||
link::Mention,
|
link::Mention,
|
||||||
object::{kind::NoteType, properties::ObjectProperties, Note},
|
object::{kind::NoteType, Note, Tombstone},
|
||||||
|
prelude::*,
|
||||||
|
primitives::XsdAnyUri,
|
||||||
|
public,
|
||||||
};
|
};
|
||||||
use activitystreams_new::object::Tombstone;
|
|
||||||
use actix_web::{body::Body, client::Client, web::Path, HttpResponse};
|
use actix_web::{body::Body, client::Client, web::Path, HttpResponse};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
|
@ -40,6 +34,8 @@ use lemmy_db::{
|
||||||
use lemmy_utils::{convert_datetime, scrape_text_for_mentions, MentionData};
|
use lemmy_utils::{convert_datetime, scrape_text_for_mentions, MentionData};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use serde_json::Error;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct CommentQuery {
|
pub struct CommentQuery {
|
||||||
|
@ -66,8 +62,7 @@ impl ToApub for Comment {
|
||||||
type Response = Note;
|
type Response = Note;
|
||||||
|
|
||||||
async fn to_apub(&self, pool: &DbPool) -> Result<Note, LemmyError> {
|
async fn to_apub(&self, pool: &DbPool) -> Result<Note, LemmyError> {
|
||||||
let mut comment = Note::default();
|
let mut comment = Note::new();
|
||||||
let oprops: &mut ObjectProperties = comment.as_mut();
|
|
||||||
|
|
||||||
let creator_id = self.creator_id;
|
let creator_id = self.creator_id;
|
||||||
let creator = blocking(pool, move |conn| User_::read(conn, creator_id)).await??;
|
let creator = blocking(pool, move |conn| User_::read(conn, creator_id)).await??;
|
||||||
|
@ -88,18 +83,18 @@ impl ToApub for Comment {
|
||||||
in_reply_to_vec.push(parent_comment.ap_id);
|
in_reply_to_vec.push(parent_comment.ap_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
oprops
|
comment
|
||||||
// Not needed when the Post is embedded in a collection (like for community outbox)
|
// Not needed when the Post is embedded in a collection (like for community outbox)
|
||||||
.set_context_xsd_any_uri(context())?
|
.set_context(context())
|
||||||
.set_id(self.ap_id.to_owned())?
|
.set_id(self.ap_id.parse::<XsdAnyUri>()?)
|
||||||
.set_published(convert_datetime(self.published))?
|
.set_published(convert_datetime(self.published).into())
|
||||||
.set_to_xsd_any_uri(community.actor_id)?
|
.set_to(community.actor_id)
|
||||||
.set_many_in_reply_to_xsd_any_uris(in_reply_to_vec)?
|
.set_many_in_reply_tos(in_reply_to_vec)
|
||||||
.set_content_xsd_string(self.content.to_owned())?
|
.set_content(self.content.to_owned())
|
||||||
.set_attributed_to_xsd_any_uri(creator.actor_id)?;
|
.set_attributed_to(creator.actor_id);
|
||||||
|
|
||||||
if let Some(u) = self.updated {
|
if let Some(u) = self.updated {
|
||||||
oprops.set_updated(convert_datetime(u))?;
|
comment.set_updated(convert_datetime(u).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(comment)
|
Ok(comment)
|
||||||
|
@ -125,12 +120,22 @@ impl FromApub for CommentForm {
|
||||||
client: &Client,
|
client: &Client,
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
) -> Result<CommentForm, LemmyError> {
|
) -> Result<CommentForm, LemmyError> {
|
||||||
let oprops = ¬e.object_props;
|
let creator_actor_id = ¬e
|
||||||
let creator_actor_id = &oprops.get_attributed_to_xsd_any_uri().unwrap().to_string();
|
.attributed_to()
|
||||||
|
.unwrap()
|
||||||
|
.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_remote_user(creator_actor_id, client, pool).await?;
|
||||||
|
|
||||||
let mut in_reply_tos = oprops.get_many_in_reply_to_xsd_any_uris().unwrap();
|
let mut in_reply_tos = note
|
||||||
|
.in_reply_to
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.as_many()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.map(|i| i.as_xsd_any_uri().unwrap());
|
||||||
let post_ap_id = in_reply_tos.next().unwrap().to_string();
|
let post_ap_id = in_reply_tos.next().unwrap().to_string();
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -153,20 +158,20 @@ impl FromApub for CommentForm {
|
||||||
creator_id: creator.id,
|
creator_id: creator.id,
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
parent_id,
|
parent_id,
|
||||||
content: oprops
|
content: note
|
||||||
.get_content_xsd_string()
|
.content()
|
||||||
.map(|c| c.to_string())
|
.unwrap()
|
||||||
.unwrap(),
|
.as_single_xsd_string()
|
||||||
|
.unwrap()
|
||||||
|
.to_string(),
|
||||||
removed: None,
|
removed: None,
|
||||||
read: None,
|
read: None,
|
||||||
published: oprops
|
published: note
|
||||||
.get_published()
|
.published()
|
||||||
.map(|u| u.as_ref().to_owned().naive_local()),
|
|
||||||
updated: oprops
|
|
||||||
.get_updated()
|
|
||||||
.map(|u| u.as_ref().to_owned().naive_local()),
|
.map(|u| u.as_ref().to_owned().naive_local()),
|
||||||
|
updated: note.updated().map(|u| u.as_ref().to_owned().naive_local()),
|
||||||
deleted: None,
|
deleted: None,
|
||||||
ap_id: oprops.get_id().unwrap().to_string(),
|
ap_id: note.id().unwrap().to_string(),
|
||||||
local: false,
|
local: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -193,16 +198,14 @@ impl ApubObjectType for Comment {
|
||||||
collect_non_local_mentions_and_addresses(&self.content, &community, client, pool).await?;
|
collect_non_local_mentions_and_addresses(&self.content, &community, client, pool).await?;
|
||||||
|
|
||||||
let id = format!("{}/create/{}", self.ap_id, uuid::Uuid::new_v4());
|
let id = format!("{}/create/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||||
let mut create = Create::new();
|
let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
populate_object_props(&mut create.object_props, maa.addressed_ccs, &id)?;
|
|
||||||
|
|
||||||
// Set the mention tags
|
|
||||||
create.object_props.set_many_tag_base_boxes(maa.tags)?;
|
|
||||||
|
|
||||||
create
|
create
|
||||||
.create_props
|
.set_context(context())
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_id(XsdAnyUri::from_str(&id)?)
|
||||||
.set_object_base_box(note)?;
|
.set_to(public())
|
||||||
|
.set_many_ccs(maa.addressed_ccs.to_owned())
|
||||||
|
// Set the mention tags
|
||||||
|
.set_many_tags(maa.get_tags()?);
|
||||||
|
|
||||||
send_activity_to_community(&creator, &community, maa.inboxes, create, client, pool).await?;
|
send_activity_to_community(&creator, &community, maa.inboxes, create, client, pool).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -227,16 +230,14 @@ impl ApubObjectType for Comment {
|
||||||
collect_non_local_mentions_and_addresses(&self.content, &community, client, pool).await?;
|
collect_non_local_mentions_and_addresses(&self.content, &community, client, pool).await?;
|
||||||
|
|
||||||
let id = format!("{}/update/{}", self.ap_id, uuid::Uuid::new_v4());
|
let id = format!("{}/update/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||||
let mut update = Update::new();
|
let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
populate_object_props(&mut update.object_props, maa.addressed_ccs, &id)?;
|
|
||||||
|
|
||||||
// Set the mention tags
|
|
||||||
update.object_props.set_many_tag_base_boxes(maa.tags)?;
|
|
||||||
|
|
||||||
update
|
update
|
||||||
.update_props
|
.set_context(context())
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_id(XsdAnyUri::from_str(&id)?)
|
||||||
.set_object_base_box(note)?;
|
.set_to(public())
|
||||||
|
.set_many_ccs(maa.addressed_ccs.to_owned())
|
||||||
|
// Set the mention tags
|
||||||
|
.set_many_tags(maa.get_tags()?);
|
||||||
|
|
||||||
send_activity_to_community(&creator, &community, maa.inboxes, update, client, pool).await?;
|
send_activity_to_community(&creator, &community, maa.inboxes, update, client, pool).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -257,18 +258,12 @@ impl ApubObjectType for Comment {
|
||||||
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
||||||
|
|
||||||
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
|
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||||
let mut delete = Delete::default();
|
let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
|
|
||||||
populate_object_props(
|
|
||||||
&mut delete.object_props,
|
|
||||||
vec![community.get_followers_url()],
|
|
||||||
&id,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
delete
|
delete
|
||||||
.delete_props
|
.set_context(context())
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_id(XsdAnyUri::from_str(&id)?)
|
||||||
.set_object_base_box(note)?;
|
.set_to(public())
|
||||||
|
.set_many_ccs(vec![community.get_followers_url()]);
|
||||||
|
|
||||||
send_activity_to_community(
|
send_activity_to_community(
|
||||||
&creator,
|
&creator,
|
||||||
|
@ -298,34 +293,22 @@ impl ApubObjectType for Comment {
|
||||||
|
|
||||||
// Generate a fake delete activity, with the correct object
|
// Generate a fake delete activity, with the correct object
|
||||||
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
|
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||||
let mut delete = Delete::default();
|
let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
|
|
||||||
populate_object_props(
|
|
||||||
&mut delete.object_props,
|
|
||||||
vec![community.get_followers_url()],
|
|
||||||
&id,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
delete
|
delete
|
||||||
.delete_props
|
.set_context(context())
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_id(XsdAnyUri::from_str(&id)?)
|
||||||
.set_object_base_box(note)?;
|
.set_to(public())
|
||||||
|
.set_many_ccs(vec![community.get_followers_url()]);
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// Undo that fake activity
|
// Undo that fake activity
|
||||||
let undo_id = format!("{}/undo/delete/{}", self.ap_id, uuid::Uuid::new_v4());
|
let undo_id = format!("{}/undo/delete/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||||
let mut undo = Undo::default();
|
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
|
||||||
|
|
||||||
populate_object_props(
|
|
||||||
&mut undo.object_props,
|
|
||||||
vec![community.get_followers_url()],
|
|
||||||
&undo_id,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
undo
|
undo
|
||||||
.undo_props
|
.set_context(context())
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_id(XsdAnyUri::from_str(&undo_id)?)
|
||||||
.set_object_base_box(delete)?;
|
.set_to(public())
|
||||||
|
.set_many_ccs(vec![community.get_followers_url()]);
|
||||||
|
|
||||||
send_activity_to_community(
|
send_activity_to_community(
|
||||||
&creator,
|
&creator,
|
||||||
|
@ -354,18 +337,12 @@ impl ApubObjectType for Comment {
|
||||||
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
||||||
|
|
||||||
let id = format!("{}/remove/{}", self.ap_id, uuid::Uuid::new_v4());
|
let id = format!("{}/remove/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||||
let mut remove = Remove::default();
|
let mut remove = Remove::new(mod_.actor_id.to_owned(), note.into_any_base()?);
|
||||||
|
|
||||||
populate_object_props(
|
|
||||||
&mut remove.object_props,
|
|
||||||
vec![community.get_followers_url()],
|
|
||||||
&id,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
remove
|
remove
|
||||||
.remove_props
|
.set_context(context())
|
||||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
.set_id(XsdAnyUri::from_str(&id)?)
|
||||||
.set_object_base_box(note)?;
|
.set_to(public())
|
||||||
|
.set_many_ccs(vec![community.get_followers_url()]);
|
||||||
|
|
||||||
send_activity_to_community(
|
send_activity_to_community(
|
||||||
&mod_,
|
&mod_,
|
||||||
|
@ -395,33 +372,21 @@ impl ApubObjectType for Comment {
|
||||||
|
|
||||||
// Generate a fake delete activity, with the correct object
|
// Generate a fake delete activity, with the correct object
|
||||||
let id = format!("{}/remove/{}", self.ap_id, uuid::Uuid::new_v4());
|
let id = format!("{}/remove/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||||
let mut remove = Remove::default();
|
let mut remove = Remove::new(mod_.actor_id.to_owned(), note.into_any_base()?);
|
||||||
|
|
||||||
populate_object_props(
|
|
||||||
&mut remove.object_props,
|
|
||||||
vec![community.get_followers_url()],
|
|
||||||
&id,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
remove
|
remove
|
||||||
.remove_props
|
.set_context(context())
|
||||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
.set_id(XsdAnyUri::from_str(&id)?)
|
||||||
.set_object_base_box(note)?;
|
.set_to(public())
|
||||||
|
.set_many_ccs(vec![community.get_followers_url()]);
|
||||||
|
|
||||||
// Undo that fake activity
|
// Undo that fake activity
|
||||||
let undo_id = format!("{}/undo/remove/{}", self.ap_id, uuid::Uuid::new_v4());
|
let undo_id = format!("{}/undo/remove/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||||
let mut undo = Undo::default();
|
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
|
||||||
|
|
||||||
populate_object_props(
|
|
||||||
&mut undo.object_props,
|
|
||||||
vec![community.get_followers_url()],
|
|
||||||
&undo_id,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
undo
|
undo
|
||||||
.undo_props
|
.set_context(context())
|
||||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
.set_id(XsdAnyUri::from_str(&undo_id)?)
|
||||||
.set_object_base_box(remove)?;
|
.set_to(public())
|
||||||
|
.set_many_ccs(vec![community.get_followers_url()]);
|
||||||
|
|
||||||
send_activity_to_community(
|
send_activity_to_community(
|
||||||
&mod_,
|
&mod_,
|
||||||
|
@ -454,16 +419,12 @@ impl ApubLikeableType for Comment {
|
||||||
|
|
||||||
let id = format!("{}/like/{}", self.ap_id, uuid::Uuid::new_v4());
|
let id = format!("{}/like/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||||
|
|
||||||
let mut like = Like::new();
|
let mut like = Like::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
populate_object_props(
|
|
||||||
&mut like.object_props,
|
|
||||||
vec![community.get_followers_url()],
|
|
||||||
&id,
|
|
||||||
)?;
|
|
||||||
like
|
like
|
||||||
.like_props
|
.set_context(context())
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_id(XsdAnyUri::from_str(&id)?)
|
||||||
.set_object_base_box(note)?;
|
.set_to(public())
|
||||||
|
.set_many_ccs(vec![community.get_followers_url()]);
|
||||||
|
|
||||||
send_activity_to_community(
|
send_activity_to_community(
|
||||||
&creator,
|
&creator,
|
||||||
|
@ -493,16 +454,12 @@ impl ApubLikeableType for Comment {
|
||||||
|
|
||||||
let id = format!("{}/dislike/{}", self.ap_id, uuid::Uuid::new_v4());
|
let id = format!("{}/dislike/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||||
|
|
||||||
let mut dislike = Dislike::new();
|
let mut dislike = Dislike::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
populate_object_props(
|
|
||||||
&mut dislike.object_props,
|
|
||||||
vec![community.get_followers_url()],
|
|
||||||
&id,
|
|
||||||
)?;
|
|
||||||
dislike
|
dislike
|
||||||
.dislike_props
|
.set_context(context())
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_id(XsdAnyUri::from_str(&id)?)
|
||||||
.set_object_base_box(note)?;
|
.set_to(public())
|
||||||
|
.set_many_ccs(vec![community.get_followers_url()]);
|
||||||
|
|
||||||
send_activity_to_community(
|
send_activity_to_community(
|
||||||
&creator,
|
&creator,
|
||||||
|
@ -532,32 +489,22 @@ impl ApubLikeableType for Comment {
|
||||||
|
|
||||||
let id = format!("{}/dislike/{}", self.ap_id, uuid::Uuid::new_v4());
|
let id = format!("{}/dislike/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||||
|
|
||||||
let mut like = Like::new();
|
let mut like = Like::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
populate_object_props(
|
|
||||||
&mut like.object_props,
|
|
||||||
vec![community.get_followers_url()],
|
|
||||||
&id,
|
|
||||||
)?;
|
|
||||||
like
|
like
|
||||||
.like_props
|
.set_context(context())
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_id(XsdAnyUri::from_str(&id)?)
|
||||||
.set_object_base_box(note)?;
|
.set_to(public())
|
||||||
|
.set_many_ccs(vec![community.get_followers_url()]);
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// Undo that fake activity
|
// Undo that fake activity
|
||||||
let undo_id = format!("{}/undo/like/{}", self.ap_id, uuid::Uuid::new_v4());
|
let undo_id = format!("{}/undo/like/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||||
let mut undo = Undo::default();
|
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
|
||||||
|
|
||||||
populate_object_props(
|
|
||||||
&mut undo.object_props,
|
|
||||||
vec![community.get_followers_url()],
|
|
||||||
&undo_id,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
undo
|
undo
|
||||||
.undo_props
|
.set_context(context())
|
||||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
.set_id(XsdAnyUri::from_str(&undo_id)?)
|
||||||
.set_object_base_box(like)?;
|
.set_to(public())
|
||||||
|
.set_many_ccs(vec![community.get_followers_url()]);
|
||||||
|
|
||||||
send_activity_to_community(
|
send_activity_to_community(
|
||||||
&creator,
|
&creator,
|
||||||
|
@ -578,6 +525,16 @@ struct MentionsAndAddresses {
|
||||||
tags: Vec<Mention>,
|
tags: Vec<Mention>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MentionsAndAddresses {
|
||||||
|
fn get_tags(&self) -> Result<Vec<AnyBase>, Error> {
|
||||||
|
self
|
||||||
|
.tags
|
||||||
|
.iter()
|
||||||
|
.map(|t| t.to_owned().into_any_base())
|
||||||
|
.collect::<Result<Vec<AnyBase>, Error>>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// This takes a comment, and builds a list of to_addresses, inboxes,
|
/// This takes a comment, and builds a list of to_addresses, inboxes,
|
||||||
/// and mention tags, so they know where to be sent to.
|
/// and mention tags, so they know where to be sent to.
|
||||||
/// Addresses are the users / addresses that go in the cc field.
|
/// Addresses are the users / addresses that go in the cc field.
|
||||||
|
@ -604,17 +561,14 @@ async fn collect_non_local_mentions_and_addresses(
|
||||||
// TODO should it be fetching it every time?
|
// TODO should it be fetching it every time?
|
||||||
if let Ok(actor_id) = fetch_webfinger_url(mention, client).await {
|
if let Ok(actor_id) = fetch_webfinger_url(mention, client).await {
|
||||||
debug!("mention actor_id: {}", actor_id);
|
debug!("mention actor_id: {}", actor_id);
|
||||||
addressed_ccs.push(actor_id.to_owned());
|
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_remote_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);
|
||||||
let mut mention_tag = Mention::new();
|
let mut mention_tag = Mention::new();
|
||||||
mention_tag
|
mention_tag.set_href(actor_id).set_name(mention.full_name());
|
||||||
.link_props
|
|
||||||
.set_href(actor_id)?
|
|
||||||
.set_name_xsd_string(mention.full_name())?;
|
|
||||||
tags.push(mention_tag);
|
tags.push(mention_tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,18 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
apub::{
|
apub::{
|
||||||
activities::{populate_object_props, send_activity},
|
activities::{populate_object_props, send_activity},
|
||||||
create_apub_response,
|
create_apub_response, create_apub_tombstone_response, create_tombstone,
|
||||||
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_remote_user,
|
||||||
get_shared_inbox,
|
get_shared_inbox, insert_activity, ActorType, FromApub, GroupExt, ToApub,
|
||||||
insert_activity,
|
|
||||||
ActorType,
|
|
||||||
FromApub,
|
|
||||||
GroupExt,
|
|
||||||
ToApub,
|
|
||||||
},
|
},
|
||||||
blocking,
|
blocking,
|
||||||
routes::DbPoolParam,
|
routes::DbPoolParam,
|
||||||
DbPool,
|
DbPool, LemmyError,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{Accept, Announce, Delete, Remove, Undo},
|
activity::{Accept, Announce, Delete, Remove, Undo},
|
||||||
Activity,
|
Activity, Base, BaseBox,
|
||||||
Base,
|
|
||||||
BaseBox,
|
|
||||||
};
|
};
|
||||||
use activitystreams_ext::Ext2;
|
use activitystreams_ext::Ext2;
|
||||||
use activitystreams_new::{
|
use activitystreams_new::{
|
||||||
|
@ -378,7 +368,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.as_str(), client, pool).await?;
|
let creator = get_or_fetch_and_upsert_remote_user(creator_uri, client, pool).await?;
|
||||||
|
|
||||||
Ok(CommunityForm {
|
Ok(CommunityForm {
|
||||||
name: group.name().unwrap().as_single_xsd_string().unwrap().into(),
|
name: group.name().unwrap().as_single_xsd_string().unwrap().into(),
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub async fn community_inbox(
|
||||||
&community.name, &input
|
&community.name, &input
|
||||||
);
|
);
|
||||||
let follow = input.follow()?;
|
let follow = input.follow()?;
|
||||||
let user_uri = follow.actor.as_single_xsd_any_uri().unwrap().to_string();
|
let user_uri = follow.actor.as_single_xsd_any_uri().unwrap();
|
||||||
let community_uri = follow.object.as_single_xsd_any_uri().unwrap().to_string();
|
let community_uri = follow.object.as_single_xsd_any_uri().unwrap().to_string();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &client, &db).await?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &client, &db).await?;
|
||||||
|
|
|
@ -4,11 +4,9 @@ use crate::{
|
||||||
blocking,
|
blocking,
|
||||||
request::{retry, RecvError},
|
request::{retry, RecvError},
|
||||||
routes::nodeinfo::{NodeInfo, NodeInfoWellKnown},
|
routes::nodeinfo::{NodeInfo, NodeInfoWellKnown},
|
||||||
DbPool,
|
DbPool, LemmyError,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::object::Note;
|
use activitystreams_new::{base::BaseExt, object::Note, prelude::*, primitives::XsdAnyUri};
|
||||||
use activitystreams_new::{base::BaseExt, prelude::*, primitives::XsdAnyUri};
|
|
||||||
use actix_web::client::Client;
|
use actix_web::client::Client;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{result::Error::NotFound, PgConnection};
|
use diesel::{result::Error::NotFound, PgConnection};
|
||||||
|
@ -22,9 +20,7 @@ use lemmy_db::{
|
||||||
post_view::PostView,
|
post_view::PostView,
|
||||||
user::{UserForm, User_},
|
user::{UserForm, User_},
|
||||||
user_view::UserView,
|
user_view::UserView,
|
||||||
Crud,
|
Crud, Joinable, SearchType,
|
||||||
Joinable,
|
|
||||||
SearchType,
|
|
||||||
};
|
};
|
||||||
use lemmy_utils::get_apub_protocol_string;
|
use lemmy_utils::get_apub_protocol_string;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
@ -139,7 +135,7 @@ pub async fn search_by_apub_id(
|
||||||
|
|
||||||
let response = match fetch_remote_object::<SearchAcceptedObjects>(client, &query_url).await? {
|
let response = match fetch_remote_object::<SearchAcceptedObjects>(client, &query_url).await? {
|
||||||
SearchAcceptedObjects::Person(p) => {
|
SearchAcceptedObjects::Person(p) => {
|
||||||
let user_uri = p.inner.id().unwrap().to_string();
|
let user_uri = p.inner.id().unwrap();
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||||
|
|
||||||
|
@ -173,16 +169,11 @@ pub async fn search_by_apub_id(
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
SearchAcceptedObjects::Comment(c) => {
|
SearchAcceptedObjects::Comment(c) => {
|
||||||
let post_url = c
|
let post_url = c.in_reply_to.as_ref().unwrap().as_many().unwrap();
|
||||||
.object_props
|
|
||||||
.get_many_in_reply_to_xsd_any_uris()
|
|
||||||
.unwrap()
|
|
||||||
.next()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
// TODO: also fetch parent comments if any
|
// TODO: also fetch parent comments if any
|
||||||
let post = fetch_remote_object(client, &Url::parse(&post_url)?).await?;
|
let x = post_url.first().unwrap().as_xsd_any_uri().unwrap();
|
||||||
|
let post = fetch_remote_object(client, x.as_url()).await?;
|
||||||
let post_form = PostForm::from_apub(&post, client, pool).await?;
|
let post_form = PostForm::from_apub(&post, client, pool).await?;
|
||||||
let comment_form = CommentForm::from_apub(&c, client, pool).await?;
|
let comment_form = CommentForm::from_apub(&c, client, pool).await?;
|
||||||
|
|
||||||
|
@ -200,13 +191,13 @@ pub async fn search_by_apub_id(
|
||||||
|
|
||||||
/// 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_remote_user(
|
||||||
apub_id: &str,
|
apub_id: &XsdAnyUri,
|
||||||
client: &Client,
|
client: &Client,
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
) -> Result<User_, LemmyError> {
|
) -> Result<User_, LemmyError> {
|
||||||
let apub_id_owned = apub_id.to_owned();
|
let apub_id_owned = apub_id.to_owned();
|
||||||
let user = blocking(pool, move |conn| {
|
let user = blocking(pool, move |conn| {
|
||||||
User_::read_from_actor_id(conn, &apub_id_owned)
|
User_::read_from_actor_id(conn, apub_id_owned.as_str())
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -214,7 +205,7 @@ pub async fn get_or_fetch_and_upsert_remote_user(
|
||||||
// If its older than a day, re-fetch it
|
// If its older than a day, re-fetch it
|
||||||
Ok(u) if !u.local && should_refetch_actor(u.last_refreshed_at) => {
|
Ok(u) if !u.local && should_refetch_actor(u.last_refreshed_at) => {
|
||||||
debug!("Fetching and updating from remote user: {}", apub_id);
|
debug!("Fetching and updating from remote user: {}", apub_id);
|
||||||
let person = fetch_remote_object::<PersonExt>(client, &Url::parse(apub_id)?).await?;
|
let person = fetch_remote_object::<PersonExt>(client, apub_id.as_url()).await?;
|
||||||
|
|
||||||
let mut uf = UserForm::from_apub(&person, client, pool).await?;
|
let mut uf = UserForm::from_apub(&person, client, pool).await?;
|
||||||
uf.last_refreshed_at = Some(naive_now());
|
uf.last_refreshed_at = Some(naive_now());
|
||||||
|
@ -225,7 +216,7 @@ pub async fn get_or_fetch_and_upsert_remote_user(
|
||||||
Ok(u) => Ok(u),
|
Ok(u) => Ok(u),
|
||||||
Err(NotFound {}) => {
|
Err(NotFound {}) => {
|
||||||
debug!("Fetching and creating remote user: {}", apub_id);
|
debug!("Fetching and creating remote user: {}", apub_id);
|
||||||
let person = fetch_remote_object::<PersonExt>(client, &Url::parse(apub_id)?).await?;
|
let person = fetch_remote_object::<PersonExt>(client, apub_id.as_url()).await?;
|
||||||
|
|
||||||
let uf = UserForm::from_apub(&person, client, pool).await?;
|
let uf = UserForm::from_apub(&person, client, pool).await?;
|
||||||
let user = blocking(pool, move |conn| User_::create(conn, &uf)).await??;
|
let user = blocking(pool, move |conn| User_::create(conn, &uf)).await??;
|
||||||
|
@ -293,7 +284,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.as_str(), client, pool).await?;
|
let c_or_m = get_or_fetch_and_upsert_remote_user(uri, client, pool).await?;
|
||||||
|
|
||||||
creator_and_moderators.push(c_or_m);
|
creator_and_moderators.push(c_or_m);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,7 @@ use crate::{
|
||||||
blocking,
|
blocking,
|
||||||
request::{retry, RecvError},
|
request::{retry, RecvError},
|
||||||
routes::webfinger::WebFingerResponse,
|
routes::webfinger::WebFingerResponse,
|
||||||
DbPool,
|
DbPool, LemmyError,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams_ext::{Ext1, Ext2};
|
use activitystreams_ext::{Ext1, Ext2};
|
||||||
use activitystreams_new::{
|
use activitystreams_new::{
|
||||||
|
@ -28,6 +27,7 @@ use activitystreams_new::{
|
||||||
actor::{ApActor, Group, Person},
|
actor::{ApActor, Group, Person},
|
||||||
object::{Page, Tombstone},
|
object::{Page, Tombstone},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
primitives::XsdAnyUri,
|
||||||
};
|
};
|
||||||
use actix_web::{body::Body, client::Client, HttpResponse};
|
use actix_web::{body::Body, client::Client, HttpResponse};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
|
@ -36,6 +36,7 @@ use lemmy_db::{activity::do_insert_activity, user::User_};
|
||||||
use lemmy_utils::{convert_datetime, get_apub_protocol_string, settings::Settings, MentionData};
|
use lemmy_utils::{convert_datetime, get_apub_protocol_string, settings::Settings, MentionData};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use std::str::FromStr;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
type GroupExt = Ext2<ApActor<Group>, GroupExtension, PublicKeyExtension>;
|
type GroupExt = Ext2<ApActor<Group>, GroupExtension, PublicKeyExtension>;
|
||||||
|
@ -310,7 +311,7 @@ pub trait ActorType {
|
||||||
pub async fn fetch_webfinger_url(
|
pub async fn fetch_webfinger_url(
|
||||||
mention: &MentionData,
|
mention: &MentionData,
|
||||||
client: &Client,
|
client: &Client,
|
||||||
) -> Result<String, LemmyError> {
|
) -> Result<XsdAnyUri, LemmyError> {
|
||||||
let fetch_url = format!(
|
let fetch_url = format!(
|
||||||
"{}://{}/.well-known/webfinger?resource=acct:{}@{}",
|
"{}://{}/.well-known/webfinger?resource=acct:{}@{}",
|
||||||
get_apub_protocol_string(),
|
get_apub_protocol_string(),
|
||||||
|
@ -335,6 +336,8 @@ pub async fn fetch_webfinger_url(
|
||||||
link
|
link
|
||||||
.href
|
.href
|
||||||
.to_owned()
|
.to_owned()
|
||||||
|
.map(|u| XsdAnyUri::from_str(&u))
|
||||||
|
.transpose()?
|
||||||
.ok_or_else(|| format_err!("No href found.").into())
|
.ok_or_else(|| format_err!("No href found.").into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,14 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
apub::{
|
apub::{
|
||||||
activities::{populate_object_props, send_activity_to_community},
|
activities::{populate_object_props, send_activity_to_community},
|
||||||
create_apub_response,
|
create_apub_response, create_apub_tombstone_response, create_tombstone,
|
||||||
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_remote_community, get_or_fetch_and_upsert_remote_user},
|
||||||
ActorType,
|
ActorType, ApubLikeableType, ApubObjectType, FromApub, PageExt, ToApub,
|
||||||
ApubLikeableType,
|
|
||||||
ApubObjectType,
|
|
||||||
FromApub,
|
|
||||||
PageExt,
|
|
||||||
ToApub,
|
|
||||||
},
|
},
|
||||||
blocking,
|
blocking,
|
||||||
routes::DbPoolParam,
|
routes::DbPoolParam,
|
||||||
DbPool,
|
DbPool, LemmyError,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
|
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
|
||||||
|
@ -166,8 +158,7 @@ impl FromApub for PostForm {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_single_xsd_any_uri()
|
.as_single_xsd_any_uri()
|
||||||
.unwrap()
|
.unwrap();
|
||||||
.as_str();
|
|
||||||
|
|
||||||
let creator = get_or_fetch_and_upsert_remote_user(creator_actor_id, client, pool).await?;
|
let creator = get_or_fetch_and_upsert_remote_user(creator_actor_id, client, pool).await?;
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
apub::{
|
apub::{
|
||||||
activities::send_activity,
|
activities::send_activity, create_tombstone, fetcher::get_or_fetch_and_upsert_remote_user,
|
||||||
create_tombstone,
|
insert_activity, ApubObjectType, FromApub, ToApub,
|
||||||
fetcher::get_or_fetch_and_upsert_remote_user,
|
|
||||||
insert_activity,
|
|
||||||
ApubObjectType,
|
|
||||||
FromApub,
|
|
||||||
ToApub,
|
|
||||||
},
|
},
|
||||||
blocking,
|
blocking, DbPool, LemmyError,
|
||||||
DbPool,
|
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{Create, Delete, Undo, Update},
|
activity::{Create, Delete, Undo, Update},
|
||||||
|
@ -76,11 +69,11 @@ impl FromApub for PrivateMessageForm {
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
) -> Result<PrivateMessageForm, LemmyError> {
|
) -> Result<PrivateMessageForm, LemmyError> {
|
||||||
let oprops = ¬e.object_props;
|
let oprops = ¬e.object_props;
|
||||||
let creator_actor_id = &oprops.get_attributed_to_xsd_any_uri().unwrap().to_string();
|
let creator_actor_id = &oprops.get_attributed_to_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_remote_user(&creator_actor_id, client, pool).await?;
|
||||||
|
|
||||||
let recipient_actor_id = &oprops.get_to_xsd_any_uri().unwrap().to_string();
|
let recipient_actor_id = &oprops.get_to_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_remote_user(&recipient_actor_id, client, pool).await?;
|
||||||
|
|
||||||
|
|
|
@ -8,15 +8,10 @@ use crate::{
|
||||||
community::do_announce,
|
community::do_announce,
|
||||||
extensions::signatures::verify,
|
extensions::signatures::verify,
|
||||||
fetcher::{
|
fetcher::{
|
||||||
get_or_fetch_and_insert_remote_comment,
|
get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post,
|
||||||
get_or_fetch_and_insert_remote_post,
|
get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user,
|
||||||
get_or_fetch_and_upsert_remote_community,
|
|
||||||
get_or_fetch_and_upsert_remote_user,
|
|
||||||
},
|
},
|
||||||
insert_activity,
|
insert_activity, FromApub, GroupExt, PageExt,
|
||||||
FromApub,
|
|
||||||
GroupExt,
|
|
||||||
PageExt,
|
|
||||||
},
|
},
|
||||||
blocking,
|
blocking,
|
||||||
routes::{ChatServerParam, DbPoolParam},
|
routes::{ChatServerParam, DbPoolParam},
|
||||||
|
@ -24,16 +19,13 @@ use crate::{
|
||||||
server::{SendComment, SendCommunityRoomMessage, SendPost},
|
server::{SendComment, SendCommunityRoomMessage, SendPost},
|
||||||
UserOperation,
|
UserOperation,
|
||||||
},
|
},
|
||||||
DbPool,
|
DbPool, LemmyError,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{Announce, Create, Delete, Dislike, Like, Remove, Undo, Update},
|
activity::{Announce, Create, Delete, Dislike, Like, Remove, Undo, Update},
|
||||||
object::Note,
|
Activity, Base, BaseBox,
|
||||||
Activity,
|
|
||||||
Base,
|
|
||||||
BaseBox,
|
|
||||||
};
|
};
|
||||||
|
use activitystreams_new::{object::Note, primitives::XsdAnyUri};
|
||||||
use actix_web::{client::Client, web, HttpRequest, HttpResponse};
|
use actix_web::{client::Client, web, HttpRequest, HttpResponse};
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
||||||
|
@ -43,8 +35,7 @@ use lemmy_db::{
|
||||||
naive_now,
|
naive_now,
|
||||||
post::{Post, PostForm, PostLike, PostLikeForm},
|
post::{Post, PostForm, PostLike, PostLikeForm},
|
||||||
post_view::PostView,
|
post_view::PostView,
|
||||||
Crud,
|
Crud, Likeable,
|
||||||
Likeable,
|
|
||||||
};
|
};
|
||||||
use lemmy_utils::scrape_text_for_mentions;
|
use lemmy_utils::scrape_text_for_mentions;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
@ -77,7 +68,7 @@ impl SharedAcceptedObjects {
|
||||||
SharedAcceptedObjects::Announce(a) => a.announce_props.get_object_base_box(),
|
SharedAcceptedObjects::Announce(a) => a.announce_props.get_object_base_box(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn sender(&self) -> String {
|
fn sender(&self) -> XsdAnyUri {
|
||||||
let uri = match self {
|
let uri = match self {
|
||||||
SharedAcceptedObjects::Create(c) => c.create_props.get_actor_xsd_any_uri(),
|
SharedAcceptedObjects::Create(c) => c.create_props.get_actor_xsd_any_uri(),
|
||||||
SharedAcceptedObjects::Update(u) => u.update_props.get_actor_xsd_any_uri(),
|
SharedAcceptedObjects::Update(u) => u.update_props.get_actor_xsd_any_uri(),
|
||||||
|
@ -88,7 +79,7 @@ impl SharedAcceptedObjects {
|
||||||
SharedAcceptedObjects::Remove(r) => r.remove_props.get_actor_xsd_any_uri(),
|
SharedAcceptedObjects::Remove(r) => r.remove_props.get_actor_xsd_any_uri(),
|
||||||
SharedAcceptedObjects::Announce(a) => a.announce_props.get_actor_xsd_any_uri(),
|
SharedAcceptedObjects::Announce(a) => a.announce_props.get_actor_xsd_any_uri(),
|
||||||
};
|
};
|
||||||
uri.unwrap().clone().to_string()
|
uri.unwrap().clone()
|
||||||
}
|
}
|
||||||
fn cc(&self) -> String {
|
fn cc(&self) -> String {
|
||||||
// TODO: there is probably an easier way to do this
|
// TODO: there is probably an easier way to do this
|
||||||
|
@ -133,7 +124,7 @@ pub async fn shared_inbox(
|
||||||
let to = cc.replace("/followers", "");
|
let to = cc.replace("/followers", "");
|
||||||
|
|
||||||
// TODO: this is ugly
|
// TODO: this is ugly
|
||||||
match get_or_fetch_and_upsert_remote_user(&sender.to_string(), &client, pool).await {
|
match get_or_fetch_and_upsert_remote_user(sender, &client, pool).await {
|
||||||
Ok(u) => verify(&request, &u)?,
|
Ok(u) => verify(&request, &u)?,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let c = get_or_fetch_and_upsert_remote_community(&sender.to_string(), &client, pool).await?;
|
let c = get_or_fetch_and_upsert_remote_community(&sender.to_string(), &client, pool).await?;
|
||||||
|
@ -219,7 +210,7 @@ pub async fn shared_inbox(
|
||||||
async fn announce_activity_if_valid<A>(
|
async fn announce_activity_if_valid<A>(
|
||||||
activity: A,
|
activity: A,
|
||||||
community_uri: &str,
|
community_uri: &str,
|
||||||
sender: &str,
|
sender: &XsdAnyUri,
|
||||||
client: &Client,
|
client: &Client,
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
) -> Result<HttpResponse, LemmyError>
|
) -> Result<HttpResponse, LemmyError>
|
||||||
|
@ -344,11 +335,7 @@ async fn receive_create_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<PageExt>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user_uri = create
|
let user_uri = create.create_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.create_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||||
|
|
||||||
|
@ -390,11 +377,7 @@ async fn receive_create_comment(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let user_uri = create
|
let user_uri = create.create_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.create_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||||
|
|
||||||
|
@ -449,11 +432,7 @@ async fn receive_update_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<PageExt>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user_uri = update
|
let user_uri = update.update_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.update_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||||
|
|
||||||
|
@ -495,7 +474,7 @@ async fn receive_like_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<PageExt>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
let user_uri = like.like_props.get_actor_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_remote_user(&user_uri, client, pool).await?;
|
||||||
|
|
||||||
|
@ -546,11 +525,7 @@ async fn receive_dislike_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<PageExt>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user_uri = dislike
|
let user_uri = dislike.dislike_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.dislike_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||||
|
|
||||||
|
@ -601,11 +576,7 @@ async fn receive_update_comment(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let user_uri = update
|
let user_uri = update.update_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.update_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||||
|
|
||||||
|
@ -660,7 +631,7 @@ async fn receive_like_comment(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
let user_uri = like.like_props.get_actor_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_remote_user(&user_uri, client, pool).await?;
|
||||||
|
|
||||||
|
@ -718,11 +689,7 @@ async fn receive_dislike_comment(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let user_uri = dislike
|
let user_uri = dislike.dislike_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.dislike_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||||
|
|
||||||
|
@ -772,11 +739,7 @@ async fn receive_delete_community(
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user_uri = delete
|
let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.delete_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let group = delete
|
let group = delete
|
||||||
.delete_props
|
.delete_props
|
||||||
|
@ -849,11 +812,7 @@ async fn receive_remove_community(
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let mod_uri = remove
|
let mod_uri = remove.remove_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.remove_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let group = remove
|
let group = remove
|
||||||
.remove_props
|
.remove_props
|
||||||
|
@ -926,11 +885,7 @@ async fn receive_delete_post(
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user_uri = delete
|
let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.delete_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let page = delete
|
let page = delete
|
||||||
.delete_props
|
.delete_props
|
||||||
|
@ -992,11 +947,7 @@ async fn receive_remove_post(
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let mod_uri = remove
|
let mod_uri = remove.remove_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.remove_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let page = remove
|
let page = remove
|
||||||
.remove_props
|
.remove_props
|
||||||
|
@ -1058,11 +1009,7 @@ async fn receive_delete_comment(
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user_uri = delete
|
let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.delete_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let note = delete
|
let note = delete
|
||||||
.delete_props
|
.delete_props
|
||||||
|
@ -1126,11 +1073,7 @@ async fn receive_remove_comment(
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let mod_uri = remove
|
let mod_uri = remove.remove_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.remove_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let note = remove
|
let note = remove
|
||||||
.remove_props
|
.remove_props
|
||||||
|
@ -1254,11 +1197,7 @@ async fn receive_undo_delete_comment(
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user_uri = delete
|
let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.delete_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let note = delete
|
let note = delete
|
||||||
.delete_props
|
.delete_props
|
||||||
|
@ -1322,11 +1261,7 @@ async fn receive_undo_remove_comment(
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let mod_uri = remove
|
let mod_uri = remove.remove_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.remove_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let note = remove
|
let note = remove
|
||||||
.remove_props
|
.remove_props
|
||||||
|
@ -1390,11 +1325,7 @@ async fn receive_undo_delete_post(
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user_uri = delete
|
let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.delete_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let page = delete
|
let page = delete
|
||||||
.delete_props
|
.delete_props
|
||||||
|
@ -1456,11 +1387,7 @@ async fn receive_undo_remove_post(
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let mod_uri = remove
|
let mod_uri = remove.remove_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.remove_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let page = remove
|
let page = remove
|
||||||
.remove_props
|
.remove_props
|
||||||
|
@ -1522,11 +1449,7 @@ async fn receive_undo_delete_community(
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user_uri = delete
|
let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.delete_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let group = delete
|
let group = delete
|
||||||
.delete_props
|
.delete_props
|
||||||
|
@ -1599,11 +1522,7 @@ async fn receive_undo_remove_community(
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
chat_server: ChatServerParam,
|
chat_server: ChatServerParam,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let mod_uri = remove
|
let mod_uri = remove.remove_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.remove_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let group = remove
|
let group = remove
|
||||||
.remove_props
|
.remove_props
|
||||||
|
@ -1713,7 +1632,7 @@ async fn receive_undo_like_comment(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
let user_uri = like.like_props.get_actor_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_remote_user(&user_uri, client, pool).await?;
|
||||||
|
|
||||||
|
@ -1767,7 +1686,7 @@ async fn receive_undo_like_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<PageExt>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
let user_uri = like.like_props.get_actor_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_remote_user(&user_uri, client, pool).await?;
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::claims::Claims,
|
api::claims::Claims,
|
||||||
apub::{
|
apub::{
|
||||||
activities::send_activity,
|
activities::send_activity, create_apub_response, insert_activity, ActorType, FromApub,
|
||||||
create_apub_response,
|
PersonExt, ToApub,
|
||||||
insert_activity,
|
|
||||||
ActorType,
|
|
||||||
FromApub,
|
|
||||||
PersonExt,
|
|
||||||
ToApub,
|
|
||||||
},
|
},
|
||||||
blocking,
|
blocking,
|
||||||
routes::DbPoolParam,
|
routes::DbPoolParam,
|
||||||
DbPool,
|
DbPool, LemmyError,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams_ext::Ext1;
|
use activitystreams_ext::Ext1;
|
||||||
use activitystreams_new::{
|
use activitystreams_new::{
|
||||||
|
|
|
@ -3,14 +3,12 @@ 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_remote_community, get_or_fetch_and_upsert_remote_user},
|
||||||
insert_activity,
|
insert_activity, FromApub,
|
||||||
FromApub,
|
|
||||||
},
|
},
|
||||||
blocking,
|
blocking,
|
||||||
routes::{ChatServerParam, DbPoolParam},
|
routes::{ChatServerParam, DbPoolParam},
|
||||||
websocket::{server::SendUserRoomMessage, UserOperation},
|
websocket::{server::SendUserRoomMessage, UserOperation},
|
||||||
DbPool,
|
DbPool, LemmyError,
|
||||||
LemmyError,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{Accept, Create, Delete, Undo, Update},
|
activity::{Accept, Create, Delete, Undo, Update},
|
||||||
|
@ -23,8 +21,7 @@ use lemmy_db::{
|
||||||
private_message::{PrivateMessage, PrivateMessageForm},
|
private_message::{PrivateMessage, PrivateMessageForm},
|
||||||
private_message_view::PrivateMessageView,
|
private_message_view::PrivateMessageView,
|
||||||
user::User_,
|
user::User_,
|
||||||
Crud,
|
Crud, Followable,
|
||||||
Followable,
|
|
||||||
};
|
};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -124,11 +121,7 @@ async fn receive_create_private_message(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let user_uri = create
|
let user_uri = create.create_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.create_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||||
verify(request, &user)?;
|
verify(request, &user)?;
|
||||||
|
@ -176,11 +169,7 @@ async fn receive_update_private_message(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let user_uri = update
|
let user_uri = update.update_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.update_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||||
verify(request, &user)?;
|
verify(request, &user)?;
|
||||||
|
@ -236,11 +225,7 @@ async fn receive_delete_private_message(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let user_uri = delete
|
let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.delete_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||||
verify(request, &user)?;
|
verify(request, &user)?;
|
||||||
|
@ -316,11 +301,7 @@ async fn receive_undo_delete_private_message(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Note>()?;
|
.into_concrete::<Note>()?;
|
||||||
|
|
||||||
let user_uri = delete
|
let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
|
||||||
.delete_props
|
|
||||||
.get_actor_xsd_any_uri()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
|
||||||
verify(request, &user)?;
|
verify(request, &user)?;
|
||||||
|
|
Loading…
Reference in a new issue