Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Community post tags (part 2: API methods) #5389

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Community post tags (part 2: API methods) #5389

wants to merge 8 commits into from

Conversation

phiresky
Copy link
Collaborator

@phiresky phiresky commented Feb 4, 2025

This is the second part of post tags, implementing the API methods.

Database PR (merged): #4997
Original RFC: LemmyNet/rfcs#4

@@ -222,6 +225,9 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) {
.route("/icon", delete().to(delete_community_icon))
.route("/banner", post().to(upload_community_banner))
.route("/banner", delete().to(delete_community_banner))
.route("/post_tag", post().to(create_community_tag))
.route("/post_tag", put().to(update_community_tag))
.route("/post_tag", delete().to(delete_community_tag))
Copy link
Member

Choose a reason for hiding this comment

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

I would go with /tags instead, using underscore looks ugly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there's also underscore in some other api methods, and here i think it's good to be unambiguous

Copy link
Member

Choose a reason for hiding this comment

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

IMO these should be at :

  • POST /community/tag (creates)
  • PUT /community/tag (updates)
  • DELETE /community/tag (deletes)

Copy link
Collaborator Author

@phiresky phiresky Feb 11, 2025

Choose a reason for hiding this comment

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

The reason I would disagree with this is that it is pretty ambiguous. These are not "community tags" they are "post tags" in a community. Community tags could just as well be tags that admins of an instance add to communities, for example a "technology" tag to all tech communities to group them. This is something that we might want in the future, and adding ambiguity just because an "underscore looks ugly" in a place that no user will ever see seems pretty misguided to me.

Copy link
Member

Choose a reason for hiding this comment

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

I spose the naming of these could be either where they live / who they belong to, or what they apply to. In that sense these are community tags, that apply to posts. This kind of hints that we're trying to do both at once, when we should adopt one: .route("/**post_tag**", post().to(create_**community**_tag))

Doesn't matter to me too much, as long as we're consistent. I think using the ownership level makes sense tho : these community tags might also apply to comments at some point, in addition to posts.

src/api_routes_v4.rs Outdated Show resolved Hide resolved
crates/api/src/post/tags.rs Outdated Show resolved Hide resolved
crates/api/src/post/tags.rs Outdated Show resolved Hide resolved
@phiresky
Copy link
Collaborator Author

phiresky commented Feb 7, 2025

Ready for review. the API tests pass locally for me, but require merging LemmyNet/lemmy-js-client#483

Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

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

What's the slug thing about? The tag already has a name and an ap_id.

let tag_form = TagInsertForm {
name: data.name.clone(),
community_id: data.community_id,
ap_id: Url::parse(&format!("{}/tag/{}", community.actor_id, &data.id_slug))?.into(),
Copy link
Member

Choose a reason for hiding this comment

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

Could you add this as a function to the community impl? Then you can do community.build_tag_ap_id(...) . Or at least as a helper function somewhere.

Copy link
Member

Choose a reason for hiding this comment

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

Or better yet a db trigger

#5409

.await?;

// Soft delete the tag
let tag_form = TagInsertForm {
Copy link
Member

Choose a reason for hiding this comment

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

Should be a TagUpdateForm, with the fields as optional. Check out some of the other community/delete.rs for an example.

Copy link
Member

Choose a reason for hiding this comment

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

Would probably be better to split each action into its own file, like we've done with the other API actions.

crates/api/src/community/tag.rs Outdated Show resolved Hide resolved
crates/api/src/community/tag.rs Outdated Show resolved Hide resolved
crates/api_common/src/community.rs Outdated Show resolved Hide resolved
crates/api_common/src/community.rs Outdated Show resolved Hide resolved
) -> LemmyResult<Json<PostResponse>> {
let post = Post::read(&mut context.pool(), data.post_id).await?;

let is_author = local_user_view.person.id == post.creator_id;
Copy link
Member

Choose a reason for hiding this comment

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

Use Post::is_creator

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Update tags for a post.
Copy link
Member

Choose a reason for hiding this comment

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

Would probably be good to add a comment about how either mods or post creators can do this.

crates/api/src/community/tag.rs Outdated Show resolved Hide resolved
@dessalines
Copy link
Member

Do the re-request review when you want me to have another look. I thought about going through it but I'm guessing its still WIP.

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.

4 participants