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

Support pinned post #86

Merged
merged 5 commits into from
Sep 29, 2024
Merged

Support pinned post #86

merged 5 commits into from
Sep 29, 2024

Conversation

takke
Copy link
Contributor

@takke takke commented Sep 28, 2024

ポストの固定に対応しました

  • Add pinnedPost to ActorDefsProfileViewDetailed with fallbacks
    • プロフィール詳細に pinnedPost を追加しました。
    • 日本のいくつかのクライアントが独自に対応していた pinnedPost は形式が違うので落ちないようにカスタムシリアライザを追加しています。
  • Change FeedDefsFeedViewPost.reason to FeedDefsReasonUnion from FeedDefsReasonRepost to support reasonPin
    • post.reason がこれまではリポスト固定でしたが「ピン」のパターンも増えたので Union を追加しています。けっこう既存アプリに影響があります。
  • Add includePins parameter to getAuthorFeed
    • ユーザーのポスト一覧取得時に固定ポストを含めることができるようになりました。
  • Add ability to set/unset pinned post to/from profile
    • プロフィール編集機能の一部としてポストの固定ができるようになりました。
  • Add post.viewer.pinned flag
    • 自分のポスト一覧内に「このポストは固定済み」と識別できるフラグが付いています。固定解除するときの判定等に使えます。

Summary by CodeRabbit

Release Notes

  • New Features

    • Users can now manage pinned posts directly from their profile updates with new options to pin or clear pinned posts.
    • The author feed request now includes an option to retrieve pinned posts.
  • Enhancements

    • The viewer state now indicates whether a feed is pinned.
    • New serialization support for different feed reasons, including repost and pin reasons.
  • Bug Fixes

    • Improved handling of pinned post attributes during profile updates.

These changes enhance user experience by providing more control over content visibility and management.

Copy link

coderabbitai bot commented Sep 28, 2024

Walkthrough

The changes involve enhancements to several classes related to user profiles and feed management in the work.socialhub.kbsky package. Key updates include the addition of properties for managing pinned posts, modifications to existing properties, and the introduction of new classes for handling serialization of feed reasons. These changes aim to improve the functionality and flexibility of user interactions and data management.

Changes

File Change Summary
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/actor/ActorUpdateProfileRequest.kt Added properties pinnedPost and clearPinnedPost to manage user pinned posts. Updated clearBanner for consistency.
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/feed/FeedGetAuthorFeedRequest.kt Introduced a new property includePins to include pin-related data in requests.
core/src/commonMain/kotlin/work/socialhub/kbsky/internal/app/bsky/_ActorResource.kt Removed forced null assertion on request.did and improved handling of pinnedPost logic based on clearPinnedPost.
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/actor/ActorDefsProfileViewDetailed.kt Added a new property pinnedPost with custom serialization.
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/actor/ActorProfile.kt Introduced a nullable property pinnedPost to reference a pinned post in user profiles.
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsFeedViewPost.kt Updated reason property type from FeedDefsReasonRepost? to FeedDefsReasonUnion?.
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonPin.kt Added a new class FeedDefsReasonPin extending FeedDefsReasonUnion with custom serialization.
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonRepost.kt Modified FeedDefsReasonRepost to inherit from FeedDefsReasonUnion and added a companion object with a TYPE constant.
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonUnion.kt Introduced an abstract class FeedDefsReasonUnion for polymorphic handling of feed reasons.
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsViewerState.kt Added a new property pinned to indicate whether a feed is pinned.
core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/FeedDefsReasonPolymorphicSerializer.kt Implemented a polymorphic serializer for FeedDefsReasonUnion to handle different feed reasons.
core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/PinnedPostSerializer.kt Created a serializer for RepoStrongRef to manage the deserialization of pinned posts.

Possibly related PRs

  • Add viewer.knownFollowers #70: The ActorDefsViewerState class has been modified to include a new property knownFollowers, which is relevant to the management of user interactions and social connections.
  • Add feed.postgate and FeedDefsViewerState.embeddingDisabled #78: The addition of the embeddingDisabled property to FeedDefsViewerState enhances state management of feed definitions, aligning with the main PR's focus on user content management.
  • Add ActorDefsSavedFeedsPrefV2 #79: The introduction of ActorDefsSavedFeedsPrefV2 relates to managing user preferences for saved feeds, connecting to the main PR's enhancements in managing user profile features.

