Skip to content

Commit

Permalink
performance: add limits for MessageBody text generally and for quotes…
Browse files Browse the repository at this point in the history
…, core already has limits on text size, but for the cases where core has a bug it's still useful to have a failsave
  • Loading branch information
Simon-Laux committed Jun 17, 2024
1 parent 23f5d31 commit 717ee36
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- skip `requestSingleInstanceLock` on mac appstore builds (mas), because it made it unable to start the app on older macOS devices. #3946
- fix tray icon explaination in settings that appears when started with `--minimized` #3949
- performance: memorize MessageBody, don't run message parser multiple times for the same message #3951
- performance: add limits for MessageBody text generally and for quotes, core already has limits on text size, but for the cases where core has a bug it's still useful to have a failsave #3951

### Removed
- removed unused Roboto font variants #3949
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/components/message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,12 @@ export const Quote = ({
</>
)}
<div className='quoted-text'>
<MessageBody text={quote.text || ''} disableJumbomoji />
<MessageBody
text={
quote.text.slice(0, 3000 /* limit quoted message size */) || ''
}
disableJumbomoji
/>
</div>
</div>
{hasMessage && quote.image && (
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/components/message/MessageBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import classNames from 'classnames'
import { getSizeClass, replaceColons } from '../conversations/emoji'
import { message2React } from './MessageMarkdown'

/** limit where message parser will not parse the message, limit of core is lower, this is just a failsafe */
const UPPER_LIMIT_FOR_PARSED_MESSAGES = 20_000

function MessageBody({
text,
disableJumbomoji,
}: {
text: string
disableJumbomoji?: boolean
}): JSX.Element {
if (text.length >= UPPER_LIMIT_FOR_PARSED_MESSAGES) {
return <>{text}</>
}
// if text is only emojis and Jumbomoji is enabled
const emojifiedText = trim(text.replace(/:[\w\d_\-+]*:/g, replaceColons))
if (!disableJumbomoji) {
Expand Down

0 comments on commit 717ee36

Please sign in to comment.