element-hq / element-web

A glossy Matrix collaboration client for the web.
https://element.io
GNU Affero General Public License v3.0
11k stars 1.96k forks source link

Limit number of characters on display names #5739

Open happyGNU opened 6 years ago

happyGNU commented 6 years ago

Description

A kid today changed his nickname on Riot.im to a 36,213 characters long nickname, spamming everyone on IRC and Riot.im

Steps to reproduce

Expected behavior

Ok, just for fun I will... Keep in mind that the amount of screenshots would had been immense, so I just post a few and a file with a copy paste of the username.

This bug probably affects all devices, although is probably easier to make it happen on a desktop because of the easy use of copy+paste.

captura de pantalla_2017-11-29_22-28-57 captura de pantalla_2017-11-29_22-29-12 captura de pantalla_2017-11-29_22-29-28 captura de pantalla_2017-11-29_22-29-58 spam.txt

ericabxy commented 6 years ago

Yeah I encountered this issue as well. To make Riot useable a username ought to be limited to some reasonable amount of characters, and maybe even abbreviated in cases such as this.

uhoreg commented 6 years ago

One possibility is to add CSS that prevents the displayname from wrapping, along with "text-overflow: ellipsis".

Also, pills will need the same treatment.

lampholder commented 6 years ago

This should certainly be fixed :D The only questions are:

36213 characters is unhelpfully obviously too long; it doesn't help us to set a sensible limit at all

I'd suggest that:

But what should the limit be?

Personally I'd vote for Matrix supporting Picasso and for Riot to truncate (with ellipsis and full text on hover) whenever a display name goes over a line break (always making room for disambiguation-mxid-in-parenthesis for the inevitable case when some idiot copies another idiot's massive name).

And Adolf W671m, Senior is out of luck and will have to implement his own realtime messaging protocol.

lampholder commented 6 years ago

Aaaand I forgot about pills. They should probably be more restrictive again - noodling around in firebug it seems that anything longer than ~35 characters looks dreadful.

uhoreg commented 6 years ago

The display in the timeline heading can be addressed by adding something along these lines:

.mx_MatrixChat_useCompactLayout .mx_EventTile .mx_SenderProfile {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

This limits the display name to one line, and adds a "..." at the end of the line if it is too long.

before: image

after: image

Note: this probably does not fix the length of membership events (e.g. "X joined", or "X changed their displayname...") nor pills

uhoreg commented 5 years ago
a.mx_UserPill {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 20em;
    vertical-align: text-bottom;
}

will address the issue for pills, and

span.mx_MEmoteBody_sender {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    display: inline-block;
    max-width: calc(100% - 2em);
    vertical-align: bottom;
}

will address the issue for emotes. (the calc in the max-width is to take into account the preceding "* ") Maybe someone who understands CSS better than I can figure out why one wants vertical-align: bottom, and the other wants vertical-align: bottom.

There doesn't seem to be an easy way to fix membership events, since the usernames are not enclosed in any tags.