note: &Note,
client: &Client,
pool: &DbPool,
- actor_id: &Url,
) -> Result<CommentForm, LemmyError> {
let creator_actor_id = ¬e
.attributed_to()
published: note.published().map(|u| u.to_owned().naive_local()),
updated: note.updated().map(|u| u.to_owned().naive_local()),
deleted: None,
- ap_id: note.id(actor_id.domain().unwrap())?.unwrap().to_string(),
+ ap_id: note.id_unchecked().unwrap().to_string(),
local: false,
})
}
type ApubType = GroupExt;
/// Parse an ActivityPub group received from another instance into a Lemmy community.
- async fn from_apub(
- group: &GroupExt,
- client: &Client,
- pool: &DbPool,
- actor_id: &Url,
- ) -> Result<Self, LemmyError> {
+ async fn from_apub(group: &GroupExt, client: &Client, pool: &DbPool) -> Result<Self, LemmyError> {
let creator_and_moderator_uris = group.inner.attributed_to().unwrap();
let creator_uri = creator_and_moderator_uris
.as_many()
updated: group.inner.updated().map(|u| u.to_owned().naive_local()),
deleted: None,
nsfw: group.ext_one.sensitive,
- actor_id: group
- .inner
- .id(actor_id.domain().unwrap())?
- .unwrap()
- .to_string(),
+ actor_id: group.inner.id_unchecked().unwrap().to_string(),
local: false,
private_key: None,
public_key: Some(group.ext_two.to_owned().public_key.public_key_pem),
response
}
SearchAcceptedObjects::Page(p) => {
- let post_form = PostForm::from_apub(&p, client, pool, &query_url).await?;
+ let post_form = PostForm::from_apub(&p, client, pool).await?;
let p = blocking(pool, move |conn| upsert_post(&post_form, conn)).await??;
response.posts = vec![blocking(pool, move |conn| PostView::read(conn, p.id, None)).await??];
// TODO: also fetch parent comments if any
let x = post_url.first().unwrap().as_xsd_any_uri().unwrap();
let post = fetch_remote_object(client, x).await?;
- let post_form = PostForm::from_apub(&post, client, pool, &query_url).await?;
- let comment_form = CommentForm::from_apub(&c, client, pool, &query_url).await?;
+ let post_form = PostForm::from_apub(&post, client, pool).await?;
+ let comment_form = CommentForm::from_apub(&c, client, pool).await?;
blocking(pool, move |conn| upsert_post(&post_form, conn)).await??;
let c = blocking(pool, move |conn| upsert_comment(&comment_form, conn)).await??;
debug!("Fetching and updating from remote user: {}", apub_id);
let person = fetch_remote_object::<PersonExt>(client, apub_id).await?;
- let mut uf = UserForm::from_apub(&person, client, pool, apub_id).await?;
+ let mut uf = UserForm::from_apub(&person, client, pool).await?;
uf.last_refreshed_at = Some(naive_now());
let user = blocking(pool, move |conn| User_::update(conn, u.id, &uf)).await??;
debug!("Fetching and creating remote user: {}", apub_id);
let person = fetch_remote_object::<PersonExt>(client, apub_id).await?;
- let uf = UserForm::from_apub(&person, client, pool, apub_id).await?;
+ let uf = UserForm::from_apub(&person, client, pool).await?;
let user = blocking(pool, move |conn| User_::create(conn, &uf)).await??;
Ok(user)
debug!("Fetching and updating from remote community: {}", apub_id);
let group = fetch_remote_object::<GroupExt>(client, apub_id).await?;
- let mut cf = CommunityForm::from_apub(&group, client, pool, apub_id).await?;
+ let mut cf = CommunityForm::from_apub(&group, client, pool).await?;
cf.last_refreshed_at = Some(naive_now());
let community = blocking(pool, move |conn| Community::update(conn, c.id, &cf)).await??;
debug!("Fetching and creating remote community: {}", apub_id);
let group = fetch_remote_object::<GroupExt>(client, apub_id).await?;
- let cf = CommunityForm::from_apub(&group, client, pool, apub_id).await?;
+ let cf = CommunityForm::from_apub(&group, client, pool).await?;
let community = blocking(pool, move |conn| Community::create(conn, &cf)).await??;
// Also add the community moderators too
Err(NotFound {}) => {
debug!("Fetching and creating remote post: {}", post_ap_id);
let post = fetch_remote_object::<PageExt>(client, post_ap_id).await?;
- let post_form = PostForm::from_apub(&post, client, pool, post_ap_id).await?;
+ let post_form = PostForm::from_apub(&post, client, pool).await?;
let post = blocking(pool, move |conn| Post::create(conn, &post_form)).await??;
comment_ap_id
);
let comment = fetch_remote_object::<Note>(client, comment_ap_id).await?;
- let comment_form = CommentForm::from_apub(&comment, client, pool, comment_ap_id).await?;
+ let comment_form = CommentForm::from_apub(&comment, client, pool).await?;
let comment = blocking(pool, move |conn| Comment::create(conn, &comment_form)).await??;
get_user_from_activity,
receive_unhandled_activity,
},
- ActorType,
FromApub,
PageExt,
},
let user = get_user_from_activity(&create, client, pool).await?;
let page = PageExt::from_any_base(create.object().to_owned().one().unwrap())?.unwrap();
- let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
+ let post = PostForm::from_apub(&page, client, pool).await?;
let inserted_post = blocking(pool, move |conn| Post::create(conn, &post)).await??;
let user = get_user_from_activity(&create, client, pool).await?;
let note = Note::from_any_base(create.object().to_owned().one().unwrap())?.unwrap();
- let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?;
+ let comment = CommentForm::from_apub(¬e, client, pool).await?;
let inserted_comment = blocking(pool, move |conn| Comment::create(conn, &comment)).await??;
get_user_from_activity,
receive_unhandled_activity,
},
- ActorType,
FromApub,
GroupExt,
PageExt,
let user = get_user_from_activity(&delete, client, pool).await?;
let page = PageExt::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap();
- let post_ap_id = PostForm::from_apub(&page, client, pool, &user.actor_id()?)
+ let post_ap_id = PostForm::from_apub(&page, client, pool)
.await?
.get_ap_id()?;
let user = get_user_from_activity(&delete, client, pool).await?;
let note = Note::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap();
- let comment_ap_id = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?)
+ let comment_ap_id = CommentForm::from_apub(¬e, client, pool)
.await?
.get_ap_id()?;
let group = GroupExt::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap();
let user = get_user_from_activity(&delete, client, pool).await?;
- let community_actor_id = CommunityForm::from_apub(&group, client, pool, &user.actor_id()?)
+ let community_actor_id = CommunityForm::from_apub(&group, client, pool)
.await?
.actor_id;
get_user_from_activity,
receive_unhandled_activity,
},
- ActorType,
FromApub,
PageExt,
},
let user = get_user_from_activity(&dislike, client, pool).await?;
let page = PageExt::from_any_base(dislike.object().to_owned().one().unwrap())?.unwrap();
- let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
+ let post = PostForm::from_apub(&page, client, pool).await?;
let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
.await?
let note = Note::from_any_base(dislike.object().to_owned().one().unwrap())?.unwrap();
let user = get_user_from_activity(&dislike, client, pool).await?;
- let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?;
+ let comment = CommentForm::from_apub(¬e, client, pool).await?;
let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
.await?
get_user_from_activity,
receive_unhandled_activity,
},
- ActorType,
FromApub,
PageExt,
},
let user = get_user_from_activity(&like, client, pool).await?;
let page = PageExt::from_any_base(like.object().to_owned().one().unwrap())?.unwrap();
- let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
+ let post = PostForm::from_apub(&page, client, pool).await?;
let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
.await?
let note = Note::from_any_base(like.object().to_owned().one().unwrap())?.unwrap();
let user = get_user_from_activity(&like, client, pool).await?;
- let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?;
+ let comment = CommentForm::from_apub(¬e, client, pool).await?;
let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
.await?
get_user_from_activity,
receive_unhandled_activity,
},
- ActorType,
FromApub,
GroupExt,
PageExt,
let mod_ = get_user_from_activity(&remove, client, pool).await?;
let page = PageExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
- let post_ap_id = PostForm::from_apub(&page, client, pool, &mod_.actor_id()?)
+ let post_ap_id = PostForm::from_apub(&page, client, pool)
.await?
.get_ap_id()?;
let mod_ = get_user_from_activity(&remove, client, pool).await?;
let note = Note::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
- let comment_ap_id = CommentForm::from_apub(¬e, client, pool, &mod_.actor_id()?)
+ let comment_ap_id = CommentForm::from_apub(¬e, client, pool)
.await?
.get_ap_id()?;
let mod_ = get_user_from_activity(&remove, client, pool).await?;
let group = GroupExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
- let community_actor_id = CommunityForm::from_apub(&group, client, pool, &mod_.actor_id()?)
+ let community_actor_id = CommunityForm::from_apub(&group, client, pool)
.await?
.actor_id;
get_user_from_activity,
receive_unhandled_activity,
},
- ActorType,
FromApub,
GroupExt,
PageExt,
let user = get_user_from_activity(delete, client, pool).await?;
let note = Note::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap();
- let comment_ap_id = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?)
+ let comment_ap_id = CommentForm::from_apub(¬e, client, pool)
.await?
.get_ap_id()?;
let mod_ = get_user_from_activity(remove, client, pool).await?;
let note = Note::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
- let comment_ap_id = CommentForm::from_apub(¬e, client, pool, &mod_.actor_id()?)
+ let comment_ap_id = CommentForm::from_apub(¬e, client, pool)
.await?
.get_ap_id()?;
let user = get_user_from_activity(delete, client, pool).await?;
let page = PageExt::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap();
- let post_ap_id = PostForm::from_apub(&page, client, pool, &user.actor_id()?)
+ let post_ap_id = PostForm::from_apub(&page, client, pool)
.await?
.get_ap_id()?;
let mod_ = get_user_from_activity(remove, client, pool).await?;
let page = PageExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
- let post_ap_id = PostForm::from_apub(&page, client, pool, &mod_.actor_id()?)
+ let post_ap_id = PostForm::from_apub(&page, client, pool)
.await?
.get_ap_id()?;
let user = get_user_from_activity(delete, client, pool).await?;
let group = GroupExt::from_any_base(delete.object().to_owned().one().unwrap())?.unwrap();
- let community_actor_id = CommunityForm::from_apub(&group, client, pool, &user.actor_id()?)
+ let community_actor_id = CommunityForm::from_apub(&group, client, pool)
.await?
.actor_id;
let mod_ = get_user_from_activity(remove, client, pool).await?;
let group = GroupExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
- let community_actor_id = CommunityForm::from_apub(&group, client, pool, &mod_.actor_id()?)
+ let community_actor_id = CommunityForm::from_apub(&group, client, pool)
.await?
.actor_id;
let user = get_user_from_activity(like, client, pool).await?;
let note = Note::from_any_base(like.object().to_owned().one().unwrap())?.unwrap();
- let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?;
+ let comment = CommentForm::from_apub(¬e, client, pool).await?;
let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
.await?
let user = get_user_from_activity(like, client, pool).await?;
let page = PageExt::from_any_base(like.object().to_owned().one().unwrap())?.unwrap();
- let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
+ let post = PostForm::from_apub(&page, client, pool).await?;
let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
.await?
get_user_from_activity,
receive_unhandled_activity,
},
- ActorType,
FromApub,
PageExt,
},
let user = get_user_from_activity(&update, client, pool).await?;
let page = PageExt::from_any_base(update.object().to_owned().one().unwrap())?.unwrap();
- let post = PostForm::from_apub(&page, client, pool, &user.actor_id()?).await?;
+ let post = PostForm::from_apub(&page, client, pool).await?;
let post_id = get_or_fetch_and_insert_post(&post.get_ap_id()?, client, pool)
.await?
let note = Note::from_any_base(update.object().to_owned().one().unwrap())?.unwrap();
let user = get_user_from_activity(&update, client, pool).await?;
- let comment = CommentForm::from_apub(¬e, client, pool, &user.actor_id()?).await?;
+ let comment = CommentForm::from_apub(¬e, client, pool).await?;
let comment_id = get_or_fetch_and_insert_comment(&comment.get_ap_id()?, client, pool)
.await?
insert_activity(user.id, create, false, pool).await?;
- let private_message = PrivateMessageForm::from_apub(¬e, client, pool, user_uri).await?;
+ let private_message = PrivateMessageForm::from_apub(¬e, client, pool).await?;
let inserted_private_message = blocking(pool, move |conn| {
PrivateMessage::create(conn, &private_message)
insert_activity(user.id, update, false, pool).await?;
- let private_message_form = PrivateMessageForm::from_apub(¬e, client, pool, user_uri).await?;
+ let private_message_form = PrivateMessageForm::from_apub(¬e, client, pool).await?;
let private_message_ap_id = private_message_form.ap_id.clone();
let private_message = blocking(pool, move |conn| {
insert_activity(user.id, delete, false, pool).await?;
- let private_message_form = PrivateMessageForm::from_apub(¬e, client, pool, user_uri).await?;
+ let private_message_form = PrivateMessageForm::from_apub(¬e, client, pool).await?;
let private_message_ap_id = private_message_form.ap_id;
let private_message = blocking(pool, move |conn| {
insert_activity(user.id, delete, false, pool).await?;
- let private_message = PrivateMessageForm::from_apub(¬e, client, pool, user_uri).await?;
+ let private_message = PrivateMessageForm::from_apub(¬e, client, pool).await?;
let private_message_ap_id = private_message.ap_id.clone();
let private_message_id = blocking(pool, move |conn| {
apub: &Self::ApubType,
client: &Client,
pool: &DbPool,
- actor_id: &Url,
) -> Result<Self, LemmyError>
where
Self: Sized;
page: &PageExt,
client: &Client,
pool: &DbPool,
- actor_id: &Url,
) -> Result<PostForm, LemmyError> {
let ext = &page.ext_one;
let creator_actor_id = page
embed_description,
embed_html,
thumbnail_url,
- ap_id: page
- .inner
- .id(actor_id.domain().unwrap())?
- .unwrap()
- .to_string(),
+ ap_id: page.inner.id_unchecked().unwrap().to_string(),
local: false,
})
}
note: &Note,
client: &Client,
pool: &DbPool,
- actor_id: &Url,
) -> Result<PrivateMessageForm, LemmyError> {
let creator_actor_id = note
.attributed_to()
updated: note.updated().map(|u| u.to_owned().naive_local()),
deleted: None,
read: None,
- ap_id: note.id(actor_id.domain().unwrap())?.unwrap().to_string(),
+ ap_id: note.id_unchecked().unwrap().to_string(),
local: false,
})
}
impl FromApub for UserForm {
type ApubType = PersonExt;
/// Parse an ActivityPub person received from another instance into a Lemmy user.
- async fn from_apub(
- person: &PersonExt,
- _: &Client,
- _: &DbPool,
- actor_id: &Url,
- ) -> Result<Self, LemmyError> {
+ async fn from_apub(person: &PersonExt, _: &Client, _: &DbPool) -> Result<Self, LemmyError> {
let avatar = match person.icon() {
Some(any_image) => Image::from_any_base(any_image.as_one().unwrap().clone())
.unwrap()
show_avatars: false,
send_notifications_to_email: false,
matrix_user_id: None,
- actor_id: person.id(actor_id.domain().unwrap())?.unwrap().to_string(),
+ actor_id: person.id_unchecked().unwrap().to_string(),
bio: person
.inner
.summary()