verify_activity(self, &context.settings())?;
verify_person_in_community(&self.actor, &community, context, request_counter).await?;
- verify_domains_match(self.actor.inner(), self.object.id_unchecked())?;
+ verify_domains_match(self.actor.inner(), self.object.id.inner())?;
check_community_deleted_or_removed(&community)?;
check_post_deleted_or_removed(&post)?;
match self.kind {
CreateOrUpdateType::Create => {
- verify_domains_match(self.actor.inner(), self.object.id_unchecked())?;
+ verify_domains_match(self.actor.inner(), self.object.id.inner())?;
verify_urls_match(self.actor(), self.object.attributed_to.inner())?;
// Check that the post isnt locked or stickied, as that isnt possible for newly created posts.
// However, when fetching a remote post we generate a new create activity with the current
if is_mod_action {
verify_mod_action(&self.actor, &community, context, request_counter).await?;
} else {
- verify_domains_match(self.actor.inner(), self.object.id_unchecked())?;
+ verify_domains_match(self.actor.inner(), self.object.id.inner())?;
verify_urls_match(self.actor(), self.object.attributed_to.inner())?;
}
}
) -> Result<(), LemmyError> {
verify_activity(self, &context.settings())?;
verify_person(&self.actor, context, request_counter).await?;
- verify_domains_match(self.actor.inner(), self.object.id_unchecked())?;
+ verify_domains_match(self.actor.inner(), self.object.id.inner())?;
self.object.verify(context, request_counter).await?;
Ok(())
}
},
PostOrComment,
};
+use lemmy_apub_lib::verify::verify_domains_match;
use lemmy_utils::utils::markdown_to_html;
#[derive(Clone, Debug)]
let note = Note {
r#type: NoteType::Note,
- id: self.ap_id.to_owned().into_inner(),
+ id: ObjectId::new(self.ap_id.to_owned()),
attributed_to: ObjectId::new(creator.actor_id),
to: vec![public()],
content: markdown_to_html(&self.content),
expected_domain: &Url,
request_counter: &mut i32,
) -> Result<ApubComment, LemmyError> {
- let ap_id = Some(note.id(expected_domain)?.clone().into());
+ 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)
Community::read(conn, community_id)
})
.await??;
- check_is_apub_id_valid(¬e.id, community.local, &context.settings())?;
+ check_is_apub_id_valid(note.id.inner(), community.local, &context.settings())?;
verify_person_in_community(
¬e.attributed_to,
&community.into(),
let group = Group {
kind: GroupType::Group,
- id: self.actor_id(),
+ id: ObjectId::new(self.actor_id()),
preferred_username: self.name.clone(),
name: self.title.clone(),
summary: self.description.as_ref().map(|b| markdown_to_html(b)),
use crate::{
check_is_apub_id_valid,
+ fetcher::object_id::ObjectId,
generate_outbox_url,
objects::get_summary_from_string_or_source,
protocol::{
let person = Person {
kind,
- id: self.actor_id.to_owned().into_inner(),
+ id: ObjectId::new(self.actor_id.clone()),
preferred_username: self.name.clone(),
name: self.display_name.clone(),
summary: self.bio.as_ref().map(|b| markdown_to_html(b)),
expected_domain: &Url,
_request_counter: &mut i32,
) -> Result<ApubPerson, LemmyError> {
- verify_domains_match(&person.id, expected_domain)?;
+ 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();
check_slurs_opt(&display_name, slur_regex)?;
check_slurs_opt(&bio, slur_regex)?;
- check_is_apub_id_valid(&person.id, false, &context.settings())?;
+ check_is_apub_id_valid(person.id.inner(), false, &context.settings())?;
let person_form = PersonForm {
name,
use lemmy_apub_lib::{
traits::ApubObject,
values::{MediaTypeHtml, MediaTypeMarkdown},
+ verify::verify_domains_match,
};
use lemmy_db_schema::{
self,
let page = Page {
r#type: PageType::Page,
- id: self.ap_id.clone().into(),
+ id: ObjectId::new(self.ap_id.clone()),
attributed_to: ObjectId::new(creator.actor_id),
to: vec![community.actor_id.into(), public()],
name: self.name.clone(),
) -> Result<ApubPost, LemmyError> {
// We can't verify the domain in case of mod action, because the mod may be on a different
// instance from the post author.
- let ap_id = if page.is_mod_action(context).await? {
- page.id_unchecked()
- } else {
- page.id(expected_domain)?
+ if !page.is_mod_action(context).await? {
+ verify_domains_match(page.id.inner(), expected_domain)?;
};
- let ap_id = Some(ap_id.clone().into());
+ let ap_id = Some(page.id.clone().into());
let creator = page
.attributed_to
.dereference(context, request_counter)
.await?;
let community = page.extract_community(context, request_counter).await?;
- check_is_apub_id_valid(&page.id, community.local, &context.settings())?;
+ 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);
use lemmy_apub_lib::{
traits::ApubObject,
values::{MediaTypeHtml, MediaTypeMarkdown},
+ verify::verify_domains_match,
};
use lemmy_db_schema::{
source::{
let note = ChatMessage {
r#type: ChatMessageType::ChatMessage,
- id: self.ap_id.clone().into(),
+ id: ObjectId::new(self.ap_id.clone()),
attributed_to: ObjectId::new(creator.actor_id),
to: [ObjectId::new(recipient.actor_id)],
content: markdown_to_html(&self.content),
expected_domain: &Url,
request_counter: &mut i32,
) -> Result<ApubPrivateMessage, LemmyError> {
- let ap_id = Some(note.id(expected_domain)?.clone().into());
+ 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)
-use crate::{fetcher::object_id::ObjectId, objects::person::ApubPerson, protocol::Source};
+use crate::{
+ fetcher::object_id::ObjectId,
+ objects::{person::ApubPerson, private_message::ApubPrivateMessage},
+ protocol::Source,
+};
use activitystreams::{
chrono::{DateTime, FixedOffset},
unparsed::Unparsed,
use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
-use url::Url;
#[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ChatMessage {
pub(crate) r#type: ChatMessageType,
- pub(crate) id: Url,
+ pub(crate) id: ObjectId<ApubPrivateMessage>,
pub(crate) attributed_to: ObjectId<ApubPerson>,
pub(crate) to: [ObjectId<ApubPerson>; 1],
pub(crate) content: String,
}
impl ChatMessage {
- pub(crate) fn id_unchecked(&self) -> &Url {
- &self.id
- }
- pub(crate) fn id(&self, expected_domain: &Url) -> Result<&Url, LemmyError> {
- verify_domains_match(&self.id, expected_domain)?;
- Ok(&self.id)
- }
-
pub(crate) async fn verify(
&self,
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- verify_domains_match(self.attributed_to.inner(), &self.id)?;
+ verify_domains_match(self.attributed_to.inner(), self.id.inner())?;
let person = self
.attributed_to
.dereference(context, request_counter)
community_outbox::ApubCommunityOutbox,
},
fetcher::object_id::ObjectId,
- objects::get_summary_from_string_or_source,
+ objects::{community::ApubCommunity, get_summary_from_string_or_source},
protocol::{ImageObject, Source},
};
use activitystreams::{
pub struct Group {
#[serde(rename = "type")]
pub(crate) kind: GroupType,
- pub(crate) id: Url,
+ pub(crate) id: ObjectId<ApubCommunity>,
/// username, set at account creation and can never be changed
pub(crate) preferred_username: String,
/// title (can be changed at any time)
expected_domain: &Url,
settings: &Settings,
) -> Result<CommunityForm, LemmyError> {
- check_is_apub_id_valid(&group.id, true, settings)?;
- verify_domains_match(expected_domain, &group.id)?;
+ 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);
use crate::{
activities::{verify_is_public, verify_person_in_community},
fetcher::{object_id::ObjectId, post_or_comment::PostOrComment},
- objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
+ objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
protocol::Source,
};
use activitystreams::{object::kind::NoteType, unparsed::Unparsed};
#[serde(rename_all = "camelCase")]
pub struct Note {
pub(crate) r#type: NoteType,
- pub(crate) id: Url,
+ pub(crate) id: ObjectId<ApubComment>,
pub(crate) attributed_to: ObjectId<ApubPerson>,
- /// Indicates that the object is publicly readable. Unlike [`Post.to`], this one doesn't contain
- /// the community ID, as it would be incompatible with Pleroma (and we can get the community from
- /// the post in [`in_reply_to`]).
pub(crate) to: Vec<Url>,
pub(crate) content: String,
pub(crate) media_type: Option<MediaTypeHtml>,
}
impl Note {
- pub(crate) fn id_unchecked(&self) -> &Url {
- &self.id
- }
- pub(crate) fn id(&self, expected_domain: &Url) -> Result<&Url, LemmyError> {
- verify_domains_match(&self.id, expected_domain)?;
- Ok(&self.id)
- }
-
pub(crate) async fn get_parents(
&self,
context: &LemmyContext,
if post.locked {
return Err(anyhow!("Post is locked").into());
}
- verify_domains_match(self.attributed_to.inner(), &self.id)?;
+ verify_domains_match(self.attributed_to.inner(), self.id.inner())?;
verify_person_in_community(&self.attributed_to, &community, context, request_counter).await?;
verify_is_public(&self.to)?;
Ok(())
#[serde(rename_all = "camelCase")]
pub struct Page {
pub(crate) r#type: PageType,
- pub(crate) id: Url,
+ pub(crate) id: ObjectId<ApubPost>,
pub(crate) attributed_to: ObjectId<ApubPerson>,
pub(crate) to: Vec<Url>,
pub(crate) name: String,
}
impl Page {
- pub(crate) fn id_unchecked(&self) -> &Url {
- &self.id
- }
- pub(crate) fn id(&self, expected_domain: &Url) -> Result<&Url, LemmyError> {
- verify_domains_match(&self.id, expected_domain)?;
- Ok(&self.id)
- }
-
/// Only mods can change the post's stickied/locked status. So if either of these is changed from
/// the current value, it is a mod action and needs to be verified as such.
///
let community = self.extract_community(context, request_counter).await?;
check_slurs(&self.name, &context.settings().slur_regex())?;
- verify_domains_match(self.attributed_to.inner(), &self.id.clone())?;
+ verify_domains_match(self.attributed_to.inner(), self.id.inner())?;
verify_person_in_community(&self.attributed_to, &community, context, request_counter).await?;
verify_is_public(&self.to.clone())?;
Ok(())
-use crate::protocol::{ImageObject, Source};
+use crate::{
+ fetcher::object_id::ObjectId,
+ objects::person::ApubPerson,
+ protocol::{ImageObject, Source},
+};
use activitystreams::{actor::Endpoints, unparsed::Unparsed, url::Url};
use chrono::{DateTime, FixedOffset};
use lemmy_apub_lib::signatures::PublicKey;
pub struct Person {
#[serde(rename = "type")]
pub(crate) kind: UserTypes,
- pub(crate) id: Url,
+ pub(crate) id: ObjectId<ApubPerson>,
/// username, set at account creation and can never be changed
pub(crate) preferred_username: String,
/// displayname (can be changed at any time)