mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 05:07:22 +01:00
Fix username links resulting in truncated chat messages (#11945)
* introduce MAX_MESSAGE_LENGTH constant * add test * fix path * fix and tests * fix typo in tests
This commit is contained in:
@@ -3,6 +3,7 @@ import { v4 as uuid } from 'uuid';
|
||||
import { defaults } from 'lodash';
|
||||
import removeMd from 'remove-markdown';
|
||||
import baseModel from '../libs/baseModel';
|
||||
import shared from '../../common';
|
||||
|
||||
const defaultSchema = () => ({
|
||||
id: String,
|
||||
@@ -113,14 +114,20 @@ export function setUserStyles (newMessage, user) {
|
||||
}
|
||||
}
|
||||
|
||||
// Sanitize an input message, separate from messageDefaults because
|
||||
// it must run before mentions are highlighted
|
||||
export function sanitizeText (msg) {
|
||||
// Trim messages longer than the MAX_MESSAGE_LENGTH
|
||||
return msg.substring(0, shared.constants.MAX_MESSAGE_LENGTH);
|
||||
}
|
||||
|
||||
export function messageDefaults (msg, user, client, flagCount = 0, info = {}) {
|
||||
const id = uuid();
|
||||
const trimmedMessage = msg.substring(0, 3000);
|
||||
const message = {
|
||||
id,
|
||||
_id: id,
|
||||
text: trimmedMessage,
|
||||
unformattedText: removeMd(trimmedMessage),
|
||||
text: msg,
|
||||
unformattedText: removeMd(msg),
|
||||
info,
|
||||
timestamp: Number(new Date()),
|
||||
likes: {},
|
||||
|
||||
Reference in New Issue
Block a user