Skip to content

Extract rich-message text for chat previews and shared text consumers - #98

Open
CHUKEPC wants to merge 3 commits into
TelegramMessenger:masterfrom
CHUKEPC:fix/rich-message-preview
Open

CHUKEPC wants to merge 3 commits into
TelegramMessenger:masterfrom
CHUKEPC:fix/rich-message-preview

Conversation

@CHUKEPC

@CHUKEPC CHUKEPC commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Key change

  • In InstantPagePreview.swift, expanded preview extraction to include untitled table cells, covers, expandable details, button rows, and image/video/audio/document/web-embed/map captions.
  • Added .postEmbed extraction with body → caption → author fallback, plus .collage and .slideshow extraction with child-content → caption fallback. Nested blocks use the same preview extraction rules.
  • Kept .thinking blocks out of previews, including nested thinking, so they cannot consume the preview budget before the answer. Table cells and button labels are separated by spaces, preserving custom emoji entities and UTF-16 ranges.
  • Keep cover extraction and empty-content filtering in the preview-specific helper. InstantPageRichText.swift is identical to master, so legacy Instant View block-quote spacing and rich-message RTL detection retain their existing behavior.
  • Preserved the existing text/media guard and non-empty unsupported-message fallback in TextUtils.swift. Rich messages that also contain ordinary text or media continue through the existing author, folder, and media-prefix path.
  • The extraction is shared: besides chat-list previews, instantPagePreviewText feeds pullText, changing readable rich-message text in reaction notifications, pinned-message service lines, in-chat search results, Copy Selected Text when copying selected messages, and channel statistics. These consumers retain their own existing prefixes/formatting.

Reason

Some supported rich messages store readable content in table cells or nested blocks rather than a top-level title or paragraph. The incomplete shared extraction could produce an unsupported chat-list preview or missing text in other consumers, including an empty quoted snippet in a reaction notification, despite readable content being available.

The fix extracts that content without replacing an unextractable message with a blank subtitle. Thinking-only, uncaptioned-media-only, and unsupported-only rich messages retain the existing fallback when no preview text can be extracted.

Screenshot/video result (before/after)

Before

Chats with rich messages (such as game cards, tables without titles, or bot cards) displayed "Message is not supported" in the dialogs list preview. Other shared-text consumers could receive no readable text; for example a reaction to a table-only message could quote an empty string. The existing captures illustrate the chat-list case:

Before - Message is not supported

Before - Rich message content

After

Readable rich-message text is available to the chat list and the shared-text consumers listed above. For example, a table with cells Name / Alice produces the reaction snippet 👍 to your "Name Alice"; pinned service text, in-chat search, selected-message copying and channel statistics also use that extracted content. The original screenshots below demonstrate only the chat-list surface:

After - Text preview shown

After - Matching rich message content

Confirmation

Verification environment: macOS 27.0 (Apple Silicon), Telegram 13.1.0, build 283357 (Debug).

  • Seven focused regression cases cover thinking exclusion, cell/button separation, custom emoji offsets, nested blocks, post embeds, collages/slideshows, and captions. The cover test now explicitly checks the separation between preview extraction and the unchanged legacy helper: preview covers remain readable and empty separators disappear, while legacy blank paragraphs and cover handling retain their baseline behavior.
  • Verified InstantPageRichText.swift is byte-identical to upstream and the preview still uses markdownPreviewRichText(from:) rather than that legacy helper.
  • All seven actual MessageTextUtils XCTest cases pass against the populated modules, including the revised preview-versus-legacy test. Swift parsing and diff whitespace checks pass. The full Debug workspace build passed with the corrections integrated against upstream ec3521b0; the local build targets macOS 12.0 for Xcode compatibility.

This follow-up changes the title and documentation only. The listed shared-text consumers were traced to their actual pullText call sites; their individual presentation is not covered by the chat-list screenshots or the helper tests. The populated workspace uses local Xcode compatibility settings not included in this PR.

  • I confirm that I have tested the affected behavior and verified that it works properly, or verified the content and links for a documentation-only change.
