+impl ImageObject {
+ pub(crate) fn new(url: DbUrl) -> Self {
+ ImageObject {
+ kind: ImageType::Image,
+ url: url.into(),
+ }
+ }
+}
+
+#[derive(Clone, Debug, Default, Deserialize, Serialize)]
+#[serde(transparent)]
+pub struct Unparsed(HashMap<String, serde_json::Value>);
+
+pub(crate) trait Id {
+ fn object_id(&self) -> &Url;
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(untagged)]
+pub(crate) enum IdOrNestedObject<Kind: Id> {
+ Id(Url),
+ NestedObject(Kind),
+}
+
+impl<Kind: Id + DeserializeOwned + Send> IdOrNestedObject<Kind> {
+ pub(crate) fn id(&self) -> &Url {
+ match self {
+ IdOrNestedObject::Id(i) => i,
+ IdOrNestedObject::NestedObject(n) => n.object_id(),
+ }
+ }
+ pub(crate) async fn object(self, context: &Data<LemmyContext>) -> Result<Kind, LemmyError> {
+ match self {
+ // TODO: move IdOrNestedObject struct to library and make fetch_object_http private
+ IdOrNestedObject::Id(i) => Ok(fetch_object_http(&i, context).await?),
+ IdOrNestedObject::NestedObject(o) => Ok(o),
+ }
+ }
+}
+
+#[async_trait::async_trait]
+pub trait InCommunity {
+ // TODO: after we use audience field and remove backwards compat, it should be possible to change
+ // this to simply `fn community(&self) -> Result<ObjectId<ApubCommunity>, LemmyError>`
+ async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError>;
+}
+