From 881654fed924090609f062ad5c810dce7af983fd Mon Sep 17 00:00:00 2001 From: asonix Date: Mon, 14 Nov 2022 19:18:09 -0600 Subject: [PATCH] Try to be a bit more clear about what object is being delivered --- src/jobs/deliver.rs | 7 +++++-- src/jobs/deliver_many.rs | 4 ++-- src/jobs/mod.rs | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/jobs/deliver.rs b/src/jobs/deliver.rs index f53d412..15ce3cf 100644 --- a/src/jobs/deliver.rs +++ b/src/jobs/deliver.rs @@ -1,4 +1,7 @@ -use crate::{error::Error, jobs::JobState}; +use crate::{ + error::Error, + jobs::{debug_object, JobState}, +}; use activitystreams::iri_string::types::IriString; use background_jobs::{ActixJob, Backoff}; use std::{future::Future, pin::Pin}; @@ -14,7 +17,7 @@ impl std::fmt::Debug for Deliver { f.debug_struct("Deliver") .field("to", &self.to.to_string()) .field("activity", &self.data["type"]) - .field("object", &self.data["object"]["type"]) + .field("object", debug_object(&self.data)) .finish() } } diff --git a/src/jobs/deliver_many.rs b/src/jobs/deliver_many.rs index cbadf80..58cdc1f 100644 --- a/src/jobs/deliver_many.rs +++ b/src/jobs/deliver_many.rs @@ -1,6 +1,6 @@ use crate::{ error::Error, - jobs::{Deliver, JobState}, + jobs::{debug_object, Deliver, JobState}, }; use activitystreams::iri_string::types::IriString; use background_jobs::ActixJob; @@ -16,7 +16,7 @@ impl std::fmt::Debug for DeliverMany { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("DeliverMany") .field("activity", &self.data["type"]) - .field("object", &self.data["object"]["type"]) + .field("object", debug_object(&self.data)) .finish() } } diff --git a/src/jobs/mod.rs b/src/jobs/mod.rs index 5346046..900d253 100644 --- a/src/jobs/mod.rs +++ b/src/jobs/mod.rs @@ -25,6 +25,20 @@ use background_jobs::{ }; use std::time::Duration; +fn debug_object(activity: &serde_json::Value) -> &serde_json::Value { + let mut object = &activity["object"]["type"]; + + if object.is_null() { + object = &activity["object"]["id"]; + } + + if object.is_null() { + object = &activity["object"]; + } + + object +} + pub(crate) fn create_workers( state: State, actors: ActorCache,