@CHUKEPC
CHUKEPC force-pushed the fix/rich-message-preview branch from e128114 to 275f155 Compare October 26, 2026 19:00
@macosswift

Copy link
Copy Markdown
Collaborator

Issues:

CONFIRMED: InstantPagePreview.swift:69-70: a .thinking block now leads the preview and uses up the 140-character budget, so for a message with thinking text followed by an answer the chat list shows only the thinking text and never the answer (before this PR it showed the answer)

CONFIRMED: InstantPagePreview.swift:75-83: table cells and button labels (106-113) are joined without a separator, so a table previews as "NameAgeAlice30" and a button row as "YesNo"

CONFIRMED: TextUtils.swift:332-335: a rich message with no extractable text (only uncaptioned media, or only unsupported blocks) now returns an empty string, which leaves a blank chat list subtitle, an empty notification and reply panel, and a dangling "You: " prefix in forum rows

CONFIRMED: InstantPageRichText.swift:19: the new .cover case returns a non-nil empty text for a cover without caption, which adds a stray "\n" separator in nested previews and block quotes

CONFIRMED: TextUtils.swift:321: the message.text.isEmpty, message.media.isEmpty guard was removed, so rich messages that also carry text or media now skip the author, folder and media prefixes; the PR description does not mention this

CONFIRMED: PR description: .postEmbed (with its fallback to the author name), .collage and .slideshow extraction is added but not listed

@CHUKEPC

CHUKEPC commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Excluded thinking from top-level and nested previews, added separators between table cells/button labels, and skipped empty cover content before adding newlines. Restored the original text/media guard and non-empty fallback, preserving existing prefixes. Updated the description to include post embeds (including author fallback), collages, and slideshows.

The full Debug workspace build passed, and all seven new XCTest preview tests passed against the actual package modules, in addition to the isolated harness.

@macosswift

Copy link
Copy Markdown
Collaborator

This pull request is not filled in correctly: the Confirmation section does not state the macOS version. Please complete every section as described in CONTRIBUTING.md and update the PR so it can be reviewed.

Issues:

CONFIRMED: InstantPageRichText.swift:18-21: this hunk no longer affects any chat-list, notification or reply preview, because the preview now goes through markdownPreviewRichText(from:); its only effects are on block quotes in the legacy Instant View (empty paragraphs no longer add a blank line, cover text now shows) and on RTL detection for block quotes in rich chat messages, and the description, which lists it among the preview fixes, mentions neither.

@CHUKEPC

CHUKEPC commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Removed the InstantPageRichText.swift hunk entirely; the legacy helper now matches master, preserving Instant View block-quote spacing/cover handling and the existing RTL path. Preview extraction remains in markdownPreviewRichText(from:), where the intended cover and empty-content behavior belongs.

Updated the regression to check preview and legacy behavior independently, corrected the scope description, and added macOS 27.0 / Telegram 13.1.0 build 283357 to Confirmation. All seven actual MessageTextUtils XCTest cases and the full Debug workspace build pass.

@macosswift

Copy link
Copy Markdown
Collaborator

Issues:

CONFIRMED: PR description: the title, Reason and Before/After describe only the chat list, but instantPagePreviewText also feeds pullText, so the new extraction also changes rich-message text in reaction notifications, the pinned-message service line, in-chat search results, Copy Selected Text and channel stats (for example a reaction to a table-only rich message now reads 👍 to your "Name Alice" instead of 👍 to your ""); please list these surfaces.

@CHUKEPC CHUKEPC changed the title Extract rich message preview text and prevent unsupported message fallback in chat list Oct 29, 2026
@CHUKEPC

CHUKEPC commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Expanded the title, Key change, Reason and Before/After scope beyond the chat list. Traced and listed the shared pullText consumers: reaction notifications, pinned-message service text, in-chat search, selected-message copying and channel statistics. The reaction-to-table example is now explicit, and the existing screenshots are labelled as illustrating only the chat-list surface. This follow-up changes documentation only.

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

Labels

None yet

2 participants