Suggested reviewers

  • uakihir0

Poem

In the meadow where rabbits play,
New features hop in, brightening the day.
Pinned posts and feeds, all in a row,
With serializers dancing, watch them glow!
A world of updates, so much to explore,
Hooray for the changes, let’s hop for more! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (11)
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsViewerState.kt (1)

11-11: LGTM! Consider adding a brief comment for clarity.

The addition of the pinned property aligns well with the PR objectives and follows the existing coding style. It's correctly implemented as a nullable Boolean, which is consistent with other properties in the class.

Consider adding a brief comment to explain the purpose of this property, as it represents a new feature:

/** Indicates whether the post is pinned in the user's post list. */
var pinned: Boolean? = null
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonPin.kt (1)

7-16: LGTM: Class structure is well-defined, with a minor suggestion.

The FeedDefsReasonPin class is correctly annotated for serialization and extends FeedDefsReasonUnion, which aligns with the PR objectives of modifying post reasoning. The companion object and type override are implemented correctly.

Consider adding a KDoc comment to the class to describe its purpose and relationship to pinned posts. This would improve code documentation and maintainability. For example:

/**
 * Represents a reason for a post being pinned in a feed.
 * This class is used in serialization/deserialization of feed items
 * where a post is pinned to the top of a user's profile.
 */
@Serializable
class FeedDefsReasonPin : FeedDefsReasonUnion() {
    // ... existing code ...
}
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonUnion.kt (1)

7-12: LGTM: Well-structured abstract class with appropriate serialization.

The FeedDefsReasonUnion class is well-defined as an abstract class with a custom polymorphic serializer. This structure is suitable for representing different types of feed reasons.

Consider enhancing the KDoc by briefly explaining the purpose of this class and how it relates to FeedDefsReasonRepost and FeedDefsReasonPin. For example:

/**
 * Abstract base class for representing different types of feed reasons.
 * Subclasses include:
 * @see FeedDefsReasonRepost
 * @see FeedDefsReasonPin
 */
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/actor/ActorUpdateProfileRequest.kt (1)

15-17: LGTM: New properties for pinned post support added correctly.

The new properties pinnedPost and clearPinnedPost are well-implemented and align with the PR objectives. The nullable RepoStrongRef? type for pinnedPost and the boolean flag for clearPinnedPost provide the necessary flexibility for managing pinned posts.

Consider updating the comment above clearPinnedPost to be more consistent with the comment style used for clearBanner:

-    // set true if you want to clear the pinned post
+    // set true if you want to clear the pinned post

This minor change would improve consistency across the class.

core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/actor/ActorProfile.kt (1)

6-6: LGTM! Changes align well with PR objectives.

The addition of the pinnedPost property and its corresponding import statement are correctly implemented and align perfectly with the PR objectives to support pinned posts functionality in user profiles.

Consider adding a brief comment above the pinnedPost property to explain its purpose and usage. This can help other developers understand the significance of this field in the ActorProfile class. For example:

// Reference to the user's pinned post, if any
var pinnedPost: RepoStrongRef? = null

Also applies to: 24-24

core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/PinnedPostSerializer.kt (1)

14-23: LGTM: Effective handling of current and legacy pinned post formats.

The transformDeserialize method successfully handles both current and legacy formats of pinned posts, ensuring backward compatibility. The fallback mechanism for the old format is well-implemented and clearly commented.

Consider adding a brief comment explaining the expected structure of the current format (JsonObject) for improved clarity and maintainability. For example:

override fun transformDeserialize(element: JsonElement): JsonElement {
    return if (element is JsonObject) {
        // Current format: {"uri": "...", "cid": "..."}
        element
    } else {
        // fallback for old pinned post format
        JsonObject(mapOf("uri" to element, "cid" to JsonPrimitive("")))
    }
}
core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/feed/FeedGetAuthorFeedRequest.kt (1)

24-32: Consider updating documentation and related code.

