]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/newtypes.rs
Implement separate mod activities for feature, lock post (#2716)
[lemmy.git] / crates / db_schema / src / newtypes.rs
index 22c4aeb896efbd49cdfb5b07efec38b8a11c39df..7e2465bb70b0eb18fd9ef0d927894fcd4dccb766 100644 (file)
@@ -1,3 +1,6 @@
+#[cfg(feature = "full")]
+use activitypub_federation::{core::object_id::ObjectId, traits::ApubObject};
+#[cfg(feature = "full")]
 use diesel_ltree::Ltree;
 use serde::{Deserialize, Serialize};
 use std::{
@@ -69,16 +72,49 @@ pub struct CommentReportId(i32);
 #[cfg_attr(feature = "full", derive(DieselNewType))]
 pub struct PostReportId(i32);
 
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
+#[cfg_attr(feature = "full", derive(DieselNewType))]
+pub struct PrivateMessageReportId(i32);
+
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
+#[cfg_attr(feature = "full", derive(DieselNewType))]
+pub struct SiteId(i32);
+
+#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
+#[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)]
+#[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)]
 #[cfg_attr(feature = "full", derive(DieselNewType))]
 pub struct CommentReplyId(i32);
 
+#[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);
+
 #[repr(transparent)]
-#[derive(Clone, PartialEq, Serialize, Deserialize, Debug)]
+#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
 #[cfg_attr(feature = "full", derive(AsExpression, FromSqlRow))]
-#[cfg_attr(feature = "full", sql_type = "diesel::sql_types::Text")]
-pub struct DbUrl(pub(crate) Url);
+#[cfg_attr(feature = "full", diesel(sql_type = diesel::sql_types::Text))]
+pub struct DbUrl(pub(crate) Box<Url>);
 
+#[cfg(feature = "full")]
 #[derive(Serialize, Deserialize)]
 #[serde(remote = "Ltree")]
 /// Do remote derivation for the Ltree struct
@@ -86,7 +122,7 @@ pub struct LtreeDef(pub String);
 
 impl Display for DbUrl {
   fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
-    self.to_owned().0.fmt(f)
+    self.clone().0.fmt(f)
   }
 }
 
@@ -94,13 +130,23 @@ impl Display for DbUrl {
 #[allow(clippy::from_over_into)]
 impl Into<DbUrl> for Url {
   fn into(self) -> DbUrl {
-    DbUrl(self)
+    DbUrl(Box::new(self))
   }
 }
 #[allow(clippy::from_over_into)]
 impl Into<Url> for DbUrl {
   fn into(self) -> Url {
-    self.0
+    *self.0
+  }
+}
+#[cfg(feature = "full")]
+impl<T> From<DbUrl> for ObjectId<T>
+where
+  T: ApubObject + Send,
+  for<'de2> <T as ApubObject>::ApubType: Deserialize<'de2>,
+{
+  fn from(value: DbUrl) -> Self {
+    ObjectId::new(value)
   }
 }