pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> {
use super::user_view::user_fast::dsl::*;
- use diesel::sql_types::{Text, Nullable};
+ use diesel::sql_types::{Nullable, Text};
user_fast
// 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))
.order_by(published)
.load::<Self>(conn)
pub fn banned(conn: &PgConnection) -> Result<Vec<Self>, Error> {
use super::user_view::user_fast::dsl::*;
- use diesel::sql_types::{Text, Nullable};
+ use diesel::sql_types::{Nullable, Text};
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))
- .filter(banned.eq(true)).load::<Self>(conn)
+ .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(banned.eq(true))
+ .load::<Self>(conn)
}
}
use crate::{
apub::{
- activities::{populate_object_props, send_activity_to_community},
- create_apub_response,
- create_apub_tombstone_response,
- create_tombstone,
- fetch_webfinger_url,
+ activities::send_activity_to_community,
+ create_apub_response, create_apub_tombstone_response, create_tombstone, fetch_webfinger_url,
fetcher::{
- get_or_fetch_and_insert_remote_comment,
- get_or_fetch_and_insert_remote_post,
+ get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post,
get_or_fetch_and_upsert_remote_user,
},
- ActorType,
- ApubLikeableType,
- ApubObjectType,
- FromApub,
- ToApub,
+ ActorType, ApubLikeableType, ApubObjectType, FromApub, ToApub,
},
blocking,
routes::DbPoolParam,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
-use activitystreams::{
+use activitystreams_new::{
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
+ base::AnyBase,
context,
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 itertools::Itertools;
use lemmy_db::{
use lemmy_utils::{convert_datetime, scrape_text_for_mentions, MentionData};
use log::debug;
use serde::Deserialize;
+use serde_json::Error;
+use std::str::FromStr;
#[derive(Deserialize)]
pub struct CommentQuery {
type Response = Note;
async fn to_apub(&self, pool: &DbPool) -> Result<Note, LemmyError> {
- let mut comment = Note::default();
- let oprops: &mut ObjectProperties = comment.as_mut();
+ let mut comment = Note::new();
let creator_id = self.creator_id;
let creator = blocking(pool, move |conn| User_::read(conn, creator_id)).await??;
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)
- .set_context_xsd_any_uri(context())?
- .set_id(self.ap_id.to_owned())?
- .set_published(convert_datetime(self.published))?
- .set_to_xsd_any_uri(community.actor_id)?
- .set_many_in_reply_to_xsd_any_uris(in_reply_to_vec)?
- .set_content_xsd_string(self.content.to_owned())?
- .set_attributed_to_xsd_any_uri(creator.actor_id)?;
+ .set_context(context())
+ .set_id(self.ap_id.parse::<XsdAnyUri>()?)
+ .set_published(convert_datetime(self.published).into())
+ .set_to(community.actor_id)
+ .set_many_in_reply_tos(in_reply_to_vec)
+ .set_content(self.content.to_owned())
+ .set_attributed_to(creator.actor_id);
if let Some(u) = self.updated {
- oprops.set_updated(convert_datetime(u))?;
+ comment.set_updated(convert_datetime(u).into());
}
Ok(comment)
client: &Client,
pool: &DbPool,
) -> Result<CommentForm, LemmyError> {
- let oprops = ¬e.object_props;
- let creator_actor_id = &oprops.get_attributed_to_xsd_any_uri().unwrap().to_string();
-
- 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 creator_actor_id = ¬e
+ .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 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();
// This post, or the parent comment might not yet exist on this server yet, fetch them.
creator_id: creator.id,
post_id: post.id,
parent_id,
- content: oprops
- .get_content_xsd_string()
- .map(|c| c.to_string())
- .unwrap(),
+ content: note
+ .content()
+ .unwrap()
+ .as_single_xsd_string()
+ .unwrap()
+ .to_string(),
removed: None,
read: None,
- published: oprops
- .get_published()
- .map(|u| u.as_ref().to_owned().naive_local()),
- updated: oprops
- .get_updated()
+ published: note
+ .published()
.map(|u| u.as_ref().to_owned().naive_local()),
+ updated: note.updated().map(|u| u.as_ref().to_owned().naive_local()),
deleted: None,
- ap_id: oprops.get_id().unwrap().to_string(),
+ ap_id: note.id().unwrap().to_string(),
local: false,
})
}
collect_non_local_mentions_and_addresses(&self.content, &community, client, pool).await?;
let id = format!("{}/create/{}", self.ap_id, uuid::Uuid::new_v4());
- let mut create = Create::new();
- 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)?;
-
+ let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
create
- .create_props
- .set_actor_xsd_any_uri(creator.actor_id.to_owned())?
- .set_object_base_box(note)?;
+ .set_context(context())
+ .set_id(XsdAnyUri::from_str(&id)?)
+ .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?;
Ok(())
collect_non_local_mentions_and_addresses(&self.content, &community, client, pool).await?;
let id = format!("{}/update/{}", self.ap_id, uuid::Uuid::new_v4());
- let mut update = Update::new();
- 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)?;
-
+ let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
update
- .update_props
- .set_actor_xsd_any_uri(creator.actor_id.to_owned())?
- .set_object_base_box(note)?;
+ .set_context(context())
+ .set_id(XsdAnyUri::from_str(&id)?)
+ .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?;
Ok(())
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
- let mut delete = Delete::default();
-
- populate_object_props(
- &mut delete.object_props,
- vec![community.get_followers_url()],
- &id,
- )?;
-
+ let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
delete
- .delete_props
- .set_actor_xsd_any_uri(creator.actor_id.to_owned())?
- .set_object_base_box(note)?;
+ .set_context(context())
+ .set_id(XsdAnyUri::from_str(&id)?)
+ .set_to(public())
+ .set_many_ccs(vec![community.get_followers_url()]);
send_activity_to_community(
&creator,
// Generate a fake delete activity, with the correct object
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
- let mut delete = Delete::default();
-
- populate_object_props(
- &mut delete.object_props,
- vec![community.get_followers_url()],
- &id,
- )?;
-
+ let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
delete
- .delete_props
- .set_actor_xsd_any_uri(creator.actor_id.to_owned())?
- .set_object_base_box(note)?;
+ .set_context(context())
+ .set_id(XsdAnyUri::from_str(&id)?)
+ .set_to(public())
+ .set_many_ccs(vec![community.get_followers_url()]);
// TODO
// Undo that fake activity
let undo_id = format!("{}/undo/delete/{}", self.ap_id, uuid::Uuid::new_v4());
- let mut undo = Undo::default();
-
- populate_object_props(
- &mut undo.object_props,
- vec![community.get_followers_url()],
- &undo_id,
- )?;
-
+ let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo
- .undo_props
- .set_actor_xsd_any_uri(creator.actor_id.to_owned())?
- .set_object_base_box(delete)?;
+ .set_context(context())
+ .set_id(XsdAnyUri::from_str(&undo_id)?)
+ .set_to(public())
+ .set_many_ccs(vec![community.get_followers_url()]);
send_activity_to_community(
&creator,
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
let id = format!("{}/remove/{}", self.ap_id, uuid::Uuid::new_v4());
- let mut remove = Remove::default();
-
- populate_object_props(
- &mut remove.object_props,
- vec![community.get_followers_url()],
- &id,
- )?;
-
+ let mut remove = Remove::new(mod_.actor_id.to_owned(), note.into_any_base()?);
remove
- .remove_props
- .set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
- .set_object_base_box(note)?;
+ .set_context(context())
+ .set_id(XsdAnyUri::from_str(&id)?)
+ .set_to(public())
+ .set_many_ccs(vec![community.get_followers_url()]);
send_activity_to_community(
&mod_,
// Generate a fake delete activity, with the correct object
let id = format!("{}/remove/{}", self.ap_id, uuid::Uuid::new_v4());
- let mut remove = Remove::default();
-
- populate_object_props(
- &mut remove.object_props,
- vec![community.get_followers_url()],
- &id,
- )?;
-
+ let mut remove = Remove::new(mod_.actor_id.to_owned(), note.into_any_base()?);
remove
- .remove_props
- .set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
- .set_object_base_box(note)?;
+ .set_context(context())
+ .set_id(XsdAnyUri::from_str(&id)?)
+ .set_to(public())
+ .set_many_ccs(vec![community.get_followers_url()]);
// Undo that fake activity
let undo_id = format!("{}/undo/remove/{}", self.ap_id, uuid::Uuid::new_v4());
- let mut undo = Undo::default();
-
- populate_object_props(
- &mut undo.object_props,
- vec![community.get_followers_url()],
- &undo_id,
- )?;
-
+ let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
undo
- .undo_props
- .set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
- .set_object_base_box(remove)?;
+ .set_context(context())
+ .set_id(XsdAnyUri::from_str(&undo_id)?)
+ .set_to(public())
+ .set_many_ccs(vec![community.get_followers_url()]);
send_activity_to_community(
&mod_,
let id = format!("{}/like/{}", self.ap_id, uuid::Uuid::new_v4());
- let mut like = Like::new();
- populate_object_props(
- &mut like.object_props,
- vec![community.get_followers_url()],
- &id,
- )?;
+ let mut like = Like::new(creator.actor_id.to_owned(), note.into_any_base()?);
like
- .like_props
- .set_actor_xsd_any_uri(creator.actor_id.to_owned())?
- .set_object_base_box(note)?;
+ .set_context(context())
+ .set_id(XsdAnyUri::from_str(&id)?)
+ .set_to(public())
+ .set_many_ccs(vec![community.get_followers_url()]);
send_activity_to_community(
&creator,
let id = format!("{}/dislike/{}", self.ap_id, uuid::Uuid::new_v4());
- let mut dislike = Dislike::new();
- populate_object_props(
- &mut dislike.object_props,
- vec![community.get_followers_url()],
- &id,
- )?;
+ let mut dislike = Dislike::new(creator.actor_id.to_owned(), note.into_any_base()?);
dislike
- .dislike_props
- .set_actor_xsd_any_uri(creator.actor_id.to_owned())?
- .set_object_base_box(note)?;
+ .set_context(context())
+ .set_id(XsdAnyUri::from_str(&id)?)
+ .set_to(public())
+ .set_many_ccs(vec![community.get_followers_url()]);
send_activity_to_community(
&creator,
let id = format!("{}/dislike/{}", self.ap_id, uuid::Uuid::new_v4());
- let mut like = Like::new();
- populate_object_props(
- &mut like.object_props,
- vec![community.get_followers_url()],
- &id,
- )?;
+ let mut like = Like::new(creator.actor_id.to_owned(), note.into_any_base()?);
like
- .like_props
- .set_actor_xsd_any_uri(creator.actor_id.to_owned())?
- .set_object_base_box(note)?;
+ .set_context(context())
+ .set_id(XsdAnyUri::from_str(&id)?)
+ .set_to(public())
+ .set_many_ccs(vec![community.get_followers_url()]);
// TODO
// Undo that fake activity
let undo_id = format!("{}/undo/like/{}", self.ap_id, uuid::Uuid::new_v4());
- let mut undo = Undo::default();
-
- populate_object_props(
- &mut undo.object_props,
- vec![community.get_followers_url()],
- &undo_id,
- )?;
-
+ let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
undo
- .undo_props
- .set_actor_xsd_any_uri(creator.actor_id.to_owned())?
- .set_object_base_box(like)?;
+ .set_context(context())
+ .set_id(XsdAnyUri::from_str(&undo_id)?)
+ .set_to(public())
+ .set_many_ccs(vec![community.get_followers_url()]);
send_activity_to_community(
&creator,
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,
/// and mention tags, so they know where to be sent to.
/// Addresses are the users / addresses that go in the cc field.
// TODO should it be fetching it every time?
if let Ok(actor_id) = fetch_webfinger_url(mention, client).await {
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 shared_inbox = mention_user.get_shared_inbox_url();
mention_inboxes.push(shared_inbox);
let mut mention_tag = Mention::new();
- mention_tag
- .link_props
- .set_href(actor_id)?
- .set_name_xsd_string(mention.full_name())?;
+ mention_tag.set_href(actor_id).set_name(mention.full_name());
tags.push(mention_tag);
}
}
use crate::{
apub::{
activities::{populate_object_props, send_activity},
- create_apub_response,
- create_apub_tombstone_response,
- create_tombstone,
+ create_apub_response, create_apub_tombstone_response, create_tombstone,
extensions::group_extensions::GroupExtension,
fetcher::get_or_fetch_and_upsert_remote_user,
- get_shared_inbox,
- insert_activity,
- ActorType,
- FromApub,
- GroupExt,
- ToApub,
+ get_shared_inbox, insert_activity, ActorType, FromApub, GroupExt, ToApub,
},
blocking,
routes::DbPoolParam,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams::{
activity::{Accept, Announce, Delete, Remove, Undo},
- Activity,
- Base,
- BaseBox,
+ Activity, Base, BaseBox,
};
use activitystreams_ext::Ext2;
use activitystreams_new::{
.as_xsd_any_uri()
.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 {
name: group.name().unwrap().as_single_xsd_string().unwrap().into(),
&community.name, &input
);
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 user = get_or_fetch_and_upsert_remote_user(&user_uri, &client, &db).await?;
blocking,
request::{retry, RecvError},
routes::nodeinfo::{NodeInfo, NodeInfoWellKnown},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
-use activitystreams::object::Note;
-use activitystreams_new::{base::BaseExt, prelude::*, primitives::XsdAnyUri};
+use activitystreams_new::{base::BaseExt, object::Note, prelude::*, primitives::XsdAnyUri};
use actix_web::client::Client;
use chrono::NaiveDateTime;
use diesel::{result::Error::NotFound, PgConnection};
post_view::PostView,
user::{UserForm, User_},
user_view::UserView,
- Crud,
- Joinable,
- SearchType,
+ Crud, Joinable, SearchType,
};
use lemmy_utils::get_apub_protocol_string;
use log::debug;
let response = match fetch_remote_object::<SearchAcceptedObjects>(client, &query_url).await? {
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?;
response
}
SearchAcceptedObjects::Comment(c) => {
- let post_url = c
- .object_props
- .get_many_in_reply_to_xsd_any_uris()
- .unwrap()
- .next()
- .unwrap()
- .to_string();
+ let post_url = c.in_reply_to.as_ref().unwrap().as_many().unwrap();
// 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 comment_form = CommentForm::from_apub(&c, client, pool).await?;
/// 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(
- apub_id: &str,
+ apub_id: &XsdAnyUri,
client: &Client,
pool: &DbPool,
) -> Result<User_, LemmyError> {
let apub_id_owned = apub_id.to_owned();
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?;
// If its older than a day, re-fetch it
Ok(u) if !u.local && should_refetch_actor(u.last_refreshed_at) => {
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?;
uf.last_refreshed_at = Some(naive_now());
Ok(u) => Ok(u),
Err(NotFound {}) => {
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 user = blocking(pool, move |conn| User_::create(conn, &uf)).await??;
let mut creator_and_moderators = Vec::new();
for uri in creator_and_moderator_uris {
- let c_or_m = get_or_fetch_and_upsert_remote_user(uri.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);
}
blocking,
request::{retry, RecvError},
routes::webfinger::WebFingerResponse,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_ext::{Ext1, Ext2};
use activitystreams_new::{
actor::{ApActor, Group, Person},
object::{Page, Tombstone},
prelude::*,
+ primitives::XsdAnyUri,
};
use actix_web::{body::Body, client::Client, HttpResponse};
use chrono::NaiveDateTime;
use lemmy_utils::{convert_datetime, get_apub_protocol_string, settings::Settings, MentionData};
use log::debug;
use serde::Serialize;
+use std::str::FromStr;
use url::Url;
type GroupExt = Ext2<ApActor<Group>, GroupExtension, PublicKeyExtension>;
pub async fn fetch_webfinger_url(
mention: &MentionData,
client: &Client,
-) -> Result<String, LemmyError> {
+) -> Result<XsdAnyUri, LemmyError> {
let fetch_url = format!(
"{}://{}/.well-known/webfinger?resource=acct:{}@{}",
get_apub_protocol_string(),
link
.href
.to_owned()
+ .map(|u| XsdAnyUri::from_str(&u))
+ .transpose()?
.ok_or_else(|| format_err!("No href found.").into())
}
use crate::{
apub::{
activities::{populate_object_props, send_activity_to_community},
- create_apub_response,
- create_apub_tombstone_response,
- create_tombstone,
+ create_apub_response, create_apub_tombstone_response, create_tombstone,
extensions::page_extension::PageExtension,
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
- ActorType,
- ApubLikeableType,
- ApubObjectType,
- FromApub,
- PageExt,
- ToApub,
+ ActorType, ApubLikeableType, ApubObjectType, FromApub, PageExt, ToApub,
},
blocking,
routes::DbPoolParam,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams::{
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
.as_ref()
.unwrap()
.as_single_xsd_any_uri()
- .unwrap()
- .as_str();
+ .unwrap();
let creator = get_or_fetch_and_upsert_remote_user(creator_actor_id, client, pool).await?;
use crate::{
apub::{
- activities::send_activity,
- create_tombstone,
- fetcher::get_or_fetch_and_upsert_remote_user,
- insert_activity,
- ApubObjectType,
- FromApub,
- ToApub,
+ activities::send_activity, create_tombstone, fetcher::get_or_fetch_and_upsert_remote_user,
+ insert_activity, ApubObjectType, FromApub, ToApub,
},
- blocking,
- DbPool,
- LemmyError,
+ blocking, DbPool, LemmyError,
};
use activitystreams::{
activity::{Create, Delete, Undo, Update},
pool: &DbPool,
) -> Result<PrivateMessageForm, LemmyError> {
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 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?;
community::do_announce,
extensions::signatures::verify,
fetcher::{
- get_or_fetch_and_insert_remote_comment,
- 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_insert_remote_comment, get_or_fetch_and_insert_remote_post,
+ get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user,
},
- insert_activity,
- FromApub,
- GroupExt,
- PageExt,
+ insert_activity, FromApub, GroupExt, PageExt,
},
blocking,
routes::{ChatServerParam, DbPoolParam},
server::{SendComment, SendCommunityRoomMessage, SendPost},
UserOperation,
},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams::{
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 lemmy_db::{
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
naive_now,
post::{Post, PostForm, PostLike, PostLikeForm},
post_view::PostView,
- Crud,
- Likeable,
+ Crud, Likeable,
};
use lemmy_utils::scrape_text_for_mentions;
use log::debug;
SharedAcceptedObjects::Announce(a) => a.announce_props.get_object_base_box(),
}
}
- fn sender(&self) -> String {
+ fn sender(&self) -> XsdAnyUri {
let uri = match self {
SharedAcceptedObjects::Create(c) => c.create_props.get_actor_xsd_any_uri(),
SharedAcceptedObjects::Update(u) => u.update_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(),
};
- uri.unwrap().clone().to_string()
+ uri.unwrap().clone()
}
fn cc(&self) -> String {
// TODO: there is probably an easier way to do this
let to = cc.replace("/followers", "");
// 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)?,
Err(_) => {
let c = get_or_fetch_and_upsert_remote_community(&sender.to_string(), &client, pool).await?;
async fn announce_activity_if_valid<A>(
activity: A,
community_uri: &str,
- sender: &str,
+ sender: &XsdAnyUri,
client: &Client,
pool: &DbPool,
) -> Result<HttpResponse, LemmyError>
.to_owned()
.into_concrete::<PageExt>()?;
- let user_uri = create
- .create_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = create.create_props.get_actor_xsd_any_uri().unwrap();
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
.to_owned()
.into_concrete::<Note>()?;
- let user_uri = create
- .create_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = create.create_props.get_actor_xsd_any_uri().unwrap();
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
.to_owned()
.into_concrete::<PageExt>()?;
- let user_uri = update
- .update_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = update.update_props.get_actor_xsd_any_uri().unwrap();
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
.to_owned()
.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?;
.to_owned()
.into_concrete::<PageExt>()?;
- let user_uri = dislike
- .dislike_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = dislike.dislike_props.get_actor_xsd_any_uri().unwrap();
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
.to_owned()
.into_concrete::<Note>()?;
- let user_uri = update
- .update_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = update.update_props.get_actor_xsd_any_uri().unwrap();
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
.to_owned()
.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?;
.to_owned()
.into_concrete::<Note>()?;
- let user_uri = dislike
- .dislike_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = dislike.dislike_props.get_actor_xsd_any_uri().unwrap();
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
pool: &DbPool,
chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
- let user_uri = delete
- .delete_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
let group = delete
.delete_props
pool: &DbPool,
chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
- let mod_uri = remove
- .remove_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let mod_uri = remove.remove_props.get_actor_xsd_any_uri().unwrap();
let group = remove
.remove_props
pool: &DbPool,
chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
- let user_uri = delete
- .delete_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
let page = delete
.delete_props
pool: &DbPool,
chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
- let mod_uri = remove
- .remove_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let mod_uri = remove.remove_props.get_actor_xsd_any_uri().unwrap();
let page = remove
.remove_props
pool: &DbPool,
chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
- let user_uri = delete
- .delete_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
let note = delete
.delete_props
pool: &DbPool,
chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
- let mod_uri = remove
- .remove_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let mod_uri = remove.remove_props.get_actor_xsd_any_uri().unwrap();
let note = remove
.remove_props
pool: &DbPool,
chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
- let user_uri = delete
- .delete_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
let note = delete
.delete_props
pool: &DbPool,
chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
- let mod_uri = remove
- .remove_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let mod_uri = remove.remove_props.get_actor_xsd_any_uri().unwrap();
let note = remove
.remove_props
pool: &DbPool,
chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
- let user_uri = delete
- .delete_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
let page = delete
.delete_props
pool: &DbPool,
chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
- let mod_uri = remove
- .remove_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let mod_uri = remove.remove_props.get_actor_xsd_any_uri().unwrap();
let page = remove
.remove_props
pool: &DbPool,
chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
- let user_uri = delete
- .delete_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
let group = delete
.delete_props
pool: &DbPool,
chat_server: ChatServerParam,
) -> Result<HttpResponse, LemmyError> {
- let mod_uri = remove
- .remove_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let mod_uri = remove.remove_props.get_actor_xsd_any_uri().unwrap();
let group = remove
.remove_props
.to_owned()
.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?;
.to_owned()
.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?;
use crate::{
api::claims::Claims,
apub::{
- activities::send_activity,
- create_apub_response,
- insert_activity,
- ActorType,
- FromApub,
- PersonExt,
- ToApub,
+ activities::send_activity, create_apub_response, insert_activity, ActorType, FromApub,
+ PersonExt, ToApub,
},
blocking,
routes::DbPoolParam,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_ext::Ext1;
use activitystreams_new::{
apub::{
extensions::signatures::verify,
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
- insert_activity,
- FromApub,
+ insert_activity, FromApub,
},
blocking,
routes::{ChatServerParam, DbPoolParam},
websocket::{server::SendUserRoomMessage, UserOperation},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams::{
activity::{Accept, Create, Delete, Undo, Update},
private_message::{PrivateMessage, PrivateMessageForm},
private_message_view::PrivateMessageView,
user::User_,
- Crud,
- Followable,
+ Crud, Followable,
};
use log::debug;
use serde::Deserialize;
.to_owned()
.into_concrete::<Note>()?;
- let user_uri = create
- .create_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = create.create_props.get_actor_xsd_any_uri().unwrap();
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
verify(request, &user)?;
.to_owned()
.into_concrete::<Note>()?;
- let user_uri = update
- .update_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = update.update_props.get_actor_xsd_any_uri().unwrap();
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
verify(request, &user)?;
.to_owned()
.into_concrete::<Note>()?;
- let user_uri = delete
- .delete_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
verify(request, &user)?;
.to_owned()
.into_concrete::<Note>()?;
- let user_uri = delete
- .delete_props
- .get_actor_xsd_any_uri()
- .unwrap()
- .to_string();
+ let user_uri = delete.delete_props.get_actor_xsd_any_uri().unwrap();
let user = get_or_fetch_and_upsert_remote_user(&user_uri, client, pool).await?;
verify(request, &user)?;