-async fn verify_mod_action(
- actor_id: &Url,
- activity_cc: Url,
- context: &LemmyContext,
-) -> Result<(), LemmyError> {
- let community = blocking(context.pool(), move |conn| {
- Community::read_from_apub_id(conn, &activity_cc.into())
- })
- .await??;
-
- if community.local {
- let actor_id: DbUrl = actor_id.clone().into();
- let actor = blocking(context.pool(), move |conn| {
- Person::read_from_apub_id(conn, &actor_id)
- })
- .await??;
-
- // Note: this will also return true for admins in addition to mods, but as we dont know about
- // remote admins, it doesnt make any difference.
- let community_id = community.id;
- let actor_id = actor.id;
- let is_mod_or_admin = blocking(context.pool(), move |conn| {
- CommunityView::is_mod_or_admin(conn, actor_id, community_id)
+pub(crate) fn check_community_deleted_or_removed(community: &Community) -> Result<(), LemmyError> {
+ if community.deleted || community.removed {
+ Err(LemmyErrorType::CannotCreatePostOrCommentInDeletedOrRemovedCommunity)?
+ } else {
+ Ok(())
+ }
+}
+
+/// Generate a unique ID for an activity, in the format:
+/// `http(s)://example.com/receive/create/202daf0a-1489-45df-8d2e-c8a3173fed36`
+fn generate_activity_id<T>(kind: T, protocol_and_hostname: &str) -> Result<Url, ParseError>
+where
+ T: ToString,
+{
+ let id = format!(
+ "{}/activities/{}/{}",
+ protocol_and_hostname,
+ kind.to_string().to_lowercase(),
+ Uuid::new_v4()
+ );
+ Url::parse(&id)
+}
+
+#[tracing::instrument(skip_all)]
+async fn send_lemmy_activity<Activity, ActorT>(
+ data: &Data<LemmyContext>,
+ activity: Activity,
+ actor: &ActorT,
+ mut inbox: Vec<Url>,
+ sensitive: bool,
+) -> Result<(), LemmyError>
+where
+ Activity: ActivityHandler + Serialize + Send + Sync + Clone,
+ ActorT: Actor,
+ Activity: ActivityHandler<Error = LemmyError>,
+{
+ static CACHE: Lazy<Cache<(), Arc<Vec<String>>>> = Lazy::new(|| {
+ Cache::builder()
+ .max_capacity(1)
+ .time_to_live(DEAD_INSTANCE_LIST_CACHE_DURATION)
+ .build()
+ });
+ let dead_instances = CACHE
+ .try_get_with((), async {
+ Ok::<_, diesel::result::Error>(Arc::new(Instance::dead_instances(&mut data.pool()).await?))