2022-11-17 08:23:01 -07:00
|
|
|
#[cfg(feature = "full")]
|
2023-03-21 09:03:05 -06:00
|
|
|
use activitypub_federation::{
|
|
|
|
fetch::collection_id::CollectionId,
|
|
|
|
fetch::object_id::ObjectId,
|
|
|
|
traits::Collection,
|
|
|
|
traits::Object,
|
|
|
|
};
|
2023-02-18 07:50:28 -07:00
|
|
|
#[cfg(feature = "full")]
|
2022-07-29 21:55:59 -06:00
|
|
|
use diesel_ltree::Ltree;
|
2021-10-16 07:33:38 -06:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::{
|
|
|
|
fmt,
|
|
|
|
fmt::{Display, Formatter},
|
2022-02-07 12:23:12 -07:00
|
|
|
ops::Deref,
|
2021-10-16 07:33:38 -06:00
|
|
|
};
|
|
|
|
use url::Url;
|
|
|
|
|
2022-05-03 11:44:13 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
2021-10-16 07:33:38 -06:00
|
|
|
pub struct PostId(pub i32);
|
|
|
|
|
|
|
|
impl fmt::Display for PostId {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 11:44:13 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
2021-10-16 07:33:38 -06:00
|
|
|
pub struct PersonId(pub i32);
|
|
|
|
|
2022-05-06 14:55:07 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
2022-05-03 11:44:13 -06:00
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
2021-10-16 07:33:38 -06:00
|
|
|
pub struct CommentId(pub i32);
|
|
|
|
|
|
|
|
impl fmt::Display for CommentId {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 11:44:13 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
2021-10-16 07:33:38 -06:00
|
|
|
pub struct CommunityId(pub i32);
|
|
|
|
|
2022-05-03 11:44:13 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
2021-10-16 07:33:38 -06:00
|
|
|
pub struct LocalUserId(pub i32);
|
|
|
|
|
2022-05-06 14:55:07 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
2022-05-03 11:44:13 -06:00
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
2021-10-16 07:33:38 -06:00
|
|
|
pub struct PrivateMessageId(i32);
|
|
|
|
|
|
|
|
impl fmt::Display for PrivateMessageId {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-06 14:55:07 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
2022-05-03 11:44:13 -06:00
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
2021-10-16 07:33:38 -06:00
|
|
|
pub struct PersonMentionId(i32);
|
|
|
|
|
2022-05-06 14:55:07 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
2022-05-03 11:44:13 -06:00
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
2021-10-16 07:33:38 -06:00
|
|
|
pub struct PersonBlockId(i32);
|
|
|
|
|
2022-05-06 14:55:07 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
2022-05-03 11:44:13 -06:00
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
2021-10-16 07:33:38 -06:00
|
|
|
pub struct CommunityBlockId(i32);
|
|
|
|
|
2022-05-06 14:55:07 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
2022-05-03 11:44:13 -06:00
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
2021-10-16 07:33:38 -06:00
|
|
|
pub struct CommentReportId(i32);
|
|
|
|
|
2022-05-06 14:55:07 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
2022-05-03 11:44:13 -06:00
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
2021-10-16 07:33:38 -06:00
|
|
|
pub struct PostReportId(i32);
|
|
|
|
|
2022-09-19 16:58:42 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
|
|
|
pub struct PrivateMessageReportId(i32);
|
|
|
|
|
2022-10-06 12:27:58 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
|
|
|
pub struct SiteId(i32);
|
|
|
|
|
2022-07-29 21:55:59 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
2022-08-18 13:11:19 -06:00
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
|
|
|
pub struct LanguageId(pub i32);
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
|
|
|
pub struct LocalUserLanguageId(pub i32);
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
2022-10-06 12:27:58 -06:00
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
|
|
|
pub struct SiteLanguageId(pub i32);
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
|
|
|
pub struct CommunityLanguageId(pub i32);
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
2022-07-29 21:55:59 -06:00
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
|
|
|
pub struct CommentReplyId(i32);
|
|
|
|
|
2022-10-27 03:24:07 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
|
|
|
pub struct InstanceId(i32);
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
|
|
|
pub struct LocalSiteId(i32);
|
|
|
|
|
2023-03-20 15:32:31 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
|
|
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
|
|
|
pub struct CustomEmojiId(i32);
|
|
|
|
|
2021-10-16 07:33:38 -06:00
|
|
|
#[repr(transparent)]
|
2022-09-26 08:09:32 -06:00
|
|
|
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
|
2022-05-03 11:44:13 -06:00
|
|
|
#[cfg_attr(feature = "full", derive(AsExpression, FromSqlRow))]
|
2022-09-26 08:09:32 -06:00
|
|
|
#[cfg_attr(feature = "full", diesel(sql_type = diesel::sql_types::Text))]
|
2023-02-18 07:50:28 -07:00
|
|
|
pub struct DbUrl(pub(crate) Box<Url>);
|
2021-10-16 07:33:38 -06:00
|
|
|
|
2023-03-21 09:03:05 -06:00
|
|
|
impl DbUrl {
|
|
|
|
pub fn inner(&self) -> &Url {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 08:23:01 -07:00
|
|
|
#[cfg(feature = "full")]
|
2022-07-29 21:55:59 -06:00
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
#[serde(remote = "Ltree")]
|
|
|
|
/// Do remote derivation for the Ltree struct
|
|
|
|
pub struct LtreeDef(pub String);
|
|
|
|
|
2021-10-16 07:33:38 -06:00
|
|
|
impl Display for DbUrl {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
2022-11-18 21:33:54 -07:00
|
|
|
self.clone().0.fmt(f)
|
2021-10-16 07:33:38 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 18:24:10 -06:00
|
|
|
// the project doesnt compile with From
|
|
|
|
#[allow(clippy::from_over_into)]
|
|
|
|
impl Into<DbUrl> for Url {
|
|
|
|
fn into(self) -> DbUrl {
|
2023-02-18 07:50:28 -07:00
|
|
|
DbUrl(Box::new(self))
|
2021-11-04 18:24:10 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#[allow(clippy::from_over_into)]
|
|
|
|
impl Into<Url> for DbUrl {
|
|
|
|
fn into(self) -> Url {
|
2023-02-18 07:50:28 -07:00
|
|
|
*self.0
|
|
|
|
}
|
|
|
|
}
|
2023-03-21 09:03:05 -06:00
|
|
|
|
2023-02-18 07:50:28 -07:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
impl<T> From<DbUrl> for ObjectId<T>
|
|
|
|
where
|
2023-03-21 09:03:05 -06:00
|
|
|
T: Object + Send + 'static,
|
|
|
|
for<'de2> <T as Object>::Kind: Deserialize<'de2>,
|
2023-02-18 07:50:28 -07:00
|
|
|
{
|
|
|
|
fn from(value: DbUrl) -> Self {
|
2023-03-21 09:03:05 -06:00
|
|
|
let url: Url = value.into();
|
|
|
|
ObjectId::from(url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "full")]
|
|
|
|
impl<T> From<DbUrl> for CollectionId<T>
|
|
|
|
where
|
|
|
|
T: Collection + Send + 'static,
|
|
|
|
for<'de2> <T as Collection>::Kind: Deserialize<'de2>,
|
|
|
|
{
|
|
|
|
fn from(value: DbUrl) -> Self {
|
|
|
|
let url: Url = value.into();
|
|
|
|
CollectionId::from(url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "full")]
|
|
|
|
impl<T> From<CollectionId<T>> for DbUrl
|
|
|
|
where
|
|
|
|
T: Collection,
|
|
|
|
for<'de2> <T as Collection>::Kind: Deserialize<'de2>,
|
|
|
|
{
|
|
|
|
fn from(value: CollectionId<T>) -> Self {
|
|
|
|
let url: Url = value.into();
|
|
|
|
url.into()
|
2021-10-16 07:33:38 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 12:23:12 -07:00
|
|
|
impl Deref for DbUrl {
|
|
|
|
type Target = Url;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|