use lemmy_db_schema::{
source::{
comment::{Comment, CommentForm},
+ community::Community,
person::Person,
post::Post,
},
let post_id = self.post_id;
let post = blocking(pool, move |conn| Post::read(conn, post_id)).await??;
+ let community_id = post.community_id;
+ let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
+
// Add a vector containing some important info to the "in_reply_to" field
// [post_ap_id, Option(parent_comment_ap_id)]
let mut in_reply_to_vec = vec![post.ap_id.into_inner()];
.set_many_contexts(lemmy_context()?)
.set_id(self.ap_id.to_owned().into_inner())
.set_published(convert_datetime(self.published))
- .set_to(public())
+ // NOTE: included community id for compatibility with lemmy v0.9.9
+ .set_many_tos(vec![community.actor_id.into_inner(), public()])
.set_many_in_reply_tos(in_reply_to_vec)
.set_attributed_to(creator.actor_id.into_inner());
};
use activitystreams_ext::Ext2;
use anyhow::Context;
+use lemmy_api_structs::blocking;
use lemmy_db_queries::DbPool;
use lemmy_db_schema::{
naive_now,
source::community::{Community, CommunityForm},
};
+use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
use lemmy_utils::{
location_info,
utils::{check_slurs, check_slurs_opt, convert_datetime},
impl ToApub for Community {
type ApubType = GroupExt;
- async fn to_apub(&self, _pool: &DbPool) -> Result<GroupExt, LemmyError> {
+ async fn to_apub(&self, pool: &DbPool) -> Result<GroupExt, LemmyError> {
+ let id = self.id;
+ let moderators = blocking(pool, move |conn| {
+ CommunityModeratorView::for_community(&conn, id)
+ })
+ .await??;
+ let moderators: Vec<Url> = moderators
+ .into_iter()
+ .map(|m| m.moderator.actor_id.into_inner())
+ .collect();
+
let mut group = ApObject::new(Group::new());
group
.set_many_contexts(lemmy_context()?)
.set_id(self.actor_id.to_owned().into())
.set_name(self.title.to_owned())
- .set_published(convert_datetime(self.published));
+ .set_published(convert_datetime(self.published))
+ // NOTE: included attritubed_to field for compatibility with lemmy v0.9.9
+ .set_many_attributed_tos(moderators);
if let Some(u) = self.updated.to_owned() {
group.set_updated(convert_datetime(u));
_mod_action_allowed: bool,
) -> Result<Self, LemmyError> {
let moderator_uris = fetch_community_mods(context, group, request_counter).await?;
- let creator_uri = moderator_uris.first().context(location_info!())?;
+ let creator = if let Some(creator_uri) = moderator_uris.first() {
+ get_or_fetch_and_upsert_person(creator_uri, context, request_counter)
+ } else {
+ // NOTE: code for compatibility with lemmy v0.9.9
+ let creator_uri = group
+ .inner
+ .attributed_to()
+ .map(|a| a.as_many())
+ .flatten()
+ .map(|a| a.first())
+ .flatten()
+ .map(|a| a.as_xsd_any_uri())
+ .flatten()
+ .context(location_info!())?;
+ get_or_fetch_and_upsert_person(creator_uri, context, request_counter)
+ }
+ .await?;
- let creator = get_or_fetch_and_upsert_person(creator_uri, context, request_counter).await?;
let name = group
.inner
.preferred_username()