The changes to FeedGetAuthorFeedRequest are well-implemented and align with the PR objective of supporting pinned posts. The addition of the includePins property with a default value of false ensures backward compatibility.

To fully integrate this change:

  1. Update any relevant documentation to explain the new includePins parameter.
  2. Review and update any code that creates or handles FeedGetAuthorFeedRequest objects to make use of this new capability where appropriate.
  3. Consider adding unit tests to verify the behavior of requests with includePins set to both true and false.
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/actor/ActorDefsProfileViewDetailed.kt (1)

26-30: LGTM: Well-implemented new property with appropriate serialization.

The pinnedPost property is correctly implemented with the following positive aspects:

  • Use of a custom serializer to handle the string type declaration used by some clients.
  • Nullable type, allowing for profiles without pinned posts.
  • Clear commenting explaining the reason for the custom serializer.

Consider slightly rewording the comment for clarity:

- // In Japan, many clients are using "string type declaration" for pinnedPost field,
- // like "pinnedPost": "at://did:plc:xxx".
- // Parse the string type declaration as uri of RepoStrongRef by using [PinnedPostSerializer]
+ // Some clients, particularly in Japan, use a string type declaration for the pinnedPost field,
+ // e.g., "pinnedPost": "at://did:plc:xxx".
+ // [PinnedPostSerializer] parses this string declaration as a URI of type RepoStrongRef.
core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/FeedDefsReasonPolymorphicSerializer.kt (2)

17-28: LGTM with a suggestion: Consider using a proper logging framework.

The selectDeserializer method correctly implements the required functionality to select the appropriate serializer based on the type, including support for FeedDefsReasonPin as per the PR objectives.

Consider replacing println with a proper logging framework for better control and flexibility in a production environment. For example:

import mu.KotlinLogging

private val logger = KotlinLogging.logger {}

// In the else block:
logger.warn { "Unknown Item type: $type (FeedDefsReasonUnion)" }

This change would require adding a logging dependency to your project if not already present.


30-33: LGTM with a suggestion: Consider making the Unknown class more flexible.

The Unknown class is correctly implemented as a serializable subclass of FeedDefsReasonUnion with a fixed "unknown" type.

For increased flexibility, consider allowing the type to be set in the constructor:

@Serializable
class Unknown(override var type: String = "unknown") : FeedDefsReasonUnion()

This change would allow for different "unknown" types if needed in the future, while maintaining the default "unknown" value.

core/src/commonMain/kotlin/work/socialhub/kbsky/internal/app/bsky/_ActorResource.kt (1)

96-101: New feature implemented: Pinned post handling

The addition of the conditional block for handling the pinnedPost attribute is well-implemented and aligns with the PR objectives. It correctly manages both setting and clearing of pinned posts.

However, consider adding validation for the pinnedPost value to ensure it meets any required format or constraints before assignment.

Consider adding validation for the pinnedPost value:

