// apub updates
CreateOrUpdatePost::send(
- &updated_post,
+ updated_post,
&local_user_view.person.clone().into(),
CreateOrUpdateType::Update,
context,
// Apub updates
// TODO stickied should pry work like locked for ease of use
CreateOrUpdatePost::send(
- &updated_post,
+ updated_post,
&local_user_view.person.clone().into(),
CreateOrUpdateType::Update,
context,
+use crate::PerformCrud;
use actix_web::web::Data;
-
use lemmy_api_common::{
blocking,
check_community_ban,
use lemmy_apub::{
fetcher::post_or_comment::PostOrComment,
generate_local_apub_endpoint,
+ objects::comment::ApubComment,
protocol::activities::{
create_or_update::comment::CreateOrUpdateComment,
voting::vote::{Vote, VoteType},
UserOperationCrud,
};
-use crate::PerformCrud;
-
#[async_trait::async_trait(?Send)]
impl PerformCrud for CreateComment {
type Response = CommentResponse;
.await?
.map_err(|e| ApiError::err("couldnt_create_comment", e))?;
- CreateOrUpdateComment::send(
- &updated_comment.clone().into(),
- &local_user_view.person.clone().into(),
- CreateOrUpdateType::Create,
- context,
- )
- .await?;
-
// Scan the comment for user mentions, add those rows
let post_id = post.id;
let mentions = scrape_text_for_mentions(&comment_form.content);
.await?
.map_err(|e| ApiError::err("couldnt_like_comment", e))?;
- let object = PostOrComment::Comment(updated_comment.into());
+ let apub_comment: ApubComment = updated_comment.into();
+ CreateOrUpdateComment::send(
+ apub_comment.clone(),
+ &local_user_view.person.clone().into(),
+ CreateOrUpdateType::Create,
+ context,
+ )
+ .await?;
+ let object = PostOrComment::Comment(apub_comment);
Vote::send(
&object,
&local_user_view.person.clone().into(),
.await?
.map_err(|e| ApiError::err("couldnt_update_comment", e))?;
- // Send the apub update
- CreateOrUpdateComment::send(
- &updated_comment.clone().into(),
- &local_user_view.person.clone().into(),
- CreateOrUpdateType::Update,
- context,
- )
- .await?;
-
// Do the mentions / recipients
let updated_comment_content = updated_comment.content.to_owned();
let mentions = scrape_text_for_mentions(&updated_comment_content);
)
.await?;
+ // Send the apub update
+ CreateOrUpdateComment::send(
+ updated_comment.into(),
+ &local_user_view.person.into(),
+ CreateOrUpdateType::Update,
+ context,
+ )
+ .await?;
+
send_comment_ws_message(
data.comment_id,
UserOperationCrud::EditComment,
.map_err(|e| ApiError::err("couldnt_update_community", e))?;
UpdateCommunity::send(
- &updated_community.into(),
+ updated_community.into(),
&local_user_view.person.into(),
context,
)
use lemmy_apub::{
fetcher::post_or_comment::PostOrComment,
generate_local_apub_endpoint,
+ objects::post::ApubPost,
protocol::activities::{
create_or_update::post::CreateOrUpdatePost,
voting::vote::{Vote, VoteType},
.await?
.map_err(|e| ApiError::err("couldnt_create_post", e))?;
- CreateOrUpdatePost::send(
- &updated_post.clone().into(),
- &local_user_view.person.clone().into(),
- CreateOrUpdateType::Create,
- context,
- )
- .await?;
-
// They like their own post by default
let person_id = local_user_view.person.id;
let post_id = inserted_post.id;
}
}
- let object = PostOrComment::Post(Box::new(updated_post.into()));
+ let apub_post: ApubPost = updated_post.into();
+ CreateOrUpdatePost::send(
+ apub_post.clone(),
+ &local_user_view.person.clone().into(),
+ CreateOrUpdateType::Create,
+ context,
+ )
+ .await?;
+ let object = PostOrComment::Post(Box::new(apub_post));
Vote::send(
&object,
&local_user_view.person.clone().into(),
// Send apub update
CreateOrUpdatePost::send(
- &updated_post.into(),
+ updated_post.into(),
&local_user_view.person.clone().into(),
CreateOrUpdateType::Update,
context,
.map_err(|e| ApiError::err("couldnt_create_private_message", e))?;
CreateOrUpdatePrivateMessage::send(
- &updated_private_message.into(),
+ updated_private_message.into(),
&local_user_view.person.into(),
CreateOrUpdateType::Create,
context,
// Send the apub update
CreateOrUpdatePrivateMessage::send(
- &updated_private_message.into(),
+ updated_private_message.into(),
&local_user_view.person.into(),
CreateOrUpdateType::Update,
context,
impl CreateOrUpdateComment {
pub async fn send(
- comment: &ApubComment,
+ comment: ApubComment,
actor: &ApubPerson,
kind: CreateOrUpdateType,
context: &LemmyContext,
kind.clone(),
&context.settings().get_protocol_and_hostname(),
)?;
- let maa = collect_non_local_mentions(comment, &community, context).await?;
+ let maa = collect_non_local_mentions(&comment, &community, context).await?;
let create_or_update = CreateOrUpdateComment {
actor: ObjectId::new(actor.actor_id()),
to: vec![public()],
- object: comment.to_apub(context).await?,
+ object: comment.into_apub(context).await?,
cc: maa.ccs,
tag: maa.tags,
kind,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
let comment =
- ApubComment::from_apub(&self.object, context, self.actor.inner(), request_counter).await?;
+ ApubComment::from_apub(self.object, context, self.actor.inner(), request_counter).await?;
let recipients = get_notif_recipients(&self.actor, &comment, context, request_counter).await?;
let notif_type = match self.kind {
CreateOrUpdateType::Create => UserOperationCrud::CreateComment,
impl UpdateCommunity {
pub async fn send(
- community: &ApubCommunity,
+ community: ApubCommunity,
actor: &ApubPerson,
context: &LemmyContext,
) -> Result<(), LemmyError> {
let update = UpdateCommunity {
actor: ObjectId::new(actor.actor_id()),
to: vec![public()],
- object: community.to_apub(context).await?,
+ object: community.clone().into_apub(context).await?,
cc: vec![community.actor_id()],
kind: UpdateType::Update,
id: id.clone(),
};
let activity = AnnouncableActivities::UpdateCommunity(Box::new(update));
- send_to_community(activity, &id, actor, community, vec![], context).await
+ send_to_community(activity, &id, actor, &community, vec![], context).await
}
}
) -> Result<(), LemmyError> {
let community = self.get_community(context, request_counter).await?;
- let updated_community = Group::from_apub_to_form(
- &self.object,
+ let updated_community = Group::into_form(
+ self.object,
&community.actor_id.clone().into(),
&context.settings(),
)
impl CreateOrUpdatePost {
pub(crate) async fn new(
- post: &ApubPost,
+ post: ApubPost,
actor: &ApubPerson,
community: &ApubCommunity,
kind: CreateOrUpdateType,
Ok(CreateOrUpdatePost {
actor: ObjectId::new(actor.actor_id()),
to: vec![public()],
- object: post.to_apub(context).await?,
+ object: post.into_apub(context).await?,
cc: vec![community.actor_id()],
kind,
id: id.clone(),
})
}
pub async fn send(
- post: &ApubPost,
+ post: ApubPost,
actor: &ApubPerson,
kind: CreateOrUpdateType,
context: &LemmyContext,
) -> Result<(), LemmyError> {
let actor = self.actor.dereference(context, request_counter).await?;
let post =
- ApubPost::from_apub(&self.object, context, &actor.actor_id(), request_counter).await?;
+ ApubPost::from_apub(self.object, context, &actor.actor_id(), request_counter).await?;
let notif_type = match self.kind {
CreateOrUpdateType::Create => UserOperationCrud::CreatePost,
impl CreateOrUpdatePrivateMessage {
pub async fn send(
- private_message: &ApubPrivateMessage,
+ private_message: ApubPrivateMessage,
actor: &ApubPerson,
kind: CreateOrUpdateType,
context: &LemmyContext,
id: id.clone(),
actor: ObjectId::new(actor.actor_id()),
to: [ObjectId::new(recipient.actor_id())],
- object: private_message.to_apub(context).await?,
+ object: private_message.into_apub(context).await?,
kind,
unparsed: Default::default(),
};
request_counter: &mut i32,
) -> Result<(), LemmyError> {
let private_message =
- ApubPrivateMessage::from_apub(&self.object, context, self.actor.inner(), request_counter)
+ ApubPrivateMessage::from_apub(self.object, context, self.actor.inner(), request_counter)
.await?;
let notif_type = match self.kind {
unimplemented!()
}
- async fn to_apub(&self, data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
+ async fn into_apub(self, data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
let ordered_items = self
.0
- .iter()
- .map(|m| ObjectId::<ApubPerson>::new(m.moderator.actor_id.clone()))
+ .into_iter()
+ .map(|m| ObjectId::<ApubPerson>::new(m.moderator.actor_id))
.collect();
Ok(GroupModerators {
r#type: OrderedCollectionType::OrderedCollection,
}
async fn from_apub(
- apub: &Self::ApubType,
+ apub: Self::ApubType,
data: &Self::DataType,
expected_domain: &Url,
request_counter: &mut i32,
}
// Add new mods to database which have been added to moderators collection
- for mod_id in &apub.ordered_items {
- let mod_id = ObjectId::new(mod_id.clone());
+ for mod_id in apub.ordered_items {
+ let mod_id = ObjectId::new(mod_id);
let mod_user: ApubPerson = mod_id.dereference(&data.1, request_counter).await?;
if !current_moderators
- .clone()
.iter()
.map(|c| c.moderator.actor_id.clone())
.any(|x| x == mod_user.actor_id)
0: community,
1: context,
};
- ApubCommunityModerators::from_apub(&json, &community_context, &url, &mut request_counter)
+ ApubCommunityModerators::from_apub(json, &community_context, &url, &mut request_counter)
.await
.unwrap();
assert_eq!(request_counter, 0);
Ok(())
}
- async fn to_apub(&self, data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
+ async fn into_apub(self, data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
let mut ordered_items = vec![];
- for post in &self.0 {
+ for post in self.0 {
let actor = post.creator_id;
let actor: ApubPerson = blocking(data.1.pool(), move |conn| Person::read(conn, actor))
.await??
}
async fn from_apub(
- apub: &Self::ApubType,
+ apub: Self::ApubType,
data: &Self::DataType,
expected_domain: &Url,
request_counter: &mut i32,
) -> Result<Self, LemmyError> {
verify_domains_match(expected_domain, &apub.id)?;
- let mut outbox_activities = apub.ordered_items.clone();
+ let mut outbox_activities = apub.ordered_items;
if outbox_activities.len() > 20 {
outbox_activities = outbox_activities[0..20].to_vec();
}
}
}
- async fn to_apub(&self, _data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
+ async fn into_apub(self, _data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
unimplemented!()
}
}
async fn from_apub(
- apub: &PageOrNote,
+ apub: PageOrNote,
context: &LemmyContext,
expected_domain: &Url,
request_counter: &mut i32,
) -> Result<Self, LemmyError> {
Ok(match apub {
PageOrNote::Page(p) => PostOrComment::Post(Box::new(
- ApubPost::from_apub(p, context, expected_domain, request_counter).await?,
+ ApubPost::from_apub(*p, context, expected_domain, request_counter).await?,
)),
PageOrNote::Note(n) => PostOrComment::Comment(
- ApubComment::from_apub(n, context, expected_domain, request_counter).await?,
+ ApubComment::from_apub(*n, context, expected_domain, request_counter).await?,
),
})
}
}
}
- async fn to_apub(&self, _data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
+ async fn into_apub(self, _data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
unimplemented!()
}
}
async fn from_apub(
- apub: &Self::ApubType,
+ apub: Self::ApubType,
context: &LemmyContext,
ed: &Url,
rc: &mut i32,
}
}
- async fn to_apub(&self, _data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
+ async fn into_apub(self, _data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
unimplemented!()
}
}
async fn from_apub(
- apub: &Self::ApubType,
+ apub: Self::ApubType,
data: &Self::DataType,
expected_domain: &Url,
request_counter: &mut i32,
}
if !comment.deleted {
- Ok(create_apub_response(&comment.to_apub(&**context).await?))
+ Ok(create_apub_response(&comment.into_apub(&**context).await?))
} else {
Ok(create_apub_tombstone_response(&comment.to_tombstone()?))
}
.into();
if !community.deleted {
- let apub = community.to_apub(&**context).await?;
+ let apub = community.into_apub(&**context).await?;
Ok(create_apub_response(&apub))
} else {
let id = ObjectId::new(generate_outbox_url(&community.actor_id)?);
let outbox_data = CommunityContext(community.into(), context.get_ref().clone());
let outbox: ApubCommunityOutbox = id.dereference(&outbox_data, &mut 0).await?;
- Ok(create_apub_response(&outbox.to_apub(&outbox_data).await?))
+ Ok(create_apub_response(&outbox.into_apub(&outbox_data).await?))
}
pub(crate) async fn get_apub_community_moderators(
let outbox_data = CommunityContext(community, context.get_ref().clone());
let moderators: ApubCommunityModerators = id.dereference(&outbox_data, &mut 0).await?;
Ok(create_apub_response(
- &moderators.to_apub(&outbox_data).await?,
+ &moderators.into_apub(&outbox_data).await?,
))
}
.into();
if !person.deleted {
- let apub = person.to_apub(&context).await?;
+ let apub = person.into_apub(&context).await?;
Ok(create_apub_response(&apub))
} else {
}
if !post.deleted {
- Ok(create_apub_response(&post.to_apub(&context).await?))
+ Ok(create_apub_response(&post.into_apub(&context).await?))
} else {
Ok(create_apub_tombstone_response(&post.to_tombstone()?))
}
Ok(())
}
- async fn to_apub(&self, context: &LemmyContext) -> Result<Note, LemmyError> {
+ async fn into_apub(self, context: &LemmyContext) -> Result<Note, LemmyError> {
let creator_id = self.creator_id;
let creator = blocking(context.pool(), move |conn| Person::read(conn, creator_id)).await??;
let note = Note {
r#type: NoteType::Note,
- id: ObjectId::new(self.ap_id.to_owned()),
+ id: ObjectId::new(self.ap_id.clone()),
attributed_to: ObjectId::new(creator.actor_id),
to: vec![public()],
content: markdown_to_html(&self.content),
///
/// If the parent community, post and comment(s) are not known locally, these are also fetched.
async fn from_apub(
- note: &Note,
+ note: Note,
context: &LemmyContext,
expected_domain: &Url,
request_counter: &mut i32,
) -> Result<ApubComment, LemmyError> {
verify_domains_match(note.id.inner(), expected_domain)?;
- let ap_id = Some(note.id.clone().into());
let creator = note
.attributed_to
.dereference(context, request_counter)
content: content_slurs_removed,
removed: None,
read: None,
- published: note.published.map(|u| u.to_owned().naive_local()),
- updated: note.updated.map(|u| u.to_owned().naive_local()),
+ published: note.published.map(|u| u.naive_local()),
+ updated: note.updated.map(|u| u.naive_local()),
deleted: None,
- ap_id,
+ ap_id: Some(note.id.into()),
local: Some(false),
};
let comment = blocking(context.pool(), move |conn| Comment::upsert(conn, &form)).await??;
let person = parse_lemmy_person(context).await;
let community = parse_lemmy_community(context).await;
let post_json = file_to_json_object("assets/lemmy/objects/page.json");
- let post = ApubPost::from_apub(&post_json, context, url, &mut 0)
+ let post = ApubPost::from_apub(post_json, context, url, &mut 0)
.await
.unwrap();
(person, community, post)
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741").unwrap();
let data = prepare_comment_test(&url, &context).await;
- let json = file_to_json_object("assets/lemmy/objects/note.json");
+ let json: Note = file_to_json_object("assets/lemmy/objects/note.json");
let mut request_counter = 0;
- let comment = ApubComment::from_apub(&json, &context, &url, &mut request_counter)
+ let comment = ApubComment::from_apub(json.clone(), &context, &url, &mut request_counter)
.await
.unwrap();
assert!(!comment.local);
assert_eq!(request_counter, 0);
- let to_apub = comment.to_apub(&context).await.unwrap();
+ let comment_id = comment.id;
+ let to_apub = comment.into_apub(&context).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
- Comment::delete(&*context.pool().get().unwrap(), comment.id).unwrap();
+ Comment::delete(&*context.pool().get().unwrap(), comment_id).unwrap();
cleanup(data, &context);
}
Url::parse("https://queer.hacktivis.me/objects/8d4973f4-53de-49cd-8c27-df160e16a9c2")
.unwrap();
let person_json = file_to_json_object("assets/pleroma/objects/person.json");
- ApubPerson::from_apub(&person_json, &context, &pleroma_url, &mut 0)
+ ApubPerson::from_apub(person_json, &context, &pleroma_url, &mut 0)
.await
.unwrap();
let json = file_to_json_object("assets/pleroma/objects/note.json");
let mut request_counter = 0;
- let comment = ApubComment::from_apub(&json, &context, &pleroma_url, &mut request_counter)
+ let comment = ApubComment::from_apub(json, &context, &pleroma_url, &mut request_counter)
.await
.unwrap();
Ok(())
}
- async fn to_apub(&self, _context: &LemmyContext) -> Result<Group, LemmyError> {
+ async fn into_apub(self, _context: &LemmyContext) -> Result<Group, LemmyError> {
let source = self.description.clone().map(|bio| Source {
content: bio,
media_type: MediaTypeMarkdown::Markdown,
/// Converts a `Group` to `Community`, inserts it into the database and updates moderators.
async fn from_apub(
- group: &Group,
+ group: Group,
context: &LemmyContext,
expected_domain: &Url,
request_counter: &mut i32,
) -> Result<ApubCommunity, LemmyError> {
- let form = Group::from_apub_to_form(group, expected_domain, &context.settings()).await?;
+ let form = Group::into_form(group.clone(), expected_domain, &context.settings()).await?;
// Fetching mods and outbox is not necessary for Lemmy to work, so ignore errors. Besides,
// we need to ignore these errors so that tests can work entirely offline.
let url = Url::parse("https://enterprise.lemmy.ml/c/tenforward").unwrap();
let mut request_counter = 0;
- let community = ApubCommunity::from_apub(&json, context, &url, &mut request_counter)
+ let community = ApubCommunity::from_apub(json, context, &url, &mut request_counter)
.await
.unwrap();
// this makes two requests to the (intentionally) broken outbox/moderators collections
Ok(())
}
- async fn to_apub(&self, _pool: &LemmyContext) -> Result<Person, LemmyError> {
+ async fn into_apub(self, _pool: &LemmyContext) -> Result<Person, LemmyError> {
let kind = if self.bot_account {
UserTypes::Service
} else {
}
async fn from_apub(
- person: &Person,
+ person: Person,
context: &LemmyContext,
expected_domain: &Url,
_request_counter: &mut i32,
) -> Result<ApubPerson, LemmyError> {
verify_domains_match(person.id.inner(), expected_domain)?;
- let actor_id = Some(person.id.clone().into());
- let name = person.preferred_username.clone();
- let display_name: Option<String> = person.name.clone();
+ let name = person.preferred_username;
+ let display_name: Option<String> = person.name;
let bio = get_summary_from_string_or_source(&person.summary, &person.source);
- let shared_inbox = person.endpoints.shared_inbox.clone().map(|s| s.into());
+ let shared_inbox = person.endpoints.shared_inbox.map(|s| s.into());
let bot_account = match person.kind {
UserTypes::Person => false,
UserTypes::Service => true,
display_name: Some(display_name),
banned: None,
deleted: None,
- avatar: Some(person.icon.clone().map(|i| i.url.into())),
- banner: Some(person.image.clone().map(|i| i.url.into())),
- published: person.published.map(|u| u.clone().naive_local()),
- updated: person.updated.map(|u| u.clone().naive_local()),
- actor_id,
+ avatar: Some(person.icon.map(|i| i.url.into())),
+ banner: Some(person.image.map(|i| i.url.into())),
+ published: person.published.map(|u| u.naive_local()),
+ updated: person.updated.map(|u| u.naive_local()),
+ actor_id: Some(person.id.into()),
bio: Some(bio),
local: Some(false),
admin: Some(false),
bot_account: Some(bot_account),
private_key: None,
- public_key: Some(Some(person.public_key.public_key_pem.clone())),
+ public_key: Some(Some(person.public_key.public_key_pem)),
last_refreshed_at: Some(naive_now()),
- inbox_url: Some(person.inbox.to_owned().into()),
+ inbox_url: Some(person.inbox.into()),
shared_inbox_url: Some(shared_inbox),
- matrix_user_id: Some(person.matrix_user_id.clone()),
+ matrix_user_id: Some(person.matrix_user_id),
};
let person = blocking(context.pool(), move |conn| {
DbPerson::upsert(conn, &person_form)
let json = file_to_json_object("assets/lemmy/objects/person.json");
let url = Url::parse("https://enterprise.lemmy.ml/u/picard").unwrap();
let mut request_counter = 0;
- let person = ApubPerson::from_apub(&json, context, &url, &mut request_counter)
+ let person = ApubPerson::from_apub(json, context, &url, &mut request_counter)
.await
.unwrap();
assert_eq!(request_counter, 0);
let json = file_to_json_object("assets/pleroma/objects/person.json");
let url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
let mut request_counter = 0;
- let person = ApubPerson::from_apub(&json, &context, &url, &mut request_counter)
+ let person = ApubPerson::from_apub(json, &context, &url, &mut request_counter)
.await
.unwrap();
}
// Turn a Lemmy post into an ActivityPub page that can be sent out over the network.
- async fn to_apub(&self, context: &LemmyContext) -> Result<Page, LemmyError> {
+ async fn into_apub(self, context: &LemmyContext) -> Result<Page, LemmyError> {
let creator_id = self.creator_id;
let creator = blocking(context.pool(), move |conn| Person::read(conn, creator_id)).await??;
let community_id = self.community_id;
}
async fn from_apub(
- page: &Page,
+ page: Page,
context: &LemmyContext,
expected_domain: &Url,
request_counter: &mut i32,
if !page.is_mod_action(context).await? {
verify_domains_match(page.id.inner(), expected_domain)?;
};
- let ap_id = Some(page.id.clone().into());
let creator = page
.attributed_to
.dereference(context, request_counter)
check_is_apub_id_valid(page.id.inner(), community.local, &context.settings())?;
verify_person_in_community(&page.attributed_to, &community, context, request_counter).await?;
- let thumbnail_url: Option<Url> = page.image.clone().map(|i| i.url);
+ let thumbnail_url: Option<Url> = page.image.map(|i| i.url);
let (metadata_res, pictrs_thumbnail) = if let Some(url) = &page.url {
fetch_site_data(context.client(), &context.settings(), Some(url)).await
} else {
.as_ref()
.map(|s| remove_slurs(&s.content, &context.settings().slur_regex()));
let form = PostForm {
- name: page.name.clone(),
- url: page.url.clone().map(|u| u.into()),
+ name: page.name,
+ url: page.url.map(|u| u.into()),
body: body_slurs_removed,
creator_id: creator.id,
community_id: community.id,
embed_description,
embed_html,
thumbnail_url: pictrs_thumbnail.map(|u| u.into()),
- ap_id,
+ ap_id: Some(page.id.into()),
local: Some(false),
};
let post = blocking(context.pool(), move |conn| Post::upsert(conn, &form)).await??;
let json = file_to_json_object("assets/lemmy/objects/page.json");
let url = Url::parse("https://enterprise.lemmy.ml/post/55143").unwrap();
let mut request_counter = 0;
- let post = ApubPost::from_apub(&json, &context, &url, &mut request_counter)
+ let post = ApubPost::from_apub(json, &context, &url, &mut request_counter)
.await
.unwrap();
unimplemented!()
}
- async fn to_apub(&self, context: &LemmyContext) -> Result<ChatMessage, LemmyError> {
+ async fn into_apub(self, context: &LemmyContext) -> Result<ChatMessage, LemmyError> {
let creator_id = self.creator_id;
let creator = blocking(context.pool(), move |conn| Person::read(conn, creator_id)).await??;
}
async fn from_apub(
- note: &ChatMessage,
+ note: ChatMessage,
context: &LemmyContext,
expected_domain: &Url,
request_counter: &mut i32,
) -> Result<ApubPrivateMessage, LemmyError> {
verify_domains_match(note.id.inner(), expected_domain)?;
- let ap_id = Some(note.id.clone().into());
+ let ap_id = Some(note.id.into());
let creator = note
.attributed_to
.dereference(context, request_counter)
creator_id: creator.id,
recipient_id: recipient.id,
content,
- published: note.published.map(|u| u.to_owned().naive_local()),
- updated: note.updated.map(|u| u.to_owned().naive_local()),
+ published: note.published.map(|u| u.naive_local()),
+ updated: note.updated.map(|u| u.naive_local()),
deleted: None,
read: None,
ap_id,
async fn prepare_comment_test(url: &Url, context: &LemmyContext) -> (ApubPerson, ApubPerson) {
let lemmy_person = file_to_json_object("assets/lemmy/objects/person.json");
- let person1 = ApubPerson::from_apub(&lemmy_person, context, url, &mut 0)
+ let person1 = ApubPerson::from_apub(lemmy_person, context, url, &mut 0)
.await
.unwrap();
let pleroma_person = file_to_json_object("assets/pleroma/objects/person.json");
let pleroma_url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
- let person2 = ApubPerson::from_apub(&pleroma_person, context, &pleroma_url, &mut 0)
+ let person2 = ApubPerson::from_apub(pleroma_person, context, &pleroma_url, &mut 0)
.await
.unwrap();
(person1, person2)
let context = init_context();
let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap();
let data = prepare_comment_test(&url, &context).await;
- let json = file_to_json_object("assets/lemmy/objects/chat_message.json");
+ let json: ChatMessage = file_to_json_object("assets/lemmy/objects/chat_message.json");
let mut request_counter = 0;
- let pm = ApubPrivateMessage::from_apub(&json, &context, &url, &mut request_counter)
+ let pm = ApubPrivateMessage::from_apub(json.clone(), &context, &url, &mut request_counter)
.await
.unwrap();
assert_eq!(pm.content.len(), 20);
assert_eq!(request_counter, 0);
- let to_apub = pm.to_apub(&context).await.unwrap();
+ let pm_id = pm.id;
+ let to_apub = pm.into_apub(&context).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
- PrivateMessage::delete(&*context.pool().get().unwrap(), pm.id).unwrap();
+ PrivateMessage::delete(&*context.pool().get().unwrap(), pm_id).unwrap();
cleanup(data, &context);
}
let pleroma_url = Url::parse("https://queer.hacktivis.me/objects/2").unwrap();
let json = file_to_json_object("assets/pleroma/objects/chat_message.json");
let mut request_counter = 0;
- let pm = ApubPrivateMessage::from_apub(&json, &context, &pleroma_url, &mut request_counter)
+ let pm = ApubPrivateMessage::from_apub(json, &context, &pleroma_url, &mut request_counter)
.await
.unwrap();
}
impl Group {
- pub(crate) async fn from_apub_to_form(
- group: &Group,
+ pub(crate) async fn into_form(
+ self,
expected_domain: &Url,
settings: &Settings,
) -> Result<CommunityForm, LemmyError> {
- check_is_apub_id_valid(group.id.inner(), true, settings)?;
- verify_domains_match(expected_domain, group.id.inner())?;
- let name = group.preferred_username.clone();
- let title = group.name.clone();
- let description = get_summary_from_string_or_source(&group.summary, &group.source);
- let shared_inbox = group.endpoints.shared_inbox.clone().map(|s| s.into());
+ check_is_apub_id_valid(self.id.inner(), true, settings)?;
+ verify_domains_match(expected_domain, self.id.inner())?;
+ let name = self.preferred_username;
+ let title = self.name;
+ let description = get_summary_from_string_or_source(&self.summary, &self.source);
+ let shared_inbox = self.endpoints.shared_inbox.map(|s| s.into());
let slur_regex = &settings.slur_regex();
check_slurs(&name, slur_regex)?;
title,
description,
removed: None,
- published: group.published.map(|u| u.naive_local()),
- updated: group.updated.map(|u| u.naive_local()),
+ published: self.published.map(|u| u.naive_local()),
+ updated: self.updated.map(|u| u.naive_local()),
deleted: None,
- nsfw: Some(group.sensitive.unwrap_or(false)),
- actor_id: Some(group.id.clone().into()),
+ nsfw: Some(self.sensitive.unwrap_or(false)),
+ actor_id: Some(self.id.into()),
local: Some(false),
private_key: None,
- public_key: Some(group.public_key.public_key_pem.clone()),
+ public_key: Some(self.public_key.public_key_pem),
last_refreshed_at: Some(naive_now()),
- icon: Some(group.icon.clone().map(|i| i.url.into())),
- banner: Some(group.image.clone().map(|i| i.url.into())),
- followers_url: Some(group.followers.clone().into()),
- inbox_url: Some(group.inbox.clone().into()),
+ icon: Some(self.icon.map(|i| i.url.into())),
+ banner: Some(self.image.map(|i| i.url.into())),
+ followers_url: Some(self.followers.into()),
+ inbox_url: Some(self.inbox.into()),
shared_inbox_url: Some(shared_inbox),
})
}
let res2: Kind::ApubType = res.json().await?;
- Ok(Kind::from_apub(&res2, data, self.inner(), request_counter).await?)
+ Ok(Kind::from_apub(res2, data, self.inner(), request_counter).await?)
}
}
async fn delete(self, data: &Self::DataType) -> Result<(), LemmyError>;
/// Trait for converting an object or actor into the respective ActivityPub type.
- async fn to_apub(&self, data: &Self::DataType) -> Result<Self::ApubType, LemmyError>;
+ async fn into_apub(self, data: &Self::DataType) -> Result<Self::ApubType, LemmyError>;
fn to_tombstone(&self) -> Result<Self::TombstoneType, LemmyError>;
/// Converts an object from ActivityPub type to Lemmy internal type.
/// * `expected_domain` Domain where the object was received from. None in case of mod action.
/// * `mod_action_allowed` True if the object can be a mod activity, ignore `expected_domain` in this case
async fn from_apub(
- apub: &Self::ApubType,
+ apub: Self::ApubType,
data: &Self::DataType,
expected_domain: &Url,
request_counter: &mut i32,