Skip to content

Adding a ModlogKindDataType to modlog API endpoint.#6300

Merged
Nutomic merged 8 commits intomainfrom
modlog_kind_all
Jan 27, 2026
Merged

Adding a ModlogKindDataType to modlog API endpoint.#6300
Nutomic merged 8 commits intomainfrom
modlog_kind_all

Conversation

@dessalines
Copy link
Copy Markdown
Member

@dessalines dessalines commented Jan 27, 2026

This is necessary to add an All type to the modlog fetch. I ran into this when adding a dropdown filter for modlogs in the front end, and they're the only one that doesn't include an all fetch type.

Notifications work in the same way, with a separated Kind enum in the DB, from the DataType fetch in the API, to allow for an All fetch.

This also potentially allows grouping multiple modlog actions into one, like "actions done on comments", etc. Those can be added later.

This is necessary to add an `All` type to the modlog fetch. I ran into
this when adding a dropdown filter for modlogs in the front end, and
they're the only one that doesn't include an all fetch type.

Notifications work in the same way, with a separated Kind from the
DataType in the API.

This also potentially allows grouping multiple modlog actions into one,
like "actions done on comments", etc. Those can be added later.
ModRemovePost,
ModTransferCommunity,
ModLockComment,
}
Copy link
Copy Markdown
Member

@Nutomic Nutomic Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the name to ModlogKindFilter, much clearer. And change the definition like this:

ModlogKindFilter {
    All,
    #[serde(untagged)]
    Other(ModlogKind)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, hadn't thought of that. I'll see if I can do the same for the notification type too.

ModlogKindDataType::ModLockComment => {
query.filter(modlog::kind.eq(ModlogKind::ModLockComment))
}
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the change above, you can get rid of all this code and write:

if let ModlogKindFilter::Other(kind) = type_ {
      query = query.filter(modlog::kind.eq(type_))
}

Plus this way its not necessary to update the enum every time a new modlog variant is added.

dessalines added a commit to LemmyNet/lemmy-js-client that referenced this pull request Jan 27, 2026
// Comments
let comment_modlog = ModlogQuery {
type_: Some(ModlogKind::ModRemoveComment),
type_: Some(ModlogKindFilter::Other(ModlogKind::ModRemoveComment)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could implement From or Into trait, and then only write Some(ModlogKind::ModRemoveComment.into())

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really worth it for a few lines IMO

@Nutomic Nutomic enabled auto-merge (squash) January 27, 2026 15:43
@Nutomic Nutomic merged commit 12e517c into main Jan 27, 2026
2 checks passed
@Nutomic Nutomic deleted the modlog_kind_all branch January 27, 2026 21:38
dessalines added a commit to LemmyNet/lemmy-js-client that referenced this pull request Jan 27, 2026
* Adding the modlog_kind filter

Backend PR: LemmyNet/lemmy#6300

* 1.0.0-modlog-kind-all.0

* 1.0.0-modlog-kind-all.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants