feat(lemmyv1): surface read_comments_at on PostView#43
Merged
Conversation
Lemmy v1 records the timestamp of the last time the current user read a post's comments in post_actions.read_comments_at. Until now compat only consumed it (via toUnreadComments) to derive unread_comments and threw the raw value away. Surface it as an optional PostView.read_comments_at so clients can distinguish never-opened posts (undefined) from opened-with-new-comments, and highlight individual comments published after the boundary. v0/PieFed leave it undefined (no equivalent timestamp). Normalized through nullToUndef since v1 sends JSON null (not omitted) for unset fields on an existing post_actions row, matching the existing read_at/vote handling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Surface
read_comments_atas an optional field onPostView.Lemmy v1 records the timestamp of the last time the current user read a post's comments in
post_actions.read_comments_at. Until now the compat layer only consumed it insidetoUnreadComments(to deriveunread_comments) and discarded the raw value.Why
It unlocks two client features (e.g. Voyager) that the count alone can't:
toUnreadCommentsreturns the total comment count whenread_comments_atis unset, sounread_comments > 0alone can't tell "5 brand-new comments since I last read" from "5 comments, never opened". The raw timestamp lets clients gate the "N new" badge onread_comments_at != null.published_atis newer thanread_comments_at.Provider coverage
post_actions.read_comments_at.undefined; neither exposes an equivalent read-comments timestamp.Notes
nullToUndef: v1 sends JSONnull(not an omitted key) for unset fields on an existingpost_actionsrow, and the schema isz.optional(z.string())(nonull). This matches the existingread_at/ vote / notification-id handling in the same file —toUnreadCommentsalready guardsread_comments_at == nullfor the same reason.Verification
pnpm test(lint + types + vitest): 25 passed, including 2 newlemmyv1-compatcases — surfaces the timestamp, and mapsnull/absent →undefined.1.0.0-nightlyinstance:get_postreturns the pre-updateread_comments_at(the boundary) and/post/listcarriespost_actions.read_comments_atper post.