mirror of https://github.com/LemmyNet/lemmy.git
simplify ObjectId::new (and fix clippy)
parent
24fc616774
commit
a5f45a169e
|
@ -61,7 +61,7 @@ impl CreateOrUpdateComment {
|
|||
let maa = collect_non_local_mentions(comment, &community, context).await?;
|
||||
|
||||
let create_or_update = CreateOrUpdateComment {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: [PublicUrl::Public],
|
||||
object: comment.to_apub(context.pool()).await?,
|
||||
cc: maa.ccs,
|
||||
|
@ -85,7 +85,7 @@ impl ActivityHandler for CreateOrUpdateComment {
|
|||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
let community = extract_community(&self.cc, context, request_counter).await?;
|
||||
let community_id = ObjectId::<Community>::new(community.actor_id());
|
||||
let community_id = ObjectId::new(community.actor_id());
|
||||
|
||||
verify_activity(self)?;
|
||||
verify_person_in_community(&self.actor, &community_id, context, request_counter).await?;
|
||||
|
|
|
@ -76,7 +76,7 @@ pub async fn collect_non_local_mentions(
|
|||
for mention in &mentions {
|
||||
// TODO should it be fetching it every time?
|
||||
if let Ok(actor_id) = fetch_webfinger_url(mention, context.client()).await {
|
||||
let actor_id: ObjectId<Person> = ObjectId::<Person>::new(actor_id);
|
||||
let actor_id: ObjectId<Person> = ObjectId::new(actor_id);
|
||||
debug!("mention actor_id: {}", actor_id);
|
||||
addressed_ccs.push(actor_id.to_owned().to_string().parse()?);
|
||||
|
||||
|
|
|
@ -57,11 +57,11 @@ impl AddMod {
|
|||
) -> Result<(), LemmyError> {
|
||||
let id = generate_activity_id(AddType::Add)?;
|
||||
let add = AddMod {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: [PublicUrl::Public],
|
||||
object: ObjectId::<Person>::new(added_mod.actor_id()),
|
||||
object: ObjectId::new(added_mod.actor_id()),
|
||||
target: generate_moderators_url(&community.actor_id)?.into(),
|
||||
cc: [ObjectId::<Community>::new(community.actor_id())],
|
||||
cc: [ObjectId::new(community.actor_id())],
|
||||
kind: AddType::Add,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
|
|
|
@ -79,7 +79,7 @@ impl AnnounceActivity {
|
|||
context: &LemmyContext,
|
||||
) -> Result<(), LemmyError> {
|
||||
let announce = AnnounceActivity {
|
||||
actor: ObjectId::<Community>::new(community.actor_id()),
|
||||
actor: ObjectId::new(community.actor_id()),
|
||||
to: [PublicUrl::Public],
|
||||
object,
|
||||
cc: vec![community.followers_url()],
|
||||
|
|
|
@ -58,10 +58,10 @@ impl BlockUserFromCommunity {
|
|||
actor: &Person,
|
||||
) -> Result<BlockUserFromCommunity, LemmyError> {
|
||||
Ok(BlockUserFromCommunity {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: [PublicUrl::Public],
|
||||
object: ObjectId::<Person>::new(target.actor_id()),
|
||||
cc: [ObjectId::<Community>::new(community.actor_id())],
|
||||
object: ObjectId::new(target.actor_id()),
|
||||
cc: [ObjectId::new(community.actor_id())],
|
||||
kind: BlockType::Block,
|
||||
id: generate_activity_id(BlockType::Block)?,
|
||||
context: lemmy_context(),
|
||||
|
|
|
@ -59,13 +59,13 @@ impl RemoveMod {
|
|||
) -> Result<(), LemmyError> {
|
||||
let id = generate_activity_id(RemoveType::Remove)?;
|
||||
let remove = RemoveMod {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: [PublicUrl::Public],
|
||||
object: ObjectId::<Person>::new(removed_mod.actor_id()),
|
||||
object: ObjectId::new(removed_mod.actor_id()),
|
||||
target: Some(generate_moderators_url(&community.actor_id)?.into()),
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
cc: [ObjectId::<Community>::new(community.actor_id())],
|
||||
cc: [ObjectId::new(community.actor_id())],
|
||||
kind: RemoveType::Remove,
|
||||
unparsed: Default::default(),
|
||||
};
|
||||
|
|
|
@ -56,10 +56,10 @@ impl UndoBlockUserFromCommunity {
|
|||
|
||||
let id = generate_activity_id(UndoType::Undo)?;
|
||||
let undo = UndoBlockUserFromCommunity {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: [PublicUrl::Public],
|
||||
object: block,
|
||||
cc: [ObjectId::<Community>::new(community.actor_id())],
|
||||
cc: [ObjectId::new(community.actor_id())],
|
||||
kind: UndoType::Undo,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
|
|
|
@ -57,10 +57,10 @@ impl UpdateCommunity {
|
|||
) -> Result<(), LemmyError> {
|
||||
let id = generate_activity_id(UpdateType::Update)?;
|
||||
let update = UpdateCommunity {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: [PublicUrl::Public],
|
||||
object: community.to_apub(context.pool()).await?,
|
||||
cc: [ObjectId::<Community>::new(community.actor_id())],
|
||||
cc: [ObjectId::new(community.actor_id())],
|
||||
kind: UpdateType::Update,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
|
|
|
@ -140,10 +140,10 @@ impl Delete {
|
|||
summary: Option<String>,
|
||||
) -> Result<Delete, LemmyError> {
|
||||
Ok(Delete {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: [PublicUrl::Public],
|
||||
object: object_id,
|
||||
cc: [ObjectId::<Community>::new(community.actor_id())],
|
||||
cc: [ObjectId::new(community.actor_id())],
|
||||
kind: DeleteType::Delete,
|
||||
summary,
|
||||
id: generate_activity_id(DeleteType::Delete)?,
|
||||
|
|
|
@ -105,7 +105,7 @@ pub(in crate::activities) async fn verify_delete_activity(
|
|||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
let object = DeletableObjects::read_from_db(object, context).await?;
|
||||
let actor = ObjectId::<Person>::new(activity.actor().clone());
|
||||
let actor = ObjectId::new(activity.actor().clone());
|
||||
match object {
|
||||
DeletableObjects::Community(c) => {
|
||||
if c.local {
|
||||
|
@ -114,7 +114,7 @@ pub(in crate::activities) async fn verify_delete_activity(
|
|||
verify_person_in_community(&actor, community_id, context, request_counter).await?;
|
||||
}
|
||||
// community deletion is always a mod (or admin) action
|
||||
verify_mod_action(&actor, ObjectId::<Community>::new(c.actor_id()), context).await?;
|
||||
verify_mod_action(&actor, ObjectId::new(c.actor_id()), context).await?;
|
||||
}
|
||||
DeletableObjects::Post(p) => {
|
||||
verify_delete_activity_post_or_comment(
|
||||
|
@ -150,7 +150,7 @@ async fn verify_delete_activity_post_or_comment(
|
|||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError> {
|
||||
let actor = ObjectId::<Person>::new(activity.actor().clone());
|
||||
let actor = ObjectId::new(activity.actor().clone());
|
||||
verify_person_in_community(&actor, community_id, context, request_counter).await?;
|
||||
if is_mod_action {
|
||||
verify_mod_action(&actor, community_id.clone(), context).await?;
|
||||
|
|
|
@ -110,10 +110,10 @@ impl UndoDelete {
|
|||
|
||||
let id = generate_activity_id(UndoType::Undo)?;
|
||||
let undo = UndoDelete {
|
||||
actor: ObjectId::<Community>::new(actor.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: [PublicUrl::Public],
|
||||
object,
|
||||
cc: [ObjectId::<Community>::new(community.actor_id())],
|
||||
cc: [ObjectId::new(community.actor_id())],
|
||||
kind: UndoType::Undo,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
|
|
|
@ -57,8 +57,8 @@ impl AcceptFollowCommunity {
|
|||
.await??;
|
||||
|
||||
let accept = AcceptFollowCommunity {
|
||||
actor: ObjectId::<Community>::new(community.actor_id()),
|
||||
to: ObjectId::<Person>::new(person.actor_id()),
|
||||
actor: ObjectId::new(community.actor_id()),
|
||||
to: ObjectId::new(person.actor_id()),
|
||||
object: follow,
|
||||
kind: AcceptType::Accept,
|
||||
id: generate_activity_id(AcceptType::Accept)?,
|
||||
|
|
|
@ -50,9 +50,9 @@ impl FollowCommunity {
|
|||
community: &Community,
|
||||
) -> Result<FollowCommunity, LemmyError> {
|
||||
Ok(FollowCommunity {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
to: ObjectId::<Community>::new(community.actor_id()),
|
||||
object: ObjectId::<Community>::new(community.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: ObjectId::new(community.actor_id()),
|
||||
object: ObjectId::new(community.actor_id()),
|
||||
kind: FollowType::Follow,
|
||||
id: generate_activity_id(FollowType::Follow)?,
|
||||
context: lemmy_context(),
|
||||
|
|
|
@ -51,8 +51,8 @@ impl UndoFollowCommunity {
|
|||
) -> Result<(), LemmyError> {
|
||||
let object = FollowCommunity::new(actor, community)?;
|
||||
let undo = UndoFollowCommunity {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
to: ObjectId::<Community>::new(community.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: ObjectId::new(community.actor_id()),
|
||||
object,
|
||||
kind: UndoType::Undo,
|
||||
id: generate_activity_id(UndoType::Undo)?,
|
||||
|
|
|
@ -58,7 +58,7 @@ pub(crate) async fn extract_community(
|
|||
let mut cc_iter = cc.iter();
|
||||
loop {
|
||||
if let Some(cid) = cc_iter.next() {
|
||||
let cid = ObjectId::<Community>::new(cid.clone());
|
||||
let cid = ObjectId::new(cid.clone());
|
||||
if let Ok(c) = cid.dereference(context, request_counter).await {
|
||||
break Ok(c);
|
||||
}
|
||||
|
|
|
@ -61,10 +61,10 @@ impl CreateOrUpdatePost {
|
|||
|
||||
let id = generate_activity_id(kind.clone())?;
|
||||
let create_or_update = CreateOrUpdatePost {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: [PublicUrl::Public],
|
||||
object: post.to_apub(context.pool()).await?,
|
||||
cc: [ObjectId::<Community>::new(community.actor_id())],
|
||||
cc: [ObjectId::new(community.actor_id())],
|
||||
kind,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
|
|
|
@ -46,8 +46,8 @@ impl CreateOrUpdatePrivateMessage {
|
|||
let create_or_update = CreateOrUpdatePrivateMessage {
|
||||
context: lemmy_context(),
|
||||
id: id.clone(),
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
to: ObjectId::<Person>::new(recipient.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: ObjectId::new(recipient.actor_id()),
|
||||
object: private_message.to_apub(context.pool()).await?,
|
||||
kind,
|
||||
unparsed: Default::default(),
|
||||
|
|
|
@ -41,8 +41,8 @@ impl DeletePrivateMessage {
|
|||
pm: &PrivateMessage,
|
||||
) -> Result<DeletePrivateMessage, LemmyError> {
|
||||
Ok(DeletePrivateMessage {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
to: ObjectId::<Person>::new(actor.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: ObjectId::new(actor.actor_id()),
|
||||
object: pm.ap_id.clone().into(),
|
||||
kind: DeleteType::Delete,
|
||||
id: generate_activity_id(DeleteType::Delete)?,
|
||||
|
|
|
@ -53,8 +53,8 @@ impl UndoDeletePrivateMessage {
|
|||
let object = DeletePrivateMessage::new(actor, pm)?;
|
||||
let id = generate_activity_id(UndoType::Undo)?;
|
||||
let undo = UndoDeletePrivateMessage {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
to: ObjectId::<Person>::new(recipient.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: ObjectId::new(recipient.actor_id()),
|
||||
object,
|
||||
kind: UndoType::Undo,
|
||||
id: id.clone(),
|
||||
|
|
|
@ -67,10 +67,10 @@ impl UndoVote {
|
|||
let object = Vote::new(object, actor, &community, kind.clone())?;
|
||||
let id = generate_activity_id(UndoType::Undo)?;
|
||||
let undo_vote = UndoVote {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: [PublicUrl::Public],
|
||||
object,
|
||||
cc: [ObjectId::<Community>::new(community.actor_id())],
|
||||
cc: [ObjectId::new(community.actor_id())],
|
||||
kind: UndoType::Undo,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
|
|
|
@ -79,10 +79,10 @@ impl Vote {
|
|||
kind: VoteType,
|
||||
) -> Result<Vote, LemmyError> {
|
||||
Ok(Vote {
|
||||
actor: ObjectId::<Person>::new(actor.actor_id()),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: [PublicUrl::Public],
|
||||
object: ObjectId::<PostOrComment>::new(object.ap_id()),
|
||||
cc: [ObjectId::<Community>::new(community.actor_id())],
|
||||
object: ObjectId::new(object.ap_id()),
|
||||
cc: [ObjectId::new(community.actor_id())],
|
||||
kind: kind.clone(),
|
||||
id: generate_activity_id(kind)?,
|
||||
context: lemmy_context(),
|
||||
|
|
|
@ -45,8 +45,8 @@ pub(crate) async fn update_community_mods(
|
|||
|
||||
// Add new mods to database which have been added to moderators collection
|
||||
for mod_id in new_moderators {
|
||||
let mod_id = ObjectId::<Person>::new::<Person, Url>(mod_id);
|
||||
let mod_user = mod_id.dereference(context, request_counter).await?;
|
||||
let mod_id = ObjectId::new(mod_id);
|
||||
let mod_user: Person = mod_id.dereference(context, request_counter).await?;
|
||||
|
||||
if !current_moderators
|
||||
.clone()
|
||||
|
|
|
@ -28,12 +28,12 @@ pub(crate) async fn get_or_fetch_and_upsert_actor(
|
|||
context: &LemmyContext,
|
||||
recursion_counter: &mut i32,
|
||||
) -> Result<Box<dyn ActorType>, LemmyError> {
|
||||
let community_id: ObjectId<Community> = ObjectId::<Community>::new(apub_id.clone());
|
||||
let community_id = ObjectId::<Community>::new(apub_id.clone());
|
||||
let community = community_id.dereference(context, recursion_counter).await;
|
||||
let actor: Box<dyn ActorType> = match community {
|
||||
Ok(c) => Box::new(c),
|
||||
Err(_) => {
|
||||
let person_id: ObjectId<Person> = ObjectId::<Person>::new(apub_id);
|
||||
let person_id = ObjectId::new(apub_id);
|
||||
let person: Person = person_id.dereference(context, recursion_counter).await?;
|
||||
Box::new(person)
|
||||
}
|
||||
|
|
|
@ -34,13 +34,11 @@ where
|
|||
Kind: FromApub + ApubObject + DeletableApubObject + Send + 'static,
|
||||
for<'de> <Kind as FromApub>::ApubType: serde::Deserialize<'de>,
|
||||
{
|
||||
pub fn new<K, T>(url: T) -> ObjectId<K>
|
||||
pub fn new<T>(url: T) -> Self
|
||||
where
|
||||
T: Into<Url>,
|
||||
K: FromApub + ApubObject + DeletableApubObject + Send + 'static,
|
||||
for<'de> <K as FromApub>::ApubType: serde::Deserialize<'de>,
|
||||
{
|
||||
ObjectId(url.into(), PhantomData::<K>)
|
||||
ObjectId(url.into(), PhantomData::<Kind>)
|
||||
}
|
||||
|
||||
pub fn inner(&self) -> &Url {
|
||||
|
|
|
@ -55,7 +55,7 @@ pub async fn search_by_apub_id(
|
|||
};
|
||||
|
||||
let request_counter = &mut 0;
|
||||
ObjectId::<SearchableObjects>::new(query_url)
|
||||
ObjectId::new(query_url)
|
||||
.dereference(context, request_counter)
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -82,14 +82,14 @@ impl Note {
|
|||
CommentInReplyToMigration::Old(in_reply_to) => {
|
||||
// This post, or the parent comment might not yet exist on this server yet, fetch them.
|
||||
let post_id = in_reply_to.get(0).context(location_info!())?;
|
||||
let post_id = ObjectId::<Post>::new(post_id.clone());
|
||||
let post_id = ObjectId::new(post_id.clone());
|
||||
let post = Box::pin(post_id.dereference(context, request_counter)).await?;
|
||||
|
||||
// The 2nd item, if it exists, is the parent comment apub_id
|
||||
// Nested comments will automatically get fetched recursively
|
||||
let parent_id: Option<CommentId> = match in_reply_to.get(1) {
|
||||
Some(comment_id) => {
|
||||
let comment_id: ObjectId<Comment> = ObjectId::<Comment>::new(comment_id.clone());
|
||||
let comment_id = ObjectId::<Comment>::new(comment_id.clone());
|
||||
let parent_comment = Box::pin(comment_id.dereference(context, request_counter)).await?;
|
||||
|
||||
Some(parent_comment.id)
|
||||
|
@ -137,7 +137,7 @@ impl Note {
|
|||
verify_domains_match(self.attributed_to.inner(), &self.id)?;
|
||||
verify_person_in_community(
|
||||
&self.attributed_to,
|
||||
&ObjectId::<Community>::new(community.actor_id()),
|
||||
&ObjectId::new(community.actor_id()),
|
||||
context,
|
||||
request_counter,
|
||||
)
|
||||
|
@ -171,7 +171,7 @@ impl ToApub for Comment {
|
|||
context: lemmy_context(),
|
||||
r#type: NoteType::Note,
|
||||
id: self.ap_id.to_owned().into_inner(),
|
||||
attributed_to: ObjectId::<Person>::new(creator.actor_id),
|
||||
attributed_to: ObjectId::new(creator.actor_id),
|
||||
to: PublicUrl::Public,
|
||||
content: self.content.clone(),
|
||||
media_type: MediaTypeHtml::Html,
|
||||
|
|
|
@ -104,7 +104,7 @@ impl Page {
|
|||
verify_domains_match(self.attributed_to.inner(), &self.id)?;
|
||||
verify_person_in_community(
|
||||
&self.attributed_to,
|
||||
&ObjectId::<Community>::new(community.actor_id()),
|
||||
&ObjectId::new(community.actor_id()),
|
||||
context,
|
||||
request_counter,
|
||||
)
|
||||
|
@ -137,7 +137,7 @@ impl ToApub for Post {
|
|||
context: lemmy_context(),
|
||||
r#type: PageType::Page,
|
||||
id: self.ap_id.clone().into(),
|
||||
attributed_to: ObjectId::<Person>::new(creator.actor_id),
|
||||
attributed_to: ObjectId::new(creator.actor_id),
|
||||
to: [community.actor_id.into(), public()],
|
||||
name: self.name.clone(),
|
||||
content: self.body.as_ref().map(|b| markdown_to_html(b)),
|
||||
|
|
|
@ -87,8 +87,8 @@ impl ToApub for PrivateMessage {
|
|||
context: lemmy_context(),
|
||||
r#type: NoteType::Note,
|
||||
id: self.ap_id.clone().into(),
|
||||
attributed_to: ObjectId::<Person>::new(creator.actor_id),
|
||||
to: ObjectId::<Person>::new(recipient.actor_id),
|
||||
attributed_to: ObjectId::new(creator.actor_id),
|
||||
to: ObjectId::new(recipient.actor_id),
|
||||
content: self.content.clone(),
|
||||
media_type: MediaTypeHtml::Html,
|
||||
source: Source {
|
||||
|
|
Loading…
Reference in New Issue