Skip to content

Phone notifications: show a DM's words, not its markers or HTML - #293

Closed
svaka2000 wants to merge 1 commit into
Open-Coding-Society:masterfrom
svaka2000:fix/push-snippet-markers
Closed

svaka2000 wants to merge 1 commit into
Open-Coding-Society:masterfrom
svaka2000:fix/push-snippet-markers

Conversation

@svaka2000

Copy link
Copy Markdown
Contributor

A DM's phone notification (added in #277) now shows the message's words. Before, it showed the message the way Spring stores it, so a reply came through as [[reply:9|Bob|hey%20there]] thanks! instead of thanks!, and a pasted link came through as <a href=…> HTML.

  • PushNotificationService.snippet builds the notification's text from the message body. Before, it only collapsed whitespace and cut the body to 140 characters. It still cuts to 140, now after the cleanup.
  • The Messages page in pages (/dm) puts [[…]] markers in a message's text for things like replies, code blocks and pins. The page reads them and shows a quote, a code block or a pin note instead, so a person never sees the marker itself. snippet now takes those markers out and keeps the words around them.
  • The rich text box sends HTML, so snippet turns it into plain text with jsoup, the HTML parser Spring already uses for DM search: tags come out, &amp; becomes &, and &nbsp; becomes a space.
  • If a message is only a marker, the notification says what happened instead, like "pinned a message", "sent code" or "shared files" (the title is still the sender's name).

Other notes:

  • Spring's marker list is the same as ANY_MARKER_PATTERN in pages' assets/js/chat/chat-reply.js, including code from Messages: GitHub link cards, slash commands and code blocks pages#2071 and pin and unpin from Messages: a Shared panel and pins pages#2072. I left a comment next to Spring's list saying it has to match, so a new marker gets added in both.
  • A marker never has a bracket inside it (pages escapes or URL-encodes them), so Spring's pattern leaves [ out too. That way a message full of [[ that never close doesn't slow snippet down.
  • notifyPerson runs inside the DM's transaction and never throws, so if the text can't be made from a body, it logs a warning and the notification goes out without text. The DM is still sent.
  • Spring can deploy this on its own, and pages doesn't need a change.
  • I added PushNotificationSnippetTest (5 tests, 3 of them fail on master). The full suite passes except ImportPersonPasswordTest (it needs a local .env) and PersonCapstoneApprovalRouteTest, which fail the same way on master.

How to try it: run ./mvnw test -Dtest='PushNotification*Test'. That runs the new test and the two push notification tests that were already there.

…HTML

The push text was the stored body with its whitespace collapsed, so a phone
showed what the page reads: [[reply:…]], [[files:…]], [[code:…]] and
[[pin:…]] markers, and the rich composer's HTML (<a href=…>, &nbsp;). Now
the markers are left out, the HTML becomes the text a reader sees, and a
message that was only a marker says what it did ("pinned a message",
"sent code", "shared files"). A marker's payload can't hold a bracket, so a
body full of unclosed "[[" is still matched in linear time.

notifyPerson runs inside the message's transaction and never throws, so if
the text can't be made from a body, the notification goes out without text
and the DM is still sent.
@svaka2000

Copy link
Copy Markdown
Contributor Author

Combined into #314 with the same commits.

@svaka2000 svaka2000 closed this Nov 26, 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.

1 participant