Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashes for extremely long messages with no line breaks #2163

Conversation

jmartinesp
Copy link
Member

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

  • Adds a max safe length for room list's last message and message summaries.

Motivation and context

Fixes #2105 .

This can affect the rendering of the timeline too, but I'm not sure about how to handle this. Should we hard truncate them at N length? Should we look for the first \n char and if it's > N truncate it them? Should we add some suffix to the end of the message to make sure users understand it's been truncated?

Screenshots / GIFs

Tests

  • In DefaultRoomLastMessageFormatter.kt, replace one of the results with some buildString { ... } that ends up having several thousand characters without any line breaks.
  • Run the app with those changes.

If it doesn't crash, the substring is doing its job and the issue is fixed. To be sure you can remove the trailing .take(MAX_SAFE_LENGTH) expression.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

@jmartinesp jmartinesp requested a review from a team as a code owner January 4, 2024 12:52
@jmartinesp jmartinesp requested review from bmarty and removed request for a team January 4, 2024 12:52
@jmartinesp
Copy link
Member Author

I mentioned it in the PR description, but I'll add it here too for more visibility:

This can affect the rendering of the timeline too, but I'm not sure about how to handle this. Should we hard truncate them at N length? Should we look for the first \n char and if it's > N truncate it then, although this could have performance implications? Should we add some suffix to the end of the message to make sure users understand it's been truncated?

Copy link
Contributor

github-actions bot commented Jan 4, 2024

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/13ztnp

Copy link

sonarqubecloud bot commented Jan 4, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link

codecov bot commented Jan 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5cf4dc8) 66.95% compared to head (0f8c49c) 67.03%.
Report is 18 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2163      +/-   ##
===========================================
+ Coverage    66.95%   67.03%   +0.08%     
===========================================
  Files         1375     1375              
  Lines        34236    34188      -48     
  Branches      7546     7449      -97     
===========================================
- Hits         22922    22918       -4     
+ Misses        7675     7653      -22     
+ Partials      3639     3617      -22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


companion object {
// Max characters to display in the summary message. This works around https://github.com/element-hq/element-x-android/issues/2105
private const val MAX_SAFE_LENGTH = 500
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

512 would have been nicer to me 🤓

@jmartinesp
Copy link
Member Author

@bmarty thanks for the approval!

I mentioned it in the PR description, but I'll add it here too for more visibility:

This can affect the rendering of the timeline too, but I'm not sure about how to handle this. Should we hard truncate them at N length? Should we look for the first \n char and if it's > N truncate it then, although this could have performance implications? Should we add some suffix to the end of the message to make sure users understand it's been truncated?

Any ideas on this? Should we discuss it tomorrow and iterate on this PR once we've decided how to handle these messages in the timeline?

@bmarty
Copy link
Member

bmarty commented Jan 5, 2024

Yes, let's discuss this IRL.

@jmartinesp
Copy link
Member Author

We'll discuss the problem with the timeline with the product team and come up with a different solution for it. We're merging this in the meantime.

@jmartinesp jmartinesp added the Run-Maestro Starts a Maestro Cloud session to run integration tests label Jan 5, 2024
@jmartinesp jmartinesp enabled auto-merge (squash) January 5, 2024 10:46
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label Jan 5, 2024
@jmartinesp jmartinesp merged commit 4776fc5 into develop Jan 5, 2024
19 checks passed
@jmartinesp jmartinesp deleted the fix/jme/2105-truncate-long-messages-in-last-message-formatter branch January 5, 2024 11:11
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.

Repeated crashing/bricked app
2 participants