- async fn from_apub(
- page: Page,
- context: &LemmyContext,
- request_counter: &mut i32,
- ) -> Result<ApubPost, LemmyError> {
- let creator = page
- .creator()?
- .dereference(context, local_instance(context), request_counter)
- .await?;
- let community = page.extract_community(context, request_counter).await?;
+ async fn from_json(page: Page, context: &Data<Self::DataType>) -> Result<ApubPost, LemmyError> {
+ let creator = page.creator()?.dereference(context).await?;
+ let community = page.community(context).await?;
+ if community.posting_restricted_to_mods {
+ is_mod_or_admin(&mut context.pool(), creator.id, community.id).await?;
+ }
+ let mut name = page
+ .name
+ .clone()
+ .or_else(|| {
+ page
+ .content
+ .clone()
+ .as_ref()
+ .and_then(|c| parse_html(c).lines().next().map(ToString::to_string))
+ })
+ .ok_or_else(|| anyhow!("Object must have name or content"))?;
+ if name.chars().count() > MAX_TITLE_LENGTH {
+ name = name.chars().take(MAX_TITLE_LENGTH).collect();
+ }
+
+ // read existing, local post if any (for generating mod log)
+ let old_post = page.id.dereference_local(context).await;