Skip to content

Commit

Permalink
add placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Jun 26, 2023
1 parent 9fa0937 commit 30fef84
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
13 changes: 8 additions & 5 deletions crates/db_schema/src/source/community.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::newtypes::{CommunityId, DbUrl, InstanceId, PersonId};
#[cfg(feature = "full")]
use crate::schema::{community, community_follower, community_moderator, community_person_ban};
use crate::{
newtypes::{CommunityId, DbUrl, InstanceId, PersonId},
source::placeholder_apub_url,
};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
Expand Down Expand Up @@ -42,10 +45,10 @@ pub struct Community {
pub icon: Option<DbUrl>,
/// A URL for a banner.
pub banner: Option<DbUrl>,
#[serde(skip)]
pub followers_url: Option<DbUrl>,
#[serde(skip)]
pub inbox_url: Option<DbUrl>,
#[serde(skip, default = "placeholder_apub_url")]
pub followers_url: DbUrl,
#[serde(skip, default = "placeholder_apub_url")]
pub inbox_url: DbUrl,
#[serde(skip)]
pub shared_inbox_url: Option<DbUrl>,
/// Whether the community is hidden.
Expand Down
11 changes: 11 additions & 0 deletions crates/db_schema/src/source/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use crate::newtypes::DbUrl;
use url::Url;

#[cfg(feature = "full")]
pub mod activity;
pub mod actor_language;
Expand Down Expand Up @@ -29,3 +32,11 @@ pub mod registration_application;
pub mod secret;
pub mod site;
pub mod tagline;

/// Default value for columns like [community::Community.inbox_url] which are marked as serde(skip).
///
/// This is necessary so they can be successfully deserialized from API responses, even though the
/// value is not sent by Lemmy. Necessary for crates which rely on Rust API such as lemmy-stats-crawler.
fn placeholder_apub_url() -> DbUrl {
DbUrl(Box::new(Url::parse("http://example.com").unwrap()))
}
9 changes: 6 additions & 3 deletions crates/db_schema/src/source/person.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::newtypes::{DbUrl, InstanceId, PersonId};
#[cfg(feature = "full")]
use crate::schema::{person, person_follower};
use crate::{
newtypes::{DbUrl, InstanceId, PersonId},
source::placeholder_apub_url,
};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
Expand Down Expand Up @@ -40,8 +43,8 @@ pub struct Person {
pub banner: Option<DbUrl>,
/// Whether the person is deleted.
pub deleted: bool,
#[serde(skip)]
pub inbox_url: Option<DbUrl>,
#[serde(skip, default = "placeholder_apub_url")]
pub inbox_url: DbUrl,
#[serde(skip)]
pub shared_inbox_url: Option<DbUrl>,
/// A matrix id, usually given an @person:matrix.org
Expand Down

0 comments on commit 30fef84

Please sign in to comment.