From cb5ad8d6f900073925244f6d59c07396d94c2c80 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Sun, 13 Jan 2019 14:47:08 +0000 Subject: [PATCH] Limit the length of topics and names in the RoomDirectory --- src/components/structures/RoomDirectory.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/structures/RoomDirectory.js b/src/components/structures/RoomDirectory.js index 4c7d004015..762185146c 100644 --- a/src/components/structures/RoomDirectory.js +++ b/src/components/structures/RoomDirectory.js @@ -34,6 +34,9 @@ import { _t } from '../../languageHandler'; import {instanceForInstanceId, protocolNameForInstanceId} from '../../utils/DirectoryUtils'; +const MAX_NAME_LENGTH = 80; +const MAX_TOPIC_LENGTH = 160; + linkifyMatrix(linkify); module.exports = React.createClass({ @@ -390,7 +393,6 @@ module.exports = React.createClass({ const self = this; let guestRead; let guestJoin; let perms; for (let i = 0; i < rooms.length; i++) { - const name = rooms[i].name || get_display_alias_for_room(rooms[i]) || _t('Unnamed room'); guestRead = null; guestJoin = null; @@ -410,7 +412,15 @@ module.exports = React.createClass({ perms =
{guestRead}{guestJoin}
; } + let name = rooms[i].name || get_display_alias_for_room(rooms[i]) || _t('Unnamed room'); + if (name.length > MAX_NAME_LENGTH) { + name = `${name.substring(0, MAX_NAME_LENGTH)}...`; + } + let topic = rooms[i].topic || ''; + if (topic.length > MAX_TOPIC_LENGTH) { + topic = `${topic.substring(0, MAX_TOPIC_LENGTH)}...`; + } topic = linkifyString(sanitizeHtml(topic)); rows.push(