Adding strum and simplifying imports.

This commit is contained in:
Dessalines 2025-01-08 18:08:35 -05:00
parent be4a05e549
commit 15f1671107
4 changed files with 44 additions and 73 deletions

1
Cargo.lock generated
View file

@ -2742,6 +2742,7 @@ dependencies = [
"serde", "serde",
"serde_with", "serde_with",
"serial_test", "serial_test",
"strum",
"tokio", "tokio",
"ts-rs", "ts-rs",
] ]

View file

@ -40,6 +40,7 @@ diesel-async = { workspace = true, features = [
serde = { workspace = true } serde = { workspace = true }
serde_with = { workspace = true } serde_with = { workspace = true }
ts-rs = { workspace = true, optional = true } ts-rs = { workspace = true, optional = true }
strum = { workspace = true }
[dev-dependencies] [dev-dependencies]
serial_test = { workspace = true } serial_test = { workspace = true }

View file

@ -70,38 +70,29 @@ use lemmy_utils::error::LemmyResult;
impl ModlogCombinedPaginationCursor { impl ModlogCombinedPaginationCursor {
// get cursor for page that starts immediately after the given post // get cursor for page that starts immediately after the given post
pub fn after_post(view: &ModlogCombinedView) -> ModlogCombinedPaginationCursor { pub fn after_post(view: &ModlogCombinedView) -> ModlogCombinedPaginationCursor {
let (prefix, id) = match view { let id = match view {
ModlogCombinedView::AdminAllowInstance(v) => { ModlogCombinedView::AdminAllowInstance(v) => v.admin_allow_instance.id.0,
("AdminAllowInstance", v.admin_allow_instance.id.0) ModlogCombinedView::AdminBlockInstance(v) => v.admin_block_instance.id.0,
} ModlogCombinedView::AdminPurgeComment(v) => v.admin_purge_comment.id.0,
ModlogCombinedView::AdminBlockInstance(v) => { ModlogCombinedView::AdminPurgeCommunity(v) => v.admin_purge_community.id.0,
("AdminBlockInstance", v.admin_block_instance.id.0) ModlogCombinedView::AdminPurgePerson(v) => v.admin_purge_person.id.0,
} ModlogCombinedView::AdminPurgePost(v) => v.admin_purge_post.id.0,
ModlogCombinedView::AdminPurgeComment(v) => ("AdminPurgeComment", v.admin_purge_comment.id.0), ModlogCombinedView::ModAdd(v) => v.mod_add.id.0,
ModlogCombinedView::AdminPurgeCommunity(v) => { ModlogCombinedView::ModAddCommunity(v) => v.mod_add_community.id.0,
("AdminPurgeCommunity", v.admin_purge_community.id.0) ModlogCombinedView::ModBan(v) => v.mod_ban.id.0,
} ModlogCombinedView::ModBanFromCommunity(v) => v.mod_ban_from_community.id.0,
ModlogCombinedView::AdminPurgePerson(v) => ("AdminPurgePerson", v.admin_purge_person.id.0),
ModlogCombinedView::AdminPurgePost(v) => ("AdminPurgePost", v.admin_purge_post.id.0), ModlogCombinedView::ModFeaturePost(v) => v.mod_feature_post.id.0,
ModlogCombinedView::ModAdd(v) => ("ModAdd", v.mod_add.id.0), ModlogCombinedView::ModHideCommunity(v) => v.mod_hide_community.id.0,
ModlogCombinedView::ModAddCommunity(v) => ("ModAddCommunity", v.mod_add_community.id.0), ModlogCombinedView::ModLockPost(v) => v.mod_lock_post.id.0,
ModlogCombinedView::ModBan(v) => ("ModBan", v.mod_ban.id.0), ModlogCombinedView::ModRemoveComment(v) => v.mod_remove_comment.id.0,
ModlogCombinedView::ModBanFromCommunity(v) => { ModlogCombinedView::ModRemoveCommunity(v) => v.mod_remove_community.id.0,
("ModBanFromCommunity", v.mod_ban_from_community.id.0)
} ModlogCombinedView::ModRemovePost(v) => v.mod_remove_post.id.0,
ModlogCombinedView::ModFeaturePost(v) => ("ModFeaturePost", v.mod_feature_post.id.0), ModlogCombinedView::ModTransferCommunity(v) => v.mod_transfer_community.id.0,
ModlogCombinedView::ModHideCommunity(v) => ("ModHideCommunity", v.mod_hide_community.id.0),
ModlogCombinedView::ModLockPost(v) => ("ModLockPost", v.mod_lock_post.id.0),
ModlogCombinedView::ModRemoveComment(v) => ("ModRemoveComment", v.mod_remove_comment.id.0),
ModlogCombinedView::ModRemoveCommunity(v) => {
("ModRemoveCommunity", v.mod_remove_community.id.0)
}
ModlogCombinedView::ModRemovePost(v) => ("ModRemovePost", v.mod_remove_post.id.0),
ModlogCombinedView::ModTransferCommunity(v) => {
("ModTransferCommunity", v.mod_transfer_community.id.0)
}
}; };
// hex encoding to prevent ossification // hex encoding to prevent ossification
let prefix = view.as_ref();
ModlogCombinedPaginationCursor(format!("{prefix}{id:x}")) ModlogCombinedPaginationCursor(format!("{prefix}{id:x}"))
} }
@ -342,55 +333,32 @@ impl ModlogCombinedQuery {
} }
if let Some(type_) = self.type_ { if let Some(type_) = self.type_ {
use lemmy_db_schema::ModlogActionType::*;
query = match type_ { query = match type_ {
ModlogActionType::All => query, All => query,
ModlogActionType::ModRemovePost => { ModRemovePost => query.filter(modlog_combined::mod_remove_post_id.is_not_null()),
query.filter(modlog_combined::mod_remove_post_id.is_not_null()) ModLockPost => query.filter(modlog_combined::mod_lock_post_id.is_not_null()),
} ModFeaturePost => query.filter(modlog_combined::mod_feature_post_id.is_not_null()),
ModlogActionType::ModLockPost => { ModRemoveComment => query.filter(modlog_combined::mod_remove_comment_id.is_not_null()),
query.filter(modlog_combined::mod_lock_post_id.is_not_null()) ModRemoveCommunity => query.filter(modlog_combined::mod_remove_community_id.is_not_null()),
} ModBanFromCommunity => {
ModlogActionType::ModFeaturePost => {
query.filter(modlog_combined::mod_feature_post_id.is_not_null())
}
ModlogActionType::ModRemoveComment => {
query.filter(modlog_combined::mod_remove_comment_id.is_not_null())
}
ModlogActionType::ModRemoveCommunity => {
query.filter(modlog_combined::mod_remove_community_id.is_not_null())
}
ModlogActionType::ModBanFromCommunity => {
query.filter(modlog_combined::mod_ban_from_community_id.is_not_null()) query.filter(modlog_combined::mod_ban_from_community_id.is_not_null())
} }
ModlogActionType::ModAddCommunity => { ModAddCommunity => query.filter(modlog_combined::mod_add_community_id.is_not_null()),
query.filter(modlog_combined::mod_add_community_id.is_not_null()) ModTransferCommunity => {
}
ModlogActionType::ModTransferCommunity => {
query.filter(modlog_combined::mod_transfer_community_id.is_not_null()) query.filter(modlog_combined::mod_transfer_community_id.is_not_null())
} }
ModlogActionType::ModAdd => query.filter(modlog_combined::mod_add_id.is_not_null()), ModAdd => query.filter(modlog_combined::mod_add_id.is_not_null()),
ModlogActionType::ModBan => query.filter(modlog_combined::mod_ban_id.is_not_null()), ModBan => query.filter(modlog_combined::mod_ban_id.is_not_null()),
ModlogActionType::ModHideCommunity => { ModHideCommunity => query.filter(modlog_combined::mod_hide_community_id.is_not_null()),
query.filter(modlog_combined::mod_hide_community_id.is_not_null()) AdminPurgePerson => query.filter(modlog_combined::admin_purge_person_id.is_not_null()),
} AdminPurgeCommunity => {
ModlogActionType::AdminPurgePerson => {
query.filter(modlog_combined::admin_purge_person_id.is_not_null())
}
ModlogActionType::AdminPurgeCommunity => {
query.filter(modlog_combined::admin_purge_community_id.is_not_null()) query.filter(modlog_combined::admin_purge_community_id.is_not_null())
} }
ModlogActionType::AdminPurgePost => { AdminPurgePost => query.filter(modlog_combined::admin_purge_post_id.is_not_null()),
query.filter(modlog_combined::admin_purge_post_id.is_not_null()) AdminPurgeComment => query.filter(modlog_combined::admin_purge_comment_id.is_not_null()),
} AdminBlockInstance => query.filter(modlog_combined::admin_block_instance_id.is_not_null()),
ModlogActionType::AdminPurgeComment => { AdminAllowInstance => query.filter(modlog_combined::admin_allow_instance_id.is_not_null()),
query.filter(modlog_combined::admin_purge_comment_id.is_not_null())
}
ModlogActionType::AdminBlockInstance => {
query.filter(modlog_combined::admin_block_instance_id.is_not_null())
}
ModlogActionType::AdminAllowInstance => {
query.filter(modlog_combined::admin_allow_instance_id.is_not_null())
}
} }
} }

View file

@ -32,6 +32,7 @@ use lemmy_db_schema::source::{
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use strum::AsRefStr;
#[cfg(feature = "full")] #[cfg(feature = "full")]
use ts_rs::TS; use ts_rs::TS;
@ -306,7 +307,7 @@ pub struct ModlogCombinedViewInternal {
pub comment: Option<Comment>, pub comment: Option<Comment>,
} }
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[derive(AsRefStr, Debug, PartialEq, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
// Use serde's internal tagging, to work easier with javascript libraries // Use serde's internal tagging, to work easier with javascript libraries