if (request.clearPinnedPost) {
    it.pinnedPost = null
} else {
    val newPinnedPost = request.pinnedPost ?: originalActorProfile.pinnedPost
    // Add validation here
    if (isValidPinnedPost(newPinnedPost)) {
        it.pinnedPost = newPinnedPost
    } else {
        // Handle invalid pinned post (e.g., log warning, throw exception)
    }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cbaad64 and e705b1c.

📒 Files selected for processing (12)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/actor/ActorUpdateProfileRequest.kt (2 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/feed/FeedGetAuthorFeedRequest.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/internal/app/bsky/_ActorResource.kt (2 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/actor/ActorDefsProfileViewDetailed.kt (2 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/actor/ActorProfile.kt (2 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsFeedViewPost.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonPin.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonRepost.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonUnion.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsViewerState.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/FeedDefsReasonPolymorphicSerializer.kt (1 hunks)
  • core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/PinnedPostSerializer.kt (1 hunks)
🔇 Additional comments (29)
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsFeedViewPost.kt (1)

9-9: Approved change, but additional actions required.

The change from FeedDefsReasonRepost? to FeedDefsReasonUnion? aligns with the PR objective of supporting the new reasonPin type and accommodating increasing instances of pinned posts. This change provides more flexibility for different types of post reasons.

However, please consider the following actions:

  1. Add a comment explaining the FeedDefsReasonUnion type and why this change was made. This will help future developers understand the reasoning behind this modification.

  2. Ensure that all existing code that uses the reason property is updated to handle the new union type correctly.

To verify the impact of this change, please run the following script:

This script will help identify areas of the codebase that might need updates due to this change.

core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonPin.kt (4)

1-6: LGTM: Package declaration and imports are well-organized.

The package declaration follows Kotlin naming conventions, and the imports are correctly organized and necessary for the class implementation. The empty line between the package declaration and imports improves readability.


10-12: LGTM: Companion object is well-implemented.

The companion object correctly defines the TYPE constant, which is constructed using BlueskyTypes.FeedDefs and "#reasonPin". This approach ensures consistent type identification for serialization and aligns with the Bluesky ecosystem's conventions.


14-15: LGTM: Type property override is correctly implemented.

The type property is properly overridden and annotated with @SerialName("\$type"), ensuring correct serialization. Initializing it with the TYPE constant from the companion object maintains consistency and allows for proper type discrimination during deserialization.


1-16: LGTM: Implementation aligns well with PR objectives.

The FeedDefsReasonPin class is a well-structured implementation that supports the addition of pinned post functionality as described in the PR objectives. It correctly extends FeedDefsReasonUnion and uses appropriate serialization annotations, allowing for the new reasonPin type in FeedDefsFeedViewPost.reason.

This implementation contributes to the enhanced user experience by providing the necessary data structure for handling pinned posts within the platform. It's consistent with the existing codebase structure and serialization patterns, which should facilitate smooth integration with other components.

core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonRepost.kt (5)

3-5: LGTM: Import statements are correctly updated.

The new import statements for SerialName and BlueskyTypes are consistent with the changes made in the class.


11-13: LGTM: Companion object with TYPE constant added.

The addition of the companion object with the TYPE constant provides a centralized and consistent way to define the type string for this class. This is good practice for maintaining type consistency across the codebase.


15-16: LGTM: Type property correctly overridden and annotated.

The type property is properly overridden and annotated with @SerialName("\$type"). This ensures correct serialization and is consistent with the class's new inheritance structure. Using the TYPE constant from the companion object promotes consistency.


1-20: Summary: Changes successfully implement part of the "Support pinned post" feature.

The modifications to FeedDefsReasonRepost class provide a more flexible structure for different reason types in feed posts. The changes are well-implemented and consistent with the PR objectives. Key points:

  1. The class now inherits from FeedDefsReasonUnion, allowing for different reason types.
  2. A companion object with a TYPE constant has been added for consistency.
  3. The type property is correctly overridden and annotated for proper serialization.

These changes lay the groundwork for supporting pinned posts and other potential reason types in the future.


9-9: LGTM: Class now inherits from FeedDefsReasonUnion.

This change aligns with the PR objective of modifying post reasoning to support new types like reasonPin. It provides a more flexible structure for different reason types.

To ensure this change doesn't break existing code, please run the following script:

✅ Verification successful

Verified: Inheritance change is safe.

The inheritance change of FeedDefsReasonRepost to FeedDefsReasonUnion does not introduce any direct instantiations or unsafe casts that could affect existing functionality. All references are either imports or safe casts, ensuring stability.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any direct instantiations or casts of FeedDefsReasonRepost
# that might be affected by the inheritance change.

rg --type kotlin -e "FeedDefsReasonRepost\(\)" -e "as FeedDefsReasonRepost"

Length of output: 77


Script:

#!/bin/bash
# Description: Search for any references to FeedDefsReasonRepost in the codebase to ensure no hidden usages.

rg --type kotlin "FeedDefsReasonRepost"

Length of output: 794

core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonUnion.kt (3)

1-5: LGTM: Package structure and imports are well-organized.

The package declaration and imports are appropriate for the class being defined. The use of a custom polymorphic serializer (FeedDefsReasonPolymorphicSerializer) is noted and aligns with the polymorphic nature of the FeedDefsReasonUnion class.


13-14: LGTM: Well-defined type property for polymorphic serialization.

The abstract type property with the @SerialName("\$type") annotation is correctly implemented. This setup is crucial for proper polymorphic serialization and deserialization of the FeedDefsReasonUnion subclasses.


1-18: Overall: Well-implemented polymorphic base class for feed reasons.

The FeedDefsReasonUnion class is well-structured and aligns with the PR objectives. It provides a solid foundation for representing different types of feed reasons, including the new reasonPin type. The use of a custom polymorphic serializer and type-safe casting properties enhances its functionality and ease of use.

This implementation allows for easy extension to support additional reason types in the future, making it a flexible and maintainable solution.

core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/actor/ActorUpdateProfileRequest.kt (3)

4-4: LGTM: Import statement for RepoStrongRef added correctly.

The new import for RepoStrongRef is necessary and correctly placed to support the new pinnedPost property.


14-14: Good: Added trailing comma to clearBanner property.

Adding a trailing comma to the clearBanner property is a good practice in Kotlin. It improves readability when properties are listed vertically and makes future additions easier with cleaner diffs.


Line range hint 1-18: Overall: Excellent implementation of pinned post support.

The changes to ActorUpdateProfileRequest successfully implement support for pinned posts as outlined in the PR objectives. The new properties and import are well-integrated into the existing class structure, following Kotlin best practices and maintaining consistency with the codebase.

Key points:

  1. Proper import of RepoStrongRef added.
  2. New properties pinnedPost and clearPinnedPost correctly implemented.
  3. Trailing comma added to improve code style and future maintainability.

These changes enhance the functionality of the class by enabling the management of a user's pinned post alongside their profile updates, which aligns perfectly with the PR's goals.

core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/PinnedPostSerializer.kt (3)

1-8: LGTM: Package declaration and imports are correct and complete.

The package declaration is consistent with the file path, and all necessary imports for JSON serialization and the RepoStrongRef model are present. There are no unused imports.


9-12: LGTM: Object declaration aligns with PR objectives.

The PinnedPostSerializer object is correctly declared as a singleton and extends JsonTransformingSerializer<RepoStrongRef>. This implementation aligns with the PR objective of supporting pinned posts, as it provides a custom serializer for the RepoStrongRef type, which is likely used to represent pinned posts.


1-24: Excellent implementation of PinnedPostSerializer

This implementation of PinnedPostSerializer effectively addresses the PR objective of supporting pinned posts. Key points:

  1. It handles both current and legacy formats of pinned posts, ensuring backward compatibility.
  2. The code is concise, well-structured, and easy to understand.
  3. The use of JsonTransformingSerializer provides a clean way to customize the deserialization process.

The serializer will work seamlessly with the pinnedPost feature in ActorDefsProfileViewDetailed mentioned in the PR objectives. Great job on creating a robust and flexible solution for handling pinned posts!

core/src/commonMain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/feed/FeedGetAuthorFeedRequest.kt (2)

24-25: LGTM: New property includePins added correctly.

The new includePins property is well-implemented:

  • Its purpose is clear from the name.
  • The default value of false maintains backward compatibility.
  • Making it non-nullable ensures type safety.
  • Its placement in the class is logical, grouped with other request parameters.

This addition aligns well with the PR objective of supporting pinned posts in the author feed.


32-32: LGTM: toMap() method updated correctly.

The toMap() method has been properly updated to include the new includePins property:

  • The property is added to the map using the addParam method, consistent with other properties.
  • The key "includePins" matches the property name, maintaining clarity and consistency.

This change ensures that the includePins parameter will be correctly included in API requests.

core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/actor/ActorDefsProfileViewDetailed.kt (2)

5-6: LGTM: Import statements are correct and necessary.

The new import statements for RepoStrongRef and PinnedPostSerializer are correctly added and are essential for the new pinnedPost property and its custom serialization.


Line range hint 1-30: Summary: Changes align well with PR objectives and are well-implemented.

The addition of the pinnedPost property to ActorDefsProfileViewDetailed successfully implements the pinned post feature as described in the PR objectives. The use of a custom serializer (PinnedPostSerializer) effectively addresses the variation in pinnedPost format used by some clients, particularly in Japan.

The implementation is clean, well-documented, and aligns perfectly with the stated goals of the pull request. Great job on this update!

core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/FeedDefsReasonPolymorphicSerializer.kt (3)

1-11: LGTM: Package declaration and imports are correct and appropriate.

The package declaration follows Kotlin naming conventions, and all necessary imports are present without any unused ones.


12-15: LGTM: FeedDefsReasonPolymorphicSerializer object is correctly implemented.

The object declaration and its extension of JsonContentPolymorphicSerializer<FeedDefsReasonUnion> are appropriate for implementing a polymorphic serializer for different feed reason types.


1-34: Overall assessment: Well-implemented polymorphic serializer supporting PR objectives.

This new file successfully implements a polymorphic serializer for FeedDefsReasonUnion, including support for the new FeedDefsReasonPin type as required by the PR objectives. The code is well-structured, follows Kotlin conventions, and provides a robust solution for handling different feed reason types.

Minor suggestions for improvement include:

  1. Using a proper logging framework instead of println.
  2. Making the Unknown class more flexible by allowing the type to be set in the constructor.

These changes would enhance the production-readiness and future-proofing of the code.

core/src/commonMain/kotlin/work/socialhub/kbsky/internal/app/bsky/_ActorResource.kt (3)

77-77: Improved null safety by removing forced null assertion

The removal of the !! operator from request.did is a positive change. It aligns with Kotlin's null safety features and reduces the risk of null pointer exceptions. This change suggests that the did property is now properly handled as potentially nullable.


108-108: Consistent improvement in null safety

This change is consistent with the earlier modification in line 77, further improving null safety by removing the forced null assertion (!!) on request.did. This consistency in handling potentially nullable values throughout the function is commendable.


Line range hint 1-158: Overall assessment: Well-implemented changes with minor improvement suggestion

The changes in this file successfully implement the pinned post functionality as described in the PR objectives. The null safety improvements are consistent and commendable. The only suggestion for improvement is to add validation for the pinnedPost value to ensure data integrity.

Great job on implementing these features while maintaining code quality!

Comment on lines +16 to +17
val asReasonRepost get() = this as? FeedDefsReasonRepost
val asReasonPin get() = this as? FeedDefsReasonPin
Copy link

@coderabbitai coderabbitai bot Sep 28, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

LGTM: Convenient type-safe casting properties.

The asReasonRepost and asReasonPin extension properties provide a safe and convenient way to cast the FeedDefsReasonUnion to its specific subtypes.

Consider adding null checks or using the Elvis operator to provide default behavior when the cast fails. For example:

val asReasonRepost get() = this as? FeedDefsReasonRepost ?: throw IllegalStateException("Not a ReasonRepost")
val asReasonPin get() = this as? FeedDefsReasonPin ?: throw IllegalStateException("Not a ReasonPin")

This approach would make it clearer when a cast fails and prevent potential null pointer exceptions further down the line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

これらのプロパティを 非 null にすることは実用上あまり意味がありません。
post.reason?.asReasonRepost?.by のように使いますが、reason が nullable なので asReasonRepost が 非 null になっても post.reason?.asReasonRepost?.by と記述することに変わりないためです。

また、kbsky 内の他の asXxx プロパティも同様に nullable なのでここだけ 非 null になり例外が出るように変えることはむしろ混乱します。

Copy link

Choose a reason for hiding this comment

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

@takke、ご説明ありがとうございます。おっしゃるとおり、asXxx プロパティを nullable にすることで、一貫性が保たれますね。理解しました。

🐰🤔


✏️ Learnings added
Learnt from: takke
PR: uakihir0/kbsky#86
File: core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonUnion.kt:16-17
Timestamp: 2024-09-28T10:32:00.259Z
Learning: In the kbsky library, `asXxx` properties are nullable, and making them non-nullable and throwing exceptions would cause confusion. Therefore, `asReasonRepost` and `asReasonPin` should remain nullable for consistency.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Owner

@uakihir0 uakihir0 left a comment

Choose a reason for hiding this comment

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

ありがとうございます!

@uakihir0 uakihir0 merged commit c498a6e into uakihir0:main Sep 29, 2024
@takke takke deleted the support_pinned_post branch September 29, 2024 09:45
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