Skip to content

Conversation

@People-11
Copy link
Contributor

@People-11 People-11 commented Sep 25, 2025

这会禁用个人页面中的礼物 Tab
由于我的垃圾思维(指返回所有stargifts_count为0),这也有可能不止关闭个人页面中的礼物功能,所以请开发者小心处理
选项会在“禁用趋势推荐”中

Summary by Sourcery

Introduce a configuration toggle to disable the Gifts feature on profile and shared media UIs and hook it into the settings screen.

New Features:

  • Add DisableGifts config flag in NaConfig
  • Expose the DisableGifts toggle in the chat settings UI

Enhancements:

  • Guard gifts count and tab logic in ProfileGiftsContainer, SharedMediaLayout, and ProfileActivity when gifts are disabled

Documentation:

  • Add English and Chinese string resources for the DisableGifts option

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 25, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduces a new disableGifts configuration flag that, when enabled, suppresses gift counts and the Gifts tab across profile and shared media views. The flag is added to the main config, gated in multiple UI components, and exposed in the settings with accompanying string resources.

Class diagram for NaConfig and disableGifts flag

classDiagram
    class NaConfig {
        +disableGifts: ConfigFlag
        +addConfig(name, parentFlag, id, defaultValue)
    }
    class ConfigFlag {
        +Bool(): boolean
    }
    NaConfig --> ConfigFlag: has
    NaConfig : +disableGifts = addConfig("DisableGifts", disableTrendingFlags, 16, false)
Loading

Class diagram for ProfileGiftsContainer and Gifts tab logic

classDiagram
    class ProfileGiftsContainer {
        -fragment: BaseFragment
        -getGiftsCount(): int
    }
    class NaConfig {
        +getDisableGifts(): ConfigFlag
    }
    ProfileGiftsContainer --> NaConfig: uses
    ProfileGiftsContainer : getGiftsCount() checks NaConfig.disableGifts.Bool()
Loading

Class diagram for SharedMediaLayout and Gifts tab logic

classDiagram
    class SharedMediaLayout {
        -initialTab: int
        -updateTabs(animated): void
    }
    class NaConfig {
        +getDisableGifts(): ConfigFlag
    }
    SharedMediaLayout --> NaConfig: uses
    SharedMediaLayout : initialTab logic checks NaConfig.disableGifts.Bool()
    SharedMediaLayout : updateTabs() checks NaConfig.disableGifts.Bool()
Loading

Class diagram for ProfileActivity and Gifts tab logic

classDiagram
    class ProfileActivity {
        -getView(dialogId): SourceView
        -updateRowsIds(): void
    }
    class NaConfig {
        +getDisableGifts(): ConfigFlag
    }
    ProfileActivity --> NaConfig: uses
    ProfileActivity : getView() and updateRowsIds() check NaConfig.disableGifts.Bool()
Loading

File-Level Changes

Change Details Files
Add new disableGifts configuration flag
  • Define disableGifts in NaConfig with default false
TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt
Gate gift count and tab visibility behind disableGifts flag
  • Wrap getGiftsCount to return zero when disabled
  • Guard initialTab logic for Gifts in SharedMediaLayout
  • Include disableGifts check in updateTabs hasGifts calculation
  • Prevent Gifts tab from opening in ProfileActivity initialTab
  • Skip gift-derived media in ProfileActivity updateRowsIds when disabled
TMessagesProj/src/main/java/org/telegram/ui/Gifts/ProfileGiftsContainer.java
TMessagesProj/src/main/java/org/telegram/ui/Components/SharedMediaLayout.java
TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java
Expose disableGifts option in settings and provide translations
  • Add ConfigCellTextCheck for disableGifts in settings activity
  • Add DisableGifts entries in English and Chinese string resources
TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java
TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml
TMessagesProj/src/main/res/values/strings_na.xml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Extract the repeated NaConfig.INSTANCE.getDisableGifts().Bool() checks into a single helper or utility method to avoid duplication and improve readability across ProfileGiftsContainer, SharedMediaLayout, and ProfileActivity.
  • Consider moving the DisableGifts toggle out of the 'Disable Trending' group into a dedicated ‘Profile Features’ or similar section so it’s more discoverable and semantically organized in the settings UI.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Extract the repeated NaConfig.INSTANCE.getDisableGifts().Bool() checks into a single helper or utility method to avoid duplication and improve readability across ProfileGiftsContainer, SharedMediaLayout, and ProfileActivity.
- Consider moving the DisableGifts toggle out of the 'Disable Trending' group into a dedicated ‘Profile Features’ or similar section so it’s more discoverable and semantically organized in the settings UI.

## Individual Comments

