Skip to content

fix(feed): don't count inline media URLs toward the long-post threshold#406

Open
dmnyc wants to merge 1 commit into
mainfrom
fix/gallery-note-false-truncation
Open

fix(feed): don't count inline media URLs toward the long-post threshold#406
dmnyc wants to merge 1 commit into
mainfrom
fix/gallery-note-false-truncation

Conversation

@dmnyc

@dmnyc dmnyc commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

A note with a short caption and an image gallery was collapsed behind a "Show more" toggle, with a large empty gap between the caption and the toggle — even though the actual text was only a few lines.

Root cause

PostCardView's long-post decision is isLong = pixelLong || charLong, where charLong = displayEvent.content.count > 600. That counts the raw content string, including inline media URLs. The repro note is 659 chars, but ~496 of those are five inline .png image URLs (~90 chars each) that render as the gallery, not as text — the caption is only ~163 chars / 4 lines. charLong tripped, the post was collapsed with the 280pt text cap, and since the text is far shorter than 280pt the frame left a big empty gap above "Show more".

Fix

  • Add ContentParser.textualLength(content:tags:) — sums only the text-bearing segments (.text, .hashtag, .inlineLink), excluding media, standalone link-preview cards, embedded quote cards, and lightning-invoice cards.
  • charLong now requires both the raw count and the text-only length to exceed 600. The raw-count guard keeps the extra parse off the hot path for short posts.
  • Genuinely long text posts (600+ chars of actual text) still collapse; the measured-height (pixelLong) path is unchanged.

Fixes #405.

Before / After

Before After
before after
Needless "Show more" + empty gap on a short gallery caption Full caption, no truncation, gallery directly below

Test plan

  • Build succeeds, installed and ran on simulator
  • Repro note renders its full caption with no "Show more" and no empty gap (verified)
  • A genuinely long (600+ chars of text) post still collapses with "Show more"
  • A gallery post with a long caption AND many images truncates on the caption length, not the URL count

A note with a short caption and an image gallery was collapsed behind a
"Show more" toggle with a large empty gap, because charLong measured raw
content.count — which includes the inline image URLs that render as the
gallery, not as text. A 4-line caption plus five ~90-char .png URLs
tripped the 600-char threshold.

Add ContentParser.textualLength(content:tags:), which sums only the
text-bearing segments (.text / .hashtag / .inlineLink) and excludes media,
standalone link cards, quote cards, and invoices. charLong now requires
both the raw count and the text-only length to exceed the threshold; the
raw-count guard keeps the extra parse off the hot path for short posts.
Genuinely long text posts still collapse; the measured-height (pixelLong)
path is unchanged.

Fixes #405
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.

bug(feed): gallery note with a short caption gets a needless "Show more" (media URLs counted toward long-post threshold)

1 participant