Skip to content

Fix inline bot rule mode conversion#63

Closed
BraveSail wants to merge 1 commit into
NextAlone:dev3from
BraveSail:fix/inline-bot-rule-mode-dev3
Closed

Fix inline bot rule mode conversion#63
BraveSail wants to merge 1 commit into
NextAlone:dev3from
BraveSail:fix/inline-bot-rule-mode-dev3

Conversation

@BraveSail
Copy link
Copy Markdown
Contributor

@BraveSail BraveSail commented May 5, 2026

Follow-up to #62.

This preserves host metadata when switching URL inline bot rules between simple and advanced modes, so host-only simple rules do not get stuck as bare regex text. It also recovers host-backed rules that were already persisted with a bare host as the pattern.

Validation:

  • git diff --check upstream/dev3..HEAD

Summary by Sourcery

Preserve and normalize host metadata for URL auto inline bot rules when converting between simple and advanced modes and when parsing persisted rules.

Bug Fixes:

  • Ensure host-only simple URL inline bot rules retain their host metadata instead of degrading to bare regex text when switching modes.
  • Recover and normalize host-backed inline bot rules that were previously stored with only a bare host pattern.
  • Keep per-row host state in the URL auto inline bot rules dialog so conversions between modes use and update the correct host value.

Enhancements:

  • Improve conversion logic between simple and advanced URL inline bot rule modes to more robustly infer and rebuild host-based patterns from existing inputs.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 5, 2026

Reviewer's Guide

Adjusts inline URL auto inline bot rule handling so host metadata is correctly preserved and normalized when converting between simple and advanced modes, and when parsing persisted rules, preventing host-only rules from degrading into bare regex text.

Sequence diagram for inline bot rule mode conversion with host preservation

sequenceDiagram
    actor User
    participant Activity as NekoExperimentalSettingsActivity
    participant Row as FixUrlAutoInlineBotRuleRow
    participant Helper as InlineBotRulesHelper

    User->>Activity: toggle advancedMode
    activate Activity
    Activity->>Activity: updateFixUrlAutoInlineBotRulesDialogMode(context, hintTextView, ruleRows, advancedMode, convertValues)

    loop for each rule row
        Activity->>Row: get value from ruleEditText
        alt advancedMode is true
            Activity->>Helper: normalizeSimpleHostInput(value)
            Helper-->>Activity: normalizedHost
            Activity->>Helper: buildHostPattern(normalizedHost)
            Helper-->>Activity: advancedPattern
            Activity->>Row: set host = normalizedHost
            Activity->>Row: ruleEditText.setText(advancedPattern)
        else simple mode
            Activity->>Helper: extractHostFromPattern(value)
            Helper-->>Activity: hostCandidate
            Activity->>Helper: getHostForRule(value, Row.host)
            Helper-->>Activity: hostFromMetadata
            Activity->>Helper: normalizeSimpleHostInput(value)
            Helper-->>Activity: fallbackHost
            Activity->>Row: set host = chosenHost
            Activity->>Row: ruleEditText.setText(chosenHost)
        end
    end

    Activity-->>User: dialog updated with converted patterns and preserved hosts
    deactivate Activity
Loading

Class diagram for updated inline bot rule handling

classDiagram
    class NekoExperimentalSettingsActivity {
        - ArrayList FixUrlAutoInlineBotRuleRow ruleRows
        + void showFixUrlAutoInlineBotRulesDialog()
        + boolean updateFixUrlAutoInlineBotRulesDialogMode(Context context, TextView hintTextView, ArrayList ruleRows, boolean advancedMode, boolean convertValues)
        + void addFixUrlAutoInlineBotRuleRow(ArrayList ruleRows, LinearLayout rowsContainer, String rule, String username, String host)
        + void setupFixUrlAutoInlineBotRuleEditText(EditTextBoldCursor editText, String rule)
    }

    class FixUrlAutoInlineBotRuleRow {
        + EditTextBoldCursor ruleEditText
        + EditTextBoldCursor usernameEditText
        + String host
        + FixUrlAutoInlineBotRuleRow(EditTextBoldCursor ruleEditText, EditTextBoldCursor usernameEditText, String host)
    }

    class InlineBotRulesHelper {
        + static ArrayList parseInlineBotRules(String list, boolean legacy)
        + static InlineBotRule extractInlineBotRule(JSONObject object)
        + static String extractHostFromPattern(String pattern)
        + static String buildHostPattern(String host)
        + static String normalizeSimpleHostInput(String hostInput)
        + static String normalizeHostInput(String hostInput)
        + static String getHostForRule(String pattern, String existingHost)
        + static void addInlineBotRule(ArrayList rules, InlineBotRule rule)
    }

    class InlineBotRule {
        + String username
        + String pattern
        + String host
        + boolean enabled
        + InlineBotRule(String username, String pattern, String host, boolean enabled)
    }

    NekoExperimentalSettingsActivity ..> FixUrlAutoInlineBotRuleRow : uses
    NekoExperimentalSettingsActivity ..> InlineBotRulesHelper : calls
    NekoExperimentalSettingsActivity ..> InlineBotRule : constructs
    FixUrlAutoInlineBotRuleRow o-- EditTextBoldCursor : composition
    InlineBotRulesHelper ..> InlineBotRule : creates
Loading

File-Level Changes

Change Details Files
Preserve and update host metadata when saving and converting inline URL rules in the experimental settings UI.
  • When saving advanced-mode rules, extract the host from the pattern and, if missing but equal to the stored host, rebuild the host-based pattern and store the host field instead of leaving it empty.
  • During mode toggling, track a parallel list of hosts alongside values so simple→advanced conversion normalizes the host and builds a host pattern, and advanced→simple conversion recovers the host from the pattern or previous host, with fallback normalization from user input.
  • Ensure empty values clear the stored host, and update each row’s stored host when applying converted values.
  • Initialize new FixUrlAutoInlineBotRuleRow instances with a host derived from the rule/host pair via a helper, and extend the row model to store a mutable host field.
TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java
Normalize and repair persisted inline bot rules where host and pattern may be out of sync or pattern is missing.
  • When parsing inline bot rules from JSON, normalize the host string and, if host is present, rebuild the pattern as a host pattern when pattern is empty, equals the raw host, or equals the normalized host.
  • Store the normalized host back into the rule so subsequent logic consistently uses a normalized form before adding the rule to the list.
TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/remote/InlineBotRulesHelper.java

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
Copy Markdown

@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 - I've left some high level feedback:

  • Several code paths assume row.host is non-null (e.g., !row.host.isEmpty() and passing it to getHostForRule), so either ensure FixUrlAutoInlineBotRuleRow.host is always initialized to a non-null value or add null-safety checks to avoid potential NullPointerExceptions.
  • In updateFixUrlAutoInlineBotRulesDialogMode, the host normalization/conversion logic is fairly intricate; consider extracting the simple→advanced and advanced→simple host conversion into small helper methods to make the control flow easier to follow and reduce duplication.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Several code paths assume `row.host` is non-null (e.g., `!row.host.isEmpty()` and passing it to `getHostForRule`), so either ensure `FixUrlAutoInlineBotRuleRow.host` is always initialized to a non-null value or add null-safety checks to avoid potential `NullPointerException`s.
- In `updateFixUrlAutoInlineBotRulesDialogMode`, the host normalization/conversion logic is fairly intricate; consider extracting the simple→advanced and advanced→simple host conversion into small helper methods to make the control flow easier to follow and reduce duplication.

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.

Preserve host metadata when switching between simple and advanced rule modes.

Recover host-backed rules that were persisted with a bare host as the pattern.
@BraveSail BraveSail force-pushed the fix/inline-bot-rule-mode-dev3 branch from ccf2105 to 51bd91d Compare May 5, 2026 14:50
@omg-xtao omg-xtao deleted the branch NextAlone:dev3 May 5, 2026 15:22
@omg-xtao omg-xtao closed this May 5, 2026
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