tlon-apps icon indicating copy to clipboard operation
tlon-apps copied to clipboard

native: render post plaintext preview from intermediate PostContent

Open davidisaaclee opened this issue 7 months ago • 2 comments

fixes TLON-4168

🧞 Hidden in this PR is a design proposition... This PR promotes the app model PostContent (different from api.PostContent) as the canonical intermediate representation for post content. https://github.com/tloncorp/tlon-apps/blob/dd0972daaca2272341cc3696030f88f03543aa72/packages/shared/src/logic/postContent.ts#L143 If accepted, we'll use this PostContent whenever interpreting a post's content; then, we'll move the API post schema to match PostContent.

What changed?

The big change here is in how the notifications render text: Black icon notification is from this PR's changes, white icon is current Testflight without this PR. iPhone/desktop in-app renderings are included for reference, since some formatting is not consistent (iPhone screenshots include this PR's change, but the screenshotted surfaces should not have been affected).

iPhone Desktop
IMG_2874 IMG_2875 IMG_2878 Screenshot 2025-05-08 at 10 05 04 AM
IMG_2873 IMG_2877 Screenshot 2025-05-08 at 10 05 30 AM

The plaintext renderer is also used in the "latest post" summary:

Before this change After this change
IMG_8B6DF1BEEE30-1 IMG_2880

The renderer is a little bit configurable (in case we want to e.g. use a double space for newlines): https://github.com/tloncorp/tlon-apps/blob/6b38d5abc05ce72d33054d7e2c3afdf24608bfee/packages/shared/src/logic/postContent.ts#L145-L164

Why not update the existing getTextContent?

ub.getTextContent operated directly off of the API's post.content – part of this PR is moving to using the in-app PostContent as the canonical intermediate representation (which means we get to share logic like automatically turning list items into block-level items, and eventually having a conversion layer for different post content schemas).

How did I test?

I added a toggle to the ChatMessage.All fixture to preview how posts are rendered into plaintext:

https://github.com/user-attachments/assets/6f02c259-46b9-4ea6-9d3c-cd87233ca669

other stuff for reviewers:

  • [wip] Move post content utils to shared/ is marked wip because the project will not build without the subsequent commit, but combining the commits seemed like it'd be noisy
  • Delete unused code was intended to only remove the dead getTextContent and its helpers, but turned out to be a more aggressive cleanup – I did this by deleting all unused functions, including those which were exported and not imported somewhere else, which ended up removing a handful of other unused members.

davidisaaclee avatar May 08 '25 17:05 davidisaaclee

End results look great, will leave the code review to others. Nice work!

jamesacklin avatar May 08 '25 19:05 jamesacklin

Merge 1ca53e5 was a little hairy – I tested by sending **bold** *italic* as a post, and then checked the chat list "latest post" preview to ensure there was no double spacing.

davidisaaclee avatar May 21 '25 19:05 davidisaaclee