### Comment 1
<location> `TMessagesProj/src/main/java/org/telegram/ui/Components/SharedMediaLayout.java:1519` </location>
<code_context>
         } else if (!NaConfig.INSTANCE.getDisableStories().Bool() && (userInfo != null && userInfo.stories_pinned_available || chatInfo != null && chatInfo.stories_pinned_available || isStoriesView())) {
             this.initialTab = getInitialTab();
-        } else if (userInfo != null && userInfo.stargifts_count > 0 || chatInfo != null && chatInfo.stargifts_count > 0) {
+        } else if (!NaConfig.INSTANCE.getDisableGifts().Bool() && (userInfo != null && userInfo.stargifts_count > 0 || chatInfo != null && chatInfo.stargifts_count > 0)) {
             this.initialTab = TAB_GIFTS;
         } else if (initialTab != -1 && topicId == 0) {
</code_context>

<issue_to_address>
**suggestion:** The conditional disables the gifts tab based on the config, but the logic could be clearer with parentheses.

Adding parentheses will make the condition's logic and operator precedence explicit, reducing the risk of misinterpretation.

Suggested implementation:

```java
        } else if (!NaConfig.INSTANCE.getDisableGifts().Bool() && ((userInfo != null && userInfo.stargifts_count > 0) || (chatInfo != null && chatInfo.stargifts_count > 0))) {

```

```java
        boolean hasGifts = !NaConfig.INSTANCE.getDisableGifts().Bool() && giftsContainer != null && ((userInfo != null && userInfo.stargifts_count > 0) || (info != null && info.stargifts_count > 0));

```
</issue_to_address>

### Comment 2
<location> `TMessagesProj/src/main/java/org/telegram/ui/Components/SharedMediaLayout.java:6497` </location>
<code_context>
         boolean hasStories = (DialogObject.isUserDialog(dialog_id) || DialogObject.isChatDialog(dialog_id)) && !DialogObject.isEncryptedDialog(dialog_id) && (userInfo != null && userInfo.stories_pinned_available || info != null && info.stories_pinned_available || isStoriesView()) && includeStories();
         hasStories = !NaConfig.INSTANCE.getDisableStories().Bool() && hasStories;
-        boolean hasGifts = giftsContainer != null && (userInfo != null && userInfo.stargifts_count > 0 || info != null && info.stargifts_count > 0);
+        boolean hasGifts = !NaConfig.INSTANCE.getDisableGifts().Bool() && giftsContainer != null && (userInfo != null && userInfo.stargifts_count > 0 || info != null && info.stargifts_count > 0);
         int changed = 0;
         if ((hasStories || hasBotPreviews) != scrollSlidingTextTabStrip.hasTab(TAB_STORIES)) {
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Logical operator precedence may cause unintended evaluation order.

Please add parentheses to clarify the intended grouping of conditions and prevent logical errors.

```suggestion
        boolean hasGifts = !NaConfig.INSTANCE.getDisableGifts().Bool()
                && giftsContainer != null
                && ((userInfo != null && userInfo.stargifts_count > 0)
                    || (info != null && info.stargifts_count > 0));
```
</issue_to_address>

### Comment 3
<location> `TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java:3579` </location>
<code_context>
         if (openCommonChats) {
             initialTab = SharedMediaLayout.TAB_COMMON_GROUPS;
-        } else if (openGifts && (userInfo != null && userInfo.stargifts_count > 0 || chatInfo != null && chatInfo.stargifts_count > 0)) {
+        } else if (!NaConfig.INSTANCE.getDisableGifts().Bool() && openGifts && (userInfo != null && userInfo.stargifts_count > 0 || chatInfo != null && chatInfo.stargifts_count > 0)) {
             initialTab = SharedMediaLayout.TAB_GIFTS;
             openedGifts = true;
</code_context>

<issue_to_address>
**suggestion:** Operator precedence in the conditional could be clarified with parentheses.

Group the `userInfo` and `chatInfo` conditions with parentheses to ensure the intended logic is clear and prevent misinterpretation.

Suggested implementation:

```java
        } else if (!NaConfig.INSTANCE.getDisableGifts().Bool() && openGifts && ((userInfo != null && userInfo.stargifts_count > 0) || (chatInfo != null && chatInfo.stargifts_count > 0))) {

```

```java
        if (!NaConfig.INSTANCE.getDisableGifts().Bool() && !hasMedia && ((userInfo != null && userInfo.stargifts_count > 0) || (chatInfo != null && chatInfo.stargifts_count > 0))) {

```
</issue_to_address>

### Comment 4
<location> `TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java:9865` </location>
<code_context>
             hasMedia = userInfo.bot_info.has_preview_medias;
         }
-        if (!hasMedia && (userInfo != null && userInfo.stargifts_count > 0 || chatInfo != null && chatInfo.stargifts_count > 0)) {
+        if (!NaConfig.INSTANCE.getDisableGifts().Bool() && !hasMedia && (userInfo != null && userInfo.stargifts_count > 0 || chatInfo != null && chatInfo.stargifts_count > 0)) {
             hasMedia = true;
         }
</code_context>

<issue_to_address>
**suggestion:** Logical grouping should be clarified for maintainability.

Add parentheses to clarify the logical grouping and prevent ambiguity in condition evaluation.

Suggested implementation:

```java
        } else if (!NaConfig.INSTANCE.getDisableGifts().Bool() && openGifts && ((userInfo != null && userInfo.stargifts_count > 0) || (chatInfo != null && chatInfo.stargifts_count > 0))) {

```

```java
        if (!NaConfig.INSTANCE.getDisableGifts().Bool() && !hasMedia && ((userInfo != null && userInfo.stargifts_count > 0) || (chatInfo != null && chatInfo.stargifts_count > 0))) {

```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@NextAlone
Copy link
Owner

@sourcery-ai[bot] xtao 看看,看起来没啥问题

@omg-xtao omg-xtao changed the base branch from main to dev September 26, 2025 16:00
@omg-xtao omg-xtao merged commit eceeb23 into NextAlone:dev Sep 27, 2025
@People-11 People-11 deleted the upstream-pr branch October 11, 2025 15:48
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.

3 participants