chore: richactivity no longer double optional
This commit is contained in:
parent
2bd7682c7e
commit
444ef5528f
2 changed files with 12 additions and 23 deletions
|
@ -40,10 +40,7 @@ impl BatchFillable for RichActivity {
|
||||||
E::Model: BatchFillableKey + Send + FromQueryResult + ModelTrait<Entity = E>,
|
E::Model: BatchFillableKey + Send + FromQueryResult + ModelTrait<Entity = E>,
|
||||||
RichObject: BatchFillableAcceptor<Vec<E::Model>>,
|
RichObject: BatchFillableAcceptor<Vec<E::Model>>,
|
||||||
{
|
{
|
||||||
if let Some(obj) = self.object {
|
self.object = self.object.with_batched::<E>(tx).await?;
|
||||||
self.object = Some(obj.with_batched::<E>(tx).await?);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,14 +87,14 @@ impl IntoActivityPub for RichObject {
|
||||||
|
|
||||||
pub struct RichActivity {
|
pub struct RichActivity {
|
||||||
pub activity: Option<crate::model::activity::Model>,
|
pub activity: Option<crate::model::activity::Model>,
|
||||||
pub object: Option<RichObject>,
|
pub object: RichObject,
|
||||||
pub discovered: chrono::DateTime<chrono::Utc>,
|
pub discovered: chrono::DateTime<chrono::Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromQueryResult for RichActivity {
|
impl FromQueryResult for RichActivity {
|
||||||
fn from_query_result(res: &QueryResult, _pre: &str) -> Result<Self, DbErr> {
|
fn from_query_result(res: &QueryResult, _pre: &str) -> Result<Self, DbErr> {
|
||||||
Ok(RichActivity {
|
Ok(RichActivity {
|
||||||
object: RichObject::from_query_result_optional(res, _pre)?,
|
object: RichObject::from_query_result(res, _pre)?,
|
||||||
activity: crate::model::activity::Model::from_query_result_optional(res, crate::model::activity::Entity.table_name())?,
|
activity: crate::model::activity::Model::from_query_result_optional(res, crate::model::activity::Entity.table_name())?,
|
||||||
discovered: res.try_get(
|
discovered: res.try_get(
|
||||||
crate::model::addressing::Entity.table_name(),
|
crate::model::addressing::Entity.table_name(),
|
||||||
|
@ -107,30 +107,22 @@ impl FromQueryResult for RichActivity {
|
||||||
impl IntoActivityPub for RichActivity {
|
impl IntoActivityPub for RichActivity {
|
||||||
fn into_activity_pub_json(self, ctx: &crate::Context) -> serde_json::Value {
|
fn into_activity_pub_json(self, ctx: &crate::Context) -> serde_json::Value {
|
||||||
use apb::ObjectMut;
|
use apb::ObjectMut;
|
||||||
match (self.activity, self.object) {
|
match (self.activity, &self.object.object) {
|
||||||
(None, None) => serde_json::Value::Null,
|
(None, None) => serde_json::Value::Null,
|
||||||
|
|
||||||
(Some(activity), None) => activity.into_activity_pub_json(ctx),
|
(Some(activity), None) => activity.into_activity_pub_json(ctx),
|
||||||
|
|
||||||
// TODO RichObject may be Some but actually be empty underneath, so this pretty match is
|
(None, Some(ref _object)) => {
|
||||||
// more or less useless since we need to match underlying object anyway. can we clear up
|
apb::new()
|
||||||
// this weirdness somehow? it's confusing too!
|
.set_activity_type(Some(apb::ActivityType::View))
|
||||||
|
.set_published(Some(self.discovered))
|
||||||
(None, Some(object)) => match object.object {
|
.set_object(apb::Node::object(self.object.into_activity_pub_json(ctx)))
|
||||||
Some(object) => {
|
|
||||||
apb::new()
|
|
||||||
.set_activity_type(Some(apb::ActivityType::View))
|
|
||||||
.set_published(Some(self.discovered))
|
|
||||||
.set_object(apb::Node::object(object.into_activity_pub_json(ctx)))
|
|
||||||
},
|
|
||||||
None => serde_json::Value::Null, // TODO we shouldn't really reach here?
|
|
||||||
},
|
},
|
||||||
|
|
||||||
(Some(activity), Some(object)) => match object.object {
|
(Some(activity), Some(ref _object)) => {
|
||||||
Some(object) => activity
|
activity
|
||||||
.into_activity_pub_json(ctx)
|
.into_activity_pub_json(ctx)
|
||||||
.set_object(apb::Node::object(object.into_activity_pub_json(ctx))),
|
.set_object(apb::Node::object(self.object.into_activity_pub_json(ctx)))
|
||||||
None => activity.into_activity_pub_json(ctx),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue