Skip to content

Conversation

@alltheseas
Copy link
Collaborator

@alltheseas alltheseas commented Feb 4, 2026

Screenshot

Screenshot 2026-02-04 at 5 55 10 PM

Summary

  • Add support for displaying a triple star badge for Purple members who have been subscribed for more than three years
  • Add memberForMoreThanThreeYears attribute to PurpleAccountAttributes
  • Add TripleStar view with iOS 17+ shape and iOS 16 fallback
  • Add tests for account attribute parsing including backward compatibility

Checklist

Standard PR Checklist

  • I have read (or I am familiar with) the Contribution Guidelines
  • I have tested the changes in this PR
  • I have profiled the changes to ensure there are no performance regressions, or I do not need to profile the changes.
    • If not needed, provide reason: UI-only change with no compute-intensive operations
  • I have opened or referred to an existing github issue related to this change.
  • My PR is either small, or I have split it into smaller logical commits that are easier to review
  • I have added the signoff line to all my commits. See Signing off your work
  • I have added appropriate changelog entries for the changes in this PR. See Adding changelog entries
  • I have added appropriate Closes: or Fixes: tags in the commit messages wherever applicable, or made sure those are not needed. See Submitting patches

Test report

Device: iPhone 17 Pro Simulator

iOS: 26.2

Damus: This branch

Setup: Built and ran tests via xcodebuild

Steps:

  1. Ran DamusPurpleAccountAttributesTests - 5 tests for parsing account attributes
  2. Verified backward compatibility when member_for_more_than_three_years field is missing
  3. Built project successfully

Results:

  • PASS

Other notes

The Purple API server will need to be updated to return the new member_for_more_than_three_years field in the account attributes response for this feature to work end-to-end.

Closes: #3591

Summary by CodeRabbit

  • New Features

    • Added membership-tenure attributes for Purple accounts (1+ year and 3+ year).
    • Introduced a three-year supporter variant and triple-star badge rendering.
  • UI

    • Supporter badge now prioritizes three-year visual over one-year and normal variants; includes platform fallback rendering.
  • Tests

    • Added tests validating Purple account attribute parsing across tenure scenarios.

@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

Adds a three‑year Purple membership attribute and badge: introduces memberForMoreThanThreeYears in account payload parsing, computes PurpleAccountAttributes from server flags, adds TripleStar and BadgeVariant.threeYearSpecial, updates a Swift package reference, and adds tests validating parsing.

Changes

Cohort / File(s) Summary
Project Configuration
damus.xcodeproj/project.pbxproj
Added DamusPurpleAccountAttributesTests.swift to project/test build entries; renamed Swift package reference occurrences from secp256k1secp256k1.swift.
Account Attributes Model
damus/Features/Purple/Models/DamusPurple.swift
Added static flags memberForMoreThanOneYear, memberForMoreThanThreeYears; extended Account.Payload.Attributes with member_for_more_than_one_year: Bool and member_for_more_than_three_years: Bool?; Account.from(payload:) now builds PurpleAccountAttributes from server flags.
Badge Component
damus/Shared/Components/SupporterBadge.swift
Added BadgeVariant.threeYearSpecial; introduced TripleStar: View (iOS17 Shape + iOS16 fallback); badge selection updated to prefer three‑year variant and render triple‑star.
Test Suite
damusTests/DamusPurpleAccountAttributesTests.swift
New tests validating parsing of one‑year and three‑year membership flags, null/absent attributes, and combinations.

Sequence Diagram(s)

sequenceDiagram
    participant Server
    participant AccountModel as Account.Model
    participant Badge as SupporterBadge
    participant View as Badge View

    Server->>AccountModel: send JSON payload (attributes flags)
    activate AccountModel
    AccountModel->>AccountModel: parse payload, compute PurpleAccountAttributes set
    AccountModel-->>Badge: provide Account with attributes
    deactivate AccountModel

    activate Badge
    Badge->>Badge: evaluate memberForMoreThanThreeYears?
    alt three-year
        Badge->>View: render TripleStar
    else one-year
        Badge->>View: render one-year variant
    else none
        Badge->>View: render normal badge
    end
    deactivate Badge
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I nibbled JSON, flags in tow,
Three years shining in purple glow.
Triple stars hopped into view,
Attributes parsed, badges new —
A rabbit claps: hooray for two‑and‑three!

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add triple star badge for three-year Purple members' clearly and concisely summarizes the main change—adding a badge for members with three years of membership.
Description check ✅ Passed The PR description includes a summary, completed standard PR checklist with all items marked, detailed test report with device/iOS/setup/steps/results, and relevant notes about API dependencies.
Linked Issues check ✅ Passed The PR addresses issue #3591 (three star anniversary) by implementing triple star badge display logic, adding memberForMoreThanThreeYears attribute parsing, and comprehensive tests for account attribute handling.
Out of Scope Changes check ✅ Passed All changes are in-scope: badge UI (SupporterBadge.swift), account attributes (DamusPurple.swift), test coverage (DamusPurpleAccountAttributesTests.swift), and project configuration (project.pbxproj for dependencies/tests).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@alltheseas
Copy link
Collaborator Author

requires Purple API change: #3591 (comment)

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: 3

🤖 Fix all issues with AI agents
In `@damus.xcodeproj/project.pbxproj`:
- Around line 1500-1504: Remove or fix the dangling PBXBuildFile entry
D73E5EFE2C6A97F4007EB227 in the Sources build phase: either delete this build
file record (the one with isa = PBXBuildFile and no fileRef) from the
project.pbxproj and from the Sources phase list, or replace its missing fileRef
with the correct file reference to the intended source file; ensure no other
build phase entries reference the same placeholder and repeat the same cleanup
for the other occurrences noted (e.g., the similar entries around lines
7262-7266).

In `@damus/Features/Purple/Models/DamusPurple.swift`:
- Around line 474-478: Add a doc comment for the new optional field
member_for_more_than_three_years in the Attributes struct explaining what the
flag represents (e.g., true when the member has been a member for more than
three years), that it is optional/nullable, and any server semantics (when it
may be omitted); update the Attributes struct's property comments so both
member_for_more_than_one_year and member_for_more_than_three_years have concise
docstrings describing their meaning and types.

In `@damus/Shared/Components/SupporterBadge.swift`:
- Around line 176-251: Add doc comments to the newly introduced TripleStar view
internals: document the TripleStar struct (describe purpose and parameters like
size and starOffset), the nested TripleStarShape (explain strokeSize, starOffset
and what path(in:) returns), and the Fallback view (describe its behavior for
iOS <17 and parameters size and starOffset). Place concise /// comments above
TripleStar, TripleStarShape, TripleStarShape.path(in:), and Fallback explaining
intent, parameters, and platform behavior to satisfy docstring coverage
guidelines.
🧹 Nitpick comments (2)
damusTests/DamusPurpleAccountAttributesTests.swift (2)

88-110: Consider consolidating or differentiating this test.

testParseAccountWithMissingThreeYearField has an identical JSON payload to testParseAccountWithOneYearAttribute (lines 40-52). While the intent differs (feature verification vs backward compatibility documentation), the tests are functionally redundant.

Consider either:

  1. Consolidating them into a single test with clear documentation of both intents, or
  2. Adding a distinguishing comment to clarify why both exist.

112-133: Consider adding a test for absent attributes key.

The current tests cover "attributes": null, but there's no test for when the attributes key is completely absent from the JSON. Depending on how Payload.Attributes is declared, these may behave differently during JSON decoding.

Suggested additional test
/// Tests backward compatibility when the attributes field is absent from the response.
func testParseAccountWithAbsentAttributesField() throws {
    let json = """
    {
        "pubkey": "\(testPubkeyHex)",
        "created_at": 1700000000,
        "expiry": 1800000000,
        "subscriber_number": 42,
        "active": true
    }
    """

    guard let account = DamusPurple.Account.from(json_data: json.data(using: .utf8)!) else {
        XCTFail("Failed to parse account")
        return
    }

    XCTAssertFalse(account.attributes.contains(.memberForMoreThanOneYear))
    XCTAssertFalse(account.attributes.contains(.memberForMoreThanThreeYears))
}

@alltheseas alltheseas added the purple Damus purple membership label Feb 4, 2026
Add support for displaying a triple star badge for Purple members
who have been subscribed for more than three years.

Changes:
- Add memberForMoreThanThreeYears attribute to PurpleAccountAttributes
- Add member_for_more_than_three_years field to server response parsing
- Add TripleStar view with iOS 17+ shape and iOS 16 fallback
- Add threeYearSpecial badge variant
- Update badge selection logic to check for three-year membership
- Add tests for account attribute parsing including backward compatibility

The server will need to be updated to return the new
member_for_more_than_three_years field in the account attributes.

Closes: damus-io#3591

Changelog-Added: Add triple star badge for three-year Purple members

Signed-off-by: alltheseas <alltheseas@users.noreply.github.com>
@alltheseas
Copy link
Collaborator Author

Addressed coderabbit nitpick comments:

  1. Removed redundant test - testParseAccountWithMissingThreeYearField was identical to testParseAccountWithOneYearAttribute, so I removed it. The backward compatibility for missing fields is implicitly tested by testParseAccountWithOneYearAttribute since the member_for_more_than_three_years field is absent in that JSON.

  2. Added test for absent attributes key - Added testParseAccountWithAbsentAttributesKey which tests when the attributes key is completely missing from the JSON (not just null).

All 5 tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

purple Damus purple membership

Projects

None yet

Development

Successfully merging this pull request may close these issues.

three star anniversary

1 participant